@skmtc/core 0.47.3 → 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/ParseContext.js +5 -4
- 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/ParseContext.js +5 -4
- 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,6 +1,7 @@
|
|
|
1
1
|
import type { ModelProjection } from './types.js';
|
|
2
2
|
import type { GenerateContextType, InsertModelOptions } from '../../context/generateTypes.js';
|
|
3
3
|
import type { ContentSettings } from '../ContentSettings.js';
|
|
4
|
+
import type { WorkspacePath } from '../../helpers/normalizeWorkspacePath.js';
|
|
4
5
|
import type { GeneratedDefinition } from '../GeneratedValue.js';
|
|
5
6
|
import type { GeneratedValue } from '../GeneratedValue.js';
|
|
6
7
|
import { type RefParts } from '../../helpers/refFns.js';
|
|
@@ -44,13 +45,10 @@ export declare class ModelDriver<V extends GeneratedValue, EnrichmentType, Proje
|
|
|
44
45
|
constructor(args: CreateModelArgs<V, EnrichmentType, ProjectionOptions>, settings?: ContentSettings<EnrichmentType>);
|
|
45
46
|
private apply;
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* cache-hit path). Returns the normalized path.
|
|
48
|
+
* The code File at `path`, created on first use through the projection's
|
|
49
|
+
* language — the static read off the projection class at the use site,
|
|
50
|
+
* never persisted (works pre-construction on the cache-hit path).
|
|
51
51
|
*/
|
|
52
|
-
private ensureFile;
|
|
53
|
-
/** The code File at `path`, created through the projection's language on first use. */
|
|
54
52
|
private ensureCodeFile;
|
|
55
53
|
private getDefinition;
|
|
56
54
|
private affirmDefinition;
|
|
@@ -68,7 +66,7 @@ type IsReferencedBackArgs = {
|
|
|
68
66
|
identifier: {
|
|
69
67
|
name: string;
|
|
70
68
|
};
|
|
71
|
-
exportPath:
|
|
69
|
+
exportPath: WorkspacePath;
|
|
72
70
|
};
|
|
73
71
|
};
|
|
74
72
|
/**
|
|
@@ -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
|
*/
|