@bleedingdev/modern-js-code-tools 3.9.0-ultramodern.3 → 3.9.0-ultramodern.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/modern-api-check-files.mjs +4 -0
- package/bin/modern-api-check.mjs +4 -0
- package/dist/cjs/cli/microvertical-api-check.cjs +71 -0
- package/dist/cjs/microvertical-api-baseline.cjs +526 -0
- package/dist/cjs/microvertical-api-boundary.cjs +470 -0
- package/dist/cjs/microvertical-api-owner.cjs +217 -0
- package/dist/cjs/oxlint-plugin/rules/strict-effect-api-boundaries.cjs +1 -1
- package/dist/cjs/strict-effect-runtime.cjs +43 -19
- package/dist/esm/cli/microvertical-api-check.js +33 -0
- package/dist/esm/microvertical-api-baseline.js +474 -0
- package/dist/esm/microvertical-api-boundary.js +412 -0
- package/dist/esm/microvertical-api-owner.js +162 -0
- package/dist/esm/oxlint-plugin/rules/strict-effect-api-boundaries.js +1 -1
- package/dist/esm/strict-effect-runtime.js +43 -19
- package/dist/esm-node/cli/microvertical-api-check.js +34 -0
- package/dist/esm-node/microvertical-api-baseline.js +475 -0
- package/dist/esm-node/microvertical-api-boundary.js +413 -0
- package/dist/esm-node/microvertical-api-owner.js +163 -0
- package/dist/esm-node/oxlint-plugin/rules/strict-effect-api-boundaries.js +1 -1
- package/dist/esm-node/strict-effect-runtime.js +43 -19
- package/dist/types/cli/microvertical-api-check.d.ts +1 -0
- package/dist/types/microvertical-api-baseline.d.ts +23 -0
- package/dist/types/microvertical-api-boundary.d.ts +32 -0
- package/dist/types/microvertical-api-owner.d.ts +6 -0
- package/package.json +15 -2
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import { parse } from "@babel/parser";
|
|
3
|
+
import traverse, { Hub, NodePath } from "@babel/traverse";
|
|
4
|
+
import { baselinePublicIdentityIsExact } from "./microvertical-api-owner.js";
|
|
5
|
+
import * as __rspack_external__babel_types_6e8337dd from "@babel/types";
|
|
6
|
+
class ConsumerSyntaxError extends Error {
|
|
7
|
+
}
|
|
8
|
+
class ConsumerValidationHub extends Hub {
|
|
9
|
+
buildError(_node, message) {
|
|
10
|
+
return new ConsumerSyntaxError(message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function parseConsumer(filePath) {
|
|
14
|
+
if (node_fs.statSync(filePath).size > 1000000) throw new Error(`${filePath}: consumer source exceeds 1 MB analysis budget`);
|
|
15
|
+
let file;
|
|
16
|
+
try {
|
|
17
|
+
file = parse(node_fs.readFileSync(filePath, 'utf8'), {
|
|
18
|
+
sourceType: 'module',
|
|
19
|
+
sourceFilename: filePath,
|
|
20
|
+
plugins: [
|
|
21
|
+
"typescript"
|
|
22
|
+
]
|
|
23
|
+
});
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if ('object' == typeof error && null !== error && 'code' in error && 'BABEL_PARSER_SYNTAX_ERROR' === error.code) throw new ConsumerSyntaxError(error instanceof Error ? error.message : String(error));
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
const program = NodePath.get({
|
|
29
|
+
hub: new ConsumerValidationHub(),
|
|
30
|
+
parentPath: void 0,
|
|
31
|
+
parent: file,
|
|
32
|
+
container: file,
|
|
33
|
+
key: 'program'
|
|
34
|
+
});
|
|
35
|
+
program.setContext();
|
|
36
|
+
traverse(file, {
|
|
37
|
+
AssignmentExpression (p) {
|
|
38
|
+
throw new ConsumerSyntaxError(`contract bindings must be immutable at ${p.node.start}`);
|
|
39
|
+
},
|
|
40
|
+
UpdateExpression (p) {
|
|
41
|
+
throw new ConsumerSyntaxError(`contract bindings must be immutable at ${p.node.start}`);
|
|
42
|
+
},
|
|
43
|
+
TSModuleDeclaration () {
|
|
44
|
+
throw new ConsumerSyntaxError('contract bindings must not be merged with namespaces');
|
|
45
|
+
}
|
|
46
|
+
}, program.scope, void 0, program);
|
|
47
|
+
return file;
|
|
48
|
+
}
|
|
49
|
+
const camelCaseStem = (stem)=>stem.replaceAll(/-([a-z0-9])/gu, (_match, letter)=>letter.toUpperCase());
|
|
50
|
+
const pascalCaseStem = (stem)=>{
|
|
51
|
+
const camelStem = camelCaseStem(stem);
|
|
52
|
+
return `${camelStem.slice(0, 1).toUpperCase()}${camelStem.slice(1)}`;
|
|
53
|
+
};
|
|
54
|
+
const identifierName = (node)=>void 0 !== node && __rspack_external__babel_types_6e8337dd.isIdentifier(node) ? node.name : void 0;
|
|
55
|
+
const propertyName = (node)=>{
|
|
56
|
+
if (void 0 !== node && (__rspack_external__babel_types_6e8337dd.isIdentifier(node) || __rspack_external__babel_types_6e8337dd.isStringLiteral(node) || __rspack_external__babel_types_6e8337dd.isNumericLiteral(node))) return __rspack_external__babel_types_6e8337dd.isIdentifier(node) ? node.name : String(node.value);
|
|
57
|
+
};
|
|
58
|
+
const accessPath = (node)=>{
|
|
59
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(node)) return [
|
|
60
|
+
node.name
|
|
61
|
+
];
|
|
62
|
+
if (__rspack_external__babel_types_6e8337dd.isMemberExpression(node) && !node.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(node.property)) {
|
|
63
|
+
const parent = accessPath(node.object);
|
|
64
|
+
return void 0 === parent ? void 0 : [
|
|
65
|
+
...parent,
|
|
66
|
+
node.property.name
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const isAccessPath = (node, expected)=>accessPath(node)?.join('.') === expected.join('.');
|
|
71
|
+
const unwrapExpression = (expression)=>{
|
|
72
|
+
let current = expression;
|
|
73
|
+
while(__rspack_external__babel_types_6e8337dd.isTSAsExpression(current) || __rspack_external__babel_types_6e8337dd.isParenthesizedExpression(current) || __rspack_external__babel_types_6e8337dd.isTSSatisfiesExpression(current))current = current.expression;
|
|
74
|
+
return current;
|
|
75
|
+
};
|
|
76
|
+
const stringLiteral = (expression)=>{
|
|
77
|
+
if (null == expression) return;
|
|
78
|
+
const unwrapped = unwrapExpression(expression);
|
|
79
|
+
return __rspack_external__babel_types_6e8337dd.isStringLiteral(unwrapped) ? unwrapped.value : void 0;
|
|
80
|
+
};
|
|
81
|
+
const numericLiteral = (expression)=>{
|
|
82
|
+
if (null == expression) return;
|
|
83
|
+
const unwrapped = unwrapExpression(expression);
|
|
84
|
+
return __rspack_external__babel_types_6e8337dd.isNumericLiteral(unwrapped) ? Number(unwrapped.value) : void 0;
|
|
85
|
+
};
|
|
86
|
+
const callExpression = (expression, callee)=>{
|
|
87
|
+
if (null == expression) return;
|
|
88
|
+
const unwrapped = unwrapExpression(expression);
|
|
89
|
+
return __rspack_external__babel_types_6e8337dd.isCallExpression(unwrapped) && isAccessPath(unwrapped.callee, callee) ? unwrapped : void 0;
|
|
90
|
+
};
|
|
91
|
+
const localConst = (sourceFile, name)=>{
|
|
92
|
+
for (const item of sourceFile.program.body){
|
|
93
|
+
const statement = __rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(item) ? item.declaration : item;
|
|
94
|
+
if (!__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement) || 'const' !== statement.kind) continue;
|
|
95
|
+
const matches = statement.declarations.filter((declaration)=>__rspack_external__babel_types_6e8337dd.isIdentifier(declaration.id, {
|
|
96
|
+
name
|
|
97
|
+
}));
|
|
98
|
+
if (1 === matches.length) return matches[0];
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const exportedConst = (sourceFile, name)=>{
|
|
102
|
+
for (const statement of sourceFile.program.body)if (__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) && 'type' !== statement.exportKind) {
|
|
103
|
+
if (__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement.declaration) && 'const' === statement.declaration.kind) {
|
|
104
|
+
const declaration = statement.declaration.declarations.find((value)=>__rspack_external__babel_types_6e8337dd.isIdentifier(value.id, {
|
|
105
|
+
name
|
|
106
|
+
}));
|
|
107
|
+
if (declaration) return declaration;
|
|
108
|
+
}
|
|
109
|
+
if (!statement.source && statement.specifiers.some((value)=>__rspack_external__babel_types_6e8337dd.isExportSpecifier(value) && 'type' !== value.exportKind && __rspack_external__babel_types_6e8337dd.isIdentifier(value.local, {
|
|
110
|
+
name
|
|
111
|
+
}) && __rspack_external__babel_types_6e8337dd.isIdentifier(value.exported, {
|
|
112
|
+
name
|
|
113
|
+
}))) return localConst(sourceFile, name);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const objectLiteral = (expression)=>{
|
|
117
|
+
if (null == expression) return;
|
|
118
|
+
const unwrapped = unwrapExpression(expression);
|
|
119
|
+
return __rspack_external__babel_types_6e8337dd.isObjectExpression(unwrapped) ? unwrapped : void 0;
|
|
120
|
+
};
|
|
121
|
+
const propertyAssignments = (properties)=>{
|
|
122
|
+
const assignments = new Map();
|
|
123
|
+
for (const property of properties){
|
|
124
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectProperty(property) || property.computed || property.shorthand) return;
|
|
125
|
+
const name = propertyName(property.key);
|
|
126
|
+
if (void 0 === name || assignments.has(name)) return;
|
|
127
|
+
assignments.set(name, property);
|
|
128
|
+
}
|
|
129
|
+
return assignments;
|
|
130
|
+
};
|
|
131
|
+
const exactCall = (expression, callee, argumentCount)=>{
|
|
132
|
+
const call = callExpression(expression, callee);
|
|
133
|
+
return call?.arguments.length === argumentCount ? call : void 0;
|
|
134
|
+
};
|
|
135
|
+
const sharedSchemaObject = (declaration, sharedSchemaName, protectedFields)=>{
|
|
136
|
+
if (declaration?.init == null) return;
|
|
137
|
+
const initializer = unwrapExpression(declaration.init);
|
|
138
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(initializer) && initializer.name === sharedSchemaName) return {
|
|
139
|
+
assignments: new Map(),
|
|
140
|
+
identity: true
|
|
141
|
+
};
|
|
142
|
+
const struct = exactCall(initializer, [
|
|
143
|
+
'Schema',
|
|
144
|
+
'Struct'
|
|
145
|
+
], 1);
|
|
146
|
+
const schemaObject = objectLiteral(struct?.arguments[0]);
|
|
147
|
+
if (void 0 === schemaObject) return;
|
|
148
|
+
const spreads = schemaObject.properties.filter(__rspack_external__babel_types_6e8337dd.isSpreadElement);
|
|
149
|
+
const assignments = propertyAssignments(schemaObject.properties.filter((property)=>!__rspack_external__babel_types_6e8337dd.isSpreadElement(property)));
|
|
150
|
+
if (1 !== spreads.length || !spreads.every((spread)=>isAccessPath(spread.argument, [
|
|
151
|
+
sharedSchemaName,
|
|
152
|
+
'fields'
|
|
153
|
+
])) || void 0 === assignments || protectedFields.some((field)=>assignments.has(field))) return;
|
|
154
|
+
return {
|
|
155
|
+
assignments,
|
|
156
|
+
identity: false
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
const directCallChain = (expression)=>{
|
|
160
|
+
if (null == expression) return;
|
|
161
|
+
let current = unwrapExpression(expression);
|
|
162
|
+
const methods = [];
|
|
163
|
+
while(__rspack_external__babel_types_6e8337dd.isCallExpression(current) && __rspack_external__babel_types_6e8337dd.isMemberExpression(current.callee) && !current.callee.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(current.callee.property) && !__rspack_external__babel_types_6e8337dd.isIdentifier(current.callee.object)){
|
|
164
|
+
methods.unshift({
|
|
165
|
+
arguments: current.arguments,
|
|
166
|
+
name: current.callee.property.name
|
|
167
|
+
});
|
|
168
|
+
current = unwrapExpression(current.callee.object);
|
|
169
|
+
}
|
|
170
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(current)) return;
|
|
171
|
+
return {
|
|
172
|
+
base: current,
|
|
173
|
+
methods
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const brandedStringSchemaIsExact = (declaration, brand)=>{
|
|
177
|
+
const initializer = declaration?.init;
|
|
178
|
+
if (null == initializer) return false;
|
|
179
|
+
const pipeCall = unwrapExpression(initializer);
|
|
180
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(pipeCall) || !__rspack_external__babel_types_6e8337dd.isMemberExpression(pipeCall.callee) || pipeCall.callee.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(pipeCall.callee.property, {
|
|
181
|
+
name: 'pipe'
|
|
182
|
+
}) || !isAccessPath(pipeCall.callee.object, [
|
|
183
|
+
'Schema',
|
|
184
|
+
'String'
|
|
185
|
+
]) || 1 !== pipeCall.arguments.length) return false;
|
|
186
|
+
const brandCall = exactCall(pipeCall.arguments[0], [
|
|
187
|
+
'Schema',
|
|
188
|
+
'brand'
|
|
189
|
+
], 1);
|
|
190
|
+
return stringLiteral(brandCall?.arguments[0]) === brand;
|
|
191
|
+
};
|
|
192
|
+
const importedRuntimeNames = (statement, expectedPackage)=>{
|
|
193
|
+
if (!__rspack_external__babel_types_6e8337dd.isImportDeclaration(statement) || statement.source.value !== expectedPackage || 'type' === statement.importKind) return [];
|
|
194
|
+
return statement.specifiers.flatMap((value)=>__rspack_external__babel_types_6e8337dd.isImportSpecifier(value) && 'type' !== value.importKind && __rspack_external__babel_types_6e8337dd.isIdentifier(value.imported) && value.imported.name === value.local.name ? [
|
|
195
|
+
value.local.name
|
|
196
|
+
] : []);
|
|
197
|
+
};
|
|
198
|
+
const importsExactBindings = (sourceFile, expectedPackage, expectedBindings)=>{
|
|
199
|
+
const names = new Set(sourceFile.program.body.flatMap((statement)=>importedRuntimeNames(statement, expectedPackage)));
|
|
200
|
+
return expectedBindings.every((name)=>names.has(name));
|
|
201
|
+
};
|
|
202
|
+
const baselineBindings = [
|
|
203
|
+
'MicroVerticalBuildMarkerSchema',
|
|
204
|
+
'MicroVerticalReadinessSchema',
|
|
205
|
+
'createMicroVerticalOperationContext'
|
|
206
|
+
];
|
|
207
|
+
const importsSharedBaselinePrimitives = (sourceFile, expectedPackage)=>importsExactBindings(sourceFile, expectedPackage, baselineBindings);
|
|
208
|
+
const singleAddedArgument = (expression, factory, names)=>{
|
|
209
|
+
const chain = directCallChain(expression);
|
|
210
|
+
if (void 0 === chain || !isAccessPath(chain.base.callee, factory)) return;
|
|
211
|
+
const [method] = chain.methods;
|
|
212
|
+
if (1 !== chain.base.arguments.length || !names.includes(stringLiteral(chain.base.arguments[0]) ?? '') || 1 !== chain.methods.length || method?.name !== 'add' || 1 !== method.arguments.length) return;
|
|
213
|
+
return method.arguments[0];
|
|
214
|
+
};
|
|
215
|
+
const foundationIsExact = (declaration, stem, readinessSchemaName)=>{
|
|
216
|
+
const group = singleAddedArgument(declaration?.init, [
|
|
217
|
+
'HttpApi',
|
|
218
|
+
'make'
|
|
219
|
+
], [
|
|
220
|
+
`${pascalCaseStem(stem)}FoundationApi`,
|
|
221
|
+
`${pascalCaseStem(stem)}ApiFoundation`
|
|
222
|
+
]);
|
|
223
|
+
const endpointExpression = singleAddedArgument(group, [
|
|
224
|
+
'HttpApiGroup',
|
|
225
|
+
'make'
|
|
226
|
+
], [
|
|
227
|
+
'foundation'
|
|
228
|
+
]);
|
|
229
|
+
const endpoint = exactCall(endpointExpression, [
|
|
230
|
+
'HttpApiEndpoint',
|
|
231
|
+
'get'
|
|
232
|
+
], 3);
|
|
233
|
+
const endpointOptions = objectLiteral(endpoint?.arguments[2]);
|
|
234
|
+
const endpointProperties = void 0 === endpointOptions ? void 0 : propertyAssignments(endpointOptions.properties);
|
|
235
|
+
return void 0 !== endpoint && 'readiness' === stringLiteral(endpoint.arguments[0]) && stringLiteral(endpoint.arguments[1]) === `/${stem}/readiness` && endpointProperties?.size === 1 && identifierName(endpointProperties.get('success')?.value) === readinessSchemaName;
|
|
236
|
+
};
|
|
237
|
+
const rootComposesFoundation = (sourceFile, declaration, stem, foundationName)=>{
|
|
238
|
+
const chain = directCallChain(declaration?.init);
|
|
239
|
+
const first = chain?.methods[0];
|
|
240
|
+
return void 0 !== chain && isAccessPath(chain.base.callee, [
|
|
241
|
+
'HttpApi',
|
|
242
|
+
'make'
|
|
243
|
+
]) && 1 === chain.base.arguments.length && stringLiteral(chain.base.arguments[0]) === `${pascalCaseStem(stem)}Api` && chain.methods.length > 0 && chain.methods.every((method, index)=>1 === method.arguments.length && ('add' === method.name || 'addHttpApi' === method.name || index === chain.methods.length - 1 && 'pipe' === method.name && 'identity' === identifierName(method.arguments[0]) && importsExactBindings(sourceFile, 'effect', [
|
|
244
|
+
'identity'
|
|
245
|
+
]))) && first?.name === 'addHttpApi' && identifierName(first.arguments[0]) === foundationName;
|
|
246
|
+
};
|
|
247
|
+
const reachableEndpoints = (sourceFile, declaration)=>{
|
|
248
|
+
const active = new Set();
|
|
249
|
+
const endpoints = [];
|
|
250
|
+
const identities = new Set();
|
|
251
|
+
const verbs = {
|
|
252
|
+
get: 'GET',
|
|
253
|
+
post: 'POST',
|
|
254
|
+
put: 'PUT',
|
|
255
|
+
patch: 'PATCH',
|
|
256
|
+
del: 'DELETE',
|
|
257
|
+
delete: 'DELETE',
|
|
258
|
+
head: 'HEAD',
|
|
259
|
+
options: 'OPTIONS'
|
|
260
|
+
};
|
|
261
|
+
let visits = 0;
|
|
262
|
+
const visit = (expression, kind, group = '')=>{
|
|
263
|
+
if (!expression) return false;
|
|
264
|
+
const node = unwrapExpression(expression);
|
|
265
|
+
if (active.has(node) || active.size >= 128 || ++visits > 2048) return false;
|
|
266
|
+
active.add(node);
|
|
267
|
+
try {
|
|
268
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(node)) return visit(localConst(sourceFile, node.name)?.init, kind, group);
|
|
269
|
+
if ('endpoint' === kind) {
|
|
270
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node) || node.arguments.length < 2 || node.arguments.length > 3) return false;
|
|
271
|
+
const callee = accessPath(node.callee);
|
|
272
|
+
const method = callee?.length === 2 && 'HttpApiEndpoint' === callee[0] ? verbs[callee[1]] : void 0;
|
|
273
|
+
const name = stringLiteral(node.arguments[0]);
|
|
274
|
+
const routePath = stringLiteral(node.arguments[1]);
|
|
275
|
+
if (!method || !name || !routePath) return false;
|
|
276
|
+
const identity = `${group}:${name}`;
|
|
277
|
+
if (identities.has(identity)) return false;
|
|
278
|
+
identities.add(identity);
|
|
279
|
+
endpoints.push({
|
|
280
|
+
group,
|
|
281
|
+
name,
|
|
282
|
+
method,
|
|
283
|
+
routePath
|
|
284
|
+
});
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
const chain = directCallChain(node);
|
|
288
|
+
if (!chain || !isAccessPath(chain.base.callee, [
|
|
289
|
+
'api' === kind ? 'HttpApi' : 'HttpApiGroup',
|
|
290
|
+
'make'
|
|
291
|
+
]) || 1 !== chain.base.arguments.length) return false;
|
|
292
|
+
const name = stringLiteral(chain.base.arguments[0]);
|
|
293
|
+
if (!name) return false;
|
|
294
|
+
return chain.methods.every((method)=>{
|
|
295
|
+
if (1 !== method.arguments.length) return false;
|
|
296
|
+
if ('pipe' === method.name) return 'identity' === identifierName(method.arguments[0]) && importsExactBindings(sourceFile, 'effect', [
|
|
297
|
+
'identity'
|
|
298
|
+
]);
|
|
299
|
+
if ('add' === method.name) return visit(method.arguments[0], 'api' === kind ? 'group' : 'endpoint', 'group' === kind ? name : '');
|
|
300
|
+
return 'api' === kind && 'addHttpApi' === method.name && visit(method.arguments[0], 'api');
|
|
301
|
+
});
|
|
302
|
+
} finally{
|
|
303
|
+
active.delete(node);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
return visit(declaration?.init, 'api') ? endpoints : void 0;
|
|
307
|
+
};
|
|
308
|
+
const operationContextFields = (property)=>{
|
|
309
|
+
const constructorCall = exactCall(property.value, [
|
|
310
|
+
'createMicroVerticalOperationContext'
|
|
311
|
+
], 1);
|
|
312
|
+
const input = objectLiteral(constructorCall?.arguments[0]);
|
|
313
|
+
return void 0 === input ? void 0 : propertyAssignments(input.properties);
|
|
314
|
+
};
|
|
315
|
+
const operationContextIdentity = (property)=>{
|
|
316
|
+
const fields = operationContextFields(property);
|
|
317
|
+
const method = stringLiteral(fields?.get('method')?.value);
|
|
318
|
+
const operationId = stringLiteral(fields?.get('operationId')?.value);
|
|
319
|
+
const routePath = stringLiteral(fields?.get('routePath')?.value);
|
|
320
|
+
if (fields?.size !== 3 || void 0 === method || void 0 === operationId || void 0 === routePath) return;
|
|
321
|
+
return {
|
|
322
|
+
method,
|
|
323
|
+
operationId,
|
|
324
|
+
routePath
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
const operationContextIsConstructed = (property, stem, propertyKey, operationPaths, endpoints)=>{
|
|
328
|
+
const identity = operationContextIdentity(property);
|
|
329
|
+
if (void 0 === identity) return false;
|
|
330
|
+
const { method, operationId, routePath } = identity;
|
|
331
|
+
if (!/^[A-Z]+$/u.test(method) || !/^\/(?!.*(?:^|\/)\.\.?\/)[^\s?#]*$/u.test(routePath)) return false;
|
|
332
|
+
const apiName = `${pascalCaseStem(stem)}Api`;
|
|
333
|
+
if ('readiness' === propertyKey && ('GET' !== method || routePath !== `/${stem}/readiness`)) return false;
|
|
334
|
+
return operationId === `${apiName}:${routePath}` || operationPaths[operationId] === routePath || endpoints.some((endpoint)=>endpoint.name === propertyKey && endpoint.method === method && endpoint.routePath === routePath && (operationId === `${apiName}:${endpoint.group}:${propertyKey}` || 'readiness' === propertyKey && operationId === `${apiName}:${camelCaseStem(stem)}:readiness`));
|
|
335
|
+
};
|
|
336
|
+
const operationMapIsConnected = (declaration, stem, operationPaths, endpoints)=>{
|
|
337
|
+
const map = objectLiteral(declaration?.init);
|
|
338
|
+
const properties = void 0 === map ? void 0 : propertyAssignments(map.properties);
|
|
339
|
+
return void 0 !== properties && properties.has('readiness') && [
|
|
340
|
+
...properties
|
|
341
|
+
].every(([key, property])=>operationContextIsConstructed(property, stem, key, operationPaths, endpoints));
|
|
342
|
+
};
|
|
343
|
+
const constAssertionObject = (declaration)=>{
|
|
344
|
+
const initializer = declaration?.init;
|
|
345
|
+
if (null == initializer || !__rspack_external__babel_types_6e8337dd.isTSAsExpression(initializer) || !__rspack_external__babel_types_6e8337dd.isTSTypeReference(initializer.typeAnnotation) || !__rspack_external__babel_types_6e8337dd.isIdentifier(initializer.typeAnnotation.typeName, {
|
|
346
|
+
name: 'const'
|
|
347
|
+
})) return;
|
|
348
|
+
return objectLiteral(initializer.expression);
|
|
349
|
+
};
|
|
350
|
+
const metadataIsExact = (declaration, expectation, endpoints)=>{
|
|
351
|
+
const object = constAssertionObject(declaration);
|
|
352
|
+
const fields = void 0 === object ? void 0 : propertyAssignments(object.properties);
|
|
353
|
+
const expectedFields = [
|
|
354
|
+
[
|
|
355
|
+
'apiPrefix',
|
|
356
|
+
expectation.apiPrefix
|
|
357
|
+
],
|
|
358
|
+
[
|
|
359
|
+
'basePath',
|
|
360
|
+
expectation.basePath
|
|
361
|
+
],
|
|
362
|
+
[
|
|
363
|
+
'ownerId',
|
|
364
|
+
expectation.ownerId
|
|
365
|
+
],
|
|
366
|
+
[
|
|
367
|
+
'readinessPath',
|
|
368
|
+
expectation.readinessPath
|
|
369
|
+
]
|
|
370
|
+
];
|
|
371
|
+
if (!fields || !expectedFields.every(([field, value])=>stringLiteral(fields.get(field)?.value) === value)) return false;
|
|
372
|
+
const common = new Set(expectedFields.map(([field])=>field));
|
|
373
|
+
return [
|
|
374
|
+
...fields
|
|
375
|
+
].every(([field, property])=>{
|
|
376
|
+
if (common.has(field)) return true;
|
|
377
|
+
const value = stringLiteral(property.value);
|
|
378
|
+
if (void 0 === value) return false;
|
|
379
|
+
const explicit = expectation.additionalPaths[field];
|
|
380
|
+
if (void 0 !== explicit) return value === explicit;
|
|
381
|
+
if (!value.startsWith(`${expectation.apiPrefix}/`) || /[\s?#]/u.test(value) || value.split('/').some((segment)=>'.' === segment || '..' === segment)) return false;
|
|
382
|
+
return endpoints.some((endpoint)=>{
|
|
383
|
+
const route = `${expectation.apiPrefix}${endpoint.routePath}`;
|
|
384
|
+
return route === value || route.startsWith(`${value}/`);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
};
|
|
388
|
+
const markerSchemaIsShared = (sourceFile, declaration)=>{
|
|
389
|
+
const schema = sharedSchemaObject(declaration, 'MicroVerticalBuildMarkerSchema', [
|
|
390
|
+
'build',
|
|
391
|
+
'buildMarker',
|
|
392
|
+
'deployProfile',
|
|
393
|
+
'packageName',
|
|
394
|
+
'sourceRevision',
|
|
395
|
+
'surface',
|
|
396
|
+
'version'
|
|
397
|
+
]);
|
|
398
|
+
if (void 0 === schema || schema.identity) return schema?.identity === true;
|
|
399
|
+
const brandedField = (property, brand)=>identifierName(property.value) === `${brand}Schema` && brandedStringSchemaIsExact(localConst(sourceFile, `${brand}Schema`), brand);
|
|
400
|
+
const validators = new Map([
|
|
401
|
+
[
|
|
402
|
+
'appId',
|
|
403
|
+
(property)=>brandedField(property, 'AppId')
|
|
404
|
+
],
|
|
405
|
+
[
|
|
406
|
+
'unitId',
|
|
407
|
+
(property)=>brandedField(property, 'UnitId')
|
|
408
|
+
],
|
|
409
|
+
[
|
|
410
|
+
'kind',
|
|
411
|
+
(property)=>'microvertical-delivery-unit' === stringLiteral(exactCall(property.value, [
|
|
412
|
+
'Schema',
|
|
413
|
+
'Literal'
|
|
414
|
+
], 1)?.arguments[0])
|
|
415
|
+
],
|
|
416
|
+
[
|
|
417
|
+
'schemaVersion',
|
|
418
|
+
(property)=>1 === numericLiteral(exactCall(property.value, [
|
|
419
|
+
'Schema',
|
|
420
|
+
'Literal'
|
|
421
|
+
], 1)?.arguments[0])
|
|
422
|
+
]
|
|
423
|
+
]);
|
|
424
|
+
return [
|
|
425
|
+
...schema.assignments
|
|
426
|
+
].every(([field, property])=>validators.get(field)?.(property) === true);
|
|
427
|
+
};
|
|
428
|
+
const readinessSchemaIsShared = (declaration, markerSchemaName, ownerMarkerIsIdentity)=>{
|
|
429
|
+
const schema = sharedSchemaObject(declaration, 'MicroVerticalReadinessSchema', [
|
|
430
|
+
'checks',
|
|
431
|
+
'status',
|
|
432
|
+
'versionSkew'
|
|
433
|
+
]);
|
|
434
|
+
return void 0 !== schema && (schema.identity && ownerMarkerIsIdentity || 1 === schema.assignments.size && identifierName(schema.assignments.get('marker')?.value) === markerSchemaName);
|
|
435
|
+
};
|
|
436
|
+
const declarationIsIdentifier = (declaration, identifier)=>declaration?.init != null && identifierName(unwrapExpression(declaration.init)) === identifier;
|
|
437
|
+
const validateParsedContract = (sourceFile, stem, expectation)=>{
|
|
438
|
+
const exportStem = camelCaseStem(stem);
|
|
439
|
+
const foundationName = `${exportStem}FoundationApi`;
|
|
440
|
+
const markerSchemaName = `${exportStem}MarkerSchema`;
|
|
441
|
+
const readinessSchemaName = `${exportStem}ReadinessSchema`;
|
|
442
|
+
const markerDeclaration = exportedConst(sourceFile, markerSchemaName);
|
|
443
|
+
if (!importsExactBindings(sourceFile, expectation.effectClientPackage, [
|
|
444
|
+
'HttpApi',
|
|
445
|
+
'HttpApiEndpoint',
|
|
446
|
+
'HttpApiGroup',
|
|
447
|
+
'Schema'
|
|
448
|
+
])) return 'MicroVertical root contract must import exact Effect API primitives from the framework client package';
|
|
449
|
+
if (!importsSharedBaselinePrimitives(sourceFile, expectation.baselinePackage)) return 'MicroVertical root contract must import exact baseline primitives from the framework baseline package';
|
|
450
|
+
if (!markerSchemaIsShared(sourceFile, markerDeclaration)) return 'MicroVertical root contract must consume the shared build marker schema without overriding shared fields';
|
|
451
|
+
if (!readinessSchemaIsShared(exportedConst(sourceFile, readinessSchemaName), markerSchemaName, declarationIsIdentifier(markerDeclaration, 'MicroVerticalBuildMarkerSchema'))) return 'MicroVertical readiness schema must consume the shared readiness schema without overriding shared fields';
|
|
452
|
+
if (!foundationIsExact(exportedConst(sourceFile, foundationName), stem, readinessSchemaName)) return 'MicroVertical readiness foundation API must directly compose its exact readiness endpoint and foundation identity';
|
|
453
|
+
if (!rootComposesFoundation(sourceFile, exportedConst(sourceFile, `${exportStem}Api`), stem, foundationName)) return 'MicroVertical root API must explicitly compose its readiness foundation API';
|
|
454
|
+
const endpoints = reachableEndpoints(sourceFile, exportedConst(sourceFile, `${exportStem}Api`));
|
|
455
|
+
if (!endpoints) return 'MicroVertical root API must compose bounded native endpoint declarations without ambiguous identities';
|
|
456
|
+
if (!operationMapIsConnected(exportedConst(sourceFile, `${exportStem}OperationContexts`), stem, expectation.operationPaths ?? {}, endpoints)) return 'MicroVertical operation map must construct every operation with the shared context constructor';
|
|
457
|
+
if (!metadataIsExact(exportedConst(sourceFile, `${exportStem}ApiContract`), expectation, endpoints)) return 'MicroVertical root contract must keep exact owner and API path metadata without forbidden fields';
|
|
458
|
+
};
|
|
459
|
+
const configuredMicroVerticalApiStem = (verticalPath, verticals)=>{
|
|
460
|
+
const topologyVertical = verticals.find((vertical)=>(vertical.path ?? `verticals/${vertical.id}`) === verticalPath);
|
|
461
|
+
const endpoint = topologyVertical?.api?.readiness?.endpoint;
|
|
462
|
+
return endpoint?.match(/^\/([a-z0-9]+(?:-[a-z0-9]+)*)\/readiness$/u)?.[1];
|
|
463
|
+
};
|
|
464
|
+
const microVerticalApiBaselineViolation = (stem, filePath, expectation)=>{
|
|
465
|
+
try {
|
|
466
|
+
const sourceFile = parseConsumer(filePath);
|
|
467
|
+
if (!baselinePublicIdentityIsExact(filePath, expectation)) return 'MicroVertical baseline imports must resolve the exact framework owner public export and schema identity';
|
|
468
|
+
return validateParsedContract(sourceFile, stem, expectation);
|
|
469
|
+
} catch (error) {
|
|
470
|
+
if (error instanceof ConsumerSyntaxError) return `MicroVertical root contract must be valid TypeScript syntax (${error.message})`;
|
|
471
|
+
throw error;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
export { configuredMicroVerticalApiStem, microVerticalApiBaselineViolation };
|