Repository navigation
Expand file tree
/
Copy pathclassifiers.ts
More file actions
166 lines (144 loc) · 5.81 KB
/
Copy pathclassifiers.ts
File metadata and controls
166 lines (144 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* Block Type Classifiers
*
* Local copies of the classifier functions from @ice/types/connection-rules.
* Inlined here because @ice/core uses NodeNext moduleResolution while
* @ice/types uses bundler resolution — the re-exports don't cross cleanly.
*
* These are trivially small and change rarely. If they diverge,
* the connection validation tests will catch it.
*
* The network-container set is the one piece that IS shared via
* `@ice/constants:NETWORK_CONTAINER_TYPES` — so a new container type
* (e.g. a future Network.PrivateLink) flips both `isContainer` predicates
* in lockstep without touching this file. The non-network predicate
* regexes still need a sync pass when changed.
*/
import { NETWORK_CONTAINER_TYPES } from '@ice/constants';
export function isDatabase(t: string): boolean {
return (
t.startsWith('Database.') ||
/PostgreSQL|MySQL|MongoDB|DynamoDB|Firestore|CosmosDB|AutonomousDB|Tablestore|ManagedDB/i.test(t)
);
}
export function isCache(t: string): boolean {
return /Redis|Cache|Memcache/i.test(t);
}
export function isQueue(t: string): boolean {
return t.startsWith('Messaging.') || /Queue|SQS|SNS|PubSub|ServiceBus|RabbitMQ|Kafka|Event/i.test(t);
}
export function isStorage(t: string): boolean {
return t.startsWith('Storage.') || /Bucket|S3|GCS|Blob|ObjectStorage|Spaces/i.test(t);
}
export function isBackend(t: string): boolean {
return (
/Backend|Container|Worker|Function|CronJob|Scheduled|AppPlatform|OCIFunctions/i.test(t) || t.startsWith('Compute.')
);
}
export function isFrontend(t: string): boolean {
return /StaticSite|SSRSite|Frontend/i.test(t);
}
export function isGateway(t: string): boolean {
return /Gateway|LoadBalancer|Internet|WAF/i.test(t) || t === 'Network.Gateway';
}
export function isAuth(t: string): boolean {
return /Auth|Identity|IAM/i.test(t) || t === 'Security.Identity';
}
export function isSecrets(t: string): boolean {
return /Secret|Vault|Certificate/i.test(t) || t === 'Security.Secret';
}
export function isMonitoring(t: string): boolean {
return /Log|Monitor|Observability|Terminal/i.test(t) || t.startsWith('Monitoring.') || t.startsWith('Log.');
}
export function isSearch(t: string): boolean {
return /Search|Elasticsearch/i.test(t) || t === 'Analytics.Search';
}
export function isVectorDb(t: string): boolean {
return /VectorDB|Vector/i.test(t) || t === 'AI.VectorDB';
}
export function isLLM(t: string): boolean {
return /LLM|ModelServing/i.test(t) || t === 'AI.LLMGateway' || t === 'AI.ModelServing';
}
export function isRepo(t: string): boolean {
return t === 'Source.Repository';
}
export function isEnvConfig(t: string): boolean {
return t === 'Config.Environment';
}
export function isDomain(t: string): boolean {
return t === 'Network.PublicEndpoint' || /Domain|DNS/i.test(t);
}
export function isContainer(iceType: string, nodeType?: string): boolean {
if (nodeType === 'container' || nodeType === 'group') return true;
return (NETWORK_CONTAINER_TYPES as readonly string[]).includes(iceType) || iceType.startsWith('Group.');
}
function isService(t: string): boolean {
return isBackend(t) || isFrontend(t);
}
/**
* Check if two block types can be connected.
* Mirrors canConnect() from @ice/types/connection-rules.
*/
export function canConnect(
srcIceType: string,
tgtIceType: string,
srcNodeType?: string,
tgtNodeType?: string,
): boolean {
if (isContainer(srcIceType, srcNodeType) || isContainer(tgtIceType, tgtNodeType)) return false;
// Check all valid connection rules
const rules: Array<{ source: (t: string) => boolean; target: (t: string) => boolean }> = [
// Traffic: request
{ source: isFrontend, target: isBackend },
{ source: isGateway, target: isGateway },
{ source: isGateway, target: isBackend },
{ source: isGateway, target: isFrontend },
{ source: isBackend, target: isBackend },
{ source: isBackend, target: isAuth },
{ source: isFrontend, target: isAuth },
{ source: isFrontend, target: isGateway },
// Traffic: data
{ source: isBackend, target: isDatabase },
{ source: isBackend, target: isCache },
{ source: isBackend, target: isStorage },
{ source: isBackend, target: isSearch },
{ source: isBackend, target: isVectorDb },
{ source: isBackend, target: isLLM },
{ source: isFrontend, target: isStorage },
// Traffic: data (reverse)
{ source: isDatabase, target: isBackend },
{ source: isCache, target: isBackend },
{ source: isStorage, target: isBackend },
{ source: isStorage, target: isFrontend },
{ source: isSearch, target: isBackend },
{ source: isVectorDb, target: isBackend },
{ source: isLLM, target: isBackend },
{ source: isAuth, target: isBackend },
{ source: isAuth, target: isFrontend },
// Traffic: publish/subscribe
{ source: isBackend, target: isQueue },
{ source: isQueue, target: isBackend },
{
source: isBackend,
target: (t: string) => /Warehouse|BigQuery|Redshift|Synapse/i.test(t) || t === 'Analytics.DataWarehouse',
},
{
source: (t: string) => /Warehouse|BigQuery|Redshift|Synapse/i.test(t) || t === 'Analytics.DataWarehouse',
target: isBackend,
},
// Traffic: stream
{ source: (t: string) => !isMonitoring(t) && !isContainer(t), target: isMonitoring },
// Pipeline
{ source: isRepo, target: isService },
{ source: isService, target: isRepo },
// Config
{ source: isService, target: isEnvConfig },
{ source: isService, target: isSecrets },
{ source: isEnvConfig, target: isService },
{ source: isSecrets, target: isService },
// DNS
{ source: isDomain, target: (t: string) => isBackend(t) || isFrontend(t) || isGateway(t) },
{ source: (t: string) => isBackend(t) || isFrontend(t) || isGateway(t), target: isDomain },
];
return rules.some((r) => r.source(srcIceType) && r.target(tgtIceType));
}