@skmtc/core 0.45.0 → 0.46.0
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/esm/anchors/attribute.js +3 -2
- package/esm/context/CoreContext.d.ts +1 -1
- package/esm/context/CoreContext.js +1 -1
- package/esm/context/GenerateContext.d.ts +13 -10
- package/esm/context/GenerateContext.js +36 -25
- package/esm/context/ParseContext.js +136 -34
- package/esm/context/generateTypes.d.ts +5 -4
- package/esm/dsl/GeneratorKeys.d.ts +21 -15
- package/esm/dsl/GeneratorKeys.js +16 -11
- package/esm/dsl/Inserted.d.ts +1 -1
- package/esm/dsl/Inserted.js +1 -1
- package/esm/dsl/model/ModelDriver.d.ts +6 -5
- package/esm/dsl/model/ModelDriver.js +22 -20
- package/esm/dsl/model/toModelEntry.d.ts +18 -18
- package/esm/dsl/model/toModelEntry.js +9 -9
- package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/esm/dsl/model/toModelProjectionBase.js +12 -8
- package/esm/dsl/model/types.d.ts +26 -17
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/esm/helpers/refFns.d.ts +108 -43
- package/esm/helpers/refFns.js +166 -57
- package/esm/oas/document/Document.d.ts +6 -0
- package/esm/oas/document/Document.js +44 -2
- package/esm/oas/ref/DanglingRefError.d.ts +5 -2
- package/esm/oas/ref/DanglingRefError.js +4 -3
- package/esm/oas/ref/Ref.d.ts +23 -12
- package/esm/oas/ref/Ref.js +68 -72
- package/esm/oas/schemaPath/traverseSchema.js +11 -5
- package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
- package/esm/types/GeneratorType.d.ts +1 -1
- package/esm/types/ProjectionOptions.d.ts +1 -1
- package/esm/types/ProjectionOptions.js +1 -1
- package/esm/types/RefName.d.ts +3 -3
- package/esm/types/TypeSystem.d.ts +3 -3
- package/package.json +1 -1
- package/script/anchors/attribute.js +3 -2
- package/script/context/CoreContext.d.ts +1 -1
- package/script/context/CoreContext.js +1 -1
- package/script/context/GenerateContext.d.ts +13 -10
- package/script/context/GenerateContext.js +36 -25
- package/script/context/ParseContext.js +135 -33
- package/script/context/generateTypes.d.ts +5 -4
- package/script/dsl/GeneratorKeys.d.ts +21 -15
- package/script/dsl/GeneratorKeys.js +16 -11
- package/script/dsl/Inserted.d.ts +1 -1
- package/script/dsl/Inserted.js +1 -1
- package/script/dsl/model/ModelDriver.d.ts +6 -5
- package/script/dsl/model/ModelDriver.js +22 -20
- package/script/dsl/model/toModelEntry.d.ts +18 -18
- package/script/dsl/model/toModelEntry.js +9 -9
- package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/script/dsl/model/toModelProjectionBase.js +12 -8
- package/script/dsl/model/types.d.ts +26 -17
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/script/helpers/refFns.d.ts +108 -43
- package/script/helpers/refFns.js +180 -59
- package/script/oas/document/Document.d.ts +6 -0
- package/script/oas/document/Document.js +44 -2
- package/script/oas/ref/DanglingRefError.d.ts +5 -2
- package/script/oas/ref/DanglingRefError.js +4 -3
- package/script/oas/ref/Ref.d.ts +23 -12
- package/script/oas/ref/Ref.js +67 -71
- package/script/oas/schemaPath/traverseSchema.js +10 -4
- package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
- package/script/types/GeneratorType.d.ts +1 -1
- package/script/types/ProjectionOptions.d.ts +1 -1
- package/script/types/ProjectionOptions.js +1 -1
- package/script/types/RefName.d.ts +3 -3
- package/script/types/TypeSystem.d.ts +3 -3
|
@@ -17,7 +17,7 @@ import type { OasRef } from '../oas/ref/Ref.js';
|
|
|
17
17
|
import type { OasVoid } from '../oas/void/Void.js';
|
|
18
18
|
import type { ModelProjection, NormalizedModelProjection } from '../dsl/model/types.js';
|
|
19
19
|
import type { ContentSettings } from '../dsl/ContentSettings.js';
|
|
20
|
-
import type {
|
|
20
|
+
import type { RefParts } from '../helpers/refFns.js';
|
|
21
21
|
import type { SchemaToNonRef, TypeSystemOutput } from '../types/TypeSystem.js';
|
|
22
22
|
import type { FileBase } from '../dsl/FileBase.js';
|
|
23
23
|
import type { ImportBase } from '../dsl/ImportBase.js';
|
|
@@ -341,7 +341,8 @@ export type FindDefinitionArgs = PickArgs & {
|
|
|
341
341
|
* @template EnrichmentType - Optional enrichment type for the model
|
|
342
342
|
*/
|
|
343
343
|
export type BuildModelSettingsArgs<V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
344
|
-
|
|
344
|
+
/** The model's ref; an `OasRef` fits it. */
|
|
345
|
+
ref: RefParts;
|
|
345
346
|
projection: ModelProjection<V, EnrichmentType, ProjectionOptions>;
|
|
346
347
|
/**
|
|
347
348
|
* Model variant whose enrichment / identifier / export path
|
|
@@ -475,12 +476,12 @@ export type GenerateContextType = {
|
|
|
475
476
|
addFile: <File extends FileBase>(file: File) => File;
|
|
476
477
|
insertOperation: <V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined>(args: InsertOperationArgs<V, EnrichmentType, ProjectionOptions>) => Inserted<V, EnrichmentType>;
|
|
477
478
|
insertNormalizedModel: <V extends GeneratedValue, Schema extends OasSchema | OasRef<'schema'> | OasVoid, EnrichmentType, ProjectionOptions = undefined>(projection: NormalizedModelProjection<V, EnrichmentType, ProjectionOptions>, { schema, fallbackName, destinationPath }: InsertNormalizedModelArgs<Schema>, ...rest: ProjectionOptionsRest<InsertNormalizedModelOptions<ProjectionOptions>, ProjectionOptions>) => InsertNormalizedModelReturn<V, Schema>;
|
|
478
|
-
insertModel: <V extends GeneratedValue, EnrichmentType, ProjectionOptions = undefined>(projection: ModelProjection<V, EnrichmentType, ProjectionOptions>,
|
|
479
|
+
insertModel: <V extends GeneratedValue, EnrichmentType, ProjectionOptions = undefined>(projection: ModelProjection<V, EnrichmentType, ProjectionOptions>, ref: RefParts, ...rest: ProjectionOptionsRest<InsertModelOptions<ProjectionOptions>, ProjectionOptions>) => Inserted<V, EnrichmentType>;
|
|
479
480
|
toOperationContentSettings: <V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: ToOperationSettingsArgs<V, EnrichmentType, ProjectionOptions>) => ContentSettings<EnrichmentType>;
|
|
480
481
|
insertWebhook: <V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined>(args: InsertWebhookArgs<V, EnrichmentType, ProjectionOptions>) => Inserted<V, EnrichmentType>;
|
|
481
482
|
toWebhookContentSettings: <V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: ToWebhookSettingsArgs<V, EnrichmentType, ProjectionOptions>) => ContentSettings<EnrichmentType>;
|
|
482
483
|
toModelContentSettings: <V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: BuildModelSettingsArgs<V, EnrichmentType, ProjectionOptions>) => ContentSettings<EnrichmentType>;
|
|
483
|
-
resolveSchemaRefOnce: (
|
|
484
|
+
resolveSchemaRefOnce: (ref: RefParts) => OasSchema | OasRef<'schema'>;
|
|
484
485
|
/** The Definition named `name` in `exportPath` (or inside the declaration `into`), or `undefined`. */
|
|
485
486
|
findDefinition: ({ name, exportPath, into }: FindDefinitionArgs) => DefinitionBase | undefined;
|
|
486
487
|
/**
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
*
|
|
57
57
|
* const modelKey = toModelGeneratorKey({
|
|
58
58
|
* generatorId: 'typescript-models',
|
|
59
|
-
* refName: 'User' as RefName,
|
|
59
|
+
* ref: { refName: 'User' as RefName, refPath: '#/components/schemas' },
|
|
60
60
|
* variant: 'main'
|
|
61
61
|
* });
|
|
62
62
|
* ```
|
|
@@ -68,8 +68,8 @@ import type { OasOperation } from '../oas/operation/Operation.js';
|
|
|
68
68
|
import type { OasWebhook } from '../oas/webhook/Webhook.js';
|
|
69
69
|
import type { GqlOperation, GqlRootKind } from '../gql/operation/GqlOperation.js';
|
|
70
70
|
import type { Brand } from '../types/Brand.js';
|
|
71
|
-
import type { RefName } from '../types/RefName.js';
|
|
72
71
|
import { type Method } from '../types/Method.js';
|
|
72
|
+
import { type RefParts } from '../helpers/refFns.js';
|
|
73
73
|
/**
|
|
74
74
|
* Template literal type for OAS operation generator keys before branding.
|
|
75
75
|
* Format: `generatorId|path|method|variant`
|
|
@@ -93,7 +93,8 @@ export type NakedOasOperationGeneratorKey = `${string}|${string}|${Method}|${str
|
|
|
93
93
|
export type NakedGqlOperationGeneratorKey = `${string}|${GqlRootKind}|${string}|${string}`;
|
|
94
94
|
/**
|
|
95
95
|
* Template literal type for model generator keys before branding.
|
|
96
|
-
* Format: `generatorId|
|
|
96
|
+
* Format: `generatorId|modelKey|variant`, where the model key is a component's
|
|
97
|
+
* `refName`, or the whole pointer of a ref into the document's content
|
|
97
98
|
* (e.g., 'typescript-models|User|main',
|
|
98
99
|
* 'zod-schemas|Customer|coercive').
|
|
99
100
|
*
|
|
@@ -207,7 +208,7 @@ export type GeneratorOnlyKey = Brand<string, 'GeneratorOnlyKey'>;
|
|
|
207
208
|
* // Model generator key
|
|
208
209
|
* const modelKey: GeneratorKey = toModelGeneratorKey({
|
|
209
210
|
* generatorId: 'typescript-types',
|
|
210
|
-
* refName: 'User',
|
|
211
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
211
212
|
* variant: 'main'
|
|
212
213
|
* });
|
|
213
214
|
*
|
|
@@ -376,8 +377,12 @@ export declare const toGqlOperationGeneratorKey: ({ generatorId, variant, ...res
|
|
|
376
377
|
type ToModelGeneratorKeyArgs = {
|
|
377
378
|
/** Unique identifier for the generator */
|
|
378
379
|
generatorId: string;
|
|
379
|
-
/**
|
|
380
|
-
|
|
380
|
+
/**
|
|
381
|
+
* The model's ref. A component's key holds its `refName`; any other
|
|
382
|
+
* target's key holds its whole pointer (`toModelKey`), so two targets that
|
|
383
|
+
* share a `refName` get two keys.
|
|
384
|
+
*/
|
|
385
|
+
ref: RefParts;
|
|
381
386
|
/** Model variant name — omitted means `'main'` */
|
|
382
387
|
variant?: string;
|
|
383
388
|
};
|
|
@@ -387,7 +392,8 @@ type ToModelGeneratorKeyArgs = {
|
|
|
387
392
|
*
|
|
388
393
|
* Model generator keys uniquely identify generators processing specific
|
|
389
394
|
* OpenAPI schema models for a given variant. The key format is:
|
|
390
|
-
* `generatorId|
|
|
395
|
+
* `generatorId|modelKey|variant`: a component's `refName`, or the whole
|
|
396
|
+
* pointer of any other target, with `%` and `|` escaped.
|
|
391
397
|
*
|
|
392
398
|
* @param args - Model generator key arguments
|
|
393
399
|
* @returns A branded ModelGeneratorKey
|
|
@@ -396,20 +402,20 @@ type ToModelGeneratorKeyArgs = {
|
|
|
396
402
|
* ```typescript
|
|
397
403
|
* const key = toModelGeneratorKey({
|
|
398
404
|
* generatorId: 'typescript-interfaces',
|
|
399
|
-
* refName: 'User',
|
|
405
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
400
406
|
* variant: 'main'
|
|
401
407
|
* });
|
|
402
408
|
* // Result: 'typescript-interfaces|User|main' (branded)
|
|
403
409
|
*
|
|
404
410
|
* const coercive = toModelGeneratorKey({
|
|
405
411
|
* generatorId: 'zod-schemas',
|
|
406
|
-
* refName: 'CreateUserRequest',
|
|
412
|
+
* ref: { refName: 'CreateUserRequest', refPath: '#/components/schemas' },
|
|
407
413
|
* variant: 'coercive'
|
|
408
414
|
* });
|
|
409
415
|
* // Result: 'zod-schemas|CreateUserRequest|coercive' (branded)
|
|
410
416
|
* ```
|
|
411
417
|
*/
|
|
412
|
-
export declare const toModelGeneratorKey: ({ generatorId,
|
|
418
|
+
export declare const toModelGeneratorKey: ({ generatorId, ref, variant }: ToModelGeneratorKeyArgs) => ModelGeneratorKey;
|
|
413
419
|
/**
|
|
414
420
|
* Arguments for {@link toGeneratorOnlyKey}.
|
|
415
421
|
*/
|
|
@@ -532,7 +538,7 @@ export declare const isGqlOperationGeneratorKey: (arg: unknown) => arg is GqlOpe
|
|
|
532
538
|
* const obj = fromGeneratorKey(key);
|
|
533
539
|
* console.log(obj.type); // 'model'
|
|
534
540
|
* console.log(obj.generatorId); // 'zod-schemas'
|
|
535
|
-
* console.log(obj.refName);
|
|
541
|
+
* console.log(obj.ref.refName); // 'User'
|
|
536
542
|
* console.log(obj.variant); // 'main'
|
|
537
543
|
* }
|
|
538
544
|
* ```
|
|
@@ -582,7 +588,7 @@ export declare const isGeneratorOnlyKey: (arg: unknown) => arg is GeneratorOnlyK
|
|
|
582
588
|
*
|
|
583
589
|
* const modelKey = toModelGeneratorKey({
|
|
584
590
|
* generatorId: 'typescript-types',
|
|
585
|
-
* refName: 'User',
|
|
591
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
586
592
|
* variant: 'main'
|
|
587
593
|
* });
|
|
588
594
|
* console.log(toGeneratorId(modelKey)); // 'typescript-types'
|
|
@@ -650,8 +656,8 @@ export type GeneratorKeyObject = {
|
|
|
650
656
|
type: 'model';
|
|
651
657
|
/** Generator identifier */
|
|
652
658
|
generatorId: string;
|
|
653
|
-
/**
|
|
654
|
-
|
|
659
|
+
/** The model's ref: a component's, or a ref into the document's content */
|
|
660
|
+
ref: RefParts;
|
|
655
661
|
/** Model variant name */
|
|
656
662
|
variant: string;
|
|
657
663
|
} | {
|
|
@@ -689,7 +695,7 @@ export type GeneratorKeyObject = {
|
|
|
689
695
|
*
|
|
690
696
|
* if (parsed.type === 'model') {
|
|
691
697
|
* console.log(parsed.generatorId); // 'zod-schemas'
|
|
692
|
-
* console.log(parsed.refName);
|
|
698
|
+
* console.log(parsed.ref.refName); // 'User'
|
|
693
699
|
* console.log(parsed.variant); // 'main'
|
|
694
700
|
* }
|
|
695
701
|
* ```
|
|
@@ -59,7 +59,7 @@ exports.fromGeneratorKey = exports.toGeneratorId = exports.isGeneratorOnlyKey =
|
|
|
59
59
|
*
|
|
60
60
|
* const modelKey = toModelGeneratorKey({
|
|
61
61
|
* generatorId: 'typescript-models',
|
|
62
|
-
* refName: 'User' as RefName,
|
|
62
|
+
* ref: { refName: 'User' as RefName, refPath: '#/components/schemas' },
|
|
63
63
|
* variant: 'main'
|
|
64
64
|
* });
|
|
65
65
|
* ```
|
|
@@ -69,6 +69,7 @@ exports.fromGeneratorKey = exports.toGeneratorId = exports.isGeneratorOnlyKey =
|
|
|
69
69
|
require("../_dnt.polyfills.js");
|
|
70
70
|
const Method_js_1 = require("../types/Method.js");
|
|
71
71
|
const Variant_js_1 = require("../types/Variant.js");
|
|
72
|
+
const refFns_js_1 = require("../helpers/refFns.js");
|
|
72
73
|
const GQL_ROOT_KINDS = ['query', 'mutation', 'subscription'];
|
|
73
74
|
const isGqlRootKind = (value) => GQL_ROOT_KINDS.includes(value);
|
|
74
75
|
/**
|
|
@@ -176,7 +177,8 @@ exports.toGqlOperationGeneratorKey = toGqlOperationGeneratorKey;
|
|
|
176
177
|
*
|
|
177
178
|
* Model generator keys uniquely identify generators processing specific
|
|
178
179
|
* OpenAPI schema models for a given variant. The key format is:
|
|
179
|
-
* `generatorId|
|
|
180
|
+
* `generatorId|modelKey|variant`: a component's `refName`, or the whole
|
|
181
|
+
* pointer of any other target, with `%` and `|` escaped.
|
|
180
182
|
*
|
|
181
183
|
* @param args - Model generator key arguments
|
|
182
184
|
* @returns A branded ModelGeneratorKey
|
|
@@ -185,21 +187,24 @@ exports.toGqlOperationGeneratorKey = toGqlOperationGeneratorKey;
|
|
|
185
187
|
* ```typescript
|
|
186
188
|
* const key = toModelGeneratorKey({
|
|
187
189
|
* generatorId: 'typescript-interfaces',
|
|
188
|
-
* refName: 'User',
|
|
190
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
189
191
|
* variant: 'main'
|
|
190
192
|
* });
|
|
191
193
|
* // Result: 'typescript-interfaces|User|main' (branded)
|
|
192
194
|
*
|
|
193
195
|
* const coercive = toModelGeneratorKey({
|
|
194
196
|
* generatorId: 'zod-schemas',
|
|
195
|
-
* refName: 'CreateUserRequest',
|
|
197
|
+
* ref: { refName: 'CreateUserRequest', refPath: '#/components/schemas' },
|
|
196
198
|
* variant: 'coercive'
|
|
197
199
|
* });
|
|
198
200
|
* // Result: 'zod-schemas|CreateUserRequest|coercive' (branded)
|
|
199
201
|
* ```
|
|
200
202
|
*/
|
|
201
|
-
const toModelGeneratorKey = ({ generatorId,
|
|
202
|
-
const
|
|
203
|
+
const toModelGeneratorKey = ({ generatorId, ref, variant = Variant_js_1.DEFAULT_VARIANT }) => {
|
|
204
|
+
const modelKey = (0, refFns_js_1.toModelKey)(ref);
|
|
205
|
+
// A pointer can hold `|` (a property named `a|b`). A component's key stays its bare name.
|
|
206
|
+
const segment = (0, refFns_js_1.isPointerKey)(modelKey) ? escapeKeySegment(modelKey) : modelKey;
|
|
207
|
+
const nakedKey = `${generatorId}|${segment}|${variant}`;
|
|
203
208
|
return nakedKey;
|
|
204
209
|
};
|
|
205
210
|
exports.toModelGeneratorKey = toModelGeneratorKey;
|
|
@@ -418,7 +423,7 @@ exports.isGqlOperationGeneratorKey = isGqlOperationGeneratorKey;
|
|
|
418
423
|
* const obj = fromGeneratorKey(key);
|
|
419
424
|
* console.log(obj.type); // 'model'
|
|
420
425
|
* console.log(obj.generatorId); // 'zod-schemas'
|
|
421
|
-
* console.log(obj.refName);
|
|
426
|
+
* console.log(obj.ref.refName); // 'User'
|
|
422
427
|
* console.log(obj.variant); // 'main'
|
|
423
428
|
* }
|
|
424
429
|
* ```
|
|
@@ -494,7 +499,7 @@ exports.isGeneratorOnlyKey = isGeneratorOnlyKey;
|
|
|
494
499
|
*
|
|
495
500
|
* const modelKey = toModelGeneratorKey({
|
|
496
501
|
* generatorId: 'typescript-types',
|
|
497
|
-
* refName: 'User',
|
|
502
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
498
503
|
* variant: 'main'
|
|
499
504
|
* });
|
|
500
505
|
* console.log(toGeneratorId(modelKey)); // 'typescript-types'
|
|
@@ -553,7 +558,7 @@ exports.toGeneratorId = toGeneratorId;
|
|
|
553
558
|
*
|
|
554
559
|
* if (parsed.type === 'model') {
|
|
555
560
|
* console.log(parsed.generatorId); // 'zod-schemas'
|
|
556
|
-
* console.log(parsed.refName);
|
|
561
|
+
* console.log(parsed.ref.refName); // 'User'
|
|
557
562
|
* console.log(parsed.variant); // 'main'
|
|
558
563
|
* }
|
|
559
564
|
* ```
|
|
@@ -598,8 +603,8 @@ const fromGeneratorKey = (generatorKey) => {
|
|
|
598
603
|
};
|
|
599
604
|
}
|
|
600
605
|
if ((0, exports.isModelGeneratorKey)(generatorKey)) {
|
|
601
|
-
const [generatorId,
|
|
602
|
-
return { type: 'model', generatorId,
|
|
606
|
+
const [generatorId, modelKey, variant] = generatorKey.split('|');
|
|
607
|
+
return { type: 'model', generatorId, ref: (0, refFns_js_1.fromModelKey)((0, refFns_js_1.isPointerKey)(modelKey) ? unescapeKeySegment(modelKey) : modelKey), variant };
|
|
603
608
|
}
|
|
604
609
|
return { type: 'generator-only', generatorId: generatorKey };
|
|
605
610
|
};
|
package/script/dsl/Inserted.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ type ConstructorArgs<V extends GeneratedValue, EnrichmentType> = {
|
|
|
53
53
|
* const identifier = userModel.toName(); // 'User'
|
|
54
54
|
*
|
|
55
55
|
* return new Definition({
|
|
56
|
-
* identifier: createType(this.refName),
|
|
56
|
+
* identifier: createType(this.ref.refName),
|
|
57
57
|
* value: {
|
|
58
58
|
* generatorKey: this.generatorKey,
|
|
59
59
|
* content: `export interface Order { user: ${userTypeName}; }`
|
package/script/dsl/Inserted.js
CHANGED
|
@@ -41,7 +41,7 @@ exports.Inserted = void 0;
|
|
|
41
41
|
* const identifier = userModel.toName(); // 'User'
|
|
42
42
|
*
|
|
43
43
|
* return new Definition({
|
|
44
|
-
* identifier: createType(this.refName),
|
|
44
|
+
* identifier: createType(this.ref.refName),
|
|
45
45
|
* value: {
|
|
46
46
|
* generatorKey: this.generatorKey,
|
|
47
47
|
* content: `export interface Order { user: ${userTypeName}; }`
|
|
@@ -3,7 +3,7 @@ import type { GenerateContextType, InsertModelOptions } from '../../context/gene
|
|
|
3
3
|
import type { ContentSettings } from '../ContentSettings.js';
|
|
4
4
|
import type { GeneratedDefinition } from '../GeneratedValue.js';
|
|
5
5
|
import type { GeneratedValue } from '../GeneratedValue.js';
|
|
6
|
-
import type
|
|
6
|
+
import { type RefParts } from '../../helpers/refFns.js';
|
|
7
7
|
/**
|
|
8
8
|
* The `insertModel` call plus the context. The Driver defaults `variant`
|
|
9
9
|
* to `'main'` and `noExport` to `false`, and reads the caller's options
|
|
@@ -12,8 +12,9 @@ import type { RefName } from '../../types/RefName.js';
|
|
|
12
12
|
type CreateModelArgs<V extends GeneratedValue, EnrichmentType, ProjectionOptions> = {
|
|
13
13
|
context: GenerateContextType;
|
|
14
14
|
projection: ModelProjection<V, EnrichmentType, ProjectionOptions>;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/** The model's ref; an `OasRef` fits it. */
|
|
16
|
+
ref: RefParts;
|
|
17
|
+
rootRef?: RefParts;
|
|
17
18
|
} & InsertModelOptions<ProjectionOptions>;
|
|
18
19
|
/**
|
|
19
20
|
* Driver for the model insertion lifecycle.
|
|
@@ -27,11 +28,11 @@ type CreateModelArgs<V extends GeneratedValue, EnrichmentType, ProjectionOptions
|
|
|
27
28
|
export declare class ModelDriver<V extends GeneratedValue, EnrichmentType, ProjectionOptions = undefined> {
|
|
28
29
|
context: GenerateContextType;
|
|
29
30
|
projection: ModelProjection<V, EnrichmentType, ProjectionOptions>;
|
|
30
|
-
|
|
31
|
+
ref: RefParts;
|
|
31
32
|
settings: ContentSettings<EnrichmentType>;
|
|
32
33
|
destinationPath?: string;
|
|
33
34
|
definition: GeneratedDefinition<V>;
|
|
34
|
-
rootRef?:
|
|
35
|
+
rootRef?: RefParts;
|
|
35
36
|
noExport: boolean;
|
|
36
37
|
variant: string;
|
|
37
38
|
/** The caller's options, as passed to `insertModel`. */
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.toModelRef = exports.isReferencedBack = exports.ModelDriver = void 0;
|
|
7
7
|
const normalizeWorkspacePath_js_1 = require("../../helpers/normalizeWorkspacePath.js");
|
|
8
8
|
const GeneratorKeys_js_1 = require("../GeneratorKeys.js");
|
|
9
|
+
const refFns_js_1 = require("../../helpers/refFns.js");
|
|
9
10
|
const Variant_js_1 = require("../../types/Variant.js");
|
|
10
11
|
const ProjectionOptions_js_1 = require("../../types/ProjectionOptions.js");
|
|
11
12
|
const isEqual_js_1 = __importDefault(require("lodash-es/isEqual.js"));
|
|
@@ -38,7 +39,7 @@ class ModelDriver {
|
|
|
38
39
|
writable: true,
|
|
39
40
|
value: void 0
|
|
40
41
|
});
|
|
41
|
-
Object.defineProperty(this, "
|
|
42
|
+
Object.defineProperty(this, "ref", {
|
|
42
43
|
enumerable: true,
|
|
43
44
|
configurable: true,
|
|
44
45
|
writable: true,
|
|
@@ -87,10 +88,10 @@ class ModelDriver {
|
|
|
87
88
|
writable: true,
|
|
88
89
|
value: void 0
|
|
89
90
|
});
|
|
90
|
-
const { context, projection,
|
|
91
|
+
const { context, projection, ref, destinationPath, rootRef, noExport = false, variant = Variant_js_1.DEFAULT_VARIANT } = args;
|
|
91
92
|
this.context = context;
|
|
92
93
|
this.projection = projection;
|
|
93
|
-
this.
|
|
94
|
+
this.ref = ref;
|
|
94
95
|
this.destinationPath = destinationPath;
|
|
95
96
|
this.rootRef = rootRef;
|
|
96
97
|
this.noExport = noExport;
|
|
@@ -131,7 +132,7 @@ class ModelDriver {
|
|
|
131
132
|
getDefinition({ identifier, exportPath }) {
|
|
132
133
|
const generatorKey = (0, GeneratorKeys_js_1.toModelGeneratorKey)({
|
|
133
134
|
generatorId: this.projection.id,
|
|
134
|
-
|
|
135
|
+
ref: this.ref,
|
|
135
136
|
variant: this.settings.variant
|
|
136
137
|
});
|
|
137
138
|
const pending = findPending({ context: this.context, name: identifier.name, exportPath });
|
|
@@ -164,7 +165,7 @@ class ModelDriver {
|
|
|
164
165
|
projection: this.projection
|
|
165
166
|
});
|
|
166
167
|
const value = whilePending({ context: this.context, marker }, () => new this.projection({
|
|
167
|
-
|
|
168
|
+
ref: this.ref,
|
|
168
169
|
context: this.context,
|
|
169
170
|
settings: this.settings,
|
|
170
171
|
destinationPath: this.settings.exportPath,
|
|
@@ -198,7 +199,7 @@ class ModelDriver {
|
|
|
198
199
|
}
|
|
199
200
|
const currentKey = (0, GeneratorKeys_js_1.toModelGeneratorKey)({
|
|
200
201
|
generatorId: this.projection.id,
|
|
201
|
-
|
|
202
|
+
ref: this.ref,
|
|
202
203
|
variant: this.settings.variant
|
|
203
204
|
});
|
|
204
205
|
assertSameKey({
|
|
@@ -306,11 +307,11 @@ const isReferencedBack = ({ context, settings }) => {
|
|
|
306
307
|
exports.isReferencedBack = isReferencedBack;
|
|
307
308
|
/** A model's content settings, once the peer is known to have the variant and to support the model. */
|
|
308
309
|
const toModelSettings = (args) => {
|
|
309
|
-
const { context, projection,
|
|
310
|
-
assertPeerVariantExists({ context, generatorId: projection.id,
|
|
311
|
-
assertPeerSupported({ context, projection,
|
|
310
|
+
const { context, projection, ref, variant = Variant_js_1.DEFAULT_VARIANT } = args;
|
|
311
|
+
assertPeerVariantExists({ context, generatorId: projection.id, ref, variant });
|
|
312
|
+
assertPeerSupported({ context, projection, ref, variant });
|
|
312
313
|
return context.toModelContentSettings({
|
|
313
|
-
|
|
314
|
+
ref,
|
|
314
315
|
projection,
|
|
315
316
|
variant,
|
|
316
317
|
options: (0, ProjectionOptions_js_1.readProjectionOptions)(args)
|
|
@@ -327,7 +328,7 @@ const toModelSettings = (args) => {
|
|
|
327
328
|
* {@link ModelDriver}.
|
|
328
329
|
*/
|
|
329
330
|
const toModelRef = (args) => {
|
|
330
|
-
const { context, projection,
|
|
331
|
+
const { context, projection, ref, destinationPath, variant = Variant_js_1.DEFAULT_VARIANT } = args;
|
|
331
332
|
const settings = toModelSettings(args);
|
|
332
333
|
const pending = findPending({
|
|
333
334
|
context,
|
|
@@ -339,7 +340,7 @@ const toModelRef = (args) => {
|
|
|
339
340
|
pending,
|
|
340
341
|
name: settings.identifier.name,
|
|
341
342
|
exportPath: settings.exportPath,
|
|
342
|
-
generatorKey: (0, GeneratorKeys_js_1.toModelGeneratorKey)({ generatorId: projection.id,
|
|
343
|
+
generatorKey: (0, GeneratorKeys_js_1.toModelGeneratorKey)({ generatorId: projection.id, ref, variant }),
|
|
343
344
|
options: (0, ProjectionOptions_js_1.readProjectionOptions)(args),
|
|
344
345
|
projection
|
|
345
346
|
});
|
|
@@ -384,22 +385,23 @@ exports.toModelRef = toModelRef;
|
|
|
384
385
|
* key. The Driver throws here — loud at the call site — rather than
|
|
385
386
|
* letting silently-wrong output reach the consumer.
|
|
386
387
|
*/
|
|
387
|
-
const assertPeerVariantExists = ({ context, generatorId,
|
|
388
|
+
const assertPeerVariantExists = ({ context, generatorId, ref, variant }) => {
|
|
388
389
|
if (variant === Variant_js_1.DEFAULT_VARIANT) {
|
|
389
390
|
return;
|
|
390
391
|
}
|
|
391
|
-
const
|
|
392
|
+
const key = (0, refFns_js_1.toModelKey)(ref);
|
|
393
|
+
const modelEnrichments = context.readEnrichment([generatorId, key]);
|
|
392
394
|
if (modelEnrichments === null || modelEnrichments === undefined) {
|
|
393
|
-
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${
|
|
395
|
+
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${key}' — ` +
|
|
394
396
|
`peer has no enrichments configured. Only '${Variant_js_1.DEFAULT_VARIANT}' is permitted.`);
|
|
395
397
|
}
|
|
396
398
|
if (typeof modelEnrichments !== 'object' || Array.isArray(modelEnrichments)) {
|
|
397
|
-
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${
|
|
399
|
+
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${key}' — ` +
|
|
398
400
|
`peer enrichment is not a variant record.`);
|
|
399
401
|
}
|
|
400
402
|
if (!(variant in modelEnrichments)) {
|
|
401
403
|
const available = Object.keys(modelEnrichments).join(', ');
|
|
402
|
-
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${
|
|
404
|
+
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${key}'. ` +
|
|
403
405
|
`Available variants: ${available}.`);
|
|
404
406
|
}
|
|
405
407
|
};
|
|
@@ -422,10 +424,10 @@ const assertPeerVariantExists = ({ context, generatorId, refName, variant }) =>
|
|
|
422
424
|
* model: `toModelProjectionBase` defaults it to `() => true`, and a
|
|
423
425
|
* hand-rolled projection may omit it.
|
|
424
426
|
*/
|
|
425
|
-
const assertPeerSupported = ({ context, projection,
|
|
427
|
+
const assertPeerSupported = ({ context, projection, ref, variant }) => {
|
|
426
428
|
const isSupported = projection.isSupported ?? (() => true);
|
|
427
|
-
if (!isSupported({
|
|
428
|
-
throw new Error(`[${projection.id}] Cannot insert '${
|
|
429
|
+
if (!isSupported({ ref, context, variant })) {
|
|
430
|
+
throw new Error(`[${projection.id}] Cannot insert '${(0, refFns_js_1.toModelKey)(ref)}' — peer generator ` +
|
|
429
431
|
`does not support this model (isSupported returned false).`);
|
|
430
432
|
}
|
|
431
433
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RefParts } from '../../helpers/refFns.js';
|
|
2
2
|
import type { EnrichmentRequest } from '../../types/EnrichmentRequest.js';
|
|
3
3
|
import type { TransformModelArgs, ToModelPreviewModuleArgs, ToModelEnrichmentsArgs, IsSupportedModelArgs } from './types.js';
|
|
4
4
|
import type { PreviewModule } from '../../types/Preview.js';
|
|
5
5
|
import type * as v from 'valibot';
|
|
6
6
|
type ToModelEntryArgs<EnrichmentType = undefined> = {
|
|
7
7
|
id: string;
|
|
8
|
-
transform: ({ context,
|
|
8
|
+
transform: ({ context, ref, variant }: TransformModelArgs) => void;
|
|
9
9
|
toEnrichmentSchema: () => v.GenericSchema<EnrichmentType>;
|
|
10
10
|
isSupported?: (args: IsSupportedModelArgs) => boolean;
|
|
11
11
|
/**
|
|
@@ -13,20 +13,20 @@ type ToModelEntryArgs<EnrichmentType = undefined> = {
|
|
|
13
13
|
* function returning `false` when omitted.
|
|
14
14
|
*/
|
|
15
15
|
supportsVariant?: () => boolean;
|
|
16
|
-
toPreviewModule?: ({ context,
|
|
17
|
-
toEnrichmentRequest?: <RequestedEnrichment extends EnrichmentType>(
|
|
18
|
-
toEnrichmentDefaults?: ({
|
|
16
|
+
toPreviewModule?: ({ context, ref, variant }: ToModelPreviewModuleArgs) => PreviewModule;
|
|
17
|
+
toEnrichmentRequest?: <RequestedEnrichment extends EnrichmentType>(ref: RefParts) => EnrichmentRequest<RequestedEnrichment> | undefined;
|
|
18
|
+
toEnrichmentDefaults?: ({ ref, context, variant }: ToModelEnrichmentsArgs) => EnrichmentType | undefined;
|
|
19
19
|
};
|
|
20
20
|
export type ModelEntry<EnrichmentType = undefined> = {
|
|
21
21
|
id: string;
|
|
22
22
|
type: 'model';
|
|
23
|
-
transform: ({ context,
|
|
23
|
+
transform: ({ context, ref, variant }: TransformModelArgs) => void;
|
|
24
24
|
isSupported: (args: IsSupportedModelArgs) => boolean;
|
|
25
25
|
supportsVariant: () => boolean;
|
|
26
|
-
toPreviewModule?: ({ context,
|
|
26
|
+
toPreviewModule?: ({ context, ref, variant }: ToModelPreviewModuleArgs) => PreviewModule;
|
|
27
27
|
toEnrichmentSchema: () => v.GenericSchema<EnrichmentType>;
|
|
28
|
-
toEnrichmentRequest?: <RequestedEnrichment extends EnrichmentType>(
|
|
29
|
-
toEnrichmentDefaults?: ({
|
|
28
|
+
toEnrichmentRequest?: <RequestedEnrichment extends EnrichmentType>(ref: RefParts) => EnrichmentRequest<RequestedEnrichment> | undefined;
|
|
29
|
+
toEnrichmentDefaults?: ({ ref, context, variant }: ToModelEnrichmentsArgs) => EnrichmentType | undefined;
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* Creates a model transformation entry for the SKMTC pipeline.
|
|
@@ -45,7 +45,7 @@ export type ModelEntry<EnrichmentType = undefined> = {
|
|
|
45
45
|
* @param args.isSupported - Optional capability gate; a model whose predicate
|
|
46
46
|
* returns `false` is recorded `notSupported` and its `transform` is skipped.
|
|
47
47
|
* Resolve the schema inside the predicate when needed
|
|
48
|
-
* (`context.resolveSchemaRefOnce(
|
|
48
|
+
* (`context.resolveSchemaRefOnce(ref)`). Defaults to supporting every model.
|
|
49
49
|
* @param args.toPreviewModule - Optional function to generate preview modules
|
|
50
50
|
* @param args.toEnrichmentSchema - Optional function to provide enrichment validation
|
|
51
51
|
* @param args.toEnrichmentRequest - Optional function to request enrichments
|
|
@@ -57,12 +57,12 @@ export type ModelEntry<EnrichmentType = undefined> = {
|
|
|
57
57
|
*
|
|
58
58
|
* const typeScriptModelEntry = toModelEntry({
|
|
59
59
|
* id: 'typescript-models',
|
|
60
|
-
* transform: ({ context,
|
|
61
|
-
* context.insertModel(TsModel,
|
|
60
|
+
* transform: ({ context, ref }) => {
|
|
61
|
+
* context.insertModel(TsModel, ref);
|
|
62
62
|
* },
|
|
63
|
-
* toPreviewModule: ({ context,
|
|
63
|
+
* toPreviewModule: ({ context, ref }) => ({
|
|
64
64
|
* group: 'forms',
|
|
65
|
-
* title: `${refName} Model`,
|
|
65
|
+
* title: `${ref.refName} Model`,
|
|
66
66
|
* description: 'Generated TypeScript interface'
|
|
67
67
|
* })
|
|
68
68
|
* });
|
|
@@ -72,15 +72,15 @@ export type ModelEntry<EnrichmentType = undefined> = {
|
|
|
72
72
|
* ```typescript
|
|
73
73
|
* const validationModelEntry = toModelEntry({
|
|
74
74
|
* id: 'validation-schemas',
|
|
75
|
-
* transform: ({ context,
|
|
76
|
-
* context.insertModel(ValidationModel,
|
|
75
|
+
* transform: ({ context, ref }) => {
|
|
76
|
+
* context.insertModel(ValidationModel, ref);
|
|
77
77
|
* },
|
|
78
78
|
* toEnrichmentSchema: () => v.object({
|
|
79
79
|
* strict: v.optional(v.boolean()),
|
|
80
80
|
* nullable: v.optional(v.boolean())
|
|
81
81
|
* }),
|
|
82
|
-
* toEnrichmentRequest: (
|
|
83
|
-
* path: `models.${refName}`,
|
|
82
|
+
* toEnrichmentRequest: (ref) => ({
|
|
83
|
+
* path: `models.${ref.refName}`,
|
|
84
84
|
* schema: enrichmentSchema
|
|
85
85
|
* })
|
|
86
86
|
* });
|
|
@@ -18,7 +18,7 @@ exports.toModelEntry = void 0;
|
|
|
18
18
|
* @param args.isSupported - Optional capability gate; a model whose predicate
|
|
19
19
|
* returns `false` is recorded `notSupported` and its `transform` is skipped.
|
|
20
20
|
* Resolve the schema inside the predicate when needed
|
|
21
|
-
* (`context.resolveSchemaRefOnce(
|
|
21
|
+
* (`context.resolveSchemaRefOnce(ref)`). Defaults to supporting every model.
|
|
22
22
|
* @param args.toPreviewModule - Optional function to generate preview modules
|
|
23
23
|
* @param args.toEnrichmentSchema - Optional function to provide enrichment validation
|
|
24
24
|
* @param args.toEnrichmentRequest - Optional function to request enrichments
|
|
@@ -30,12 +30,12 @@ exports.toModelEntry = void 0;
|
|
|
30
30
|
*
|
|
31
31
|
* const typeScriptModelEntry = toModelEntry({
|
|
32
32
|
* id: 'typescript-models',
|
|
33
|
-
* transform: ({ context,
|
|
34
|
-
* context.insertModel(TsModel,
|
|
33
|
+
* transform: ({ context, ref }) => {
|
|
34
|
+
* context.insertModel(TsModel, ref);
|
|
35
35
|
* },
|
|
36
|
-
* toPreviewModule: ({ context,
|
|
36
|
+
* toPreviewModule: ({ context, ref }) => ({
|
|
37
37
|
* group: 'forms',
|
|
38
|
-
* title: `${refName} Model`,
|
|
38
|
+
* title: `${ref.refName} Model`,
|
|
39
39
|
* description: 'Generated TypeScript interface'
|
|
40
40
|
* })
|
|
41
41
|
* });
|
|
@@ -45,15 +45,15 @@ exports.toModelEntry = void 0;
|
|
|
45
45
|
* ```typescript
|
|
46
46
|
* const validationModelEntry = toModelEntry({
|
|
47
47
|
* id: 'validation-schemas',
|
|
48
|
-
* transform: ({ context,
|
|
49
|
-
* context.insertModel(ValidationModel,
|
|
48
|
+
* transform: ({ context, ref }) => {
|
|
49
|
+
* context.insertModel(ValidationModel, ref);
|
|
50
50
|
* },
|
|
51
51
|
* toEnrichmentSchema: () => v.object({
|
|
52
52
|
* strict: v.optional(v.boolean()),
|
|
53
53
|
* nullable: v.optional(v.boolean())
|
|
54
54
|
* }),
|
|
55
|
-
* toEnrichmentRequest: (
|
|
56
|
-
* path: `models.${refName}`,
|
|
55
|
+
* toEnrichmentRequest: (ref) => ({
|
|
56
|
+
* path: `models.${ref.refName}`,
|
|
57
57
|
* schema: enrichmentSchema
|
|
58
58
|
* })
|
|
59
59
|
* });
|