@bleedingdev/modern-js-code-tools 3.8.3-ultramodern.6 → 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.
- 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/cli/oxlint.cjs +9 -5
- package/dist/cjs/microvertical-api-baseline.cjs +677 -0
- package/dist/cjs/microvertical-api-boundary.cjs +507 -0
- package/dist/cjs/microvertical-api-owner.cjs +217 -0
- package/dist/cjs/oxlint-plugin/rules/strict-effect-api-boundaries.cjs +7 -5
- package/dist/cjs/strict-effect-runtime.cjs +411 -0
- package/dist/esm/cli/microvertical-api-check.js +33 -0
- package/dist/esm/cli/oxlint.js +10 -6
- package/dist/esm/microvertical-api-baseline.js +621 -0
- package/dist/esm/microvertical-api-boundary.js +449 -0
- package/dist/esm/microvertical-api-owner.js +162 -0
- package/dist/esm/oxlint-plugin/rules/strict-effect-api-boundaries.js +7 -5
- package/dist/esm/strict-effect-runtime.js +358 -0
- package/dist/esm-node/cli/microvertical-api-check.js +34 -0
- package/dist/esm-node/cli/oxlint.js +10 -6
- package/dist/esm-node/microvertical-api-baseline.js +622 -0
- package/dist/esm-node/microvertical-api-boundary.js +450 -0
- package/dist/esm-node/microvertical-api-owner.js +163 -0
- package/dist/esm-node/oxlint-plugin/rules/strict-effect-api-boundaries.js +7 -5
- package/dist/esm-node/strict-effect-runtime.js +359 -0
- package/dist/types/cli/microvertical-api-check.d.ts +1 -0
- package/dist/types/microvertical-api-baseline.d.ts +28 -0
- package/dist/types/microvertical-api-boundary.d.ts +32 -0
- package/dist/types/microvertical-api-owner.d.ts +6 -0
- package/dist/types/strict-effect-runtime.d.ts +10 -0
- package/package.json +26 -5
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_fs from "node:fs";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { parse } from "@babel/parser";
|
|
5
|
+
import traverse, { Hub, NodePath } from "@babel/traverse";
|
|
6
|
+
import * as __rspack_external__babel_types_6e8337dd from "@babel/types";
|
|
7
|
+
const edge = '@modern-js/bff-effect/effect-edge';
|
|
8
|
+
const nodeRuntime = '@modern-js/bff-effect/effect';
|
|
9
|
+
const sharedRuntime = /^@[^/]+\/shared-contracts\/server\/effect-bff-runtime$/u;
|
|
10
|
+
const failure = 'Generated API entries must export defineEffectBff(...) or the server-only shared Effect BFF assembly helper with an explicitly composed handler Layer and an unshadowed executable root; entries must implement handlers through HttpApiBuilder.group.';
|
|
11
|
+
const invalidSources = new WeakSet();
|
|
12
|
+
function invalidSource(message) {
|
|
13
|
+
const error = new Error(message);
|
|
14
|
+
invalidSources.add(error);
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
class SourceValidationHub extends Hub {
|
|
18
|
+
buildError(_node, message) {
|
|
19
|
+
return invalidSource(message);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function createEffectApiImportResolver(filename) {
|
|
23
|
+
const directory = node_fs.realpathSync(node_path.dirname(filename));
|
|
24
|
+
const owner = node_fs.realpathSync(node_path.resolve(directory, '..'));
|
|
25
|
+
const resolve = (from)=>(specifier)=>{
|
|
26
|
+
if (!specifier.startsWith('.')) return;
|
|
27
|
+
const target = node_path.resolve(node_path.dirname(from), specifier);
|
|
28
|
+
if (!target.startsWith(`${owner}${node_path.sep}`)) return;
|
|
29
|
+
for (const candidate of [
|
|
30
|
+
target,
|
|
31
|
+
`${target}.ts`,
|
|
32
|
+
`${target}.mts`
|
|
33
|
+
])try {
|
|
34
|
+
const real = node_fs.realpathSync(candidate);
|
|
35
|
+
if (!real.startsWith(`${owner}${node_path.sep}`) || node_fs.statSync(real).size > 1000000) return;
|
|
36
|
+
return {
|
|
37
|
+
id: real,
|
|
38
|
+
source: node_fs.readFileSync(real, 'utf8'),
|
|
39
|
+
resolveImport: resolve(real)
|
|
40
|
+
};
|
|
41
|
+
} catch {}
|
|
42
|
+
};
|
|
43
|
+
return resolve(node_path.join(directory, node_path.basename(filename)));
|
|
44
|
+
}
|
|
45
|
+
function strictEffectRuntimeTopologyViolation(source, resolveImport) {
|
|
46
|
+
const modules = new Map();
|
|
47
|
+
const owners = new Map();
|
|
48
|
+
const paths = new Map();
|
|
49
|
+
const mutated = new Set();
|
|
50
|
+
const load = (input)=>{
|
|
51
|
+
const existing = modules.get(input.id);
|
|
52
|
+
if (existing) return existing;
|
|
53
|
+
if (modules.size >= 64 || input.source.length > 1000000) throw invalidSource('API source budget exceeded');
|
|
54
|
+
let file;
|
|
55
|
+
try {
|
|
56
|
+
file = parse(input.source, {
|
|
57
|
+
sourceType: 'module',
|
|
58
|
+
sourceFilename: input.id,
|
|
59
|
+
plugins: [
|
|
60
|
+
"typescript"
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
} catch (cause) {
|
|
64
|
+
if ('object' == typeof cause && null !== cause && 'code' in cause && 'BABEL_PARSER_SYNTAX_ERROR' === cause.code && 'reasonCode' in cause && 'string' == typeof cause.reasonCode) throw invalidSource('Invalid API syntax');
|
|
65
|
+
throw cause;
|
|
66
|
+
}
|
|
67
|
+
const module = {
|
|
68
|
+
...input,
|
|
69
|
+
file
|
|
70
|
+
};
|
|
71
|
+
modules.set(input.id, module);
|
|
72
|
+
const program = NodePath.get({
|
|
73
|
+
hub: new SourceValidationHub(),
|
|
74
|
+
parentPath: void 0,
|
|
75
|
+
parent: file,
|
|
76
|
+
container: file,
|
|
77
|
+
key: 'program'
|
|
78
|
+
});
|
|
79
|
+
program.setContext();
|
|
80
|
+
traverse(file, {
|
|
81
|
+
enter (nodePath) {
|
|
82
|
+
paths.set(nodePath.node, nodePath);
|
|
83
|
+
owners.set(nodePath.node, module);
|
|
84
|
+
if (nodePath.isAssignmentExpression() || nodePath.isUpdateExpression() || nodePath.isUnaryExpression({
|
|
85
|
+
operator: 'delete'
|
|
86
|
+
})) {
|
|
87
|
+
let target = nodePath.isAssignmentExpression() ? nodePath.node.left : nodePath.node.argument;
|
|
88
|
+
while(__rspack_external__babel_types_6e8337dd.isMemberExpression(target))target = target.object;
|
|
89
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(target)) {
|
|
90
|
+
const binding = nodePath.scope.getBinding(target.name);
|
|
91
|
+
if (binding) mutated.add(binding);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (nodePath.isTSModuleDeclaration() && __rspack_external__babel_types_6e8337dd.isIdentifier(nodePath.node.id)) {
|
|
95
|
+
const binding = nodePath.scope.getBinding(nodePath.node.id.name);
|
|
96
|
+
if (binding) mutated.add(binding);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}, program.scope, void 0, program);
|
|
100
|
+
return module;
|
|
101
|
+
};
|
|
102
|
+
try {
|
|
103
|
+
const entry = load({
|
|
104
|
+
id: '/entry.ts',
|
|
105
|
+
source,
|
|
106
|
+
resolveImport
|
|
107
|
+
});
|
|
108
|
+
const unwrap = (node)=>{
|
|
109
|
+
while(__rspack_external__babel_types_6e8337dd.isParenthesizedExpression(node) || __rspack_external__babel_types_6e8337dd.isTSSatisfiesExpression(node) || __rspack_external__babel_types_6e8337dd.isTSAsExpression(node) || __rspack_external__babel_types_6e8337dd.isTSTypeAssertion(node) || __rspack_external__babel_types_6e8337dd.isTSNonNullExpression(node))node = node.expression;
|
|
110
|
+
return node;
|
|
111
|
+
};
|
|
112
|
+
const binding = (node)=>{
|
|
113
|
+
node = unwrap(node);
|
|
114
|
+
if (!__rspack_external__babel_types_6e8337dd.isIdentifier(node)) return;
|
|
115
|
+
const nodePath = paths.get(node);
|
|
116
|
+
if (!nodePath) throw new Error('Missing API lexical scope');
|
|
117
|
+
const value = nodePath.scope.getBinding(node.name);
|
|
118
|
+
return value?.constant && !mutated.has(value) ? value : void 0;
|
|
119
|
+
};
|
|
120
|
+
const declaration = (node)=>binding(node)?.path.node;
|
|
121
|
+
const imported = (node)=>{
|
|
122
|
+
const value = binding(node);
|
|
123
|
+
const decl = value?.path.node;
|
|
124
|
+
if (!decl || !__rspack_external__babel_types_6e8337dd.isImportSpecifier(decl) && !__rspack_external__babel_types_6e8337dd.isImportNamespaceSpecifier(decl) || __rspack_external__babel_types_6e8337dd.isImportSpecifier(decl) && 'type' === decl.importKind) return;
|
|
125
|
+
const statement = value.path.parent;
|
|
126
|
+
if (!__rspack_external__babel_types_6e8337dd.isImportDeclaration(statement) || 'type' === statement.importKind) return;
|
|
127
|
+
return {
|
|
128
|
+
namespace: __rspack_external__babel_types_6e8337dd.isImportNamespaceSpecifier(decl),
|
|
129
|
+
name: __rspack_external__babel_types_6e8337dd.isImportNamespaceSpecifier(decl) ? '*' : __rspack_external__babel_types_6e8337dd.isIdentifier(decl.imported) ? decl.imported.name : decl.imported.value,
|
|
130
|
+
specifier: statement.source.value
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const namespaceSources = {
|
|
134
|
+
HttpApi: [
|
|
135
|
+
edge,
|
|
136
|
+
'effect/unstable/httpapi'
|
|
137
|
+
],
|
|
138
|
+
HttpApiBuilder: [
|
|
139
|
+
edge,
|
|
140
|
+
'effect/unstable/httpapi'
|
|
141
|
+
],
|
|
142
|
+
HttpRouter: [
|
|
143
|
+
edge,
|
|
144
|
+
'effect/unstable/http'
|
|
145
|
+
]
|
|
146
|
+
};
|
|
147
|
+
const native = (node, name, sources)=>{
|
|
148
|
+
const value = imported(node);
|
|
149
|
+
if (!value) return false;
|
|
150
|
+
const importedNameMatches = value.namespace ? value.specifier === `effect/${name}` : value.name === name && value.specifier !== `effect/${name}`;
|
|
151
|
+
return importedNameMatches && (sources ?? namespaceSources[name] ?? [
|
|
152
|
+
edge
|
|
153
|
+
]).includes(value.specifier);
|
|
154
|
+
};
|
|
155
|
+
const method = (node, namespace, member, sources)=>{
|
|
156
|
+
node = unwrap(node);
|
|
157
|
+
return __rspack_external__babel_types_6e8337dd.isMemberExpression(node) && !node.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(node.property, {
|
|
158
|
+
name: member
|
|
159
|
+
}) && native(node.object, namespace, sources);
|
|
160
|
+
};
|
|
161
|
+
const initialized = (node)=>{
|
|
162
|
+
const value = binding(node);
|
|
163
|
+
return value?.kind === 'const' && __rspack_external__babel_types_6e8337dd.isVariableDeclarator(value.path.node) ? value.path.node.init ?? void 0 : void 0;
|
|
164
|
+
};
|
|
165
|
+
const moduleFor = (node)=>{
|
|
166
|
+
const value = imported(node);
|
|
167
|
+
if (!value) return;
|
|
168
|
+
const input = owners.get(node)?.resolveImport?.(value.specifier);
|
|
169
|
+
return input ? {
|
|
170
|
+
module: load(input),
|
|
171
|
+
name: value.name
|
|
172
|
+
} : void 0;
|
|
173
|
+
};
|
|
174
|
+
const exported = (module, name)=>{
|
|
175
|
+
for (const statement of module.file.program.body)if (__rspack_external__babel_types_6e8337dd.isExportNamedDeclaration(statement) && 'type' !== statement.exportKind) {
|
|
176
|
+
if (__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement.declaration)) {
|
|
177
|
+
for (const decl of statement.declaration.declarations)if (__rspack_external__babel_types_6e8337dd.isIdentifier(decl.id, {
|
|
178
|
+
name
|
|
179
|
+
})) return decl.id;
|
|
180
|
+
}
|
|
181
|
+
if (!statement.source) {
|
|
182
|
+
const specifier = statement.specifiers.find((element)=>__rspack_external__babel_types_6e8337dd.isExportSpecifier(element) && 'type' !== element.exportKind && (__rspack_external__babel_types_6e8337dd.isIdentifier(element.exported) ? element.exported.name : element.exported.value) === name);
|
|
183
|
+
if (__rspack_external__babel_types_6e8337dd.isExportSpecifier(specifier)) return specifier.local;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const externalValue = (node)=>{
|
|
188
|
+
const value = moduleFor(node);
|
|
189
|
+
return value ? exported(value.module, value.name) : void 0;
|
|
190
|
+
};
|
|
191
|
+
const apiIdentity = (node, seen = new Set())=>{
|
|
192
|
+
node = unwrap(node);
|
|
193
|
+
if (seen.has(node)) return;
|
|
194
|
+
seen.add(node);
|
|
195
|
+
const value = imported(node);
|
|
196
|
+
if (value) {
|
|
197
|
+
if (!value.specifier.startsWith('.')) return;
|
|
198
|
+
const module = moduleFor(node);
|
|
199
|
+
const exportedValue = module && exported(module.module, module.name);
|
|
200
|
+
if (exportedValue) return apiIdentity(exportedValue, seen);
|
|
201
|
+
if (module && /(?:^|\/)shared\/(?:api|rpc)\.ts$/u.test(value.specifier)) return `${module.module.id}:import:${value.name}`;
|
|
202
|
+
if (!owners.get(node)?.resolveImport && /(?:^|\/)shared\/(?:api|rpc)\.ts$/u.test(value.specifier)) return `${value.specifier}:${value.name}`;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const init = initialized(node);
|
|
206
|
+
if (init && __rspack_external__babel_types_6e8337dd.isIdentifier(unwrap(init))) return apiIdentity(init, seen);
|
|
207
|
+
const valueBinding = binding(node);
|
|
208
|
+
return valueBinding ? `${owners.get(valueBinding.path.node)?.id}:${valueBinding.identifier.start}` : void 0;
|
|
209
|
+
};
|
|
210
|
+
const properties = (node)=>{
|
|
211
|
+
node = unwrap(node);
|
|
212
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectExpression(node)) return;
|
|
213
|
+
const result = new Map();
|
|
214
|
+
for (const prop of node.properties){
|
|
215
|
+
if (!__rspack_external__babel_types_6e8337dd.isObjectProperty(prop) || prop.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(prop.key) || result.has(prop.key.name)) return;
|
|
216
|
+
result.set(prop.key.name, prop.value);
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
};
|
|
220
|
+
const active = new Set();
|
|
221
|
+
const guarded = (node, check)=>{
|
|
222
|
+
node = unwrap(node);
|
|
223
|
+
if (active.has(node) || active.size > 128) return false;
|
|
224
|
+
active.add(node);
|
|
225
|
+
try {
|
|
226
|
+
return check(node);
|
|
227
|
+
} finally{
|
|
228
|
+
active.delete(node);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const layerSources = [
|
|
232
|
+
edge,
|
|
233
|
+
'effect',
|
|
234
|
+
'effect/Layer'
|
|
235
|
+
];
|
|
236
|
+
const returned = (body)=>{
|
|
237
|
+
if (!__rspack_external__babel_types_6e8337dd.isBlockStatement(body)) return body;
|
|
238
|
+
const statements = body.body;
|
|
239
|
+
const last = statements.at(-1);
|
|
240
|
+
return statements.slice(0, -1).every((statement)=>__rspack_external__babel_types_6e8337dd.isVariableDeclaration(statement)) && __rspack_external__babel_types_6e8337dd.isReturnStatement(last) ? last.argument : void 0;
|
|
241
|
+
};
|
|
242
|
+
const pipe = (node, check)=>__rspack_external__babel_types_6e8337dd.isMemberExpression(node.callee) && !node.callee.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(node.callee.property, {
|
|
243
|
+
name: 'pipe'
|
|
244
|
+
}) && check(node.callee.object) && node.arguments.every((argument)=>method(argument, 'Layer', 'orDie', layerSources) || __rspack_external__babel_types_6e8337dd.isCallExpression(argument) && method(argument.callee, 'Layer', 'provide', layerSources) && argument.arguments.length > 0);
|
|
245
|
+
const handled = (node)=>{
|
|
246
|
+
node = unwrap(node);
|
|
247
|
+
if (!__rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(node) && !__rspack_external__babel_types_6e8337dd.isFunctionExpression(node)) return false;
|
|
248
|
+
const parameter = node.params[0];
|
|
249
|
+
if (!__rspack_external__babel_types_6e8337dd.isIdentifier(parameter)) return false;
|
|
250
|
+
const body = returned(node.body);
|
|
251
|
+
const chain = (value, count = 0)=>{
|
|
252
|
+
value = unwrap(value);
|
|
253
|
+
if (__rspack_external__babel_types_6e8337dd.isIdentifier(value)) return count > 0 && declaration(value) === parameter;
|
|
254
|
+
return __rspack_external__babel_types_6e8337dd.isCallExpression(value) && __rspack_external__babel_types_6e8337dd.isMemberExpression(value.callee) && !value.callee.computed && __rspack_external__babel_types_6e8337dd.isIdentifier(value.callee.property) && [
|
|
255
|
+
'handle',
|
|
256
|
+
'handleRaw'
|
|
257
|
+
].includes(value.callee.property.name) && 2 === value.arguments.length && chain(value.callee.object, count + 1);
|
|
258
|
+
};
|
|
259
|
+
return !!body && chain(body);
|
|
260
|
+
};
|
|
261
|
+
const handlers = (node, api)=>guarded(node, (node)=>{
|
|
262
|
+
const init = initialized(node) ?? externalValue(node);
|
|
263
|
+
if (init) return handlers(init, api);
|
|
264
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node)) return false;
|
|
265
|
+
if (pipe(node, (value)=>handlers(value, api))) return true;
|
|
266
|
+
if (method(node.callee, 'Layer', 'mergeAll', layerSources)) return node.arguments.length > 0 && node.arguments.every((argument)=>handlers(argument, api));
|
|
267
|
+
return method(node.callee, 'HttpApiBuilder', 'group') && 3 === node.arguments.length && apiIdentity(node.arguments[0]) === api && handled(node.arguments[2]);
|
|
268
|
+
});
|
|
269
|
+
const transport = (node)=>guarded(node, (node)=>{
|
|
270
|
+
const init = initialized(node);
|
|
271
|
+
if (init) return transport(init);
|
|
272
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node)) return method(node, 'Layer', 'empty', layerSources);
|
|
273
|
+
return pipe(node, transport) || method(node.callee, 'HttpRouter', 'cors') || method(node.callee, 'Layer', 'mergeAll', layerSources) && node.arguments.length > 0 && node.arguments.every(transport);
|
|
274
|
+
});
|
|
275
|
+
const directLayer = (node, api)=>guarded(node, (node)=>{
|
|
276
|
+
const init = initialized(node);
|
|
277
|
+
if (init) return directLayer(init, api);
|
|
278
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node) || !__rspack_external__babel_types_6e8337dd.isMemberExpression(node.callee) || node.callee.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(node.callee.property, {
|
|
279
|
+
name: 'pipe'
|
|
280
|
+
})) return false;
|
|
281
|
+
const base = unwrap(node.callee.object);
|
|
282
|
+
return __rspack_external__babel_types_6e8337dd.isCallExpression(base) && method(base.callee, 'HttpApiBuilder', 'layer') && 1 === base.arguments.length && apiIdentity(base.arguments[0]) === api && node.arguments.length > 0 && node.arguments.every((argument)=>__rspack_external__babel_types_6e8337dd.isCallExpression(argument) && method(argument.callee, 'Layer', 'provide', layerSources) && 1 === argument.arguments.length && handlers(argument.arguments[0], api));
|
|
283
|
+
});
|
|
284
|
+
const rpc = (values)=>{
|
|
285
|
+
const api = values.get('api');
|
|
286
|
+
const apiLayer = values.get('layer');
|
|
287
|
+
const apiInit = api && (initialized(api) ?? unwrap(api));
|
|
288
|
+
if (!apiInit || !__rspack_external__babel_types_6e8337dd.isCallExpression(apiInit) || !method(apiInit.callee, 'HttpApi', 'make') || 1 !== apiInit.arguments.length || !apiLayer || !transport(apiLayer)) return false;
|
|
289
|
+
const config = values.get('rpc');
|
|
290
|
+
const fields = config && properties(config);
|
|
291
|
+
const route = fields?.get('path');
|
|
292
|
+
const serialization = fields?.get('serialization');
|
|
293
|
+
if (!__rspack_external__babel_types_6e8337dd.isStringLiteral(route, {
|
|
294
|
+
value: '/rpc'
|
|
295
|
+
}) || !__rspack_external__babel_types_6e8337dd.isStringLiteral(serialization, {
|
|
296
|
+
value: 'json'
|
|
297
|
+
})) return false;
|
|
298
|
+
const group = fields?.get('group');
|
|
299
|
+
const layer = fields?.get('layer');
|
|
300
|
+
const value = group && imported(group);
|
|
301
|
+
if (!group || !layer || value?.specifier !== '../shared/rpc.ts') return false;
|
|
302
|
+
const groupValue = externalValue(group);
|
|
303
|
+
const groupInit = groupValue && initialized(groupValue);
|
|
304
|
+
if (!groupInit || !__rspack_external__babel_types_6e8337dd.isCallExpression(groupInit) || !method(groupInit.callee, 'RpcGroup', 'make', [
|
|
305
|
+
'effect/unstable/rpc',
|
|
306
|
+
'@modern-js/bff-effect/effect-client'
|
|
307
|
+
])) return false;
|
|
308
|
+
const layerInit = initialized(layer) ?? unwrap(layer);
|
|
309
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(layerInit) || !__rspack_external__babel_types_6e8337dd.isMemberExpression(layerInit.callee) || layerInit.callee.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(layerInit.callee.property, {
|
|
310
|
+
name: 'toLayer'
|
|
311
|
+
}) || apiIdentity(layerInit.callee.object) !== apiIdentity(group) || 1 !== layerInit.arguments.length) return false;
|
|
312
|
+
const implementation = unwrap(layerInit.arguments[0]);
|
|
313
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(implementation) || !__rspack_external__babel_types_6e8337dd.isMemberExpression(implementation.callee) || implementation.callee.computed || !__rspack_external__babel_types_6e8337dd.isIdentifier(implementation.callee.property, {
|
|
314
|
+
name: 'of'
|
|
315
|
+
}) || apiIdentity(implementation.callee.object) !== apiIdentity(group) || 1 !== implementation.arguments.length) return false;
|
|
316
|
+
const entries = properties(implementation.arguments[0]);
|
|
317
|
+
return !!entries?.size && [
|
|
318
|
+
...entries.values()
|
|
319
|
+
].every((value)=>__rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(value) || __rspack_external__babel_types_6e8337dd.isFunctionExpression(value));
|
|
320
|
+
};
|
|
321
|
+
const runtime = (node)=>guarded(node, (node)=>{
|
|
322
|
+
const init = initialized(node);
|
|
323
|
+
if (init) return runtime(init);
|
|
324
|
+
if (!__rspack_external__babel_types_6e8337dd.isCallExpression(node)) return false;
|
|
325
|
+
const value = imported(node.callee);
|
|
326
|
+
if (value?.name === 'defineEffectBff' && [
|
|
327
|
+
edge,
|
|
328
|
+
nodeRuntime
|
|
329
|
+
].includes(value.specifier) || value?.name === 'assembleEffectBffRuntime' && sharedRuntime.test(value.specifier)) {
|
|
330
|
+
if (1 !== node.arguments.length) return false;
|
|
331
|
+
const values = properties(node.arguments[0]);
|
|
332
|
+
if (!values) return false;
|
|
333
|
+
if ('defineEffectBff' === value.name && values.has('rpc')) return rpc(values);
|
|
334
|
+
const api = values.get('api');
|
|
335
|
+
const apiBinding = api && imported(api);
|
|
336
|
+
if (!api || apiBinding?.specifier !== '../shared/api.ts') return false;
|
|
337
|
+
const identity = apiIdentity(api);
|
|
338
|
+
if (!identity) return false;
|
|
339
|
+
const layer = values.get('defineEffectBff' === value.name ? 'layer' : 'handlers');
|
|
340
|
+
const extra = values.get('transport');
|
|
341
|
+
return void 0 !== layer && ('defineEffectBff' === value.name ? directLayer(layer, identity) : handlers(layer, identity)) && (!extra || transport(extra));
|
|
342
|
+
}
|
|
343
|
+
const decl = declaration(node.callee);
|
|
344
|
+
const factory = decl && __rspack_external__babel_types_6e8337dd.isFunctionDeclaration(decl) ? decl : initialized(node.callee);
|
|
345
|
+
if (!factory || !__rspack_external__babel_types_6e8337dd.isFunctionDeclaration(factory) && !__rspack_external__babel_types_6e8337dd.isArrowFunctionExpression(factory) && !__rspack_external__babel_types_6e8337dd.isFunctionExpression(factory) || !factory.body) return false;
|
|
346
|
+
const result = returned(factory.body);
|
|
347
|
+
return !!result && runtime(result);
|
|
348
|
+
});
|
|
349
|
+
const root = entry.file.program.body.find((statement)=>__rspack_external__babel_types_6e8337dd.isExportDefaultDeclaration(statement));
|
|
350
|
+
return root && runtime(root.declaration) ? void 0 : failure;
|
|
351
|
+
} catch (cause) {
|
|
352
|
+
if ('object' == typeof cause && null !== cause && invalidSources.has(cause)) return failure;
|
|
353
|
+
const message = 'object' == typeof cause && null !== cause && 'message' in cause && 'string' == typeof cause.message ? cause.message : String(cause);
|
|
354
|
+
throw new Error(`Strict Effect API analysis failed: ${message}`, {
|
|
355
|
+
cause
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
export { createEffectApiImportResolver, strictEffectRuntimeTopologyViolation };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runMicroVerticalApiCheckCli(args?: string[], filesOnly?: boolean): number;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only `.tsx` is JSX. Enabling JSX for a `.ts` file misreads a generic arrow
|
|
3
|
+
* such as `const f = <T>(value: T) => value` as an unclosed JSX element.
|
|
4
|
+
*/
|
|
5
|
+
export declare const consumerParserPlugins: (filePath: string) => ('typescript' | 'jsx')[];
|
|
6
|
+
export interface MicroVerticalApiBaselineExpectation {
|
|
7
|
+
/** Optional override for operation IDs outside reachable endpoint naming conventions. */
|
|
8
|
+
readonly operationPaths?: Readonly<Record<string, string>>;
|
|
9
|
+
readonly additionalPaths: Readonly<Record<string, string>>;
|
|
10
|
+
readonly apiPrefix: string;
|
|
11
|
+
readonly basePath: string;
|
|
12
|
+
readonly effectClientPackage: string;
|
|
13
|
+
readonly ownerId: string;
|
|
14
|
+
readonly readinessPath: string;
|
|
15
|
+
readonly baselinePackage: '@modern-js/bff-effect/microvertical-api';
|
|
16
|
+
readonly baselinePackageDirectory: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MicroVerticalTopologyEntry {
|
|
19
|
+
readonly api?: {
|
|
20
|
+
readonly readiness?: {
|
|
21
|
+
readonly endpoint?: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly path?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const configuredMicroVerticalApiStem: (verticalPath: string, verticals: readonly MicroVerticalTopologyEntry[]) => string | undefined;
|
|
28
|
+
export declare const microVerticalApiBaselineViolation: (stem: string, filePath: string, expectation: MicroVerticalApiBaselineExpectation) => string | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type { MicroVerticalApiBaselineExpectation, MicroVerticalTopologyEntry, } from './microvertical-api-baseline.js';
|
|
2
|
+
export { configuredMicroVerticalApiStem, microVerticalApiBaselineViolation, } from './microvertical-api-baseline.js';
|
|
3
|
+
export interface MicroVerticalConfiguredApp {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly id?: string;
|
|
6
|
+
readonly kind?: string;
|
|
7
|
+
readonly package?: string;
|
|
8
|
+
readonly surfaceProfile?: string;
|
|
9
|
+
readonly deliveryUnitKind?: string;
|
|
10
|
+
readonly api?: {
|
|
11
|
+
readonly stem?: string;
|
|
12
|
+
readonly prefix?: string;
|
|
13
|
+
readonly protocol?: 'rest' | 'rpc';
|
|
14
|
+
readonly operationPaths?: Readonly<Record<string, string>>;
|
|
15
|
+
readonly additionalPaths?: Readonly<Record<string, string>>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface MicroVerticalApiCheckOptions {
|
|
19
|
+
readonly workspaceRoot: string;
|
|
20
|
+
readonly configuredApps?: readonly MicroVerticalConfiguredApp[];
|
|
21
|
+
/** Explicit expected installed owner, useful for isolated/non-hoisted installations. */
|
|
22
|
+
readonly baselinePackageDirectory?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface MicroVerticalApiCheckResult {
|
|
25
|
+
readonly diagnostics: readonly string[];
|
|
26
|
+
readonly toolErrors: readonly string[];
|
|
27
|
+
readonly topologyFilesAnalyzed: number;
|
|
28
|
+
}
|
|
29
|
+
/** Full standalone check: source runtime topology is analyzed once per entry. */
|
|
30
|
+
export declare const checkMicroVerticalApiBoundaries: (options: MicroVerticalApiCheckOptions) => MicroVerticalApiCheckResult;
|
|
31
|
+
/** Consumer files/export/owner checks; caller must separately run runtime topology analysis. */
|
|
32
|
+
export declare const checkMicroVerticalApiConsumerFiles: (options: MicroVerticalApiCheckOptions) => MicroVerticalApiCheckResult;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MicroVerticalApiBaselineExpectation } from './microvertical-api-baseline.js';
|
|
2
|
+
export declare const baselinePackage = "@modern-js/bff-effect/microvertical-api";
|
|
3
|
+
/** Locate the installed package from this consumer's resolver, never this tool's installation. */
|
|
4
|
+
export declare function resolveBaselinePackageDirectory(fromFile: string): string;
|
|
5
|
+
/** Follow only public bindings and local barrels. Never examine schema implementation expressions. */
|
|
6
|
+
export declare function baselinePublicIdentityIsExact(fromFile: string, expectation: MicroVerticalApiBaselineExpectation): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** A bounded, owner-local source resolver; never executes application modules. */
|
|
2
|
+
export interface EffectApiSource {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly source: string;
|
|
5
|
+
readonly resolveImport?: (specifier: string) => EffectApiSource | undefined;
|
|
6
|
+
}
|
|
7
|
+
export type EffectApiImportResolver = (specifier: string) => EffectApiSource | undefined;
|
|
8
|
+
export declare function createEffectApiImportResolver(filename: string): EffectApiImportResolver;
|
|
9
|
+
/** Proves binding identity and an exported composition, not the occurrence of names. */
|
|
10
|
+
export declare function strictEffectRuntimeTopologyViolation(source: string, resolveImport?: EffectApiImportResolver): string | undefined;
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">=20"
|
|
25
25
|
},
|
|
26
|
-
"version": "3.
|
|
26
|
+
"version": "3.9.0-ultramodern.10",
|
|
27
27
|
"types": "./dist/types/index.d.ts",
|
|
28
28
|
"main": "./dist/esm-node/index.js",
|
|
29
29
|
"typesVersions": {
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
],
|
|
34
34
|
"oxlint-plugin": [
|
|
35
35
|
"./dist/types/oxlint-plugin.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"microvertical-api-boundary": [
|
|
38
|
+
"./dist/types/microvertical-api-boundary.d.ts"
|
|
36
39
|
]
|
|
37
40
|
}
|
|
38
41
|
},
|
|
@@ -45,6 +48,11 @@
|
|
|
45
48
|
},
|
|
46
49
|
"default": "./dist/esm-node/index.js"
|
|
47
50
|
},
|
|
51
|
+
"./strict-effect-runtime": {
|
|
52
|
+
"types": "./dist/types/strict-effect-runtime.d.ts",
|
|
53
|
+
"import": "./dist/esm-node/strict-effect-runtime.js",
|
|
54
|
+
"require": "./dist/cjs/strict-effect-runtime.cjs"
|
|
55
|
+
},
|
|
48
56
|
"./oxlint-plugin": {
|
|
49
57
|
"types": "./dist/types/oxlint-plugin.d.ts",
|
|
50
58
|
"node": {
|
|
@@ -52,18 +60,27 @@
|
|
|
52
60
|
"require": "./dist/cjs/oxlint-plugin.cjs"
|
|
53
61
|
},
|
|
54
62
|
"default": "./dist/esm-node/oxlint-plugin.js"
|
|
63
|
+
},
|
|
64
|
+
"./microvertical-api-boundary": {
|
|
65
|
+
"types": "./dist/types/microvertical-api-boundary.d.ts",
|
|
66
|
+
"import": "./dist/esm-node/microvertical-api-boundary.js",
|
|
67
|
+
"require": "./dist/cjs/microvertical-api-boundary.cjs"
|
|
55
68
|
}
|
|
56
69
|
},
|
|
57
70
|
"files": [
|
|
58
|
-
"dist"
|
|
71
|
+
"dist",
|
|
72
|
+
"bin"
|
|
59
73
|
],
|
|
60
74
|
"dependencies": {
|
|
61
|
-
"
|
|
75
|
+
"@babel/parser": "^8.0.4",
|
|
76
|
+
"@babel/traverse": "^8.0.4",
|
|
77
|
+
"@babel/types": "^8.0.4",
|
|
78
|
+
"oxlint": "1.81.0"
|
|
62
79
|
},
|
|
63
80
|
"devDependencies": {
|
|
64
|
-
"@rslib/core": "0.
|
|
81
|
+
"@rslib/core": "1.0.0",
|
|
65
82
|
"@scripts/rstest-config": "2.66.0",
|
|
66
|
-
"@types/node": "^26.
|
|
83
|
+
"@types/node": "^26.4.1",
|
|
67
84
|
"@typescript/native-preview": "7.0.0-dev.20260707.2"
|
|
68
85
|
},
|
|
69
86
|
"sideEffects": false,
|
|
@@ -71,6 +88,10 @@
|
|
|
71
88
|
"access": "public"
|
|
72
89
|
},
|
|
73
90
|
"modern:source": "./src/index.ts",
|
|
91
|
+
"bin": {
|
|
92
|
+
"modern-api-check": "bin/modern-api-check.mjs",
|
|
93
|
+
"modern-api-check-files": "bin/modern-api-check-files.mjs"
|
|
94
|
+
},
|
|
74
95
|
"scripts": {
|
|
75
96
|
"build": "rm -rf dist && rslib build -c rslib.config.mts",
|
|
76
97
|
"dev": "rslib build -c rslib.config.mts -w",
|