@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
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.toModelRef = exports.isReferencedBack = exports.ModelDriver = void 0;
|
|
7
|
-
const
|
|
7
|
+
const driverFiles_js_1 = require("../driverFiles.js");
|
|
8
8
|
const GeneratorKeys_js_1 = require("../GeneratorKeys.js");
|
|
9
9
|
const refFns_js_1 = require("../../helpers/refFns.js");
|
|
10
10
|
const Variant_js_1 = require("../../types/Variant.js");
|
|
@@ -113,17 +113,12 @@ class ModelDriver {
|
|
|
113
113
|
return definition;
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* cache-hit path). Returns the normalized path.
|
|
116
|
+
* The code File at `path`, created on first use through the projection's
|
|
117
|
+
* language — the static read off the projection class at the use site,
|
|
118
|
+
* never persisted (works pre-construction on the cache-hit path).
|
|
120
119
|
*/
|
|
121
|
-
ensureFile(path) {
|
|
122
|
-
return ensureFile({ context: this.context, lang: this.projection.lang, path });
|
|
123
|
-
}
|
|
124
|
-
/** The code File at `path`, created through the projection's language on first use. */
|
|
125
120
|
ensureCodeFile(path) {
|
|
126
|
-
const file = this.context
|
|
121
|
+
const file = (0, driverFiles_js_1.ensureFile)({ context: this.context, lang: this.projection.lang, path });
|
|
127
122
|
if (!(file instanceof CodeFileBase_js_1.CodeFileBase)) {
|
|
128
123
|
throw new Error(`File at '${path}' is not a code file: a model Definition cannot go there.`);
|
|
129
124
|
}
|
|
@@ -147,7 +142,7 @@ class ModelDriver {
|
|
|
147
142
|
});
|
|
148
143
|
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.`);
|
|
149
144
|
}
|
|
150
|
-
const found =
|
|
145
|
+
const found = (0, driverFiles_js_1.findDefinitionAt)({ context: this.context, name: identifier.name, exportPath });
|
|
151
146
|
if (found !== undefined) {
|
|
152
147
|
if (this.affirmDefinition(found, exportPath)) {
|
|
153
148
|
return found;
|
|
@@ -159,7 +154,7 @@ class ModelDriver {
|
|
|
159
154
|
// there, not a cache miss.
|
|
160
155
|
const marker = new PendingDefinition_js_1.PendingDefinition({
|
|
161
156
|
identifier,
|
|
162
|
-
exportPath
|
|
157
|
+
exportPath,
|
|
163
158
|
generatorKey,
|
|
164
159
|
options: this.options,
|
|
165
160
|
projection: this.projection
|
|
@@ -181,7 +176,7 @@ class ModelDriver {
|
|
|
181
176
|
definition.reaches = marker.reaches;
|
|
182
177
|
// Added once the constructor returned, so the Definition renders after
|
|
183
178
|
// the models it refers to, and a constructor that throws adds no file.
|
|
184
|
-
const taken =
|
|
179
|
+
const taken = (0, driverFiles_js_1.findDefinitionAt)({ context: this.context, name: identifier.name, exportPath });
|
|
185
180
|
if (taken !== undefined) {
|
|
186
181
|
assertSameKey({
|
|
187
182
|
name: identifier.name,
|
|
@@ -251,10 +246,7 @@ const whilePending = ({ context, marker }, construct) => {
|
|
|
251
246
|
* pending stack holds exactly the models whose constructors are running, so
|
|
252
247
|
* the search is as long as the chain of models being built.
|
|
253
248
|
*/
|
|
254
|
-
const findPending = ({ context, name, exportPath }) =>
|
|
255
|
-
const path = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(exportPath);
|
|
256
|
-
return context.pendingStack.find(pending => pending.identifier.name === name && pending.exportPath === path);
|
|
257
|
-
};
|
|
249
|
+
const findPending = ({ context, name, exportPath }) => context.pendingStack.find(pending => pending.identifier.name === name && pending.exportPath === exportPath);
|
|
258
250
|
/** A model under construction is this model only with the same key, projection class and options. */
|
|
259
251
|
const assertSamePending = ({ pending, name, exportPath, generatorKey, options, projection }) => {
|
|
260
252
|
assertSameKey({ name, exportPath, cachedKey: pending.generatorKey, generatorKey });
|
|
@@ -263,14 +255,6 @@ const assertSamePending = ({ pending, name, exportPath, generatorKey, options, p
|
|
|
263
255
|
}
|
|
264
256
|
assertSameOptions({ name, exportPath, cachedOptions: pending.options, options });
|
|
265
257
|
};
|
|
266
|
-
/** Ensure the file at `path` exists, creating it through `lang` on first write. Returns the normalized path. */
|
|
267
|
-
const ensureFile = ({ context, lang, path }) => {
|
|
268
|
-
const normalizedPath = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(path);
|
|
269
|
-
if (!context.getFile(normalizedPath)) {
|
|
270
|
-
context.addFile(lang.createFile({ path: normalizedPath, settings: context.settings }));
|
|
271
|
-
}
|
|
272
|
-
return normalizedPath;
|
|
273
|
-
};
|
|
274
258
|
/**
|
|
275
259
|
* Import a model's identifier from its export path into `destinationPath`,
|
|
276
260
|
* unless the two are one file. The language builds the import object
|
|
@@ -278,14 +262,13 @@ const ensureFile = ({ context, lang, path }) => {
|
|
|
278
262
|
* stores it via the pure-data `context.register`.
|
|
279
263
|
*/
|
|
280
264
|
const stitchModelImport = ({ context, lang, identifier, exportPath, destinationPath }) => {
|
|
281
|
-
|
|
282
|
-
|
|
265
|
+
const importInto = (0, driverFiles_js_1.toImportDestination)({ context, exportPath, destinationPath });
|
|
266
|
+
if (importInto === undefined) {
|
|
283
267
|
return;
|
|
284
268
|
}
|
|
285
|
-
ensureFile({ context, lang, path: destinationPath });
|
|
286
269
|
context.register({
|
|
287
270
|
imports: [lang.toImport({ identifier, module: exportPath })],
|
|
288
|
-
destinationPath
|
|
271
|
+
destinationPath: (0, driverFiles_js_1.toImportFile)({ context, lang, destination: importInto }).path
|
|
289
272
|
});
|
|
290
273
|
};
|
|
291
274
|
/** 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;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GqlOperationDriver = void 0;
|
|
7
|
-
const
|
|
7
|
+
const driverFiles_js_1 = require("../../driverFiles.js");
|
|
8
8
|
const GeneratorKeys_js_1 = require("../../GeneratorKeys.js");
|
|
9
9
|
const Variant_js_1 = require("../../../types/Variant.js");
|
|
10
10
|
const ProjectionOptions_js_1 = require("../../../types/ProjectionOptions.js");
|
|
@@ -101,18 +101,21 @@ class GqlOperationDriver {
|
|
|
101
101
|
apply({ destinationPath } = {}) {
|
|
102
102
|
const { identifier, exportPath } = this.settings;
|
|
103
103
|
const definition = this.getDefinition({ identifier, exportPath });
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const importInto = (0, driverFiles_js_1.toImportDestination)({ context: this.context, exportPath, destinationPath });
|
|
105
|
+
if (importInto !== undefined) {
|
|
106
106
|
// Cross-file import of the peer's identifier from its export path.
|
|
107
107
|
// The language builds the import object (`toImport`) and creates the
|
|
108
108
|
// destination file on first write (caller-side); the engine stores
|
|
109
109
|
// via the pure-data `context.register`. The import lands in the
|
|
110
110
|
// caller's file (`destinationPath`); `insertOperation` only composes
|
|
111
111
|
// same-language generators, so the peer's `lang` is the caller's.
|
|
112
|
-
this.ensureFile(destinationPath);
|
|
113
112
|
this.context.register({
|
|
114
113
|
imports: [this.projection.lang.toImport({ identifier, module: exportPath })],
|
|
115
|
-
destinationPath
|
|
114
|
+
destinationPath: (0, driverFiles_js_1.toImportFile)({
|
|
115
|
+
context: this.context,
|
|
116
|
+
lang: this.projection.lang,
|
|
117
|
+
destination: importInto
|
|
118
|
+
}).path
|
|
116
119
|
});
|
|
117
120
|
}
|
|
118
121
|
return definition;
|
|
@@ -121,17 +124,17 @@ class GqlOperationDriver {
|
|
|
121
124
|
* Ensure the file at `path` exists, creating it on first write through
|
|
122
125
|
* the projection's language — the static read off the projection class
|
|
123
126
|
* at the use site, never persisted (works pre-construction on the
|
|
124
|
-
* cache-hit path). Returns the
|
|
127
|
+
* cache-hit path). Returns the file.
|
|
125
128
|
*/
|
|
126
129
|
ensureFile(path) {
|
|
127
|
-
|
|
128
|
-
if (!this.context.getFile(normalizedPath)) {
|
|
129
|
-
this.context.addFile(this.projection.lang.createFile({ path: normalizedPath, settings: this.context.settings }));
|
|
130
|
-
}
|
|
131
|
-
return normalizedPath;
|
|
130
|
+
return (0, driverFiles_js_1.ensureFile)({ context: this.context, lang: this.projection.lang, path });
|
|
132
131
|
}
|
|
133
132
|
getDefinition({ identifier, exportPath }) {
|
|
134
|
-
const cachedDefinition =
|
|
133
|
+
const cachedDefinition = (0, driverFiles_js_1.findDefinitionAt)({
|
|
134
|
+
context: this.context,
|
|
135
|
+
name: identifier.name,
|
|
136
|
+
exportPath
|
|
137
|
+
});
|
|
135
138
|
if (this.affirmDefinition(cachedDefinition, exportPath)) {
|
|
136
139
|
return cachedDefinition;
|
|
137
140
|
}
|
|
@@ -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;
|
|
@@ -16,7 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
var _OasOperationDriver_into;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.OasOperationDriver = void 0;
|
|
19
|
-
const
|
|
19
|
+
const driverFiles_js_1 = require("../../driverFiles.js");
|
|
20
20
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
21
21
|
const GeneratorKeys_js_1 = require("../../GeneratorKeys.js");
|
|
22
22
|
const Variant_js_1 = require("../../../types/Variant.js");
|
|
@@ -140,10 +140,7 @@ class OasOperationDriver {
|
|
|
140
140
|
const { identifier, exportPath } = this.settings;
|
|
141
141
|
// The file an import has to be stitched into, or `undefined` when there
|
|
142
142
|
// is none to stitch — no destination, or the projection's own file.
|
|
143
|
-
const importInto = destinationPath
|
|
144
|
-
(0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(exportPath) !== (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath)
|
|
145
|
-
? destinationPath
|
|
146
|
-
: undefined;
|
|
143
|
+
const importInto = (0, driverFiles_js_1.toImportDestination)({ context: this.context, exportPath, destinationPath });
|
|
147
144
|
// A member is declared inside its container, so it has no module-level
|
|
148
145
|
// name — an import of it would name a symbol its file never exports, and
|
|
149
146
|
// the `Inserted.toName()` handed back would be unresolvable. What a caller
|
|
@@ -160,10 +157,13 @@ class OasOperationDriver {
|
|
|
160
157
|
// via the pure-data `context.register`. The import lands in the
|
|
161
158
|
// caller's file (`destinationPath`); `insertOperation` only composes
|
|
162
159
|
// same-language generators, so the peer's `lang` is the caller's.
|
|
163
|
-
this.ensureFile(importInto);
|
|
164
160
|
this.context.register({
|
|
165
161
|
imports: [this.projection.lang.toImport({ identifier, module: exportPath })],
|
|
166
|
-
destinationPath:
|
|
162
|
+
destinationPath: (0, driverFiles_js_1.toImportFile)({
|
|
163
|
+
context: this.context,
|
|
164
|
+
lang: this.projection.lang,
|
|
165
|
+
destination: importInto
|
|
166
|
+
}).path
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
return definition;
|
|
@@ -172,14 +172,10 @@ class OasOperationDriver {
|
|
|
172
172
|
* Ensure the file at `path` exists, creating it on first write through
|
|
173
173
|
* the projection's language — the static read off the projection class
|
|
174
174
|
* at the use site, never persisted (works pre-construction on the
|
|
175
|
-
* cache-hit path). Returns the
|
|
175
|
+
* cache-hit path). Returns the file.
|
|
176
176
|
*/
|
|
177
177
|
ensureFile(path) {
|
|
178
|
-
|
|
179
|
-
if (!this.context.getFile(normalizedPath)) {
|
|
180
|
-
this.context.addFile(this.projection.lang.createFile({ path: normalizedPath, settings: this.context.settings }));
|
|
181
|
-
}
|
|
182
|
-
return normalizedPath;
|
|
178
|
+
return (0, driverFiles_js_1.ensureFile)({ context: this.context, lang: this.projection.lang, path });
|
|
183
179
|
}
|
|
184
180
|
getDefinition({ identifier, exportPath }) {
|
|
185
181
|
// A member's place is its container, resolved (and created, on the first
|
|
@@ -191,7 +187,8 @@ class OasOperationDriver {
|
|
|
191
187
|
const into = __classPrivateFieldGet(this, _OasOperationDriver_into, "f");
|
|
192
188
|
// Spread rather than always-pass: a non-member's call shape is exactly
|
|
193
189
|
// what it was, so nothing downstream sees a key it never had.
|
|
194
|
-
const cachedDefinition =
|
|
190
|
+
const cachedDefinition = (0, driverFiles_js_1.findDefinitionAt)({
|
|
191
|
+
context: this.context,
|
|
195
192
|
name: identifier.name,
|
|
196
193
|
exportPath,
|
|
197
194
|
...(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;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.WebhookDriver = void 0;
|
|
7
|
-
const
|
|
7
|
+
const driverFiles_js_1 = require("../driverFiles.js");
|
|
8
8
|
const GeneratorKeys_js_1 = require("../GeneratorKeys.js");
|
|
9
9
|
const Variant_js_1 = require("../../types/Variant.js");
|
|
10
10
|
const ProjectionOptions_js_1 = require("../../types/ProjectionOptions.js");
|
|
@@ -101,30 +101,33 @@ class WebhookDriver {
|
|
|
101
101
|
apply({ destinationPath } = {}) {
|
|
102
102
|
const { identifier, exportPath } = this.settings;
|
|
103
103
|
const definition = this.getDefinition({ identifier, exportPath });
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const importInto = (0, driverFiles_js_1.toImportDestination)({ context: this.context, exportPath, destinationPath });
|
|
105
|
+
if (importInto !== undefined) {
|
|
106
106
|
// Cross-file import of the peer's identifier from its export path.
|
|
107
|
-
this.ensureFile(destinationPath);
|
|
108
107
|
this.context.register({
|
|
109
108
|
imports: [this.projection.lang.toImport({ identifier, module: exportPath })],
|
|
110
|
-
destinationPath
|
|
109
|
+
destinationPath: (0, driverFiles_js_1.toImportFile)({
|
|
110
|
+
context: this.context,
|
|
111
|
+
lang: this.projection.lang,
|
|
112
|
+
destination: importInto
|
|
113
|
+
}).path
|
|
111
114
|
});
|
|
112
115
|
}
|
|
113
116
|
return definition;
|
|
114
117
|
}
|
|
115
118
|
/**
|
|
116
119
|
* Ensure the file at `path` exists, creating it on first write through the
|
|
117
|
-
* projection's language. Returns the
|
|
120
|
+
* projection's language. Returns the file.
|
|
118
121
|
*/
|
|
119
122
|
ensureFile(path) {
|
|
120
|
-
|
|
121
|
-
if (!this.context.getFile(normalizedPath)) {
|
|
122
|
-
this.context.addFile(this.projection.lang.createFile({ path: normalizedPath, settings: this.context.settings }));
|
|
123
|
-
}
|
|
124
|
-
return normalizedPath;
|
|
123
|
+
return (0, driverFiles_js_1.ensureFile)({ context: this.context, lang: this.projection.lang, path });
|
|
125
124
|
}
|
|
126
125
|
getDefinition({ identifier, exportPath }) {
|
|
127
|
-
const cachedDefinition =
|
|
126
|
+
const cachedDefinition = (0, driverFiles_js_1.findDefinitionAt)({
|
|
127
|
+
context: this.context,
|
|
128
|
+
name: identifier.name,
|
|
129
|
+
exportPath
|
|
130
|
+
});
|
|
128
131
|
if (this.affirmDefinition(cachedDefinition, exportPath)) {
|
|
129
132
|
return cachedDefinition;
|
|
130
133
|
}
|
|
@@ -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,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getByWorkspacePath = void 0;
|
|
4
|
+
const normalizeWorkspacePath_js_1 = require("./normalizeWorkspacePath.js");
|
|
5
|
+
/**
|
|
6
|
+
* The value at `path` in a map keyed by normalized workspace paths, such as
|
|
7
|
+
* the engine's files. A path that is a key is normalized already, so only a
|
|
8
|
+
* path that is no key is normalized, and looked up again.
|
|
9
|
+
*
|
|
10
|
+
* Throws, as {@link normalizeWorkspacePath} does, for a path that is no key
|
|
11
|
+
* and cannot name a file below `basePath`.
|
|
12
|
+
*/
|
|
13
|
+
const getByWorkspacePath = (map, path) => map.get(path) ?? map.get((0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(path));
|
|
14
|
+
exports.getByWorkspacePath = getByWorkspacePath;
|
|
@@ -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;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeWorkspacePath = exports.toNormalizedWorkspacePath = exports.isValidWorkspacePath = exports.hasWorkspaceAnchor = exports.isAbsolutePath = exports.hasParentSegment = void 0;
|
|
3
|
+
exports.applyGeneratedSuffixToWorkspacePath = exports.normalizeWorkspacePath = exports.toNormalizedWorkspacePath = exports.isValidWorkspacePath = exports.hasWorkspaceAnchor = exports.isAbsolutePath = exports.hasParentSegment = void 0;
|
|
4
4
|
const normalize_js_1 = require("../deps/jsr.io/@std/path/1.1.6/posix/normalize.js");
|
|
5
5
|
const is_absolute_js_1 = require("../deps/jsr.io/@std/path/1.1.6/posix/is_absolute.js");
|
|
6
6
|
const is_absolute_js_2 = require("../deps/jsr.io/@std/path/1.1.6/windows/is_absolute.js");
|
|
7
7
|
const toWorkspacePath_js_1 = require("./toWorkspacePath.js");
|
|
8
|
+
const applyGeneratedSuffix_js_1 = require("./applyGeneratedSuffix.js");
|
|
8
9
|
/**
|
|
9
10
|
* Whether a path contains a `..` parent-reference segment. `..` is a parent
|
|
10
11
|
* reference only as a whole segment — a directory name that merely contains
|
|
@@ -77,7 +78,9 @@ exports.toNormalizedWorkspacePath = toNormalizedWorkspacePath;
|
|
|
77
78
|
* return one as `@/types/User.ts`, `./types/User.ts`, `/types/User.ts`,
|
|
78
79
|
* `types/User.ts`, or with Windows separators; the engine stores this form
|
|
79
80
|
* and nothing else, so file-map keys, import modules and the ejected lookup
|
|
80
|
-
* always agree. The result is a fixed point
|
|
81
|
+
* always agree. The result is a fixed point, and is typed
|
|
82
|
+
* {@link WorkspacePath} so that passing it in again does not compile: a
|
|
83
|
+
* value of that type is already in this form.
|
|
81
84
|
*
|
|
82
85
|
* Throws in the cases {@link toNormalizedWorkspacePath} throws.
|
|
83
86
|
*
|
|
@@ -90,6 +93,19 @@ exports.toNormalizedWorkspacePath = toNormalizedWorkspacePath;
|
|
|
90
93
|
*/
|
|
91
94
|
const normalizeWorkspacePath = (path, options = {}) => `@/${(0, exports.toNormalizedWorkspacePath)(path, options)}`;
|
|
92
95
|
exports.normalizeWorkspacePath = normalizeWorkspacePath;
|
|
96
|
+
/**
|
|
97
|
+
* `path` with the generated-file suffix inserted ({@link applyGeneratedSuffix}),
|
|
98
|
+
* still a {@link WorkspacePath}. A suffix with no separator only lengthens the
|
|
99
|
+
* last segment of a path in its one spelling, so the result is in that
|
|
100
|
+
* spelling too; a suffix with one is normalized with the path.
|
|
101
|
+
*/
|
|
102
|
+
const applyGeneratedSuffixToWorkspacePath = (path, suffix, options = {}) => {
|
|
103
|
+
const suffixed = (0, applyGeneratedSuffix_js_1.applyGeneratedSuffix)(path, suffix);
|
|
104
|
+
return /[/\\]/.test(suffix)
|
|
105
|
+
? (0, exports.normalizeWorkspacePath)(suffixed, options)
|
|
106
|
+
: suffixed;
|
|
107
|
+
};
|
|
108
|
+
exports.applyGeneratedSuffixToWorkspacePath = applyGeneratedSuffixToWorkspacePath;
|
|
93
109
|
/**
|
|
94
110
|
* Separator swap, then every anchor spelling goes (`@/`, `./`, a leading
|
|
95
111
|
* `/` — {@link toWorkspacePath}), then POSIX normalize of what is left so
|