@skmtc/core 0.44.2 → 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.
Files changed (113) hide show
  1. package/esm/anchors/attribute.js +3 -2
  2. package/esm/context/CoreContext.d.ts +1 -1
  3. package/esm/context/CoreContext.js +1 -1
  4. package/esm/context/GenerateContext.d.ts +13 -10
  5. package/esm/context/GenerateContext.js +36 -25
  6. package/esm/context/ParseContext.js +136 -34
  7. package/esm/context/generateTypes.d.ts +7 -6
  8. package/esm/context/generateTypes.js +2 -0
  9. package/esm/dsl/GeneratorKeys.d.ts +21 -15
  10. package/esm/dsl/GeneratorKeys.js +16 -11
  11. package/esm/dsl/Inserted.d.ts +1 -1
  12. package/esm/dsl/Inserted.js +1 -1
  13. package/esm/dsl/model/ModelDriver.d.ts +6 -5
  14. package/esm/dsl/model/ModelDriver.js +22 -20
  15. package/esm/dsl/model/toModelEntry.d.ts +18 -18
  16. package/esm/dsl/model/toModelEntry.js +9 -9
  17. package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
  18. package/esm/dsl/model/toModelProjectionBase.js +12 -8
  19. package/esm/dsl/model/types.d.ts +26 -17
  20. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  21. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  22. package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  23. package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  24. package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  25. package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
  26. package/esm/helpers/refFns.d.ts +108 -43
  27. package/esm/helpers/refFns.js +166 -57
  28. package/esm/oas/document/Document.d.ts +6 -0
  29. package/esm/oas/document/Document.js +44 -2
  30. package/esm/oas/header/Header.js +4 -1
  31. package/esm/oas/parameter/Parameter.d.ts +1 -1
  32. package/esm/oas/parameter/Parameter.js +5 -2
  33. package/esm/oas/ref/DanglingRefError.d.ts +5 -2
  34. package/esm/oas/ref/DanglingRefError.js +4 -3
  35. package/esm/oas/ref/Ref.d.ts +23 -12
  36. package/esm/oas/ref/Ref.js +68 -72
  37. package/esm/oas/schemaPath/traverseSchema.js +11 -5
  38. package/esm/parse/missingSchema.d.ts +30 -0
  39. package/esm/parse/missingSchema.js +33 -0
  40. package/esm/parse/v3-0/header/toHeadersV3.js +5 -0
  41. package/esm/parse/v3-0/parameter/toParameterV3.js +11 -0
  42. package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  43. package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
  44. package/esm/parse/v3-1/header/toHeadersV3.js +5 -0
  45. package/esm/parse/v3-1/parameter/toParameterV3.js +11 -0
  46. package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  47. package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
  48. package/esm/parse/v3-2/header/toHeadersV3.js +5 -0
  49. package/esm/parse/v3-2/parameter/toParameterV3.js +11 -0
  50. package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  51. package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
  52. package/esm/types/GeneratorType.d.ts +1 -1
  53. package/esm/types/ProjectionOptions.d.ts +1 -1
  54. package/esm/types/ProjectionOptions.js +1 -1
  55. package/esm/types/RefName.d.ts +3 -3
  56. package/esm/types/TypeSystem.d.ts +3 -3
  57. package/package.json +1 -1
  58. package/script/anchors/attribute.js +3 -2
  59. package/script/context/CoreContext.d.ts +1 -1
  60. package/script/context/CoreContext.js +1 -1
  61. package/script/context/GenerateContext.d.ts +13 -10
  62. package/script/context/GenerateContext.js +36 -25
  63. package/script/context/ParseContext.js +135 -33
  64. package/script/context/generateTypes.d.ts +7 -6
  65. package/script/context/generateTypes.js +2 -0
  66. package/script/dsl/GeneratorKeys.d.ts +21 -15
  67. package/script/dsl/GeneratorKeys.js +16 -11
  68. package/script/dsl/Inserted.d.ts +1 -1
  69. package/script/dsl/Inserted.js +1 -1
  70. package/script/dsl/model/ModelDriver.d.ts +6 -5
  71. package/script/dsl/model/ModelDriver.js +22 -20
  72. package/script/dsl/model/toModelEntry.d.ts +18 -18
  73. package/script/dsl/model/toModelEntry.js +9 -9
  74. package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
  75. package/script/dsl/model/toModelProjectionBase.js +12 -8
  76. package/script/dsl/model/types.d.ts +26 -17
  77. package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  78. package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  79. package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  80. package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  81. package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  82. package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
  83. package/script/helpers/refFns.d.ts +108 -43
  84. package/script/helpers/refFns.js +180 -59
  85. package/script/oas/document/Document.d.ts +6 -0
  86. package/script/oas/document/Document.js +44 -2
  87. package/script/oas/header/Header.js +4 -1
  88. package/script/oas/parameter/Parameter.d.ts +1 -1
  89. package/script/oas/parameter/Parameter.js +5 -2
  90. package/script/oas/ref/DanglingRefError.d.ts +5 -2
  91. package/script/oas/ref/DanglingRefError.js +4 -3
  92. package/script/oas/ref/Ref.d.ts +23 -12
  93. package/script/oas/ref/Ref.js +67 -71
  94. package/script/oas/schemaPath/traverseSchema.js +10 -4
  95. package/script/parse/missingSchema.d.ts +30 -0
  96. package/script/parse/missingSchema.js +38 -0
  97. package/script/parse/v3-0/header/toHeadersV3.js +5 -0
  98. package/script/parse/v3-0/parameter/toParameterV3.js +11 -0
  99. package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  100. package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
  101. package/script/parse/v3-1/header/toHeadersV3.js +5 -0
  102. package/script/parse/v3-1/parameter/toParameterV3.js +11 -0
  103. package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  104. package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
  105. package/script/parse/v3-2/header/toHeadersV3.js +5 -0
  106. package/script/parse/v3-2/parameter/toParameterV3.js +11 -0
  107. package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  108. package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
  109. package/script/types/GeneratorType.d.ts +1 -1
  110. package/script/types/ProjectionOptions.d.ts +1 -1
  111. package/script/types/ProjectionOptions.js +1 -1
  112. package/script/types/RefName.d.ts +3 -3
  113. 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 { RefName } from '../../types/RefName.js';
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
- refName: RefName;
24
+ /** The model's ref (see {@link RefParts}); an `OasRef` fits it. */
25
+ ref: RefParts;
25
26
  } & ProjectionOptionsArg<ProjectionOptions>;
26
27
  type ToEnrichmentsArgs = {
27
- refName: RefName;
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: (refName: RefName, context: GenerateContextType) => IdType;
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
- refName: RefName;
81
- context: GenerateContextType;
82
- }) => boolean;
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
- refName: RefName;
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>, refName: RefName, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions>, PeerProjectionOptions>): Inserted<V, PeerEnrichmentType>;
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: (refName: RefName, context: GenerateContextType) => IdType;
133
+ toIdentifierType: (ref: RefParts, context: GenerateContextType) => IdType;
130
134
  toExportPath: (args: ToModelExportPathArgs<EnrichmentType, ProjectionOptions>) => string;
131
- toEnrichments: ({ refName, context, variant }: ToEnrichmentsArgs) => EnrichmentType;
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 {};
@@ -1,6 +1,7 @@
1
1
  import { readProjectionOptions } from '../../types/ProjectionOptions.js';
2
2
  import { toPeerInsertOptions } from '../../types/InsertOptions.js';
3
3
  import { toModelGeneratorKey } from '../GeneratorKeys.js';
4
+ import { toModelKey } from '../../helpers/refFns.js';
4
5
  import { DEFAULT_VARIANT } from '../../types/Variant.js';
5
6
  import { parseEnrichmentUmbrella } from '../../enrichments/parseEnrichmentUmbrella.js';
6
7
  /**
@@ -30,7 +31,7 @@ export const toModelProjectionBase = (base, config) => {
30
31
  context: args.context,
31
32
  generatorKey: toModelGeneratorKey({
32
33
  generatorId: config.id,
33
- refName: args.refName,
34
+ ref: args.ref,
34
35
  variant: args.settings.variant ?? DEFAULT_VARIANT
35
36
  })
36
37
  });
@@ -40,7 +41,8 @@ export const toModelProjectionBase = (base, config) => {
40
41
  writable: true,
41
42
  value: void 0
42
43
  });
43
- Object.defineProperty(this, "refName", {
44
+ /** The ref this model is built for (see {@link RefParts}). */
45
+ Object.defineProperty(this, "ref", {
44
46
  enumerable: true,
45
47
  configurable: true,
46
48
  writable: true,
@@ -53,7 +55,7 @@ export const toModelProjectionBase = (base, config) => {
53
55
  writable: true,
54
56
  value: void 0
55
57
  });
56
- this.refName = args.refName;
58
+ this.ref = args.ref;
57
59
  this.settings = args.settings;
58
60
  this.options = readProjectionOptions(args);
59
61
  }
@@ -63,8 +65,8 @@ export const toModelProjectionBase = (base, config) => {
63
65
  * unless `noExport` is set. `{ options }` is required when the peer
64
66
  * declares options and refused when it does not.
65
67
  */
66
- insertModel(projection, refName, ...rest) {
67
- return this.context.insertModel(projection, refName, {
68
+ insertModel(projection, ref, ...rest) {
69
+ return this.context.insertModel(projection, ref, {
68
70
  ...toPeerInsertOptions(rest),
69
71
  destinationPath: this.settings.exportPath
70
72
  });
@@ -115,10 +117,12 @@ export const toModelProjectionBase = (base, config) => {
115
117
  enumerable: true,
116
118
  configurable: true,
117
119
  writable: true,
118
- value: ({ refName, context, variant }) => {
120
+ value: ({ ref, context, variant }) => {
119
121
  // The three enrichment scopes assembled into the umbrella a generator
120
122
  // reads off `this.settings.enrichments`. Subject is per-item
121
- // (`[id][refName][variant]`) — the variant axis is core-owned, and the
123
+ // (`[id][refName][variant]`, or the whole pointer in place of
124
+ // `refName` for a ref that does not point at a component, `toModelKey`)
125
+ // — the variant axis is core-owned, and the
122
126
  // engine has already asserted `'main'` exists; generator and stack are
123
127
  // run-constants (`[id][_generator]`, `[_stack]`). The required composite
124
128
  // schema parses the raw umbrella once — typed, cast-free.
@@ -127,7 +131,7 @@ export const toModelProjectionBase = (base, config) => {
127
131
  return parseEnrichmentUmbrella({
128
132
  context,
129
133
  generatorId: config.id,
130
- subjectSegments: [refName, variant],
134
+ subjectSegments: [toModelKey(ref), variant],
131
135
  schema: config.toEnrichmentSchema()
132
136
  });
133
137
  }
@@ -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 { RefName } from '../../types/RefName.js';
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
- refName: RefName;
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?: RefName;
23
+ rootRef?: RefParts;
23
24
  } & ProjectionOptionsArg<ProjectionOptions>;
24
25
  export type WithTransformModel = {
25
- transformModel: (refName: RefName) => void;
26
+ transformModel: (ref: RefParts) => void;
26
27
  };
27
28
  export type ToModelEnrichmentsArgs = {
28
- refName: RefName;
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
- refName: RefName;
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 (or just `'main'`
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(refName)`)
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
- refName: RefName;
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
- refName: RefName;
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
- refName: RefName;
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
- refName: RefName;
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
- refName: RefName;
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, refName, settings, destinationPath, rootRef, options }: ModelProjectionConstructorArgs<EnrichmentType, ProjectionOptions>): V;
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(refName, context) })`.
123
+ * ...toIdentifierType(ref, context) })`.
115
124
  */
116
- toIdentifierType: (refName: RefName, context: GenerateContextType) => IdentifierType;
125
+ toIdentifierType: (ref: RefParts, context: GenerateContextType) => IdentifierType;
117
126
  toExportPath: (args: ToModelExportPathArgs<EnrichmentType, ProjectionOptions>) => string;
118
- toEnrichments: ({ refName, context, variant }: ToModelEnrichmentsArgs) => EnrichmentType;
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 { RefName } from '../../../types/RefName.js';
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>, refName: RefName, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions_1>, PeerProjectionOptions_1>): Inserted<V, PeerEnrichmentType_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.
@@ -83,8 +83,8 @@ export const toGqlOperationProjectionBase = (base, config) => {
83
83
  * `{ options }` is required when the peer declares options and refused
84
84
  * when it does not.
85
85
  */
86
- insertModel(projection, refName, ...rest) {
87
- return this.context.insertModel(projection, refName, {
86
+ insertModel(projection, ref, ...rest) {
87
+ return this.context.insertModel(projection, ref, {
88
88
  ...toPeerInsertOptions(rest),
89
89
  destinationPath: this.settings.exportPath
90
90
  });
@@ -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 { RefName } from '../../../types/RefName.js';
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>, refName: RefName, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions_1>, PeerProjectionOptions_1>): Inserted<V, PeerEnrichmentType_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
@@ -100,8 +100,8 @@ export const toOasOperationProjectionBase = (base, config) => {
100
100
  * `{ options }` is required when the peer declares options and refused
101
101
  * when it does not.
102
102
  */
103
- insertModel(projection, refName, ...rest) {
104
- return this.context.insertModel(projection, refName, {
103
+ insertModel(projection, ref, ...rest) {
104
+ return this.context.insertModel(projection, ref, {
105
105
  ...toPeerInsertOptions(rest),
106
106
  destinationPath: this.settings.exportPath
107
107
  });
@@ -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 { RefName } from '../../types/RefName.js';
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>, refName: RefName, ...rest: ProjectionOptionsRest<PeerInsertOptions<PeerProjectionOptions_1>, PeerProjectionOptions_1>): Inserted<V, PeerEnrichmentType_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
@@ -70,8 +70,8 @@ export const toWebhookProjectionBase = (base, config) => {
70
70
  * webhook's payload type). `{ options }` is required when the peer
71
71
  * declares options and refused when it does not.
72
72
  */
73
- insertModel(projection, refName, ...rest) {
74
- return this.context.insertModel(projection, refName, {
73
+ insertModel(projection, ref, ...rest) {
74
+ return this.context.insertModel(projection, ref, {
75
75
  ...toPeerInsertOptions(rest),
76
76
  destinationPath: this.settings.exportPath
77
77
  });
@@ -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
- * Extracts a reference name from an OpenAPI $ref string.
8
- *
9
- * This function parses JSON Pointer references (like '#/components/schemas/User')
10
- * and extracts the final component as a branded RefName type. It's used throughout
11
- * the SKMTC system to convert string references into type-safe reference names.
12
- *
13
- * A `$ref` is a URI fragment that holds a JSON pointer (RFC 6901), so the name
14
- * is unescaped as one: `%20` is a space, and `~1` and `~0` are `/` and `~`.
15
- * `#/components/schemas/Foo%20Bar` names the component `Foo Bar`.
16
- *
17
- * @param $ref - The OpenAPI reference string (e.g., '#/components/schemas/User')
18
- * @returns The extracted reference name as a branded RefName type
19
- *
20
- * @throws {Error} When the reference string is invalid or empty
21
- *
22
- * @example Basic usage
23
- * ```typescript
24
- * import { toRefName } from '@skmtc/core/helpers';
25
- *
26
- * const refName = toRefName('#/components/schemas/User');
27
- * console.log(refName); // 'User' (typed as RefName)
28
- *
29
- * const responseRef = toRefName('#/components/responses/ErrorResponse');
30
- * console.log(responseRef); // 'ErrorResponse' (typed as RefName)
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
- * @example Error cases
34
- * ```typescript
35
- * // These will throw errors:
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
- * @example Integration with OAS processing
41
- * ```typescript
42
- * class SchemaProcessor {
43
- * processReference(ref: string) {
44
- * const refName = toRefName(ref);
45
- * const schema = this.document.components.schemas[refName];
46
- * return this.processSchema(schema, refName);
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 toRefName: ($ref: string) => RefName;
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 = toRefName(schemaOrRef.$ref);
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');