@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.
Files changed (51) hide show
  1. package/esm/context/GenerateContext.d.ts +14 -3
  2. package/esm/context/GenerateContext.js +39 -33
  3. package/esm/context/ParseContext.js +5 -4
  4. package/esm/context/RenderContext.d.ts +3 -2
  5. package/esm/context/RenderContext.js +6 -5
  6. package/esm/context/generateTypes.d.ts +6 -2
  7. package/esm/dsl/ContentSettings.d.ts +17 -12
  8. package/esm/dsl/ContentSettings.js +13 -9
  9. package/esm/dsl/Inserted.d.ts +4 -3
  10. package/esm/dsl/Inserted.js +2 -2
  11. package/esm/dsl/PendingDefinition.d.ts +3 -2
  12. package/esm/dsl/driverFiles.d.ts +46 -0
  13. package/esm/dsl/driverFiles.js +31 -0
  14. package/esm/dsl/model/ModelDriver.d.ts +5 -7
  15. package/esm/dsl/model/ModelDriver.js +12 -29
  16. package/esm/dsl/operation/gql/GqlOperationDriver.d.ts +1 -1
  17. package/esm/dsl/operation/gql/GqlOperationDriver.js +15 -12
  18. package/esm/dsl/operation/oas/OasOperationDriver.d.ts +1 -1
  19. package/esm/dsl/operation/oas/OasOperationDriver.js +11 -14
  20. package/esm/dsl/webhook/WebhookDriver.d.ts +1 -1
  21. package/esm/dsl/webhook/WebhookDriver.js +15 -12
  22. package/esm/helpers/getByWorkspacePath.d.ts +9 -0
  23. package/esm/helpers/getByWorkspacePath.js +10 -0
  24. package/esm/helpers/normalizeWorkspacePath.d.ts +25 -2
  25. package/esm/helpers/normalizeWorkspacePath.js +16 -1
  26. package/package.json +1 -1
  27. package/script/context/GenerateContext.d.ts +14 -3
  28. package/script/context/GenerateContext.js +37 -31
  29. package/script/context/ParseContext.js +5 -4
  30. package/script/context/RenderContext.d.ts +3 -2
  31. package/script/context/RenderContext.js +6 -5
  32. package/script/context/generateTypes.d.ts +6 -2
  33. package/script/dsl/ContentSettings.d.ts +17 -12
  34. package/script/dsl/ContentSettings.js +13 -9
  35. package/script/dsl/Inserted.d.ts +4 -3
  36. package/script/dsl/Inserted.js +2 -2
  37. package/script/dsl/PendingDefinition.d.ts +3 -2
  38. package/script/dsl/driverFiles.d.ts +46 -0
  39. package/script/dsl/driverFiles.js +38 -0
  40. package/script/dsl/model/ModelDriver.d.ts +5 -7
  41. package/script/dsl/model/ModelDriver.js +12 -29
  42. package/script/dsl/operation/gql/GqlOperationDriver.d.ts +1 -1
  43. package/script/dsl/operation/gql/GqlOperationDriver.js +15 -12
  44. package/script/dsl/operation/oas/OasOperationDriver.d.ts +1 -1
  45. package/script/dsl/operation/oas/OasOperationDriver.js +11 -14
  46. package/script/dsl/webhook/WebhookDriver.d.ts +1 -1
  47. package/script/dsl/webhook/WebhookDriver.js +15 -12
  48. package/script/helpers/getByWorkspacePath.d.ts +9 -0
  49. package/script/helpers/getByWorkspacePath.js +14 -0
  50. package/script/helpers/normalizeWorkspacePath.d.ts +25 -2
  51. package/script/helpers/normalizeWorkspacePath.js +18 -2
@@ -17,6 +17,7 @@ var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_failedI
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.toModelSource = exports.toGqlOperationSource = exports.toWebhookSource = exports.toOasOperationSource = exports.GenerateContext = void 0;
19
19
  const normalizeWorkspacePath_js_1 = require("../helpers/normalizeWorkspacePath.js");
20
+ const getByWorkspacePath_js_1 = require("../helpers/getByWorkspacePath.js");
20
21
  const applyGeneratedSuffix_js_1 = require("../helpers/applyGeneratedSuffix.js");
21
22
  const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
22
23
  const refFns_js_1 = require("../helpers/refFns.js");
@@ -483,11 +484,22 @@ class GenerateContext {
483
484
  * exists. Neutral primitive: returns the abstract `FileBase` and never
484
485
  * constructs anything, so a (future) language-owned `register` can ask
485
486
  * "does this file exist yet?" without the engine knowing the language.
486
- * To create-on-miss, use the internal `#getFile`; to add a
487
- * language-constructed file, use {@link addFile}.
487
+ * To create on a miss, add a file your language constructs with
488
+ * {@link addFile} (`getFile(path) ?? addFile(lang.createFile(…))`).
489
+ *
490
+ * `filePath` may be in any spelling. It is normalized only when it is no
491
+ * key: a key is a normalized path. The file's own `path` is the key.
488
492
  */
489
493
  getFile(filePath) {
490
- return __classPrivateFieldGet(this, _GenerateContext_files, "f").get((0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(filePath));
494
+ return (0, getByWorkspacePath_js_1.getByWorkspacePath)(__classPrivateFieldGet(this, _GenerateContext_files, "f"), filePath);
495
+ }
496
+ /**
497
+ * The file whose normalized path is `path`, or `undefined`. A normalized
498
+ * path is a key as it is, so a miss is not normalized again, as it is in
499
+ * {@link getFile}: there is no file there in any spelling.
500
+ */
501
+ getFileByWorkspacePath(path) {
502
+ return __classPrivateFieldGet(this, _GenerateContext_files, "f").get(path);
491
503
  }
492
504
  /**
493
505
  * Read-only view of every file generated so far, keyed by (normalized)
@@ -506,7 +518,8 @@ class GenerateContext {
506
518
  * Store a language-constructed file. The engine never constructs a
507
519
  * concrete (language) `File`; the language's `register` builds its own
508
520
  * `FileBase` subclass and hands it in here. Throws if a file already
509
- * exists at the (normalized) path. Returns the stored file, so
521
+ * exists at the (normalized) path. Sets `file.path` to that normalized
522
+ * path, the file's key. Returns the stored file, so
510
523
  * get-or-create is a single expression at the call site
511
524
  * (`context.getFile(path) ?? context.addFile(new KtFile({ … }))`).
512
525
  */
@@ -523,6 +536,7 @@ class GenerateContext {
523
536
  if (existingPath !== undefined) {
524
537
  throw new Error(`File '${normalizedPath}' differs from '${existingPath}' only in case. On a file system that ignores case, as macOS's and Windows' do by default, they are one file.`);
525
538
  }
539
+ file.path = normalizedPath;
526
540
  __classPrivateFieldGet(this, _GenerateContext_files, "f").set(normalizedPath, file);
527
541
  __classPrivateFieldGet(this, _GenerateContext_foldedPaths, "f").set(foldedPath, normalizedPath);
528
542
  return file;
@@ -534,12 +548,8 @@ class GenerateContext {
534
548
  * @param args - Registration arguments with destination path and JSON content
535
549
  */
536
550
  registerJson({ destinationPath, json }) {
537
- const normalizedPath = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath);
538
- let currentFile = this.getFile(normalizedPath);
539
- if (!currentFile) {
540
- currentFile = new JsonFile_js_1.JsonFile({ path: normalizedPath, content: {} });
541
- this.addFile(currentFile);
542
- }
551
+ const currentFile = this.getFile(destinationPath) ??
552
+ this.addFile(new JsonFile_js_1.JsonFile({ path: (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath), content: {} }));
543
553
  (0, tiny_invariant_1.default)(currentFile instanceof JsonFile_js_1.JsonFile, `File at "${destinationPath}" is not a "JsonFile" type`);
544
554
  currentFile.content = json;
545
555
  }
@@ -553,12 +563,8 @@ class GenerateContext {
553
563
  * @experimental This method is experimental and may change in future versions
554
564
  */
555
565
  registerMarkdown({ destinationPath, markdown }) {
556
- const normalizedPath = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath);
557
- let currentFile = this.getFile(normalizedPath);
558
- if (!currentFile) {
559
- currentFile = new MarkdownFile_js_1.MarkdownFile({ path: normalizedPath, content: '' });
560
- this.addFile(currentFile);
561
- }
566
+ const currentFile = this.getFile(destinationPath) ??
567
+ this.addFile(new MarkdownFile_js_1.MarkdownFile({ path: (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath), content: '' }));
562
568
  (0, tiny_invariant_1.default)(currentFile instanceof MarkdownFile_js_1.MarkdownFile, `File at "${destinationPath}" is not a "MarkdownFile" type`);
563
569
  currentFile.content = markdown;
564
570
  }
@@ -574,14 +580,13 @@ class GenerateContext {
574
580
  * @mutates this.files
575
581
  */
576
582
  register({ imports = [], reExports = [], definitions, custom, destinationPath, into }) {
577
- const normalizedPath = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath);
578
- const currentFile = this.getFile(normalizedPath);
583
+ const currentFile = this.getFile(destinationPath);
579
584
  // `register` never creates files — it speaks pure data and the engine
580
585
  // never names a file class. Callers pre-create the destination file
581
586
  // through their language (the lang package's register function, the
582
587
  // Drivers' ensureFile); reaching a file-miss here is a bug at the
583
588
  // caller.
584
- (0, tiny_invariant_1.default)(currentFile, `Cannot register into '${normalizedPath}' — the file does not exist. ` +
589
+ (0, tiny_invariant_1.default)(currentFile, () => `Cannot register into '${(0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath)}' — the file does not exist. ` +
585
590
  `Pre-create it through your lang (its register function does this).`);
586
591
  // `custom` is language-neutral — it lives on `FileBase`, so any file
587
592
  // (code or not, e.g. a JSON/Markdown file) can receive it. Last
@@ -603,7 +608,7 @@ class GenerateContext {
603
608
  const placesADefinition = definitions?.some(definition => definition !== undefined) ?? false;
604
609
  const place = into === undefined || !placesADefinition
605
610
  ? currentFile
606
- : __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContainer).call(this, currentFile, into, normalizedPath);
611
+ : __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContainer).call(this, currentFile, into, currentFile.path);
607
612
  definitions?.forEach(definition => {
608
613
  if (definition) {
609
614
  place.addDefinition(definition);
@@ -679,17 +684,18 @@ class GenerateContext {
679
684
  // the use site (same ephemeral read the Drivers make) — pre-creates
680
685
  // the destination file caller-side, and stores via the pure-data
681
686
  // `register`.
682
- const normalizedPath = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath);
683
- if (!this.getFile(normalizedPath)) {
684
- this.addFile(projection.lang.createFile({ path: normalizedPath, settings: this.settings }));
685
- }
687
+ const file = this.getFile(destinationPath) ??
688
+ this.addFile(projection.lang.createFile({
689
+ path: (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(destinationPath),
690
+ settings: this.settings
691
+ }));
686
692
  const definition = projection.lang.toDefinition({
687
693
  context: this,
688
694
  identifier: projection.createIdentifier(fallbackName),
689
695
  value,
690
696
  noExport: insertOptions.noExport
691
697
  });
692
- this.register({ definitions: [definition], destinationPath: normalizedPath });
698
+ this.register({ definitions: [definition], destinationPath: file.path });
693
699
  // @TODO Using mapped types would help avoid generics casting
694
700
  return definition;
695
701
  }
@@ -766,10 +772,10 @@ class GenerateContext {
766
772
  }),
767
773
  ...args.projection.toIdentifierType(args.operation, this)
768
774
  }),
769
- exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this,
770
- // A member has no file of its own: the Driver passes its container's.
771
- args.exportPath ??
772
- args.projection.toExportPath({
775
+ // A member has no file of its own: the Driver passes its container's,
776
+ // which is a finished export path (normalized, suffixed, ejected).
777
+ exportPath: args.exportPath ??
778
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, args.projection.toExportPath({
773
779
  operation: args.operation,
774
780
  enrichments,
775
781
  variant,
@@ -1242,14 +1248,14 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
1242
1248
  source
1243
1249
  };
1244
1250
  }, _GenerateContext_toContentSettingsExportPath = function _GenerateContext_toContentSettingsExportPath(exportPath, generatorId) {
1245
- const suffixed = (0, applyGeneratedSuffix_js_1.applyGeneratedSuffix)((0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(exportPath, { generatorId }), this.settings?.generatedSuffix ?? applyGeneratedSuffix_js_1.DEFAULT_GENERATED_SUFFIX);
1251
+ const suffixed = (0, normalizeWorkspacePath_js_1.applyGeneratedSuffixToWorkspacePath)((0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(exportPath, { generatorId }), this.settings?.generatedSuffix ?? applyGeneratedSuffix_js_1.DEFAULT_GENERATED_SUFFIX, { generatorId });
1246
1252
  return __classPrivateFieldGet(this, _GenerateContext_instances, "a", _GenerateContext_ejectedBySuffixedPath_get).get(suffixed) ?? suffixed;
1247
1253
  }, _GenerateContext_ejectedBySuffixedPath_get = function _GenerateContext_ejectedBySuffixedPath_get() {
1248
1254
  if (__classPrivateFieldGet(this, _GenerateContext_ejectedBySuffixedPathCache, "f") === undefined) {
1249
1255
  const suffix = this.settings?.generatedSuffix ?? applyGeneratedSuffix_js_1.DEFAULT_GENERATED_SUFFIX;
1250
1256
  __classPrivateFieldSet(this, _GenerateContext_ejectedBySuffixedPathCache, new Map((this.settings?.ejected ?? []).map(ejectedPath => {
1251
1257
  const normalized = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(ejectedPath);
1252
- return [(0, applyGeneratedSuffix_js_1.applyGeneratedSuffix)(normalized, suffix), normalized];
1258
+ return [(0, normalizeWorkspacePath_js_1.applyGeneratedSuffixToWorkspacePath)(normalized, suffix), normalized];
1253
1259
  })), "f");
1254
1260
  }
1255
1261
  return __classPrivateFieldGet(this, _GenerateContext_ejectedBySuffixedPathCache, "f");
@@ -776,25 +776,26 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
776
776
  const errorMessage = error instanceof Error ? error.message : String(error);
777
777
  const at = rootCause.location === undefined ? '' : ` at '${rootCause.location}'`;
778
778
  const message = `Depends on '${refKey}', removed because of the error${at}: ${errorMessage}`;
779
+ // `logIssueAt` serializes the cause and picks the issue's protocol shape.
779
780
  switch (this.protocol.type) {
780
781
  case 'oas':
781
- __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
782
+ this.logIssueAt({
782
783
  protocol: 'oas',
783
784
  level: 'error',
784
785
  type: 'INVALID_DEPENDENCY_REF',
785
786
  location,
786
787
  message,
787
- cause: (0, SerializedError_js_1.toSerializedError)(error)
788
+ cause: error
788
789
  });
789
790
  break;
790
791
  case 'gql':
791
- __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
792
+ this.logIssueAt({
792
793
  protocol: 'gql',
793
794
  level: 'error',
794
795
  type: 'INVALID_DEPENDENCY_REF',
795
796
  location,
796
797
  message,
797
- cause: (0, SerializedError_js_1.toSerializedError)(error)
798
+ cause: error
798
799
  });
799
800
  break;
800
801
  default: {
@@ -132,8 +132,9 @@ export declare class RenderContext {
132
132
  /**
133
133
  * Retrieves a file from the context by its export path.
134
134
  *
135
- * The path is canonicalized first ({@link normalizeWorkspacePath}), so any
136
- * spelling of the same export path finds the same file. Throws when no
135
+ * A path that is no key is canonicalized ({@link normalizeWorkspacePath})
136
+ * and looked up again, so any spelling of the same export path finds the
137
+ * same file. Throws when no
137
138
  * file exists at that path.
138
139
  *
139
140
  * @param filePath - The export path to retrieve, in any spelling
@@ -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
- * The path is canonicalized first ({@link normalizeWorkspacePath}), so any
254
- * spelling of the same export path finds the same file. Throws when no
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 normalizedPath = (0, normalizeWorkspacePath_js_1.normalizeWorkspacePath)(filePath);
273
- const currentFile = this.files.get(normalizedPath);
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?: string;
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: string;
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: string;
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); // './src/generated/models.ts'
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
- /** The path where generated content will be exported */
136
- exportPath: string;
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); // './src/generated/models.ts'
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
- /** The path where generated content will be exported */
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
  * }
@@ -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(); // './src/models.ts'
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(); // './src/models/User.ts'
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(): string;
136
+ toExportPath(): WorkspacePath;
136
137
  /**
137
138
  * Gets the generated value from the inserted artifact.
138
139
  *
@@ -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(); // './src/models.ts'
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(); // './src/models/User.ts'
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: string;
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: string;
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
- * Ensure the file at `path` exists, creating it on first write through
48
- * the projection's language — the static read off the projection class
49
- * at the use site, never persisted (works pre-construction on the
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: string;
69
+ exportPath: WorkspacePath;
72
70
  };
73
71
  };
74
72
  /**