@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenerateContextType, InsertNormalizedModelArgs, InsertNormalizedModelOptions, InsertNormalizedModelReturn } from '../../context/generateTypes.js';
|
|
2
2
|
import { type ProjectionOptionsArg, type ProjectionOptionsRest } from '../../types/ProjectionOptions.js';
|
|
3
3
|
import { type PeerInsertOptions } from '../../types/InsertOptions.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type RefParts } from '../../helpers/refFns.js';
|
|
5
5
|
import type { ContentSettings } from '../ContentSettings.js';
|
|
6
6
|
import type { LangSnippetConstructor } from '../Lang.js';
|
|
7
7
|
import type { IdentifierType } from '../IdentifierType.js';
|
|
@@ -21,10 +21,11 @@ import type * as v from 'valibot';
|
|
|
21
21
|
export type ModelProjectionArgs<EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
22
22
|
context: GenerateContextType;
|
|
23
23
|
settings: ContentSettings<EnrichmentType>;
|
|
24
|
-
|
|
24
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
25
|
+
ref: RefParts;
|
|
25
26
|
} & ProjectionOptionsArg<ProjectionOptions>;
|
|
26
27
|
type ToEnrichmentsArgs = {
|
|
27
|
-
|
|
28
|
+
ref: RefParts;
|
|
28
29
|
context: GenerateContextType;
|
|
29
30
|
/** Model variant whose enrichment should be resolved (see {@link Variant}) */
|
|
30
31
|
variant: string;
|
|
@@ -52,7 +53,7 @@ export type ModelProjectionBaseConfig<EnrichmentType = undefined, IdType extends
|
|
|
52
53
|
* `type` is bound to that language's `EntityType` vocabulary (the loose
|
|
53
54
|
* `string` by default). The tightening rides the type argument.
|
|
54
55
|
*/
|
|
55
|
-
toIdentifierType: (
|
|
56
|
+
toIdentifierType: (ref: RefParts, context: GenerateContextType) => IdType;
|
|
56
57
|
toExportPath: (args: ToModelExportPathArgs<EnrichmentType, ProjectionOptions>) => string;
|
|
57
58
|
/**
|
|
58
59
|
* Required composite schema for the `{ subject, generator, stack }`
|
|
@@ -76,10 +77,12 @@ export type ModelProjectionBaseConfig<EnrichmentType = undefined, IdType extends
|
|
|
76
77
|
* `insertModel` (the model counterpart of the operation-reference
|
|
77
78
|
* protocol). When omitted, advertises support for every model.
|
|
78
79
|
*/
|
|
79
|
-
isSupported?: (args:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
isSupported?: (args: IsSupportedArgs) => boolean;
|
|
81
|
+
};
|
|
82
|
+
/** What a model projection's `isSupported` receives. */
|
|
83
|
+
type IsSupportedArgs = {
|
|
84
|
+
ref: RefParts;
|
|
85
|
+
context: GenerateContextType;
|
|
83
86
|
};
|
|
84
87
|
/**
|
|
85
88
|
* Build a model projection base class from a per-generator config.
|
|
@@ -103,7 +106,8 @@ export type ModelProjectionBaseConfig<EnrichmentType = undefined, IdType extends
|
|
|
103
106
|
export declare const toModelProjectionBase: <EnrichmentType = undefined, IdType extends IdentifierType = IdentifierType, ProjectionOptions = undefined>(base: LangSnippetConstructor, config: ModelProjectionBaseConfig<EnrichmentType, IdType, ProjectionOptions>) => {
|
|
104
107
|
new (args: ModelProjectionArgs<EnrichmentType, ProjectionOptions>): {
|
|
105
108
|
settings: ContentSettings<EnrichmentType>;
|
|
106
|
-
|
|
109
|
+
/** The ref this model is built for (see {@link RefParts}). */
|
|
110
|
+
ref: RefParts;
|
|
107
111
|
/** The caller's options. */
|
|
108
112
|
options: ProjectionOptions;
|
|
109
113
|
/**
|
|
@@ -112,7 +116,7 @@ export declare const toModelProjectionBase: <EnrichmentType = undefined, IdType
|
|
|
112
116
|
* unless `noExport` is set. `{ options }` is required when the peer
|
|
113
117
|
* declares options and refused when it does not.
|
|
114
118
|
*/
|
|
115
|
-
insertModel<V extends GeneratedValue, PeerEnrichmentType = undefined, PeerProjectionOptions = undefined>(projection: ModelProjection<V, PeerEnrichmentType, PeerProjectionOptions>,
|
|
119
|
+
insertModel<V extends GeneratedValue, PeerEnrichmentType = undefined, PeerProjectionOptions = undefined>(projection: ModelProjection<V, PeerEnrichmentType, PeerProjectionOptions>, ref: RefParts, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions>, PeerProjectionOptions>): Inserted<V, PeerEnrichmentType>;
|
|
116
120
|
/**
|
|
117
121
|
* Insert a related model with reference normalization. If `schema` is a
|
|
118
122
|
* `$ref`, the referenced name is used; otherwise `fallbackName` applies.
|
|
@@ -126,19 +130,16 @@ export declare const toModelProjectionBase: <EnrichmentType = undefined, IdType
|
|
|
126
130
|
id: string;
|
|
127
131
|
type: "model";
|
|
128
132
|
toIdentifierName: (args: ToModelIdentifierNameArgs<EnrichmentType, ProjectionOptions>) => string;
|
|
129
|
-
toIdentifierType: (
|
|
133
|
+
toIdentifierType: (ref: RefParts, context: GenerateContextType) => IdType;
|
|
130
134
|
toExportPath: (args: ToModelExportPathArgs<EnrichmentType, ProjectionOptions>) => string;
|
|
131
|
-
toEnrichments: ({
|
|
135
|
+
toEnrichments: ({ ref, context, variant }: ToEnrichmentsArgs) => EnrichmentType;
|
|
132
136
|
/**
|
|
133
137
|
* Derive the seed enrichment values for a model from its schema (the CMS
|
|
134
138
|
* persists these, then the user edits). Returns `undefined` when the
|
|
135
139
|
* generator declares no `toEnrichmentDefaults` — the common case.
|
|
136
140
|
*/
|
|
137
141
|
toEnrichmentDefaults: (args: ToEnrichmentsArgs) => EnrichmentType | undefined;
|
|
138
|
-
isSupported: (args:
|
|
139
|
-
refName: RefName;
|
|
140
|
-
context: GenerateContextType;
|
|
141
|
-
}) => boolean;
|
|
142
|
+
isSupported: (args: IsSupportedArgs) => boolean;
|
|
142
143
|
lang: import("../Lang.js").Lang;
|
|
143
144
|
};
|
|
144
145
|
export {};
|
|
@@ -4,6 +4,7 @@ exports.toModelProjectionBase = void 0;
|
|
|
4
4
|
const ProjectionOptions_js_1 = require("../../types/ProjectionOptions.js");
|
|
5
5
|
const InsertOptions_js_1 = require("../../types/InsertOptions.js");
|
|
6
6
|
const GeneratorKeys_js_1 = require("../GeneratorKeys.js");
|
|
7
|
+
const refFns_js_1 = require("../../helpers/refFns.js");
|
|
7
8
|
const Variant_js_1 = require("../../types/Variant.js");
|
|
8
9
|
const parseEnrichmentUmbrella_js_1 = require("../../enrichments/parseEnrichmentUmbrella.js");
|
|
9
10
|
/**
|
|
@@ -33,7 +34,7 @@ const toModelProjectionBase = (base, config) => {
|
|
|
33
34
|
context: args.context,
|
|
34
35
|
generatorKey: (0, GeneratorKeys_js_1.toModelGeneratorKey)({
|
|
35
36
|
generatorId: config.id,
|
|
36
|
-
|
|
37
|
+
ref: args.ref,
|
|
37
38
|
variant: args.settings.variant ?? Variant_js_1.DEFAULT_VARIANT
|
|
38
39
|
})
|
|
39
40
|
});
|
|
@@ -43,7 +44,8 @@ const toModelProjectionBase = (base, config) => {
|
|
|
43
44
|
writable: true,
|
|
44
45
|
value: void 0
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
+
/** The ref this model is built for (see {@link RefParts}). */
|
|
48
|
+
Object.defineProperty(this, "ref", {
|
|
47
49
|
enumerable: true,
|
|
48
50
|
configurable: true,
|
|
49
51
|
writable: true,
|
|
@@ -56,7 +58,7 @@ const toModelProjectionBase = (base, config) => {
|
|
|
56
58
|
writable: true,
|
|
57
59
|
value: void 0
|
|
58
60
|
});
|
|
59
|
-
this.
|
|
61
|
+
this.ref = args.ref;
|
|
60
62
|
this.settings = args.settings;
|
|
61
63
|
this.options = (0, ProjectionOptions_js_1.readProjectionOptions)(args);
|
|
62
64
|
}
|
|
@@ -66,8 +68,8 @@ const toModelProjectionBase = (base, config) => {
|
|
|
66
68
|
* unless `noExport` is set. `{ options }` is required when the peer
|
|
67
69
|
* declares options and refused when it does not.
|
|
68
70
|
*/
|
|
69
|
-
insertModel(projection,
|
|
70
|
-
return this.context.insertModel(projection,
|
|
71
|
+
insertModel(projection, ref, ...rest) {
|
|
72
|
+
return this.context.insertModel(projection, ref, {
|
|
71
73
|
...(0, InsertOptions_js_1.toPeerInsertOptions)(rest),
|
|
72
74
|
destinationPath: this.settings.exportPath
|
|
73
75
|
});
|
|
@@ -118,10 +120,12 @@ const toModelProjectionBase = (base, config) => {
|
|
|
118
120
|
enumerable: true,
|
|
119
121
|
configurable: true,
|
|
120
122
|
writable: true,
|
|
121
|
-
value: ({
|
|
123
|
+
value: ({ ref, context, variant }) => {
|
|
122
124
|
// The three enrichment scopes assembled into the umbrella a generator
|
|
123
125
|
// reads off `this.settings.enrichments`. Subject is per-item
|
|
124
|
-
// (`[id][refName][variant]
|
|
126
|
+
// (`[id][refName][variant]`, or the whole pointer in place of
|
|
127
|
+
// `refName` for a ref that does not point at a component, `toModelKey`)
|
|
128
|
+
// — the variant axis is core-owned, and the
|
|
125
129
|
// engine has already asserted `'main'` exists; generator and stack are
|
|
126
130
|
// run-constants (`[id][_generator]`, `[_stack]`). The required composite
|
|
127
131
|
// schema parses the raw umbrella once — typed, cast-free.
|
|
@@ -130,7 +134,7 @@ const toModelProjectionBase = (base, config) => {
|
|
|
130
134
|
return (0, parseEnrichmentUmbrella_js_1.parseEnrichmentUmbrella)({
|
|
131
135
|
context,
|
|
132
136
|
generatorId: config.id,
|
|
133
|
-
subjectSegments: [
|
|
137
|
+
subjectSegments: [(0, refFns_js_1.toModelKey)(ref), variant],
|
|
134
138
|
schema: config.toEnrichmentSchema()
|
|
135
139
|
});
|
|
136
140
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenerateContextType } from '../../context/generateTypes.js';
|
|
2
2
|
import type { Lang } from '../Lang.js';
|
|
3
3
|
import type { ContentSettings } from '../ContentSettings.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { RefParts } from '../../helpers/refFns.js';
|
|
5
5
|
import type { IdentifierType } from '../IdentifierType.js';
|
|
6
6
|
import type { IdentifierBase } from '../IdentifierBase.js';
|
|
7
7
|
import type { GeneratedValue } from '../GeneratedValue.js';
|
|
@@ -16,27 +16,31 @@ import type { ProjectionOptionsArg } from '../../types/ProjectionOptions.js';
|
|
|
16
16
|
*/
|
|
17
17
|
export type ModelProjectionConstructorArgs<EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
18
18
|
context: GenerateContextType;
|
|
19
|
-
|
|
19
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
20
|
+
ref: RefParts;
|
|
20
21
|
settings: ContentSettings<EnrichmentType>;
|
|
21
22
|
destinationPath: string;
|
|
22
|
-
rootRef?:
|
|
23
|
+
rootRef?: RefParts;
|
|
23
24
|
} & ProjectionOptionsArg<ProjectionOptions>;
|
|
24
25
|
export type WithTransformModel = {
|
|
25
|
-
transformModel: (
|
|
26
|
+
transformModel: (ref: RefParts) => void;
|
|
26
27
|
};
|
|
27
28
|
export type ToModelEnrichmentsArgs = {
|
|
28
|
-
|
|
29
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
30
|
+
ref: RefParts;
|
|
29
31
|
context: GenerateContextType;
|
|
30
32
|
/** Model variant whose enrichment should be resolved (see {@link Variant}) */
|
|
31
33
|
variant: string;
|
|
32
34
|
};
|
|
33
35
|
export type TransformModelArgs = {
|
|
34
36
|
context: GenerateContextType;
|
|
35
|
-
|
|
37
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
38
|
+
ref: RefParts;
|
|
36
39
|
/**
|
|
37
40
|
* The model variant the engine is dispatching for this call. The
|
|
38
41
|
* engine fans out one `transform` call per variant declared in the
|
|
39
|
-
* consumer's `enrichments[id][refName]` block (
|
|
42
|
+
* consumer's `enrichments[id][refName]` block (the whole pointer for a
|
|
43
|
+
* model that is not a component) (or just `'main'`
|
|
40
44
|
* when no enrichments are configured). See {@link Variant}.
|
|
41
45
|
*/
|
|
42
46
|
variant: string;
|
|
@@ -46,24 +50,27 @@ export type TransformModelArgs = {
|
|
|
46
50
|
* entry/dispatch boundary. The capability counterpart of
|
|
47
51
|
* {@link TransformModelArgs}: it carries the resolved enrichment umbrella so
|
|
48
52
|
* the predicate can gate on user config, but no schema — the predicate
|
|
49
|
-
* resolves the schema itself (`context.resolveSchemaRefOnce(
|
|
53
|
+
* resolves the schema itself (`context.resolveSchemaRefOnce(ref)`)
|
|
50
54
|
* when it needs it, mirroring how `transform` works.
|
|
51
55
|
*/
|
|
52
56
|
export type IsSupportedModelArgs = {
|
|
53
57
|
context: GenerateContextType;
|
|
54
|
-
|
|
58
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
59
|
+
ref: RefParts;
|
|
55
60
|
/** Model variant being probed (see {@link Variant}) */
|
|
56
61
|
variant: string;
|
|
57
62
|
};
|
|
58
63
|
export type ToModelPreviewModuleArgs = {
|
|
59
64
|
context: GenerateContextType;
|
|
60
|
-
|
|
65
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
66
|
+
ref: RefParts;
|
|
61
67
|
/** Model variant the preview module describes (see {@link Variant}) */
|
|
62
68
|
variant: string;
|
|
63
69
|
};
|
|
64
70
|
export type ToModelMappingArgs = {
|
|
65
71
|
context: GenerateContextType;
|
|
66
|
-
|
|
72
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
73
|
+
ref: RefParts;
|
|
67
74
|
/** Model variant the mapping module describes (see {@link Variant}) */
|
|
68
75
|
variant: string;
|
|
69
76
|
};
|
|
@@ -72,13 +79,15 @@ export type ToModelMappingArgs = {
|
|
|
72
79
|
* depends on them: definitions are cached by name and export path.
|
|
73
80
|
*/
|
|
74
81
|
export type ToModelIdentifierNameArgs<EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
75
|
-
|
|
82
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
83
|
+
ref: RefParts;
|
|
76
84
|
enrichments: EnrichmentType;
|
|
77
85
|
/** Model variant the identifier should disambiguate (see {@link Variant}) */
|
|
78
86
|
variant: string;
|
|
79
87
|
} & ProjectionOptionsArg<ProjectionOptions>;
|
|
80
88
|
export type ToModelExportPathArgs<EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
81
|
-
|
|
89
|
+
/** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
|
|
90
|
+
ref: RefParts;
|
|
82
91
|
enrichments: EnrichmentType;
|
|
83
92
|
/** Model variant the export path should disambiguate (see {@link Variant}) */
|
|
84
93
|
variant: string;
|
|
@@ -95,7 +104,7 @@ export type ToModelExportPathArgs<EnrichmentType = undefined, ProjectionOptions
|
|
|
95
104
|
export type ModelProjection<V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
96
105
|
prototype: V;
|
|
97
106
|
} & {
|
|
98
|
-
new ({ context,
|
|
107
|
+
new ({ context, ref, settings, destinationPath, rootRef, options }: ModelProjectionConstructorArgs<EnrichmentType, ProjectionOptions>): V;
|
|
99
108
|
id: string;
|
|
100
109
|
type: 'model';
|
|
101
110
|
/**
|
|
@@ -111,11 +120,11 @@ export type ModelProjection<V extends GeneratedValue, EnrichmentType = undefined
|
|
|
111
120
|
* Context-aware, overridable: the non-`name` parts of the identifier
|
|
112
121
|
* (`type` / `typeName` / `exported`), derived from the schema. The engine
|
|
113
122
|
* assembles `lang.toIdentifier({ name: toIdentifierName(args),
|
|
114
|
-
* ...toIdentifierType(
|
|
123
|
+
* ...toIdentifierType(ref, context) })`.
|
|
115
124
|
*/
|
|
116
|
-
toIdentifierType: (
|
|
125
|
+
toIdentifierType: (ref: RefParts, context: GenerateContextType) => IdentifierType;
|
|
117
126
|
toExportPath: (args: ToModelExportPathArgs<EnrichmentType, ProjectionOptions>) => string;
|
|
118
|
-
toEnrichments: ({
|
|
127
|
+
toEnrichments: ({ ref, context, variant }: ToModelEnrichmentsArgs) => EnrichmentType;
|
|
119
128
|
/**
|
|
120
129
|
* Family-level capability predicate, surfaced as a static by
|
|
121
130
|
* `toModelProjectionBase` (default `() => true`). The Driver probes it on
|
|
@@ -9,7 +9,7 @@ import type { IdentifierType } from '../../IdentifierType.js';
|
|
|
9
9
|
import type { GeneratedValue } from '../../GeneratedValue.js';
|
|
10
10
|
import type { Inserted } from '../../Inserted.js';
|
|
11
11
|
import type { ModelProjection, NormalizedModelProjection } from '../../model/types.js';
|
|
12
|
-
import type {
|
|
12
|
+
import type { RefParts } from '../../../helpers/refFns.js';
|
|
13
13
|
import type { OasSchema } from '../../../oas/schema/Schema.js';
|
|
14
14
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
15
15
|
import type { OasVoid } from '../../../oas/void/Void.js';
|
|
@@ -103,7 +103,7 @@ export declare const toGqlOperationProjectionBase: <EnrichmentType = undefined,
|
|
|
103
103
|
* `{ options }` is required when the peer declares options and refused
|
|
104
104
|
* when it does not.
|
|
105
105
|
*/
|
|
106
|
-
insertModel<V extends GeneratedValue, PeerEnrichmentType_1 = undefined, PeerProjectionOptions_1 = undefined>(projection: ModelProjection<V, PeerEnrichmentType_1, PeerProjectionOptions_1>,
|
|
106
|
+
insertModel<V extends GeneratedValue, PeerEnrichmentType_1 = undefined, PeerProjectionOptions_1 = undefined>(projection: ModelProjection<V, PeerEnrichmentType_1, PeerProjectionOptions_1>, ref: RefParts, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions_1>, PeerProjectionOptions_1>): Inserted<V, PeerEnrichmentType_1>;
|
|
107
107
|
/**
|
|
108
108
|
* Insert a related model with reference normalization. Useful for
|
|
109
109
|
* schemas that may be either a `$ref` or a concrete object.
|
|
@@ -86,8 +86,8 @@ const toGqlOperationProjectionBase = (base, config) => {
|
|
|
86
86
|
* `{ options }` is required when the peer declares options and refused
|
|
87
87
|
* when it does not.
|
|
88
88
|
*/
|
|
89
|
-
insertModel(projection,
|
|
90
|
-
return this.context.insertModel(projection,
|
|
89
|
+
insertModel(projection, ref, ...rest) {
|
|
90
|
+
return this.context.insertModel(projection, ref, {
|
|
91
91
|
...(0, InsertOptions_js_1.toPeerInsertOptions)(rest),
|
|
92
92
|
destinationPath: this.settings.exportPath
|
|
93
93
|
});
|
|
@@ -10,7 +10,7 @@ import type { IdentifierType } from '../../IdentifierType.js';
|
|
|
10
10
|
import type { GeneratedValue } from '../../GeneratedValue.js';
|
|
11
11
|
import type { Inserted } from '../../Inserted.js';
|
|
12
12
|
import type { ModelProjection, NormalizedModelProjection } from '../../model/types.js';
|
|
13
|
-
import type {
|
|
13
|
+
import type { RefParts } from '../../../helpers/refFns.js';
|
|
14
14
|
import type { OasSchema } from '../../../oas/schema/Schema.js';
|
|
15
15
|
import type { OasRef } from '../../../oas/ref/Ref.js';
|
|
16
16
|
import type { OasVoid } from '../../../oas/void/Void.js';
|
|
@@ -128,7 +128,7 @@ export declare const toOasOperationProjectionBase: <EnrichmentType = undefined,
|
|
|
128
128
|
* `{ options }` is required when the peer declares options and refused
|
|
129
129
|
* when it does not.
|
|
130
130
|
*/
|
|
131
|
-
insertModel<V extends GeneratedValue, PeerEnrichmentType_1 = undefined, PeerProjectionOptions_1 = undefined>(projection: ModelProjection<V, PeerEnrichmentType_1, PeerProjectionOptions_1>,
|
|
131
|
+
insertModel<V extends GeneratedValue, PeerEnrichmentType_1 = undefined, PeerProjectionOptions_1 = undefined>(projection: ModelProjection<V, PeerEnrichmentType_1, PeerProjectionOptions_1>, ref: RefParts, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions_1>, PeerProjectionOptions_1>): Inserted<V, PeerEnrichmentType_1>;
|
|
132
132
|
/**
|
|
133
133
|
* Insert a related model with reference normalization. Useful for inline
|
|
134
134
|
* request/response schemas where the schema may be either a `$ref` or a
|
|
@@ -103,8 +103,8 @@ const toOasOperationProjectionBase = (base, config) => {
|
|
|
103
103
|
* `{ options }` is required when the peer declares options and refused
|
|
104
104
|
* when it does not.
|
|
105
105
|
*/
|
|
106
|
-
insertModel(projection,
|
|
107
|
-
return this.context.insertModel(projection,
|
|
106
|
+
insertModel(projection, ref, ...rest) {
|
|
107
|
+
return this.context.insertModel(projection, ref, {
|
|
108
108
|
...(0, InsertOptions_js_1.toPeerInsertOptions)(rest),
|
|
109
109
|
destinationPath: this.settings.exportPath
|
|
110
110
|
});
|
|
@@ -11,7 +11,7 @@ import type { GeneratedValue } from '../GeneratedValue.js';
|
|
|
11
11
|
import type { Inserted } from '../Inserted.js';
|
|
12
12
|
import type { ModelProjection, NormalizedModelProjection } from '../model/types.js';
|
|
13
13
|
import type { OasOperationProjection } from '../operation/oas/types.js';
|
|
14
|
-
import type {
|
|
14
|
+
import type { RefParts } from '../../helpers/refFns.js';
|
|
15
15
|
import type { OasSchema } from '../../oas/schema/Schema.js';
|
|
16
16
|
import type { OasRef } from '../../oas/ref/Ref.js';
|
|
17
17
|
import type { OasVoid } from '../../oas/void/Void.js';
|
|
@@ -98,7 +98,7 @@ export declare const toWebhookProjectionBase: <EnrichmentType = undefined, IdTyp
|
|
|
98
98
|
* webhook's payload type). `{ options }` is required when the peer
|
|
99
99
|
* declares options and refused when it does not.
|
|
100
100
|
*/
|
|
101
|
-
insertModel<V extends GeneratedValue, PeerEnrichmentType_1 = undefined, PeerProjectionOptions_1 = undefined>(projection: ModelProjection<V, PeerEnrichmentType_1, PeerProjectionOptions_1>,
|
|
101
|
+
insertModel<V extends GeneratedValue, PeerEnrichmentType_1 = undefined, PeerProjectionOptions_1 = undefined>(projection: ModelProjection<V, PeerEnrichmentType_1, PeerProjectionOptions_1>, ref: RefParts, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions_1>, PeerProjectionOptions_1>): Inserted<V, PeerEnrichmentType_1>;
|
|
102
102
|
/**
|
|
103
103
|
* Insert a related model with reference normalization. Useful for inline
|
|
104
104
|
* payload schemas where the schema may be either a `$ref` or a concrete
|
|
@@ -73,8 +73,8 @@ const toWebhookProjectionBase = (base, config) => {
|
|
|
73
73
|
* webhook's payload type). `{ options }` is required when the peer
|
|
74
74
|
* declares options and refused when it does not.
|
|
75
75
|
*/
|
|
76
|
-
insertModel(projection,
|
|
77
|
-
return this.context.insertModel(projection,
|
|
76
|
+
insertModel(projection, ref, ...rest) {
|
|
77
|
+
return this.context.insertModel(projection, ref, {
|
|
78
78
|
...(0, InsertOptions_js_1.toPeerInsertOptions)(rest),
|
|
79
79
|
destinationPath: this.settings.exportPath
|
|
80
80
|
});
|
|
@@ -3,52 +3,117 @@ import type { RefName } from '../types/RefName.js';
|
|
|
3
3
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
4
4
|
import type { ReferenceObject } from '../parse/v3-0/_merge-all-of/types.js';
|
|
5
5
|
import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
6
|
+
import type { OasRefData } from '../oas/ref/ref-types.js';
|
|
7
|
+
/** The kind of component a `$ref` points at: `schema`, `parameter`, `response`, and so on. */
|
|
8
|
+
type RefType = OasRefData['refType'];
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
10
|
+
* Where a `$ref` points, in two parts: `refPath`, the JSON pointer before its
|
|
11
|
+
* last segment, and `refName`, that last segment unescaped.
|
|
12
|
+
* `#/components/schemas/Pet` is `refPath` `#/components/schemas` and `refName`
|
|
13
|
+
* `Pet`. `#/components/schemas/__sharedInput/$defs/schema0` is `refPath`
|
|
14
|
+
* `#/components/schemas/__sharedInput/$defs` and `refName` `schema0`.
|
|
15
|
+
*
|
|
16
|
+
* `refPath` has one spelling, whatever the `$ref` has: no percent escapes, and
|
|
17
|
+
* `~` and `/` in a segment as `~0` and `~1` (RFC 6901). Two refs to one place
|
|
18
|
+
* have equal parts.
|
|
19
|
+
*
|
|
20
|
+
* The model API takes a model's ref in this shape (`insertModel(Peer, ref)`,
|
|
21
|
+
* `toIdentifierName({ ref, … })`), so the two parts travel together. An
|
|
22
|
+
* `OasRef` has both fields and fits it as it is.
|
|
23
|
+
*/
|
|
24
|
+
export type RefParts = {
|
|
25
|
+
/** The last segment of the pointer, unescaped. Empty for a `$ref` that ends in `/`. */
|
|
26
|
+
refName: RefName;
|
|
27
|
+
/**
|
|
28
|
+
* The pointer before the last segment, starting with `#`, with no percent
|
|
29
|
+
* escapes. A remote `$ref` ({@link isRemoteRefPath}) has the file before the `#`.
|
|
30
|
+
*/
|
|
31
|
+
refPath: string;
|
|
32
|
+
};
|
|
33
|
+
type ToRefPartsArgs = {
|
|
34
|
+
$ref: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Splits a `$ref` into {@link RefParts}.
|
|
32
38
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* toRefName('invalid/ref/'); // Error: 'Invalid reference'
|
|
37
|
-
* toRefName('#/components/schemas/'); // Error: 'Invalid reference'
|
|
38
|
-
* ```
|
|
39
|
+
* A `$ref` is a URI whose fragment holds a JSON pointer (RFC 6901), so the
|
|
40
|
+
* name is unescaped as one: `%20` is a space, and `~1` and `~0` are `/` and
|
|
41
|
+
* `~`. `#/components/schemas/Foo%20Bar` names the component `Foo Bar`.
|
|
39
42
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
* A remote `$ref`, one that does not start with `#`, points outside the
|
|
44
|
+
* document, so its `refPath` does not start with `#` and it names nothing
|
|
45
|
+
* here: `other.yml#/components/schemas/A` is `refPath`
|
|
46
|
+
* `other.yml#/components/schemas` and `refName` `A`. This never throws: a
|
|
47
|
+
* `$ref` that names nothing is found out when it is resolved.
|
|
48
|
+
*/
|
|
49
|
+
export declare const toRefParts: ({ $ref }: ToRefPartsArgs) => RefParts;
|
|
50
|
+
/** The `components` bucket that holds components of each kind: `schemas`, `parameters`, and so on. */
|
|
51
|
+
export declare const toComponentsBucket: (refType: RefType) => string;
|
|
52
|
+
/**
|
|
53
|
+
* Whether a `refPath` is that of a remote `$ref`: one that points outside the
|
|
54
|
+
* document (`other.yml#/components/schemas/A`, `./pet.yaml`, a bare id). Core
|
|
55
|
+
* does not fetch, so a remote `$ref` names nothing. The document is bundled
|
|
56
|
+
* into one before core reads it.
|
|
57
|
+
*/
|
|
58
|
+
export declare const isRemoteRefPath: (refPath: string) => boolean;
|
|
59
|
+
/** The segments of a `refPath` in the document, each unescaped. `#` has none. */
|
|
60
|
+
export declare const toRefPathSegments: (refPath: string) => string[];
|
|
61
|
+
type IsDefaultRefPathArgs = {
|
|
62
|
+
refPath: string;
|
|
63
|
+
refType: RefType;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The `components` bucket a `refPath` is, such as `schemas` for
|
|
67
|
+
* `#/components/schemas`, or `undefined` for any other path. A ref whose path
|
|
68
|
+
* is a bucket names a component, of the bucket's kind whatever kind the ref
|
|
69
|
+
* is written for; any other ref points into a document's content, as one into
|
|
70
|
+
* an extension of `components` (`#/components/x-shared/Foo`) does. A bucket
|
|
71
|
+
* core does not read (`pathItems`) is still a bucket.
|
|
72
|
+
*/
|
|
73
|
+
export declare const toRefPathBucket: (refPath: string) => string | undefined;
|
|
74
|
+
/** Whether `refPath` is where components of `refType` live, as `toRefParts` spells it. */
|
|
75
|
+
export declare const isDefaultRefPath: ({ refPath, refType }: IsDefaultRefPathArgs) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The whole pointer of a ref, with no percent escapes. Two `$ref`s that point
|
|
78
|
+
* at the same place give the same pointer, so it keys a ref that does not
|
|
79
|
+
* point at a component. A remote `$ref` is given as written.
|
|
80
|
+
*/
|
|
81
|
+
export declare const toRefPointer: ({ refName, refPath }: RefParts) => string;
|
|
82
|
+
/**
|
|
83
|
+
* The ref of the schema component named `refName`: `refPath`
|
|
84
|
+
* `#/components/schemas`. For code that holds a component's name but no
|
|
85
|
+
* `OasRef`, such as the engine's sweep over `components.schemas`.
|
|
86
|
+
*/
|
|
87
|
+
export declare const toSchemaComponentRef: (refName: RefName) => RefParts;
|
|
88
|
+
/**
|
|
89
|
+
* The key a model is known by in the engine: its generator key, its
|
|
90
|
+
* enrichments (`[id][key][variant]`) and its manifest entry. A component
|
|
91
|
+
* (`refPath` `#/components/schemas`) is keyed by its `refName`, as it always
|
|
92
|
+
* was. Any other target is keyed by its whole pointer ({@link toRefPointer}),
|
|
93
|
+
* so two targets that share a `refName` stay apart.
|
|
94
|
+
*/
|
|
95
|
+
export declare const toModelKey: ({ refName, refPath }: RefParts) => string;
|
|
96
|
+
/**
|
|
97
|
+
* A name for a model that differs between targets with one `refName`
|
|
98
|
+
* (`…/properties/disk` under two schemas). A component is named by its
|
|
99
|
+
* `refName`, through `toComponentName`. Any other target is named by its whole
|
|
100
|
+
* pointer, its segments joined by `_`: `Order_items`, `Pet_properties_tag`.
|
|
101
|
+
* A segment that is not alphanumeric gets a hash, so `@type` and `type` differ.
|
|
102
|
+
*/
|
|
103
|
+
export declare const toModelName: ({ refName, refPath }: RefParts, toComponentName?: (refName: string) => string) => string;
|
|
104
|
+
/** Whether a model key ({@link toModelKey}) is a whole pointer, and not a component's `refName`. */
|
|
105
|
+
export declare const isPointerKey: (key: string) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Reverses {@link toModelKey}, for a key read back out of a generator key.
|
|
108
|
+
* A pointer starts with `#/`; any other key is a component's `refName`. A key
|
|
109
|
+
* has no percent escapes, so a `%` in it is read as written.
|
|
110
|
+
*/
|
|
111
|
+
export declare const fromModelKey: (key: string) => RefParts;
|
|
112
|
+
/**
|
|
113
|
+
* The value at a ref's pointer in a raw document, or `undefined` when the
|
|
114
|
+
* pointer leads nowhere, or out of the document. It walks objects by key and arrays by index.
|
|
50
115
|
*/
|
|
51
|
-
export declare const
|
|
116
|
+
export declare const toRawRefTarget: (document: unknown, { refName, refPath }: RefParts) => unknown;
|
|
52
117
|
/**
|
|
53
118
|
* Type representing an object with a $ref property.
|
|
54
119
|
*/
|
|
@@ -75,7 +140,7 @@ type Ref = {
|
|
|
75
140
|
* if (isRef(schemaOrRef)) {
|
|
76
141
|
* // TypeScript now knows schemaOrRef has a $ref property
|
|
77
142
|
* console.log(schemaOrRef.$ref); // Safe to access
|
|
78
|
-
* const refName =
|
|
143
|
+
* const { refName, refPath } = toRefParts({ $ref: schemaOrRef.$ref });
|
|
79
144
|
* } else {
|
|
80
145
|
* // Handle as actual schema object
|
|
81
146
|
* console.log('Direct schema object');
|