@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,211 @@
1
+ import type { AnalysisContext } from "./plan.ts";
2
+ /** Sections recorded in `webda.module.json`. */
3
+ export type Section = "models" | "moddas" | "deployers" | "beans";
4
+ /** Structural metadata recorded for a model. */
5
+ export interface ModelMetadata {
6
+ /** Namespaced name, repeated as the entry's own identifier. */
7
+ Identifier: string;
8
+ /** Pluralised display name. */
9
+ Plural: string;
10
+ /** Namespaced ancestors, nearest first. */
11
+ Ancestors: string[];
12
+ /** Namespaced direct subclasses. */
13
+ Subclasses: string[];
14
+ /** Attributes forming the primary key. */
15
+ PrimaryKey: string[];
16
+ /** Separator joining a composite primary key, when declared. */
17
+ PrimaryKeySeparator?: string;
18
+ }
19
+ /** One discovered Webda object. */
20
+ export interface DiscoveredObject {
21
+ /** Namespaced name, as used for the section key. */
22
+ name: string;
23
+ /** Exported identifier. */
24
+ exportName: string;
25
+ /** Section it belongs to. */
26
+ section: Section;
27
+ /** `Import` value: output path without extension, then `:export`. */
28
+ importTarget: string;
29
+ /** File declaring it. */
30
+ fileName: string;
31
+ /** Name of the class as written, before any @Webda* tag renaming. */
32
+ className: string;
33
+ /** Names of the classes it derives from, nearest first. */
34
+ baseNames: string[];
35
+ /** Primary key attributes, when declared. */
36
+ primaryKey: string[];
37
+ /** Primary key separator, when declared. */
38
+ primaryKeySeparator?: string;
39
+ }
40
+ /** Discovery options. */
41
+ export interface DiscoveryOptions {
42
+ /** Application root, used to relativise output paths. */
43
+ appPath: string;
44
+ /** Source root. */
45
+ rootDir: string;
46
+ /** Output root. */
47
+ outDir: string;
48
+ /** Namespace prefix applied to unqualified names. */
49
+ namespace?: string;
50
+ /**
51
+ * Return every classified class, including several resolving to the same
52
+ * namespaced name. The caller then owns deduplication — the module
53
+ * generator reproduces TypeScript 6's last-in-program-order-wins rule.
54
+ */
55
+ keepDuplicates?: boolean;
56
+ }
57
+ /**
58
+ * Name of the npm package that owns a file.
59
+ *
60
+ * Walks up to the nearest `package.json`, matching `getPackageFromType`.
61
+ * @param fileName - file to attribute
62
+ * @returns the package name, when one is found
63
+ */
64
+ export declare function packageOf(fileName: string): string | undefined;
65
+ /**
66
+ * The declared type of a class, and every type it derives from.
67
+ *
68
+ * Each base is re-resolved through its symbol: `getBaseTypes()` returns
69
+ * instantiated references whose own bases are empty, so a generic link
70
+ * otherwise terminates the walk.
71
+ * @param ctx - analysis context
72
+ * @param cls - the class declaration
73
+ * @returns the type chain, nearest first
74
+ */
75
+ export declare function classTree(ctx: AnalysisContext, cls: any): any[];
76
+ /**
77
+ * Whether a type chain contains a given class from a given package.
78
+ * @param ctx - analysis context
79
+ * @param chain - the type chain
80
+ * @param packageName - owning npm package
81
+ * @param symbolName - class name
82
+ * @returns true on a match
83
+ */
84
+ export declare function chainExtends(ctx: AnalysisContext, chain: any[], packageName: string, symbolName: string): boolean;
85
+ /**
86
+ * Output path for a source file, without extension.
87
+ *
88
+ * Mirrors `ts.getOutputFileNames` for the common `rootDir`/`outDir` layout.
89
+ * @param fileName - the source file
90
+ * @param options - discovery options
91
+ * @returns path relative to the application root
92
+ */
93
+ export declare function outputTarget(fileName: string, options: DiscoveryOptions): string;
94
+ /**
95
+ * The name a class is exported under, if any.
96
+ *
97
+ * Mirrors `getExportedName`: a `default` modifier records `"default"` rather
98
+ * than the class name, and a class with no export modifier may still be
99
+ * re-exported by a later `export { X }` — `webda.module.json` records the alias
100
+ * in both cases, so the `Import` string is wrong without this.
101
+ * @param ctx - analysis context
102
+ * @param sf - containing file
103
+ * @param cls - the class declaration
104
+ * @returns the exported name, or undefined when not exported
105
+ */
106
+ export declare function exportedName(ctx: AnalysisContext, sf: any, cls: any): string | undefined;
107
+ /**
108
+ * Discover every Webda object in the project.
109
+ * @param ctx - analysis context
110
+ * @param options - discovery options
111
+ * @returns discovered objects, ordered by section then name
112
+ */
113
+ export declare function discoverWebdaObjects(ctx: AnalysisContext, options: DiscoveryOptions): DiscoveredObject[];
114
+ /**
115
+ * Directory of the npm package that owns a file: the nearest folder with a
116
+ * `package.json`.
117
+ * @param fileName - file to attribute
118
+ * @returns the package directory, when one is found
119
+ */
120
+ export declare function packageRootOf(fileName: string): string | undefined;
121
+ /**
122
+ * Name of a model declared by a dependency package, as its own
123
+ * `webda.module.json` records it.
124
+ *
125
+ * The class is matched on its `Import` target: the declaring file relative to
126
+ * the package, without extension, then `:` and the export name. A source file
127
+ * (`src/x.ts`) also matches its compiled counterpart (`lib/x`).
128
+ * @param fileName - file declaring the class
129
+ * @param className - exported name of the class
130
+ * @param appPath - the project being compiled, whose own module is skipped
131
+ * @returns the namespaced model name, when the dependency declares one
132
+ */
133
+ export declare function dependencyModelName(fileName: string, className: string, appPath: string): string | undefined;
134
+ /**
135
+ * Build the structural half of each model's `webda.module.json` entry.
136
+ *
137
+ * Ancestors and subclasses are resolved among the discovered models, so they
138
+ * carry namespaced names rather than raw class names.
139
+ * @param objects - discovered objects
140
+ * @param plural - pluralisation function, supplied by the host
141
+ * @returns metadata per model name
142
+ */
143
+ export declare function buildModelMetadata(objects: DiscoveredObject[], plural: (name: string) => string): Record<string, ModelMetadata>;
144
+ /** One reflected attribute. */
145
+ export interface ReflectedAttribute {
146
+ /** Type as written in the source. */
147
+ type: string;
148
+ /** Resolved type arguments, when the type is generic. */
149
+ typeParameters?: string[];
150
+ }
151
+ /**
152
+ * Reflect a model's attributes, as `webda.module.json` records them.
153
+ *
154
+ * The recorded type is the *written* text rather than a resolved type: an
155
+ * inline object literal appears verbatim, comments and all. Generic types are
156
+ * the exception — their arguments are resolved through the checker so a type
157
+ * parameter is reported as its constraint.
158
+ *
159
+ * Properties keyed by a symbol, carrying `@ignore`, or marked not-enumerable
160
+ * are excluded, matching the original.
161
+ * @param ctx - analysis context
162
+ * @param sf - file declaring the class
163
+ * @param cls - the class declaration
164
+ * @returns attribute name to reflected type
165
+ */
166
+ export declare function reflectAttributes(ctx: AnalysisContext, sf: any, cls: any): Record<string, ReflectedAttribute>;
167
+ /** Relations recorded for a model. */
168
+ export interface ModelRelations {
169
+ /** Owning model, from a `ModelParent<T>` attribute. */
170
+ parent?: {
171
+ attribute: string;
172
+ model: string;
173
+ };
174
+ /**
175
+ * Outgoing links, from the `ModelLink*` family.
176
+ *
177
+ * `model` is absent when the target is a type parameter, as on a generic
178
+ * base class — the link is still real and is recorded without it.
179
+ */
180
+ links?: {
181
+ attribute: string;
182
+ model?: string;
183
+ type: string;
184
+ }[];
185
+ /** Reverse lookups, from `ModelRelated<T, U, "attr">`. */
186
+ queries?: {
187
+ attribute: string;
188
+ model: string;
189
+ targetAttribute: string;
190
+ }[];
191
+ /** Behaviour-typed attributes. */
192
+ behaviors?: {
193
+ attribute: string;
194
+ behavior: string;
195
+ }[];
196
+ }
197
+ /**
198
+ * Build a model's `Relations` entry.
199
+ *
200
+ * Relation kinds are recognised by the written type name — `ModelParent`,
201
+ * `ModelRelated`, the `ModelLink*` family — and the referenced model is
202
+ * resolved to its namespaced identifier so the graph is expressed in module
203
+ * terms rather than class names.
204
+ * @param ctx - analysis context
205
+ * @param sf - file declaring the class
206
+ * @param cls - the class declaration
207
+ * @param resolveModelId - maps a class name to its namespaced identifier
208
+ * @returns the relations, omitting empty groups
209
+ */
210
+ export declare function buildRelations(ctx: AnalysisContext, sf: any, cls: any, resolveModelId: (className: string) => string | undefined): ModelRelations;
211
+ //# sourceMappingURL=module-discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-discovery.d.ts","sourceRoot":"","sources":["../src/module-discovery.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGjD,gDAAgD;AAChD,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC;AAElE,gDAAgD;AAChD,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,oCAAoC;IACpC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,gEAAgE;IAChE,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,mCAAmC;AACnC,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,SAAS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