@powerhousedao/reactor-api 6.2.3-dev.55 → 6.2.3-dev.56

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 (30) hide show
  1. package/dist/{adapter-gateway-apollo-D2DNlPY0.mjs → adapter-gateway-apollo-DTcAJpfN.mjs} +3 -3
  2. package/dist/{adapter-gateway-apollo-B54G_cXT.mjs → adapter-gateway-apollo-DwAmdCYz.mjs} +5 -5
  3. package/dist/{adapter-gateway-apollo-B54G_cXT.mjs.map → adapter-gateway-apollo-DwAmdCYz.mjs.map} +1 -1
  4. package/dist/adapter-gateway-stitching-969ZPot-.mjs +4 -0
  5. package/dist/{adapter-gateway-stitching-Dzv10u8D.mjs → adapter-gateway-stitching-ClVkjojb.mjs} +20 -8
  6. package/dist/adapter-gateway-stitching-ClVkjojb.mjs.map +1 -0
  7. package/dist/base-document-models-69WRTSfH.mjs +1243 -0
  8. package/dist/base-document-models-69WRTSfH.mjs.map +1 -0
  9. package/dist/create-schema-DLTPkNpK.d.mts +138 -0
  10. package/dist/create-schema-DLTPkNpK.d.mts.map +1 -0
  11. package/dist/index.d.mts +46 -99
  12. package/dist/index.d.mts.map +1 -1
  13. package/dist/index.mjs +526 -1180
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/src/graphql/subgraph-types.d.mts +37 -0
  16. package/dist/src/graphql/subgraph-types.d.mts.map +1 -0
  17. package/dist/src/graphql/subgraph-types.mjs +105 -0
  18. package/dist/src/graphql/subgraph-types.mjs.map +1 -0
  19. package/dist/src/packages/vite-loader.d.mts +3 -2
  20. package/dist/src/packages/vite-loader.d.mts.map +1 -1
  21. package/dist/src/packages/vite-loader.mjs +20 -22
  22. package/dist/src/packages/vite-loader.mjs.map +1 -1
  23. package/dist/{subgraph-extraction-sQlZLLPH.mjs → subgraph-extraction-CPtTeQAT.mjs} +44 -10
  24. package/dist/subgraph-extraction-CPtTeQAT.mjs.map +1 -0
  25. package/dist/{types-DlTiz6AA.d.mts → types-D3pD6fvQ.d.mts} +15 -3
  26. package/dist/types-D3pD6fvQ.d.mts.map +1 -0
  27. package/package.json +18 -13
  28. package/dist/adapter-gateway-stitching-Dzv10u8D.mjs.map +0 -1
  29. package/dist/subgraph-extraction-sQlZLLPH.mjs.map +0 -1
  30. package/dist/types-DlTiz6AA.d.mts.map +0 -1
@@ -0,0 +1,37 @@
1
+ import { C as reservedTypeNames, a as ReservedTypeNames } from "../../create-schema-DLTPkNpK.mjs";
2
+ import { DocumentNode } from "graphql";
3
+ import { DocumentModelGlobalState } from "@powerhousedao/shared/document-model";
4
+ //#region src/graphql/subgraph-type-ownership.d.ts
5
+ type OwnershipConflict = {
6
+ claim: string;
7
+ owner: string;
8
+ };
9
+ //#endregion
10
+ //#region src/graphql/subgraph-types.d.ts
11
+ /** Owner of the types every generated document-model schema carries. */
12
+ export declare const DOCUMENT_MODEL_SCHEMA_OWNER = "document-model schema";
13
+ /** The type definitions of every core subgraph, by subgraph name. */
14
+ export declare const coreSubgraphTypeDefs: ReadonlyMap<string, DocumentNode>;
15
+ /** A package's own subgraph, in the order the package exports it. */
16
+ export type PackageSubgraph = {
17
+ name: string;
18
+ typeDefs: DocumentNode;
19
+ };
20
+ export type PackageSubgraphConflicts = {
21
+ /** Set when the server refuses the subgraph's name. */
22
+ nameHeldBy?: "core" | "document model";
23
+ /** Types and root fields the subgraph loses. */
24
+ claims: OwnershipConflict[];
25
+ };
26
+ export type PackageSubgraphReport = {
27
+ /** By subgraph name; subgraphs without a conflict are left out. */
28
+ conflicts: Map<string, PackageSubgraphConflicts>;
29
+ /** Models whose schema does not generate, left out of the check. */
30
+ skippedModels: string[];
31
+ };
32
+ /** Package subgraphs the server refuses or excludes; host subgraphs unchecked. */
33
+ export declare function findPackageSubgraphConflicts(subgraphs: readonly PackageSubgraph[], documentModels: readonly DocumentModelGlobalState[]): PackageSubgraphReport;
34
+ //#endregion
35
+ export { type OwnershipConflict, type ReservedTypeNames, reservedTypeNames };
36
+ export {};
37
+ //# sourceMappingURL=subgraph-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph-types.d.mts","names":[],"sources":["../../../src/graphql/subgraph-type-ownership.ts","../../../src/graphql/subgraph-types.ts"],"mappings":";;;;KAqJY;EAAsB;EAAe;;;;;qBCvHpC;;qBAGA,sBAAsB,oBAAoB;;YAS3C;EAAoB;EAAc,UAAU;;YAE5C;;EAEV;;EAEA,QAAQ;;YAGE;;EAEV,WAAW,YAAY;;EAEvB;;;wBAec,6BACd,oBAAoB,mBACpB,yBAAyB,6BACxB"}
@@ -0,0 +1,105 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b8e7b48c-09ef-5ac8-b3ea-6beffcac4f22")}catch(e){}}();
3
+ import { C as hasOperationSchemas, D as schema_default$1, a as collectSubgraphClaims, b as getDocumentModelSubgraphName, g as findSubgraphTypeCollisions, h as documentModelSubgraphTypes, i as inspectionTypeDefs, n as systemTypeDefs, r as schema_default, s as resolveClaimOwnership, t as baseDocumentModels, v as generatedTypesOf, w as reservedTypeNames } from "../../base-document-models-69WRTSfH.mjs";
4
+ import { typedefs } from "@powerhousedao/analytics-engine-graphql";
5
+ import { gql } from "graphql-tag";
6
+ //#region src/graphql/subgraph-types.ts
7
+ /** Owner of the types every generated document-model schema carries. */
8
+ const DOCUMENT_MODEL_SCHEMA_OWNER = "document-model schema";
9
+ /** The type definitions of every core subgraph, by subgraph name. */
10
+ const coreSubgraphTypeDefs = /* @__PURE__ */ new Map([
11
+ ["analytics", gql(typedefs)],
12
+ ["system", systemTypeDefs],
13
+ ["r", gql(schema_default)],
14
+ ["inspection", inspectionTypeDefs],
15
+ ["auth", gql(schema_default$1)]
16
+ ]);
17
+ function claimsOf(typeDefs, generated) {
18
+ try {
19
+ return collectSubgraphClaims(typeDefs, generated);
20
+ } catch {
21
+ return /* @__PURE__ */ new Map();
22
+ }
23
+ }
24
+ /** Package subgraphs the server refuses or excludes; host subgraphs unchecked. */
25
+ function findPackageSubgraphConflicts(subgraphs, documentModels) {
26
+ const models = [];
27
+ const modelSubgraphs = [];
28
+ const skippedModels = [];
29
+ const allModels = [...baseDocumentModels.map(([, model]) => model.documentModel.global), ...documentModels];
30
+ for (const model of allModels) {
31
+ let typeDefs;
32
+ try {
33
+ generatedTypesOf([model]);
34
+ if (hasOperationSchemas(model)) typeDefs = documentModelSubgraphTypes(model).typeDefs;
35
+ } catch {
36
+ skippedModels.push(model.name);
37
+ continue;
38
+ }
39
+ models.push(model);
40
+ const name = getDocumentModelSubgraphName(model);
41
+ if (typeDefs && !modelSubgraphs.some((owner) => owner.name === name)) modelSubgraphs.push({
42
+ name,
43
+ typeDefs
44
+ });
45
+ }
46
+ const generated = generatedTypesOf(models);
47
+ const fixed = generatedTypesOf([]).names;
48
+ const generatedOwners = /* @__PURE__ */ new Map();
49
+ for (const model of models) for (const name of generatedTypesOf([model]).names) if (!fixed.has(name)) generatedOwners.set(name, getDocumentModelSubgraphName(model));
50
+ const conflicts = /* @__PURE__ */ new Map();
51
+ const admitted = [];
52
+ for (const subgraph of subgraphs) {
53
+ if (coreSubgraphTypeDefs.has(subgraph.name)) {
54
+ conflicts.set(subgraph.name, {
55
+ nameHeldBy: "core",
56
+ claims: []
57
+ });
58
+ continue;
59
+ }
60
+ if (modelSubgraphs.some((owner) => owner.name === subgraph.name)) {
61
+ conflicts.set(subgraph.name, {
62
+ nameHeldBy: "document model",
63
+ claims: []
64
+ });
65
+ continue;
66
+ }
67
+ let collisions;
68
+ try {
69
+ collisions = findSubgraphTypeCollisions(generated, subgraph.typeDefs);
70
+ } catch {
71
+ collisions = [];
72
+ }
73
+ if (collisions.length > 0) {
74
+ conflicts.set(subgraph.name, { claims: collisions.map((claim) => ({
75
+ claim,
76
+ owner: generatedOwners.get(claim) ?? "document-model schema"
77
+ })) });
78
+ continue;
79
+ }
80
+ admitted.push(subgraph);
81
+ }
82
+ const packageNames = new Set(admitted.map(({ name }) => name));
83
+ const excluded = resolveClaimOwnership([
84
+ ...Array.from(coreSubgraphTypeDefs, ([name, typeDefs]) => ({
85
+ name,
86
+ typeDefs
87
+ })),
88
+ ...modelSubgraphs,
89
+ ...admitted
90
+ ].map(({ name, typeDefs }) => ({
91
+ candidate: name,
92
+ name,
93
+ claims: claimsOf(typeDefs, generated.names)
94
+ })));
95
+ for (const [name, claims] of excluded) if (packageNames.has(name)) conflicts.set(name, { claims });
96
+ return {
97
+ conflicts,
98
+ skippedModels
99
+ };
100
+ }
101
+ //#endregion
102
+ export { DOCUMENT_MODEL_SCHEMA_OWNER, coreSubgraphTypeDefs, findPackageSubgraphConflicts, reservedTypeNames };
103
+
104
+ //# sourceMappingURL=subgraph-types.mjs.map
105
+ //# debugId=b8e7b48c-09ef-5ac8-b3ea-6beffcac4f22
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph-types.mjs","sources":["../../../src/graphql/subgraph-types.ts"],"sourcesContent":["import { typedefs as analyticsTypeDefs } from \"@powerhousedao/analytics-engine-graphql\";\nimport type { DocumentModelGlobalState } from \"@powerhousedao/shared/document-model\";\nimport type { DocumentNode } from \"graphql\";\nimport { gql } from \"graphql-tag\";\nimport { baseDocumentModels } from \"../packages/base-document-models.js\";\nimport {\n findSubgraphTypeCollisions,\n documentModelSubgraphTypes,\n generatedTypesOf,\n getDocumentModelSubgraphName,\n hasOperationSchemas,\n} from \"../utils/create-schema.js\";\nimport authSchema from \"./auth/schema.graphql\";\nimport { inspectionTypeDefs } from \"./inspection/schema.js\";\nimport reactorSchema from \"./reactor/schema.graphql\";\nimport {\n collectSubgraphClaims,\n type OwnershipConflict,\n resolveClaimOwnership,\n type SubgraphClaims,\n} from \"./subgraph-type-ownership.js\";\nimport { systemTypeDefs } from \"./system/schema.js\";\n\nexport {\n reservedTypeNames,\n type ReservedTypeNames,\n} from \"../utils/create-schema.js\";\nexport type { OwnershipConflict } from \"./subgraph-type-ownership.js\";\n\n/** Owner of the types every generated document-model schema carries. */\nexport const DOCUMENT_MODEL_SCHEMA_OWNER = \"document-model schema\";\n\n/** The type definitions of every core subgraph, by subgraph name. */\nexport const coreSubgraphTypeDefs: ReadonlyMap<string, DocumentNode> = new Map([\n [\"analytics\", gql(analyticsTypeDefs)],\n [\"system\", systemTypeDefs],\n [\"r\", gql(reactorSchema)],\n [\"inspection\", inspectionTypeDefs],\n [\"auth\", gql(authSchema)],\n]);\n\n/** A package's own subgraph, in the order the package exports it. */\nexport type PackageSubgraph = { name: string; typeDefs: DocumentNode };\n\nexport type PackageSubgraphConflicts = {\n /** Set when the server refuses the subgraph's name. */\n nameHeldBy?: \"core\" | \"document model\";\n /** Types and root fields the subgraph loses. */\n claims: OwnershipConflict[];\n};\n\nexport type PackageSubgraphReport = {\n /** By subgraph name; subgraphs without a conflict are left out. */\n conflicts: Map<string, PackageSubgraphConflicts>;\n /** Models whose schema does not generate, left out of the check. */\n skippedModels: string[];\n};\n\ntype ModelSubgraph = { name: string; typeDefs: DocumentNode };\n\nfunction claimsOf(typeDefs: DocumentNode, generated: ReadonlySet<string>) {\n try {\n return collectSubgraphClaims(typeDefs, generated);\n } catch {\n // Malformed typeDefs fail where the schema is built, so claim nothing.\n return new Map() as SubgraphClaims;\n }\n}\n\n/** Package subgraphs the server refuses or excludes; host subgraphs unchecked. */\nexport function findPackageSubgraphConflicts(\n subgraphs: readonly PackageSubgraph[],\n documentModels: readonly DocumentModelGlobalState[],\n): PackageSubgraphReport {\n const models: DocumentModelGlobalState[] = [];\n const modelSubgraphs: ModelSubgraph[] = [];\n const skippedModels: string[] = [];\n const allModels = [\n ...baseDocumentModels.map(([, model]) => model.documentModel.global),\n ...documentModels,\n ];\n for (const model of allModels) {\n let typeDefs: DocumentNode | undefined;\n try {\n generatedTypesOf([model]);\n if (hasOperationSchemas(model)) {\n typeDefs = documentModelSubgraphTypes(model).typeDefs;\n }\n } catch {\n skippedModels.push(model.name);\n continue;\n }\n models.push(model);\n const name = getDocumentModelSubgraphName(model);\n if (typeDefs && !modelSubgraphs.some((owner) => owner.name === name)) {\n modelSubgraphs.push({ name, typeDefs });\n }\n }\n\n const generated = generatedTypesOf(models);\n const fixed = generatedTypesOf([]).names;\n const generatedOwners = new Map<string, string>();\n for (const model of models) {\n for (const name of generatedTypesOf([model]).names) {\n if (!fixed.has(name)) {\n generatedOwners.set(name, getDocumentModelSubgraphName(model));\n }\n }\n }\n\n const conflicts = new Map<string, PackageSubgraphConflicts>();\n const admitted: PackageSubgraph[] = [];\n for (const subgraph of subgraphs) {\n if (coreSubgraphTypeDefs.has(subgraph.name)) {\n conflicts.set(subgraph.name, { nameHeldBy: \"core\", claims: [] });\n continue;\n }\n if (modelSubgraphs.some((owner) => owner.name === subgraph.name)) {\n conflicts.set(subgraph.name, {\n nameHeldBy: \"document model\",\n claims: [],\n });\n continue;\n }\n let collisions: string[];\n try {\n collisions = findSubgraphTypeCollisions(generated, subgraph.typeDefs);\n } catch {\n collisions = [];\n }\n if (collisions.length > 0) {\n conflicts.set(subgraph.name, {\n claims: collisions.map((claim) => ({\n claim,\n owner: generatedOwners.get(claim) ?? DOCUMENT_MODEL_SCHEMA_OWNER,\n })),\n });\n continue;\n }\n admitted.push(subgraph);\n }\n\n const packageNames = new Set(admitted.map(({ name }) => name));\n const excluded = resolveClaimOwnership(\n [\n ...Array.from(coreSubgraphTypeDefs, ([name, typeDefs]) => ({\n name,\n typeDefs,\n })),\n ...modelSubgraphs,\n ...admitted,\n ].map(({ name, typeDefs }) => ({\n candidate: name,\n name,\n claims: claimsOf(typeDefs, generated.names),\n })),\n );\n for (const [name, claims] of excluded) {\n if (packageNames.has(name)) conflicts.set(name, { claims });\n }\n return { conflicts, skippedModels };\n}\n"],"names":["analyticsTypeDefs","reactorSchema","authSchema"],"mappings":";;;;;;;AA8BA,MAAa,8BAA8B;;AAG3C,MAAa,uCAA0D,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WAA8B,CAAC;CACrC,KAAK,MAAM,YAAY,WAAW;EAChC,IAAI,qBAAqB,IAAI,SAAS,IAAI,GAAG;GAC3C,UAAU,IAAI,SAAS,MAAM;IAAE,YAAY;IAAQ,QAAQ,CAAC;GAAE,CAAC;GAC/D;EACF;EACA,IAAI,eAAe,MAAM,UAAU,MAAM,SAAS,SAAS,IAAI,GAAG;GAChE,UAAU,IAAI,SAAS,MAAM;IAC3B,YAAY;IACZ,QAAQ,CAAC;GACX,CAAC;GACD;EACF;EACA,IAAI;EACJ,IAAI;GACF,aAAa,2BAA2B,WAAW,SAAS,QAAQ;EACtE,QAAQ;GACN,aAAa,CAAC;EAChB;EACA,IAAI,WAAW,SAAS,GAAG;GACzB,UAAU,IAAI,SAAS,MAAM,EAC3B,QAAQ,WAAW,KAAK,WAAW;IACjC;IACA,OAAO,gBAAgB,IAAI,KAAK,KAAA;GAClC,EAAE,EACJ,CAAC;GACD;EACF;EACA,SAAS,KAAK,QAAQ;CACxB;CAEA,MAAM,eAAe,IAAI,IAAI,SAAS,KAAK,EAAE,WAAW,IAAI,CAAC;CAC7D,MAAM,WAAW,sBACf;EACE,GAAG,MAAM,KAAK,uBAAuB,CAAC,MAAM,eAAe;GACzD;GACA;EACF,EAAE;EACF,GAAG;EACH,GAAG;CACL,CAAC,CAAC,KAAK,EAAE,MAAM,gBAAgB;EAC7B,WAAW;EACX;EACA,QAAQ,SAAS,UAAU,UAAU,KAAK;CAC5C,EAAE,CACJ;CACA,KAAK,MAAM,CAAC,MAAM,WAAW,UAC3B,IAAI,aAAa,IAAI,IAAI,GAAG,UAAU,IAAI,MAAM,EAAE,OAAO,CAAC;CAE5D,OAAO;EAAE;EAAW;CAAc;AACpC","debug_id":"b8e7b48c-09ef-5ac8-b3ea-6beffcac4f22"}
@@ -1,4 +1,4 @@
1
- import { o as ISubscribablePackageLoader, s as ISubscriptionOptions, u as PackagePieceEntry } from "../../types-DlTiz6AA.mjs";
1
+ import { d as ReportError, o as ISubscribablePackageLoader, s as ISubscriptionOptions, u as PackagePieceEntry } from "../../types-D3pD6fvQ.mjs";
2
2
  import { DocumentModelModule, UpgradeManifest } from "@powerhousedao/shared/document-model";
3
3
  import { ILogger } from "document-model";
4
4
  import { Logger, ViteDevServer } from "vite";
@@ -9,6 +9,7 @@ export interface VitePackageLoaderOptions {
9
9
  /** Modules, as paths or file URLs, whose dependencies a package the project
10
10
  * does not install may resolve from. This loader's own module always is. */
11
11
  resolveFrom?: string[];
12
+ reportError?: ReportError;
12
13
  }
13
14
  export declare class VitePackageLoader implements ISubscribablePackageLoader {
14
15
  #private;
@@ -24,7 +25,7 @@ export declare class VitePackageLoader implements ISubscribablePackageLoader {
24
25
  private getPiecesPath;
25
26
  private aliasedRoot;
26
27
  private pieceRoot;
27
- loadDocumentModels(identifier: string, immediate?: boolean): Promise<DocumentModelModule[]>;
28
+ loadDocumentModels(identifier: string): Promise<DocumentModelModule[]>;
28
29
  loadUpgradeManifests(identifier: string): Promise<UpgradeManifest<readonly number[]>[]>;
29
30
  loadSubgraphs(identifier: string): Promise<SubgraphClass[]>;
30
31
  loadProcessors(identifier: string): Promise<ProcessorFactoryBuilder | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"vite-loader.d.mts","names":[],"sources":["../../../src/packages/vite-loader.mts"],"mappings":";;;;;;wBA+BgB,iBAAiB,QAAQ,SAAS,kBAAW;iBA2B5C;;;EAGf;;qBAQW,6BAA6B;;mBACvB;mBAEA;mBAEA;WAER;SAEF,MAAM,MAAM,eAAe,UAAU,2BAAwB;EAIpE,YAAY,MAAM,eAAe,UAAS;UAyDlC;UAIA;UAIA;UAIA;UAMA;UASA;EAcD,mBAAmB,oBAAoB,sBAAiB,QAAA;EA0BzD,qBACJ,qBACC,QAAQ;EAoBL,cAAc,qBAAqB,QAAQ;EAiB3C,eACJ,qBACC,QAAQ;EAkBL,WAAW,qBAAqB,QAAQ;EAsB9C,uBACE,oBACA,UAAU,gBAAgB,gCAC1B,UAAU;EAwBZ,kBACE,oBACA,UAAU,WAAW,0BACrB,UAAU;EAuBZ,mBACE,oBACA,UAAU,YAAY,yCACtB,UAAU;EAuBZ,eACE,oBACA,UAAU,QAAQ,8BAClB,UAAU;;wBA2BQ,gBAAgB,cAAc,SAAS,SAAM,QAAA"}
1
+ {"version":3,"file":"vite-loader.d.mts","names":[],"sources":["../../../src/packages/vite-loader.mts"],"mappings":";;;;;;wBAgCgB,iBAAiB,QAAQ,SAAS,kBAAW;iBA2B5C;;;EAGf;EACA,cAAc;;qBAQH,6BAA6B;;mBACvB;mBAEA;mBAEA;WAIR;SAEF,MAAM,MAAM,eAAe,UAAU,2BAAwB;EAIpE,YAAY,MAAM,eAAe,UAAS;UA0DlC;UAIA;UAIA;UAIA;UAMA;UASA;EAcF,mBAAmB,qBAAqB,QAAQ;EAehD,qBACJ,qBACC,QAAQ;EAoBL,cAAc,qBAAqB,QAAQ;EAiB3C,eACJ,qBACC,QAAQ;EAkBL,WAAW,qBAAqB,QAAQ;EA0C9C,uBACE,oBACA,UAAU,gBAAgB,gCAC1B,UAAU;EAwBZ,kBACE,oBACA,UAAU,WAAW,0BACrB,UAAU;EAuBZ,mBACE,oBACA,UAAU,YAAY,yCACtB,UAAU;EAuBZ,eACE,oBACA,UAAU,QAAQ,8BAClB,UAAU;;wBA6BQ,gBAAgB,cAAc,SAAS,SAAM,QAAA"}
@@ -1,6 +1,6 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="647a32d0-3e32-5241-8c60-6c1d9d1e7ec5")}catch(e){}}();
3
- import { _ as isSubpath, a as packageRootOf, c as piecesFromListModule, g as extractUpgradeManifests, h as debounce, l as extractDocumentModels, n as BUILT_PIECE_LIST, o as pieceListLocation, r as PIECES_SUBPATH, t as extractSubgraphs } from "../../subgraph-extraction-sQlZLLPH.mjs";
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a46f476a-896c-5e31-8f57-aa722ea238e9")}catch(e){}}();
3
+ import { _ as debounce, a as packageRootOf, c as piecesFromListModule, g as runDetached, l as extractDocumentModels, n as BUILT_PIECE_LIST, o as pieceListLocation, r as PIECES_SUBPATH, t as extractSubgraphs, v as extractUpgradeManifests, y as isSubpath } from "../../subgraph-extraction-CPtTeQAT.mjs";
4
4
  import { childLogger } from "document-model";
5
5
  import path from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -19,6 +19,7 @@ var VitePackageLoader = class VitePackageLoader {
19
19
  logger = childLogger(["reactor-api", "vite-loader"]);
20
20
  vite;
21
21
  importers;
22
+ #reportError;
22
23
  name = "VitePackageLoader";
23
24
  static build(vite, options) {
24
25
  return new VitePackageLoader(vite, options);
@@ -26,6 +27,7 @@ var VitePackageLoader = class VitePackageLoader {
26
27
  constructor(vite, options = {}) {
27
28
  this.vite = vite;
28
29
  this.importers = [...options.resolveFrom ?? [], import.meta.url].map((from) => from.startsWith("file:") ? fileURLToPath(from) : from);
30
+ this.#reportError = options.reportError;
29
31
  }
30
32
  async #resolve(identifier, subpath) {
31
33
  const aliased = path.isAbsolute(identifier) ? void 0 : this.aliasedRoot(identifier);
@@ -84,11 +86,7 @@ var VitePackageLoader = class VitePackageLoader {
84
86
  return;
85
87
  }
86
88
  }
87
- loadDocumentModels(identifier, immediate = false) {
88
- return this.#loadDocumentModelsWithDebounce(immediate, identifier);
89
- }
90
- #loadDocumentModelsWithDebounce = debounce(this.#loadDocumentModels.bind(this), 500);
91
- async #loadDocumentModels(identifier) {
89
+ async loadDocumentModels(identifier) {
92
90
  this.logger.debug("Loading document models from", this.getDocumentModelsPath(identifier));
93
91
  const loaded = await this.#load(identifier, "document-models");
94
92
  if (!loaded) return [];
@@ -143,11 +141,18 @@ var VitePackageLoader = class VitePackageLoader {
143
141
  this.logger.debug(` ➜ Loaded ${pieces.length} Pieces from: ${identifier}`);
144
142
  return pieces;
145
143
  }
146
- onDocumentModelsChange(identifier, handler, options) {
147
- const listener = async (changedPath) => {
148
- const documentModelsPath = this.getDocumentModelsPath(identifier);
149
- if (isSubpath(documentModelsPath, changedPath)) handler(await this.loadDocumentModels(identifier));
144
+ #watcherListener(label, matches, reload, options) {
145
+ const reloadOnce = debounce(() => runDetached(label, reload, {
146
+ logger: this.logger,
147
+ report: this.#reportError
148
+ }), options?.debounce ?? 100);
149
+ return (changedPath) => {
150
+ if (matches(changedPath)) reloadOnce();
150
151
  };
152
+ }
153
+ onDocumentModelsChange(identifier, handler, options) {
154
+ const documentModelsPath = this.getDocumentModelsPath(identifier);
155
+ const listener = this.#watcherListener(`Reloading the document models of ${identifier}`, (changedPath) => isSubpath(documentModelsPath, changedPath), async () => handler(await this.loadDocumentModels(identifier)), options);
151
156
  this.vite.watcher.on("change", listener);
152
157
  this.vite.watcher.on("add", listener);
153
158
  this.vite.watcher.on("unlink", listener);
@@ -159,9 +164,7 @@ var VitePackageLoader = class VitePackageLoader {
159
164
  }
160
165
  onSubgraphsChange(identifier, handler, options) {
161
166
  const subgraphsPath = this.getSubgraphsPath(identifier);
162
- const listener = async (changedPath) => {
163
- if (isSubpath(subgraphsPath, changedPath)) handler(await this.loadSubgraphs(identifier));
164
- };
167
+ const listener = this.#watcherListener(`Reloading the subgraphs of ${identifier}`, (changedPath) => isSubpath(subgraphsPath, changedPath), async () => handler(await this.loadSubgraphs(identifier)), options);
165
168
  this.vite.watcher.on("change", listener);
166
169
  this.vite.watcher.on("add", listener);
167
170
  this.vite.watcher.on("unlink", listener);
@@ -173,9 +176,7 @@ var VitePackageLoader = class VitePackageLoader {
173
176
  }
174
177
  onProcessorsChange(identifier, handler, options) {
175
178
  const processorsPath = this.getProcessorsPath(identifier);
176
- const listener = async (changedPath) => {
177
- if (isSubpath(processorsPath, changedPath)) handler(await this.loadProcessors(identifier));
178
- };
179
+ const listener = this.#watcherListener(`Reloading the processors of ${identifier}`, (changedPath) => isSubpath(processorsPath, changedPath), async () => handler(await this.loadProcessors(identifier)), options);
179
180
  this.vite.watcher.on("change", listener);
180
181
  this.vite.watcher.on("add", listener);
181
182
  this.vite.watcher.on("unlink", listener);
@@ -189,10 +190,7 @@ var VitePackageLoader = class VitePackageLoader {
189
190
  const watched = [this.getPiecesPath(identifier)];
190
191
  const root = this.pieceRoot(identifier);
191
192
  if (root !== void 0) watched.push(path.dirname(path.resolve(root, BUILT_PIECE_LIST)));
192
- const listener = async (changedPath) => {
193
- if (!watched.some((dir) => isSubpath(dir, changedPath))) return;
194
- handler(await this.loadPieces(identifier));
195
- };
193
+ const listener = this.#watcherListener(`Reloading the pieces of ${identifier}`, (changedPath) => watched.some((dir) => isSubpath(dir, changedPath)), async () => handler(await this.loadPieces(identifier)), options);
196
194
  this.vite.watcher.on("change", listener);
197
195
  this.vite.watcher.on("add", listener);
198
196
  this.vite.watcher.on("unlink", listener);
@@ -231,4 +229,4 @@ async function startViteServer(root, logger) {
231
229
  export { VitePackageLoader, createViteLogger, startViteServer };
232
230
 
233
231
  //# sourceMappingURL=vite-loader.mjs.map
234
- //# debugId=647a32d0-3e32-5241-8c60-6c1d9d1e7ec5
232
+ //# debugId=a46f476a-896c-5e31-8f57-aa722ea238e9
@@ -1 +1 @@
1
- {"version":3,"file":"vite-loader.mjs","sources":["../../../src/packages/vite-loader.mts"],"sourcesContent":["import { viteCommonjs } from \"@originjs/vite-plugin-commonjs\";\nimport type {\n ProcessorFactoryBuilder,\n SubgraphClass,\n} from \"@powerhousedao/reactor-api\";\nimport type {\n DocumentModelModule,\n UpgradeManifest,\n} from \"@powerhousedao/shared/document-model\";\nimport { childLogger, type ILogger } from \"document-model\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readPackage } from \"read-pkg\";\nimport type { Logger, PluginOption, ViteDevServer } from \"vite\";\nimport { createLogger, createServer } from \"vite\";\nimport { extractDocumentModels } from \"./document-model-detection.js\";\nimport { extractSubgraphs } from \"./subgraph-extraction.js\";\nimport {\n BUILT_PIECE_LIST,\n PIECES_SUBPATH,\n packageRootOf,\n pieceListLocation,\n piecesFromListModule,\n} from \"./pieces.js\";\nimport type {\n ISubscribablePackageLoader,\n ISubscriptionOptions,\n PackagePieceEntry,\n} from \"./types.js\";\nimport { debounce, extractUpgradeManifests, isSubpath } from \"./util.js\";\n\nexport function createViteLogger(logger: ILogger, prefix = \"\") {\n const customLogger = createLogger(\"info\", {\n prefix,\n });\n // Wrapped rather than assigned: the logger methods are bound to their own\n // instance, and re-homing them onto Vite's logger object made every Vite\n // log line throw.\n //\n // Vite's text goes through as a replacement, never as the format string: it\n // is somebody else's prose, not a template. `ILogger` substitutes `@token`,\n // and Vite log lines are full of npm scopes, so `pre-transforming\n // @powerhousedao/design-system` came out as `pre-transforming\n // null/design-system`. Substituting into `@line` instead emits it verbatim.\n //\n // Vite's second argument is dropped for the same reason. It is `LogOptions`\n // -- `{ clear, timestamp }` -- and forwarding it made it the replacement for\n // whatever `@token` the line happened to contain, or got appended as JSON.\n // Only `error` keeps it, where it carries the error itself.\n customLogger.info = (msg) => logger.info(\"@line\", msg);\n customLogger.warn = (msg) => logger.warn(\"@line\", msg);\n customLogger.error = (msg, options) =>\n options?.error\n ? logger.error(\"@line\", msg, options.error)\n : logger.error(\"@line\", msg);\n return customLogger;\n}\n\nexport interface VitePackageLoaderOptions {\n /** Modules, as paths or file URLs, whose dependencies a package the project\n * does not install may resolve from. This loader's own module always is. */\n resolveFrom?: string[];\n}\n\ninterface LoadedModule {\n id: string;\n namespace: Record<string, unknown>;\n}\n\nexport class VitePackageLoader implements ISubscribablePackageLoader {\n private readonly logger = childLogger([\"reactor-api\", \"vite-loader\"]);\n\n private readonly vite: ViteDevServer;\n\n private readonly importers: string[];\n\n readonly name = \"VitePackageLoader\";\n\n static build(vite: ViteDevServer, options?: VitePackageLoaderOptions) {\n return new VitePackageLoader(vite, options);\n }\n\n constructor(vite: ViteDevServer, options: VitePackageLoaderOptions = {}) {\n this.vite = vite;\n this.importers = [...(options.resolveFrom ?? []), import.meta.url].map(\n (from) => (from.startsWith(\"file:\") ? fileURLToPath(from) : from),\n );\n }\n\n // The project first, then the host's own dependencies. A bare name or a path\n // Vite cannot resolve is a package without that module, not an error.\n async #resolve(identifier: string, subpath: string) {\n const aliased = path.isAbsolute(identifier)\n ? undefined\n : this.aliasedRoot(identifier);\n const specifier = path.posix.join(aliased ?? identifier, subpath);\n const bare = !aliased && !path.isAbsolute(identifier);\n const importers = bare ? [undefined, ...this.importers] : [undefined];\n const container = this.vite.environments.ssr.pluginContainer;\n for (const importer of importers) {\n try {\n const resolved = await container.resolveId(specifier, importer);\n if (resolved && !resolved.external) return resolved.id;\n } catch (e) {\n this.logger.debug(\"Could not resolve @specifier: @error\", specifier, e);\n }\n }\n return undefined;\n }\n\n // Resolved before it is loaded, so only a module that exists and fails is\n // reported; one a package does not have is a debug-level miss.\n async #load(\n identifier: string,\n subpath: string,\n ): Promise<LoadedModule | undefined> {\n const id = await this.#resolve(identifier, subpath);\n if (id === undefined) {\n this.logger.debug(\"No @subpath module in @pkg\", subpath, identifier);\n return undefined;\n }\n try {\n const namespace = (await this.vite.ssrLoadModule(id)) as Record<\n string,\n unknown\n >;\n return { id, namespace };\n } catch (e) {\n this.logger.error(\n \"Failed to load @subpath of @pkg from @id: @error\",\n subpath,\n identifier,\n id,\n e instanceof Error ? e.message : e,\n );\n return undefined;\n }\n }\n\n private getDocumentModelsPath(identifier: string): string {\n return path.posix.join(identifier, \"./document-models\");\n }\n\n private getSubgraphsPath(identifier: string): string {\n return path.posix.join(identifier, \"./subgraphs\");\n }\n\n private getProcessorsPath(identifier: string): string {\n return path.posix.join(identifier, \"./processors\");\n }\n\n private getPiecesPath(identifier: string): string {\n return path.posix.join(identifier, `./${PIECES_SUBPATH}`);\n }\n\n // The dev server aliases the local project by its own package name, so a\n // package that is this project is rooted at the source tree vite serves.\n private aliasedRoot(identifier: string): string | undefined {\n const alias = this.vite.config.resolve.alias;\n const entries = Array.isArray(alias) ? alias : [];\n const hit = entries.find((entry) => entry.find === identifier);\n return typeof hit?.replacement === \"string\" ? hit.replacement : undefined;\n }\n\n // What a declared piece path is relative to. Not the module vite loaded: a\n // list read from source still points at the built output beside it.\n private pieceRoot(identifier: string, listId?: string): string | undefined {\n if (!path.isAbsolute(identifier)) {\n const aliased = this.aliasedRoot(identifier);\n if (aliased) return aliased;\n // A built list resolved from wherever the package is installed.\n if (listId) return packageRootOf(path.dirname(listId));\n }\n try {\n return pieceListLocation(identifier).root;\n } catch {\n return undefined;\n }\n }\n\n public loadDocumentModels(identifier: string, immediate = false) {\n return this.#loadDocumentModelsWithDebounce(immediate, identifier);\n }\n\n #loadDocumentModelsWithDebounce = debounce(\n this.#loadDocumentModels.bind(this),\n 500,\n );\n\n async #loadDocumentModels(\n identifier: string,\n ): Promise<DocumentModelModule[]> {\n this.logger.debug(\n \"Loading document models from\",\n this.getDocumentModelsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"document-models\");\n if (!loaded) return [];\n\n const documentModels = extractDocumentModels(loaded.namespace);\n this.logger.verbose(\n ` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`,\n );\n return documentModels;\n }\n\n async loadUpgradeManifests(\n identifier: string,\n ): Promise<UpgradeManifest<readonly number[]>[]> {\n // Projects generated before the aggregate index re-exported the\n // manifests only expose them at document-models/upgrade-manifests.\n for (const subpath of [\n \"document-models\",\n \"document-models/upgrade-manifests\",\n ]) {\n const loaded = await this.#load(identifier, subpath);\n if (!loaded) continue;\n const manifests = extractUpgradeManifests(loaded.namespace);\n if (manifests.length > 0) {\n this.logger.verbose(\n ` ➜ Loaded ${manifests.length} Upgrade Manifests from: ${identifier}`,\n );\n return manifests;\n }\n }\n return [];\n }\n\n async loadSubgraphs(identifier: string): Promise<SubgraphClass[]> {\n this.logger.verbose(\n \"Loading subgraphs from\",\n this.getSubgraphsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"subgraphs\");\n if (!loaded) return [];\n\n const subgraphs = extractSubgraphs(loaded.namespace);\n\n this.logger.debug(\n ` ➜ Loaded ${subgraphs.length} Subgraphs from: ${identifier}`,\n );\n\n return subgraphs;\n }\n\n async loadProcessors(\n identifier: string,\n ): Promise<ProcessorFactoryBuilder | null> {\n this.logger.verbose(\n \"Loading processors from\",\n this.getProcessorsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"processors\");\n const factory = loaded?.namespace.processorFactory;\n if (typeof factory === \"function\") {\n this.logger.verbose(` ➜ Loaded Processor Factory from: ${identifier}`);\n return factory as ProcessorFactoryBuilder;\n }\n\n this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);\n return null;\n }\n\n // The list only, never a piece: in dev it is usually the TypeScript source,\n // and what it names is still the built bundle a worker will load.\n async loadPieces(identifier: string): Promise<PackagePieceEntry[]> {\n this.logger.verbose(\"Loading pieces from\", this.getPiecesPath(identifier));\n const loaded = await this.#load(identifier, PIECES_SUBPATH);\n if (!loaded) return [];\n\n const root = this.pieceRoot(identifier, loaded.id);\n if (root === undefined) {\n this.logger.debug(` ➜ No package root found for: ${identifier}`);\n return [];\n }\n\n const pieces = piecesFromListModule(loaded.namespace, {\n root,\n identifier,\n logger: this.logger,\n });\n this.logger.debug(\n ` ➜ Loaded ${pieces.length} Pieces from: ${identifier}`,\n );\n return pieces;\n }\n\n onDocumentModelsChange(\n identifier: string,\n handler: (documentModels: DocumentModelModule[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const listener = async (changedPath: string) => {\n const documentModelsPath = this.getDocumentModelsPath(identifier);\n if (isSubpath(documentModelsPath, changedPath)) {\n const documentModels = await this.loadDocumentModels(identifier);\n handler(documentModels);\n }\n };\n\n // \"change\" alone misses files that are created or deleted: a removed\n // document-models/ entry would never report an empty result, and the\n // package's registered models would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onSubgraphsChange(\n identifier: string,\n handler: (subgraphs: SubgraphClass[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const subgraphsPath = this.getSubgraphsPath(identifier);\n const listener = async (changedPath: string) => {\n if (isSubpath(subgraphsPath, changedPath)) {\n const subgraphs = await this.loadSubgraphs(identifier);\n handler(subgraphs);\n }\n };\n // \"change\" alone misses files that are created or deleted: a removed\n // subgraphs/ entry would never report an empty result, and the\n // package's registered subgraphs would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onProcessorsChange(\n identifier: string,\n handler: (processors: ProcessorFactoryBuilder | null) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const processorsPath = this.getProcessorsPath(identifier);\n const listener = async (changedPath: string) => {\n if (isSubpath(processorsPath, changedPath)) {\n const processors = await this.loadProcessors(identifier);\n handler(processors);\n }\n };\n // \"change\" alone misses files that are created or deleted: a removed\n // processors/ entry would never report an empty result, and the\n // package's registered processor factories would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onPiecesChange(\n identifier: string,\n handler: (pieces: PackagePieceEntry[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n // Both the source list and the build output: the list says which pieces a\n // package ships, and only the build decides whether one is there to run.\n const watched = [this.getPiecesPath(identifier)];\n const root = this.pieceRoot(identifier);\n if (root !== undefined) {\n watched.push(path.dirname(path.resolve(root, BUILT_PIECE_LIST)));\n }\n const listener = async (changedPath: string) => {\n if (!watched.some((dir) => isSubpath(dir, changedPath))) return;\n handler(await this.loadPieces(identifier));\n };\n // \"change\" alone misses files that are created or deleted, and a piece\n // appearing for the first time is exactly the build this watches for.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n}\n\nexport async function startViteServer(root: string, logger?: Logger) {\n const packageJson = await readPackage({ cwd: root });\n\n const vite = await createServer({\n root,\n configFile: false,\n logger,\n server: { middlewareMode: true, watch: { ignored: [\"**/.ph/**\"] } },\n appType: \"custom\",\n build: {\n rollupOptions: {\n input: [],\n },\n },\n resolve: {\n tsconfigPaths: true,\n alias: {\n [packageJson.name]: root,\n },\n },\n plugins: [\n // cast: the plugin ships types built against an older vite, and the\n // mismatched Plugin type crashes tsc 6 during assignability checking\n viteCommonjs() as PluginOption,\n {\n name: \"suppress-hmr\",\n handleHotUpdate() {\n return []; // return empty array to suppress server refresh\n },\n },\n ],\n });\n\n return vite;\n}\n"],"names":[],"mappings":";;;;;;;;;;AA+BA,SAAgB,iBAAiB,QAAiB,SAAS,IAAI;CAC7D,MAAM,eAAe,aAAa,QAAQ,EACxC,OACF,CAAC;CAeD,aAAa,QAAQ,QAAQ,OAAO,KAAK,SAAS,GAAG;CACrD,aAAa,QAAQ,QAAQ,OAAO,KAAK,SAAS,GAAG;CACrD,aAAa,SAAS,KAAK,YACzB,SAAS,QACL,OAAO,MAAM,SAAS,KAAK,QAAQ,KAAK,IACxC,OAAO,MAAM,SAAS,GAAG;CAC/B,OAAO;AACT;AAaA,IAAa,oBAAb,MAAa,kBAAwD;CACnE,SAA0B,YAAY,CAAC,eAAe,aAAa,C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EACA,SAAS,CAGP,aAAa,GACb;GACE,MAAM;GACN,kBAAkB;IAChB,OAAO,CAAC;GACV;EACF,CACF;CACF,CAAC;AAGH","debug_id":"647a32d0-3e32-5241-8c60-6c1d9d1e7ec5"}
1
+ {"version":3,"file":"vite-loader.mjs","sources":["../../../src/packages/vite-loader.mts"],"sourcesContent":["import { viteCommonjs } from \"@originjs/vite-plugin-commonjs\";\nimport type {\n ProcessorFactoryBuilder,\n SubgraphClass,\n} from \"@powerhousedao/reactor-api\";\nimport type {\n DocumentModelModule,\n UpgradeManifest,\n} from \"@powerhousedao/shared/document-model\";\nimport { childLogger, type ILogger } from \"document-model\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { readPackage } from \"read-pkg\";\nimport type { Logger, PluginOption, ViteDevServer } from \"vite\";\nimport { createLogger, createServer } from \"vite\";\nimport { extractDocumentModels } from \"./document-model-detection.js\";\nimport { extractSubgraphs } from \"./subgraph-extraction.js\";\nimport {\n BUILT_PIECE_LIST,\n PIECES_SUBPATH,\n packageRootOf,\n pieceListLocation,\n piecesFromListModule,\n} from \"./pieces.js\";\nimport type {\n ISubscribablePackageLoader,\n ISubscriptionOptions,\n PackagePieceEntry,\n} from \"./types.js\";\nimport { debounce, extractUpgradeManifests, isSubpath } from \"./util.js\";\nimport { runDetached, type ReportError } from \"../utils/detached.js\";\n\nexport function createViteLogger(logger: ILogger, prefix = \"\") {\n const customLogger = createLogger(\"info\", {\n prefix,\n });\n // Wrapped rather than assigned: the logger methods are bound to their own\n // instance, and re-homing them onto Vite's logger object made every Vite\n // log line throw.\n //\n // Vite's text goes through as a replacement, never as the format string: it\n // is somebody else's prose, not a template. `ILogger` substitutes `@token`,\n // and Vite log lines are full of npm scopes, so `pre-transforming\n // @powerhousedao/design-system` came out as `pre-transforming\n // null/design-system`. Substituting into `@line` instead emits it verbatim.\n //\n // Vite's second argument is dropped for the same reason. It is `LogOptions`\n // -- `{ clear, timestamp }` -- and forwarding it made it the replacement for\n // whatever `@token` the line happened to contain, or got appended as JSON.\n // Only `error` keeps it, where it carries the error itself.\n customLogger.info = (msg) => logger.info(\"@line\", msg);\n customLogger.warn = (msg) => logger.warn(\"@line\", msg);\n customLogger.error = (msg, options) =>\n options?.error\n ? logger.error(\"@line\", msg, options.error)\n : logger.error(\"@line\", msg);\n return customLogger;\n}\n\nexport interface VitePackageLoaderOptions {\n /** Modules, as paths or file URLs, whose dependencies a package the project\n * does not install may resolve from. This loader's own module always is. */\n resolveFrom?: string[];\n reportError?: ReportError;\n}\n\ninterface LoadedModule {\n id: string;\n namespace: Record<string, unknown>;\n}\n\nexport class VitePackageLoader implements ISubscribablePackageLoader {\n private readonly logger = childLogger([\"reactor-api\", \"vite-loader\"]);\n\n private readonly vite: ViteDevServer;\n\n private readonly importers: string[];\n\n readonly #reportError?: ReportError;\n\n readonly name = \"VitePackageLoader\";\n\n static build(vite: ViteDevServer, options?: VitePackageLoaderOptions) {\n return new VitePackageLoader(vite, options);\n }\n\n constructor(vite: ViteDevServer, options: VitePackageLoaderOptions = {}) {\n this.vite = vite;\n this.importers = [...(options.resolveFrom ?? []), import.meta.url].map(\n (from) => (from.startsWith(\"file:\") ? fileURLToPath(from) : from),\n );\n this.#reportError = options.reportError;\n }\n\n // The project first, then the host's own dependencies. A bare name or a path\n // Vite cannot resolve is a package without that module, not an error.\n async #resolve(identifier: string, subpath: string) {\n const aliased = path.isAbsolute(identifier)\n ? undefined\n : this.aliasedRoot(identifier);\n const specifier = path.posix.join(aliased ?? identifier, subpath);\n const bare = !aliased && !path.isAbsolute(identifier);\n const importers = bare ? [undefined, ...this.importers] : [undefined];\n const container = this.vite.environments.ssr.pluginContainer;\n for (const importer of importers) {\n try {\n const resolved = await container.resolveId(specifier, importer);\n if (resolved && !resolved.external) return resolved.id;\n } catch (e) {\n this.logger.debug(\"Could not resolve @specifier: @error\", specifier, e);\n }\n }\n return undefined;\n }\n\n // Resolved before it is loaded, so only a module that exists and fails is\n // reported; one a package does not have is a debug-level miss.\n async #load(\n identifier: string,\n subpath: string,\n ): Promise<LoadedModule | undefined> {\n const id = await this.#resolve(identifier, subpath);\n if (id === undefined) {\n this.logger.debug(\"No @subpath module in @pkg\", subpath, identifier);\n return undefined;\n }\n try {\n const namespace = (await this.vite.ssrLoadModule(id)) as Record<\n string,\n unknown\n >;\n return { id, namespace };\n } catch (e) {\n this.logger.error(\n \"Failed to load @subpath of @pkg from @id: @error\",\n subpath,\n identifier,\n id,\n e instanceof Error ? e.message : e,\n );\n return undefined;\n }\n }\n\n private getDocumentModelsPath(identifier: string): string {\n return path.posix.join(identifier, \"./document-models\");\n }\n\n private getSubgraphsPath(identifier: string): string {\n return path.posix.join(identifier, \"./subgraphs\");\n }\n\n private getProcessorsPath(identifier: string): string {\n return path.posix.join(identifier, \"./processors\");\n }\n\n private getPiecesPath(identifier: string): string {\n return path.posix.join(identifier, `./${PIECES_SUBPATH}`);\n }\n\n // The dev server aliases the local project by its own package name, so a\n // package that is this project is rooted at the source tree vite serves.\n private aliasedRoot(identifier: string): string | undefined {\n const alias = this.vite.config.resolve.alias;\n const entries = Array.isArray(alias) ? alias : [];\n const hit = entries.find((entry) => entry.find === identifier);\n return typeof hit?.replacement === \"string\" ? hit.replacement : undefined;\n }\n\n // What a declared piece path is relative to. Not the module vite loaded: a\n // list read from source still points at the built output beside it.\n private pieceRoot(identifier: string, listId?: string): string | undefined {\n if (!path.isAbsolute(identifier)) {\n const aliased = this.aliasedRoot(identifier);\n if (aliased) return aliased;\n // A built list resolved from wherever the package is installed.\n if (listId) return packageRootOf(path.dirname(listId));\n }\n try {\n return pieceListLocation(identifier).root;\n } catch {\n return undefined;\n }\n }\n\n async loadDocumentModels(identifier: string): Promise<DocumentModelModule[]> {\n this.logger.debug(\n \"Loading document models from\",\n this.getDocumentModelsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"document-models\");\n if (!loaded) return [];\n\n const documentModels = extractDocumentModels(loaded.namespace);\n this.logger.verbose(\n ` ➜ Loaded ${documentModels.length} Document Models from: ${identifier}`,\n );\n return documentModels;\n }\n\n async loadUpgradeManifests(\n identifier: string,\n ): Promise<UpgradeManifest<readonly number[]>[]> {\n // Projects generated before the aggregate index re-exported the\n // manifests only expose them at document-models/upgrade-manifests.\n for (const subpath of [\n \"document-models\",\n \"document-models/upgrade-manifests\",\n ]) {\n const loaded = await this.#load(identifier, subpath);\n if (!loaded) continue;\n const manifests = extractUpgradeManifests(loaded.namespace);\n if (manifests.length > 0) {\n this.logger.verbose(\n ` ➜ Loaded ${manifests.length} Upgrade Manifests from: ${identifier}`,\n );\n return manifests;\n }\n }\n return [];\n }\n\n async loadSubgraphs(identifier: string): Promise<SubgraphClass[]> {\n this.logger.verbose(\n \"Loading subgraphs from\",\n this.getSubgraphsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"subgraphs\");\n if (!loaded) return [];\n\n const subgraphs = extractSubgraphs(loaded.namespace);\n\n this.logger.debug(\n ` ➜ Loaded ${subgraphs.length} Subgraphs from: ${identifier}`,\n );\n\n return subgraphs;\n }\n\n async loadProcessors(\n identifier: string,\n ): Promise<ProcessorFactoryBuilder | null> {\n this.logger.verbose(\n \"Loading processors from\",\n this.getProcessorsPath(identifier),\n );\n const loaded = await this.#load(identifier, \"processors\");\n const factory = loaded?.namespace.processorFactory;\n if (typeof factory === \"function\") {\n this.logger.verbose(` ➜ Loaded Processor Factory from: ${identifier}`);\n return factory as ProcessorFactoryBuilder;\n }\n\n this.logger.verbose(` ➜ No Processor Factory found for: ${identifier}`);\n return null;\n }\n\n // The list only, never a piece: in dev it is usually the TypeScript source,\n // and what it names is still the built bundle a worker will load.\n async loadPieces(identifier: string): Promise<PackagePieceEntry[]> {\n this.logger.verbose(\"Loading pieces from\", this.getPiecesPath(identifier));\n const loaded = await this.#load(identifier, PIECES_SUBPATH);\n if (!loaded) return [];\n\n const root = this.pieceRoot(identifier, loaded.id);\n if (root === undefined) {\n this.logger.debug(` ➜ No package root found for: ${identifier}`);\n return [];\n }\n\n const pieces = piecesFromListModule(loaded.namespace, {\n root,\n identifier,\n logger: this.logger,\n });\n this.logger.debug(\n ` ➜ Loaded ${pieces.length} Pieces from: ${identifier}`,\n );\n return pieces;\n }\n\n // One reload per burst of file events, run detached.\n #watcherListener(\n label: string,\n matches: (changedPath: string) => unknown,\n reload: () => Promise<void>,\n options?: ISubscriptionOptions,\n ): (changedPath: string) => void {\n const reloadOnce = debounce(\n () =>\n runDetached(label, reload, {\n logger: this.logger,\n report: this.#reportError,\n }),\n options?.debounce ?? 100,\n );\n return (changedPath) => {\n if (matches(changedPath)) void reloadOnce();\n };\n }\n\n onDocumentModelsChange(\n identifier: string,\n handler: (documentModels: DocumentModelModule[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const documentModelsPath = this.getDocumentModelsPath(identifier);\n const listener = this.#watcherListener(\n `Reloading the document models of ${identifier}`,\n (changedPath) => isSubpath(documentModelsPath, changedPath),\n async () => handler(await this.loadDocumentModels(identifier)),\n options,\n );\n\n // \"change\" alone misses files that are created or deleted: a removed\n // document-models/ entry would never report an empty result, and the\n // package's registered models would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onSubgraphsChange(\n identifier: string,\n handler: (subgraphs: SubgraphClass[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const subgraphsPath = this.getSubgraphsPath(identifier);\n const listener = this.#watcherListener(\n `Reloading the subgraphs of ${identifier}`,\n (changedPath) => isSubpath(subgraphsPath, changedPath),\n async () => handler(await this.loadSubgraphs(identifier)),\n options,\n );\n // \"change\" alone misses files that are created or deleted: a removed\n // subgraphs/ entry would never report an empty result, and the\n // package's registered subgraphs would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onProcessorsChange(\n identifier: string,\n handler: (processors: ProcessorFactoryBuilder | null) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n const processorsPath = this.getProcessorsPath(identifier);\n const listener = this.#watcherListener(\n `Reloading the processors of ${identifier}`,\n (changedPath) => isSubpath(processorsPath, changedPath),\n async () => handler(await this.loadProcessors(identifier)),\n options,\n );\n // \"change\" alone misses files that are created or deleted: a removed\n // processors/ entry would never report an empty result, and the\n // package's registered processor factories would leak.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n\n onPiecesChange(\n identifier: string,\n handler: (pieces: PackagePieceEntry[]) => void,\n options?: ISubscriptionOptions,\n ): () => void {\n // Both the source list and the build output: the list says which pieces a\n // package ships, and only the build decides whether one is there to run.\n const watched = [this.getPiecesPath(identifier)];\n const root = this.pieceRoot(identifier);\n if (root !== undefined) {\n watched.push(path.dirname(path.resolve(root, BUILT_PIECE_LIST)));\n }\n const listener = this.#watcherListener(\n `Reloading the pieces of ${identifier}`,\n (changedPath) => watched.some((dir) => isSubpath(dir, changedPath)),\n async () => handler(await this.loadPieces(identifier)),\n options,\n );\n // \"change\" alone misses files that are created or deleted, and a piece\n // appearing for the first time is exactly the build this watches for.\n this.vite.watcher.on(\"change\", listener);\n this.vite.watcher.on(\"add\", listener);\n this.vite.watcher.on(\"unlink\", listener);\n\n return () => {\n this.vite.watcher.off(\"change\", listener);\n this.vite.watcher.off(\"add\", listener);\n this.vite.watcher.off(\"unlink\", listener);\n };\n }\n}\n\nexport async function startViteServer(root: string, logger?: Logger) {\n const packageJson = await readPackage({ cwd: root });\n\n const vite = await createServer({\n root,\n configFile: false,\n logger,\n server: { middlewareMode: true, watch: { ignored: [\"**/.ph/**\"] } },\n appType: \"custom\",\n build: {\n rollupOptions: {\n input: [],\n },\n },\n resolve: {\n tsconfigPaths: true,\n alias: {\n [packageJson.name]: root,\n },\n },\n plugins: [\n // cast: the plugin ships types built against an older vite, and the\n // mismatched Plugin type crashes tsc 6 during assignability checking\n viteCommonjs() as PluginOption,\n {\n name: \"suppress-hmr\",\n handleHotUpdate() {\n return []; // return empty array to suppress server refresh\n },\n },\n ],\n });\n\n return vite;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAgCA,SAAgB,iBAAiB,QAAiB,SAAS,IAAI;CAC7D,MAAM,eAAe,aAAa,QAAQ,EACxC,OACF,CAAC;CAeD,aAAa,QAAQ,QAAQ,OAAO,KAAK,SAAS,GAAG;CACrD,aAAa,QAAQ,QAAQ,OAAO,KAAK,SAAS,GAAG;CACrD,aAAa,SAAS,KAAK,YACzB,SAAS,QACL,OAAO,MAAM,SAAS,KAAK,QAAQ,KAAK,IACxC,OAAO,MAAM,SAAS,GAAG;CAC/B,OAAO;AACT;AAcA,IAAa,oBAAb,MAAa,kBAAwD;CACnE,SAA0B,YAAY,CAAC,eAAe,aAAa,CAAC;CAEpE;CAEA;CAEA;CAEA,OAAgB;CAEhB,OAAO,MAAM,MAAqB,SAAoC;EACpE,OAAO,IAAI,kBAAkB,MAAM,OAAO;CAC5C;CAEA,YAAY,MAAqB,UAAoC,CAAC,GAAG;EACvE,KAAK,OAAO;EACZ,KAAK,YAAY,CAAC,GAAI,QAAQ,eAAe,CAAC,GAAI,YAAY,GAAG,CAAC,CAAC,KAChE,SAAU,KAAK,WAAW,OAAO,IAAI,cAAc,IAAI,IAAI,IAC9D;EACA,KAAK,eAAe,QAAQ;CAC9B;CAIA,MAAM,SAAS,YAAoB,SAAiB;EAClD,MAAM,UAAU,KAAK,WAAW,UAAU,IACtC,KAAA,IACA,KAAK,YAAY,UAAU;EAC/B,MAAM,YAAY,KAAK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Ac,UAAU,CAAC;EAC/C,MAAM,OAAO,KAAK,UAAU,UAAU;EACtC,IAAI,SAAS,KAAA,GACX,QAAQ,KAAK,KAAK,QAAQ,KAAK,QAAQ,MAAM,gBAAgB,CAAC,CAAC;EAEjE,MAAM,WAAW,KAAK,iBACpB,2BAA2B,eAC1B,gBAAgB,QAAQ,MAAM,QAAQ,UAAU,KAAK,WAAW,CAAC,GAClE,YAAY,QAAQ,MAAM,KAAK,WAAW,UAAU,CAAC,GACrD,OACF;EAGA,KAAK,KAAK,QAAQ,GAAG,UAAU,QAAQ;EACvC,KAAK,KAAK,QAAQ,GAAG,OAAO,QAAQ;EACpC,KAAK,KAAK,QAAQ,GAAG,UAAU,QAAQ;EAEvC,aAAa;GACX,KAAK,KAAK,QAAQ,IAAI,UAAU,QAAQ;GACxC,KAAK,KAAK,QAAQ,IAAI,OAAO,QAAQ;GACrC,KAAK,KAAK,QAAQ,IAAI,UAAU,QAAQ;EAC1C;CACF;AACF;AAEA,eAAsB,gBAAgB,MAAc,QAAiB;CACnE,MAAM,cAAc,MAAM,YAAY,EAAE,KAAK,KAAK,CAAC;CAgCnD,OAAO,MA9BY,aAAa;EAC9B;EACA,YAAY;EACZ;EACA,QAAQ;GAAE,gBAAgB;GAAM,OAAO,EAAE,SAAS,CAAC,WAAW,EAAE;EAAE;EAClE,SAAS;EACT,OAAO,EACL,eAAe,EACb,OAAO,CAAC,EACV,EACF;EACA,SAAS;GACP,eAAe;GACf,OAAO,GACJ,YAAY,OAAO,KACtB;EACF;EACA,SAAS,CAGP,aAAa,GACb;GACE,MAAM;GACN,kBAAkB;IAChB,OAAO,CAAC;GACV;EACF,CACF;CACF,CAAC;AAGH","debug_id":"a46f476a-896c-5e31-8f57-aa722ea238e9"}
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a7006388-c7a4-51a6-82d1-b4ec96082701")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c35c049c-bef2-5025-9ac3-30cc55cbe758")}catch(e){}}();
3
3
  import { createRequire } from "node:module";
4
4
  import { gql } from "graphql-tag";
5
5
  import { GraphQLError } from "graphql";
@@ -673,15 +673,30 @@ function extractUpgradeManifests(namespace) {
673
673
  else add(value);
674
674
  return Array.from(manifests.values());
675
675
  }
676
+ /** Calls superseded before the timer fires settle with the run that follows. */
676
677
  function debounce(func, delay = 250) {
677
678
  let timer;
678
- return (immediate = false, ...args) => {
679
- if (timer) clearTimeout(timer);
679
+ let waiting = [];
680
+ const run = async () => {
681
+ timer = void 0;
682
+ const callers = waiting;
683
+ waiting = [];
684
+ try {
685
+ const value = await func();
686
+ callers.forEach((caller) => caller.resolve(value));
687
+ } catch (error) {
688
+ callers.forEach((caller) => caller.reject(error));
689
+ }
690
+ };
691
+ return (immediate = false) => {
692
+ clearTimeout(timer);
680
693
  return new Promise((resolve, reject) => {
681
- if (immediate) func(...args).then(resolve).catch(reject);
682
- else timer = setTimeout(() => {
683
- func(...args).then(resolve).catch(reject);
684
- }, delay);
694
+ waiting.push({
695
+ resolve,
696
+ reject
697
+ });
698
+ if (immediate) run();
699
+ else timer = setTimeout(() => void run(), delay);
685
700
  });
686
701
  };
687
702
  }
@@ -690,6 +705,25 @@ function isSubpath(parent, dir) {
690
705
  return relative && !relative.startsWith("..") && !path.isAbsolute(relative);
691
706
  }
692
707
  //#endregion
708
+ //#region src/utils/detached.ts
709
+ /** Logs `error` as the message's last replacement and reports it. */
710
+ function reportFailure({ logger, report }, error, message, ...args) {
711
+ logger.error(message, ...args, error);
712
+ try {
713
+ report?.(error);
714
+ } catch (reportError) {
715
+ logger.error("Reporting a failure failed: @error", reportError);
716
+ }
717
+ }
718
+ /** Runs work nobody awaits: a failure is logged and reported, never thrown. */
719
+ async function runDetached(label, task, options) {
720
+ try {
721
+ await task();
722
+ } catch (error) {
723
+ reportFailure(options, error, "@label failed: @error", label);
724
+ }
725
+ }
726
+ //#endregion
693
727
  //#region src/graphql/utils.ts
694
728
  function isSubgraphClass(candidate) {
695
729
  if (typeof candidate !== "function") return false;
@@ -926,7 +960,7 @@ function extractSubgraphs(namespace) {
926
960
  return found;
927
961
  }
928
962
  //#endregion
929
- export { AuthenticationRequiredError as A, callerSubject as C, AuthorizedDocumentHandle as D, AuthorizationPolicy as E, MalformedStoredOperationError as M, RefusalNotRecordedError as N, createAuthorizationService as O, BaseSubgraph as S, createCanonicalDocumentIdResolver as T, isSubpath as _, packageRootOf as a, loadSubgraphs as b, piecesFromListModule as c, buildGraphQlDriveDocument as d, buildGraphqlOperation as f, extractUpgradeManifests as g, debounce as h, PIECE_SOURCE_LIST as i, ForbiddenError as j, AuthEvaluationUnsupportedError as k, extractDocumentModels as l, isSubgraphClass as m, BUILT_PIECE_LIST as n, pieceListLocation as o, buildGraphqlOperations as p, PIECES_SUBPATH as r, piecesFromCdnList as s, extractSubgraphs as t, buildGraphQlDocument as u, loadDocumentModels as v, CanonicalDocumentIdResolutionError as w, manifestDeclaredSubgraphs as x, loadProcessors as y };
963
+ export { createAuthorizationService as A, manifestDeclaredSubgraphs as C, createCanonicalDocumentIdResolver as D, CanonicalDocumentIdResolutionError as E, RefusalNotRecordedError as F, AuthenticationRequiredError as M, ForbiddenError as N, AuthorizationPolicy as O, MalformedStoredOperationError as P, loadSubgraphs as S, callerSubject as T, debounce as _, packageRootOf as a, loadDocumentModels as b, piecesFromListModule as c, buildGraphQlDriveDocument as d, buildGraphqlOperation as f, runDetached as g, reportFailure as h, PIECE_SOURCE_LIST as i, AuthEvaluationUnsupportedError as j, AuthorizedDocumentHandle as k, extractDocumentModels as l, isSubgraphClass as m, BUILT_PIECE_LIST as n, pieceListLocation as o, buildGraphqlOperations as p, PIECES_SUBPATH as r, piecesFromCdnList as s, extractSubgraphs as t, buildGraphQlDocument as u, extractUpgradeManifests as v, BaseSubgraph as w, loadProcessors as x, isSubpath as y };
930
964
 
931
- //# sourceMappingURL=subgraph-extraction-sQlZLLPH.mjs.map
932
- //# debugId=a7006388-c7a4-51a6-82d1-b4ec96082701
965
+ //# sourceMappingURL=subgraph-extraction-CPtTeQAT.mjs.map
966
+ //# debugId=c35c049c-bef2-5025-9ac3-30cc55cbe758