@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
@@ -1,3 +1,4 @@
1
+ import { type WorkspacePath } from '../helpers/normalizeWorkspacePath.js';
1
2
  import type { DefinitionBase } from '../dsl/Definition.js';
2
3
  import type { PendingDefinition } from '../dsl/PendingDefinition.js';
3
4
  import type { OasSchema } from '../oas/schema/Schema.js';
@@ -216,10 +217,19 @@ export declare class GenerateContext implements GenerateContextType {
216
217
  * exists. Neutral primitive: returns the abstract `FileBase` and never
217
218
  * constructs anything, so a (future) language-owned `register` can ask
218
219
  * "does this file exist yet?" without the engine knowing the language.
219
- * To create-on-miss, use the internal `#getFile`; to add a
220
- * language-constructed file, use {@link addFile}.
220
+ * To create on a miss, add a file your language constructs with
221
+ * {@link addFile} (`getFile(path) ?? addFile(lang.createFile(…))`).
222
+ *
223
+ * `filePath` may be in any spelling. It is normalized only when it is no
224
+ * key: a key is a normalized path. The file's own `path` is the key.
221
225
  */
222
226
  getFile(filePath: string): FileBase | undefined;
227
+ /**
228
+ * The file whose normalized path is `path`, or `undefined`. A normalized
229
+ * path is a key as it is, so a miss is not normalized again, as it is in
230
+ * {@link getFile}: there is no file there in any spelling.
231
+ */
232
+ getFileByWorkspacePath(path: WorkspacePath): FileBase | undefined;
223
233
  /**
224
234
  * Read-only view of every file generated so far, keyed by (normalized)
225
235
  * export path. An **inspection / tooling** seam — NOT a coordination
@@ -235,7 +245,8 @@ export declare class GenerateContext implements GenerateContextType {
235
245
  * Store a language-constructed file. The engine never constructs a
236
246
  * concrete (language) `File`; the language's `register` builds its own
237
247
  * `FileBase` subclass and hands it in here. Throws if a file already
238
- * exists at the (normalized) path. Returns the stored file, so
248
+ * exists at the (normalized) path. Sets `file.path` to that normalized
249
+ * path, the file's key. Returns the stored file, so
239
250
  * get-or-create is a single expression at the call site
240
251
  * (`context.getFile(path) ?? context.addFile(new KtFile({ … }))`).
241
252
  */
@@ -10,8 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_failedItems, _GenerateContext_foldedPaths, _GenerateContext_previews, _GenerateContext_captureChannel, _GenerateContext_enrichmentAudit, _GenerateContext_currentSubjectTrail, _GenerateContext_reportSkippedEnrichment, _GenerateContext_logError, _GenerateContext_failItem, _GenerateContext_schemaRefNames, _GenerateContext_subjectDefaults, _GenerateContext_runOasOperationGenerator, _GenerateContext_runWebhookGenerator, _GenerateContext_runGqlOperationGenerator, _GenerateContext_runModelGenerator, _GenerateContext_addPreview, _GenerateContext_toContentSettingsExportPath, _GenerateContext_ejectedBySuffixedPath_get, _GenerateContext_ejectedBySuffixedPathCache, _GenerateContext_findContainer, _GenerateContext_toContainer;
13
- import { normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
14
- import { applyGeneratedSuffix, DEFAULT_GENERATED_SUFFIX } from '../helpers/applyGeneratedSuffix.js';
13
+ import { applyGeneratedSuffixToWorkspacePath, normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
14
+ import { getByWorkspacePath } from '../helpers/getByWorkspacePath.js';
15
+ import { DEFAULT_GENERATED_SUFFIX } from '../helpers/applyGeneratedSuffix.js';
15
16
  import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
16
17
  import { isDefaultRefPath, isRemoteRefPath, toModelKey, toRefPointer, toSchemaComponentRef } from '../helpers/refFns.js';
17
18
  import { isMethod } from '../types/Method.js';
@@ -477,11 +478,22 @@ export class GenerateContext {
477
478
  * exists. Neutral primitive: returns the abstract `FileBase` and never
478
479
  * constructs anything, so a (future) language-owned `register` can ask
479
480
  * "does this file exist yet?" without the engine knowing the language.
480
- * To create-on-miss, use the internal `#getFile`; to add a
481
- * language-constructed file, use {@link addFile}.
481
+ * To create on a miss, add a file your language constructs with
482
+ * {@link addFile} (`getFile(path) ?? addFile(lang.createFile(…))`).
483
+ *
484
+ * `filePath` may be in any spelling. It is normalized only when it is no
485
+ * key: a key is a normalized path. The file's own `path` is the key.
482
486
  */
483
487
  getFile(filePath) {
484
- return __classPrivateFieldGet(this, _GenerateContext_files, "f").get(normalizeWorkspacePath(filePath));
488
+ return getByWorkspacePath(__classPrivateFieldGet(this, _GenerateContext_files, "f"), filePath);
489
+ }
490
+ /**
491
+ * The file whose normalized path is `path`, or `undefined`. A normalized
492
+ * path is a key as it is, so a miss is not normalized again, as it is in
493
+ * {@link getFile}: there is no file there in any spelling.
494
+ */
495
+ getFileByWorkspacePath(path) {
496
+ return __classPrivateFieldGet(this, _GenerateContext_files, "f").get(path);
485
497
  }
486
498
  /**
487
499
  * Read-only view of every file generated so far, keyed by (normalized)
@@ -500,7 +512,8 @@ export class GenerateContext {
500
512
  * Store a language-constructed file. The engine never constructs a
501
513
  * concrete (language) `File`; the language's `register` builds its own
502
514
  * `FileBase` subclass and hands it in here. Throws if a file already
503
- * exists at the (normalized) path. Returns the stored file, so
515
+ * exists at the (normalized) path. Sets `file.path` to that normalized
516
+ * path, the file's key. Returns the stored file, so
504
517
  * get-or-create is a single expression at the call site
505
518
  * (`context.getFile(path) ?? context.addFile(new KtFile({ … }))`).
506
519
  */
@@ -517,6 +530,7 @@ export class GenerateContext {
517
530
  if (existingPath !== undefined) {
518
531
  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.`);
519
532
  }
533
+ file.path = normalizedPath;
520
534
  __classPrivateFieldGet(this, _GenerateContext_files, "f").set(normalizedPath, file);
521
535
  __classPrivateFieldGet(this, _GenerateContext_foldedPaths, "f").set(foldedPath, normalizedPath);
522
536
  return file;
@@ -528,12 +542,8 @@ export class GenerateContext {
528
542
  * @param args - Registration arguments with destination path and JSON content
529
543
  */
530
544
  registerJson({ destinationPath, json }) {
531
- const normalizedPath = normalizeWorkspacePath(destinationPath);
532
- let currentFile = this.getFile(normalizedPath);
533
- if (!currentFile) {
534
- currentFile = new JsonFile({ path: normalizedPath, content: {} });
535
- this.addFile(currentFile);
536
- }
545
+ const currentFile = this.getFile(destinationPath) ??
546
+ this.addFile(new JsonFile({ path: normalizeWorkspacePath(destinationPath), content: {} }));
537
547
  invariant(currentFile instanceof JsonFile, `File at "${destinationPath}" is not a "JsonFile" type`);
538
548
  currentFile.content = json;
539
549
  }
@@ -547,12 +557,8 @@ export class GenerateContext {
547
557
  * @experimental This method is experimental and may change in future versions
548
558
  */
549
559
  registerMarkdown({ destinationPath, markdown }) {
550
- const normalizedPath = normalizeWorkspacePath(destinationPath);
551
- let currentFile = this.getFile(normalizedPath);
552
- if (!currentFile) {
553
- currentFile = new MarkdownFile({ path: normalizedPath, content: '' });
554
- this.addFile(currentFile);
555
- }
560
+ const currentFile = this.getFile(destinationPath) ??
561
+ this.addFile(new MarkdownFile({ path: normalizeWorkspacePath(destinationPath), content: '' }));
556
562
  invariant(currentFile instanceof MarkdownFile, `File at "${destinationPath}" is not a "MarkdownFile" type`);
557
563
  currentFile.content = markdown;
558
564
  }
@@ -568,14 +574,13 @@ export class GenerateContext {
568
574
  * @mutates this.files
569
575
  */
570
576
  register({ imports = [], reExports = [], definitions, custom, destinationPath, into }) {
571
- const normalizedPath = normalizeWorkspacePath(destinationPath);
572
- const currentFile = this.getFile(normalizedPath);
577
+ const currentFile = this.getFile(destinationPath);
573
578
  // `register` never creates files — it speaks pure data and the engine
574
579
  // never names a file class. Callers pre-create the destination file
575
580
  // through their language (the lang package's register function, the
576
581
  // Drivers' ensureFile); reaching a file-miss here is a bug at the
577
582
  // caller.
578
- invariant(currentFile, `Cannot register into '${normalizedPath}' — the file does not exist. ` +
583
+ invariant(currentFile, () => `Cannot register into '${normalizeWorkspacePath(destinationPath)}' — the file does not exist. ` +
579
584
  `Pre-create it through your lang (its register function does this).`);
580
585
  // `custom` is language-neutral — it lives on `FileBase`, so any file
581
586
  // (code or not, e.g. a JSON/Markdown file) can receive it. Last
@@ -597,7 +602,7 @@ export class GenerateContext {
597
602
  const placesADefinition = definitions?.some(definition => definition !== undefined) ?? false;
598
603
  const place = into === undefined || !placesADefinition
599
604
  ? currentFile
600
- : __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContainer).call(this, currentFile, into, normalizedPath);
605
+ : __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContainer).call(this, currentFile, into, currentFile.path);
601
606
  definitions?.forEach(definition => {
602
607
  if (definition) {
603
608
  place.addDefinition(definition);
@@ -673,17 +678,18 @@ export class GenerateContext {
673
678
  // the use site (same ephemeral read the Drivers make) — pre-creates
674
679
  // the destination file caller-side, and stores via the pure-data
675
680
  // `register`.
676
- const normalizedPath = normalizeWorkspacePath(destinationPath);
677
- if (!this.getFile(normalizedPath)) {
678
- this.addFile(projection.lang.createFile({ path: normalizedPath, settings: this.settings }));
679
- }
681
+ const file = this.getFile(destinationPath) ??
682
+ this.addFile(projection.lang.createFile({
683
+ path: normalizeWorkspacePath(destinationPath),
684
+ settings: this.settings
685
+ }));
680
686
  const definition = projection.lang.toDefinition({
681
687
  context: this,
682
688
  identifier: projection.createIdentifier(fallbackName),
683
689
  value,
684
690
  noExport: insertOptions.noExport
685
691
  });
686
- this.register({ definitions: [definition], destinationPath: normalizedPath });
692
+ this.register({ definitions: [definition], destinationPath: file.path });
687
693
  // @TODO Using mapped types would help avoid generics casting
688
694
  return definition;
689
695
  }
@@ -760,10 +766,10 @@ export class GenerateContext {
760
766
  }),
761
767
  ...args.projection.toIdentifierType(args.operation, this)
762
768
  }),
763
- exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this,
764
- // A member has no file of its own: the Driver passes its container's.
765
- args.exportPath ??
766
- args.projection.toExportPath({
769
+ // A member has no file of its own: the Driver passes its container's,
770
+ // which is a finished export path (normalized, suffixed, ejected).
771
+ exportPath: args.exportPath ??
772
+ __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, args.projection.toExportPath({
767
773
  operation: args.operation,
768
774
  enrichments,
769
775
  variant,
@@ -1235,14 +1241,14 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
1235
1241
  source
1236
1242
  };
1237
1243
  }, _GenerateContext_toContentSettingsExportPath = function _GenerateContext_toContentSettingsExportPath(exportPath, generatorId) {
1238
- const suffixed = applyGeneratedSuffix(normalizeWorkspacePath(exportPath, { generatorId }), this.settings?.generatedSuffix ?? DEFAULT_GENERATED_SUFFIX);
1244
+ const suffixed = applyGeneratedSuffixToWorkspacePath(normalizeWorkspacePath(exportPath, { generatorId }), this.settings?.generatedSuffix ?? DEFAULT_GENERATED_SUFFIX, { generatorId });
1239
1245
  return __classPrivateFieldGet(this, _GenerateContext_instances, "a", _GenerateContext_ejectedBySuffixedPath_get).get(suffixed) ?? suffixed;
1240
1246
  }, _GenerateContext_ejectedBySuffixedPath_get = function _GenerateContext_ejectedBySuffixedPath_get() {
1241
1247
  if (__classPrivateFieldGet(this, _GenerateContext_ejectedBySuffixedPathCache, "f") === undefined) {
1242
1248
  const suffix = this.settings?.generatedSuffix ?? DEFAULT_GENERATED_SUFFIX;
1243
1249
  __classPrivateFieldSet(this, _GenerateContext_ejectedBySuffixedPathCache, new Map((this.settings?.ejected ?? []).map(ejectedPath => {
1244
1250
  const normalized = normalizeWorkspacePath(ejectedPath);
1245
- return [applyGeneratedSuffix(normalized, suffix), normalized];
1251
+ return [applyGeneratedSuffixToWorkspacePath(normalized, suffix), normalized];
1246
1252
  })), "f");
1247
1253
  }
1248
1254
  return __classPrivateFieldGet(this, _GenerateContext_ejectedBySuffixedPathCache, "f");
@@ -772,25 +772,26 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
772
772
  const errorMessage = error instanceof Error ? error.message : String(error);
773
773
  const at = rootCause.location === undefined ? '' : ` at '${rootCause.location}'`;
774
774
  const message = `Depends on '${refKey}', removed because of the error${at}: ${errorMessage}`;
775
+ // `logIssueAt` serializes the cause and picks the issue's protocol shape.
775
776
  switch (this.protocol.type) {
776
777
  case 'oas':
777
- __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
778
+ this.logIssueAt({
778
779
  protocol: 'oas',
779
780
  level: 'error',
780
781
  type: 'INVALID_DEPENDENCY_REF',
781
782
  location,
782
783
  message,
783
- cause: toSerializedError(error)
784
+ cause: error
784
785
  });
785
786
  break;
786
787
  case 'gql':
787
- __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
788
+ this.logIssueAt({
788
789
  protocol: 'gql',
789
790
  level: 'error',
790
791
  type: 'INVALID_DEPENDENCY_REF',
791
792
  location,
792
793
  message,
793
- cause: toSerializedError(error)
794
+ cause: error
794
795
  });
795
796
  break;
796
797
  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
@@ -11,6 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
11
11
  };
12
12
  var _RenderContext_captureChannel, _RenderContext_capture;
13
13
  import invariant from 'tiny-invariant';
14
+ import { getByWorkspacePath } from '../helpers/getByWorkspacePath.js';
14
15
  import { normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
15
16
  import { toResolvedArtifactPath } from '../helpers/toResolvedArtifactPath.js';
16
17
  import { CodeFileBase } from '../dsl/CodeFileBase.js';
@@ -244,8 +245,9 @@ export class RenderContext {
244
245
  /**
245
246
  * Retrieves a file from the context by its export path.
246
247
  *
247
- * The path is canonicalized first ({@link normalizeWorkspacePath}), so any
248
- * spelling of the same export path finds the same file. Throws when no
248
+ * A path that is no key is canonicalized ({@link normalizeWorkspacePath})
249
+ * and looked up again, so any spelling of the same export path finds the
250
+ * same file. Throws when no
249
251
  * file exists at that path.
250
252
  *
251
253
  * @param filePath - The export path to retrieve, in any spelling
@@ -263,9 +265,8 @@ export class RenderContext {
263
265
  * ```
264
266
  */
265
267
  getFile(filePath) {
266
- const normalizedPath = normalizeWorkspacePath(filePath);
267
- const currentFile = this.files.get(normalizedPath);
268
- invariant(currentFile, `File not found during render phase: ${normalizedPath}`);
268
+ const currentFile = getByWorkspacePath(this.files, filePath);
269
+ invariant(currentFile, () => `File not found during render phase: ${normalizeWorkspacePath(filePath)}`);
269
270
  return currentFile;
270
271
  }
271
272
  /**
@@ -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
  * }
@@ -22,15 +22,15 @@ import { DEFAULT_VARIANT } from '../types/Variant.js';
22
22
  *
23
23
  * @example Basic settings without enrichments
24
24
  * ```typescript
25
- * import { ContentSettings } from '@skmtc/core';
25
+ * import { ContentSettings, normalizeWorkspacePath } from '@skmtc/core';
26
26
  * import { createType } from '@skmtc/lang-typescript';
27
27
  *
28
28
  * const settings = ContentSettings.empty({
29
- * exportPath: './src/generated/models.ts',
29
+ * exportPath: normalizeWorkspacePath('./src/generated/models.ts'),
30
30
  * identifier: createType('UserModels')
31
31
  * });
32
32
  *
33
- * console.log(settings.exportPath); // './src/generated/models.ts'
33
+ * console.log(settings.exportPath); // '@/src/generated/models.ts'
34
34
  * console.log(settings.enrichments); // undefined
35
35
  * ```
36
36
  *
@@ -44,7 +44,7 @@ import { DEFAULT_VARIANT } from '../types/Variant.js';
44
44
  *
45
45
  * const enrichedSettings = new ContentSettings({
46
46
  * identifier: createType('ValidatedModels'),
47
- * exportPath: './src/models/validated.ts',
47
+ * exportPath: normalizeWorkspacePath('./src/models/validated.ts'),
48
48
  * enrichments: {
49
49
  * validateRequired: true,
50
50
  * generateComments: true,
@@ -66,7 +66,7 @@ import { DEFAULT_VARIANT } from '../types/Variant.js';
66
66
  * ...args,
67
67
  * settings: new ContentSettings({
68
68
  * identifier: createType(args.refName),
69
- * exportPath: './src/validated-models.ts',
69
+ * exportPath: normalizeWorkspacePath('./src/validated-models.ts'),
70
70
  * enrichments: {
71
71
  * validateRequired: true,
72
72
  * generateComments: false,
@@ -107,7 +107,7 @@ export class ContentSettings {
107
107
  * ```typescript
108
108
  * const settings = new ContentSettings({
109
109
  * identifier: createType('ApiModels'),
110
- * exportPath: './src/api/models.ts',
110
+ * exportPath: normalizeWorkspacePath('./src/api/models.ts'),
111
111
  * enrichments: {
112
112
  * includeValidation: true,
113
113
  * format: 'detailed'
@@ -124,7 +124,11 @@ export class ContentSettings {
124
124
  writable: true,
125
125
  value: void 0
126
126
  });
127
- /** The path where generated content will be exported */
127
+ /**
128
+ * The path where generated content will be exported, normalized
129
+ * ({@link normalizeWorkspacePath}): it finds its file without being
130
+ * normalized again.
131
+ */
128
132
  Object.defineProperty(this, "exportPath", {
129
133
  enumerable: true,
130
134
  configurable: true,
@@ -171,7 +175,7 @@ export class ContentSettings {
171
175
  * ```typescript
172
176
  * const basicSettings = ContentSettings.empty({
173
177
  * identifier: createType('SimpleModels'),
174
- * exportPath: './src/models.ts'
178
+ * exportPath: normalizeWorkspacePath('./src/models.ts')
175
179
  * });
176
180
  *
177
181
  * console.log(basicSettings.enrichments); // undefined
@@ -183,7 +187,7 @@ export class ContentSettings {
183
187
  * ...args,
184
188
  * settings: ContentSettings.empty({
185
189
  * identifier: createType(args.refName),
186
- * exportPath: './src/simple-models.ts'
190
+ * exportPath: normalizeWorkspacePath('./src/simple-models.ts')
187
191
  * })
188
192
  * });
189
193
  * }
@@ -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
  *
@@ -34,7 +34,7 @@
34
34
  *
35
35
  * // Access the generated value (guaranteed to be present)
36
36
  * const userTypeName = userModel.toValue(); // UserModelValue (not undefined)
37
- * const exportPath = userModel.toExportPath(); // './src/models.ts'
37
+ * const exportPath = userModel.toExportPath(); // '@/src/models.ts'
38
38
  * const identifier = userModel.toName(); // 'User'
39
39
  *
40
40
  * return new Definition({
@@ -128,7 +128,7 @@ export class Inserted {
128
128
  * @example
129
129
  * ```typescript
130
130
  * const userModel = this.insertModel(generator, 'User');
131
- * const exportPath = userModel.toExportPath(); // './src/models/User.ts'
131
+ * const exportPath = userModel.toExportPath(); // '@/src/models/User.ts'
132
132
  *
133
133
  * // Create import statement
134
134
  * 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,31 @@
1
+ import { normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
2
+ /**
3
+ * Where an import from `exportPath` goes, or `undefined` when it goes
4
+ * nowhere: there is no destination, or the destination is `exportPath`'s own
5
+ * file, where the symbol is in scope. Creates nothing: {@link toImportFile}
6
+ * creates the file once the import is wanted.
7
+ */
8
+ export const toImportDestination = ({ context, exportPath, destinationPath }) => {
9
+ if (!destinationPath || destinationPath === exportPath) {
10
+ return undefined;
11
+ }
12
+ const file = context.getFile(destinationPath);
13
+ if (file !== undefined) {
14
+ return file.path === exportPath ? undefined : file;
15
+ }
16
+ const path = normalizeWorkspacePath(destinationPath);
17
+ return path === exportPath ? undefined : path;
18
+ };
19
+ /** The file of `destination`, created through `lang` if it does not exist yet. */
20
+ export const toImportFile = ({ context, lang, destination }) => typeof destination === 'string' ? ensureFile({ context, lang, path: destination }) : destination;
21
+ /** The file at `path`, created through `lang` on first write. */
22
+ export const ensureFile = ({ context, lang, path }) => context.getFileByWorkspacePath(path) ??
23
+ context.addFile(lang.createFile({ path, settings: context.settings }));
24
+ /**
25
+ * {@link GenerateContextType.findDefinition} for a normalized export path: a
26
+ * definition is in a file, so with no file at the path there is none, and
27
+ * the path is not normalized again to find that out.
28
+ */
29
+ export const findDefinitionAt = ({ context, ...args }) => context.getFileByWorkspacePath(args.exportPath) === undefined
30
+ ? undefined
31
+ : context.findDefinition(args);