@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,567 @@
1
+ /**
2
+ * Accessor generator — the typed replacement for `createAccessorTransformer`
3
+ * and `createDeclarationAccessorTransformer`.
4
+ *
5
+ * Handles all three coercion kinds from
6
+ * `packages/ts-plugin/src/transforms/accessors.ts`:
7
+ *
8
+ * | kind | trigger | generated |
9
+ * |------------------------|-------------------------------------------|-----------|
10
+ * | `builtin` | type name in the coercion registry (Date) | asymmetric accessor pair |
11
+ * | `set-method` | type has a `@WebdaAutoSetter` `set(...)` | asymmetric accessor pair |
12
+ * | `relation-initializer` | type resolves to `ModelRelated` | readonly initializer |
13
+ *
14
+ * The first two emit *asymmetric accessors*, which are ordinary TypeScript, so
15
+ * any compiler produces the right `.js` and `.d.ts` with no plugin.
16
+ */
17
+ import { SymbolFlags } from "typescript/unstable/sync";
18
+ import * as is from "typescript/unstable/ast/is";
19
+ import { DEFAULT_COERCIONS } from "../coercions.js";
20
+ import { classesOf, isStatic, memberName } from "../context.js";
21
+ import { ValueImports } from "./imports.js";
22
+ /**
23
+ * How to coerce each registry type at runtime.
24
+ *
25
+ * Which types coerce, and the widened setter type they accept, comes from
26
+ * {@link DEFAULT_COERCIONS} so that this generator, `@webda/compiler` and the
27
+ * language service cannot drift apart. Only the runtime coercion expression —
28
+ * which is meaningless outside code generation — lives here.
29
+ */
30
+ const COERCE_EXPRESSIONS = {
31
+ Date: v => `new Date(${v} as string | number | Date)`
32
+ };
33
+ const BUILTINS = Object.fromEntries(Object.entries(DEFAULT_COERCIONS)
34
+ .filter(([name]) => COERCE_EXPRESSIONS[name])
35
+ .map(([name, rule]) => [name, { setterType: rule.setterType, coerce: COERCE_EXPRESSIONS[name] }]));
36
+ /** Class names treated as model bases. */
37
+ const MODEL_BASES = new Set(["Model", "UuidModel", "CoreModel"]);
38
+ /**
39
+ * Whether a class is a model, following the base chain through the checker.
40
+ *
41
+ * The direct `extends` clause is not enough. In `@webda/core`, `Ident extends
42
+ * OwnerModel` and `SimpleUser extends User` are both models, several links away
43
+ * from `UuidModel`; matching only the written base name silently skips them and
44
+ * their fields are never coerced. The chain is walked with the checker so it also
45
+ * crosses package boundaries into `@webda/models`.
46
+ * @param ctx - analysis context
47
+ * @param sf - file declaring the class
48
+ * @param cls - the class declaration
49
+ * @returns true when the class derives from a known model base
50
+ */
51
+ function isModelClass(ctx, sf, cls) {
52
+ // Cheap syntactic hit first: most models name a known base directly.
53
+ if (ctx.baseNames(sf, cls).some(b => MODEL_BASES.has(b)))
54
+ return true;
55
+ // `getTypeAtLocation` on a class declaration yields the static side, whose
56
+ // base types are constructor types — the instance chain is what we need.
57
+ const symbol = cls.name ? ctx.checker.getSymbolAtLocation(cls.name) : undefined;
58
+ const declared = symbol ? ctx.checker.getDeclaredTypeOfSymbol(symbol) : undefined;
59
+ if (!declared)
60
+ return false;
61
+ const seen = new Set();
62
+ const queue = [declared];
63
+ while (queue.length) {
64
+ const type = queue.shift();
65
+ if (!type)
66
+ continue;
67
+ const symbol = type.getSymbol?.() ?? type.symbol;
68
+ const name = symbol?.name;
69
+ if (name && MODEL_BASES.has(name))
70
+ return true;
71
+ // Keyed by declaration: a model may legitimately share its base's name,
72
+ // e.g. sample-app's `User extends User` from `@webda/core`. Guarding on the
73
+ // name alone stops the walk one link short and the class is never detected.
74
+ const declaration = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
75
+ const owner = declaration?.resolve(ctx.project);
76
+ const file = owner?.getSourceFile?.()?.fileName ?? owner?._sourceFile?.fileName ?? "";
77
+ const key = name ? `${name}@${file}` : type;
78
+ if (seen.has(key))
79
+ continue;
80
+ seen.add(key);
81
+ // Guard against pathological hierarchies rather than trusting the graph.
82
+ if (seen.size > 64)
83
+ return false;
84
+ // `getBaseTypes()` hands back instantiated references whose own bases are
85
+ // empty, so a generic link such as `AbstractOwnerModel<T> extends UuidModel`
86
+ // terminates the walk. Re-resolving each base through its symbol gets the
87
+ // declared type, which does carry the next link.
88
+ const resolved = symbol ? (ctx.checker.getDeclaredTypeOfSymbol(symbol) ?? type) : type;
89
+ for (const base of resolved.getBaseTypes?.() ?? type.getBaseTypes?.() ?? [])
90
+ queue.push(base);
91
+ }
92
+ return false;
93
+ }
94
+ /** Runtime class name that needs an initializer rather than an accessor. */
95
+ const RELATION_CONTAINER = "ModelRelated";
96
+ /**
97
+ * Follow a type to the class that actually implements it, so aliases like
98
+ * `ManyToOne<T>` resolve to `ModelLink` and `OneToMany<T>` to `ModelRelated`.
99
+ * @param ctx - analysis context
100
+ * @param typeNode - the property's type node
101
+ * @returns the resolved class name, if any
102
+ */
103
+ function resolveRuntimeClass(ctx, typeNode) {
104
+ const type = ctx.checker.getTypeFromTypeNode(typeNode);
105
+ if (!type)
106
+ return undefined;
107
+ const symbol = type.getSymbol?.() ?? type.symbol;
108
+ const name = symbol?.name;
109
+ if (name && name !== "__type")
110
+ return name;
111
+ // Fall back to the printed type, taking the head of `Foo<Bar>`.
112
+ const printed = ctx.checker.typeToString(type);
113
+ const head = /^([A-Za-z_$][\w$]*)/.exec(printed)?.[1];
114
+ return head;
115
+ }
116
+ /**
117
+ * Find a `set` method tagged `@WebdaAutoSetter` on the property's type and
118
+ * return its parameter type as a string.
119
+ * @param ctx - analysis context
120
+ * @param typeNode - the property's type node
121
+ * @returns the widened parameter type, if the tag is present
122
+ */
123
+ function autoSetterParamType(ctx, typeNode) {
124
+ const type = ctx.checker.getTypeFromTypeNode(typeNode);
125
+ if (!type)
126
+ return undefined;
127
+ const setSymbol = ctx.checker.getPropertyOfType(type, "set");
128
+ if (!setSymbol)
129
+ return undefined;
130
+ const decl = setSymbol.valueDeclaration ?? setSymbol.declarations?.[0];
131
+ const node = decl?.resolve(ctx.project);
132
+ if (!node)
133
+ return undefined;
134
+ const owner = node.getSourceFile?.() ?? node._sourceFile;
135
+ if (!owner || !/@WebdaAutoSetter\b/.test(ctx.triviaOf(owner, node)))
136
+ return undefined;
137
+ const setType = ctx.checker.getTypeOfSymbol(setSymbol);
138
+ if (!setType)
139
+ return undefined;
140
+ // 0 === SignatureKind.Call
141
+ const sigs = ctx.checker.getSignaturesOfType(setType, 0);
142
+ if (!sigs.length)
143
+ return undefined;
144
+ const param = ctx.checker.getParameterType(sigs[0], 0);
145
+ return param ? ctx.checker.typeToString(param) : undefined;
146
+ }
147
+ /**
148
+ * Whether a name reaches this file only through a type-only import.
149
+ *
150
+ * `import type { Team }` is erased at emit, so referencing `Team` as a value
151
+ * produces TS1361. `Checker.resolveName` still resolves it — it answers about
152
+ * the symbol, not about what survives emit — so the import form has to be
153
+ * inspected directly.
154
+ * @param sf - the file that will contain the generated reference
155
+ * @param name - identifier to be used as a value
156
+ * @returns true when the name is imported for types only
157
+ */
158
+ function isTypeOnlyImport(sf, name) {
159
+ for (const statement of sf.statements) {
160
+ if (!is.isImportDeclaration(statement))
161
+ continue;
162
+ const clause = statement.importClause;
163
+ if (!clause)
164
+ continue;
165
+ const bindings = clause.namedBindings;
166
+ if (!bindings?.elements)
167
+ continue;
168
+ for (const element of bindings.elements) {
169
+ if (element.name?.text !== name)
170
+ continue;
171
+ if (clause.isTypeOnly || element.isTypeOnly)
172
+ return true;
173
+ }
174
+ }
175
+ return false;
176
+ }
177
+ /**
178
+ * Whether every identifier a generated snippet references is usable here.
179
+ *
180
+ * The emit-time transformer erased types, so a printed type could name classes
181
+ * the file never imported and nothing noticed. Generated *source* is checked,
182
+ * so `set x(value: string | Classroom | ...)` is TS2304 when `Classroom` is not
183
+ * in scope, and `new BinariesImpl()` is TS2304 when the file imports the public
184
+ * alias instead of the implementation.
185
+ *
186
+ * Conservative on purpose: anything not clearly resolvable means the property
187
+ * is skipped and keeps today's behaviour.
188
+ * @param ctx - analysis context
189
+ * @param sf - file the snippet will live in
190
+ * @param snippet - generated text to check
191
+ * @param location - node used for scope resolution
192
+ * @param provided - names the caller has just made available through imports
193
+ * @returns true when every referenced name resolves
194
+ */
195
+ function referencesResolve(ctx, sf, snippet, location, provided = new Set()) {
196
+ const skip = new Set([
197
+ "string",
198
+ "number",
199
+ "boolean",
200
+ "any",
201
+ "unknown",
202
+ "never",
203
+ "void",
204
+ "null",
205
+ "undefined",
206
+ "object",
207
+ "symbol",
208
+ "bigint",
209
+ "this",
210
+ "value",
211
+ "readonly",
212
+ "get",
213
+ "set",
214
+ "new",
215
+ "return",
216
+ "if",
217
+ "else",
218
+ "const",
219
+ "instanceof",
220
+ "true",
221
+ "false",
222
+ "Date",
223
+ "Record",
224
+ "Array",
225
+ "Promise",
226
+ // Injected by this generator, so not yet resolvable in the authored text.
227
+ "WEBDA_STORAGE"
228
+ ]);
229
+ for (const match of snippet.matchAll(/\b[A-Z][\w$]*\b/g)) {
230
+ const name = match[0];
231
+ if (skip.has(name) || provided.has(name))
232
+ continue;
233
+ // A type-only import is legitimate inside a type annotation, so the test is
234
+ // simply whether the name means anything here at all. Value positions are
235
+ // checked separately by the caller, where the distinction matters.
236
+ const asValue = ctx.checker.resolveName(name, SymbolFlags.Value, location);
237
+ const asType = ctx.checker.resolveName(name, SymbolFlags.Type, location);
238
+ if (!asValue && !asType)
239
+ return false;
240
+ }
241
+ return true;
242
+ }
243
+ /**
244
+ * How many parameters the runtime class's constructor declares.
245
+ *
246
+ * Read from the property's *type*, not by looking the class name up in the
247
+ * file: `BelongTo<User>` resolves to `ModelLink`, which the file usually does
248
+ * not import at all.
249
+ * @param ctx - analysis context
250
+ * @param typeNode - the property's type node
251
+ * @returns the largest declared parameter count, or undefined
252
+ */
253
+ function constructorParameterCount(ctx, typeNode) {
254
+ const symbol = ctx.checker.getTypeFromTypeNode(typeNode)?.getSymbol?.();
255
+ if (!symbol || !(symbol.flags & SymbolFlags.Class))
256
+ return undefined;
257
+ const ctorType = ctx.checker.getTypeOfSymbol(symbol);
258
+ // 1 === SignatureKind.Construct
259
+ const counts = ctx.checker.getSignaturesOfType(ctorType, 1).map(sig => sig.parameters.length);
260
+ return counts.length ? Math.max(...counts) : undefined;
261
+ }
262
+ /**
263
+ * The runtime class a type argument names, falling back from a type parameter.
264
+ *
265
+ * On a generic class the written argument can be a type parameter, which does
266
+ * not exist at runtime — `new ModelLink(T)` is a ReferenceError on first use,
267
+ * and it is exactly what the TypeScript 6 transformer emits for
268
+ * `AbstractOwnerModel<T extends User>`. The parameter's default, then its
269
+ * constraint, is the most specific class that does exist.
270
+ * @param ctx - analysis context
271
+ * @param arg - the type argument
272
+ * @returns a class name, or undefined
273
+ */
274
+ function runtimeClassOf(ctx, arg) {
275
+ if (arg?.isTypeParameter?.()) {
276
+ arg =
277
+ ctx.checker.getDefaultFromTypeParameter?.(arg) ??
278
+ ctx.checker.getConstraintOfTypeParameter?.(arg) ??
279
+ undefined;
280
+ }
281
+ const name = arg?.getSymbol?.()?.name;
282
+ return name && /^[A-Za-z_$][\w$]*$/.test(name) ? name : undefined;
283
+ }
284
+ /**
285
+ * Constructor arguments for a relation class, derived from its type arguments.
286
+ *
287
+ * Decided by the kind of coercion, as the TypeScript 6 transformer decides it
288
+ * — not by constructor arity, which the 7.1 API does not report reliably
289
+ * (`minArgumentCount` is absent, so defaulted parameters count as required):
290
+ *
291
+ * - set-method (`ModelLink<T>`, `ModelLinksSimpleArray<T>`, ...): `(Target)`
292
+ * - relation container (`ModelRelated<Target, Owner, "attribute">`):
293
+ * `(Target, this)`, plus the attribute when the author wrote one — a
294
+ * defaulted third parameter resolves to `""`, which is not what was written
295
+ * @param ctx - analysis context
296
+ * @param typeNode - the property's type node
297
+ * @param kind - which coercion is being generated
298
+ * @returns the arguments, or undefined when the target cannot be named
299
+ */
300
+ function constructorArguments(ctx, typeNode, kind) {
301
+ // A class whose constructor declares no parameters takes no arguments.
302
+ // Parameter *count* is reliable in 7.1 where the minimum arity is not.
303
+ if (constructorParameterCount(ctx, typeNode) === 0)
304
+ return { text: "", values: [] };
305
+ const type = ctx.checker.getTypeFromTypeNode(typeNode);
306
+ const args = type?.isTypeReference?.() ? ctx.checker.getTypeArguments(type) : [];
307
+ // The name as written, when it is a plain identifier naming a class: a
308
+ // default export's symbol is called `default`, which is not what the file
309
+ // binds it to. The symbol is only consulted for a type parameter, whose
310
+ // written name does not exist at runtime — and only when it provably names
311
+ // the same class as the resolved argument, since an alias may reorder its
312
+ // parameters.
313
+ const written = typeNode?.typeArguments?.[0];
314
+ const writtenName = written && is.isTypeReferenceNode(written) ? written.typeName?.text : undefined;
315
+ const resolvedSymbol = args[0]?.isTypeParameter?.() ? undefined : args[0]?.getSymbol?.();
316
+ const sameClass = !!resolvedSymbol &&
317
+ (resolvedSymbol.flags & SymbolFlags.Class) !== 0 &&
318
+ (resolvedSymbol.name === writtenName || resolvedSymbol.name === "default");
319
+ const target = writtenName && sameClass ? writtenName : runtimeClassOf(ctx, args[0]);
320
+ if (!target || target === "default")
321
+ return undefined;
322
+ if (kind === "set-method")
323
+ return { text: target, values: [target] };
324
+ const writtenCount = typeNode?.typeArguments?.length ?? 0;
325
+ if (writtenCount <= 2)
326
+ return { text: `${target}, this`, values: [target] };
327
+ if (!args[2]?.isStringLiteralType?.())
328
+ return undefined;
329
+ return { text: `${target}, this, ${JSON.stringify(args[2].value)}`, values: [target] };
330
+ }
331
+ /**
332
+ * Indentation of the line containing an offset.
333
+ * @param text - file text
334
+ * @param offset - offset within the line
335
+ * @returns leading whitespace
336
+ */
337
+ function indentAt(text, offset) {
338
+ const lineStart = text.lastIndexOf("\n", offset - 1) + 1;
339
+ const prefix = text.slice(lineStart, offset);
340
+ return /^[ \t]*$/.test(prefix) ? prefix : " ";
341
+ }
342
+ /**
343
+ * Render the generated members for one resolved property.
344
+ * @param r - the resolved coercion
345
+ * @returns generated TypeScript source
346
+ */
347
+ function render(r) {
348
+ const slot = `this[WEBDA_STORAGE][${JSON.stringify(r.name)}]`;
349
+ const i = r.indent;
350
+ if (r.kind === "relation-initializer") {
351
+ // Not assignable, so no accessor pair — just a readonly initialised field.
352
+ return `readonly ${r.name}: ${r.typeText} = new ${r.runtimeClass}(${r.ctorArg ?? ""}) as ${r.typeText};`;
353
+ }
354
+ const lines = [];
355
+ lines.push(`get ${r.name}(): ${r.typeText} {`);
356
+ lines.push(r.defaultExpr === undefined ? `${i} return ${slot};` : `${i} return ${slot} ?? ${r.defaultExpr};`);
357
+ lines.push(`${i}}`);
358
+ lines.push(`${i}set ${r.name}(value: ${r.setterType}) {`);
359
+ if (r.kind === "builtin") {
360
+ lines.push(`${i} ${slot} = value !== undefined && value !== null ? ${r.coerce("value")} : value;`);
361
+ }
362
+ else {
363
+ // The TypeScript 6 transformer's exact structure, so the emit-parity
364
+ // oracle proves equivalence instead of it being argued. `null` /
365
+ // `undefined` clear the relation rather than being wrapped in a new one.
366
+ lines.push(`${i} if (value instanceof ${r.runtimeClass}) {`);
367
+ lines.push(`${i} ${slot} = value;`);
368
+ lines.push(`${i} } else if (value != null) {`);
369
+ lines.push(`${i} const inst: ${r.typeText} = ${slot} || new ${r.runtimeClass}(${r.ctorArg ?? ""});`);
370
+ lines.push(`${i} inst.set(value as any);`);
371
+ lines.push(`${i} ${slot} = inst;`);
372
+ lines.push(`${i} } else {`);
373
+ lines.push(`${i} ${slot} = value;`);
374
+ lines.push(`${i} }`);
375
+ }
376
+ lines.push(`${i}}`);
377
+ return lines.join("\n");
378
+ }
379
+ /**
380
+ * The `toJSON` the TypeScript 6 transformer injected, as source.
381
+ *
382
+ * Own properties first, then the storage slot, over whatever the parent
383
+ * produced — so a subclass of a class that already merges storage is
384
+ * unaffected, and the order matches what ships today. One deliberate
385
+ * departure: when the parent hands back the instance itself, as
386
+ * `Model.toJSON()` does, a fresh object is used instead.
387
+ * @param i - indentation of the class members
388
+ * @returns the method source, framed by newlines
389
+ */
390
+ function renderToJson(i) {
391
+ return [
392
+ "",
393
+ `${i}/** Generated by @webda/content-mapper: include values held in WEBDA_STORAGE. */`,
394
+ `${i}toJSON(): any {`,
395
+ // `as unknown` keeps the runtime check — a base may not define toJSON —
396
+ // without TS2774 under `strict`.
397
+ `${i} const parent: any = (super.toJSON as unknown) ? super.toJSON() : {};`,
398
+ // `Model.toJSON()` returns `this`: merging into it would only re-run the
399
+ // setters, and the accessors would still be invisible to JSON.stringify.
400
+ `${i} const result: any = parent === this ? {} : parent;`,
401
+ `${i} for (const key of Object.keys(this)) {`,
402
+ `${i} result[key] = (this as any)[key];`,
403
+ `${i} }`,
404
+ `${i} Object.assign(result, (this as any)[WEBDA_STORAGE]);`,
405
+ `${i} return result;`,
406
+ `${i}}`,
407
+ ""
408
+ ].join("\n");
409
+ }
410
+ /**
411
+ * Create the accessor generator.
412
+ * @param options - generator options
413
+ * @returns a generator
414
+ */
415
+ export function accessorsGenerator(options = {}) {
416
+ const storageModule = options.storageModule ?? "@webda/models";
417
+ return {
418
+ name: "accessors",
419
+ analyze(ctx) {
420
+ const out = [];
421
+ for (const sf of ctx.sourceFiles) {
422
+ const edits = [];
423
+ const imports = new ValueImports(ctx, sf, "accessors");
424
+ let needsStorage = false;
425
+ for (const cls of classesOf(sf)) {
426
+ const eligible = options.accessorsForAll || isModelClass(ctx, sf, cls);
427
+ if (!eligible)
428
+ continue;
429
+ let transformed = false;
430
+ // Never clobber an explicitly written accessor.
431
+ const existing = new Set();
432
+ for (const m of cls.members) {
433
+ if (is.isGetAccessorDeclaration(m) || is.isSetAccessorDeclaration(m)) {
434
+ const n = memberName(m);
435
+ if (n)
436
+ existing.add(n);
437
+ }
438
+ }
439
+ for (const m of cls.members) {
440
+ if (!is.isPropertyDeclaration(m) || isStatic(m))
441
+ continue;
442
+ const name = memberName(m);
443
+ if (!name || existing.has(name))
444
+ continue;
445
+ if (!m.type)
446
+ continue;
447
+ // An initialiser is preserved by moving it into the getter as a
448
+ // fallback. The observable trade-off is that an explicit
449
+ // `undefined` now reads back as the default.
450
+ const initializer = m.initializer;
451
+ const defaultExpr = initializer ? ctx.textOf(sf, initializer) : undefined;
452
+ const typeText = ctx.textOf(sf, m.type);
453
+ const start = m.getStart();
454
+ const indent = indentAt(sf.text, start);
455
+ const head = /^([A-Za-z_$][\w$]*)/.exec(typeText)?.[1] ?? typeText;
456
+ let resolved;
457
+ const builtin = BUILTINS[head];
458
+ if (builtin) {
459
+ resolved = {
460
+ name,
461
+ typeText,
462
+ kind: "builtin",
463
+ setterType: builtin.setterType,
464
+ coerce: builtin.coerce,
465
+ defaultExpr,
466
+ start,
467
+ end: m.end,
468
+ indent
469
+ };
470
+ }
471
+ else {
472
+ const runtimeClass = resolveRuntimeClass(ctx, m.type);
473
+ if (runtimeClass === RELATION_CONTAINER) {
474
+ const ctor = constructorArguments(ctx, m.type, "relation-initializer");
475
+ // An author-written initialiser wins for a readonly field.
476
+ if (defaultExpr !== undefined || !ctor)
477
+ continue;
478
+ resolved = {
479
+ name,
480
+ typeText,
481
+ kind: "relation-initializer",
482
+ runtimeClass,
483
+ ctorArg: ctor.text,
484
+ ctorValues: ctor.values,
485
+ start,
486
+ end: m.end,
487
+ indent
488
+ };
489
+ }
490
+ else {
491
+ const param = autoSetterParamType(ctx, m.type);
492
+ const ctor = param && runtimeClass ? constructorArguments(ctx, m.type, "set-method") : undefined;
493
+ if (param && runtimeClass && ctor) {
494
+ resolved = {
495
+ name,
496
+ typeText,
497
+ kind: "set-method",
498
+ setterType: `${param} | ${typeText}`,
499
+ runtimeClass,
500
+ ctorArg: ctor.text,
501
+ ctorValues: ctor.values,
502
+ defaultExpr,
503
+ start,
504
+ end: m.end,
505
+ indent
506
+ };
507
+ }
508
+ }
509
+ }
510
+ if (!resolved)
511
+ continue;
512
+ const rendered = render(resolved);
513
+ // Whatever the generated members construct or test with
514
+ // `instanceof` must survive emit as a value. Promoted or added
515
+ // imports are rolled back if any name cannot be made available, so
516
+ // a skipped property leaves nothing behind.
517
+ const rollback = imports.checkpoint();
518
+ const runtimeNames = [resolved.runtimeClass, ...(resolved.ctorValues ?? [])].filter(Boolean);
519
+ // `BelongTo<User>` names the alias; the module that exports it is
520
+ // where `ModelLink` is looked for.
521
+ const via = [head, ...new Set(typeText.match(/[A-Za-z_$][\w$]*/g) ?? [])];
522
+ // Then everything else they mention must already exist here. The
523
+ // runtime names were just made available, so they count.
524
+ // Types the printed setter signature names but the file lacks
525
+ // (`PrimaryKeyType<User>`) get an erased `import type`.
526
+ const typeNames = [...new Set(resolved.setterType?.match(/\b[A-Z][\w$]*\b/g) ?? [])];
527
+ if (!runtimeNames.every(runtime => imports.ensure(runtime, m, via)) ||
528
+ !typeNames.every(typeName => runtimeNames.includes(typeName) || imports.ensureType(typeName, m, via)) ||
529
+ !referencesResolve(ctx, sf, rendered, m, new Set([...runtimeNames, ...typeNames]))) {
530
+ rollback();
531
+ continue;
532
+ }
533
+ if (resolved.kind !== "relation-initializer")
534
+ needsStorage = true;
535
+ transformed = true;
536
+ edits.push({ start, end: m.end, text: rendered, source: "accessors" });
537
+ }
538
+ // Any class this generator touched gets the TypeScript 6
539
+ // transformer's `toJSON`, unless it declares one. It is not
540
+ // optional: `Model.toJSON()` returns `this`, `JSON.stringify` skips
541
+ // the symbol-keyed storage, and without this every generated
542
+ // accessor's value would be silently dropped from serialisation.
543
+ if (transformed && !cls.members.some((member) => memberName(member) === "toJSON")) {
544
+ needsStorage = true;
545
+ const close = cls.end - 1;
546
+ const indent = indentAt(sf.text, cls.members[0]?.getStart?.() ?? close);
547
+ edits.push({ start: close, end: close, text: renderToJson(indent), source: "accessors" });
548
+ }
549
+ }
550
+ if (edits.length) {
551
+ edits.push(...imports.collect());
552
+ if (needsStorage && !new RegExp(`\\bWEBDA_STORAGE\\b`).test(sf.text)) {
553
+ edits.push({
554
+ start: 0,
555
+ end: 0,
556
+ text: `import { WEBDA_STORAGE } from ${JSON.stringify(storageModule)};\n`,
557
+ source: "accessors"
558
+ });
559
+ }
560
+ out.push({ fileName: sf.fileName, edits });
561
+ }
562
+ }
563
+ return out;
564
+ }
565
+ };
566
+ }
567
+ //# sourceMappingURL=accessors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessors.js","sourceRoot":"","sources":["../../src/generators/accessors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ5C;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAA0C;IAChE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,6BAA6B;CACtD,CAAC;AAEF,MAAM,QAAQ,GAAgC,MAAM,CAAC,WAAW,CAC9D,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;KAC9B,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EA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ACpB,CAAC,CAAC;oBACL,CAAC;oBACD,GAAG,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;YAED,OAAO,GAAG,CAAC;QACb,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Generator } from "../plan.ts";
2
+ /**
3
+ * Storage slot backing a Behaviour's `parent` reference.
4
+ *
5
+ * Must match `BEHAVIOR_PARENT_KEY` in `@webda/ts-plugin`: the per-Behaviour
6
+ * `parent` getter reads it and `toJSON` filters it out, so a mismatch silently
7
+ * serialises the parent back into stored data.
8
+ */
9
+ export declare const BEHAVIOR_PARENT_KEY = "__parent__";
10
+ /** Options for the behaviour generator. */
11
+ export interface BehaviorOptions {
12
+ /** Module specifier providing `WEBDA_STORAGE`. */
13
+ storageModule?: string;
14
+ }
15
+ /**
16
+ * Create the behaviour generator.
17
+ * @param options - generator options
18
+ * @returns a generator
19
+ */
20
+ export declare function behaviorsGenerator(options?: BehaviorOptions): Generator;
21
+ //# sourceMappingURL=behaviors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"behaviors.d.ts","sourceRoot":"","sources":["../../src/generators/behaviors.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAoC,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAqLD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,eAAoB,GAAG,SAAS,CAsG3E"}