@skmtc/core 0.47.4 → 0.48.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/context/GenerateContext.d.ts +14 -3
- package/esm/context/GenerateContext.js +39 -33
- package/esm/context/RenderContext.d.ts +3 -2
- package/esm/context/RenderContext.js +6 -5
- package/esm/context/generateTypes.d.ts +6 -2
- package/esm/dsl/ContentSettings.d.ts +17 -12
- package/esm/dsl/ContentSettings.js +13 -9
- package/esm/dsl/Inserted.d.ts +4 -3
- package/esm/dsl/Inserted.js +2 -2
- package/esm/dsl/PendingDefinition.d.ts +3 -2
- package/esm/dsl/driverFiles.d.ts +46 -0
- package/esm/dsl/driverFiles.js +31 -0
- package/esm/dsl/model/ModelDriver.d.ts +5 -7
- package/esm/dsl/model/ModelDriver.js +12 -29
- package/esm/dsl/operation/gql/GqlOperationDriver.d.ts +1 -1
- package/esm/dsl/operation/gql/GqlOperationDriver.js +15 -12
- package/esm/dsl/operation/oas/OasOperationDriver.d.ts +1 -1
- package/esm/dsl/operation/oas/OasOperationDriver.js +11 -14
- package/esm/dsl/webhook/WebhookDriver.d.ts +1 -1
- package/esm/dsl/webhook/WebhookDriver.js +15 -12
- package/esm/helpers/getByWorkspacePath.d.ts +9 -0
- package/esm/helpers/getByWorkspacePath.js +10 -0
- package/esm/helpers/normalizeWorkspacePath.d.ts +25 -2
- package/esm/helpers/normalizeWorkspacePath.js +16 -1
- package/package.json +1 -1
- package/script/context/GenerateContext.d.ts +14 -3
- package/script/context/GenerateContext.js +37 -31
- package/script/context/RenderContext.d.ts +3 -2
- package/script/context/RenderContext.js +6 -5
- package/script/context/generateTypes.d.ts +6 -2
- package/script/dsl/ContentSettings.d.ts +17 -12
- package/script/dsl/ContentSettings.js +13 -9
- package/script/dsl/Inserted.d.ts +4 -3
- package/script/dsl/Inserted.js +2 -2
- package/script/dsl/PendingDefinition.d.ts +3 -2
- package/script/dsl/driverFiles.d.ts +46 -0
- package/script/dsl/driverFiles.js +38 -0
- package/script/dsl/model/ModelDriver.d.ts +5 -7
- package/script/dsl/model/ModelDriver.js +12 -29
- package/script/dsl/operation/gql/GqlOperationDriver.d.ts +1 -1
- package/script/dsl/operation/gql/GqlOperationDriver.js +15 -12
- package/script/dsl/operation/oas/OasOperationDriver.d.ts +1 -1
- package/script/dsl/operation/oas/OasOperationDriver.js +11 -14
- package/script/dsl/webhook/WebhookDriver.d.ts +1 -1
- package/script/dsl/webhook/WebhookDriver.js +15 -12
- package/script/helpers/getByWorkspacePath.d.ts +9 -0
- package/script/helpers/getByWorkspacePath.js +14 -0
- package/script/helpers/normalizeWorkspacePath.d.ts +25 -2
- package/script/helpers/normalizeWorkspacePath.js +18 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ensureFile, findDefinitionAt, toImportDestination, toImportFile } from '../driverFiles.js';
|
|
2
2
|
import { toModelGeneratorKey } from '../GeneratorKeys.js';
|
|
3
3
|
import { toModelKey } from '../../helpers/refFns.js';
|
|
4
4
|
import { DEFAULT_VARIANT } from '../../types/Variant.js';
|
|
@@ -107,17 +107,12 @@ export class ModelDriver {
|
|
|
107
107
|
return definition;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* cache-hit path). Returns the normalized path.
|
|
110
|
+
* The code File at `path`, created on first use through the projection's
|
|
111
|
+
* language — the static read off the projection class at the use site,
|
|
112
|
+
* never persisted (works pre-construction on the cache-hit path).
|
|
114
113
|
*/
|
|
115
|
-
ensureFile(path) {
|
|
116
|
-
return ensureFile({ context: this.context, lang: this.projection.lang, path });
|
|
117
|
-
}
|
|
118
|
-
/** The code File at `path`, created through the projection's language on first use. */
|
|
119
114
|
ensureCodeFile(path) {
|
|
120
|
-
const file = this.context
|
|
115
|
+
const file = ensureFile({ context: this.context, lang: this.projection.lang, path });
|
|
121
116
|
if (!(file instanceof CodeFileBase)) {
|
|
122
117
|
throw new Error(`File at '${path}' is not a code file: a model Definition cannot go there.`);
|
|
123
118
|
}
|
|
@@ -141,7 +136,7 @@ export class ModelDriver {
|
|
|
141
136
|
});
|
|
142
137
|
throw new Error(`'${identifier.name}' in file '${exportPath}' is being constructed further up the stack. A reference back to it goes through toModelRef, which returns it suspended; a second projection would never finish.`);
|
|
143
138
|
}
|
|
144
|
-
const found = this.context
|
|
139
|
+
const found = findDefinitionAt({ context: this.context, name: identifier.name, exportPath });
|
|
145
140
|
if (found !== undefined) {
|
|
146
141
|
if (this.affirmDefinition(found, exportPath)) {
|
|
147
142
|
return found;
|
|
@@ -153,7 +148,7 @@ export class ModelDriver {
|
|
|
153
148
|
// there, not a cache miss.
|
|
154
149
|
const marker = new PendingDefinition({
|
|
155
150
|
identifier,
|
|
156
|
-
exportPath
|
|
151
|
+
exportPath,
|
|
157
152
|
generatorKey,
|
|
158
153
|
options: this.options,
|
|
159
154
|
projection: this.projection
|
|
@@ -175,7 +170,7 @@ export class ModelDriver {
|
|
|
175
170
|
definition.reaches = marker.reaches;
|
|
176
171
|
// Added once the constructor returned, so the Definition renders after
|
|
177
172
|
// the models it refers to, and a constructor that throws adds no file.
|
|
178
|
-
const taken = this.context
|
|
173
|
+
const taken = findDefinitionAt({ context: this.context, name: identifier.name, exportPath });
|
|
179
174
|
if (taken !== undefined) {
|
|
180
175
|
assertSameKey({
|
|
181
176
|
name: identifier.name,
|
|
@@ -244,10 +239,7 @@ const whilePending = ({ context, marker }, construct) => {
|
|
|
244
239
|
* pending stack holds exactly the models whose constructors are running, so
|
|
245
240
|
* the search is as long as the chain of models being built.
|
|
246
241
|
*/
|
|
247
|
-
const findPending = ({ context, name, exportPath }) =>
|
|
248
|
-
const path = normalizeWorkspacePath(exportPath);
|
|
249
|
-
return context.pendingStack.find(pending => pending.identifier.name === name && pending.exportPath === path);
|
|
250
|
-
};
|
|
242
|
+
const findPending = ({ context, name, exportPath }) => context.pendingStack.find(pending => pending.identifier.name === name && pending.exportPath === exportPath);
|
|
251
243
|
/** A model under construction is this model only with the same key, projection class and options. */
|
|
252
244
|
const assertSamePending = ({ pending, name, exportPath, generatorKey, options, projection }) => {
|
|
253
245
|
assertSameKey({ name, exportPath, cachedKey: pending.generatorKey, generatorKey });
|
|
@@ -256,14 +248,6 @@ const assertSamePending = ({ pending, name, exportPath, generatorKey, options, p
|
|
|
256
248
|
}
|
|
257
249
|
assertSameOptions({ name, exportPath, cachedOptions: pending.options, options });
|
|
258
250
|
};
|
|
259
|
-
/** Ensure the file at `path` exists, creating it through `lang` on first write. Returns the normalized path. */
|
|
260
|
-
const ensureFile = ({ context, lang, path }) => {
|
|
261
|
-
const normalizedPath = normalizeWorkspacePath(path);
|
|
262
|
-
if (!context.getFile(normalizedPath)) {
|
|
263
|
-
context.addFile(lang.createFile({ path: normalizedPath, settings: context.settings }));
|
|
264
|
-
}
|
|
265
|
-
return normalizedPath;
|
|
266
|
-
};
|
|
267
251
|
/**
|
|
268
252
|
* Import a model's identifier from its export path into `destinationPath`,
|
|
269
253
|
* unless the two are one file. The language builds the import object
|
|
@@ -271,14 +255,13 @@ const ensureFile = ({ context, lang, path }) => {
|
|
|
271
255
|
* stores it via the pure-data `context.register`.
|
|
272
256
|
*/
|
|
273
257
|
const stitchModelImport = ({ context, lang, identifier, exportPath, destinationPath }) => {
|
|
274
|
-
|
|
275
|
-
|
|
258
|
+
const importInto = toImportDestination({ context, exportPath, destinationPath });
|
|
259
|
+
if (importInto === undefined) {
|
|
276
260
|
return;
|
|
277
261
|
}
|
|
278
|
-
ensureFile({ context, lang, path: destinationPath });
|
|
279
262
|
context.register({
|
|
280
263
|
imports: [lang.toImport({ identifier, module: exportPath })],
|
|
281
|
-
destinationPath
|
|
264
|
+
destinationPath: toImportFile({ context, lang, destination: importInto }).path
|
|
282
265
|
});
|
|
283
266
|
};
|
|
284
267
|
/** The models `definition`'s construction reached that are still pending. */
|
|
@@ -38,7 +38,7 @@ export declare class GqlOperationDriver<V extends GeneratedValue, EnrichmentType
|
|
|
38
38
|
* Ensure the file at `path` exists, creating it on first write through
|
|
39
39
|
* the projection's language — the static read off the projection class
|
|
40
40
|
* at the use site, never persisted (works pre-construction on the
|
|
41
|
-
* cache-hit path). Returns the
|
|
41
|
+
* cache-hit path). Returns the file.
|
|
42
42
|
*/
|
|
43
43
|
private ensureFile;
|
|
44
44
|
private getDefinition;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ensureFile, findDefinitionAt, toImportDestination, toImportFile } from '../../driverFiles.js';
|
|
2
2
|
import { toGqlOperationGeneratorKey } from '../../GeneratorKeys.js';
|
|
3
3
|
import { DEFAULT_VARIANT } from '../../../types/Variant.js';
|
|
4
4
|
import { readProjectionOptions, toValueOptions } from '../../../types/ProjectionOptions.js';
|
|
@@ -95,18 +95,21 @@ export class GqlOperationDriver {
|
|
|
95
95
|
apply({ destinationPath } = {}) {
|
|
96
96
|
const { identifier, exportPath } = this.settings;
|
|
97
97
|
const definition = this.getDefinition({ identifier, exportPath });
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const importInto = toImportDestination({ context: this.context, exportPath, destinationPath });
|
|
99
|
+
if (importInto !== undefined) {
|
|
100
100
|
// Cross-file import of the peer's identifier from its export path.
|
|
101
101
|
// The language builds the import object (`toImport`) and creates the
|
|
102
102
|
// destination file on first write (caller-side); the engine stores
|
|
103
103
|
// via the pure-data `context.register`. The import lands in the
|
|
104
104
|
// caller's file (`destinationPath`); `insertOperation` only composes
|
|
105
105
|
// same-language generators, so the peer's `lang` is the caller's.
|
|
106
|
-
this.ensureFile(destinationPath);
|
|
107
106
|
this.context.register({
|
|
108
107
|
imports: [this.projection.lang.toImport({ identifier, module: exportPath })],
|
|
109
|
-
destinationPath
|
|
108
|
+
destinationPath: toImportFile({
|
|
109
|
+
context: this.context,
|
|
110
|
+
lang: this.projection.lang,
|
|
111
|
+
destination: importInto
|
|
112
|
+
}).path
|
|
110
113
|
});
|
|
111
114
|
}
|
|
112
115
|
return definition;
|
|
@@ -115,17 +118,17 @@ export class GqlOperationDriver {
|
|
|
115
118
|
* Ensure the file at `path` exists, creating it on first write through
|
|
116
119
|
* the projection's language — the static read off the projection class
|
|
117
120
|
* at the use site, never persisted (works pre-construction on the
|
|
118
|
-
* cache-hit path). Returns the
|
|
121
|
+
* cache-hit path). Returns the file.
|
|
119
122
|
*/
|
|
120
123
|
ensureFile(path) {
|
|
121
|
-
|
|
122
|
-
if (!this.context.getFile(normalizedPath)) {
|
|
123
|
-
this.context.addFile(this.projection.lang.createFile({ path: normalizedPath, settings: this.context.settings }));
|
|
124
|
-
}
|
|
125
|
-
return normalizedPath;
|
|
124
|
+
return ensureFile({ context: this.context, lang: this.projection.lang, path });
|
|
126
125
|
}
|
|
127
126
|
getDefinition({ identifier, exportPath }) {
|
|
128
|
-
const cachedDefinition =
|
|
127
|
+
const cachedDefinition = findDefinitionAt({
|
|
128
|
+
context: this.context,
|
|
129
|
+
name: identifier.name,
|
|
130
|
+
exportPath
|
|
131
|
+
});
|
|
129
132
|
if (this.affirmDefinition(cachedDefinition, exportPath)) {
|
|
130
133
|
return cachedDefinition;
|
|
131
134
|
}
|
|
@@ -39,7 +39,7 @@ export declare class OasOperationDriver<V extends GeneratedValue, EnrichmentType
|
|
|
39
39
|
* Ensure the file at `path` exists, creating it on first write through
|
|
40
40
|
* the projection's language — the static read off the projection class
|
|
41
41
|
* at the use site, never persisted (works pre-construction on the
|
|
42
|
-
* cache-hit path). Returns the
|
|
42
|
+
* cache-hit path). Returns the file.
|
|
43
43
|
*/
|
|
44
44
|
private ensureFile;
|
|
45
45
|
private getDefinition;
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _OasOperationDriver_into;
|
|
13
|
-
import {
|
|
13
|
+
import { ensureFile, findDefinitionAt, toImportDestination, toImportFile } from '../../driverFiles.js';
|
|
14
14
|
import invariant from 'tiny-invariant';
|
|
15
15
|
import { toOasOperationGeneratorKey } from '../../GeneratorKeys.js';
|
|
16
16
|
import { DEFAULT_VARIANT } from '../../../types/Variant.js';
|
|
@@ -134,10 +134,7 @@ export class OasOperationDriver {
|
|
|
134
134
|
const { identifier, exportPath } = this.settings;
|
|
135
135
|
// The file an import has to be stitched into, or `undefined` when there
|
|
136
136
|
// is none to stitch — no destination, or the projection's own file.
|
|
137
|
-
const importInto = destinationPath
|
|
138
|
-
normalizeWorkspacePath(exportPath) !== normalizeWorkspacePath(destinationPath)
|
|
139
|
-
? destinationPath
|
|
140
|
-
: undefined;
|
|
137
|
+
const importInto = toImportDestination({ context: this.context, exportPath, destinationPath });
|
|
141
138
|
// A member is declared inside its container, so it has no module-level
|
|
142
139
|
// name — an import of it would name a symbol its file never exports, and
|
|
143
140
|
// the `Inserted.toName()` handed back would be unresolvable. What a caller
|
|
@@ -154,10 +151,13 @@ export class OasOperationDriver {
|
|
|
154
151
|
// via the pure-data `context.register`. The import lands in the
|
|
155
152
|
// caller's file (`destinationPath`); `insertOperation` only composes
|
|
156
153
|
// same-language generators, so the peer's `lang` is the caller's.
|
|
157
|
-
this.ensureFile(importInto);
|
|
158
154
|
this.context.register({
|
|
159
155
|
imports: [this.projection.lang.toImport({ identifier, module: exportPath })],
|
|
160
|
-
destinationPath:
|
|
156
|
+
destinationPath: toImportFile({
|
|
157
|
+
context: this.context,
|
|
158
|
+
lang: this.projection.lang,
|
|
159
|
+
destination: importInto
|
|
160
|
+
}).path
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
return definition;
|
|
@@ -166,14 +166,10 @@ export class OasOperationDriver {
|
|
|
166
166
|
* Ensure the file at `path` exists, creating it on first write through
|
|
167
167
|
* the projection's language — the static read off the projection class
|
|
168
168
|
* at the use site, never persisted (works pre-construction on the
|
|
169
|
-
* cache-hit path). Returns the
|
|
169
|
+
* cache-hit path). Returns the file.
|
|
170
170
|
*/
|
|
171
171
|
ensureFile(path) {
|
|
172
|
-
|
|
173
|
-
if (!this.context.getFile(normalizedPath)) {
|
|
174
|
-
this.context.addFile(this.projection.lang.createFile({ path: normalizedPath, settings: this.context.settings }));
|
|
175
|
-
}
|
|
176
|
-
return normalizedPath;
|
|
172
|
+
return ensureFile({ context: this.context, lang: this.projection.lang, path });
|
|
177
173
|
}
|
|
178
174
|
getDefinition({ identifier, exportPath }) {
|
|
179
175
|
// A member's place is its container, resolved (and created, on the first
|
|
@@ -185,7 +181,8 @@ export class OasOperationDriver {
|
|
|
185
181
|
const into = __classPrivateFieldGet(this, _OasOperationDriver_into, "f");
|
|
186
182
|
// Spread rather than always-pass: a non-member's call shape is exactly
|
|
187
183
|
// what it was, so nothing downstream sees a key it never had.
|
|
188
|
-
const cachedDefinition =
|
|
184
|
+
const cachedDefinition = findDefinitionAt({
|
|
185
|
+
context: this.context,
|
|
189
186
|
name: identifier.name,
|
|
190
187
|
exportPath,
|
|
191
188
|
...(into !== undefined ? { into } : {})
|
|
@@ -36,7 +36,7 @@ export declare class WebhookDriver<V extends GeneratedValue, EnrichmentType = un
|
|
|
36
36
|
private apply;
|
|
37
37
|
/**
|
|
38
38
|
* Ensure the file at `path` exists, creating it on first write through the
|
|
39
|
-
* projection's language. Returns the
|
|
39
|
+
* projection's language. Returns the file.
|
|
40
40
|
*/
|
|
41
41
|
private ensureFile;
|
|
42
42
|
private getDefinition;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ensureFile, findDefinitionAt, toImportDestination, toImportFile } from '../driverFiles.js';
|
|
2
2
|
import { toWebhookGeneratorKey } from '../GeneratorKeys.js';
|
|
3
3
|
import { DEFAULT_VARIANT } from '../../types/Variant.js';
|
|
4
4
|
import { readProjectionOptions, toValueOptions } from '../../types/ProjectionOptions.js';
|
|
@@ -95,30 +95,33 @@ export class WebhookDriver {
|
|
|
95
95
|
apply({ destinationPath } = {}) {
|
|
96
96
|
const { identifier, exportPath } = this.settings;
|
|
97
97
|
const definition = this.getDefinition({ identifier, exportPath });
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const importInto = toImportDestination({ context: this.context, exportPath, destinationPath });
|
|
99
|
+
if (importInto !== undefined) {
|
|
100
100
|
// Cross-file import of the peer's identifier from its export path.
|
|
101
|
-
this.ensureFile(destinationPath);
|
|
102
101
|
this.context.register({
|
|
103
102
|
imports: [this.projection.lang.toImport({ identifier, module: exportPath })],
|
|
104
|
-
destinationPath
|
|
103
|
+
destinationPath: toImportFile({
|
|
104
|
+
context: this.context,
|
|
105
|
+
lang: this.projection.lang,
|
|
106
|
+
destination: importInto
|
|
107
|
+
}).path
|
|
105
108
|
});
|
|
106
109
|
}
|
|
107
110
|
return definition;
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
110
113
|
* Ensure the file at `path` exists, creating it on first write through the
|
|
111
|
-
* projection's language. Returns the
|
|
114
|
+
* projection's language. Returns the file.
|
|
112
115
|
*/
|
|
113
116
|
ensureFile(path) {
|
|
114
|
-
|
|
115
|
-
if (!this.context.getFile(normalizedPath)) {
|
|
116
|
-
this.context.addFile(this.projection.lang.createFile({ path: normalizedPath, settings: this.context.settings }));
|
|
117
|
-
}
|
|
118
|
-
return normalizedPath;
|
|
117
|
+
return ensureFile({ context: this.context, lang: this.projection.lang, path });
|
|
119
118
|
}
|
|
120
119
|
getDefinition({ identifier, exportPath }) {
|
|
121
|
-
const cachedDefinition =
|
|
120
|
+
const cachedDefinition = findDefinitionAt({
|
|
121
|
+
context: this.context,
|
|
122
|
+
name: identifier.name,
|
|
123
|
+
exportPath
|
|
124
|
+
});
|
|
122
125
|
if (this.affirmDefinition(cachedDefinition, exportPath)) {
|
|
123
126
|
return cachedDefinition;
|
|
124
127
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value at `path` in a map keyed by normalized workspace paths, such as
|
|
3
|
+
* the engine's files. A path that is a key is normalized already, so only a
|
|
4
|
+
* path that is no key is normalized, and looked up again.
|
|
5
|
+
*
|
|
6
|
+
* Throws, as {@link normalizeWorkspacePath} does, for a path that is no key
|
|
7
|
+
* and cannot name a file below `basePath`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getByWorkspacePath: <Value>(map: ReadonlyMap<string, Value>, path: string) => Value | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { normalizeWorkspacePath } from './normalizeWorkspacePath.js';
|
|
2
|
+
/**
|
|
3
|
+
* The value at `path` in a map keyed by normalized workspace paths, such as
|
|
4
|
+
* the engine's files. A path that is a key is normalized already, so only a
|
|
5
|
+
* path that is no key is normalized, and looked up again.
|
|
6
|
+
*
|
|
7
|
+
* Throws, as {@link normalizeWorkspacePath} does, for a path that is no key
|
|
8
|
+
* and cannot name a file below `basePath`.
|
|
9
|
+
*/
|
|
10
|
+
export const getByWorkspacePath = (map, path) => map.get(path) ?? map.get(normalizeWorkspacePath(path));
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
import type { Brand } from '../types/Brand.js';
|
|
2
|
+
/**
|
|
3
|
+
* A workspace path in its one spelling. Only this module makes one:
|
|
4
|
+
* {@link normalizeWorkspacePath}, and
|
|
5
|
+
* {@link applyGeneratedSuffixToWorkspacePath} for one with the suffix
|
|
6
|
+
* inserted. The engine keys files by it, so a value of this type finds its
|
|
7
|
+
* file without being normalized again.
|
|
8
|
+
*/
|
|
9
|
+
export type WorkspacePath = Brand<string, 'WorkspacePath'>;
|
|
10
|
+
/**
|
|
11
|
+
* `Path`, unless it is already a {@link WorkspacePath}: normalizing one
|
|
12
|
+
* again is a compile error.
|
|
13
|
+
*/
|
|
14
|
+
export type UncheckedPath<Path extends string> = Path extends WorkspacePath ? never : Path;
|
|
1
15
|
/**
|
|
2
16
|
* Options for {@link normalizeWorkspacePath} and {@link toNormalizedWorkspacePath}.
|
|
3
17
|
*/
|
|
@@ -50,7 +64,9 @@ export declare const toNormalizedWorkspacePath: (path: string, { generatorId }?:
|
|
|
50
64
|
* return one as `@/types/User.ts`, `./types/User.ts`, `/types/User.ts`,
|
|
51
65
|
* `types/User.ts`, or with Windows separators; the engine stores this form
|
|
52
66
|
* and nothing else, so file-map keys, import modules and the ejected lookup
|
|
53
|
-
* always agree. The result is a fixed point
|
|
67
|
+
* always agree. The result is a fixed point, and is typed
|
|
68
|
+
* {@link WorkspacePath} so that passing it in again does not compile: a
|
|
69
|
+
* value of that type is already in this form.
|
|
54
70
|
*
|
|
55
71
|
* Throws in the cases {@link toNormalizedWorkspacePath} throws.
|
|
56
72
|
*
|
|
@@ -61,4 +77,11 @@ export declare const toNormalizedWorkspacePath: (path: string, { generatorId }?:
|
|
|
61
77
|
* normalizeWorkspacePath('../User.ts') // throws
|
|
62
78
|
* ```
|
|
63
79
|
*/
|
|
64
|
-
export declare const normalizeWorkspacePath: (path:
|
|
80
|
+
export declare const normalizeWorkspacePath: <Path extends string>(path: UncheckedPath<Path>, options?: NormalizeWorkspacePathOptions) => WorkspacePath;
|
|
81
|
+
/**
|
|
82
|
+
* `path` with the generated-file suffix inserted ({@link applyGeneratedSuffix}),
|
|
83
|
+
* still a {@link WorkspacePath}. A suffix with no separator only lengthens the
|
|
84
|
+
* last segment of a path in its one spelling, so the result is in that
|
|
85
|
+
* spelling too; a suffix with one is normalized with the path.
|
|
86
|
+
*/
|
|
87
|
+
export declare const applyGeneratedSuffixToWorkspacePath: (path: WorkspacePath, suffix: string, options?: NormalizeWorkspacePathOptions) => WorkspacePath;
|
|
@@ -2,6 +2,7 @@ import { normalize } from '../deps/jsr.io/@std/path/1.1.6/posix/normalize.js';
|
|
|
2
2
|
import { isAbsolute as isPosixAbsolute } from '../deps/jsr.io/@std/path/1.1.6/posix/is_absolute.js';
|
|
3
3
|
import { isAbsolute as isWindowsAbsolute } from '../deps/jsr.io/@std/path/1.1.6/windows/is_absolute.js';
|
|
4
4
|
import { toWorkspacePath } from './toWorkspacePath.js';
|
|
5
|
+
import { applyGeneratedSuffix } from './applyGeneratedSuffix.js';
|
|
5
6
|
/**
|
|
6
7
|
* Whether a path contains a `..` parent-reference segment. `..` is a parent
|
|
7
8
|
* reference only as a whole segment — a directory name that merely contains
|
|
@@ -69,7 +70,9 @@ export const toNormalizedWorkspacePath = (path, { generatorId } = {}) => {
|
|
|
69
70
|
* return one as `@/types/User.ts`, `./types/User.ts`, `/types/User.ts`,
|
|
70
71
|
* `types/User.ts`, or with Windows separators; the engine stores this form
|
|
71
72
|
* and nothing else, so file-map keys, import modules and the ejected lookup
|
|
72
|
-
* always agree. The result is a fixed point
|
|
73
|
+
* always agree. The result is a fixed point, and is typed
|
|
74
|
+
* {@link WorkspacePath} so that passing it in again does not compile: a
|
|
75
|
+
* value of that type is already in this form.
|
|
73
76
|
*
|
|
74
77
|
* Throws in the cases {@link toNormalizedWorkspacePath} throws.
|
|
75
78
|
*
|
|
@@ -81,6 +84,18 @@ export const toNormalizedWorkspacePath = (path, { generatorId } = {}) => {
|
|
|
81
84
|
* ```
|
|
82
85
|
*/
|
|
83
86
|
export const normalizeWorkspacePath = (path, options = {}) => `@/${toNormalizedWorkspacePath(path, options)}`;
|
|
87
|
+
/**
|
|
88
|
+
* `path` with the generated-file suffix inserted ({@link applyGeneratedSuffix}),
|
|
89
|
+
* still a {@link WorkspacePath}. A suffix with no separator only lengthens the
|
|
90
|
+
* last segment of a path in its one spelling, so the result is in that
|
|
91
|
+
* spelling too; a suffix with one is normalized with the path.
|
|
92
|
+
*/
|
|
93
|
+
export const applyGeneratedSuffixToWorkspacePath = (path, suffix, options = {}) => {
|
|
94
|
+
const suffixed = applyGeneratedSuffix(path, suffix);
|
|
95
|
+
return /[/\\]/.test(suffix)
|
|
96
|
+
? normalizeWorkspacePath(suffixed, options)
|
|
97
|
+
: suffixed;
|
|
98
|
+
};
|
|
84
99
|
/**
|
|
85
100
|
* Separator swap, then every anchor spelling goes (`@/`, `./`, a leading
|
|
86
101
|
* `/` — {@link toWorkspacePath}), then POSIX normalize of what is left so
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
1
2
|
import type { DefinitionBase } from '../dsl/Definition.js';
|
|
2
3
|
import type { PendingDefinition } from '../dsl/PendingDefinition.js';
|
|
3
4
|
import type { OasSchema } from '../oas/schema/Schema.js';
|
|
@@ -216,10 +217,19 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
216
217
|
* exists. Neutral primitive: returns the abstract `FileBase` and never
|
|
217
218
|
* constructs anything, so a (future) language-owned `register` can ask
|
|
218
219
|
* "does this file exist yet?" without the engine knowing the language.
|
|
219
|
-
* To create
|
|
220
|
-
*
|
|
220
|
+
* To create on a miss, add a file your language constructs with
|
|
221
|
+
* {@link addFile} (`getFile(path) ?? addFile(lang.createFile(…))`).
|
|
222
|
+
*
|
|
223
|
+
* `filePath` may be in any spelling. It is normalized only when it is no
|
|
224
|
+
* key: a key is a normalized path. The file's own `path` is the key.
|
|
221
225
|
*/
|
|
222
226
|
getFile(filePath: string): FileBase | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* The file whose normalized path is `path`, or `undefined`. A normalized
|
|
229
|
+
* path is a key as it is, so a miss is not normalized again, as it is in
|
|
230
|
+
* {@link getFile}: there is no file there in any spelling.
|
|
231
|
+
*/
|
|
232
|
+
getFileByWorkspacePath(path: WorkspacePath): FileBase | undefined;
|
|
223
233
|
/**
|
|
224
234
|
* Read-only view of every file generated so far, keyed by (normalized)
|
|
225
235
|
* export path. An **inspection / tooling** seam — NOT a coordination
|
|
@@ -235,7 +245,8 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
235
245
|
* Store a language-constructed file. The engine never constructs a
|
|
236
246
|
* concrete (language) `File`; the language's `register` builds its own
|
|
237
247
|
* `FileBase` subclass and hands it in here. Throws if a file already
|
|
238
|
-
* exists at the (normalized) path.
|
|
248
|
+
* exists at the (normalized) path. Sets `file.path` to that normalized
|
|
249
|
+
* path, the file's key. Returns the stored file, so
|
|
239
250
|
* get-or-create is a single expression at the call site
|
|
240
251
|
* (`context.getFile(path) ?? context.addFile(new KtFile({ … }))`).
|
|
241
252
|
*/
|
|
@@ -17,6 +17,7 @@ var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_failedI
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.toModelSource = exports.toGqlOperationSource = exports.toWebhookSource = exports.toOasOperationSource = exports.GenerateContext = void 0;
|
|
19
19
|
const normalizeWorkspacePath_js_1 = require("../helpers/normalizeWorkspacePath.js");
|
|
20
|
+
const getByWorkspacePath_js_1 = require("../helpers/getByWorkspacePath.js");
|
|
20
21
|
const applyGeneratedSuffix_js_1 = require("../helpers/applyGeneratedSuffix.js");
|
|
21
22
|
const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
|
|
22
23
|
const refFns_js_1 = require("../helpers/refFns.js");
|
|
@@ -483,11 +484,22 @@ class GenerateContext {
|
|
|
483
484
|
* exists. Neutral primitive: returns the abstract `FileBase` and never
|
|
484
485
|
* constructs anything, so a (future) language-owned `register` can ask
|
|
485
486
|
* "does this file exist yet?" without the engine knowing the language.
|
|
486
|
-
* To create
|
|
487
|
-
*
|
|
487
|
+
* To create on a miss, add a file your language constructs with
|
|
488
|
+
* {@link addFile} (`getFile(path) ?? addFile(lang.createFile(…))`).
|
|
489
|
+
*
|
|
490
|
+
* `filePath` may be in any spelling. It is normalized only when it is no
|
|
491
|
+
* key: a key is a normalized path. The file's own `path` is the key.
|
|
488
492
|
*/
|
|
489
493
|
getFile(filePath) {
|
|
490
|
-
return __classPrivateFieldGet(this, _GenerateContext_files, "f")
|
|
494
|
+
return (0, getByWorkspacePath_js_1.getByWorkspacePath)(__classPrivateFieldGet(this, _GenerateContext_files, "f"), filePath);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* The file whose normalized path is `path`, or `undefined`. A normalized
|
|
498
|
+
* path is a key as it is, so a miss is not normalized again, as it is in
|
|
499
|
+
* {@link getFile}: there is no file there in any spelling.
|
|
500
|
+
*/
|
|
501
|
+
getFileByWorkspacePath(path) {
|
|
502
|
+
return __classPrivateFieldGet(this, _GenerateContext_files, "f").get(path);
|
|
491
503
|
}
|
|
492
504
|
/**
|
|
493
505
|
* Read-only view of every file generated so far, keyed by (normalized)
|
|
@@ -506,7 +518,8 @@ class GenerateContext {
|
|
|
506
518
|
* Store a language-constructed file. The engine never constructs a
|
|
507
519
|
* concrete (language) `File`; the language's `register` builds its own
|
|
508
520
|
* `FileBase` subclass and hands it in here. Throws if a file already
|
|
509
|
-
* exists at the (normalized) path.
|
|
521
|
+
* exists at the (normalized) path. Sets `file.path` to that normalized
|
|
522
|
+
* path, the file's key. Returns the stored file, so
|
|
510
523
|
* get-or-create is a single expression at the call site
|
|
511
524
|
* (`context.getFile(path) ?? context.addFile(new KtFile({ … }))`).
|
|
512
525
|
*/
|
|
@@ -523,6 +536,7 @@ class GenerateContext {
|
|
|
523
536
|
if (existingPath !== undefined) {
|
|
524
537
|
throw new Error(`File '${normalizedPath}' differs from '${existingPath}' only in case. On a file system that ignores case, as macOS's and Windows' do by default, they are one file.`);
|
|
525
538
|
}
|
|
539
|
+
file.path = normalizedPath;
|
|
526
540
|
__classPrivateFieldGet(this, _GenerateContext_files, "f").set(normalizedPath, file);
|
|
527
541
|
__classPrivateFieldGet(this, _GenerateContext_foldedPaths, "f").set(foldedPath, normalizedPath);
|
|
528
542
|
return file;
|
|
@@ -534,12 +548,8 @@ class GenerateContext {
|
|
|
534
548
|
* @param args - Registration arguments with destination path and JSON content
|
|
535
549
|
*/
|
|
536
550
|
registerJson({ destinationPath, json }) {
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
if (!currentFile) {
|
|
540
|
-
currentFile = new JsonFile_js_1.JsonFile({ path: normalizedPath, content: {} });
|
|
541
|
-
this.addFile(currentFile);
|
|
542
|
-
}
|
|
551
|
+
const currentFile = this.getFile(destinationPath) ??
|
|
552
|
+
this.addFile(new JsonFile_js_1.JsonFile({ path: (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath), content: {} }));
|
|
543
553
|
(0, tiny_invariant_1.default)(currentFile instanceof JsonFile_js_1.JsonFile, `File at "${destinationPath}" is not a "JsonFile" type`);
|
|
544
554
|
currentFile.content = json;
|
|
545
555
|
}
|
|
@@ -553,12 +563,8 @@ class GenerateContext {
|
|
|
553
563
|
* @experimental This method is experimental and may change in future versions
|
|
554
564
|
*/
|
|
555
565
|
registerMarkdown({ destinationPath, markdown }) {
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
if (!currentFile) {
|
|
559
|
-
currentFile = new MarkdownFile_js_1.MarkdownFile({ path: normalizedPath, content: '' });
|
|
560
|
-
this.addFile(currentFile);
|
|
561
|
-
}
|
|
566
|
+
const currentFile = this.getFile(destinationPath) ??
|
|
567
|
+
this.addFile(new MarkdownFile_js_1.MarkdownFile({ path: (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath), content: '' }));
|
|
562
568
|
(0, tiny_invariant_1.default)(currentFile instanceof MarkdownFile_js_1.MarkdownFile, `File at "${destinationPath}" is not a "MarkdownFile" type`);
|
|
563
569
|
currentFile.content = markdown;
|
|
564
570
|
}
|
|
@@ -574,14 +580,13 @@ class GenerateContext {
|
|
|
574
580
|
* @mutates this.files
|
|
575
581
|
*/
|
|
576
582
|
register({ imports = [], reExports = [], definitions, custom, destinationPath, into }) {
|
|
577
|
-
const
|
|
578
|
-
const currentFile = this.getFile(normalizedPath);
|
|
583
|
+
const currentFile = this.getFile(destinationPath);
|
|
579
584
|
// `register` never creates files — it speaks pure data and the engine
|
|
580
585
|
// never names a file class. Callers pre-create the destination file
|
|
581
586
|
// through their language (the lang package's register function, the
|
|
582
587
|
// Drivers' ensureFile); reaching a file-miss here is a bug at the
|
|
583
588
|
// caller.
|
|
584
|
-
(0, tiny_invariant_1.default)(currentFile, `Cannot register into '${
|
|
589
|
+
(0, tiny_invariant_1.default)(currentFile, () => `Cannot register into '${(0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath)}' — the file does not exist. ` +
|
|
585
590
|
`Pre-create it through your lang (its register function does this).`);
|
|
586
591
|
// `custom` is language-neutral — it lives on `FileBase`, so any file
|
|
587
592
|
// (code or not, e.g. a JSON/Markdown file) can receive it. Last
|
|
@@ -603,7 +608,7 @@ class GenerateContext {
|
|
|
603
608
|
const placesADefinition = definitions?.some(definition => definition !== undefined) ?? false;
|
|
604
609
|
const place = into === undefined || !placesADefinition
|
|
605
610
|
? currentFile
|
|
606
|
-
: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContainer).call(this, currentFile, into,
|
|
611
|
+
: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContainer).call(this, currentFile, into, currentFile.path);
|
|
607
612
|
definitions?.forEach(definition => {
|
|
608
613
|
if (definition) {
|
|
609
614
|
place.addDefinition(definition);
|
|
@@ -679,17 +684,18 @@ class GenerateContext {
|
|
|
679
684
|
// the use site (same ephemeral read the Drivers make) — pre-creates
|
|
680
685
|
// the destination file caller-side, and stores via the pure-data
|
|
681
686
|
// `register`.
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
687
|
+
const file = this.getFile(destinationPath) ??
|
|
688
|
+
this.addFile(projection.lang.createFile({
|
|
689
|
+
path: (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath),
|
|
690
|
+
settings: this.settings
|
|
691
|
+
}));
|
|
686
692
|
const definition = projection.lang.toDefinition({
|
|
687
693
|
context: this,
|
|
688
694
|
identifier: projection.createIdentifier(fallbackName),
|
|
689
695
|
value,
|
|
690
696
|
noExport: insertOptions.noExport
|
|
691
697
|
});
|
|
692
|
-
this.register({ definitions: [definition], destinationPath:
|
|
698
|
+
this.register({ definitions: [definition], destinationPath: file.path });
|
|
693
699
|
// @TODO Using mapped types would help avoid generics casting
|
|
694
700
|
return definition;
|
|
695
701
|
}
|
|
@@ -766,10 +772,10 @@ class GenerateContext {
|
|
|
766
772
|
}),
|
|
767
773
|
...args.projection.toIdentifierType(args.operation, this)
|
|
768
774
|
}),
|
|
769
|
-
|
|
770
|
-
//
|
|
771
|
-
args.exportPath ??
|
|
772
|
-
args.projection.toExportPath({
|
|
775
|
+
// A member has no file of its own: the Driver passes its container's,
|
|
776
|
+
// which is a finished export path (normalized, suffixed, ejected).
|
|
777
|
+
exportPath: args.exportPath ??
|
|
778
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, args.projection.toExportPath({
|
|
773
779
|
operation: args.operation,
|
|
774
780
|
enrichments,
|
|
775
781
|
variant,
|
|
@@ -1242,14 +1248,14 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1242
1248
|
source
|
|
1243
1249
|
};
|
|
1244
1250
|
}, _GenerateContext_toContentSettingsExportPath = function _GenerateContext_toContentSettingsExportPath(exportPath, generatorId) {
|
|
1245
|
-
const suffixed = (0,
|
|
1251
|
+
const suffixed = (0, normalizeWorkspacePath_js_1.applyGeneratedSuffixToWorkspacePath)((0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(exportPath, { generatorId }), this.settings?.generatedSuffix ?? applyGeneratedSuffix_js_1.DEFAULT_GENERATED_SUFFIX, { generatorId });
|
|
1246
1252
|
return __classPrivateFieldGet(this, _GenerateContext_instances, "a", _GenerateContext_ejectedBySuffixedPath_get).get(suffixed) ?? suffixed;
|
|
1247
1253
|
}, _GenerateContext_ejectedBySuffixedPath_get = function _GenerateContext_ejectedBySuffixedPath_get() {
|
|
1248
1254
|
if (__classPrivateFieldGet(this, _GenerateContext_ejectedBySuffixedPathCache, "f") === undefined) {
|
|
1249
1255
|
const suffix = this.settings?.generatedSuffix ?? applyGeneratedSuffix_js_1.DEFAULT_GENERATED_SUFFIX;
|
|
1250
1256
|
__classPrivateFieldSet(this, _GenerateContext_ejectedBySuffixedPathCache, new Map((this.settings?.ejected ?? []).map(ejectedPath => {
|
|
1251
1257
|
const normalized = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(ejectedPath);
|
|
1252
|
-
return [(0,
|
|
1258
|
+
return [(0, normalizeWorkspacePath_js_1.applyGeneratedSuffixToWorkspacePath)(normalized, suffix), normalized];
|
|
1253
1259
|
})), "f");
|
|
1254
1260
|
}
|
|
1255
1261
|
return __classPrivateFieldGet(this, _GenerateContext_ejectedBySuffixedPathCache, "f");
|
|
@@ -132,8 +132,9 @@ export declare class RenderContext {
|
|
|
132
132
|
/**
|
|
133
133
|
* Retrieves a file from the context by its export path.
|
|
134
134
|
*
|
|
135
|
-
*
|
|
136
|
-
* spelling of the same export path finds the
|
|
135
|
+
* A path that is no key is canonicalized ({@link normalizeWorkspacePath})
|
|
136
|
+
* and looked up again, so any spelling of the same export path finds the
|
|
137
|
+
* same file. Throws when no
|
|
137
138
|
* file exists at that path.
|
|
138
139
|
*
|
|
139
140
|
* @param filePath - The export path to retrieve, in any spelling
|