@webda/content-mapper 0.0.0-stage → 4.0.0-beta.4

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 (115) hide show
  1. package/LICENSE +166 -0
  2. package/lib/coercions.d.ts +22 -0
  3. package/lib/coercions.d.ts.map +1 -0
  4. package/lib/coercions.js +10 -0
  5. package/lib/coercions.js.map +1 -0
  6. package/lib/context.d.ts +56 -0
  7. package/lib/context.d.ts.map +1 -0
  8. package/lib/context.js +111 -0
  9. package/lib/context.js.map +1 -0
  10. package/lib/defaults.d.ts +31 -0
  11. package/lib/defaults.d.ts.map +1 -0
  12. package/lib/defaults.js +33 -0
  13. package/lib/defaults.js.map +1 -0
  14. package/lib/generators/accessors.d.ts +15 -0
  15. package/lib/generators/accessors.d.ts.map +1 -0
  16. package/lib/generators/accessors.js +567 -0
  17. package/lib/generators/accessors.js.map +1 -0
  18. package/lib/generators/behaviors.d.ts +21 -0
  19. package/lib/generators/behaviors.d.ts.map +1 -0
  20. package/lib/generators/behaviors.js +292 -0
  21. package/lib/generators/behaviors.js.map +1 -0
  22. package/lib/generators/imports.d.ts +86 -0
  23. package/lib/generators/imports.d.ts.map +1 -0
  24. package/lib/generators/imports.js +205 -0
  25. package/lib/generators/imports.js.map +1 -0
  26. package/lib/generators/loadparameters.d.ts +7 -0
  27. package/lib/generators/loadparameters.d.ts.map +1 -0
  28. package/lib/generators/loadparameters.js +175 -0
  29. package/lib/generators/loadparameters.js.map +1 -0
  30. package/lib/generators/qlvalidator.d.ts +53 -0
  31. package/lib/generators/qlvalidator.d.ts.map +1 -0
  32. package/lib/generators/qlvalidator.js +238 -0
  33. package/lib/generators/qlvalidator.js.map +1 -0
  34. package/lib/index.d.ts +53 -0
  35. package/lib/index.d.ts.map +1 -0
  36. package/lib/index.js +36 -0
  37. package/lib/index.js.map +1 -0
  38. package/lib/module-discovery.d.ts +211 -0
  39. package/lib/module-discovery.d.ts.map +1 -0
  40. package/lib/module-discovery.js +662 -0
  41. package/lib/module-discovery.js.map +1 -0
  42. package/lib/module.d.ts +213 -0
  43. package/lib/module.d.ts.map +1 -0
  44. package/lib/module.js +1243 -0
  45. package/lib/module.js.map +1 -0
  46. package/lib/plan.d.ts +101 -0
  47. package/lib/plan.d.ts.map +1 -0
  48. package/lib/plan.js +61 -0
  49. package/lib/plan.js.map +1 -0
  50. package/lib/property-order.d.ts +37 -0
  51. package/lib/property-order.d.ts.map +1 -0
  52. package/lib/property-order.js +141 -0
  53. package/lib/property-order.js.map +1 -0
  54. package/lib/schema/action.d.ts +46 -0
  55. package/lib/schema/action.d.ts.map +1 -0
  56. package/lib/schema/action.js +190 -0
  57. package/lib/schema/action.js.map +1 -0
  58. package/lib/schema/annotations.d.ts +63 -0
  59. package/lib/schema/annotations.d.ts.map +1 -0
  60. package/lib/schema/annotations.js +116 -0
  61. package/lib/schema/annotations.js.map +1 -0
  62. package/lib/schema/converter.d.ts +363 -0
  63. package/lib/schema/converter.d.ts.map +1 -0
  64. package/lib/schema/converter.js +1377 -0
  65. package/lib/schema/converter.js.map +1 -0
  66. package/lib/schema/jsdoc.d.ts +34 -0
  67. package/lib/schema/jsdoc.d.ts.map +1 -0
  68. package/lib/schema/jsdoc.js +206 -0
  69. package/lib/schema/jsdoc.js.map +1 -0
  70. package/lib/schema/model.d.ts +27 -0
  71. package/lib/schema/model.d.ts.map +1 -0
  72. package/lib/schema/model.js +86 -0
  73. package/lib/schema/model.js.map +1 -0
  74. package/lib/schema/project.d.ts +34 -0
  75. package/lib/schema/project.d.ts.map +1 -0
  76. package/lib/schema/project.js +305 -0
  77. package/lib/schema/project.js.map +1 -0
  78. package/lib/schema/service.d.ts +62 -0
  79. package/lib/schema/service.d.ts.map +1 -0
  80. package/lib/schema/service.js +130 -0
  81. package/lib/schema/service.js.map +1 -0
  82. package/lib/schema/types.d.ts +61 -0
  83. package/lib/schema/types.d.ts.map +1 -0
  84. package/lib/schema/types.js +36 -0
  85. package/lib/schema/types.js.map +1 -0
  86. package/lib/schema/worker-cli.d.ts +3 -0
  87. package/lib/schema/worker-cli.d.ts.map +1 -0
  88. package/lib/schema/worker-cli.js +7 -0
  89. package/lib/schema/worker-cli.js.map +1 -0
  90. package/lib/schema/worker.d.ts +81 -0
  91. package/lib/schema/worker.d.ts.map +1 -0
  92. package/lib/schema/worker.js +186 -0
  93. package/lib/schema/worker.js.map +1 -0
  94. package/lib/server.d.ts +2 -0
  95. package/lib/server.d.ts.map +1 -0
  96. package/lib/server.js +133 -0
  97. package/lib/server.js.map +1 -0
  98. package/lib/session.d.ts +84 -0
  99. package/lib/session.d.ts.map +1 -0
  100. package/lib/session.js +141 -0
  101. package/lib/session.js.map +1 -0
  102. package/lib/spans.d.ts +46 -0
  103. package/lib/spans.d.ts.map +1 -0
  104. package/lib/spans.js +64 -0
  105. package/lib/spans.js.map +1 -0
  106. package/lib/twopass.d.ts +45 -0
  107. package/lib/twopass.d.ts.map +1 -0
  108. package/lib/twopass.js +87 -0
  109. package/lib/twopass.js.map +1 -0
  110. package/lib/vite.d.ts +20 -0
  111. package/lib/vite.d.ts.map +1 -0
  112. package/lib/vite.js +41 -0
  113. package/lib/vite.js.map +1 -0
  114. package/package.json +89 -3
  115. package/README.md +0 -3
@@ -0,0 +1,305 @@
1
+ /**
2
+ * The top-level `schemas` map of `webda.module.json`.
3
+ *
4
+ * Stage 7.3. Unlike service and model schemas, these entries record no
5
+ * provenance — the key is all there is — so reproducing them means
6
+ * reproducing the discovery as well as the conversion. Two kinds share the
7
+ * map:
8
+ *
9
+ * - **`<Namespace>/<Name>`** for a type tagged `@WebdaSchema`. Discovered
10
+ * across the *whole program*, dependencies included, which is why
11
+ * `@webda/core`'s `BinaryFile` reappears in every application under that
12
+ * application's namespace.
13
+ * - **`<Root>.<method>.input` / `.output`** for a method decorated `@Action`
14
+ * or `@Operation`, on a model, a modda, a bean or a `@WebdaBehavior`
15
+ * class. The root differs per kind and is not uniform — see
16
+ * {@link actionRoots}.
17
+ */
18
+ import { existsSync, readFileSync } from "node:fs";
19
+ import { dirname, join } from "node:path";
20
+ import { ModifierFlags, SyntaxKind } from "typescript/unstable/ast";
21
+ import * as is from "typescript/unstable/ast/is";
22
+ import { getJSDocTags, getTextOfJSDocComment } from "typescript/unstable/ast";
23
+ import { discoverWebdaObjects } from "../module-discovery.js";
24
+ import { generateActionInput, generateActionOutput } from "./action.js";
25
+ import { SchemaConverter } from "./converter.js";
26
+ /**
27
+ * Build every top-level schema for a project.
28
+ * @param ctx - analysis context, whose `sourceFiles` are the project's own
29
+ * @param options - roots and namespace
30
+ * @returns the `schemas` map
31
+ */
32
+ export function generateTopLevelSchemas(ctx, options) {
33
+ const schemas = {};
34
+ const converterOptions = { project: ctx.project, checker: ctx.checker };
35
+ // `@WebdaSchema` types first, keyed in sorted order, then actions — the
36
+ // order `WebdaSchemaResults.generateSchemas` flushes its two maps in.
37
+ for (const [name, node] of [...declaredSchemas(ctx, options)].sort(([a], [b]) => a.localeCompare(b))) {
38
+ const converter = new SchemaConverter(converterOptions);
39
+ const schema = converter.fromNode(node);
40
+ schema.title = nameOf(node) ?? name;
41
+ schemas[name] = schema;
42
+ }
43
+ for (const [root, method, honorName] of actionRoots(ctx, options)) {
44
+ // Model actions are exposed, and their schemas named, after `@Action({ name })`
45
+ const name = (honorName && actionNameOption(method)) || methodName(method);
46
+ if (!name)
47
+ continue;
48
+ schemas[`${root}.${name}.input`] = generateActionInput(method, converterOptions);
49
+ const output = generateActionOutput(method, converterOptions);
50
+ // A method whose return type cannot be resolved contributes no entry at
51
+ // all: `@webda/compiler` stores `undefined`, which `JSON.stringify` drops.
52
+ if (output)
53
+ schemas[`${root}.${name}.output`] = output;
54
+ }
55
+ return schemas;
56
+ }
57
+ /**
58
+ * Every `@WebdaSchema`-tagged declaration in the program.
59
+ *
60
+ * Deliberately not limited to the project's own sources. The TypeScript 6
61
+ * walk tests the tag before it tests whether the file is a root file, so a
62
+ * tagged type in a dependency's `.d.ts` is re-emitted under the consuming
63
+ * application's namespace. Restricting this to project sources would drop
64
+ * `Webda/BinaryFile` from every downstream module.
65
+ * @param ctx - analysis context
66
+ * @param options - roots and namespace
67
+ * @returns name to declaration
68
+ */
69
+ function declaredSchemas(ctx, options) {
70
+ const found = new Map();
71
+ for (const fileName of ctx.program.getSourceFileNames()) {
72
+ if (fileName.endsWith(".spec.ts") || isDefaultLibrary(fileName))
73
+ continue;
74
+ const sourceFile = ctx.program.getSourceFile(fileName);
75
+ if (!sourceFile)
76
+ continue;
77
+ for (const statement of sourceFile.statements) {
78
+ const tag = webdaTag(statement, "WebdaSchema");
79
+ if (tag === undefined)
80
+ continue;
81
+ const bare = tag || nameOf(statement);
82
+ if (!bare)
83
+ continue;
84
+ const name = bare.includes("/") ? bare : `${options.namespace ?? "Webda"}/${bare}`;
85
+ if (!found.has(name))
86
+ found.set(name, statement);
87
+ }
88
+ }
89
+ return found;
90
+ }
91
+ /**
92
+ * Every decorated method, paired with the root its schema key uses.
93
+ *
94
+ * The root is not computed uniformly, and the inconsistency is observable in
95
+ * the committed artefact rather than incidental:
96
+ *
97
+ * | source | root |
98
+ * | ---------- | --------------------------------------------- |
99
+ * | model | the namespaced model name |
100
+ * | modda/bean | the **raw class name**, unnamespaced |
101
+ * | behaviour | the `@WebdaBehavior` payload, else namespaced |
102
+ *
103
+ * `.webda/operations.json` depends on the middle row: it recovers service
104
+ * operations by matching `^([^.]+)\.` against the short class name, so a
105
+ * namespaced key would not be found.
106
+ * @param ctx - analysis context
107
+ * @param options - roots and namespace
108
+ * @returns root and method pairs, in discovery order
109
+ */
110
+ function actionRoots(ctx, options) {
111
+ const pairs = [];
112
+ const discovered = discoverWebdaObjects(ctx, options);
113
+ const classFor = (fileName, className) => {
114
+ const sourceFile = ctx.program.getSourceFile(fileName);
115
+ return sourceFile?.statements.find((statement) => is.isClassDeclaration(statement) && statement.name?.text === className);
116
+ };
117
+ for (const object of discovered) {
118
+ if (object.section !== "models")
119
+ continue;
120
+ const declaration = classFor(object.fileName, object.className);
121
+ if (!declaration)
122
+ continue;
123
+ // Instance methods come from the type, so inherited actions count;
124
+ // statics are not on the instance type and are read off the class.
125
+ for (const method of instanceActions(ctx, declaration))
126
+ pairs.push([object.name, method, true]);
127
+ for (const method of staticActions(declaration))
128
+ pairs.push([object.name, method, true]);
129
+ }
130
+ for (const object of discovered) {
131
+ if (object.section !== "moddas" && object.section !== "beans")
132
+ continue;
133
+ const declaration = classFor(object.fileName, object.className);
134
+ if (!declaration)
135
+ continue;
136
+ for (const method of instanceActions(ctx, declaration))
137
+ pairs.push([object.className, method]);
138
+ }
139
+ // Behaviours, from the project's own sources only — a dependency already
140
+ // emitted the schemas for the behaviours it owns.
141
+ for (const sourceFile of ctx.sourceFiles) {
142
+ if (sourceFile.fileName.endsWith(".spec.ts"))
143
+ continue;
144
+ for (const statement of sourceFile.statements) {
145
+ if (!is.isClassDeclaration(statement) || !statement.name)
146
+ continue;
147
+ const tag = webdaTag(statement, "WebdaBehavior");
148
+ if (tag === undefined)
149
+ continue;
150
+ const bare = tag || statement.name.text;
151
+ const root = bare.includes("/") ? bare : `${options.namespace ?? "Webda"}/${bare}`;
152
+ for (const method of instanceActions(ctx, statement))
153
+ pairs.push([root, method]);
154
+ }
155
+ }
156
+ return pairs;
157
+ }
158
+ /**
159
+ * Decorated instance methods of a class, including inherited ones.
160
+ * @param ctx - analysis context
161
+ * @param declaration - the class
162
+ * @returns the method declarations
163
+ */
164
+ function instanceActions(ctx, declaration) {
165
+ const type = ctx.checker.getTypeAtLocation(declaration);
166
+ const methods = [];
167
+ for (const property of ctx.checker.getPropertiesOfType(type)) {
168
+ const node = property.valueDeclaration?.resolve(ctx.project);
169
+ if (!node || !is.isMethodDeclaration(node))
170
+ continue;
171
+ if (hasActionDecorator(node))
172
+ methods.push(node);
173
+ }
174
+ return methods;
175
+ }
176
+ /**
177
+ * Decorated static methods declared on a class.
178
+ * @param declaration - the class
179
+ * @returns the method declarations
180
+ */
181
+ function staticActions(declaration) {
182
+ return declaration.members.filter((member) => is.isMethodDeclaration(member) &&
183
+ (member.modifierFlags & ModifierFlags.Static) !== 0 &&
184
+ hasActionDecorator(member));
185
+ }
186
+ /**
187
+ * Whether a method carries `@Action` or `@Operation`.
188
+ *
189
+ * Both the bare and the called form count. `@Route` does not, despite what
190
+ * `exploreServices`'s own documentation says.
191
+ * @param method - the method declaration
192
+ * @returns true when decorated
193
+ */
194
+ function hasActionDecorator(method) {
195
+ for (const modifier of method.modifiers ?? []) {
196
+ if (modifier.kind !== SyntaxKind.Decorator)
197
+ continue;
198
+ const expression = modifier.expression;
199
+ if (!expression)
200
+ continue;
201
+ const identifier = is.isCallExpression(expression) ? expression.expression : expression;
202
+ const name = identifier.text;
203
+ if (name === "Action" || name === "Operation")
204
+ return true;
205
+ }
206
+ return false;
207
+ }
208
+ /**
209
+ * The payload of a `Webda*` JSDoc tag, or undefined when the tag is absent.
210
+ *
211
+ * An empty string means "present with no payload", which the callers treat
212
+ * as "fall back to the declaration name" — so the two cases have to stay
213
+ * distinguishable.
214
+ * @param node - the declaration
215
+ * @param tagName - the tag to look for
216
+ * @returns the first token of the payload, `""`, or undefined
217
+ */
218
+ function webdaTag(node, tagName) {
219
+ for (const tag of getJSDocTags(node)) {
220
+ if (tag.tagName.text !== tagName)
221
+ continue;
222
+ const text = getTextOfJSDocComment(tag.comment)?.trim() ?? "";
223
+ return text.replace("\n", " ").split(" ")[0] ?? "";
224
+ }
225
+ return undefined;
226
+ }
227
+ /**
228
+ * The declared name of a node, when it has one.
229
+ * @param node - the declaration
230
+ * @returns the name
231
+ */
232
+ function nameOf(node) {
233
+ return node.name?.text;
234
+ }
235
+ /**
236
+ * A method's name as written.
237
+ * @param method - the method declaration
238
+ * @returns the name, or undefined for a computed one
239
+ */
240
+ function methodName(method) {
241
+ return method.name.text;
242
+ }
243
+ /**
244
+ * The string-literal `name` option of a method's `@Action`/`@Operation`.
245
+ * @param method - the method declaration
246
+ * @returns the name, or undefined when the decorator sets none
247
+ */
248
+ export function actionNameOption(method) {
249
+ for (const modifier of method.modifiers ?? []) {
250
+ if (modifier.kind !== SyntaxKind.Decorator)
251
+ continue;
252
+ const expression = modifier.expression;
253
+ if (!expression || !is.isCallExpression(expression))
254
+ continue;
255
+ const name = expression.expression.text;
256
+ if (name !== "Action" && name !== "Operation")
257
+ continue;
258
+ const argument = expression.arguments?.[0];
259
+ if (!argument || !is.isObjectLiteralExpression(argument))
260
+ return undefined;
261
+ for (const property of argument.properties) {
262
+ if (is.isPropertyAssignment(property) &&
263
+ property.name?.text === "name" &&
264
+ is.isStringLiteral(property.initializer)) {
265
+ return property.initializer.text || undefined;
266
+ }
267
+ }
268
+ return undefined;
269
+ }
270
+ return undefined;
271
+ }
272
+ /**
273
+ * Whether a file is part of the TypeScript standard library.
274
+ * @param fileName - absolute path
275
+ * @returns true for `lib.*.d.ts` shipped with the compiler
276
+ */
277
+ function isDefaultLibrary(fileName) {
278
+ return /[\\/]lib\.[a-z0-9.]+\.d\.ts$/.test(fileName);
279
+ }
280
+ /**
281
+ * Read a project's namespace the way `WebdaProject` does.
282
+ * @param appPath - application root
283
+ * @returns the namespace, when one applies
284
+ */
285
+ export function namespaceOf(appPath) {
286
+ let folder = appPath;
287
+ while (folder.length > 2) {
288
+ const manifestPath = join(folder, "package.json");
289
+ if (existsSync(manifestPath)) {
290
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
291
+ if (manifest.webda?.namespace)
292
+ return manifest.webda.namespace;
293
+ if (!manifest.name?.startsWith("@"))
294
+ return undefined;
295
+ const scope = manifest.name.split("/")[0].slice(1);
296
+ return scope.charAt(0).toUpperCase() + scope.slice(1);
297
+ }
298
+ const parent = dirname(folder);
299
+ if (parent === folder)
300
+ break;
301
+ folder = parent;
302
+ }
303
+ return undefined;
304
+ }
305
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/schema/project.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;G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OAAe;IACzC,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAClD,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;YAChE,IAAI,QAAQ,CAAC,KAAK,EAAE,SAAS;gBAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC;YAC/D,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC;gBAAE,OAAO,SAAS,CAAC;YACtD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxD,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,MAAM,KAAK,MAAM;YAAE,MAAM;QAC7B,MAAM,GAAG,MAAM,CAAC;IAClB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Service parameter schemas — the `Schema` field of a modda, bean or deployer
3
+ * entry in `webda.module.json`.
4
+ *
5
+ * This is the first third of stage 7 and the easiest: plain configuration
6
+ * objects, no accessors, no model semantics, but it exercises the whole
7
+ * pipeline. 1,589 of the corpus's 4,154 schema nodes come from here.
8
+ *
9
+ * The schema is generated from the **type argument** of the service's base
10
+ * clause — the `X` in `class Store extends Service<StoreParameters>` — not
11
+ * from the service class and not from `loadParameters`. That is what
12
+ * `ModuleGenerator.getSchemaNode` does, and the committed artefact reflects
13
+ * it.
14
+ */
15
+ import type { Checker, Project } from "typescript/unstable/sync";
16
+ import type { ClassDeclaration, TypeNode } from "typescript/unstable/ast";
17
+ import type { JSONSchema7 } from "./types.ts";
18
+ /** What is needed to find and convert a service's parameters. */
19
+ export interface ServiceSchemaOptions {
20
+ /** Project the checker belongs to. */
21
+ project: Project;
22
+ /** The resident checker. */
23
+ checker: Checker;
24
+ /**
25
+ * Base type the parameters must derive from. `ServiceParameters` for moddas
26
+ * and beans, `DeployerResources` for deployers.
27
+ */
28
+ parametersBase?: string;
29
+ /**
30
+ * Add the free-form `openapi` property. True for moddas and beans, false
31
+ * for deployers — `WebdaSchemaResults.generateSchemas` gates it the same
32
+ * way.
33
+ */
34
+ addOpenApi?: boolean;
35
+ /** `title` for the document; the service class name, not the parameters class. */
36
+ title?: string;
37
+ }
38
+ /**
39
+ * Find the parameters type node on a service class.
40
+ *
41
+ * Two shapes are accepted, matching `getSchemaNode`:
42
+ *
43
+ * - `class S extends Service<SParameters>` — the type argument
44
+ * - `class S<T extends SParameters> extends Service<T>` — the constraint
45
+ *
46
+ * The base chain is walked because a service commonly names its parameters on
47
+ * an intermediate class rather than on itself.
48
+ * @param declaration - the service class
49
+ * @param checker - the checker resolving base types
50
+ * @param project - project used to resolve declaration handles
51
+ * @param base - name of the type the parameters must derive from
52
+ * @returns the type node, or undefined when the class declares none
53
+ */
54
+ export declare function findParametersNode(declaration: ClassDeclaration, checker: Checker, project: Project, base?: string): TypeNode | undefined;
55
+ /**
56
+ * Generate a service's `Schema` entry.
57
+ * @param declaration - the service class
58
+ * @param options - checker, project and post-processing switches
59
+ * @returns the schema, or undefined when the service declares no parameters
60
+ */
61
+ export declare function generateServiceSchema(declaration: ClassDeclaration, options: ServiceSchemaOptions): JSONSchema7 | undefined;
62
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/schema/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAA4B,MAAM,0BAA0B,CAAC;AAE3F,OAAO,KAAK,EAAE,gBAAgB,EAAQ,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,iEAAiE;AACjE,MAAM,WAAW,oBAAoB;IACnC,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,IAAI,SAAsB,GACzB,QAAQ,GAAG,SAAS,CAgBtB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,WAAW,GAAG,SAAS,CAiBzB"}
@@ -0,0 +1,130 @@
1
+ import { SyntaxKind } from "typescript/unstable/ast";
2
+ import * as is from "typescript/unstable/ast/is";
3
+ import { SchemaConverter } from "./converter.js";
4
+ /**
5
+ * Find the parameters type node on a service class.
6
+ *
7
+ * Two shapes are accepted, matching `getSchemaNode`:
8
+ *
9
+ * - `class S extends Service<SParameters>` — the type argument
10
+ * - `class S<T extends SParameters> extends Service<T>` — the constraint
11
+ *
12
+ * The base chain is walked because a service commonly names its parameters on
13
+ * an intermediate class rather than on itself.
14
+ * @param declaration - the service class
15
+ * @param checker - the checker resolving base types
16
+ * @param project - project used to resolve declaration handles
17
+ * @param base - name of the type the parameters must derive from
18
+ * @returns the type node, or undefined when the class declares none
19
+ */
20
+ export function findParametersNode(declaration, checker, project, base = "ServiceParameters") {
21
+ for (const cls of classChain(declaration, checker, project)) {
22
+ for (const clause of cls.heritageClauses ?? []) {
23
+ if (clause.token !== SyntaxKind.ExtendsKeyword)
24
+ continue;
25
+ for (const heritage of clause.types) {
26
+ for (const argument of heritage.typeArguments ?? []) {
27
+ if (derivesFrom(checker.getTypeFromTypeNode(argument), base, checker))
28
+ return argument;
29
+ }
30
+ }
31
+ }
32
+ for (const parameter of cls.typeParameters ?? []) {
33
+ const constraint = parameter.constraint;
34
+ if (constraint && derivesFrom(checker.getTypeFromTypeNode(constraint), base, checker))
35
+ return constraint;
36
+ }
37
+ }
38
+ return undefined;
39
+ }
40
+ /**
41
+ * Generate a service's `Schema` entry.
42
+ * @param declaration - the service class
43
+ * @param options - checker, project and post-processing switches
44
+ * @returns the schema, or undefined when the service declares no parameters
45
+ */
46
+ export function generateServiceSchema(declaration, options) {
47
+ const node = findParametersNode(declaration, options.checker, options.project, options.parametersBase);
48
+ if (!node)
49
+ return undefined;
50
+ const converter = new SchemaConverter({ project: options.project, checker: options.checker, mode: "input" });
51
+ const schema = converter.fromNode(node);
52
+ // Both of these are applied after the recursive key sort in the TypeScript 6
53
+ // pipeline, so they land at the end of their objects. `webda.module.json` is
54
+ // compared by value, not by key order, but the same order is kept here so a
55
+ // textual diff of the artefact stays clean.
56
+ if (options.addOpenApi) {
57
+ schema.properties ??= {};
58
+ schema.properties.openapi = { type: "object", additionalProperties: true };
59
+ }
60
+ if (options.title)
61
+ schema.title = options.title;
62
+ return schema;
63
+ }
64
+ /**
65
+ * A class declaration and each class it derives from, nearest first.
66
+ *
67
+ * Keyed on declaration rather than name: `class Store extends Store` is
68
+ * ordinary in Webda, and a name-keyed guard stops the walk one link short.
69
+ * @param declaration - the starting class
70
+ * @param checker - the checker resolving base types
71
+ * @param project - project used to resolve declaration handles
72
+ * @returns the class declarations in the chain
73
+ */
74
+ function classChain(declaration, checker, project) {
75
+ const chain = [];
76
+ const seen = new Set();
77
+ let current = declaration;
78
+ while (current && !seen.has(current) && chain.length < 64) {
79
+ seen.add(current);
80
+ chain.push(current);
81
+ const symbol = current.name ? checker.getSymbolAtLocation(current.name) : undefined;
82
+ const declared = symbol ? checker.getDeclaredTypeOfSymbol(symbol) : undefined;
83
+ const baseType = declared?.isClassOrInterface() ? checker.getBaseTypes(declared)[0] : undefined;
84
+ current = baseType ? resolveClass(baseType, project) : undefined;
85
+ }
86
+ return chain;
87
+ }
88
+ /**
89
+ * Whether a type is, or derives from, a named class.
90
+ * @param type - the type to test
91
+ * @param name - the base class name
92
+ * @param checker - the checker resolving base types
93
+ * @returns true on a match
94
+ */
95
+ function derivesFrom(type, name, checker) {
96
+ const seen = new Set();
97
+ const queue = [type];
98
+ while (queue.length > 0) {
99
+ const current = queue.shift();
100
+ if (seen.has(current.id))
101
+ continue;
102
+ seen.add(current.id);
103
+ const symbol = current.getSymbol();
104
+ if (symbol?.name === name)
105
+ return true;
106
+ // `Service<StoreParameters<T>>` hands back an instantiated reference, and
107
+ // an instantiated reference reports no base types of its own. Re-resolving
108
+ // through the symbol reaches the generic target, which does — without this
109
+ // a generic parameters class silently falls back to the base
110
+ // `ServiceParameters` and emits the wrong schema.
111
+ const declared = symbol ? checker.getDeclaredTypeOfSymbol(symbol) : current;
112
+ const walkable = declared.isClassOrInterface() ? declared : current;
113
+ if (!walkable.isClassOrInterface())
114
+ continue;
115
+ queue.push(...checker.getBaseTypes(walkable));
116
+ }
117
+ return false;
118
+ }
119
+ /**
120
+ * The class declaration behind a type, if it has one.
121
+ * @param type - the type
122
+ * @param project - project used to resolve the declaration handle
123
+ * @returns the class declaration
124
+ */
125
+ function resolveClass(type, project) {
126
+ const symbol = type.getSymbol();
127
+ const node = symbol?.valueDeclaration?.resolve(project) ?? symbol?.declarations[0]?.resolve(project);
128
+ return node && is.isClassDeclaration(node) ? node : undefined;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Q,GAAS,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAClF,MAAM,QAAQ,GAAG,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;QACpE,IAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE;YAAE,SAAS;QAC7C,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,IAAU,EAAE,OAAgB;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,MAAM,EAAE,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACrG,OAAO,IAAI,IAAI,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The JSON Schema subset Webda actually emits, plus the failure type.
3
+ *
4
+ * Measured across core, models, runtime and sample-app the committed corpus is
5
+ * 4,154 nodes using twelve keywords — no `oneOf`, no `not`, no
6
+ * `patternProperties`, no conditionals. The index signature is still open
7
+ * because JSDoc tags can introduce arbitrary keywords (see `annotations.ts`).
8
+ */
9
+ /** A JSON Schema draft-07 document or subschema. */
10
+ export interface JSONSchema7 {
11
+ $schema?: string;
12
+ $ref?: string;
13
+ $id?: string;
14
+ $comment?: string;
15
+ title?: string;
16
+ description?: string;
17
+ default?: unknown;
18
+ const?: unknown;
19
+ enum?: unknown[];
20
+ type?: string | string[];
21
+ format?: string;
22
+ properties?: Record<string, JSONSchema7>;
23
+ required?: string[];
24
+ additionalProperties?: boolean | JSONSchema7;
25
+ items?: JSONSchema7 | JSONSchema7[];
26
+ minItems?: number;
27
+ maxItems?: number;
28
+ anyOf?: JSONSchema7[];
29
+ allOf?: JSONSchema7[];
30
+ not?: JSONSchema7;
31
+ definitions?: Record<string, JSONSchema7>;
32
+ contentEncoding?: string;
33
+ contentMediaType?: string;
34
+ pattern?: string;
35
+ readOnly?: boolean;
36
+ /** JSDoc tags can set arbitrary keywords. */
37
+ [keyword: string]: unknown;
38
+ }
39
+ /**
40
+ * Raised when a type cannot be converted.
41
+ *
42
+ * The stage 7 plan makes this the load-bearing part of the design. Every bug
43
+ * found while porting stages 4 to 6 produced plausible output that
44
+ * type-checked; for a schema the same failure is worse, because valid JSON
45
+ * that describes the wrong contract validates real payloads against it and
46
+ * nothing complains. So there is no best-effort path: an unconvertible type
47
+ * stops generation and names itself.
48
+ */
49
+ export declare class SchemaConversionError extends Error {
50
+ /** Schema path where conversion failed, e.g. `/MyParams/store`. */
51
+ readonly path: string;
52
+ /** The type as the checker prints it. */
53
+ readonly typeName: string;
54
+ /**
55
+ * @param message - what could not be converted
56
+ * @param path - schema path of the offending property
57
+ * @param typeName - stringified type
58
+ */
59
+ constructor(message: string, path: string, typeName: string);
60
+ }
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE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
+ * Measured across core, models, runtime and sample-app the committed corpus is
5
+ * 4,154 nodes using twelve keywords — no `oneOf`, no `not`, no
6
+ * `patternProperties`, no conditionals. The index signature is still open
7
+ * because JSDoc tags can introduce arbitrary keywords (see `annotations.ts`).
8
+ */
9
+ /**
10
+ * Raised when a type cannot be converted.
11
+ *
12
+ * The stage 7 plan makes this the load-bearing part of the design. Every bug
13
+ * found while porting stages 4 to 6 produced plausible output that
14
+ * type-checked; for a schema the same failure is worse, because valid JSON
15
+ * that describes the wrong contract validates real payloads against it and
16
+ * nothing complains. So there is no best-effort path: an unconvertible type
17
+ * stops generation and names itself.
18
+ */
19
+ export class SchemaConversionError extends Error {
20
+ /** Schema path where conversion failed, e.g. `/MyParams/store`. */
21
+ path;
22
+ /** The type as the checker prints it. */
23
+ typeName;
24
+ /**
25
+ * @param message - what could not be converted
26
+ * @param path - schema path of the offending property
27
+ * @param typeName - stringified type
28
+ */
29
+ constructor(message, path, typeName) {
30
+ super(`${message} at ${path} (type ${typeName})`);
31
+ this.name = "SchemaConversionError";
32
+ this.path = path;
33
+ this.typeName = typeName;
34
+ }
35
+ }
36
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/schema/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiCH;;;;;;;;;GASG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,mEAAmE;IAC1D,IAAI,CAAS;IACtB,yCAAyC;IAChC,QAAQ,CAAS;IAE1B;;;;OAIG;IACH,YAAY,OAAe,EAAE,IAAY,EAAE,QAAgB;QACzD,KAAK,CAAC,GAAG,OAAO,OAAO,IAAI,UAAU,QAAQ,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=worker-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-cli.d.ts","sourceRoot":"","sources":["../../src/schema/worker-cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Entry point for the schema worker; see `./worker.ts` for the protocol.
4
+ */
5
+ import { main } from "./worker.js";
6
+ await main();
7
+ //# sourceMappingURL=worker-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-cli.js","sourceRoot":"","sources":["../../src/schema/worker-cli.ts"],"names":[],"mappings":";AACA;;GAEG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,MAAM,IAAI,EAAE,CAAC"}