@nimiplatform/app-tools 0.6.3 → 0.7.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/README.md +100 -10
- package/bin/nimi-app.mjs +6 -12
- package/lib/app-dependency-combinations.mjs +62 -0
- package/lib/app-doctor-update.mjs +18 -16
- package/lib/app-info.mjs +25 -2
- package/lib/app-lifecycle-guidance.mjs +4 -2
- package/lib/app-pack.mjs +5 -2
- package/lib/app-project-lifecycle.mjs +208 -50
- package/lib/app-safety-profile.mjs +204 -0
- package/lib/app-scaffold-capabilities.mjs +8 -0
- package/lib/app-scaffold-profiles.mjs +42 -3
- package/lib/app-scaffold.mjs +2 -1
- package/lib/canonical-capability-ids.generated.mjs +21 -0
- package/lib/index.mjs +0 -4
- package/package.json +7 -12
- package/scripts/dev-shell.mjs +20 -2
- package/skills/nimi-app-lifecycle/SKILL.md +7 -3
- package/skills/nimi-app-lifecycle/references/acceptance.md +6 -0
- package/skills/nimi-app-lifecycle/references/adapt.md +46 -1
- package/skills/nimi-app-lifecycle/references/audit.md +55 -0
- package/skills/nimi-app-lifecycle/references/platform-gaps.md +15 -0
- package/skills/nimi-app-lifecycle/references/release.md +1 -1
- package/skills/nimi-app-lifecycle/references/safety-declaration.md +37 -0
- package/skills/nimi-app-lifecycle/references/upgrade-platform.md +2 -2
- package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +8 -10
- package/templates/default-starter/AGENTS.md +4 -2
- package/lib/simulator-conformance-ast.mjs +0 -498
- package/lib/simulator-conformance-css.mjs +0 -116
- package/lib/simulator-conformance-graph.mjs +0 -757
- package/lib/simulator-conformance.d.mts +0 -14
- package/lib/simulator-conformance.mjs +0 -203
- package/lib/simulator-css-profile.d.mts +0 -27
- package/lib/simulator-css-profile.mjs +0 -531
- package/lib/simulator-kit-export-resolution.mjs +0 -70
- package/lib/simulator-manifest.mjs +0 -334
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import {
|
|
3
|
-
SIMULATOR_MODULE_PROTOCOL,
|
|
4
|
-
SimulatorConformanceError,
|
|
5
|
-
} from './simulator-manifest.mjs';
|
|
6
|
-
|
|
7
|
-
function fail(code, message, fieldPath = '') {
|
|
8
|
-
throw new SimulatorConformanceError(code, message, fieldPath);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function propertyNameText(name) {
|
|
12
|
-
if (!name) return '';
|
|
13
|
-
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
|
|
14
|
-
return String(name.text);
|
|
15
|
-
}
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function findExportedVariable(source, exportName) {
|
|
20
|
-
for (const statement of source.statements) {
|
|
21
|
-
if (!ts.isVariableStatement(statement)) continue;
|
|
22
|
-
const modifiers = ts.getModifiers(statement) || [];
|
|
23
|
-
if (!modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) continue;
|
|
24
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
25
|
-
if (ts.isIdentifier(declaration.name) && declaration.name.text === exportName) {
|
|
26
|
-
return declaration.initializer || null;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function unwrapExpression(node) {
|
|
34
|
-
let current = node;
|
|
35
|
-
while (
|
|
36
|
-
current
|
|
37
|
-
&& (ts.isAsExpression(current)
|
|
38
|
-
|| ts.isSatisfiesExpression(current)
|
|
39
|
-
|| ts.isParenthesizedExpression(current)
|
|
40
|
-
|| ts.isTypeAssertionExpression(current))
|
|
41
|
-
) {
|
|
42
|
-
current = current.expression;
|
|
43
|
-
}
|
|
44
|
-
return current;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function objectLiteral(node) {
|
|
48
|
-
let expression = unwrapExpression(node);
|
|
49
|
-
if (expression
|
|
50
|
-
&& ts.isCallExpression(expression)
|
|
51
|
-
&& ts.isPropertyAccessExpression(expression.expression)
|
|
52
|
-
&& expression.expression.expression.getText() === 'Object'
|
|
53
|
-
&& expression.expression.name.text === 'freeze'
|
|
54
|
-
&& expression.arguments.length === 1) {
|
|
55
|
-
expression = unwrapExpression(expression.arguments[0]);
|
|
56
|
-
}
|
|
57
|
-
return expression && ts.isObjectLiteralExpression(expression) ? expression : null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function objectProperties(node) {
|
|
61
|
-
const expression = objectLiteral(node);
|
|
62
|
-
if (!expression) return new Map();
|
|
63
|
-
const result = new Map();
|
|
64
|
-
for (const [index, property] of expression.properties.entries()) {
|
|
65
|
-
if (ts.isPropertyAssignment(property)
|
|
66
|
-
|| ts.isMethodDeclaration(property)
|
|
67
|
-
|| ts.isShorthandPropertyAssignment(property)) {
|
|
68
|
-
const name = propertyNameText(property.name);
|
|
69
|
-
if (name && !result.has(name)) {
|
|
70
|
-
result.set(name, property);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Exact metadata objects must not hide spread, computed, duplicate, accessor,
|
|
75
|
-
// or otherwise ambiguous members behind the recognized field set.
|
|
76
|
-
result.set(Symbol(`ambiguous-object-member-${index}`), property);
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function assertExactPropertySet(properties, expected, code, message, fieldPath) {
|
|
82
|
-
const exact = new Set(expected);
|
|
83
|
-
if (properties.size !== exact.size || [...properties.keys()].some((key) => !exact.has(key))) {
|
|
84
|
-
fail(code, message, fieldPath);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function literalPropertyValue(property) {
|
|
89
|
-
if (!property || !ts.isPropertyAssignment(property)) return null;
|
|
90
|
-
const initializer = unwrapExpression(property.initializer);
|
|
91
|
-
return initializer && ts.isStringLiteral(initializer) ? initializer.text : null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function isFunctionPropertyAssignment(property) {
|
|
95
|
-
if (!ts.isPropertyAssignment(property)) return false;
|
|
96
|
-
const initializer = unwrapExpression(property.initializer);
|
|
97
|
-
return Boolean(initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function functionPropertyNode(property) {
|
|
101
|
-
if (ts.isMethodDeclaration(property)) {
|
|
102
|
-
return property;
|
|
103
|
-
}
|
|
104
|
-
if (isFunctionPropertyAssignment(property)) return unwrapExpression(property.initializer);
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function assertSynchronousFunction(property, code, label, fieldPath) {
|
|
109
|
-
const functionNode = functionPropertyNode(property);
|
|
110
|
-
const modifiers = functionNode && ts.canHaveModifiers(functionNode) ? ts.getModifiers(functionNode) || [] : [];
|
|
111
|
-
if (!functionNode
|
|
112
|
-
|| modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword)
|
|
113
|
-
|| functionNode.asteriskToken) {
|
|
114
|
-
fail(code, `${label} must be a synchronous non-generator function`, fieldPath);
|
|
115
|
-
}
|
|
116
|
-
return functionNode;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function isConditionalReturnExpression(expression) {
|
|
120
|
-
return ts.isConditionalExpression(expression)
|
|
121
|
-
|| (ts.isBinaryExpression(expression)
|
|
122
|
-
&& [
|
|
123
|
-
ts.SyntaxKind.AmpersandAmpersandToken,
|
|
124
|
-
ts.SyntaxKind.BarBarToken,
|
|
125
|
-
ts.SyntaxKind.QuestionQuestionToken,
|
|
126
|
-
].includes(expression.operatorToken.kind))
|
|
127
|
-
|| Boolean(expression.questionDotToken);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function directReturnExpression(property, code, label, fieldPath) {
|
|
131
|
-
const functionNode = assertSynchronousFunction(property, code, label, fieldPath);
|
|
132
|
-
const body = functionNode.body;
|
|
133
|
-
if (!body) fail(code, `${label} must have an implementation body`, fieldPath);
|
|
134
|
-
if (!ts.isBlock(body)) {
|
|
135
|
-
const expression = unwrapExpression(body);
|
|
136
|
-
if (!expression || isConditionalReturnExpression(expression)) {
|
|
137
|
-
fail(code, `${label} must have one unconditional return expression`, fieldPath);
|
|
138
|
-
}
|
|
139
|
-
return expression;
|
|
140
|
-
}
|
|
141
|
-
const returns = [];
|
|
142
|
-
const visit = (node) => {
|
|
143
|
-
if (node !== body
|
|
144
|
-
&& (ts.isFunctionDeclaration(node)
|
|
145
|
-
|| ts.isFunctionExpression(node)
|
|
146
|
-
|| ts.isArrowFunction(node)
|
|
147
|
-
|| ts.isMethodDeclaration(node)
|
|
148
|
-
|| ts.isGetAccessorDeclaration(node)
|
|
149
|
-
|| ts.isSetAccessorDeclaration(node))) return;
|
|
150
|
-
if (ts.isReturnStatement(node)) returns.push(node);
|
|
151
|
-
ts.forEachChild(node, visit);
|
|
152
|
-
};
|
|
153
|
-
visit(body);
|
|
154
|
-
const directReturns = body.statements.filter(ts.isReturnStatement);
|
|
155
|
-
if (returns.length !== 1
|
|
156
|
-
|| directReturns.length !== 1
|
|
157
|
-
|| returns[0] !== directReturns[0]
|
|
158
|
-
|| !directReturns[0].expression) {
|
|
159
|
-
fail(code, `${label} must have exactly one direct unconditional return`, fieldPath);
|
|
160
|
-
}
|
|
161
|
-
const expression = unwrapExpression(directReturns[0].expression);
|
|
162
|
-
if (!expression || isConditionalReturnExpression(expression)) {
|
|
163
|
-
fail(code, `${label} must have one unconditional return expression`, fieldPath);
|
|
164
|
-
}
|
|
165
|
-
return expression;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function literalJson(node, fieldPath, depth = 0) {
|
|
169
|
-
if (depth > 32) fail('SIM_FIXTURE_LITERAL_DEPTH', 'fixture literal exceeds maximum depth', fieldPath);
|
|
170
|
-
const expression = unwrapExpression(node);
|
|
171
|
-
if (!expression) fail('SIM_FIXTURE_LITERAL', 'fixture value must be a static JSON literal', fieldPath);
|
|
172
|
-
if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) return expression.text;
|
|
173
|
-
if (ts.isNumericLiteral(expression)) return Number(expression.text);
|
|
174
|
-
if (expression.kind === ts.SyntaxKind.TrueKeyword) return true;
|
|
175
|
-
if (expression.kind === ts.SyntaxKind.FalseKeyword) return false;
|
|
176
|
-
if (expression.kind === ts.SyntaxKind.NullKeyword) return null;
|
|
177
|
-
if (ts.isPrefixUnaryExpression(expression)
|
|
178
|
-
&& expression.operator === ts.SyntaxKind.MinusToken
|
|
179
|
-
&& ts.isNumericLiteral(expression.operand)) {
|
|
180
|
-
return -Number(expression.operand.text);
|
|
181
|
-
}
|
|
182
|
-
if (ts.isArrayLiteralExpression(expression)) {
|
|
183
|
-
return expression.elements.map((entry, index) => literalJson(entry, `${fieldPath}[${index}]`, depth + 1));
|
|
184
|
-
}
|
|
185
|
-
const objectExpression = objectLiteral(expression);
|
|
186
|
-
if (objectExpression) {
|
|
187
|
-
const result = {};
|
|
188
|
-
for (const property of objectExpression.properties) {
|
|
189
|
-
const key = propertyNameText(property.name);
|
|
190
|
-
if (!ts.isPropertyAssignment(property) || !key || Object.hasOwn(result, key)) {
|
|
191
|
-
fail('SIM_FIXTURE_LITERAL', 'fixture objects require unique explicit property assignments', fieldPath);
|
|
192
|
-
}
|
|
193
|
-
result[key] = literalJson(property.initializer, `${fieldPath}.${key}`, depth + 1);
|
|
194
|
-
}
|
|
195
|
-
return result;
|
|
196
|
-
}
|
|
197
|
-
fail('SIM_FIXTURE_LITERAL', 'fixture value must be a static JSON literal', fieldPath);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function assertFixtureRecord(value, fieldPath, expectedKeys) {
|
|
201
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
202
|
-
fail('SIM_FIXTURE_SHAPE', 'must be an object', fieldPath);
|
|
203
|
-
}
|
|
204
|
-
const keys = Object.keys(value).sort();
|
|
205
|
-
const expected = [...expectedKeys].sort();
|
|
206
|
-
if (keys.length !== expected.length || keys.some((key, index) => key !== expected[index])) {
|
|
207
|
-
fail('SIM_FIXTURE_FIELDS', `must expose exactly ${expected.join(', ')}`, fieldPath);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function assertFiniteInteger(value, fieldPath, { minimum = 0 } = {}) {
|
|
212
|
-
if (!Number.isSafeInteger(value) || value < minimum) {
|
|
213
|
-
fail('SIM_FIXTURE_SCHEMA', `must be a safe integer >= ${minimum}`, fieldPath);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function assertSimulatorSchema(value, fieldPath, depth = 0) {
|
|
218
|
-
if (depth > 24) fail('SIM_FIXTURE_SCHEMA', 'schema exceeds maximum depth', fieldPath);
|
|
219
|
-
if (!value || typeof value !== 'object' || Array.isArray(value) || typeof value.kind !== 'string') {
|
|
220
|
-
fail('SIM_FIXTURE_SCHEMA', 'must be a Simulator schema object', fieldPath);
|
|
221
|
-
}
|
|
222
|
-
const exact = (keys) => assertFixtureRecord(value, fieldPath, keys);
|
|
223
|
-
if (value.kind === 'null' || value.kind === 'boolean' || value.kind === 'number' || value.kind === 'json') {
|
|
224
|
-
exact(['kind']);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (value.kind === 'integer') {
|
|
228
|
-
const keys = ['kind'];
|
|
229
|
-
if (Object.hasOwn(value, 'minimum')) {
|
|
230
|
-
assertFiniteInteger(value.minimum, `${fieldPath}.minimum`, { minimum: Number.MIN_SAFE_INTEGER });
|
|
231
|
-
keys.push('minimum');
|
|
232
|
-
}
|
|
233
|
-
if (Object.hasOwn(value, 'maximum')) {
|
|
234
|
-
assertFiniteInteger(value.maximum, `${fieldPath}.maximum`, { minimum: Number.MIN_SAFE_INTEGER });
|
|
235
|
-
keys.push('maximum');
|
|
236
|
-
}
|
|
237
|
-
exact(keys);
|
|
238
|
-
if (value.minimum !== undefined && value.maximum !== undefined && value.minimum > value.maximum) {
|
|
239
|
-
fail('SIM_FIXTURE_SCHEMA', 'minimum cannot exceed maximum', fieldPath);
|
|
240
|
-
}
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (value.kind === 'string') {
|
|
244
|
-
const keys = ['kind'];
|
|
245
|
-
for (const name of ['minLength', 'maxLength']) {
|
|
246
|
-
if (Object.hasOwn(value, name)) {
|
|
247
|
-
assertFiniteInteger(value[name], `${fieldPath}.${name}`);
|
|
248
|
-
keys.push(name);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
exact(keys);
|
|
252
|
-
if (value.minLength !== undefined && value.maxLength !== undefined && value.minLength > value.maxLength) {
|
|
253
|
-
fail('SIM_FIXTURE_SCHEMA', 'minLength cannot exceed maxLength', fieldPath);
|
|
254
|
-
}
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (value.kind === 'stringEnum') {
|
|
258
|
-
exact(['kind', 'values']);
|
|
259
|
-
if (!Array.isArray(value.values) || value.values.length === 0
|
|
260
|
-
|| value.values.some((entry) => typeof entry !== 'string')
|
|
261
|
-
|| new Set(value.values).size !== value.values.length) {
|
|
262
|
-
fail('SIM_FIXTURE_SCHEMA', 'stringEnum values must be non-empty unique strings', `${fieldPath}.values`);
|
|
263
|
-
}
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
if (value.kind === 'array') {
|
|
267
|
-
const keys = ['items', 'kind'];
|
|
268
|
-
for (const name of ['minItems', 'maxItems']) {
|
|
269
|
-
if (Object.hasOwn(value, name)) {
|
|
270
|
-
assertFiniteInteger(value[name], `${fieldPath}.${name}`);
|
|
271
|
-
keys.push(name);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
exact(keys);
|
|
275
|
-
assertSimulatorSchema(value.items, `${fieldPath}.items`, depth + 1);
|
|
276
|
-
if (value.minItems !== undefined && value.maxItems !== undefined && value.minItems > value.maxItems) {
|
|
277
|
-
fail('SIM_FIXTURE_SCHEMA', 'minItems cannot exceed maxItems', fieldPath);
|
|
278
|
-
}
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
if (value.kind === 'object') {
|
|
282
|
-
const keys = ['kind', 'properties'];
|
|
283
|
-
if (Object.hasOwn(value, 'required')) keys.push('required');
|
|
284
|
-
exact(keys);
|
|
285
|
-
if (!value.properties || typeof value.properties !== 'object' || Array.isArray(value.properties)) {
|
|
286
|
-
fail('SIM_FIXTURE_SCHEMA', 'object properties must be a mapping', `${fieldPath}.properties`);
|
|
287
|
-
}
|
|
288
|
-
for (const [key, schema] of Object.entries(value.properties)) {
|
|
289
|
-
if (!key) fail('SIM_FIXTURE_SCHEMA', 'property names must be non-empty', `${fieldPath}.properties`);
|
|
290
|
-
assertSimulatorSchema(schema, `${fieldPath}.properties.${key}`, depth + 1);
|
|
291
|
-
}
|
|
292
|
-
if (value.required !== undefined) {
|
|
293
|
-
if (!Array.isArray(value.required)
|
|
294
|
-
|| value.required.some((entry) => typeof entry !== 'string' || !Object.hasOwn(value.properties, entry))
|
|
295
|
-
|| new Set(value.required).size !== value.required.length) {
|
|
296
|
-
fail('SIM_FIXTURE_SCHEMA', 'required must contain unique declared property names', `${fieldPath}.required`);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
if (value.kind === 'union') {
|
|
302
|
-
exact(['kind', 'variants']);
|
|
303
|
-
if (!Array.isArray(value.variants) || value.variants.length === 0) {
|
|
304
|
-
fail('SIM_FIXTURE_SCHEMA', 'union variants must be non-empty', `${fieldPath}.variants`);
|
|
305
|
-
}
|
|
306
|
-
value.variants.forEach((variant, index) => assertSimulatorSchema(variant, `${fieldPath}.variants[${index}]`, depth + 1));
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
fail('SIM_FIXTURE_SCHEMA', `unknown schema kind ${JSON.stringify(value.kind)}`, `${fieldPath}.kind`);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function assertExactStringSet(actual, expected, code, fieldPath) {
|
|
313
|
-
if (!actual || typeof actual !== 'object' || Array.isArray(actual)) {
|
|
314
|
-
fail(code, 'must be a mapping', fieldPath);
|
|
315
|
-
}
|
|
316
|
-
const left = Object.keys(actual).sort();
|
|
317
|
-
const right = [...expected].sort();
|
|
318
|
-
if (left.length !== right.length || left.some((entry, index) => entry !== right[index])) {
|
|
319
|
-
fail(code, `must match Manifest set ${JSON.stringify(right)}`, fieldPath);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export function extractConformanceFixture(source, manifest) {
|
|
324
|
-
const initializer = findExportedVariable(source, 'simulatorConformanceFixture');
|
|
325
|
-
if (!initializer) {
|
|
326
|
-
fail('SIM_FIXTURE_EXPORT', 'fixture must export simulatorConformanceFixture as a static object', manifest.fixtures.conformance);
|
|
327
|
-
}
|
|
328
|
-
const fixture = literalJson(initializer, 'simulatorConformanceFixture');
|
|
329
|
-
assertFixtureRecord(fixture, 'simulatorConformanceFixture', ['protocol', 'moduleId', 'catalog', 'lifecycle']);
|
|
330
|
-
if (fixture.protocol !== SIMULATOR_MODULE_PROTOCOL || fixture.moduleId !== manifest.module_id) {
|
|
331
|
-
fail('SIM_FIXTURE_IDENTITY', 'fixture protocol/moduleId must match the Manifest', manifest.fixtures.conformance);
|
|
332
|
-
}
|
|
333
|
-
assertFixtureRecord(fixture.catalog, 'simulatorConformanceFixture.catalog', ['commandSchemas', 'eventSchemas', 'moduleData']);
|
|
334
|
-
assertExactStringSet(
|
|
335
|
-
fixture.catalog.commandSchemas,
|
|
336
|
-
manifest.requires.simulator_commands,
|
|
337
|
-
'SIM_FIXTURE_COMMAND_SCHEMAS',
|
|
338
|
-
'simulatorConformanceFixture.catalog.commandSchemas',
|
|
339
|
-
);
|
|
340
|
-
assertExactStringSet(
|
|
341
|
-
fixture.catalog.eventSchemas,
|
|
342
|
-
manifest.requires.simulator_events,
|
|
343
|
-
'SIM_FIXTURE_EVENT_SCHEMAS',
|
|
344
|
-
'simulatorConformanceFixture.catalog.eventSchemas',
|
|
345
|
-
);
|
|
346
|
-
for (const [type, schema] of Object.entries(fixture.catalog.commandSchemas)) {
|
|
347
|
-
assertSimulatorSchema(schema, `simulatorConformanceFixture.catalog.commandSchemas.${type}`);
|
|
348
|
-
}
|
|
349
|
-
for (const [type, schema] of Object.entries(fixture.catalog.eventSchemas)) {
|
|
350
|
-
assertSimulatorSchema(schema, `simulatorConformanceFixture.catalog.eventSchemas.${type}`);
|
|
351
|
-
}
|
|
352
|
-
if (JSON.stringify(fixture.lifecycle) !== JSON.stringify(['prepare', 'activate', 'deactivate', 'dispose'])) {
|
|
353
|
-
fail('SIM_FIXTURE_LIFECYCLE', 'lifecycle must declare prepare, activate, deactivate, dispose in order', 'simulatorConformanceFixture.lifecycle');
|
|
354
|
-
}
|
|
355
|
-
return Object.freeze(fixture);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export function assertRendererMetadata(source, manifest) {
|
|
359
|
-
const initializer = findExportedVariable(source, manifest.renderer.export);
|
|
360
|
-
if (!initializer) {
|
|
361
|
-
fail(
|
|
362
|
-
'SIM_RENDERER_EXPORT',
|
|
363
|
-
`renderer export ${JSON.stringify(manifest.renderer.export)} must be an exported object`,
|
|
364
|
-
'renderer.export',
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
const properties = objectProperties(initializer);
|
|
368
|
-
assertExactPropertySet(
|
|
369
|
-
properties,
|
|
370
|
-
['protocol', 'moduleId', 'factory'],
|
|
371
|
-
'SIM_RENDERER_FIELDS',
|
|
372
|
-
'renderer metadata must expose exactly protocol, moduleId, and factory',
|
|
373
|
-
manifest.renderer.entry,
|
|
374
|
-
);
|
|
375
|
-
if (literalPropertyValue(properties.get('protocol')) !== SIMULATOR_MODULE_PROTOCOL) {
|
|
376
|
-
fail(
|
|
377
|
-
'SIM_RENDERER_PROTOCOL',
|
|
378
|
-
`renderer protocol must equal ${SIMULATOR_MODULE_PROTOCOL}`,
|
|
379
|
-
manifest.renderer.entry,
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
if (literalPropertyValue(properties.get('moduleId')) !== manifest.module_id) {
|
|
383
|
-
fail('SIM_RENDERER_MODULE_ID', 'renderer moduleId must equal Manifest module_id', manifest.renderer.entry);
|
|
384
|
-
}
|
|
385
|
-
const factoryProperty = properties.get('factory');
|
|
386
|
-
if (!factoryProperty || !ts.isPropertyAssignment(factoryProperty)) {
|
|
387
|
-
fail('SIM_RENDERER_FACTORY', 'renderer factory field must bind the canonical factory export', manifest.renderer.entry);
|
|
388
|
-
}
|
|
389
|
-
const factoryExpression = unwrapExpression(factoryProperty.initializer);
|
|
390
|
-
if (!factoryExpression
|
|
391
|
-
|| !ts.isIdentifier(factoryExpression)
|
|
392
|
-
|| factoryExpression.text !== manifest.composition.factory_export) {
|
|
393
|
-
fail(
|
|
394
|
-
'SIM_RENDERER_FACTORY',
|
|
395
|
-
`renderer factory must bind ${JSON.stringify(manifest.composition.factory_export)}`,
|
|
396
|
-
manifest.renderer.entry,
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
export function assertCanonicalFactoryMetadata(source, manifest) {
|
|
402
|
-
const initializer = findExportedVariable(source, manifest.composition.factory_export);
|
|
403
|
-
if (!initializer) {
|
|
404
|
-
fail(
|
|
405
|
-
'SIM_FACTORY_EXPORT',
|
|
406
|
-
`canonical factory export ${JSON.stringify(manifest.composition.factory_export)} must be an exported object`,
|
|
407
|
-
'composition.factory_export',
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
const properties = objectProperties(initializer);
|
|
411
|
-
assertExactPropertySet(
|
|
412
|
-
properties,
|
|
413
|
-
['factoryId', 'createInstance'],
|
|
414
|
-
'SIM_FACTORY_FIELDS',
|
|
415
|
-
'canonical factory must expose exactly factoryId and createInstance',
|
|
416
|
-
manifest.composition.factory_entry,
|
|
417
|
-
);
|
|
418
|
-
const factoryId = literalPropertyValue(properties.get('factoryId'));
|
|
419
|
-
if (!factoryId || factoryId !== factoryId.trim()) {
|
|
420
|
-
fail(
|
|
421
|
-
'SIM_FACTORY_ID',
|
|
422
|
-
'canonical factoryId must be a non-empty exact string literal',
|
|
423
|
-
manifest.composition.factory_entry,
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
const createInstance = properties.get('createInstance');
|
|
427
|
-
if (!createInstance
|
|
428
|
-
|| (!ts.isMethodDeclaration(createInstance)
|
|
429
|
-
&& !isFunctionPropertyAssignment(createInstance))) {
|
|
430
|
-
fail(
|
|
431
|
-
'SIM_FACTORY_CREATE_INSTANCE',
|
|
432
|
-
'canonical factory must define createInstance directly',
|
|
433
|
-
manifest.composition.factory_entry,
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
directReturnExpression(
|
|
437
|
-
createInstance,
|
|
438
|
-
'SIM_FACTORY_CREATE_INSTANCE_CONTROL_FLOW',
|
|
439
|
-
'canonical createInstance',
|
|
440
|
-
manifest.composition.factory_entry,
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export function assertAdapterMetadata(source, manifest) {
|
|
445
|
-
const initializer = findExportedVariable(source, manifest.renderer.adapter_export);
|
|
446
|
-
if (!initializer) {
|
|
447
|
-
fail(
|
|
448
|
-
'SIM_ADAPTER_EXPORT',
|
|
449
|
-
`Adapter export ${JSON.stringify(manifest.renderer.adapter_export)} must be an exported object`,
|
|
450
|
-
'renderer.adapter_export',
|
|
451
|
-
);
|
|
452
|
-
}
|
|
453
|
-
const properties = objectProperties(initializer);
|
|
454
|
-
assertExactPropertySet(
|
|
455
|
-
properties,
|
|
456
|
-
['protocol', 'moduleId', 'behavior', 'create'],
|
|
457
|
-
'SIM_ADAPTER_FIELDS',
|
|
458
|
-
'Adapter factory must expose exactly protocol, moduleId, behavior, and create',
|
|
459
|
-
manifest.renderer.adapter_entry,
|
|
460
|
-
);
|
|
461
|
-
if (literalPropertyValue(properties.get('protocol')) !== SIMULATOR_MODULE_PROTOCOL) {
|
|
462
|
-
fail(
|
|
463
|
-
'SIM_ADAPTER_PROTOCOL',
|
|
464
|
-
`Adapter protocol must equal ${SIMULATOR_MODULE_PROTOCOL}`,
|
|
465
|
-
manifest.renderer.adapter_entry,
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
if (literalPropertyValue(properties.get('moduleId')) !== manifest.module_id) {
|
|
469
|
-
fail('SIM_ADAPTER_MODULE_ID', 'Adapter moduleId must equal Manifest module_id', manifest.renderer.adapter_entry);
|
|
470
|
-
}
|
|
471
|
-
const create = properties.get('create');
|
|
472
|
-
if (!create || (!ts.isMethodDeclaration(create) && !isFunctionPropertyAssignment(create))) {
|
|
473
|
-
fail('SIM_ADAPTER_CREATE', 'Adapter factory must define create directly', manifest.renderer.adapter_entry);
|
|
474
|
-
}
|
|
475
|
-
const instanceProperties = objectProperties(directReturnExpression(
|
|
476
|
-
create,
|
|
477
|
-
'SIM_ADAPTER_CREATE_CONTROL_FLOW',
|
|
478
|
-
'Adapter create',
|
|
479
|
-
manifest.renderer.adapter_entry,
|
|
480
|
-
));
|
|
481
|
-
for (const required of ['prepare', 'activate', 'deactivate', 'dispose']) {
|
|
482
|
-
const method = instanceProperties.get(required);
|
|
483
|
-
if (!method || (!ts.isMethodDeclaration(method) && !isFunctionPropertyAssignment(method))) {
|
|
484
|
-
fail(
|
|
485
|
-
'SIM_ADAPTER_LIFECYCLE',
|
|
486
|
-
`Adapter instance is missing lifecycle method ${JSON.stringify(required)}`,
|
|
487
|
-
manifest.renderer.adapter_entry,
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
assertExactPropertySet(
|
|
492
|
-
instanceProperties,
|
|
493
|
-
['prepare', 'activate', 'deactivate', 'dispose'],
|
|
494
|
-
'SIM_ADAPTER_INSTANCE_FIELDS',
|
|
495
|
-
'Adapter instance must expose exactly prepare, activate, deactivate, and dispose',
|
|
496
|
-
manifest.renderer.adapter_entry,
|
|
497
|
-
);
|
|
498
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import selectorParser from 'postcss-selector-parser';
|
|
2
|
-
|
|
3
|
-
import { SimulatorConformanceError } from './simulator-manifest.mjs';
|
|
4
|
-
|
|
5
|
-
function fail(code, message, fieldPath) {
|
|
6
|
-
throw new SimulatorConformanceError(code, message, fieldPath);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function validateSimulatorCssSelectors(root, relativePath, rootClass, globalPrefix) {
|
|
10
|
-
let usesRoot = false;
|
|
11
|
-
root.walkRules((rule) => {
|
|
12
|
-
let parent = rule.parent;
|
|
13
|
-
let insideRootScope = false;
|
|
14
|
-
while (parent) {
|
|
15
|
-
if (parent.type === 'atrule' && /keyframes$/i.test(parent.name)) return;
|
|
16
|
-
if (parent.type === 'atrule'
|
|
17
|
-
&& parent.name.toLowerCase() === 'scope'
|
|
18
|
-
&& parent.params.trim() === `(.${rootClass})`) {
|
|
19
|
-
insideRootScope = true;
|
|
20
|
-
usesRoot = true;
|
|
21
|
-
}
|
|
22
|
-
parent = parent.parent;
|
|
23
|
-
}
|
|
24
|
-
selectorParser((selectors) => {
|
|
25
|
-
selectors.each((selector) => {
|
|
26
|
-
const classes = [];
|
|
27
|
-
selector.walkClasses((classNode) => {
|
|
28
|
-
classes.push(classNode.value);
|
|
29
|
-
});
|
|
30
|
-
const selectorOwnsRoot = classes.includes(rootClass);
|
|
31
|
-
if (selectorOwnsRoot) usesRoot = true;
|
|
32
|
-
const scoped = insideRootScope
|
|
33
|
-
|| selectorOwnsRoot
|
|
34
|
-
|| (classes.length > 0 && classes.every((value) => value.startsWith(globalPrefix)));
|
|
35
|
-
if (!scoped) {
|
|
36
|
-
fail('SIM_CSS_GLOBAL_SELECTOR', `unscoped selector ${JSON.stringify(selector.toString())} is forbidden`, relativePath);
|
|
37
|
-
}
|
|
38
|
-
if (!insideRootScope && !selectorOwnsRoot) {
|
|
39
|
-
const invalid = classes.find((value) => !value.startsWith(globalPrefix));
|
|
40
|
-
if (invalid) {
|
|
41
|
-
fail('SIM_CSS_NAMESPACE', `CSS class ${JSON.stringify(invalid)} is outside the derived module namespace`, relativePath);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}).processSync(rule.selector);
|
|
46
|
-
});
|
|
47
|
-
return usesRoot;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function validateSimulatorCssGlobalSymbols(root, relativePath, globalPrefix) {
|
|
51
|
-
const propertyPrefix = `--${globalPrefix}`;
|
|
52
|
-
root.walkDecls((declaration) => {
|
|
53
|
-
if (declaration.prop.startsWith('--') && !declaration.prop.startsWith(propertyPrefix)) {
|
|
54
|
-
fail('SIM_CSS_CUSTOM_PROPERTY_NAMESPACE', `App-owned custom property ${JSON.stringify(declaration.prop)} is outside ${propertyPrefix}*`, relativePath);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
root.walkAtRules((rule) => {
|
|
58
|
-
const name = rule.name.toLowerCase();
|
|
59
|
-
if (/keyframes$/u.test(name) && !rule.params.trim().startsWith(globalPrefix)) {
|
|
60
|
-
fail('SIM_CSS_KEYFRAMES_NAMESPACE', `App-owned keyframes ${JSON.stringify(rule.params.trim())} are outside ${globalPrefix}*`, relativePath);
|
|
61
|
-
}
|
|
62
|
-
if (name === 'property' && !rule.params.trim().startsWith(propertyPrefix)) {
|
|
63
|
-
fail('SIM_CSS_PROPERTY_NAMESPACE', `App-owned @property ${JSON.stringify(rule.params.trim())} is outside ${propertyPrefix}*`, relativePath);
|
|
64
|
-
}
|
|
65
|
-
if (name === 'layer' && rule.params.trim() === 'properties') {
|
|
66
|
-
fail('SIM_CSS_RESERVED_LAYER', 'Tailwind foundation property layer is reserved to the shared foundation', relativePath);
|
|
67
|
-
}
|
|
68
|
-
if (name !== 'font-face') return;
|
|
69
|
-
const family = rule.nodes?.find((node) => node.type === 'decl' && node.prop.toLowerCase() === 'font-family');
|
|
70
|
-
const value = family?.value.trim().replace(/^['"]|['"]$/gu, '') || '';
|
|
71
|
-
if (!value.startsWith(globalPrefix)) {
|
|
72
|
-
fail('SIM_CSS_FONT_NAMESPACE', `App-owned font family ${JSON.stringify(value)} is outside ${globalPrefix}*`, relativePath);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function validateSimulatorProductionFoundationCss(root, relativePath) {
|
|
78
|
-
const selectors = [];
|
|
79
|
-
root.walkAtRules((rule) => {
|
|
80
|
-
if (rule.name.toLowerCase() !== 'import') {
|
|
81
|
-
fail(
|
|
82
|
-
'SIM_CSS_PRODUCTION_SECOND_TRUTH',
|
|
83
|
-
`production host foundation cannot declare @${rule.name}`,
|
|
84
|
-
relativePath,
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
root.walkRules((rule) => {
|
|
89
|
-
if (rule.parent !== root) {
|
|
90
|
-
fail('SIM_CSS_PRODUCTION_SECOND_TRUTH', 'production host foundation rules must be top-level', relativePath);
|
|
91
|
-
}
|
|
92
|
-
selectorParser((parsed) => {
|
|
93
|
-
parsed.each((selector) => {
|
|
94
|
-
const value = selector.toString().trim();
|
|
95
|
-
if (![':root', 'html', 'body'].includes(value)) {
|
|
96
|
-
fail(
|
|
97
|
-
'SIM_CSS_PRODUCTION_SECOND_TRUTH',
|
|
98
|
-
`App UI selector ${JSON.stringify(value)} must live in the canonical style closure`,
|
|
99
|
-
relativePath,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
selectors.push(value);
|
|
103
|
-
});
|
|
104
|
-
}).processSync(rule.selector);
|
|
105
|
-
});
|
|
106
|
-
root.walkDecls((declaration) => {
|
|
107
|
-
if (declaration.prop.startsWith('--')) {
|
|
108
|
-
fail(
|
|
109
|
-
'SIM_CSS_PRODUCTION_SECOND_TRUTH',
|
|
110
|
-
'App custom properties must live in the canonical style closure',
|
|
111
|
-
relativePath,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return Object.freeze([...new Set(selectors)].sort());
|
|
116
|
-
}
|