@bleedingdev/modern-js-code-tools 3.9.0-ultramodern.1 → 3.9.0-ultramodern.10

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.
Files changed (29) hide show
  1. package/bin/modern-api-check-files.mjs +4 -0
  2. package/bin/modern-api-check.mjs +4 -0
  3. package/dist/cjs/cli/microvertical-api-check.cjs +71 -0
  4. package/dist/cjs/cli/oxlint.cjs +9 -5
  5. package/dist/cjs/microvertical-api-baseline.cjs +677 -0
  6. package/dist/cjs/microvertical-api-boundary.cjs +507 -0
  7. package/dist/cjs/microvertical-api-owner.cjs +217 -0
  8. package/dist/cjs/oxlint-plugin/rules/strict-effect-api-boundaries.cjs +7 -5
  9. package/dist/cjs/strict-effect-runtime.cjs +411 -0
  10. package/dist/esm/cli/microvertical-api-check.js +33 -0
  11. package/dist/esm/cli/oxlint.js +10 -6
  12. package/dist/esm/microvertical-api-baseline.js +621 -0
  13. package/dist/esm/microvertical-api-boundary.js +449 -0
  14. package/dist/esm/microvertical-api-owner.js +162 -0
  15. package/dist/esm/oxlint-plugin/rules/strict-effect-api-boundaries.js +7 -5
  16. package/dist/esm/strict-effect-runtime.js +358 -0
  17. package/dist/esm-node/cli/microvertical-api-check.js +34 -0
  18. package/dist/esm-node/cli/oxlint.js +10 -6
  19. package/dist/esm-node/microvertical-api-baseline.js +622 -0
  20. package/dist/esm-node/microvertical-api-boundary.js +450 -0
  21. package/dist/esm-node/microvertical-api-owner.js +163 -0
  22. package/dist/esm-node/oxlint-plugin/rules/strict-effect-api-boundaries.js +7 -5
  23. package/dist/esm-node/strict-effect-runtime.js +359 -0
  24. package/dist/types/cli/microvertical-api-check.d.ts +1 -0
  25. package/dist/types/microvertical-api-baseline.d.ts +28 -0
  26. package/dist/types/microvertical-api-boundary.d.ts +32 -0
  27. package/dist/types/microvertical-api-owner.d.ts +6 -0
  28. package/dist/types/strict-effect-runtime.d.ts +10 -0
  29. package/package.json +25 -4
@@ -0,0 +1,621 @@
1
+ import node_fs from "node:fs";
2
+ import node_path from "node:path";
3
+ import { parse } from "@babel/parser";
4
+ import traverse, { Hub, NodePath } from "@babel/traverse";
5
+ import { baselinePublicIdentityIsExact } from "./microvertical-api-owner.js";
6
+ import * as __rspack_external__babel_types_6e8337dd from "@babel/types";
7
+ const consumerParserPlugins = (filePath)=>filePath.endsWith('.tsx') || filePath.endsWith('.jsx') ? [
8
+ "typescript",
9
+ 'jsx'
10
+ ] : [
11
+ "typescript"
12
+ ];
13
+ class ConsumerSyntaxError extends Error {
14
+ }
15
+ class ConsumerValidationHub extends Hub {
16
+ buildError(_node, message) {
17
+ return new ConsumerSyntaxError(message);
18
+ }
19
+ }
20
+ function parseConsumer(filePath) {
21
+ if (node_fs.statSync(filePath).size > 1000000) throw new Error(`${filePath}: consumer source exceeds 1 MB analysis budget`);
22
+ let file;
23
+ try {
24
+ file = parse(node_fs.readFileSync(filePath, 'utf8'), {
25
+ sourceType: 'module',
26
+ sourceFilename: filePath,
27
+ plugins: consumerParserPlugins(filePath)
28
+ });
29
+ } catch (error) {
30
+ 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));
31
+ throw error;
32
+ }
33
+ const program = NodePath.get({
34
+ hub: new ConsumerValidationHub(),
35
+ parentPath: void 0,
36
+ parent: file,
37
+ container: file,
38
+ key: 'program'
39
+ });
40
+ program.setContext();
41
+ traverse(file, {
42
+ AssignmentExpression (p) {
43
+ throw new ConsumerSyntaxError(`contract bindings must be immutable at ${p.node.start}`);
44
+ },
45
+ UpdateExpression (p) {
46
+ throw new ConsumerSyntaxError(`contract bindings must be immutable at ${p.node.start}`);
47
+ },
48
+ TSModuleDeclaration () {
49
+ throw new ConsumerSyntaxError('contract bindings must not be merged with namespaces');
50
+ }
51
+ }, program.scope, void 0, program);
52
+ return file;
53
+ }
54
+ const camelCaseStem = (stem)=>stem.replaceAll(/-([a-z0-9])/gu, (_match, letter)=>letter.toUpperCase());
55
+ const pascalCaseStem = (stem)=>{
56
+ const camelStem = camelCaseStem(stem);
57
+ return `${camelStem.slice(0, 1).toUpperCase()}${camelStem.slice(1)}`;
58
+ };
59
+ const identifierName = (node)=>void 0 !== node && __rspack_external__babel_types_6e8337dd.isIdentifier(node) ? node.name : void 0;
60
+ const propertyName = (node)=>{
61
+ 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);
62
+ };
63
+ const accessPath = (node)=>{
64
+ if (__rspack_external__babel_types_6e8337dd.isIdentifier(node)) return [
65
+ node.name
66
+ ];
67
+ if (__rspack_external__babel_types_6e8337dd.isMemberExpression(node) && !node.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(node.property)) {
68
+ const parent = accessPath(node.object);
69
+ return void 0 === parent ? void 0 : [
70
+ ...parent,
71
+ node.property.name
72
+ ];
73
+ }
74
+ };
75
+ const isAccessPath = (node, expected)=>accessPath(node)?.join('.') === expected.join('.');
76
+ const unwrapExpression = (expression)=>{
77
+ let current = expression;
78
+ 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;
79
+ return current;
80
+ };
81
+ const stringLiteral = (expression)=>{
82
+ if (null == expression) return;
83
+ const unwrapped = unwrapExpression(expression);
84
+ return __rspack_external__babel_types_6e8337dd.isStringLiteral(unwrapped) ? unwrapped.value : void 0;
85
+ };
86
+ const numericLiteral = (expression)=>{
87
+ if (null == expression) return;
88
+ const unwrapped = unwrapExpression(expression);
89
+ return __rspack_external__babel_types_6e8337dd.isNumericLiteral(unwrapped) ? Number(unwrapped.value) : void 0;
90
+ };
91
+ const callExpression = (expression, callee)=>{
92
+ if (null == expression) return;
93
+ const unwrapped = unwrapExpression(expression);
94
+ return __rspack_external__babel_types_6e8337dd.isCallExpression(unwrapped) && isAccessPath(unwrapped.callee, callee) ? unwrapped : void 0;
95
+ };
96
+ const localConst = (sourceFile, name)=>{
97
+ for (const item of sourceFile.program.body){
98
+ const statement = __rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(item) ? item.declaration : item;
99
+ if (!__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement) || 'const' !== statement.kind) continue;
100
+ const matches = statement.declarations.filter((declaration)=>__rspack_external__babel_types_6e8337dd.isIdentifier(declaration.id, {
101
+ name
102
+ }));
103
+ if (1 === matches.length) return matches[0];
104
+ }
105
+ };
106
+ const exportedConst = (sourceFile, name)=>{
107
+ for (const statement of sourceFile.program.body)if (__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) && 'type' !== statement.exportKind) {
108
+ if (__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement.declaration) && 'const' === statement.declaration.kind) {
109
+ const declaration = statement.declaration.declarations.find((value)=>__rspack_external__babel_types_6e8337dd.isIdentifier(value.id, {
110
+ name
111
+ }));
112
+ if (declaration) return declaration;
113
+ }
114
+ 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, {
115
+ name
116
+ }) && __rspack_external__babel_types_6e8337dd.isIdentifier(value.exported, {
117
+ name
118
+ }))) return localConst(sourceFile, name);
119
+ }
120
+ };
121
+ const resolveRelativeModulePath = (fromPath, specifier)=>{
122
+ if (!/^\.\.?\//u.test(specifier)) return;
123
+ const resolved = node_path.resolve(node_path.dirname(fromPath), specifier);
124
+ const stem = resolved.replace(/\.(?:[cm]?[jt]sx?)$/u, '');
125
+ for (const candidate of [
126
+ `${stem}.ts`,
127
+ `${stem}.tsx`,
128
+ node_path.join(stem, 'index.ts'),
129
+ node_path.join(stem, 'index.tsx')
130
+ ])if (node_fs.existsSync(candidate) && node_fs.statSync(candidate).isFile()) return candidate;
131
+ };
132
+ const createModuleReader = (root)=>{
133
+ const modules = new Map([
134
+ [
135
+ root.path,
136
+ root
137
+ ]
138
+ ]);
139
+ return (filePath)=>{
140
+ if (modules.has(filePath)) return modules.get(filePath);
141
+ if (modules.size >= 256) return;
142
+ let module;
143
+ try {
144
+ module = {
145
+ file: parseConsumer(filePath),
146
+ path: filePath
147
+ };
148
+ } catch {
149
+ module = void 0;
150
+ }
151
+ modules.set(filePath, module);
152
+ return module;
153
+ };
154
+ };
155
+ const importedBinding = (module, name)=>{
156
+ for (const statement of module.file.program.body)if (__rspack_external__babel_types_6e8337dd.isImportDeclaration(statement) && 'type' !== statement.importKind) {
157
+ for (const specifier of statement.specifiers)if (__rspack_external__babel_types_6e8337dd.isIdentifier(specifier.local, {
158
+ name
159
+ })) {
160
+ if (__rspack_external__babel_types_6e8337dd.isImportSpecifier(specifier) && 'type' !== specifier.importKind) return {
161
+ imported: propertyName(specifier.imported) ?? name,
162
+ specifier: statement.source.value
163
+ };
164
+ if (__rspack_external__babel_types_6e8337dd.isImportDefaultSpecifier(specifier)) return {
165
+ imported: 'default',
166
+ specifier: statement.source.value
167
+ };
168
+ }
169
+ }
170
+ };
171
+ const reexportedBinding = (module, name)=>{
172
+ for (const statement of module.file.program.body){
173
+ if (!__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) || 'type' === statement.exportKind) continue;
174
+ const specifier = statement.specifiers.find((value)=>__rspack_external__babel_types_6e8337dd.isExportSpecifier(value) && 'type' !== value.exportKind && propertyName(value.exported) === name);
175
+ if (void 0 !== specifier && __rspack_external__babel_types_6e8337dd.isExportSpecifier(specifier)) return {
176
+ local: specifier.local.name,
177
+ ...statement.source ? {
178
+ specifier: statement.source.value
179
+ } : {}
180
+ };
181
+ }
182
+ };
183
+ const defaultExport = (module)=>{
184
+ for (const statement of module.file.program.body){
185
+ if (!__rspack_external__babel_types_6e8337dd.isExportDefaultDeclaration(statement)) continue;
186
+ const declaration = statement.declaration;
187
+ if (__rspack_external__babel_types_6e8337dd.isIdentifier(declaration)) return declaration.name;
188
+ return __rspack_external__babel_types_6e8337dd.isExpression(declaration) ? declaration : void 0;
189
+ }
190
+ };
191
+ const resolveBinding = (module, name, scope, readModule, seen)=>{
192
+ const key = `${scope}:${module.path}#${name}`;
193
+ if (seen.has(key) || seen.size >= 512) return;
194
+ seen.add(key);
195
+ const declaration = 'export' === scope ? exportedConst(module.file, name) : localConst(module.file, name);
196
+ if (declaration?.init) return {
197
+ expression: declaration.init,
198
+ module
199
+ };
200
+ const throughModule = (specifier, imported)=>{
201
+ const resolvedPath = resolveRelativeModulePath(module.path, specifier);
202
+ const target = void 0 === resolvedPath ? void 0 : readModule(resolvedPath);
203
+ return void 0 === target ? void 0 : resolveBinding(target, imported, 'export', readModule, seen);
204
+ };
205
+ if ('local' === scope) {
206
+ const imported = importedBinding(module, name);
207
+ return void 0 === imported ? void 0 : throughModule(imported.specifier, imported.imported);
208
+ }
209
+ if ('default' === name) {
210
+ const exported = defaultExport(module);
211
+ if ('string' == typeof exported) return resolveBinding(module, exported, 'local', readModule, seen);
212
+ return void 0 === exported ? void 0 : {
213
+ expression: exported,
214
+ module
215
+ };
216
+ }
217
+ const reexported = reexportedBinding(module, name);
218
+ if (void 0 !== reexported) return void 0 === reexported.specifier ? resolveBinding(module, reexported.local, 'local', readModule, seen) : throughModule(reexported.specifier, reexported.local);
219
+ for (const statement of module.file.program.body){
220
+ if (!__rspack_external__babel_types_6e8337dd.isExportAllDeclaration(statement) || 'type' === statement.exportKind) continue;
221
+ const resolved = throughModule(statement.source.value, name);
222
+ if (void 0 !== resolved) return resolved;
223
+ }
224
+ };
225
+ const objectLiteral = (expression)=>{
226
+ if (null == expression) return;
227
+ const unwrapped = unwrapExpression(expression);
228
+ return __rspack_external__babel_types_6e8337dd.isObjectExpression(unwrapped) ? unwrapped : void 0;
229
+ };
230
+ const propertyAssignments = (properties)=>{
231
+ const assignments = new Map();
232
+ for (const property of properties){
233
+ if (!__rspack_external__babel_types_6e8337dd.isObjectProperty(property) || property.computed || property.shorthand) return;
234
+ const name = propertyName(property.key);
235
+ if (void 0 === name || assignments.has(name)) return;
236
+ assignments.set(name, property);
237
+ }
238
+ return assignments;
239
+ };
240
+ const exactCall = (expression, callee, argumentCount)=>{
241
+ const call = callExpression(expression, callee);
242
+ return call?.arguments.length === argumentCount ? call : void 0;
243
+ };
244
+ const sharedSchemaObject = (declaration, sharedSchemaName, protectedFields)=>{
245
+ if (declaration?.init == null) return;
246
+ const initializer = unwrapExpression(declaration.init);
247
+ if (__rspack_external__babel_types_6e8337dd.isIdentifier(initializer) && initializer.name === sharedSchemaName) return {
248
+ assignments: new Map(),
249
+ identity: true
250
+ };
251
+ const struct = exactCall(initializer, [
252
+ 'Schema',
253
+ 'Struct'
254
+ ], 1);
255
+ const schemaObject = objectLiteral(struct?.arguments[0]);
256
+ if (void 0 === schemaObject) return;
257
+ const spreads = schemaObject.properties.filter(__rspack_external__babel_types_6e8337dd.isSpreadElement);
258
+ const assignments = propertyAssignments(schemaObject.properties.filter((property)=>!__rspack_external__babel_types_6e8337dd.isSpreadElement(property)));
259
+ if (1 !== spreads.length || !spreads.every((spread)=>isAccessPath(spread.argument, [
260
+ sharedSchemaName,
261
+ 'fields'
262
+ ])) || void 0 === assignments || protectedFields.some((field)=>assignments.has(field))) return;
263
+ return {
264
+ assignments,
265
+ identity: false
266
+ };
267
+ };
268
+ const directCallChain = (expression)=>{
269
+ if (null == expression) return;
270
+ let current = unwrapExpression(expression);
271
+ const methods = [];
272
+ 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)){
273
+ methods.unshift({
274
+ arguments: current.arguments,
275
+ name: current.callee.property.name
276
+ });
277
+ current = unwrapExpression(current.callee.object);
278
+ }
279
+ if (!__rspack_external__babel_types_6e8337dd.isCallExpression(current)) return;
280
+ return {
281
+ base: current,
282
+ methods
283
+ };
284
+ };
285
+ const brandedStringSchemaIsExact = (declaration, brand)=>{
286
+ const initializer = declaration?.init;
287
+ if (null == initializer) return false;
288
+ const pipeCall = unwrapExpression(initializer);
289
+ 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, {
290
+ name: 'pipe'
291
+ }) || !isAccessPath(pipeCall.callee.object, [
292
+ 'Schema',
293
+ 'String'
294
+ ]) || 1 !== pipeCall.arguments.length) return false;
295
+ const brandCall = exactCall(pipeCall.arguments[0], [
296
+ 'Schema',
297
+ 'brand'
298
+ ], 1);
299
+ return stringLiteral(brandCall?.arguments[0]) === brand;
300
+ };
301
+ const importedRuntimeNames = (statement, expectedPackage)=>{
302
+ if (!__rspack_external__babel_types_6e8337dd.isImportDeclaration(statement) || statement.source.value !== expectedPackage || 'type' === statement.importKind) return [];
303
+ 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 ? [
304
+ value.local.name
305
+ ] : []);
306
+ };
307
+ const importsExactBindings = (sourceFile, expectedPackage, expectedBindings)=>{
308
+ const names = new Set(sourceFile.program.body.flatMap((statement)=>importedRuntimeNames(statement, expectedPackage)));
309
+ return expectedBindings.every((name)=>names.has(name));
310
+ };
311
+ const baselineBindings = [
312
+ 'MicroVerticalBuildMarkerSchema',
313
+ 'MicroVerticalReadinessSchema',
314
+ 'createMicroVerticalOperationContext'
315
+ ];
316
+ const importsSharedBaselinePrimitives = (sourceFile, expectedPackage)=>importsExactBindings(sourceFile, expectedPackage, baselineBindings);
317
+ const singleAddedArgument = (expression, factory, names)=>{
318
+ const chain = directCallChain(expression);
319
+ if (void 0 === chain || !isAccessPath(chain.base.callee, factory)) return;
320
+ const [method] = chain.methods;
321
+ 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;
322
+ return method.arguments[0];
323
+ };
324
+ const foundationIsExact = (declaration, stem, readinessSchemaName)=>{
325
+ const group = singleAddedArgument(declaration?.init, [
326
+ 'HttpApi',
327
+ 'make'
328
+ ], [
329
+ `${pascalCaseStem(stem)}FoundationApi`,
330
+ `${pascalCaseStem(stem)}ApiFoundation`
331
+ ]);
332
+ const endpointExpression = singleAddedArgument(group, [
333
+ 'HttpApiGroup',
334
+ 'make'
335
+ ], [
336
+ 'foundation'
337
+ ]);
338
+ const endpoint = exactCall(endpointExpression, [
339
+ 'HttpApiEndpoint',
340
+ 'get'
341
+ ], 3);
342
+ const endpointOptions = objectLiteral(endpoint?.arguments[2]);
343
+ const endpointProperties = void 0 === endpointOptions ? void 0 : propertyAssignments(endpointOptions.properties);
344
+ return void 0 !== endpoint && 'readiness' === stringLiteral(endpoint.arguments[0]) && stringLiteral(endpoint.arguments[1]) === `/${stem}/readiness` && endpointProperties?.size === 1 && identifierName(endpointProperties.get('success')?.value) === readinessSchemaName;
345
+ };
346
+ const rootComposesFoundation = (sourceFile, declaration, stem, foundationName)=>{
347
+ const chain = directCallChain(declaration?.init);
348
+ const first = chain?.methods[0];
349
+ return void 0 !== chain && isAccessPath(chain.base.callee, [
350
+ 'HttpApi',
351
+ 'make'
352
+ ]) && 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', [
353
+ 'identity'
354
+ ]))) && first?.name === 'addHttpApi' && identifierName(first.arguments[0]) === foundationName;
355
+ };
356
+ const nonEndpointCombinators = {
357
+ api: {
358
+ annotate: 2,
359
+ annotateMerge: 1,
360
+ middleware: 1
361
+ },
362
+ group: {
363
+ annotate: 2,
364
+ annotateEndpoints: 2,
365
+ annotateEndpointsMerge: 1,
366
+ annotateMerge: 1,
367
+ middleware: 1
368
+ }
369
+ };
370
+ const reachableEndpoints = (rootModule, declaration)=>{
371
+ const readModule = createModuleReader(rootModule);
372
+ const active = new Set();
373
+ const endpoints = [];
374
+ const identities = new Set();
375
+ const verbs = {
376
+ get: 'GET',
377
+ post: 'POST',
378
+ put: 'PUT',
379
+ patch: 'PATCH',
380
+ del: 'DELETE',
381
+ delete: 'DELETE',
382
+ head: 'HEAD',
383
+ options: 'OPTIONS'
384
+ };
385
+ let visits = 0;
386
+ const visit = (expression, module, kind, group = '')=>{
387
+ if (!expression) return false;
388
+ const node = unwrapExpression(expression);
389
+ if (active.has(node) || active.size >= 128 || ++visits > 2048) return false;
390
+ active.add(node);
391
+ try {
392
+ if (__rspack_external__babel_types_6e8337dd.isIdentifier(node)) {
393
+ const resolved = resolveBinding(module, node.name, 'local', readModule, new Set());
394
+ return void 0 !== resolved && visit(resolved.expression, resolved.module, kind, group);
395
+ }
396
+ if ('endpoint' === kind) {
397
+ if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node) || node.arguments.length < 2 || node.arguments.length > 3) return false;
398
+ const callee = accessPath(node.callee);
399
+ const method = callee?.length === 2 && 'HttpApiEndpoint' === callee[0] ? verbs[callee[1]] : void 0;
400
+ const name = stringLiteral(node.arguments[0]);
401
+ const routePath = stringLiteral(node.arguments[1]);
402
+ if (!method || !name || !routePath) return false;
403
+ const identity = `${group}:${name}`;
404
+ if (identities.has(identity)) return false;
405
+ identities.add(identity);
406
+ endpoints.push({
407
+ group,
408
+ name,
409
+ method,
410
+ routePath
411
+ });
412
+ return true;
413
+ }
414
+ const chain = directCallChain(node);
415
+ if (!chain || !isAccessPath(chain.base.callee, [
416
+ 'api' === kind ? 'HttpApi' : 'HttpApiGroup',
417
+ 'make'
418
+ ]) || 1 !== chain.base.arguments.length) return false;
419
+ const name = stringLiteral(chain.base.arguments[0]);
420
+ if (!name) return false;
421
+ const chainStart = endpoints.length;
422
+ const combinators = nonEndpointCombinators[kind];
423
+ return chain.methods.every((method)=>{
424
+ if ('prefix' === method.name) {
425
+ const prefix = stringLiteral(method.arguments[0]);
426
+ if (1 !== method.arguments.length || !prefix?.startsWith('/')) return false;
427
+ for(let index = chainStart; index < endpoints.length; index += 1){
428
+ const endpoint = endpoints[index];
429
+ endpoints[index] = {
430
+ ...endpoint,
431
+ routePath: `${prefix}${endpoint.routePath}`
432
+ };
433
+ }
434
+ return true;
435
+ }
436
+ const combinatorArity = combinators[method.name];
437
+ if (void 0 !== combinatorArity) return method.arguments.length === combinatorArity;
438
+ if (1 !== method.arguments.length) return false;
439
+ if ('pipe' === method.name) return 'identity' === identifierName(method.arguments[0]) && importsExactBindings(module.file, 'effect', [
440
+ 'identity'
441
+ ]);
442
+ if ('add' === method.name) return visit(method.arguments[0], module, 'api' === kind ? 'group' : 'endpoint', 'group' === kind ? name : '');
443
+ return 'api' === kind && 'addHttpApi' === method.name && visit(method.arguments[0], module, 'api');
444
+ });
445
+ } finally{
446
+ active.delete(node);
447
+ }
448
+ };
449
+ return visit(declaration?.init, rootModule, 'api') ? endpoints : void 0;
450
+ };
451
+ const operationContextFields = (property)=>{
452
+ const constructorCall = exactCall(property.value, [
453
+ 'createMicroVerticalOperationContext'
454
+ ], 1);
455
+ const input = objectLiteral(constructorCall?.arguments[0]);
456
+ return void 0 === input ? void 0 : propertyAssignments(input.properties);
457
+ };
458
+ const operationContextIdentity = (property)=>{
459
+ const fields = operationContextFields(property);
460
+ const method = stringLiteral(fields?.get('method')?.value);
461
+ const operationId = stringLiteral(fields?.get('operationId')?.value);
462
+ const routePath = stringLiteral(fields?.get('routePath')?.value);
463
+ if (fields?.size !== 3 || void 0 === method || void 0 === operationId || void 0 === routePath) return;
464
+ return {
465
+ method,
466
+ operationId,
467
+ routePath
468
+ };
469
+ };
470
+ const operationContextIsConstructed = (property, stem, propertyKey, operationPaths, endpoints)=>{
471
+ const identity = operationContextIdentity(property);
472
+ if (void 0 === identity) return false;
473
+ const { method, operationId, routePath } = identity;
474
+ if (!/^[A-Z]+$/u.test(method) || !/^\/(?!.*(?:^|\/)\.\.?\/)[^\s?#]*$/u.test(routePath)) return false;
475
+ const apiName = `${pascalCaseStem(stem)}Api`;
476
+ if ('readiness' === propertyKey && ('GET' !== method || routePath !== `/${stem}/readiness`)) return false;
477
+ 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`));
478
+ };
479
+ const operationMapIsConnected = (declaration, stem, operationPaths, endpoints)=>{
480
+ const map = objectLiteral(declaration?.init);
481
+ const properties = void 0 === map ? void 0 : propertyAssignments(map.properties);
482
+ return void 0 !== properties && properties.has('readiness') && [
483
+ ...properties
484
+ ].every(([key, property])=>operationContextIsConstructed(property, stem, key, operationPaths, endpoints));
485
+ };
486
+ const constAssertionObject = (declaration)=>{
487
+ const initializer = declaration?.init;
488
+ 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, {
489
+ name: 'const'
490
+ })) return;
491
+ return objectLiteral(initializer.expression);
492
+ };
493
+ const metadataIsExact = (declaration, expectation, endpoints)=>{
494
+ const object = constAssertionObject(declaration);
495
+ const fields = void 0 === object ? void 0 : propertyAssignments(object.properties);
496
+ const expectedFields = [
497
+ [
498
+ 'apiPrefix',
499
+ expectation.apiPrefix
500
+ ],
501
+ [
502
+ 'basePath',
503
+ expectation.basePath
504
+ ],
505
+ [
506
+ 'ownerId',
507
+ expectation.ownerId
508
+ ],
509
+ [
510
+ 'readinessPath',
511
+ expectation.readinessPath
512
+ ]
513
+ ];
514
+ if (!fields || !expectedFields.every(([field, value])=>stringLiteral(fields.get(field)?.value) === value)) return false;
515
+ const common = new Set(expectedFields.map(([field])=>field));
516
+ return [
517
+ ...fields
518
+ ].every(([field, property])=>{
519
+ if (common.has(field)) return true;
520
+ const value = stringLiteral(property.value);
521
+ if (void 0 === value) return false;
522
+ const explicit = expectation.additionalPaths[field];
523
+ if (void 0 !== explicit) return value === explicit;
524
+ if (!value.startsWith(`${expectation.apiPrefix}/`) || /[\s?#]/u.test(value) || value.split('/').some((segment)=>'.' === segment || '..' === segment)) return false;
525
+ return endpoints.some((endpoint)=>{
526
+ const route = `${expectation.apiPrefix}${endpoint.routePath}`;
527
+ return route === value || route.startsWith(`${value}/`);
528
+ });
529
+ });
530
+ };
531
+ const markerSchemaIsShared = (sourceFile, declaration)=>{
532
+ const schema = sharedSchemaObject(declaration, 'MicroVerticalBuildMarkerSchema', [
533
+ 'build',
534
+ 'buildMarker',
535
+ 'deployProfile',
536
+ 'packageName',
537
+ 'sourceRevision',
538
+ 'surface',
539
+ 'version'
540
+ ]);
541
+ if (void 0 === schema || schema.identity) return schema?.identity === true;
542
+ const brandedField = (property, brand)=>identifierName(property.value) === `${brand}Schema` && brandedStringSchemaIsExact(localConst(sourceFile, `${brand}Schema`), brand);
543
+ const validators = new Map([
544
+ [
545
+ 'appId',
546
+ (property)=>brandedField(property, 'AppId')
547
+ ],
548
+ [
549
+ 'unitId',
550
+ (property)=>brandedField(property, 'UnitId')
551
+ ],
552
+ [
553
+ 'kind',
554
+ (property)=>'microvertical-delivery-unit' === stringLiteral(exactCall(property.value, [
555
+ 'Schema',
556
+ 'Literal'
557
+ ], 1)?.arguments[0])
558
+ ],
559
+ [
560
+ 'schemaVersion',
561
+ (property)=>1 === numericLiteral(exactCall(property.value, [
562
+ 'Schema',
563
+ 'Literal'
564
+ ], 1)?.arguments[0])
565
+ ]
566
+ ]);
567
+ return [
568
+ ...schema.assignments
569
+ ].every(([field, property])=>validators.get(field)?.(property) === true);
570
+ };
571
+ const readinessSchemaIsShared = (declaration, markerSchemaName, ownerMarkerIsIdentity)=>{
572
+ const schema = sharedSchemaObject(declaration, 'MicroVerticalReadinessSchema', [
573
+ 'checks',
574
+ 'status',
575
+ 'versionSkew'
576
+ ]);
577
+ return void 0 !== schema && (schema.identity && ownerMarkerIsIdentity || 1 === schema.assignments.size && identifierName(schema.assignments.get('marker')?.value) === markerSchemaName);
578
+ };
579
+ const declarationIsIdentifier = (declaration, identifier)=>declaration?.init != null && identifierName(unwrapExpression(declaration.init)) === identifier;
580
+ const validateParsedContract = (module, stem, expectation)=>{
581
+ const sourceFile = module.file;
582
+ const exportStem = camelCaseStem(stem);
583
+ const foundationName = `${exportStem}FoundationApi`;
584
+ const markerSchemaName = `${exportStem}MarkerSchema`;
585
+ const readinessSchemaName = `${exportStem}ReadinessSchema`;
586
+ const markerDeclaration = exportedConst(sourceFile, markerSchemaName);
587
+ if (!importsExactBindings(sourceFile, expectation.effectClientPackage, [
588
+ 'HttpApi',
589
+ 'HttpApiEndpoint',
590
+ 'HttpApiGroup',
591
+ 'Schema'
592
+ ])) return 'MicroVertical root contract must import exact Effect API primitives from the framework client package';
593
+ if (!importsSharedBaselinePrimitives(sourceFile, expectation.baselinePackage)) return 'MicroVertical root contract must import exact baseline primitives from the framework baseline package';
594
+ if (!markerSchemaIsShared(sourceFile, markerDeclaration)) return 'MicroVertical root contract must consume the shared build marker schema without overriding shared fields';
595
+ if (!readinessSchemaIsShared(exportedConst(sourceFile, readinessSchemaName), markerSchemaName, declarationIsIdentifier(markerDeclaration, 'MicroVerticalBuildMarkerSchema'))) return 'MicroVertical readiness schema must consume the shared readiness schema without overriding shared fields';
596
+ if (!foundationIsExact(exportedConst(sourceFile, foundationName), stem, readinessSchemaName)) return 'MicroVertical readiness foundation API must directly compose its exact readiness endpoint and foundation identity';
597
+ if (!rootComposesFoundation(sourceFile, exportedConst(sourceFile, `${exportStem}Api`), stem, foundationName)) return 'MicroVertical root API must explicitly compose its readiness foundation API';
598
+ const endpoints = reachableEndpoints(module, exportedConst(sourceFile, `${exportStem}Api`));
599
+ if (!endpoints) return 'MicroVertical root API must compose bounded native endpoint declarations without ambiguous identities';
600
+ if (!operationMapIsConnected(exportedConst(sourceFile, `${exportStem}OperationContexts`), stem, expectation.operationPaths ?? {}, endpoints)) return 'MicroVertical operation map must construct every operation with the shared context constructor';
601
+ if (!metadataIsExact(exportedConst(sourceFile, `${exportStem}ApiContract`), expectation, endpoints)) return 'MicroVertical root contract must keep exact owner and API path metadata without forbidden fields';
602
+ };
603
+ const configuredMicroVerticalApiStem = (verticalPath, verticals)=>{
604
+ const topologyVertical = verticals.find((vertical)=>(vertical.path ?? `verticals/${vertical.id}`) === verticalPath);
605
+ const endpoint = topologyVertical?.api?.readiness?.endpoint;
606
+ return endpoint?.match(/^\/([a-z0-9]+(?:-[a-z0-9]+)*)\/readiness$/u)?.[1];
607
+ };
608
+ const microVerticalApiBaselineViolation = (stem, filePath, expectation)=>{
609
+ try {
610
+ const sourceFile = parseConsumer(filePath);
611
+ if (!baselinePublicIdentityIsExact(filePath, expectation)) return 'MicroVertical baseline imports must resolve the exact framework owner public export and schema identity';
612
+ return validateParsedContract({
613
+ file: sourceFile,
614
+ path: filePath
615
+ }, stem, expectation);
616
+ } catch (error) {
617
+ if (error instanceof ConsumerSyntaxError) return `MicroVertical root contract must be valid TypeScript syntax (${error.message})`;
618
+ throw error;
619
+ }
620
+ };
621
+ export { configuredMicroVerticalApiStem, consumerParserPlugins, microVerticalApiBaselineViolation };