@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
|
@@ -17,6 +17,7 @@ var _RenderContext_captureChannel, _RenderContext_capture;
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.RenderContext = void 0;
|
|
19
19
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
20
|
+
const getByWorkspacePath_js_1 = require("../helpers/getByWorkspacePath.js");
|
|
20
21
|
const normalizeWorkspacePath_js_1 = require("../helpers/normalizeWorkspacePath.js");
|
|
21
22
|
const toResolvedArtifactPath_js_1 = require("../helpers/toResolvedArtifactPath.js");
|
|
22
23
|
const CodeFileBase_js_1 = require("../dsl/CodeFileBase.js");
|
|
@@ -250,8 +251,9 @@ class RenderContext {
|
|
|
250
251
|
/**
|
|
251
252
|
* Retrieves a file from the context by its export path.
|
|
252
253
|
*
|
|
253
|
-
*
|
|
254
|
-
* spelling of the same export path finds the
|
|
254
|
+
* A path that is no key is canonicalized ({@link normalizeWorkspacePath})
|
|
255
|
+
* and looked up again, so any spelling of the same export path finds the
|
|
256
|
+
* same file. Throws when no
|
|
255
257
|
* file exists at that path.
|
|
256
258
|
*
|
|
257
259
|
* @param filePath - The export path to retrieve, in any spelling
|
|
@@ -269,9 +271,8 @@ class RenderContext {
|
|
|
269
271
|
* ```
|
|
270
272
|
*/
|
|
271
273
|
getFile(filePath) {
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
(0, tiny_invariant_1.default)(currentFile, `File not found during render phase: ${normalizedPath}`);
|
|
274
|
+
const currentFile = (0, getByWorkspacePath_js_1.getByWorkspacePath)(this.files, filePath);
|
|
275
|
+
(0, tiny_invariant_1.default)(currentFile, () => `File not found during render phase: ${(0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(filePath)}`);
|
|
275
276
|
return currentFile;
|
|
276
277
|
}
|
|
277
278
|
/**
|
|
@@ -20,6 +20,7 @@ import type { ContentSettings } from '../dsl/ContentSettings.js';
|
|
|
20
20
|
import type { RefParts } from '../helpers/refFns.js';
|
|
21
21
|
import type { SchemaToNonRef, TypeSystemOutput } from '../types/TypeSystem.js';
|
|
22
22
|
import type { FileBase } from '../dsl/FileBase.js';
|
|
23
|
+
import type { WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
23
24
|
import type { ImportBase } from '../dsl/ImportBase.js';
|
|
24
25
|
import type { ReExportBase } from '../dsl/ReExportBase.js';
|
|
25
26
|
import type { Stringable } from '../dsl/Stringable.js';
|
|
@@ -374,9 +375,10 @@ export type ToOasOperationSettingsFields<V extends GeneratedValue, EnrichmentTyp
|
|
|
374
375
|
* The Driver passes the container's path when the projection declared a
|
|
375
376
|
* `toContainer`: a member is declared inside its container, so it has no
|
|
376
377
|
* file of its own to compute, and restating one is a way for the two to
|
|
377
|
-
* disagree.
|
|
378
|
+
* disagree. It is the container's `ContentSettings.exportPath`, used as it
|
|
379
|
+
* is: the suffix and `ejected` were applied when that was made.
|
|
378
380
|
*/
|
|
379
|
-
exportPath?:
|
|
381
|
+
exportPath?: WorkspacePath;
|
|
380
382
|
};
|
|
381
383
|
/** {@link ToOasOperationSettingsFields} plus the caller's options. */
|
|
382
384
|
export type ToOasOperationSettingsArgs<V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined> = ToOasOperationSettingsFields<V, EnrichmentType, ProjectionOptions> & ProjectionOptionsArg<NoInfer<ProjectionOptions>>;
|
|
@@ -470,6 +472,8 @@ export type GenerateContextType = {
|
|
|
470
472
|
register: (args: ContextRegisterArgs) => void;
|
|
471
473
|
/** Look up an existing file by path (no creation); the neutral read primitive. */
|
|
472
474
|
getFile: (filePath: string) => FileBase | undefined;
|
|
475
|
+
/** Look up an existing file by its normalized path, which is its key: a miss is not normalized again. */
|
|
476
|
+
getFileByWorkspacePath: (path: WorkspacePath) => FileBase | undefined;
|
|
473
477
|
/** Read-only view of every file generated so far — an inspection/tooling seam (not coordination). */
|
|
474
478
|
inspectedFiles: ReadonlyMap<string, FileBase>;
|
|
475
479
|
/** Store a language-constructed file; the neutral write primitive. Returns the stored file. */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { IdentifierBase } from './IdentifierBase.js';
|
|
2
|
+
import type { WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
2
3
|
/**
|
|
3
4
|
* Arguments for creating empty ContentSettings without enrichments.
|
|
4
5
|
*/
|
|
5
6
|
type EmptyArgs = {
|
|
6
7
|
/** The path where generated content will be exported */
|
|
7
|
-
exportPath:
|
|
8
|
+
exportPath: WorkspacePath;
|
|
8
9
|
/** The identifier for the content being generated */
|
|
9
10
|
identifier: IdentifierBase;
|
|
10
11
|
/**
|
|
@@ -24,7 +25,7 @@ type CreateArgs<EnrichmentType = undefined> = {
|
|
|
24
25
|
/** The identifier for the content being generated */
|
|
25
26
|
identifier: IdentifierBase;
|
|
26
27
|
/** The path where generated content will be exported */
|
|
27
|
-
exportPath:
|
|
28
|
+
exportPath: WorkspacePath;
|
|
28
29
|
/** Custom enrichment data for extending generation */
|
|
29
30
|
enrichments: EnrichmentType;
|
|
30
31
|
/**
|
|
@@ -58,15 +59,15 @@ type CreateArgs<EnrichmentType = undefined> = {
|
|
|
58
59
|
*
|
|
59
60
|
* @example Basic settings without enrichments
|
|
60
61
|
* ```typescript
|
|
61
|
-
* import { ContentSettings } from '@skmtc/core';
|
|
62
|
+
* import { ContentSettings, normalizeWorkspacePath } from '@skmtc/core';
|
|
62
63
|
* import { createType } from '@skmtc/lang-typescript';
|
|
63
64
|
*
|
|
64
65
|
* const settings = ContentSettings.empty({
|
|
65
|
-
* exportPath: './src/generated/models.ts',
|
|
66
|
+
* exportPath: normalizeWorkspacePath('./src/generated/models.ts'),
|
|
66
67
|
* identifier: createType('UserModels')
|
|
67
68
|
* });
|
|
68
69
|
*
|
|
69
|
-
* console.log(settings.exportPath); // '
|
|
70
|
+
* console.log(settings.exportPath); // '@/src/generated/models.ts'
|
|
70
71
|
* console.log(settings.enrichments); // undefined
|
|
71
72
|
* ```
|
|
72
73
|
*
|
|
@@ -80,7 +81,7 @@ type CreateArgs<EnrichmentType = undefined> = {
|
|
|
80
81
|
*
|
|
81
82
|
* const enrichedSettings = new ContentSettings({
|
|
82
83
|
* identifier: createType('ValidatedModels'),
|
|
83
|
-
* exportPath: './src/models/validated.ts',
|
|
84
|
+
* exportPath: normalizeWorkspacePath('./src/models/validated.ts'),
|
|
84
85
|
* enrichments: {
|
|
85
86
|
* validateRequired: true,
|
|
86
87
|
* generateComments: true,
|
|
@@ -102,7 +103,7 @@ type CreateArgs<EnrichmentType = undefined> = {
|
|
|
102
103
|
* ...args,
|
|
103
104
|
* settings: new ContentSettings({
|
|
104
105
|
* identifier: createType(args.refName),
|
|
105
|
-
* exportPath: './src/validated-models.ts',
|
|
106
|
+
* exportPath: normalizeWorkspacePath('./src/validated-models.ts'),
|
|
106
107
|
* enrichments: {
|
|
107
108
|
* validateRequired: true,
|
|
108
109
|
* generateComments: false,
|
|
@@ -132,8 +133,12 @@ type CreateArgs<EnrichmentType = undefined> = {
|
|
|
132
133
|
export declare class ContentSettings<EnrichmentType = undefined> {
|
|
133
134
|
/** The identifier for the content being generated */
|
|
134
135
|
identifier: IdentifierBase;
|
|
135
|
-
/**
|
|
136
|
-
|
|
136
|
+
/**
|
|
137
|
+
* The path where generated content will be exported, normalized
|
|
138
|
+
* ({@link normalizeWorkspacePath}): it finds its file without being
|
|
139
|
+
* normalized again.
|
|
140
|
+
*/
|
|
141
|
+
exportPath: WorkspacePath;
|
|
137
142
|
/** Custom enrichment data for extending generation */
|
|
138
143
|
enrichments: EnrichmentType;
|
|
139
144
|
/**
|
|
@@ -156,7 +161,7 @@ export declare class ContentSettings<EnrichmentType = undefined> {
|
|
|
156
161
|
* ```typescript
|
|
157
162
|
* const settings = new ContentSettings({
|
|
158
163
|
* identifier: createType('ApiModels'),
|
|
159
|
-
* exportPath: './src/api/models.ts',
|
|
164
|
+
* exportPath: normalizeWorkspacePath('./src/api/models.ts'),
|
|
160
165
|
* enrichments: {
|
|
161
166
|
* includeValidation: true,
|
|
162
167
|
* format: 'detailed'
|
|
@@ -182,7 +187,7 @@ export declare class ContentSettings<EnrichmentType = undefined> {
|
|
|
182
187
|
* ```typescript
|
|
183
188
|
* const basicSettings = ContentSettings.empty({
|
|
184
189
|
* identifier: createType('SimpleModels'),
|
|
185
|
-
* exportPath: './src/models.ts'
|
|
190
|
+
* exportPath: normalizeWorkspacePath('./src/models.ts')
|
|
186
191
|
* });
|
|
187
192
|
*
|
|
188
193
|
* console.log(basicSettings.enrichments); // undefined
|
|
@@ -194,7 +199,7 @@ export declare class ContentSettings<EnrichmentType = undefined> {
|
|
|
194
199
|
* ...args,
|
|
195
200
|
* settings: ContentSettings.empty({
|
|
196
201
|
* identifier: createType(args.refName),
|
|
197
|
-
* exportPath: './src/simple-models.ts'
|
|
202
|
+
* exportPath: normalizeWorkspacePath('./src/simple-models.ts')
|
|
198
203
|
* })
|
|
199
204
|
* });
|
|
200
205
|
* }
|
|
@@ -25,15 +25,15 @@ const Variant_js_1 = require("../types/Variant.js");
|
|
|
25
25
|
*
|
|
26
26
|
* @example Basic settings without enrichments
|
|
27
27
|
* ```typescript
|
|
28
|
-
* import { ContentSettings } from '@skmtc/core';
|
|
28
|
+
* import { ContentSettings, normalizeWorkspacePath } from '@skmtc/core';
|
|
29
29
|
* import { createType } from '@skmtc/lang-typescript';
|
|
30
30
|
*
|
|
31
31
|
* const settings = ContentSettings.empty({
|
|
32
|
-
* exportPath: './src/generated/models.ts',
|
|
32
|
+
* exportPath: normalizeWorkspacePath('./src/generated/models.ts'),
|
|
33
33
|
* identifier: createType('UserModels')
|
|
34
34
|
* });
|
|
35
35
|
*
|
|
36
|
-
* console.log(settings.exportPath); // '
|
|
36
|
+
* console.log(settings.exportPath); // '@/src/generated/models.ts'
|
|
37
37
|
* console.log(settings.enrichments); // undefined
|
|
38
38
|
* ```
|
|
39
39
|
*
|
|
@@ -47,7 +47,7 @@ const Variant_js_1 = require("../types/Variant.js");
|
|
|
47
47
|
*
|
|
48
48
|
* const enrichedSettings = new ContentSettings({
|
|
49
49
|
* identifier: createType('ValidatedModels'),
|
|
50
|
-
* exportPath: './src/models/validated.ts',
|
|
50
|
+
* exportPath: normalizeWorkspacePath('./src/models/validated.ts'),
|
|
51
51
|
* enrichments: {
|
|
52
52
|
* validateRequired: true,
|
|
53
53
|
* generateComments: true,
|
|
@@ -69,7 +69,7 @@ const Variant_js_1 = require("../types/Variant.js");
|
|
|
69
69
|
* ...args,
|
|
70
70
|
* settings: new ContentSettings({
|
|
71
71
|
* identifier: createType(args.refName),
|
|
72
|
-
* exportPath: './src/validated-models.ts',
|
|
72
|
+
* exportPath: normalizeWorkspacePath('./src/validated-models.ts'),
|
|
73
73
|
* enrichments: {
|
|
74
74
|
* validateRequired: true,
|
|
75
75
|
* generateComments: false,
|
|
@@ -110,7 +110,7 @@ class ContentSettings {
|
|
|
110
110
|
* ```typescript
|
|
111
111
|
* const settings = new ContentSettings({
|
|
112
112
|
* identifier: createType('ApiModels'),
|
|
113
|
-
* exportPath: './src/api/models.ts',
|
|
113
|
+
* exportPath: normalizeWorkspacePath('./src/api/models.ts'),
|
|
114
114
|
* enrichments: {
|
|
115
115
|
* includeValidation: true,
|
|
116
116
|
* format: 'detailed'
|
|
@@ -127,7 +127,11 @@ class ContentSettings {
|
|
|
127
127
|
writable: true,
|
|
128
128
|
value: void 0
|
|
129
129
|
});
|
|
130
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* The path where generated content will be exported, normalized
|
|
132
|
+
* ({@link normalizeWorkspacePath}): it finds its file without being
|
|
133
|
+
* normalized again.
|
|
134
|
+
*/
|
|
131
135
|
Object.defineProperty(this, "exportPath", {
|
|
132
136
|
enumerable: true,
|
|
133
137
|
configurable: true,
|
|
@@ -174,7 +178,7 @@ class ContentSettings {
|
|
|
174
178
|
* ```typescript
|
|
175
179
|
* const basicSettings = ContentSettings.empty({
|
|
176
180
|
* identifier: createType('SimpleModels'),
|
|
177
|
-
* exportPath: './src/models.ts'
|
|
181
|
+
* exportPath: normalizeWorkspacePath('./src/models.ts')
|
|
178
182
|
* });
|
|
179
183
|
*
|
|
180
184
|
* console.log(basicSettings.enrichments); // undefined
|
|
@@ -186,7 +190,7 @@ class ContentSettings {
|
|
|
186
190
|
* ...args,
|
|
187
191
|
* settings: ContentSettings.empty({
|
|
188
192
|
* identifier: createType(args.refName),
|
|
189
|
-
* exportPath: './src/simple-models.ts'
|
|
193
|
+
* exportPath: normalizeWorkspacePath('./src/simple-models.ts')
|
|
190
194
|
* })
|
|
191
195
|
* });
|
|
192
196
|
* }
|
package/script/dsl/Inserted.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GeneratedDefinition, GeneratedValue } from './GeneratedValue.js';
|
|
2
2
|
import type { ContentSettings } from './ContentSettings.js';
|
|
3
3
|
import type { IdentifierBase } from './IdentifierBase.js';
|
|
4
|
+
import type { WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
4
5
|
/**
|
|
5
6
|
* Constructor arguments for {@link Inserted}.
|
|
6
7
|
*
|
|
@@ -49,7 +50,7 @@ type ConstructorArgs<V extends GeneratedValue, EnrichmentType> = {
|
|
|
49
50
|
*
|
|
50
51
|
* // Access the generated value (guaranteed to be present)
|
|
51
52
|
* const userTypeName = userModel.toValue(); // UserModelValue (not undefined)
|
|
52
|
-
* const exportPath = userModel.toExportPath(); // '
|
|
53
|
+
* const exportPath = userModel.toExportPath(); // '@/src/models.ts'
|
|
53
54
|
* const identifier = userModel.toName(); // 'User'
|
|
54
55
|
*
|
|
55
56
|
* return new Definition({
|
|
@@ -126,13 +127,13 @@ export declare class Inserted<V extends GeneratedValue, EnrichmentType> {
|
|
|
126
127
|
* @example
|
|
127
128
|
* ```typescript
|
|
128
129
|
* const userModel = this.insertModel(generator, 'User');
|
|
129
|
-
* const exportPath = userModel.toExportPath(); // '
|
|
130
|
+
* const exportPath = userModel.toExportPath(); // '@/src/models/User.ts'
|
|
130
131
|
*
|
|
131
132
|
* // Create import statement
|
|
132
133
|
* const importStmt = `import { User } from '${exportPath}';`;
|
|
133
134
|
* ```
|
|
134
135
|
*/
|
|
135
|
-
toExportPath():
|
|
136
|
+
toExportPath(): WorkspacePath;
|
|
136
137
|
/**
|
|
137
138
|
* Gets the generated value from the inserted artifact.
|
|
138
139
|
*
|
package/script/dsl/Inserted.js
CHANGED
|
@@ -37,7 +37,7 @@ exports.Inserted = void 0;
|
|
|
37
37
|
*
|
|
38
38
|
* // Access the generated value (guaranteed to be present)
|
|
39
39
|
* const userTypeName = userModel.toValue(); // UserModelValue (not undefined)
|
|
40
|
-
* const exportPath = userModel.toExportPath(); // '
|
|
40
|
+
* const exportPath = userModel.toExportPath(); // '@/src/models.ts'
|
|
41
41
|
* const identifier = userModel.toName(); // 'User'
|
|
42
42
|
*
|
|
43
43
|
* return new Definition({
|
|
@@ -131,7 +131,7 @@ class Inserted {
|
|
|
131
131
|
* @example
|
|
132
132
|
* ```typescript
|
|
133
133
|
* const userModel = this.insertModel(generator, 'User');
|
|
134
|
-
* const exportPath = userModel.toExportPath(); // '
|
|
134
|
+
* const exportPath = userModel.toExportPath(); // '@/src/models/User.ts'
|
|
135
135
|
*
|
|
136
136
|
* // Create import statement
|
|
137
137
|
* const importStmt = `import { User } from '${exportPath}';`;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { IdentifierBase } from './IdentifierBase.js';
|
|
2
2
|
import type { GeneratorKey } from './GeneratorKeys.js';
|
|
3
|
+
import type { WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
3
4
|
type PendingDefinitionArgs = {
|
|
4
5
|
identifier: IdentifierBase;
|
|
5
|
-
exportPath:
|
|
6
|
+
exportPath: WorkspacePath;
|
|
6
7
|
generatorKey: GeneratorKey;
|
|
7
8
|
options: unknown;
|
|
8
9
|
projection: unknown;
|
|
@@ -24,7 +25,7 @@ type PendingDefinitionArgs = {
|
|
|
24
25
|
export declare class PendingDefinition {
|
|
25
26
|
identifier: IdentifierBase;
|
|
26
27
|
/** The file the Definition will go to, normalized. */
|
|
27
|
-
exportPath:
|
|
28
|
+
exportPath: WorkspacePath;
|
|
28
29
|
/** The key the Definition will carry: the identity check runs on the entry too. */
|
|
29
30
|
generatorKey: GeneratorKey;
|
|
30
31
|
/** The caller's options the projection is constructed with: identity, like the key. */
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FindDefinitionArgs, GenerateContextType } from '../context/generateTypes.js';
|
|
2
|
+
import type { DefinitionBase } from './Definition.js';
|
|
3
|
+
import type { FileBase } from './FileBase.js';
|
|
4
|
+
import type { Lang } from './Lang.js';
|
|
5
|
+
import { type WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
6
|
+
/** The file an import goes into: the file when it exists, its normalized path when it does not yet. */
|
|
7
|
+
export type ImportDestination = FileBase | WorkspacePath;
|
|
8
|
+
type ToImportDestinationArgs = {
|
|
9
|
+
context: GenerateContextType;
|
|
10
|
+
/** The file the imported symbol is declared in. */
|
|
11
|
+
exportPath: WorkspacePath;
|
|
12
|
+
/** The file that uses the symbol, as a generator spelled it. */
|
|
13
|
+
destinationPath: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Where an import from `exportPath` goes, or `undefined` when it goes
|
|
17
|
+
* nowhere: there is no destination, or the destination is `exportPath`'s own
|
|
18
|
+
* file, where the symbol is in scope. Creates nothing: {@link toImportFile}
|
|
19
|
+
* creates the file once the import is wanted.
|
|
20
|
+
*/
|
|
21
|
+
export declare const toImportDestination: ({ context, exportPath, destinationPath }: ToImportDestinationArgs) => ImportDestination | undefined;
|
|
22
|
+
type ToImportFileArgs = {
|
|
23
|
+
context: GenerateContextType;
|
|
24
|
+
lang: Lang;
|
|
25
|
+
destination: ImportDestination;
|
|
26
|
+
};
|
|
27
|
+
/** The file of `destination`, created through `lang` if it does not exist yet. */
|
|
28
|
+
export declare const toImportFile: ({ context, lang, destination }: ToImportFileArgs) => FileBase;
|
|
29
|
+
type EnsureFileArgs = {
|
|
30
|
+
context: GenerateContextType;
|
|
31
|
+
lang: Lang;
|
|
32
|
+
path: WorkspacePath;
|
|
33
|
+
};
|
|
34
|
+
/** The file at `path`, created through `lang` on first write. */
|
|
35
|
+
export declare const ensureFile: ({ context, lang, path }: EnsureFileArgs) => FileBase;
|
|
36
|
+
type FindDefinitionAtArgs = Omit<FindDefinitionArgs, 'exportPath'> & {
|
|
37
|
+
context: GenerateContextType;
|
|
38
|
+
exportPath: WorkspacePath;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* {@link GenerateContextType.findDefinition} for a normalized export path: a
|
|
42
|
+
* definition is in a file, so with no file at the path there is none, and
|
|
43
|
+
* the path is not normalized again to find that out.
|
|
44
|
+
*/
|
|
45
|
+
export declare const findDefinitionAt: ({ context, ...args }: FindDefinitionAtArgs) => DefinitionBase | undefined;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findDefinitionAt = exports.ensureFile = exports.toImportFile = exports.toImportDestination = void 0;
|
|
4
|
+
const normalizeWorkspacePath_js_1 = require("../helpers/normalizeWorkspacePath.js");
|
|
5
|
+
/**
|
|
6
|
+
* Where an import from `exportPath` goes, or `undefined` when it goes
|
|
7
|
+
* nowhere: there is no destination, or the destination is `exportPath`'s own
|
|
8
|
+
* file, where the symbol is in scope. Creates nothing: {@link toImportFile}
|
|
9
|
+
* creates the file once the import is wanted.
|
|
10
|
+
*/
|
|
11
|
+
const toImportDestination = ({ context, exportPath, destinationPath }) => {
|
|
12
|
+
if (!destinationPath || destinationPath === exportPath) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const file = context.getFile(destinationPath);
|
|
16
|
+
if (file !== undefined) {
|
|
17
|
+
return file.path === exportPath ? undefined : file;
|
|
18
|
+
}
|
|
19
|
+
const path = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath);
|
|
20
|
+
return path === exportPath ? undefined : path;
|
|
21
|
+
};
|
|
22
|
+
exports.toImportDestination = toImportDestination;
|
|
23
|
+
/** The file of `destination`, created through `lang` if it does not exist yet. */
|
|
24
|
+
const toImportFile = ({ context, lang, destination }) => typeof destination === 'string' ? (0, exports.ensureFile)({ context, lang, path: destination }) : destination;
|
|
25
|
+
exports.toImportFile = toImportFile;
|
|
26
|
+
/** The file at `path`, created through `lang` on first write. */
|
|
27
|
+
const ensureFile = ({ context, lang, path }) => context.getFileByWorkspacePath(path) ??
|
|
28
|
+
context.addFile(lang.createFile({ path, settings: context.settings }));
|
|
29
|
+
exports.ensureFile = ensureFile;
|
|
30
|
+
/**
|
|
31
|
+
* {@link GenerateContextType.findDefinition} for a normalized export path: a
|
|
32
|
+
* definition is in a file, so with no file at the path there is none, and
|
|
33
|
+
* the path is not normalized again to find that out.
|
|
34
|
+
*/
|
|
35
|
+
const findDefinitionAt = ({ context, ...args }) => context.getFileByWorkspacePath(args.exportPath) === undefined
|
|
36
|
+
? undefined
|
|
37
|
+
: context.findDefinition(args);
|
|
38
|
+
exports.findDefinitionAt = findDefinitionAt;
|
|
@@ -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
|
/**
|
|
@@ -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;
|