@contractkit/plugin-typescript 0.17.2 → 0.17.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.
- package/.turbo/turbo-build$colon$ci.log +6 -6
- package/.turbo/turbo-test$colon$ci.log +14 -14
- package/CHANGELOG.md +12 -0
- package/coverage/clover.xml +689 -659
- package/coverage/coverage-final.json +4 -4
- package/coverage/index.html +18 -18
- package/coverage/src/codegen-contract.ts.html +356 -224
- package/coverage/src/codegen-operation.ts.html +1 -1
- package/coverage/src/codegen-plain-types.ts.html +197 -101
- package/coverage/src/codegen-sdk.ts.html +1 -1
- package/coverage/src/index.html +28 -28
- package/coverage/src/index.ts.html +1 -1
- package/coverage/src/path-utils.ts.html +1 -1
- package/coverage/src/ts-render.ts.html +11 -11
- package/coverage/tests/helpers.ts.html +7 -7
- package/coverage/tests/index.html +1 -1
- package/dist/codegen-contract.d.ts +5 -0
- package/dist/codegen-contract.d.ts.map +1 -1
- package/dist/codegen-plain-types.d.ts.map +1 -1
- package/dist/index.js +61 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/codegen-contract.ts +47 -3
- package/src/codegen-plain-types.ts +44 -12
- package/tests/codegen-contract.test.ts +26 -0
- package/tests/codegen-plain-types.test.ts +38 -0
|
@@ -634,7 +634,7 @@ export function <span class="fstat-no" title="function not covered" >computePubl
|
|
|
634
634
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
635
635
|
Code coverage generated by
|
|
636
636
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
637
|
-
at 2026-05-
|
|
637
|
+
at 2026-05-05T15:55:20.433Z
|
|
638
638
|
</div>
|
|
639
639
|
<script src="../prettify.js"></script>
|
|
640
640
|
<script>
|
|
@@ -237,7 +237,7 @@
|
|
|
237
237
|
<span class="cline-any cline-yes">5x</span>
|
|
238
238
|
<span class="cline-any cline-neutral"> </span>
|
|
239
239
|
<span class="cline-any cline-neutral"> </span>
|
|
240
|
-
<span class="cline-any cline-yes">
|
|
240
|
+
<span class="cline-any cline-yes">178x</span>
|
|
241
241
|
<span class="cline-any cline-neutral"> </span>
|
|
242
242
|
<span class="cline-any cline-neutral"> </span>
|
|
243
243
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -254,9 +254,9 @@
|
|
|
254
254
|
<span class="cline-any cline-neutral"> </span>
|
|
255
255
|
<span class="cline-any cline-neutral"> </span>
|
|
256
256
|
<span class="cline-any cline-neutral"> </span>
|
|
257
|
-
<span class="cline-any cline-yes">
|
|
257
|
+
<span class="cline-any cline-yes">343x</span>
|
|
258
258
|
<span class="cline-any cline-neutral"> </span>
|
|
259
|
-
<span class="cline-any cline-yes">
|
|
259
|
+
<span class="cline-any cline-yes">170x</span>
|
|
260
260
|
<span class="cline-any cline-neutral"> </span>
|
|
261
261
|
<span class="cline-any cline-yes">20x</span>
|
|
262
262
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -273,7 +273,7 @@
|
|
|
273
273
|
<span class="cline-any cline-neutral"> </span>
|
|
274
274
|
<span class="cline-any cline-yes">10x</span>
|
|
275
275
|
<span class="cline-any cline-neutral"> </span>
|
|
276
|
-
<span class="cline-any cline-yes">
|
|
276
|
+
<span class="cline-any cline-yes">12x</span>
|
|
277
277
|
<span class="cline-any cline-neutral"> </span>
|
|
278
278
|
<span class="cline-any cline-yes">3x</span>
|
|
279
279
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -292,19 +292,19 @@
|
|
|
292
292
|
<span class="cline-any cline-neutral"> </span>
|
|
293
293
|
<span class="cline-any cline-neutral"> </span>
|
|
294
294
|
<span class="cline-any cline-neutral"> </span>
|
|
295
|
-
<span class="cline-any cline-yes">
|
|
295
|
+
<span class="cline-any cline-yes">170x</span>
|
|
296
296
|
<span class="cline-any cline-neutral"> </span>
|
|
297
297
|
<span class="cline-any cline-neutral"> </span>
|
|
298
298
|
<span class="cline-any cline-neutral"> </span>
|
|
299
299
|
<span class="cline-any cline-neutral"> </span>
|
|
300
|
-
<span class="cline-any cline-yes">
|
|
300
|
+
<span class="cline-any cline-yes">116x</span>
|
|
301
301
|
<span class="cline-any cline-neutral"> </span>
|
|
302
302
|
<span class="cline-any cline-neutral"> </span>
|
|
303
303
|
<span class="cline-any cline-yes">23x</span>
|
|
304
304
|
<span class="cline-any cline-neutral"> </span>
|
|
305
305
|
<span class="cline-any cline-yes">6x</span>
|
|
306
306
|
<span class="cline-any cline-neutral"> </span>
|
|
307
|
-
<span class="cline-any cline-yes">
|
|
307
|
+
<span class="cline-any cline-yes">5x</span>
|
|
308
308
|
<span class="cline-any cline-neutral"> </span>
|
|
309
309
|
<span class="cline-any cline-neutral"> </span>
|
|
310
310
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -339,8 +339,8 @@
|
|
|
339
339
|
<span class="cline-any cline-neutral"> </span>
|
|
340
340
|
<span class="cline-any cline-neutral"> </span>
|
|
341
341
|
<span class="cline-any cline-neutral"> </span>
|
|
342
|
-
<span class="cline-any cline-yes">
|
|
343
|
-
<span class="cline-any cline-yes">
|
|
342
|
+
<span class="cline-any cline-yes">92x</span>
|
|
343
|
+
<span class="cline-any cline-yes">46x</span>
|
|
344
344
|
<span class="cline-any cline-neutral"> </span>
|
|
345
345
|
<span class="cline-any cline-yes">15x</span>
|
|
346
346
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -363,7 +363,7 @@
|
|
|
363
363
|
<span class="cline-any cline-neutral"> </span>
|
|
364
364
|
<span class="cline-any cline-yes">1x</span>
|
|
365
365
|
<span class="cline-any cline-neutral"> </span>
|
|
366
|
-
<span class="cline-any cline-yes">
|
|
366
|
+
<span class="cline-any cline-yes">19x</span>
|
|
367
367
|
<span class="cline-any cline-neutral"> </span>
|
|
368
368
|
<span class="cline-any cline-neutral"> </span>
|
|
369
369
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -577,7 +577,7 @@ export function renderOutputTsType(type: ContractTypeNode, modelsWithOutput?: Se
|
|
|
577
577
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
578
578
|
Code coverage generated by
|
|
579
579
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
580
|
-
at 2026-05-
|
|
580
|
+
at 2026-05-05T15:55:20.433Z
|
|
581
581
|
</div>
|
|
582
582
|
<script src="../prettify.js"></script>
|
|
583
583
|
<script>
|
|
@@ -341,11 +341,11 @@
|
|
|
341
341
|
<span class="cline-any cline-neutral"> </span>
|
|
342
342
|
<span class="cline-any cline-neutral"> </span>
|
|
343
343
|
<span class="cline-any cline-neutral"> </span>
|
|
344
|
-
<span class="cline-any cline-yes">
|
|
344
|
+
<span class="cline-any cline-yes">874x</span>
|
|
345
345
|
<span class="cline-any cline-neutral"> </span>
|
|
346
346
|
<span class="cline-any cline-neutral"> </span>
|
|
347
347
|
<span class="cline-any cline-neutral"> </span>
|
|
348
|
-
<span class="cline-any cline-yes">
|
|
348
|
+
<span class="cline-any cline-yes">318x</span>
|
|
349
349
|
<span class="cline-any cline-neutral"> </span>
|
|
350
350
|
<span class="cline-any cline-neutral"> </span>
|
|
351
351
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -365,7 +365,7 @@
|
|
|
365
365
|
<span class="cline-any cline-neutral"> </span>
|
|
366
366
|
<span class="cline-any cline-neutral"> </span>
|
|
367
367
|
<span class="cline-any cline-neutral"> </span>
|
|
368
|
-
<span class="cline-any cline-yes">
|
|
368
|
+
<span class="cline-any cline-yes">15x</span>
|
|
369
369
|
<span class="cline-any cline-neutral"> </span>
|
|
370
370
|
<span class="cline-any cline-neutral"> </span>
|
|
371
371
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -389,7 +389,7 @@
|
|
|
389
389
|
<span class="cline-any cline-neutral"> </span>
|
|
390
390
|
<span class="cline-any cline-neutral"> </span>
|
|
391
391
|
<span class="cline-any cline-neutral"> </span>
|
|
392
|
-
<span class="cline-any cline-yes">
|
|
392
|
+
<span class="cline-any cline-yes">257x</span>
|
|
393
393
|
<span class="cline-any cline-neutral"> </span>
|
|
394
394
|
<span class="cline-any cline-neutral"> </span>
|
|
395
395
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -401,7 +401,7 @@
|
|
|
401
401
|
<span class="cline-any cline-neutral"> </span>
|
|
402
402
|
<span class="cline-any cline-neutral"> </span>
|
|
403
403
|
<span class="cline-any cline-neutral"> </span>
|
|
404
|
-
<span class="cline-any cline-yes">
|
|
404
|
+
<span class="cline-any cline-yes">178x</span>
|
|
405
405
|
<span class="cline-any cline-neutral"> </span>
|
|
406
406
|
<span class="cline-any cline-neutral"> </span>
|
|
407
407
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -411,7 +411,7 @@
|
|
|
411
411
|
<span class="cline-any cline-neutral"> </span>
|
|
412
412
|
<span class="cline-any cline-neutral"> </span>
|
|
413
413
|
<span class="cline-any cline-neutral"> </span>
|
|
414
|
-
<span class="cline-any cline-yes">
|
|
414
|
+
<span class="cline-any cline-yes">137x</span>
|
|
415
415
|
<span class="cline-any cline-neutral"> </span>
|
|
416
416
|
<span class="cline-any cline-neutral"> </span>
|
|
417
417
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -811,7 +811,7 @@ operation /users/{id}: {
|
|
|
811
811
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
812
812
|
Code coverage generated by
|
|
813
813
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
814
|
-
at 2026-05-
|
|
814
|
+
at 2026-05-05T15:55:20.433Z
|
|
815
815
|
</div>
|
|
816
816
|
<script src="../prettify.js"></script>
|
|
817
817
|
<script>
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
102
102
|
Code coverage generated by
|
|
103
103
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
104
|
-
at 2026-05-
|
|
104
|
+
at 2026-05-05T15:55:20.433Z
|
|
105
105
|
</div>
|
|
106
106
|
<script src="../prettify.js"></script>
|
|
107
107
|
<script>
|
|
@@ -5,6 +5,7 @@ import type { ContractRootNode, ModelNode, ContractTypeNode, ObjectMode } from '
|
|
|
5
5
|
* @returns `"z.strictObject"` | `"z.object"` | `"z.looseObject"`
|
|
6
6
|
*/
|
|
7
7
|
export declare function modeToWrapper(mode: ObjectMode): string;
|
|
8
|
+
/** Cross-file context passed to `generateContract` to wire up imports and Input/Output variant tracking. */
|
|
8
9
|
export interface ContractCodegenContext {
|
|
9
10
|
/** Map from model name → absolute output file path */
|
|
10
11
|
modelOutPaths: Map<string, string>;
|
|
@@ -56,9 +57,13 @@ export declare function renderInputType(type: ContractTypeNode, modelsWithInput?
|
|
|
56
57
|
* Also uses Input variants for model refs when modelsWithInput is provided.
|
|
57
58
|
*/
|
|
58
59
|
export declare function renderQueryType(type: ContractTypeNode, modelsWithInput?: Set<string>, defaultMode?: ObjectMode): string;
|
|
60
|
+
/** Returns true if `type` (recursively) contains a scalar with the given `name`. */
|
|
59
61
|
export declare function typeNeedsScalar(type: ContractTypeNode, name: string): boolean;
|
|
62
|
+
/** Returns true if any model in `root` uses a scalar with the given `name`. */
|
|
60
63
|
export declare function rootNeedsScalar(root: ContractRootNode, name: string): boolean;
|
|
64
|
+
/** Returns true if `type` (recursively) contains a `date`, `time`, or `datetime` scalar. */
|
|
61
65
|
export declare function typeNeedsDateTime(type: ContractTypeNode): boolean;
|
|
66
|
+
/** Collect model names referenced in `root` that are not defined locally (need to be imported). */
|
|
62
67
|
export declare function collectExternalRefs(root: ContractRootNode): string[];
|
|
63
68
|
/** Collect external Input variant refs needed for Input schema fields. */
|
|
64
69
|
export declare function collectExternalInputRefs(root: ContractRootNode, modelsWithInput: Set<string>): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-contract.d.ts","sourceRoot":"","sources":["../src/codegen-contract.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,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C,IAAI,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAcpE;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CA4BvG;AAmCD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CA6D/D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAgB3F;AAED,gGAAgG;AAChG,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen-plain-types.d.ts","sourceRoot":"","sources":["../src/codegen-plain-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAapE;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"codegen-plain-types.d.ts","sourceRoot":"","sources":["../src/codegen-plain-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAapE;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,MAAM,CA2CnG"}
|
package/dist/index.js
CHANGED
|
@@ -159,7 +159,7 @@ function generateModel(model, outPath, modelsWithInput, modelsWithWriteonly, mod
|
|
|
159
159
|
}
|
|
160
160
|
const effective = modelMap ? flattenFormatChain(model, modelMap) : model;
|
|
161
161
|
const needsInputSplit = effective.fields.some((f) => f.visibility !== "normal") || (modelsWithInput?.has(effective.name) ?? false);
|
|
162
|
-
const lines = needsInputSplit ? generateThreeSchemaModel(effective, outPath, modelsWithInput, modelsWithWriteonly) : generateSimpleModel(effective, outPath);
|
|
162
|
+
const lines = needsInputSplit ? generateThreeSchemaModel(effective, outPath, modelsWithInput, modelsWithWriteonly, modelMap) : generateSimpleModel(effective, outPath);
|
|
163
163
|
if (modelsWithOutput?.has(effective.name)) {
|
|
164
164
|
lines.push(`export type ${effective.name}Output = z.output<typeof ${effective.name}>;`);
|
|
165
165
|
}
|
|
@@ -229,7 +229,21 @@ function buildExtendChain(bases, resolveName) {
|
|
|
229
229
|
};
|
|
230
230
|
}
|
|
231
231
|
__name(buildExtendChain, "buildExtendChain");
|
|
232
|
-
function
|
|
232
|
+
function collectEffectiveWritableFieldNames(modelName, modelMap) {
|
|
233
|
+
const model = modelMap.get(modelName);
|
|
234
|
+
if (!model || model.type) return /* @__PURE__ */ new Set();
|
|
235
|
+
const result = /* @__PURE__ */ new Set();
|
|
236
|
+
for (const base of model.bases ?? []) {
|
|
237
|
+
for (const f of collectEffectiveWritableFieldNames(base, modelMap)) result.add(f);
|
|
238
|
+
}
|
|
239
|
+
for (const field of model.fields) {
|
|
240
|
+
if (field.visibility === "readonly") result.delete(field.name);
|
|
241
|
+
else result.add(field.name);
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
__name(collectEffectiveWritableFieldNames, "collectEffectiveWritableFieldNames");
|
|
246
|
+
function generateThreeSchemaModel(model, outPath, modelsWithInput, modelsWithWriteonly, modelMap) {
|
|
233
247
|
const lines = [];
|
|
234
248
|
const name = model.name;
|
|
235
249
|
lines.push(...generateComments(model, outPath));
|
|
@@ -263,9 +277,25 @@ function generateThreeSchemaModel(model, outPath, modelsWithInput, modelsWithWri
|
|
|
263
277
|
lines.push("");
|
|
264
278
|
const writeFields = allFields.filter((f) => f.visibility !== "readonly");
|
|
265
279
|
const writeBody = modelsWithInput ? renderInputFields(writeFields, modelsWithInput, model.mode) : renderFields(writeFields, model.mode);
|
|
280
|
+
const fieldsToOmit = /* @__PURE__ */ new Set();
|
|
281
|
+
if (bases.length > 0 && modelMap) {
|
|
282
|
+
for (const field of allFields) {
|
|
283
|
+
if (field.visibility === "readonly") {
|
|
284
|
+
for (const base of bases) {
|
|
285
|
+
if (collectEffectiveWritableFieldNames(base, modelMap).has(field.name)) {
|
|
286
|
+
fieldsToOmit.add(field.name);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const omitClause = fieldsToOmit.size > 0 ? `.omit({ ${[
|
|
294
|
+
...fieldsToOmit
|
|
295
|
+
].map((f) => `${quoteKey(f)}: true`).join(", ")} })` : "";
|
|
266
296
|
if (bases.length > 0) {
|
|
267
297
|
const { head, tail } = buildExtendChain(bases, (b) => modelsWithInput?.has(b) ? `${b}Input` : b);
|
|
268
|
-
lines.push(`export const ${name}Input = ${head}${tail}.extend({`);
|
|
298
|
+
lines.push(`export const ${name}Input = ${head}${tail}${omitClause}.extend({`);
|
|
269
299
|
} else {
|
|
270
300
|
lines.push(`export const ${name}Input = ${wrapper}({`);
|
|
271
301
|
}
|
|
@@ -2551,19 +2581,23 @@ function generatePlainTypes(root, context) {
|
|
|
2551
2581
|
}
|
|
2552
2582
|
lines.push("");
|
|
2553
2583
|
}
|
|
2584
|
+
const modelMap = new Map(root.models.map((m) => [
|
|
2585
|
+
m.name,
|
|
2586
|
+
m
|
|
2587
|
+
]));
|
|
2554
2588
|
for (const model of topoSortModels(root.models)) {
|
|
2555
|
-
lines.push(...generateModel2(model, context?.currentOutPath, allModelsWithInput, allModelsWithOutput));
|
|
2589
|
+
lines.push(...generateModel2(model, context?.currentOutPath, allModelsWithInput, allModelsWithOutput, modelMap));
|
|
2556
2590
|
lines.push("");
|
|
2557
2591
|
}
|
|
2558
2592
|
return lines.join("\n");
|
|
2559
2593
|
}
|
|
2560
2594
|
__name(generatePlainTypes, "generatePlainTypes");
|
|
2561
|
-
function generateModel2(model, outPath, modelsWithInput, modelsWithOutput) {
|
|
2595
|
+
function generateModel2(model, outPath, modelsWithInput, modelsWithOutput, modelMap) {
|
|
2562
2596
|
if (model.type) {
|
|
2563
2597
|
return generateTypeAlias2(model, outPath, modelsWithInput, modelsWithOutput);
|
|
2564
2598
|
}
|
|
2565
2599
|
const needsInputSplit = model.fields.some((f) => f.visibility !== "normal") || (modelsWithInput?.has(model.name) ?? false);
|
|
2566
|
-
const lines = needsInputSplit ? generateVisibilityModel(model, outPath, modelsWithInput) : generateSimpleModel2(model, outPath);
|
|
2600
|
+
const lines = needsInputSplit ? generateVisibilityModel(model, outPath, modelsWithInput, modelMap) : generateSimpleModel2(model, outPath, modelMap);
|
|
2567
2601
|
if (modelsWithOutput?.has(model.name)) {
|
|
2568
2602
|
lines.push("");
|
|
2569
2603
|
lines.push(...generateOutputModel(model, modelsWithOutput));
|
|
@@ -2571,6 +2605,23 @@ function generateModel2(model, outPath, modelsWithInput, modelsWithOutput) {
|
|
|
2571
2605
|
return lines;
|
|
2572
2606
|
}
|
|
2573
2607
|
__name(generateModel2, "generateModel");
|
|
2608
|
+
function collectInheritedFieldNames(bases, modelMap) {
|
|
2609
|
+
const result = /* @__PURE__ */ new Set();
|
|
2610
|
+
const visit = /* @__PURE__ */ __name((name) => {
|
|
2611
|
+
const m = modelMap.get(name);
|
|
2612
|
+
if (!m || m.type) return;
|
|
2613
|
+
for (const f of m.fields) result.add(f.name);
|
|
2614
|
+
for (const b of m.bases ?? []) visit(b);
|
|
2615
|
+
}, "visit");
|
|
2616
|
+
for (const b of bases) visit(b);
|
|
2617
|
+
return result;
|
|
2618
|
+
}
|
|
2619
|
+
__name(collectInheritedFieldNames, "collectInheritedFieldNames");
|
|
2620
|
+
function computeOverrideNames(model, modelMap) {
|
|
2621
|
+
const inherited = modelMap ? collectInheritedFieldNames(model.bases ?? [], modelMap) : /* @__PURE__ */ new Set();
|
|
2622
|
+
return model.fields.filter((f) => f.override || inherited.has(f.name)).map((f) => f.name);
|
|
2623
|
+
}
|
|
2624
|
+
__name(computeOverrideNames, "computeOverrideNames");
|
|
2574
2625
|
function generateComments2(model, outPath) {
|
|
2575
2626
|
const lines = [];
|
|
2576
2627
|
lines.push("/**");
|
|
@@ -2607,11 +2658,11 @@ function buildExtendsClause(bases, overrideNames, baseNameResolver) {
|
|
|
2607
2658
|
return ` extends ${wrapped.join(", ")}`;
|
|
2608
2659
|
}
|
|
2609
2660
|
__name(buildExtendsClause, "buildExtendsClause");
|
|
2610
|
-
function generateSimpleModel2(model, outPath) {
|
|
2661
|
+
function generateSimpleModel2(model, outPath, modelMap) {
|
|
2611
2662
|
const lines = [];
|
|
2612
2663
|
lines.push(...generateComments2(model, outPath));
|
|
2613
2664
|
const bases = model.bases ?? [];
|
|
2614
|
-
const overrideNames = model
|
|
2665
|
+
const overrideNames = computeOverrideNames(model, modelMap);
|
|
2615
2666
|
lines.push(`export interface ${model.name}${buildExtendsClause(bases, overrideNames, (b) => b)} {`);
|
|
2616
2667
|
for (const field of model.fields) {
|
|
2617
2668
|
lines.push(` ${renderField2(field)}`);
|
|
@@ -2620,11 +2671,11 @@ function generateSimpleModel2(model, outPath) {
|
|
|
2620
2671
|
return lines;
|
|
2621
2672
|
}
|
|
2622
2673
|
__name(generateSimpleModel2, "generateSimpleModel");
|
|
2623
|
-
function generateVisibilityModel(model, outPath, modelsWithInput) {
|
|
2674
|
+
function generateVisibilityModel(model, outPath, modelsWithInput, modelMap) {
|
|
2624
2675
|
const lines = [];
|
|
2625
2676
|
lines.push(...generateComments2(model, outPath));
|
|
2626
2677
|
const bases = model.bases ?? [];
|
|
2627
|
-
const overrideNames = model
|
|
2678
|
+
const overrideNames = computeOverrideNames(model, modelMap);
|
|
2628
2679
|
const readFields = model.fields.filter((f) => f.visibility !== "writeonly");
|
|
2629
2680
|
lines.push(`export interface ${model.name}${buildExtendsClause(bases, overrideNames, (b) => b)} {`);
|
|
2630
2681
|
for (const field of readFields) {
|