document-model 6.2.3-dev.9 → 6.2.3-dev.91

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/dist/mock.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import { generateMock } from "@powerhousedao/shared/document-model/mock";
2
- export { generateMock };
2
+ export { generateMock };
3
+ export {};
package/dist/node.d.mts CHANGED
@@ -1,15 +1,14 @@
1
1
  import { MinimalBackupData, PHBaseState, PHDocument, Reducer, ReplayDocumentOptions, VersionedReplayConfig } from "@powerhousedao/shared/document-model";
2
2
  import { BinaryLike } from "node:crypto";
3
-
4
3
  //#region node.d.mts
5
- declare function writeFileNode(path: string, name: string, data: Uint8Array): Promise<string>;
6
- declare function readFileNode(path: string): NonSharedBuffer;
7
- declare function fetchFileNode(url: string): Promise<{
4
+ export declare function writeFileNode(path: string, name: string, data: Uint8Array): Promise<string>;
5
+ export declare function readFileNode(path: string): NonSharedBuffer;
6
+ export declare function fetchFileNode(url: string): Promise<{
8
7
  buffer: Buffer;
9
8
  mimeType?: string;
10
9
  }>;
11
- declare const getFileNode: (file: string) => Promise<NonSharedBuffer>;
12
- declare const hashNode: (data: BinaryLike, algorithm?: string, encoding?: "base64" | "hex", _params?: Record<string, unknown>) => string;
10
+ export declare const getFileNode: (file: string) => Promise<NonSharedBuffer>;
11
+ export declare const hashNode: (data: BinaryLike, algorithm?: string, encoding?: "base64" | "hex", _params?: Record<string, unknown>) => string;
13
12
  /**
14
13
  * Loads a document from a ZIP file.
15
14
  *
@@ -25,7 +24,7 @@ declare const hashNode: (data: BinaryLike, algorithm?: string, encoding?: "base6
25
24
  * @returns A promise that resolves to the document state after applying all the operations.
26
25
  * @throws An error if the initial state or the operations history is not found in the ZIP file.
27
26
  */
28
- declare function baseLoadFromFile<TState extends PHBaseState = PHBaseState>(path: string, reducer: Reducer<TState>, options?: ReplayDocumentOptions): Promise<PHDocument<TState>>;
27
+ export declare function baseLoadFromFile<TState extends PHBaseState = PHBaseState>(path: string, reducer: Reducer<TState>, options?: ReplayDocumentOptions): Promise<PHDocument<TState>>;
29
28
  /**
30
29
  * Loads a version-aware document from a ZIP file.
31
30
  *
@@ -35,13 +34,13 @@ declare function baseLoadFromFile<TState extends PHBaseState = PHBaseState>(path
35
34
  * @param options - Optional replay options.
36
35
  * @returns A promise that resolves to the document state after versioned replay.
37
36
  */
38
- declare function baseLoadFromFileVersioned<TState extends PHBaseState = PHBaseState>(path: string, config: VersionedReplayConfig, options?: ReplayDocumentOptions): Promise<PHDocument<TState>>;
37
+ export declare function baseLoadFromFileVersioned<TState extends PHBaseState = PHBaseState>(path: string, config: VersionedReplayConfig, options?: ReplayDocumentOptions): Promise<PHDocument<TState>>;
39
38
  /**
40
39
  * Saves a minimal document backup to a .phd file.
41
40
  * Used when the full document is not available (e.g., in onOperations handler).
42
41
  * Creates a file with minimal header and empty operations.
43
42
  */
44
- declare function baseMinimalSaveToFile(data: MinimalBackupData, path: string, extension: string): Promise<string>;
43
+ export declare function baseMinimalSaveToFile(data: MinimalBackupData, path: string, extension: string): Promise<string>;
45
44
  /**
46
45
  * Saves a document to a ZIP file.
47
46
  *
@@ -54,7 +53,7 @@ declare function baseMinimalSaveToFile(data: MinimalBackupData, path: string, ex
54
53
  * @param extension - The extension to use for the file.
55
54
  * @returns A promise that resolves to the path of the saved file.
56
55
  */
57
- declare function baseSaveToFile(document: PHDocument, path: string, extension: string, name?: string): Promise<string>;
56
+ export declare function baseSaveToFile(document: PHDocument, path: string, extension: string, name?: string): Promise<string>;
58
57
  //#endregion
59
- export { baseLoadFromFile, baseLoadFromFileVersioned, baseMinimalSaveToFile, baseSaveToFile, fetchFileNode, getFileNode, hashNode, readFileNode, writeFileNode };
58
+ export {};
60
59
  //# sourceMappingURL=node.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.mts","names":[],"sources":["../node.mts"],"mappings":";;;;iBAkBgB,aAAA,CACd,IAAA,UACA,IAAA,UACA,IAAA,EAA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ACR,UAAU,wBACT,QAAQ,WAAW;;;;;;wBAUA,sBACpB,MAAM,mBACN,cACA,oBAAiB;;;;;;;;;;;;;wBA0BG,eACpB,UAAU,YACV,cACA,mBACA,gBAAa"}
package/dist/node.mjs CHANGED
@@ -69,7 +69,8 @@ const hashNode = (data, algorithm = "sha1", encoding = "base64", _params) => {
69
69
  * @throws An error if the initial state or the operations history is not found in the ZIP file.
70
70
  */
71
71
  async function baseLoadFromFile(path, reducer, options) {
72
- return baseLoadFromInput(readFileNode(path), reducer, options);
72
+ const file = readFileNode(path);
73
+ return baseLoadFromInput(file, reducer, options);
73
74
  }
74
75
  /**
75
76
  * Loads a version-aware document from a ZIP file.
@@ -81,7 +82,8 @@ async function baseLoadFromFile(path, reducer, options) {
81
82
  * @returns A promise that resolves to the document state after versioned replay.
82
83
  */
83
84
  async function baseLoadFromFileVersioned(path, config, options) {
84
- return baseLoadFromInputVersioned(readFileNode(path), config, options);
85
+ const file = readFileNode(path);
86
+ return baseLoadFromInputVersioned(file, config, options);
85
87
  }
86
88
  /**
87
89
  * Saves a minimal document backup to a .phd file.
package/dist/node.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.mjs","names":[],"sources":["../node.mts"],"sourcesContent":["import {\n baseLoadFromInput,\n baseLoadFromInputVersioned,\n createMinimalZip,\n createZip,\n type MinimalBackupData,\n type PHBaseState,\n type PHDocument,\n type Reducer,\n type ReplayDocumentOptions,\n type VersionedReplayConfig,\n} from \"@powerhousedao/shared/document-model\";\nimport type { BinaryLike } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport https from \"node:https\";\nimport { join } from \"node:path\";\n\nexport function writeFileNode(\n path: string,\n name: string,\n data: Uint8Array,\n): Promise<string> {\n const filePath = join(path, name);\n fs.mkdirSync(path, { recursive: true });\n\n return new Promise((resolve, reject) => {\n try {\n fs.writeFile(filePath, data, {}, (err) => {\n if (err) {\n reject(err);\n } else {\n resolve(filePath);\n }\n });\n } catch (error: unknown) {\n if (error instanceof Error) {\n reject(error);\n } else {\n reject(new Error(String(error)));\n }\n }\n });\n}\n\nexport function readFileNode(path: string) {\n return fs.readFileSync(path);\n}\n\nexport function fetchFileNode(\n url: string,\n): Promise<{ buffer: Buffer; mimeType?: string }> {\n return new Promise((resolve, reject) => {\n https\n .get(url, (resp) => {\n const data: Uint8Array[] = [];\n const mimeType = resp.headers[\"content-type\"];\n resp.on(\"data\", (chunk: Uint8Array) => {\n data.push(chunk);\n });\n\n resp.on(\"end\", () => {\n resolve({ buffer: Buffer.concat(data), mimeType });\n });\n })\n .on(\"error\", (err) => {\n reject(err);\n });\n });\n}\n\nexport const getFileNode = (file: string) => {\n return Promise.resolve(readFileNode(file));\n};\n\nexport const hashNode = (\n data: BinaryLike,\n algorithm = \"sha1\",\n encoding: \"base64\" | \"hex\" = \"base64\",\n _params?: Record<string, unknown>,\n) => {\n if (![\"sha1\", \"sha256\", \"sha512\"].includes(algorithm)) {\n throw new Error(\n `Hashing algorithm not supported: \"${algorithm}\". Available: sha1, sha256, sha512`,\n );\n }\n\n if (![\"base64\", \"hex\"].includes(encoding)) {\n throw new Error(\n `Hash encoding not supported: \"${encoding}\". Available: base64, hex`,\n );\n }\n\n return createHash(algorithm).update(data).digest(encoding);\n};\n\n/**\n * Loads a document from a ZIP file.\n *\n * @remarks\n * This function reads a ZIP file and returns the document state after\n * applying all the operations. The reducer is used to apply the operations.\n *\n * @typeParam S - The type of the state object.\n * @typeParam A - The type of the actions that can be applied to the state object.\n *\n * @param path - The path to the ZIP file.\n * @param reducer - The reducer to apply the operations to the state object.\n * @returns A promise that resolves to the document state after applying all the operations.\n * @throws An error if the initial state or the operations history is not found in the ZIP file.\n */\nexport async function baseLoadFromFile<\n TState extends PHBaseState = PHBaseState,\n>(\n path: string,\n reducer: Reducer<TState>,\n options?: ReplayDocumentOptions,\n): Promise<PHDocument<TState>> {\n const file = readFileNode(path);\n return baseLoadFromInput(file, reducer, options);\n}\n\n/**\n * Loads a version-aware document from a ZIP file.\n *\n * @typeParam TState - The type of the state object.\n * @param path - The path to the ZIP file.\n * @param config - Versioned replay config with per-version reducers and optional upgrade manifest.\n * @param options - Optional replay options.\n * @returns A promise that resolves to the document state after versioned replay.\n */\nexport async function baseLoadFromFileVersioned<\n TState extends PHBaseState = PHBaseState,\n>(\n path: string,\n config: VersionedReplayConfig,\n options?: ReplayDocumentOptions,\n): Promise<PHDocument<TState>> {\n const file = readFileNode(path);\n return baseLoadFromInputVersioned<TState>(file, config, options);\n}\n\n/**\n * Saves a minimal document backup to a .phd file.\n * Used when the full document is not available (e.g., in onOperations handler).\n * Creates a file with minimal header and empty operations.\n */\nexport async function baseMinimalSaveToFile(\n data: MinimalBackupData,\n path: string,\n extension: string,\n) {\n const file = await createMinimalZip(data);\n const fileExtension = extension ? `.${extension}.phd` : \".phd\";\n\n return writeFileNode(\n path,\n data.name.endsWith(fileExtension)\n ? data.name\n : `${data.name}${fileExtension}`,\n file,\n );\n}\n\n/**\n * Saves a document to a ZIP file.\n *\n * @remarks\n * This function creates a ZIP file containing the document's state and\n * operations. The file is saved to the specified path.\n *\n * @param document - The document to save to the file.\n * @param path - The path to save the file to.\n * @param extension - The extension to use for the file.\n * @returns A promise that resolves to the path of the saved file.\n */\nexport async function baseSaveToFile(\n document: PHDocument,\n path: string,\n extension: string,\n name?: string,\n) {\n const file = await createZip(document);\n const fileName = name ?? document.header.name;\n const fileExtension = extension ? `.${extension}.phd` : \".phd\";\n\n return writeFileNode(\n path,\n fileName.endsWith(fileExtension) ? fileName : `${fileName}${fileExtension}`,\n file,\n );\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,cACd,MACA,MACA,MACiB;CACjB,MAAM,WAAW,KAAK,MAAM,KAAK;AACjC,IAAG,UAAU,MAAM,EAAE,WAAW,MAAM,CAAC;AAEvC,QAAO,IAAI,SAAS,SAAS,WAAW;AACtC,MAAI;AACF,MAAG,UAAU,UAAU,MAAM,EAAE,GAAG,QAAQ;AACxC,Q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AM,OAAO,MAAM,iBAAiB,KAAK;CACzC,MAAM,gBAAgB,YAAY,IAAI,UAAU,QAAQ;AAExD,QAAO,cACL,MACA,KAAK,KAAK,SAAS,cAAc,GAC7B,KAAK,OACL,GAAG,KAAK,OAAO,iBACnB,KACD;;;;;;;;;;;;;;AAeH,eAAsB,eACpB,UACA,MACA,WACA,MACA;CACA,MAAM,OAAO,MAAM,UAAU,SAAS;CACtC,MAAM,WAAW,QAAQ,SAAS,OAAO;CACzC,MAAM,gBAAgB,YAAY,IAAI,UAAU,QAAQ;AAExD,QAAO,cACL,MACA,SAAS,SAAS,cAAc,GAAG,WAAW,GAAG,WAAW,iBAC5D,KACD"}
1
+ {"version":3,"file":"node.mjs","names":[],"sources":["../node.mts"],"sourcesContent":["import {\n baseLoadFromInput,\n baseLoadFromInputVersioned,\n createMinimalZip,\n createZip,\n type MinimalBackupData,\n type PHBaseState,\n type PHDocument,\n type Reducer,\n type ReplayDocumentOptions,\n type VersionedReplayConfig,\n} from \"@powerhousedao/shared/document-model\";\nimport type { BinaryLike } from \"node:crypto\";\nimport { createHash } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport https from \"node:https\";\nimport { join } from \"node:path\";\n\nexport function writeFileNode(\n path: string,\n name: string,\n data: Uint8Array,\n): Promise<string> {\n const filePath = join(path, name);\n fs.mkdirSync(path, { recursive: true });\n\n return new Promise((resolve, reject) => {\n try {\n fs.writeFile(filePath, data, {}, (err) => {\n if (err) {\n reject(err);\n } else {\n resolve(filePath);\n }\n });\n } catch (error: unknown) {\n if (error instanceof Error) {\n reject(error);\n } else {\n reject(new Error(String(error)));\n }\n }\n });\n}\n\nexport function readFileNode(path: string) {\n return fs.readFileSync(path);\n}\n\nexport function fetchFileNode(\n url: string,\n): Promise<{ buffer: Buffer; mimeType?: string }> {\n return new Promise((resolve, reject) => {\n https\n .get(url, (resp) => {\n const data: Uint8Array[] = [];\n const mimeType = resp.headers[\"content-type\"];\n resp.on(\"data\", (chunk: Uint8Array) => {\n data.push(chunk);\n });\n\n resp.on(\"end\", () => {\n resolve({ buffer: Buffer.concat(data), mimeType });\n });\n })\n .on(\"error\", (err) => {\n reject(err);\n });\n });\n}\n\nexport const getFileNode = (file: string) => {\n return Promise.resolve(readFileNode(file));\n};\n\nexport const hashNode = (\n data: BinaryLike,\n algorithm = \"sha1\",\n encoding: \"base64\" | \"hex\" = \"base64\",\n _params?: Record<string, unknown>,\n) => {\n if (![\"sha1\", \"sha256\", \"sha512\"].includes(algorithm)) {\n throw new Error(\n `Hashing algorithm not supported: \"${algorithm}\". Available: sha1, sha256, sha512`,\n );\n }\n\n if (![\"base64\", \"hex\"].includes(encoding)) {\n throw new Error(\n `Hash encoding not supported: \"${encoding}\". Available: base64, hex`,\n );\n }\n\n return createHash(algorithm).update(data).digest(encoding);\n};\n\n/**\n * Loads a document from a ZIP file.\n *\n * @remarks\n * This function reads a ZIP file and returns the document state after\n * applying all the operations. The reducer is used to apply the operations.\n *\n * @typeParam S - The type of the state object.\n * @typeParam A - The type of the actions that can be applied to the state object.\n *\n * @param path - The path to the ZIP file.\n * @param reducer - The reducer to apply the operations to the state object.\n * @returns A promise that resolves to the document state after applying all the operations.\n * @throws An error if the initial state or the operations history is not found in the ZIP file.\n */\nexport async function baseLoadFromFile<\n TState extends PHBaseState = PHBaseState,\n>(\n path: string,\n reducer: Reducer<TState>,\n options?: ReplayDocumentOptions,\n): Promise<PHDocument<TState>> {\n const file = readFileNode(path);\n return baseLoadFromInput(file, reducer, options);\n}\n\n/**\n * Loads a version-aware document from a ZIP file.\n *\n * @typeParam TState - The type of the state object.\n * @param path - The path to the ZIP file.\n * @param config - Versioned replay config with per-version reducers and optional upgrade manifest.\n * @param options - Optional replay options.\n * @returns A promise that resolves to the document state after versioned replay.\n */\nexport async function baseLoadFromFileVersioned<\n TState extends PHBaseState = PHBaseState,\n>(\n path: string,\n config: VersionedReplayConfig,\n options?: ReplayDocumentOptions,\n): Promise<PHDocument<TState>> {\n const file = readFileNode(path);\n return baseLoadFromInputVersioned<TState>(file, config, options);\n}\n\n/**\n * Saves a minimal document backup to a .phd file.\n * Used when the full document is not available (e.g., in onOperations handler).\n * Creates a file with minimal header and empty operations.\n */\nexport async function baseMinimalSaveToFile(\n data: MinimalBackupData,\n path: string,\n extension: string,\n) {\n const file = await createMinimalZip(data);\n const fileExtension = extension ? `.${extension}.phd` : \".phd\";\n\n return writeFileNode(\n path,\n data.name.endsWith(fileExtension)\n ? data.name\n : `${data.name}${fileExtension}`,\n file,\n );\n}\n\n/**\n * Saves a document to a ZIP file.\n *\n * @remarks\n * This function creates a ZIP file containing the document's state and\n * operations. The file is saved to the specified path.\n *\n * @param document - The document to save to the file.\n * @param path - The path to save the file to.\n * @param extension - The extension to use for the file.\n * @returns A promise that resolves to the path of the saved file.\n */\nexport async function baseSaveToFile(\n document: PHDocument,\n path: string,\n extension: string,\n name?: string,\n) {\n const file = await createZip(document);\n const fileName = name ?? document.header.name;\n const fileExtension = extension ? `.${extension}.phd` : \".phd\";\n\n return writeFileNode(\n path,\n fileName.endsWith(fileExtension) ? fileName : `${fileName}${fileExtension}`,\n file,\n );\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,cACd,MACA,MACA,MACiB;CACjB,MAAM,WAAW,KAAK,MAAM,IAAI;CAChC,GAAG,UAAU,MAAM,EAAE,WAAW,KAAK,CAAC;CAEtC,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI;GACF,GAAG,UAAU,UAAU,MAAM,CAAC,IAAI,QAAQ;IACxC,IAAI,KACF,OAAO,GAAG;SAEV,QAAQ,QAAQ;GAEpB,CAAC;EACH,SAAS,OAAgB;GACvB,IAAI,iBAAiB,OACnB,OAAO,KAAK;QAEZ,OAAO,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC;EAEnC;CACF,CAAC;AACH;AAEA,SAAgB,aAAa,MAAc;CACzC,OAAO,GAAG,aAAa,IAAI;AAC7B;AAEA,SAAgB,cACd,KACgD;CAChD,OAAO,IAAI,SAAS,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GAAG,KAAK,OAAO,iBACnB,IACF;AACF;;;;;;;;;;;;;AAcA,eAAsB,eACpB,UACA,MACA,WACA,MACA;CACA,MAAM,OAAO,MAAM,UAAU,QAAQ;CACrC,MAAM,WAAW,QAAQ,SAAS,OAAO;CACzC,MAAM,gBAAgB,YAAY,IAAI,UAAU,QAAQ;CAExD,OAAO,cACL,MACA,SAAS,SAAS,aAAa,IAAI,WAAW,GAAG,WAAW,iBAC5D,IACF;AACF"}
@@ -0,0 +1,39 @@
1
+ import { a as SCALAR_DEFINITION_VERSION, c as ScalarRepresentation, d as scalarDefinitionVersion, f as ScalarLiteralNode, i as DescribedScalarDefinition, l as ScalarValue, n as getCatalogScalar, o as ScalarCoercion, r as scalarCatalog, s as ScalarDefinition, t as documentModelScalars, u as isScalarDefinition } from "./catalog-B3nJD57s.js";
2
+ import { z } from "zod";
3
+ //#region src/scalars/representation.d.ts
4
+ type JsonRepresentation = Exclude<ScalarRepresentation, "opaque">;
5
+ //#endregion
6
+ //#region src/scalars/define-scalar.d.ts
7
+ type Json = string | number | boolean | null | Json[] | {
8
+ [key: string]: Json;
9
+ };
10
+ type OutputIsAny = {
11
+ "defineScalar refuses this schema: its output is any": never;
12
+ };
13
+ type AcceptsMissingValue = {
14
+ "defineScalar refuses this schema: it accepts a missing value; nullability belongs in the SDL": never;
15
+ };
16
+ type OutputCanBeNull = {
17
+ "defineScalar refuses this schema: its output can be null; nullability belongs in the SDL": never;
18
+ };
19
+ type OutputIsNotJson = {
20
+ "defineScalar refuses this schema: its output must be JSON": never;
21
+ };
22
+ type OutputFailsSchema = {
23
+ "defineScalar refuses this schema: its output must pass the schema again": never;
24
+ };
25
+ type TakesMissingValue<S extends z.ZodType> = S["_zod"]["optin"] extends "defaulted" ? true : S["_zod"]["optout"] extends "optional" ? true : unknown extends z.input<S> ? false : undefined extends z.input<S> ? true : false;
26
+ type CanonicalSchema<S extends z.ZodType> = 0 extends 1 & z.output<S> ? OutputIsAny : TakesMissingValue<S> extends true ? AcceptsMissingValue : z.output<S> extends Json ? null extends z.output<S> ? OutputCanBeNull : z.output<S> extends z.input<S> ? S : OutputFailsSchema : OutputIsNotJson;
27
+ type ScalarInput<TName extends string, S extends z.ZodType> = {
28
+ name: TName;
29
+ schema: S & CanonicalSchema<S>;
30
+ description?: string;
31
+ example?: NoInfer<z.input<S>>;
32
+ /** Only for a schema whose JSON shape zod cannot state, such as `z.custom`. */
33
+ representation?: JsonRepresentation;
34
+ };
35
+ export declare function defineScalar<TName extends string, S extends z.ZodType>(input: ScalarInput<TName, S>): DescribedScalarDefinition<TName, z.output<S>>;
36
+ //#endregion
37
+ export { type DescribedScalarDefinition, SCALAR_DEFINITION_VERSION, type ScalarCoercion, type ScalarDefinition, type ScalarLiteralNode, type ScalarRepresentation, type ScalarValue, documentModelScalars, getCatalogScalar, isScalarDefinition, scalarCatalog, scalarDefinitionVersion };
38
+ export {};
39
+ //# sourceMappingURL=scalars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalars.d.ts","names":[],"sources":["../src/scalars/representation.ts","../src/scalars/define-scalar.ts"],"mappings":";;;KAKY,qBAAqB,QAAQ;;;KCIpC,0CAA0C;GAAY,cAAc;;KAEpE;EACH;;KAEG;EACH;;KAEG;EACH;;KAEG;EACH;;KAEG;EACH;;KAMG,kBAAkB,UAAU,EAAE,WACjC,gDAEI,gEAEkB,EAAE,MAAM,+BAEJ,EAAE,MAAM;KAI/B,gBAAgB,UAAU,EAAE,yBAAyB,EAAE,OAAO,KAC/D,cACA,kBAAkB,kBAChB,sBACA,EAAE,OAAO,WAAW,oBACL,EAAE,OAAO,KACpB,kBACA,EAAE,OAAO,WAAW,EAAE,MAAM,KAC1B,IACA,oBACJ;KAEH,YAAY,sBAAsB,UAAU,EAAE;EACjD,MAAM;EACN,QAAQ,IAAI,gBAAgB;EAC5B;EACA,UAAU,QAAQ,EAAE,MAAM;;EAE1B,iBAAiB;;wBAwDH,aAAa,sBAAsB,UAAU,EAAE,SAC7D,OAAO,YAAY,OAAO,KACzB,0BAA0B,OAAO,EAAE,OAAO"}
@@ -0,0 +1,146 @@
1
+ import { a as SCALAR_DEFINITION_VERSION, i as defineCatalogScalar, n as getCatalogScalar, o as isScalarDefinition, r as scalarCatalog, s as scalarDefinitionVersion, t as documentModelScalars } from "./catalog-6zzASEUv.js";
2
+ import { z } from "zod";
3
+ //#region src/scalars/representation.ts
4
+ const shapeOfJsonType = {
5
+ null: "null",
6
+ string: "string",
7
+ number: "number",
8
+ integer: "number",
9
+ boolean: "boolean",
10
+ object: "json-object",
11
+ array: "json"
12
+ };
13
+ function shapeOfValue(value) {
14
+ if (value === null) return "null";
15
+ if (Array.isArray(value)) return "json";
16
+ if (typeof value === "object") return "json-object";
17
+ return shapeOfJsonType[typeof value];
18
+ }
19
+ /**
20
+ * The shapes a value of `node` can have, or `undefined` when zod states none.
21
+ * A union allows each branch's shapes; an intersection only those every
22
+ * stated member allows. `root` holds the `$defs` a local `$ref` names.
23
+ */
24
+ function jsonShapes(node, root, visiting = /* @__PURE__ */ new Set()) {
25
+ if (typeof node !== "object" || node === null || visiting.has(node)) return;
26
+ const inner = /* @__PURE__ */ new Set([...visiting, node]);
27
+ const record = node;
28
+ const { type, anyOf, oneOf, allOf } = record;
29
+ const stated = [];
30
+ const statedValues = (shapes) => {
31
+ if (!shapes.includes(void 0)) stated.push(new Set(shapes));
32
+ };
33
+ const not = record.not;
34
+ if (typeof not === "object" && not !== null && Object.keys(not).length === 0) stated.push(/* @__PURE__ */ new Set());
35
+ if (typeof type === "string" || Array.isArray(type)) statedValues([type].flat().map((name) => shapeOfJsonType[String(name)]));
36
+ if (Array.isArray(record.enum)) statedValues(record.enum.map(shapeOfValue));
37
+ if ("const" in record) statedValues([shapeOfValue(record.const)]);
38
+ const ref = record.$ref;
39
+ if (typeof ref === "string" && ref.startsWith("#/$defs/")) {
40
+ const defs = root.$defs;
41
+ const name = ref.slice(8).replaceAll("~1", "/").replaceAll("~0", "~");
42
+ const shapes = jsonShapes(defs?.[name], root, inner);
43
+ if (shapes) stated.push(shapes);
44
+ }
45
+ const branches = anyOf ?? oneOf;
46
+ if (Array.isArray(branches)) {
47
+ const shapes = branches.map((branch) => jsonShapes(branch, root, inner));
48
+ if (!shapes.includes(void 0)) stated.push(new Set(shapes.flatMap((set) => [...set ?? []])));
49
+ }
50
+ if (Array.isArray(allOf)) for (const member of allOf) {
51
+ const shapes = jsonShapes(member, root, inner);
52
+ if (shapes) stated.push(shapes);
53
+ }
54
+ if (stated.length === 0) return void 0;
55
+ const [first, ...rest] = stated;
56
+ return new Set([...first].filter((shape) => rest.every((set) => set.has(shape))));
57
+ }
58
+ /**
59
+ * The representation zod states for every output value of `schema`, or
60
+ * `undefined` when it cannot state one. One shape is that representation;
61
+ * several are `json`.
62
+ */
63
+ function statedRepresentation(schema) {
64
+ const jsonSchema = outputJsonSchema(schema);
65
+ const stated = jsonShapes(jsonSchema, jsonSchema);
66
+ if (stated === void 0) return void 0;
67
+ const shapes = [...stated].filter((shape) => shape !== "null");
68
+ if (shapes.length === 0) return void 0;
69
+ const [only, ...rest] = shapes;
70
+ return rest.length === 0 ? only : "json";
71
+ }
72
+ function outputJsonSchema(schema) {
73
+ try {
74
+ return z.toJSONSchema(schema, {
75
+ io: "output",
76
+ unrepresentable: "any"
77
+ });
78
+ } catch {
79
+ return {};
80
+ }
81
+ }
82
+ //#endregion
83
+ //#region src/scalars/define-scalar.ts
84
+ const inputKeys = /* @__PURE__ */ new Set([
85
+ "name",
86
+ "schema",
87
+ "description",
88
+ "example",
89
+ "representation"
90
+ ]);
91
+ const jsonRepresentations = /* @__PURE__ */ new Set([
92
+ "string",
93
+ "number",
94
+ "boolean",
95
+ "json-object",
96
+ "json"
97
+ ]);
98
+ const graphqlBuiltIns = /* @__PURE__ */ new Set([
99
+ "Int",
100
+ "Float",
101
+ "String",
102
+ "Boolean",
103
+ "ID"
104
+ ]);
105
+ const catalogNames = new Set(scalarCatalog.map((definition) => definition.name));
106
+ const graphqlName = /^[_A-Za-z][_0-9A-Za-z]*$/;
107
+ const refusals = [
108
+ (input) => {
109
+ const unknownKeys = Object.keys(input).filter((key) => !inputKeys.has(key));
110
+ return unknownKeys.length > 0 ? `unknown input key ${unknownKeys.join(", ")}; defineScalar accepts only name, schema, description, example and representation` : void 0;
111
+ },
112
+ ({ name }) => typeof name !== "string" || !graphqlName.test(name) || name.startsWith("__") ? "the name is not a valid GraphQL name" : void 0,
113
+ ({ name }) => graphqlBuiltIns.has(name) ? "the name is a GraphQL built-in scalar" : void 0,
114
+ ({ name }) => catalogNames.has(name) ? "the name is a catalog scalar" : void 0,
115
+ ({ schema }) => schema._zod.optin === "defaulted" || schema._zod.optout === "optional" ? "the schema accepts a missing value; nullability belongs in the SDL" : void 0
116
+ ];
117
+ function defineScalar(input) {
118
+ for (const refusal of refusals) {
119
+ const reason = refusal(input);
120
+ if (reason !== void 0) throw new Error(`Cannot define scalar "${String(input.name)}": ${reason}.`);
121
+ }
122
+ const { example, representation, ...definition } = input;
123
+ const schema = input.schema;
124
+ const parsedExample = example === void 0 ? void 0 : schema.safeParse(example);
125
+ if (parsedExample?.success === false) throw new Error(`Cannot define scalar "${input.name}": the example fails the schema: ${z.prettifyError(parsedExample.error)}`);
126
+ return defineCatalogScalar({
127
+ ...definition,
128
+ schema,
129
+ ...parsedExample && { example: parsedExample.data },
130
+ typescriptType: null,
131
+ zodSource: null,
132
+ representation: scalarRepresentation(input.name, schema, representation)
133
+ });
134
+ }
135
+ function scalarRepresentation(name, schema, declared) {
136
+ const derived = statedRepresentation(schema);
137
+ if (declared === void 0) return derived ?? "json";
138
+ if (!jsonRepresentations.has(declared)) throw new Error(`Cannot define scalar "${name}": representation must be one of ${[...jsonRepresentations].join(", ")}.`);
139
+ const representation = declared;
140
+ if (derived !== void 0 && derived !== representation) throw new Error(`Cannot define scalar "${name}": the schema's values are ${derived}, so representation cannot be ${representation}.`);
141
+ return representation;
142
+ }
143
+ //#endregion
144
+ export { SCALAR_DEFINITION_VERSION, defineScalar, documentModelScalars, getCatalogScalar, isScalarDefinition, scalarCatalog, scalarDefinitionVersion };
145
+
146
+ //# sourceMappingURL=scalars.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalars.js","names":[],"sources":["../src/scalars/representation.ts","../src/scalars/define-scalar.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { ScalarRepresentation } from \"./types.js\";\n\n// defineScalar refuses a schema whose output is not JSON, so a package\n// scalar's values are never opaque.\nexport type JsonRepresentation = Exclude<ScalarRepresentation, \"opaque\">;\n\n// \"null\" is tracked through intersections and dropped before deciding: the\n// SDL owns nullability, so a null value never decides a representation.\ntype JsonShape = JsonRepresentation | \"null\";\n\nconst shapeOfJsonType: Readonly<Record<string, JsonShape | undefined>> = {\n null: \"null\",\n string: \"string\",\n number: \"number\",\n integer: \"number\",\n boolean: \"boolean\",\n object: \"json-object\",\n array: \"json\",\n};\n\nfunction shapeOfValue(value: unknown): JsonShape | undefined {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"json\";\n if (typeof value === \"object\") return \"json-object\";\n return shapeOfJsonType[typeof value];\n}\n\n/**\n * The shapes a value of `node` can have, or `undefined` when zod states none.\n * A union allows each branch's shapes; an intersection only those every\n * stated member allows. `root` holds the `$defs` a local `$ref` names.\n */\nfunction jsonShapes(\n node: unknown,\n root: Readonly<Record<string, unknown>>,\n visiting: ReadonlySet<unknown> = new Set(),\n): ReadonlySet<JsonShape> | undefined {\n if (typeof node !== \"object\" || node === null || visiting.has(node)) {\n return undefined;\n }\n const inner = new Set([...visiting, node]);\n const record = node as Record<string, unknown>;\n const { type, anyOf, oneOf, allOf } = record;\n const stated: ReadonlySet<JsonShape>[] = [];\n const statedValues = (shapes: (JsonShape | undefined)[]) => {\n if (!shapes.includes(undefined)) {\n stated.push(new Set(shapes as JsonShape[]));\n }\n };\n // zod writes z.never() as { not: {} }, which no value matches.\n const not = record.not;\n if (\n typeof not === \"object\" &&\n not !== null &&\n Object.keys(not).length === 0\n ) {\n stated.push(new Set());\n }\n if (typeof type === \"string\" || Array.isArray(type)) {\n statedValues([type].flat().map((name) => shapeOfJsonType[String(name)]));\n }\n if (Array.isArray(record.enum)) statedValues(record.enum.map(shapeOfValue));\n if (\"const\" in record) statedValues([shapeOfValue(record.const)]);\n const ref = record.$ref;\n if (typeof ref === \"string\" && ref.startsWith(\"#/$defs/\")) {\n const defs = root.$defs as Record<string, unknown> | undefined;\n // A JSON Pointer token escapes \"~\" as \"~0\" and \"/\" as \"~1\".\n const name = ref\n .slice(\"#/$defs/\".length)\n .replaceAll(\"~1\", \"/\")\n .replaceAll(\"~0\", \"~\");\n const shapes = jsonShapes(defs?.[name], root, inner);\n if (shapes) stated.push(shapes);\n }\n const branches = anyOf ?? oneOf;\n if (Array.isArray(branches)) {\n const shapes = branches.map((branch) => jsonShapes(branch, root, inner));\n if (!shapes.includes(undefined)) {\n stated.push(new Set(shapes.flatMap((set) => [...(set ?? [])])));\n }\n }\n if (Array.isArray(allOf)) {\n for (const member of allOf) {\n const shapes = jsonShapes(member, root, inner);\n if (shapes) stated.push(shapes);\n }\n }\n if (stated.length === 0) return undefined;\n const [first, ...rest] = stated;\n return new Set(\n [...first].filter((shape) => rest.every((set) => set.has(shape))),\n );\n}\n\n/**\n * The representation zod states for every output value of `schema`, or\n * `undefined` when it cannot state one. One shape is that representation;\n * several are `json`.\n */\nexport function statedRepresentation(\n schema: z.ZodType,\n): JsonRepresentation | undefined {\n const jsonSchema = outputJsonSchema(schema);\n const stated = jsonShapes(jsonSchema, jsonSchema);\n if (stated === undefined) return undefined;\n const shapes = [...stated].filter((shape) => shape !== \"null\");\n if (shapes.length === 0) return undefined;\n const [only, ...rest] = shapes;\n return rest.length === 0 ? only : \"json\";\n}\n\nfunction outputJsonSchema(schema: z.ZodType): Record<string, unknown> {\n try {\n return z.toJSONSchema(schema, { io: \"output\", unrepresentable: \"any\" });\n } catch {\n return {};\n }\n}\n","import { z } from \"zod\";\nimport { scalarCatalog } from \"./catalog.js\";\nimport { defineCatalogScalar } from \"./define-catalog-scalar.js\";\nimport {\n type JsonRepresentation,\n statedRepresentation,\n} from \"./representation.js\";\nimport type { DescribedScalarDefinition } from \"./types.js\";\n\ntype Json = string | number | boolean | null | Json[] | { [key: string]: Json };\n\ntype OutputIsAny = {\n \"defineScalar refuses this schema: its output is any\": never;\n};\ntype AcceptsMissingValue = {\n \"defineScalar refuses this schema: it accepts a missing value; nullability belongs in the SDL\": never;\n};\ntype OutputCanBeNull = {\n \"defineScalar refuses this schema: its output can be null; nullability belongs in the SDL\": never;\n};\ntype OutputIsNotJson = {\n \"defineScalar refuses this schema: its output must be JSON\": never;\n};\ntype OutputFailsSchema = {\n \"defineScalar refuses this schema: its output must pass the schema again\": never;\n};\n\n// zod marks .default() and .prefault() with optin \"defaulted\" and .optional()\n// and .nullish() with optout \"optional\". z.coerce and z.preprocess take\n// `unknown`, which includes undefined, so for them only the markers count.\ntype TakesMissingValue<S extends z.ZodType> =\n S[\"_zod\"][\"optin\"] extends \"defaulted\"\n ? true\n : S[\"_zod\"][\"optout\"] extends \"optional\"\n ? true\n : unknown extends z.input<S>\n ? false\n : undefined extends z.input<S>\n ? true\n : false;\n\ntype CanonicalSchema<S extends z.ZodType> = 0 extends 1 & z.output<S>\n ? OutputIsAny\n : TakesMissingValue<S> extends true\n ? AcceptsMissingValue\n : z.output<S> extends Json\n ? null extends z.output<S>\n ? OutputCanBeNull\n : z.output<S> extends z.input<S>\n ? S\n : OutputFailsSchema\n : OutputIsNotJson;\n\ntype ScalarInput<TName extends string, S extends z.ZodType> = {\n name: TName;\n schema: S & CanonicalSchema<S>;\n description?: string;\n example?: NoInfer<z.input<S>>;\n /** Only for a schema whose JSON shape zod cannot state, such as `z.custom`. */\n representation?: JsonRepresentation;\n};\n\nconst inputKeys = new Set([\n \"name\",\n \"schema\",\n \"description\",\n \"example\",\n \"representation\",\n]);\nconst jsonRepresentations: ReadonlySet<unknown> = new Set<JsonRepresentation>([\n \"string\",\n \"number\",\n \"boolean\",\n \"json-object\",\n \"json\",\n]);\nconst graphqlBuiltIns: ReadonlySet<unknown> = new Set([\n \"Int\",\n \"Float\",\n \"String\",\n \"Boolean\",\n \"ID\",\n]);\nconst catalogNames: ReadonlySet<unknown> = new Set(\n scalarCatalog.map((definition) => definition.name),\n);\nconst graphqlName = /^[_A-Za-z][_0-9A-Za-z]*$/;\n\ntype Refusal = (\n input: Readonly<Record<string, unknown>> & { readonly schema: z.ZodType },\n) => string | undefined;\n\nconst refusals: readonly Refusal[] = [\n (input) => {\n const unknownKeys = Object.keys(input).filter((key) => !inputKeys.has(key));\n return unknownKeys.length > 0\n ? `unknown input key ${unknownKeys.join(\", \")}; defineScalar accepts only name, schema, description, example and representation`\n : undefined;\n },\n ({ name }) =>\n typeof name !== \"string\" || !graphqlName.test(name) || name.startsWith(\"__\")\n ? \"the name is not a valid GraphQL name\"\n : undefined,\n ({ name }) =>\n graphqlBuiltIns.has(name)\n ? \"the name is a GraphQL built-in scalar\"\n : undefined,\n ({ name }) =>\n catalogNames.has(name) ? \"the name is a catalog scalar\" : undefined,\n ({ schema }) =>\n schema._zod.optin === \"defaulted\" || schema._zod.optout === \"optional\"\n ? \"the schema accepts a missing value; nullability belongs in the SDL\"\n : undefined,\n];\n\nexport function defineScalar<TName extends string, S extends z.ZodType>(\n input: ScalarInput<TName, S>,\n): DescribedScalarDefinition<TName, z.output<S>> {\n for (const refusal of refusals) {\n const reason = refusal(input);\n if (reason !== undefined) {\n throw new Error(\n `Cannot define scalar \"${String(input.name)}\": ${reason}.`,\n );\n }\n }\n const { example, representation, ...definition } = input;\n // TypeScript cannot relate a generic S to its own z.output<S>.\n const schema = input.schema as z.ZodType<z.output<S>>;\n const parsedExample =\n example === undefined ? undefined : schema.safeParse(example);\n if (parsedExample?.success === false) {\n throw new Error(\n `Cannot define scalar \"${input.name}\": the example fails the schema: ${z.prettifyError(parsedExample.error)}`,\n );\n }\n return defineCatalogScalar({\n ...definition,\n schema,\n ...(parsedExample && { example: parsedExample.data }),\n typescriptType: null,\n zodSource: null,\n representation: scalarRepresentation(input.name, schema, representation),\n });\n}\n\nfunction scalarRepresentation(\n name: string,\n schema: z.ZodType,\n declared: unknown,\n): JsonRepresentation {\n const derived = statedRepresentation(schema);\n if (declared === undefined) return derived ?? \"json\";\n if (!jsonRepresentations.has(declared)) {\n throw new Error(\n `Cannot define scalar \"${name}\": representation must be one of ${[...jsonRepresentations].join(\", \")}.`,\n );\n }\n const representation = declared as JsonRepresentation;\n if (derived !== undefined && derived !== representation) {\n throw new Error(\n `Cannot define scalar \"${name}\": the schema's values are ${derived}, so representation cannot be ${representation}.`,\n );\n }\n return representation;\n}\n"],"mappings":";;;AAWA,MAAM,kBAAmE;CACvE,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,SAAS;CACT,QAAQ;CACR,OAAO;AACT;AAEA,SAAS,aAAa,OAAuC;CAC3D,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO;CACjC,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,gBAAgB,OAAO;AAChC;;;;;;AAOA,SAAS,WACP,MACA,MACA,2BAAiC,IAAI,IAAI,GACL;CACpC,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,SAAS,IAAI,IAAI,GAChE;CAEF,MAAM,wBAAQ,IAAI,IAAI,CAAC,GAAG,UAAU,IAAI,CAAC;CACzC,MAAM,SAAS;CACf,MAAM,EAAE,MAAM,OAAO,OAAO,UAAU;CACtC,MAAM,SAAmC,CAAC;CAC1C,MAAM,gBAAgB,WAAsC;EAC1D,IAAI,CAAC,OAAO,SAAS,KAAA,CAAS,GAC5B,OAAO,KAAK,IAAI,IAAI,MAAqB,CAAC;CAE9C;CAEA,MAAM,MAAM,OAAO;CACnB,IACE,OAAO,QAAQ,YACf,QAAQ,QACR,OAAO,KAAK,GAAG,CAAC,CAAC,WAAW,GAE5B,OAAO,qBAAK,IAAI,IAAI,CAAC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O,KAAK,WAAW,aACxD,uEACA,KAAA;AACR;AAEA,SAAgB,aACd,OAC+C;CAC/C,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,SAAS,QAAQ,KAAK;EAC5B,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MACR,yBAAyB,OAAO,MAAM,IAAI,EAAE,KAAK,OAAO,EAC1D;CAEJ;CACA,MAAM,EAAE,SAAS,gBAAgB,GAAG,eAAe;CAEnD,MAAM,SAAS,MAAM;CACrB,MAAM,gBACJ,YAAY,KAAA,IAAY,KAAA,IAAY,OAAO,UAAU,OAAO;CAC9D,IAAI,eAAe,YAAY,OAC7B,MAAM,IAAI,MACR,yBAAyB,MAAM,KAAK,mCAAmC,EAAE,cAAc,cAAc,KAAK,GAC5G;CAEF,OAAO,oBAAoB;EACzB,GAAG;EACH;EACA,GAAI,iBAAiB,EAAE,SAAS,cAAc,KAAK;EACnD,gBAAgB;EAChB,WAAW;EACX,gBAAgB,qBAAqB,MAAM,MAAM,QAAQ,cAAc;CACzE,CAAC;AACH;AAEA,SAAS,qBACP,MACA,QACA,UACoB;CACpB,MAAM,UAAU,qBAAqB,MAAM;CAC3C,IAAI,aAAa,KAAA,GAAW,OAAO,WAAW;CAC9C,IAAI,CAAC,oBAAoB,IAAI,QAAQ,GACnC,MAAM,IAAI,MACR,yBAAyB,KAAK,mCAAmC,CAAC,GAAG,mBAAmB,CAAC,CAAC,KAAK,IAAI,EAAE,EACvG;CAEF,MAAM,iBAAiB;CACvB,IAAI,YAAY,KAAA,KAAa,YAAY,gBACvC,MAAM,IAAI,MACR,yBAAyB,KAAK,6BAA6B,QAAQ,gCAAgC,eAAe,EACpH;CAEF,OAAO;AACT"}
@@ -0,0 +1,121 @@
1
+ import { DefinitionCheckReport, DefinitionCheckSkipReason, DefinitionDiagnostic, DefinitionPath, DefinitionSource, DocumentModelDefinition, DocumentModelModule, DocumentModelPHState, Sha256Digest, UpgradeManifest } from "@powerhousedao/shared/document-model";
2
+ //#region src/definition/kernel/diagnostics.d.ts
3
+ /** @experimental One line: code, severity and phase, location, message, expected, received, related and repair. */
4
+ export declare function formatDefinitionDiagnostic(diagnostic: DefinitionDiagnostic): string;
5
+ //#endregion
6
+ //#region src/definition/tooling/adapters/types.d.ts
7
+ /**
8
+ * @experimental The shape both authoring paths normalize into. A consumer
9
+ * reads it without learning which adapter produced it.
10
+ */
11
+ type NormalizedDocumentModelArtifact = {
12
+ readonly kind: "powerhouse.document-model-artifact";
13
+ readonly source: DefinitionSource;
14
+ readonly documentType: string;
15
+ readonly version: number;
16
+ readonly definition: DocumentModelDefinition;
17
+ readonly digest: Sha256Digest;
18
+ readonly documentModel: DocumentModelPHState;
19
+ };
20
+ /** @experimental */
21
+ type NormalizedDocumentModelResult = {
22
+ readonly artifacts: readonly NormalizedDocumentModelArtifact[];
23
+ readonly upgradeManifest: UpgradeManifest<readonly number[]> | null;
24
+ readonly diagnostics: readonly DefinitionDiagnostic[];
25
+ };
26
+ //#endregion
27
+ //#region src/definition/tooling/adapters/code-first-document-model-source-adapter.d.ts
28
+ /**
29
+ * @experimental Normalizes one materialized code-first module, or a family
30
+ * and its versions in order. A family reports every malformed member: a
31
+ * valid sibling never makes a broken one pass.
32
+ */
33
+ export declare function adaptCodeFirstDocumentModelSource(value: unknown, source: DefinitionSource): NormalizedDocumentModelResult;
34
+ //#endregion
35
+ //#region src/definition/tooling/definition-source-types.d.ts
36
+ /**
37
+ * @experimental The selected sources, exactly as a definition report carries
38
+ * them. Defined from the stored report type so the two cannot disagree.
39
+ */
40
+ type DefinitionSourceSet = DefinitionCheckReport["sourceSet"];
41
+ /** @experimental Where the selected source list came from. */
42
+ type DefinitionSourceOrigin = DefinitionSourceSet["origin"];
43
+ /**
44
+ * @experimental The loader's one substitutable dependency: something that
45
+ * turns a package-relative TypeScript path into a module namespace. Codegen
46
+ * supplies a Vite environment; a build can supply its own module graph.
47
+ */
48
+ interface TypeScriptSourceImportInterface {
49
+ importModule(request: {
50
+ readonly packageRoot: string;
51
+ readonly specifier: `./${string}`;
52
+ readonly packageRevision: Sha256Digest;
53
+ readonly signal?: AbortSignal;
54
+ }): Promise<Readonly<Record<string, unknown>>>;
55
+ disposeRevision?(packageRevision?: Sha256Digest): Promise<void> | void;
56
+ }
57
+ /** @experimental */
58
+ type DefinitionSourceSelectionRequest = {
59
+ readonly configFile?: string;
60
+ readonly allowMissingConfig?: boolean;
61
+ };
62
+ /** @experimental */
63
+ type DefinitionSourceLoadRequest = DefinitionSourceSelectionRequest & {
64
+ /**
65
+ * Binds the imported bytes this load may reuse. A definition digest is not
66
+ * enough: editing a reducer helper leaves every definition digest unchanged.
67
+ */
68
+ readonly packageRevision: Sha256Digest;
69
+ readonly signal?: AbortSignal;
70
+ };
71
+ /** @experimental A selection, resolved without importing anything. */
72
+ type DefinitionSourceResolution = {
73
+ readonly packageRoot: string;
74
+ readonly sourceSet: DefinitionSourceSet;
75
+ readonly diagnostics: readonly DefinitionDiagnostic[];
76
+ } & ({
77
+ readonly status: "ready" | "failed";
78
+ readonly skipReason?: never;
79
+ } | {
80
+ readonly status: "skipped";
81
+ readonly skipReason: DefinitionCheckSkipReason;
82
+ });
83
+ /** @experimental One value the traversal recognized, and where it was found. */
84
+ type LoadedDefinition<TValue> = {
85
+ readonly source: DefinitionSource;
86
+ readonly path: DefinitionPath;
87
+ readonly value: TValue;
88
+ };
89
+ /** @experimental */
90
+ type LoadedDefinitionSet = DefinitionSourceResolution & {
91
+ readonly documentModels: readonly LoadedDefinition<DocumentModelModule>[];
92
+ readonly upgradeManifests: readonly LoadedDefinition<UpgradeManifest<readonly number[]>>[];
93
+ };
94
+ //#endregion
95
+ //#region src/definition/tooling/definition-source-loader.d.ts
96
+ /**
97
+ * @experimental Imports the selected definition sources and finds the
98
+ * materialized document models, families and upgrade manifests they export.
99
+ * It folds aliases, reports two values that claim one `documentType@version`,
100
+ * and returns everything sorted by source, so neither config order nor
101
+ * import completion order changes a result. Validity belongs to the
102
+ * adapters; registration belongs to the host.
103
+ */
104
+ export declare class DefinitionSourceLoader {
105
+ #private;
106
+ constructor(importer: TypeScriptSourceImportInterface);
107
+ resolve(request: DefinitionSourceSelectionRequest): DefinitionSourceResolution;
108
+ normalizeDefinitionSources(request: DefinitionSourceLoadRequest): Promise<LoadedDefinitionSet>;
109
+ dispose(): Promise<void>;
110
+ }
111
+ //#endregion
112
+ //#region src/definition/tooling/definition-source-resolution.d.ts
113
+ /**
114
+ * @experimental The selection a command would load, resolved without
115
+ * importing anything and without any machine-specific path but the root.
116
+ */
117
+ export declare function resolveDefinitionSelection(request: DefinitionSourceSelectionRequest): DefinitionSourceResolution;
118
+ //#endregion
119
+ export type { DefinitionSourceLoadRequest, DefinitionSourceOrigin, DefinitionSourceResolution, DefinitionSourceSelectionRequest, DefinitionSourceSet, LoadedDefinition, LoadedDefinitionSet, NormalizedDocumentModelArtifact, NormalizedDocumentModelResult, TypeScriptSourceImportInterface };
120
+ export {};
121
+ //# sourceMappingURL=tooling.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooling.d.mts","names":[],"sources":["../src/definition/kernel/diagnostics.ts","../src/definition/tooling/adapters/types.ts","../src/definition/tooling/adapters/code-first-document-model-source-adapter.ts","../src/definition/tooling/definition-source-types.ts","../src/definition/tooling/definition-source-loader.ts","../src/definition/tooling/definition-source-resolution.ts"],"mappings":";;;wBAuQgB,2BACd,YAAY;;;;;;;KC3PF;WACD;WACA,QAAQ;WACR;WAEA;WAEA,YAAY;WAEZ,QAAQ;WAER,eAAe;;;KAId;WACD,oBAAoB;WAEpB,iBAAiB;WACjB,sBAAsB;;;;;;;;;wBC2NjB,kCACd,gBACA,QAAQ,mBACP;;;;;;;KC/OS,sBAAsB;;KAGtB,yBAAyB;;;;;;UAOpB;EACf,aAAa;aACF;aACA;aACA,iBAAiB;aACjB,SAAS;MAChB,QAAQ,SAAS;EAErB,iBAAiB,kBAAkB,eAAe;;;KAIxC;WACD;WAEA;;;KAIC,8BAA8B;;;;;WAK/B,iBAAiB;WACjB,SAAS;;;KAIR;WACD;WACA,WAAW;WACX,sBAAsB;;WAElB;WAAqC;;WAErC;WACA,YAAY;;;KAKf,iBAAiB;WAClB,QAAQ;WAER,MAAM;WACN,OAAO;;;KAIN,sBAAsB;WACvB,yBAAyB,iBAAiB;WAC1C,2BAA2B,iBAClC;;;;;;;;;;;;qBC+ZS;;EAQX,YAAY,UAAU;EAItB,QACE,SAAS,mCACR;EAIG,2BACJ,SAAS,8BACR,QAAQ;EAmFL,WAAW;;;;;;;;wBCvDH,2BACd,SAAS,mCACR"}