@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
|
* ```
|
package/esm/dsl/GeneratorKeys.js
CHANGED
|
@@ -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
|
* ```
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
import "../_dnt.polyfills.js";
|
|
67
67
|
import { isMethod } from '../types/Method.js';
|
|
68
68
|
import { DEFAULT_VARIANT } from '../types/Variant.js';
|
|
69
|
+
import { fromModelKey, isPointerKey, toModelKey } from '../helpers/refFns.js';
|
|
69
70
|
const GQL_ROOT_KINDS = ['query', 'mutation', 'subscription'];
|
|
70
71
|
const isGqlRootKind = (value) => GQL_ROOT_KINDS.includes(value);
|
|
71
72
|
/**
|
|
@@ -169,7 +170,8 @@ export const toGqlOperationGeneratorKey = ({ generatorId, variant = DEFAULT_VARI
|
|
|
169
170
|
*
|
|
170
171
|
* Model generator keys uniquely identify generators processing specific
|
|
171
172
|
* OpenAPI schema models for a given variant. The key format is:
|
|
172
|
-
* `generatorId|
|
|
173
|
+
* `generatorId|modelKey|variant`: a component's `refName`, or the whole
|
|
174
|
+
* pointer of any other target, with `%` and `|` escaped.
|
|
173
175
|
*
|
|
174
176
|
* @param args - Model generator key arguments
|
|
175
177
|
* @returns A branded ModelGeneratorKey
|
|
@@ -178,21 +180,24 @@ export const toGqlOperationGeneratorKey = ({ generatorId, variant = DEFAULT_VARI
|
|
|
178
180
|
* ```typescript
|
|
179
181
|
* const key = toModelGeneratorKey({
|
|
180
182
|
* generatorId: 'typescript-interfaces',
|
|
181
|
-
* refName: 'User',
|
|
183
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
182
184
|
* variant: 'main'
|
|
183
185
|
* });
|
|
184
186
|
* // Result: 'typescript-interfaces|User|main' (branded)
|
|
185
187
|
*
|
|
186
188
|
* const coercive = toModelGeneratorKey({
|
|
187
189
|
* generatorId: 'zod-schemas',
|
|
188
|
-
* refName: 'CreateUserRequest',
|
|
190
|
+
* ref: { refName: 'CreateUserRequest', refPath: '#/components/schemas' },
|
|
189
191
|
* variant: 'coercive'
|
|
190
192
|
* });
|
|
191
193
|
* // Result: 'zod-schemas|CreateUserRequest|coercive' (branded)
|
|
192
194
|
* ```
|
|
193
195
|
*/
|
|
194
|
-
export const toModelGeneratorKey = ({ generatorId,
|
|
195
|
-
const
|
|
196
|
+
export const toModelGeneratorKey = ({ generatorId, ref, variant = DEFAULT_VARIANT }) => {
|
|
197
|
+
const modelKey = toModelKey(ref);
|
|
198
|
+
// A pointer can hold `|` (a property named `a|b`). A component's key stays its bare name.
|
|
199
|
+
const segment = isPointerKey(modelKey) ? escapeKeySegment(modelKey) : modelKey;
|
|
200
|
+
const nakedKey = `${generatorId}|${segment}|${variant}`;
|
|
196
201
|
return nakedKey;
|
|
197
202
|
};
|
|
198
203
|
/**
|
|
@@ -404,7 +409,7 @@ export const isGqlOperationGeneratorKey = (arg) => {
|
|
|
404
409
|
* const obj = fromGeneratorKey(key);
|
|
405
410
|
* console.log(obj.type); // 'model'
|
|
406
411
|
* console.log(obj.generatorId); // 'zod-schemas'
|
|
407
|
-
* console.log(obj.refName);
|
|
412
|
+
* console.log(obj.ref.refName); // 'User'
|
|
408
413
|
* console.log(obj.variant); // 'main'
|
|
409
414
|
* }
|
|
410
415
|
* ```
|
|
@@ -478,7 +483,7 @@ export const isGeneratorOnlyKey = (arg) => {
|
|
|
478
483
|
*
|
|
479
484
|
* const modelKey = toModelGeneratorKey({
|
|
480
485
|
* generatorId: 'typescript-types',
|
|
481
|
-
* refName: 'User',
|
|
486
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
482
487
|
* variant: 'main'
|
|
483
488
|
* });
|
|
484
489
|
* console.log(toGeneratorId(modelKey)); // 'typescript-types'
|
|
@@ -536,7 +541,7 @@ export const toGeneratorId = (generatorKey) => {
|
|
|
536
541
|
*
|
|
537
542
|
* if (parsed.type === 'model') {
|
|
538
543
|
* console.log(parsed.generatorId); // 'zod-schemas'
|
|
539
|
-
* console.log(parsed.refName);
|
|
544
|
+
* console.log(parsed.ref.refName); // 'User'
|
|
540
545
|
* console.log(parsed.variant); // 'main'
|
|
541
546
|
* }
|
|
542
547
|
* ```
|
|
@@ -581,8 +586,8 @@ export const fromGeneratorKey = (generatorKey) => {
|
|
|
581
586
|
};
|
|
582
587
|
}
|
|
583
588
|
if (isModelGeneratorKey(generatorKey)) {
|
|
584
|
-
const [generatorId,
|
|
585
|
-
return { type: 'model', generatorId,
|
|
589
|
+
const [generatorId, modelKey, variant] = generatorKey.split('|');
|
|
590
|
+
return { type: 'model', generatorId, ref: fromModelKey(isPointerKey(modelKey) ? unescapeKeySegment(modelKey) : modelKey), variant };
|
|
586
591
|
}
|
|
587
592
|
return { type: 'generator-only', generatorId: generatorKey };
|
|
588
593
|
};
|
package/esm/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/esm/dsl/Inserted.js
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
* const identifier = userModel.toName(); // 'User'
|
|
39
39
|
*
|
|
40
40
|
* return new Definition({
|
|
41
|
-
* identifier: createType(this.refName),
|
|
41
|
+
* identifier: createType(this.ref.refName),
|
|
42
42
|
* value: {
|
|
43
43
|
* generatorKey: this.generatorKey,
|
|
44
44
|
* 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`. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizeWorkspacePath } from '../../helpers/normalizeWorkspacePath.js';
|
|
2
2
|
import { toModelGeneratorKey } from '../GeneratorKeys.js';
|
|
3
|
+
import { toModelKey } from '../../helpers/refFns.js';
|
|
3
4
|
import { DEFAULT_VARIANT } from '../../types/Variant.js';
|
|
4
5
|
import { readProjectionOptions, toValueOptions } from '../../types/ProjectionOptions.js';
|
|
5
6
|
import isEqual from 'lodash-es/isEqual.js';
|
|
@@ -32,7 +33,7 @@ export class ModelDriver {
|
|
|
32
33
|
writable: true,
|
|
33
34
|
value: void 0
|
|
34
35
|
});
|
|
35
|
-
Object.defineProperty(this, "
|
|
36
|
+
Object.defineProperty(this, "ref", {
|
|
36
37
|
enumerable: true,
|
|
37
38
|
configurable: true,
|
|
38
39
|
writable: true,
|
|
@@ -81,10 +82,10 @@ export class ModelDriver {
|
|
|
81
82
|
writable: true,
|
|
82
83
|
value: void 0
|
|
83
84
|
});
|
|
84
|
-
const { context, projection,
|
|
85
|
+
const { context, projection, ref, destinationPath, rootRef, noExport = false, variant = DEFAULT_VARIANT } = args;
|
|
85
86
|
this.context = context;
|
|
86
87
|
this.projection = projection;
|
|
87
|
-
this.
|
|
88
|
+
this.ref = ref;
|
|
88
89
|
this.destinationPath = destinationPath;
|
|
89
90
|
this.rootRef = rootRef;
|
|
90
91
|
this.noExport = noExport;
|
|
@@ -125,7 +126,7 @@ export class ModelDriver {
|
|
|
125
126
|
getDefinition({ identifier, exportPath }) {
|
|
126
127
|
const generatorKey = toModelGeneratorKey({
|
|
127
128
|
generatorId: this.projection.id,
|
|
128
|
-
|
|
129
|
+
ref: this.ref,
|
|
129
130
|
variant: this.settings.variant
|
|
130
131
|
});
|
|
131
132
|
const pending = findPending({ context: this.context, name: identifier.name, exportPath });
|
|
@@ -158,7 +159,7 @@ export class ModelDriver {
|
|
|
158
159
|
projection: this.projection
|
|
159
160
|
});
|
|
160
161
|
const value = whilePending({ context: this.context, marker }, () => new this.projection({
|
|
161
|
-
|
|
162
|
+
ref: this.ref,
|
|
162
163
|
context: this.context,
|
|
163
164
|
settings: this.settings,
|
|
164
165
|
destinationPath: this.settings.exportPath,
|
|
@@ -192,7 +193,7 @@ export class ModelDriver {
|
|
|
192
193
|
}
|
|
193
194
|
const currentKey = toModelGeneratorKey({
|
|
194
195
|
generatorId: this.projection.id,
|
|
195
|
-
|
|
196
|
+
ref: this.ref,
|
|
196
197
|
variant: this.settings.variant
|
|
197
198
|
});
|
|
198
199
|
assertSameKey({
|
|
@@ -298,11 +299,11 @@ export const isReferencedBack = ({ context, settings }) => {
|
|
|
298
299
|
};
|
|
299
300
|
/** A model's content settings, once the peer is known to have the variant and to support the model. */
|
|
300
301
|
const toModelSettings = (args) => {
|
|
301
|
-
const { context, projection,
|
|
302
|
-
assertPeerVariantExists({ context, generatorId: projection.id,
|
|
303
|
-
assertPeerSupported({ context, projection,
|
|
302
|
+
const { context, projection, ref, variant = DEFAULT_VARIANT } = args;
|
|
303
|
+
assertPeerVariantExists({ context, generatorId: projection.id, ref, variant });
|
|
304
|
+
assertPeerSupported({ context, projection, ref, variant });
|
|
304
305
|
return context.toModelContentSettings({
|
|
305
|
-
|
|
306
|
+
ref,
|
|
306
307
|
projection,
|
|
307
308
|
variant,
|
|
308
309
|
options: readProjectionOptions(args)
|
|
@@ -319,7 +320,7 @@ const toModelSettings = (args) => {
|
|
|
319
320
|
* {@link ModelDriver}.
|
|
320
321
|
*/
|
|
321
322
|
export const toModelRef = (args) => {
|
|
322
|
-
const { context, projection,
|
|
323
|
+
const { context, projection, ref, destinationPath, variant = DEFAULT_VARIANT } = args;
|
|
323
324
|
const settings = toModelSettings(args);
|
|
324
325
|
const pending = findPending({
|
|
325
326
|
context,
|
|
@@ -331,7 +332,7 @@ export const toModelRef = (args) => {
|
|
|
331
332
|
pending,
|
|
332
333
|
name: settings.identifier.name,
|
|
333
334
|
exportPath: settings.exportPath,
|
|
334
|
-
generatorKey: toModelGeneratorKey({ generatorId: projection.id,
|
|
335
|
+
generatorKey: toModelGeneratorKey({ generatorId: projection.id, ref, variant }),
|
|
335
336
|
options: readProjectionOptions(args),
|
|
336
337
|
projection
|
|
337
338
|
});
|
|
@@ -375,22 +376,23 @@ export const toModelRef = (args) => {
|
|
|
375
376
|
* key. The Driver throws here — loud at the call site — rather than
|
|
376
377
|
* letting silently-wrong output reach the consumer.
|
|
377
378
|
*/
|
|
378
|
-
const assertPeerVariantExists = ({ context, generatorId,
|
|
379
|
+
const assertPeerVariantExists = ({ context, generatorId, ref, variant }) => {
|
|
379
380
|
if (variant === DEFAULT_VARIANT) {
|
|
380
381
|
return;
|
|
381
382
|
}
|
|
382
|
-
const
|
|
383
|
+
const key = toModelKey(ref);
|
|
384
|
+
const modelEnrichments = context.readEnrichment([generatorId, key]);
|
|
383
385
|
if (modelEnrichments === null || modelEnrichments === undefined) {
|
|
384
|
-
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${
|
|
386
|
+
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${key}' — ` +
|
|
385
387
|
`peer has no enrichments configured. Only '${DEFAULT_VARIANT}' is permitted.`);
|
|
386
388
|
}
|
|
387
389
|
if (typeof modelEnrichments !== 'object' || Array.isArray(modelEnrichments)) {
|
|
388
|
-
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${
|
|
390
|
+
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${key}' — ` +
|
|
389
391
|
`peer enrichment is not a variant record.`);
|
|
390
392
|
}
|
|
391
393
|
if (!(variant in modelEnrichments)) {
|
|
392
394
|
const available = Object.keys(modelEnrichments).join(', ');
|
|
393
|
-
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${
|
|
395
|
+
throw new Error(`[${generatorId}] Cannot insert variant '${variant}' for '${key}'. ` +
|
|
394
396
|
`Available variants: ${available}.`);
|
|
395
397
|
}
|
|
396
398
|
};
|
|
@@ -413,10 +415,10 @@ const assertPeerVariantExists = ({ context, generatorId, refName, variant }) =>
|
|
|
413
415
|
* model: `toModelProjectionBase` defaults it to `() => true`, and a
|
|
414
416
|
* hand-rolled projection may omit it.
|
|
415
417
|
*/
|
|
416
|
-
const assertPeerSupported = ({ context, projection,
|
|
418
|
+
const assertPeerSupported = ({ context, projection, ref, variant }) => {
|
|
417
419
|
const isSupported = projection.isSupported ?? (() => true);
|
|
418
|
-
if (!isSupported({
|
|
419
|
-
throw new Error(`[${projection.id}] Cannot insert '${
|
|
420
|
+
if (!isSupported({ ref, context, variant })) {
|
|
421
|
+
throw new Error(`[${projection.id}] Cannot insert '${toModelKey(ref)}' — peer generator ` +
|
|
420
422
|
`does not support this model (isSupported returned false).`);
|
|
421
423
|
}
|
|
422
424
|
};
|
|
@@ -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
|
* });
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @param args.isSupported - Optional capability gate; a model whose predicate
|
|
16
16
|
* returns `false` is recorded `notSupported` and its `transform` is skipped.
|
|
17
17
|
* Resolve the schema inside the predicate when needed
|
|
18
|
-
* (`context.resolveSchemaRefOnce(
|
|
18
|
+
* (`context.resolveSchemaRefOnce(ref)`). Defaults to supporting every model.
|
|
19
19
|
* @param args.toPreviewModule - Optional function to generate preview modules
|
|
20
20
|
* @param args.toEnrichmentSchema - Optional function to provide enrichment validation
|
|
21
21
|
* @param args.toEnrichmentRequest - Optional function to request enrichments
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
*
|
|
28
28
|
* const typeScriptModelEntry = toModelEntry({
|
|
29
29
|
* id: 'typescript-models',
|
|
30
|
-
* transform: ({ context,
|
|
31
|
-
* context.insertModel(TsModel,
|
|
30
|
+
* transform: ({ context, ref }) => {
|
|
31
|
+
* context.insertModel(TsModel, ref);
|
|
32
32
|
* },
|
|
33
|
-
* toPreviewModule: ({ context,
|
|
33
|
+
* toPreviewModule: ({ context, ref }) => ({
|
|
34
34
|
* group: 'forms',
|
|
35
|
-
* title: `${refName} Model`,
|
|
35
|
+
* title: `${ref.refName} Model`,
|
|
36
36
|
* description: 'Generated TypeScript interface'
|
|
37
37
|
* })
|
|
38
38
|
* });
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
* ```typescript
|
|
43
43
|
* const validationModelEntry = toModelEntry({
|
|
44
44
|
* id: 'validation-schemas',
|
|
45
|
-
* transform: ({ context,
|
|
46
|
-
* context.insertModel(ValidationModel,
|
|
45
|
+
* transform: ({ context, ref }) => {
|
|
46
|
+
* context.insertModel(ValidationModel, ref);
|
|
47
47
|
* },
|
|
48
48
|
* toEnrichmentSchema: () => v.object({
|
|
49
49
|
* strict: v.optional(v.boolean()),
|
|
50
50
|
* nullable: v.optional(v.boolean())
|
|
51
51
|
* }),
|
|
52
|
-
* toEnrichmentRequest: (
|
|
53
|
-
* path: `models.${refName}`,
|
|
52
|
+
* toEnrichmentRequest: (ref) => ({
|
|
53
|
+
* path: `models.${ref.refName}`,
|
|
54
54
|
* schema: enrichmentSchema
|
|
55
55
|
* })
|
|
56
56
|
* });
|