@powerhousedao/reactor-api 6.2.3-dev.53 → 6.2.3-dev.55
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/{adapter-gateway-mercurius-rbKlwF9m.mjs → adapter-gateway-mercurius-BhO0nwH_.mjs} +4 -4
- package/dist/{adapter-gateway-mercurius-rbKlwF9m.mjs.map → adapter-gateway-mercurius-BhO0nwH_.mjs.map} +1 -1
- package/dist/index.d.mts +72 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +614 -192
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/index.mjs
CHANGED
|
@@ -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]="
|
|
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]="258ec262-91c0-5680-9801-22cef42aa999")}catch(e){}}();
|
|
3
3
|
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
4
4
|
import { A as AuthenticationRequiredError, C as callerSubject, D as AuthorizedDocumentHandle, E as AuthorizationPolicy, M as MalformedStoredOperationError, N as RefusalNotRecordedError, O as createAuthorizationService, S as BaseSubgraph, T as createCanonicalDocumentIdResolver, b as loadSubgraphs, c as piecesFromListModule, d as buildGraphQlDriveDocument, f as buildGraphqlOperation, g as extractUpgradeManifests, h as debounce, i as PIECE_SOURCE_LIST, j as ForbiddenError, k as AuthEvaluationUnsupportedError, l as extractDocumentModels, m as isSubgraphClass, o as pieceListLocation, p as buildGraphqlOperations, s as piecesFromCdnList, t as extractSubgraphs, u as buildGraphQlDocument, v as loadDocumentModels, w as CanonicalDocumentIdResolutionError, x as manifestDeclaredSubgraphs, y as loadProcessors } from "./subgraph-extraction-sQlZLLPH.mjs";
|
|
5
5
|
import { l as createDurableNodeFs, n as openCurrentPgliteForVerify, r as preparePgliteDataDir, u as resolvePgliteFsync } from "./pglite-node-Ow9i5Rb4.mjs";
|
|
@@ -11,6 +11,7 @@ import { GraphQLError, Kind, Lexer, OperationTypeNode, Source, TokenKind, parse,
|
|
|
11
11
|
import { AuthEnforcementDisabledError, BareReadGate, BatchJobFailedError, ChannelError, ChannelErrorSource, DEFAULT_DRIVE_CONTAINER_TYPES, DriveCollectionId, DriveInspection, InvalidDeadLetterCursorError, JOB_NOT_FOUND_ERROR_NAME, JobStatus, ModelReadGate, PropagationMode as PropagationMode$1, READ_ONLY_ACCESS, SyncOperation, SyncScopeGate, consolidateSyncOperations, createReactorHostModuleBase, createReactorInspector, driveIdFromUrl, envelopesToSyncOperations, parseDriveUrl, readDecisionModel, supportsPurgeRefusals, syncOperationErrorType, toWireDeadLetter, toWireQueueState } from "@powerhousedao/reactor";
|
|
12
12
|
import { deserializeSignature, readPeerManifest, serializeSignature, setName, withSignaturePolicy } from "@powerhousedao/shared/document-model";
|
|
13
13
|
import { ConsoleLogger, childLogger, documentModelDocumentModelModule } from "document-model";
|
|
14
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
14
15
|
import path, { isAbsolute, join } from "node:path";
|
|
15
16
|
import { match } from "path-to-regexp";
|
|
16
17
|
import posix from "node:path/posix";
|
|
@@ -363,7 +364,7 @@ async function createGatewayAdapter(type, logger) {
|
|
|
363
364
|
return new ApolloGatewayAdapter(logger);
|
|
364
365
|
}
|
|
365
366
|
case "mercurius": {
|
|
366
|
-
const { MercuriusGatewayAdapter } = await import("./adapter-gateway-mercurius-
|
|
367
|
+
const { MercuriusGatewayAdapter } = await import("./adapter-gateway-mercurius-BhO0nwH_.mjs");
|
|
367
368
|
return new MercuriusGatewayAdapter(logger);
|
|
368
369
|
}
|
|
369
370
|
case "stitching": {
|
|
@@ -1519,15 +1520,16 @@ const RevisionType = `
|
|
|
1519
1520
|
}
|
|
1520
1521
|
`;
|
|
1521
1522
|
/**
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1523
|
+
* A subgraph defines a type whose name the generated document-model schema
|
|
1524
|
+
* owns, so one of the two definitions would be lost.
|
|
1524
1525
|
*/
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1526
|
+
var SubgraphTypeCollisionError = class extends Error {
|
|
1527
|
+
typeNames;
|
|
1528
|
+
constructor(typeNames) {
|
|
1529
|
+
super(`Subgraph defines types reserved by the document-model schema: ${typeNames.join(", ")}`);
|
|
1530
|
+
this.name = "SubgraphTypeCollisionError";
|
|
1531
|
+
this.typeNames = typeNames;
|
|
1532
|
+
}
|
|
1531
1533
|
};
|
|
1532
1534
|
/**
|
|
1533
1535
|
* Type-system definition kinds that GraphQL requires to be uniquely named.
|
|
@@ -1554,24 +1556,20 @@ const TYPE_DEFINITION_KINDS = /* @__PURE__ */ new Set([
|
|
|
1554
1556
|
* twice in one scope) so the assembled subgraph SDL composes instead of crashing
|
|
1555
1557
|
* the gateway (Sentry #917).
|
|
1556
1558
|
*/
|
|
1557
|
-
const dedupeTypeDefinitions = (
|
|
1558
|
-
const
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
kind: Kind.DOCUMENT,
|
|
1572
|
-
definitions
|
|
1573
|
-
};
|
|
1574
|
-
};
|
|
1559
|
+
const dedupeTypeDefinitions = (definitions, seen = /* @__PURE__ */ new Set()) => definitions.filter((def) => {
|
|
1560
|
+
const name = typeDefinitionName(def);
|
|
1561
|
+
if (name === void 0) return true;
|
|
1562
|
+
if (seen.has(name)) {
|
|
1563
|
+
logger$1.debug(`Dropping duplicate type definition: ${name}`);
|
|
1564
|
+
return false;
|
|
1565
|
+
}
|
|
1566
|
+
seen.add(name);
|
|
1567
|
+
return true;
|
|
1568
|
+
});
|
|
1569
|
+
function typeDefinitionName(def) {
|
|
1570
|
+
if (!TYPE_DEFINITION_KINDS.has(def.kind)) return void 0;
|
|
1571
|
+
return def.name?.value;
|
|
1572
|
+
}
|
|
1575
1573
|
const EMPTY_DOCUMENT = {
|
|
1576
1574
|
kind: Kind.DOCUMENT,
|
|
1577
1575
|
definitions: []
|
|
@@ -1664,19 +1662,19 @@ function buildModuleSchemas(specification, documentName, allTypeNames, hasValidS
|
|
|
1664
1662
|
});
|
|
1665
1663
|
}).filter(Boolean).join("\n") ?? "";
|
|
1666
1664
|
}
|
|
1667
|
-
const buildSubgraphSchemaModule = (documentModels, resolvers, typeDefs) => {
|
|
1665
|
+
const buildSubgraphSchemaModule = (documentModels, resolvers, typeDefs, options = {}) => {
|
|
1668
1666
|
const newResolvers = {
|
|
1669
1667
|
...resolvers,
|
|
1670
1668
|
JSONObject: GraphQLJSONObject,
|
|
1671
1669
|
Unknown: GraphQLJSON
|
|
1672
1670
|
};
|
|
1673
1671
|
return {
|
|
1674
|
-
typeDefs:
|
|
1672
|
+
typeDefs: assembleSubgraphTypeDefs(options.generated ?? getGeneratedDocumentModelTypes(documentModels), typeDefs, options.ownTypeNames),
|
|
1675
1673
|
resolvers: newResolvers
|
|
1676
1674
|
};
|
|
1677
1675
|
};
|
|
1678
|
-
const createSchema = (documentModels, resolvers, typeDefs) => {
|
|
1679
|
-
return buildSubgraphSchema([buildSubgraphSchemaModule(documentModels, resolvers, typeDefs)]);
|
|
1676
|
+
const createSchema = (documentModels, resolvers, typeDefs, options = {}) => {
|
|
1677
|
+
return buildSubgraphSchema([buildSubgraphSchemaModule(documentModels, resolvers, typeDefs, options)]);
|
|
1680
1678
|
};
|
|
1681
1679
|
/**
|
|
1682
1680
|
* Create a merged GraphQL schema from multiple subgraph modules.
|
|
@@ -1689,27 +1687,29 @@ const createMergedSchema = (modules) => {
|
|
|
1689
1687
|
function getDocumentModelSchemaName(documentModel) {
|
|
1690
1688
|
return pascalCase(documentModel.name.replaceAll("/", " "));
|
|
1691
1689
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1690
|
+
/**
|
|
1691
|
+
* The generated document-model types followed by the subgraph's own. Throws
|
|
1692
|
+
* {@link SubgraphTypeCollisionError} when the subgraph defines a generated
|
|
1693
|
+
* name not in `ownTypeNames`.
|
|
1694
|
+
*/
|
|
1695
|
+
const getDocumentModelTypeDefs = (documentModels, typeDefs, ownTypeNames) => assembleSubgraphTypeDefs(getGeneratedDocumentModelTypes(documentModels), typeDefs, ownTypeNames);
|
|
1696
|
+
/** Names of the type definitions in `doc`. */
|
|
1697
|
+
function typeDefinitionNames(doc) {
|
|
1698
|
+
return new Set(doc.definitions.map(typeDefinitionName).filter((name) => name !== void 0));
|
|
1699
|
+
}
|
|
1700
|
+
/** The SDL `documentModel` adds to the generated schema, under `dmSchemaName`. */
|
|
1701
|
+
function documentModelTypesSdl(documentModel, dmSchemaName) {
|
|
1702
|
+
const latestSpec = documentModel.specifications.at(-1);
|
|
1703
|
+
const globalSchema = latestSpec?.state.global.schema ?? "";
|
|
1704
|
+
const localSchema = latestSpec?.state.local.schema ?? "";
|
|
1705
|
+
const definitions = [...stateTypeDefinitions(globalSchema), ...stateTypeDefinitions(localSchema, LOCAL_STATE_STUBS)];
|
|
1706
|
+
const stateDoc = {
|
|
1707
|
+
kind: Kind.DOCUMENT,
|
|
1708
|
+
definitions
|
|
1709
|
+
};
|
|
1710
|
+
const prefixed = prefixTypeNames(stateDoc, dmSchemaName, new Set(definedTypeNames(stateDoc, STATE_PREFIX_KINDS)));
|
|
1711
|
+
let sdl = definitions.length > 0 ? `${print(prefixed)}\n` : "";
|
|
1712
|
+
sdl += `
|
|
1713
1713
|
type ${dmSchemaName} implements IDocument {
|
|
1714
1714
|
id: String!
|
|
1715
1715
|
name: String!
|
|
@@ -1722,6 +1722,53 @@ const getDocumentModelTypeDefs = (documentModels, typeDefs$1) => {
|
|
|
1722
1722
|
${dmSchemaName !== "DocumentModel" ? `state: ${dmSchemaName}_${dmSchemaName}State!` : ""}
|
|
1723
1723
|
stateJSON: JSONObject
|
|
1724
1724
|
}\n`;
|
|
1725
|
+
return sdl;
|
|
1726
|
+
}
|
|
1727
|
+
function addScalarFlags(definitions, into) {
|
|
1728
|
+
for (const def of definitions) {
|
|
1729
|
+
const name = typeDefinitionName(def);
|
|
1730
|
+
if (name === void 0) continue;
|
|
1731
|
+
const scalar = def.kind === Kind.SCALAR_TYPE_DEFINITION;
|
|
1732
|
+
into.set(name, scalar && (into.get(name) ?? true));
|
|
1733
|
+
}
|
|
1734
|
+
return into;
|
|
1735
|
+
}
|
|
1736
|
+
let fixedGeneratedTypes;
|
|
1737
|
+
/**
|
|
1738
|
+
* Type names no document model may generate: the root types, the generated
|
|
1739
|
+
* types every schema carries, and the types of `coreTypeDefs`.
|
|
1740
|
+
*/
|
|
1741
|
+
function reservedTypeNames(coreTypeDefs) {
|
|
1742
|
+
fixedGeneratedTypes ??= addScalarFlags(getGeneratedDocumentModelTypes([]).definitions, /* @__PURE__ */ new Map());
|
|
1743
|
+
const reserved = new Map([
|
|
1744
|
+
["Query", false],
|
|
1745
|
+
["Mutation", false],
|
|
1746
|
+
["Subscription", false],
|
|
1747
|
+
...fixedGeneratedTypes
|
|
1748
|
+
]);
|
|
1749
|
+
for (const typeDefs of coreTypeDefs) addScalarFlags(typeDefs.definitions, reserved);
|
|
1750
|
+
return reserved;
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* The reserved names `documentModel`'s generated types take. A scalar may
|
|
1754
|
+
* repeat a reserved scalar: the duplicate is dropped on assembly.
|
|
1755
|
+
*/
|
|
1756
|
+
function reservedTypeNamesTaken(documentModel, reserved) {
|
|
1757
|
+
const global = documentModel.documentModel.global;
|
|
1758
|
+
const generated = addScalarFlags(parseSdl(documentModelTypesSdl(global, getDocumentModelSchemaName(global))).definitions, /* @__PURE__ */ new Map());
|
|
1759
|
+
return Array.from(generated).filter(([name, scalar]) => reserved.has(name) && !(scalar && reserved.get(name))).map(([name]) => name);
|
|
1760
|
+
}
|
|
1761
|
+
function getGeneratedDocumentModelTypes(documentModels) {
|
|
1762
|
+
let dmSchema = "";
|
|
1763
|
+
const addedDocumentModels = /* @__PURE__ */ new Set();
|
|
1764
|
+
documentModels.forEach(({ documentModel }) => {
|
|
1765
|
+
const dmSchemaName = getDocumentModelSchemaName(documentModel.global);
|
|
1766
|
+
if (addedDocumentModels.has(dmSchemaName)) {
|
|
1767
|
+
logger$1.debug(`Skipping document model with duplicate name: ${dmSchemaName}`);
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
addedDocumentModels.add(dmSchemaName);
|
|
1771
|
+
dmSchema += documentModelTypesSdl(documentModel.global, dmSchemaName);
|
|
1725
1772
|
});
|
|
1726
1773
|
const schema = gql`
|
|
1727
1774
|
scalar JSONObject
|
|
@@ -1797,11 +1844,39 @@ const getDocumentModelTypeDefs = (documentModels, typeDefs$1) => {
|
|
|
1797
1844
|
operations(first: Int, skip: Int): [Operation!]!
|
|
1798
1845
|
stateJSON: JSONObject
|
|
1799
1846
|
}
|
|
1800
|
-
|
|
1801
|
-
${stripScalarDefinitions(typeDefs$1)}
|
|
1802
1847
|
`;
|
|
1803
|
-
|
|
1804
|
-
|
|
1848
|
+
const definitions = dedupeTypeDefinitions(schema.definitions);
|
|
1849
|
+
return {
|
|
1850
|
+
definitions,
|
|
1851
|
+
names: new Set(definitions.map(typeDefinitionName).filter((name) => name !== void 0))
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Names of the generated types `typeDefs` redefines, other than those a
|
|
1856
|
+
* model's own subgraph may repeat. Scalars are dropped on assembly, so they
|
|
1857
|
+
* never collide.
|
|
1858
|
+
*/
|
|
1859
|
+
function findSubgraphTypeCollisions(generated, typeDefs, ownTypeNames) {
|
|
1860
|
+
const collisions = [];
|
|
1861
|
+
for (const def of typeDefs.definitions) {
|
|
1862
|
+
if (def.kind === Kind.SCALAR_TYPE_DEFINITION) continue;
|
|
1863
|
+
const name = typeDefinitionName(def);
|
|
1864
|
+
if (name === void 0 || !generated.names.has(name)) continue;
|
|
1865
|
+
if (ownTypeNames?.has(name)) continue;
|
|
1866
|
+
collisions.push(name);
|
|
1867
|
+
}
|
|
1868
|
+
return collisions;
|
|
1869
|
+
}
|
|
1870
|
+
/** Throws {@link SubgraphTypeCollisionError}; see {@link getDocumentModelTypeDefs}. */
|
|
1871
|
+
function assembleSubgraphTypeDefs(generated, typeDefs, ownTypeNames) {
|
|
1872
|
+
const collisions = findSubgraphTypeCollisions(generated, typeDefs, ownTypeNames);
|
|
1873
|
+
if (collisions.length > 0) throw new SubgraphTypeCollisionError(collisions);
|
|
1874
|
+
const subgraphDefinitions = typeDefs.definitions.filter((def) => def.kind !== Kind.SCALAR_TYPE_DEFINITION);
|
|
1875
|
+
return {
|
|
1876
|
+
kind: Kind.DOCUMENT,
|
|
1877
|
+
definitions: [...generated.definitions, ...dedupeTypeDefinitions(subgraphDefinitions, new Set(generated.names))]
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1805
1880
|
/**
|
|
1806
1881
|
* Extract the names of types defined in a GraphQL schema.
|
|
1807
1882
|
* Unparseable schemas yield no names.
|
|
@@ -4625,11 +4700,14 @@ async function pushSyncEnvelopes(syncManager, args) {
|
|
|
4625
4700
|
*/
|
|
4626
4701
|
var DocumentModelSubgraph = class extends BaseSubgraph {
|
|
4627
4702
|
documentModel;
|
|
4703
|
+
/** Names of the types its schema generator emits for the model. */
|
|
4704
|
+
generatedTypeNames;
|
|
4628
4705
|
constructor(documentModel, args) {
|
|
4629
4706
|
super(args);
|
|
4630
4707
|
this.documentModel = documentModel;
|
|
4631
4708
|
this.name = kebabCase(documentModel.documentModel.global.name);
|
|
4632
4709
|
this.typeDefs = generateDocumentModelSchema(this.documentModel.documentModel.global, { useNewApi: true });
|
|
4710
|
+
this.generatedTypeNames = typeDefinitionNames(this.typeDefs);
|
|
4633
4711
|
this.resolvers = this.generateResolvers();
|
|
4634
4712
|
}
|
|
4635
4713
|
/** Returns the typed query resolvers for this document model. */
|
|
@@ -5046,11 +5124,26 @@ function filterLatestDocumentModelVersions(documentModels) {
|
|
|
5046
5124
|
}
|
|
5047
5125
|
const DefaultFeatureFlags = { enableDocumentModelSubgraphs: true };
|
|
5048
5126
|
/**
|
|
5049
|
-
*
|
|
5050
|
-
*
|
|
5051
|
-
*
|
|
5127
|
+
* Where a subgraph came from: a core subgraph, the host, the generated
|
|
5128
|
+
* document-model subgraphs, or a package name. A name belongs to one origin:
|
|
5129
|
+
* the same origin replaces it, a higher-ranked one evicts it, and any other is
|
|
5130
|
+
* refused.
|
|
5052
5131
|
*/
|
|
5053
|
-
const
|
|
5132
|
+
const CORE_ORIGIN = Symbol("core");
|
|
5133
|
+
const DOCUMENT_MODEL_ORIGIN = Symbol("document-models");
|
|
5134
|
+
const HOST_ORIGIN = Symbol("host");
|
|
5135
|
+
function describeOrigin(origin) {
|
|
5136
|
+
if (origin === CORE_ORIGIN) return "core";
|
|
5137
|
+
if (origin === DOCUMENT_MODEL_ORIGIN) return "document models";
|
|
5138
|
+
if (origin === HOST_ORIGIN) return "the host";
|
|
5139
|
+
return `package ${origin}`;
|
|
5140
|
+
}
|
|
5141
|
+
function rank(origin) {
|
|
5142
|
+
if (origin === CORE_ORIGIN) return 3;
|
|
5143
|
+
if (origin === HOST_ORIGIN) return 2;
|
|
5144
|
+
if (origin === DOCUMENT_MODEL_ORIGIN) return 1;
|
|
5145
|
+
return 0;
|
|
5146
|
+
}
|
|
5054
5147
|
function refuseConnection(connection, reason) {
|
|
5055
5148
|
const { socket } = connection;
|
|
5056
5149
|
socket?.close?.(4403, reason);
|
|
@@ -5095,11 +5188,35 @@ var GraphQLManager = class {
|
|
|
5095
5188
|
/** Mounted SSE routes, keyed by path: the supergraph's and each subgraph's. */
|
|
5096
5189
|
sseRouteHandles = /* @__PURE__ */ new Map();
|
|
5097
5190
|
/**
|
|
5098
|
-
*
|
|
5099
|
-
*
|
|
5100
|
-
* can be torn down (see unregisterPackage /
|
|
5191
|
+
* Origin → the subgraph instances registered from it. Core and host
|
|
5192
|
+
* subgraphs are not tracked. Tracks the package association so that
|
|
5193
|
+
* removed packages can be torn down (see unregisterPackage /
|
|
5194
|
+
* prunePackageSubgraphs).
|
|
5101
5195
|
*/
|
|
5102
5196
|
packageSubgraphs = /* @__PURE__ */ new Map();
|
|
5197
|
+
#origins = /* @__PURE__ */ new WeakMap();
|
|
5198
|
+
/**
|
|
5199
|
+
* Package → the supergraph and subgraph classes (by subgraph name) it last
|
|
5200
|
+
* provided, so a subgraph refused or evicted for its name can register once
|
|
5201
|
+
* the name is free. `refused` keeps each one's instance until it is set
|
|
5202
|
+
* up, so the next attempt reuses it and a refusal that still holds logs
|
|
5203
|
+
* once.
|
|
5204
|
+
*/
|
|
5205
|
+
#packageClasses = /* @__PURE__ */ new Map();
|
|
5206
|
+
/** Registry changes run one at a time: a registration is admitted before
|
|
5207
|
+
* the awaits that complete it. */
|
|
5208
|
+
#registryChanges = Promise.resolve();
|
|
5209
|
+
/** Active while a subgraph hook runs, so a registry change the hook makes
|
|
5210
|
+
* runs inline instead of waiting on the change that called the hook. Work
|
|
5211
|
+
* the hook detaches, such as a timer, enqueues as usual once the hook has
|
|
5212
|
+
* settled; while the hook is pending it cannot be told from awaited work
|
|
5213
|
+
* and runs inline too. */
|
|
5214
|
+
#inHook = new AsyncLocalStorage();
|
|
5215
|
+
#generatedTypes;
|
|
5216
|
+
/** Document models refused from the schema, by id, with the reason logged. */
|
|
5217
|
+
#refusedModels = /* @__PURE__ */ new Map();
|
|
5218
|
+
/** Subgraphs excluded for a type collision, with the reason last logged. */
|
|
5219
|
+
#loggedCollisions = /* @__PURE__ */ new WeakMap();
|
|
5103
5220
|
/** Per-subgraph handlers by name, before auth/drive middleware is applied,
|
|
5104
5221
|
* for in-process queries by trusted internals. */
|
|
5105
5222
|
#internalSubgraphHandlers = /* @__PURE__ */ new Map();
|
|
@@ -5162,7 +5279,6 @@ var GraphQLManager = class {
|
|
|
5162
5279
|
this.#driveMiddleware = createDriveFetchMiddleware(this.driveOwnershipCache);
|
|
5163
5280
|
this.logger.debug(`Drive ownership cache populated with ${this.driveOwnershipCache.size()} drives`);
|
|
5164
5281
|
const models = (await this.reactorClient.getDocumentModelModules()).results;
|
|
5165
|
-
this.cachedDocumentModels = models;
|
|
5166
5282
|
if (!models.find((it) => it.documentModel.global.name === "DocumentDrive")) throw new Error("DocumentDrive model required");
|
|
5167
5283
|
await this.gatewayAdapter.start(this.httpServer);
|
|
5168
5284
|
this.httpAdapter.setupMiddleware({ bodyLimit: "50mb" });
|
|
@@ -5197,8 +5313,8 @@ var GraphQLManager = class {
|
|
|
5197
5313
|
};
|
|
5198
5314
|
this.httpAdapter.mount(driveRoutePath, this.#authMiddleware ? this.#authMiddleware(driveInfoHandler) : driveInfoHandler);
|
|
5199
5315
|
this.logger.info(`Registered REST endpoint: GET ${driveRoutePath}`);
|
|
5200
|
-
await this.#setupCoreSubgraphs("graphql", coreSubgraphs);
|
|
5201
|
-
if (this.featureFlags.enableDocumentModelSubgraphs) await this.#setupDocumentModelSubgraphs("graphql",
|
|
5316
|
+
await this.#setupCoreSubgraphs("graphql", coreSubgraphs, models);
|
|
5317
|
+
if (this.featureFlags.enableDocumentModelSubgraphs) await this.#setupDocumentModelSubgraphs("graphql", this.cachedDocumentModels);
|
|
5202
5318
|
await this.#createSupergraphGateway();
|
|
5203
5319
|
return this.updateRouter();
|
|
5204
5320
|
}
|
|
@@ -5208,26 +5324,55 @@ var GraphQLManager = class {
|
|
|
5208
5324
|
*/
|
|
5209
5325
|
async regenerateDocumentModelSubgraphs() {
|
|
5210
5326
|
if (!this.featureFlags.enableDocumentModelSubgraphs) return;
|
|
5327
|
+
await this.#serialize(() => this.#regenerateDocumentModelSubgraphs());
|
|
5328
|
+
}
|
|
5329
|
+
async #regenerateDocumentModelSubgraphs() {
|
|
5211
5330
|
try {
|
|
5212
5331
|
const models = (await this.reactorClient.getDocumentModelModules()).results;
|
|
5213
|
-
this.cachedDocumentModels = models;
|
|
5214
|
-
const registeredNames = await this.#setupDocumentModelSubgraphs("graphql",
|
|
5215
|
-
await this
|
|
5216
|
-
await this
|
|
5332
|
+
this.cachedDocumentModels = this.#admitModels(models);
|
|
5333
|
+
const registeredNames = await this.#setupDocumentModelSubgraphs("graphql", this.cachedDocumentModels);
|
|
5334
|
+
await this.#pruneOrigin(DOCUMENT_MODEL_ORIGIN, registeredNames);
|
|
5335
|
+
await this.#restorePackageSubgraphs();
|
|
5336
|
+
this.#scheduleRouterUpdate();
|
|
5217
5337
|
this.logger.info("Regenerated document model subgraphs with @count models", models.length);
|
|
5218
5338
|
} catch (error) {
|
|
5219
5339
|
this.logger.error("Failed to regenerate document model subgraphs: @error", error);
|
|
5220
5340
|
throw error;
|
|
5221
5341
|
}
|
|
5222
5342
|
}
|
|
5223
|
-
async #setupCoreSubgraphs(supergraph, coreSubgraphs) {
|
|
5343
|
+
async #setupCoreSubgraphs(supergraph, coreSubgraphs, models) {
|
|
5224
5344
|
for (const subgraph of coreSubgraphs) try {
|
|
5225
5345
|
await this.registerSubgraph(subgraph, supergraph, true);
|
|
5226
5346
|
} catch (error) {
|
|
5227
5347
|
this.logger.error("Failed to setup core subgraph @subgraph: @error", subgraph.name, error);
|
|
5228
5348
|
}
|
|
5349
|
+
this.cachedDocumentModels = this.#admitModels(models);
|
|
5229
5350
|
return this.#setupSubgraphs(this.coreSubgraphsMap);
|
|
5230
5351
|
}
|
|
5352
|
+
/**
|
|
5353
|
+
* The models whose generated types take no reserved name. The others stay
|
|
5354
|
+
* in the reactor but are left out of the schema.
|
|
5355
|
+
*/
|
|
5356
|
+
#admitModels(models) {
|
|
5357
|
+
const reserved = reservedTypeNames(Array.from(this.coreSubgraphsMap.values(), (subgraphs) => subgraphs.map((subgraph) => subgraph.typeDefs)).flat());
|
|
5358
|
+
const refused = /* @__PURE__ */ new Map();
|
|
5359
|
+
const admitted = models.filter((model) => {
|
|
5360
|
+
let taken;
|
|
5361
|
+
try {
|
|
5362
|
+
taken = reservedTypeNamesTaken(model, reserved);
|
|
5363
|
+
} catch {
|
|
5364
|
+
return true;
|
|
5365
|
+
}
|
|
5366
|
+
if (taken.length === 0) return true;
|
|
5367
|
+
const id = model.documentModel.global.id;
|
|
5368
|
+
const reason = `generates reserved type names: ${taken.join(", ")}`;
|
|
5369
|
+
refused.set(id, reason);
|
|
5370
|
+
if (this.#refusedModels.get(id) !== reason) this.logger.error("Refusing document model @documentType from the GraphQL schema: @reason", id, reason);
|
|
5371
|
+
return false;
|
|
5372
|
+
});
|
|
5373
|
+
this.#refusedModels = refused;
|
|
5374
|
+
return admitted;
|
|
5375
|
+
}
|
|
5231
5376
|
async #setupDocumentModelSubgraphs(supergraph, documentModels) {
|
|
5232
5377
|
const latestDocumentModels = filterLatestDocumentModelVersions(documentModels);
|
|
5233
5378
|
const registeredNames = /* @__PURE__ */ new Set();
|
|
@@ -5249,8 +5394,8 @@ var GraphQLManager = class {
|
|
|
5249
5394
|
attachments: this.attachments,
|
|
5250
5395
|
inspection: this.inspection
|
|
5251
5396
|
});
|
|
5252
|
-
await this.#addSubgraphInstance(subgraphInstance, supergraph, false,
|
|
5253
|
-
registeredNames.add(
|
|
5397
|
+
const registered = await this.#addSubgraphInstance(subgraphInstance, supergraph, false, DOCUMENT_MODEL_ORIGIN);
|
|
5398
|
+
if (registered) registeredNames.add(registered.name);
|
|
5254
5399
|
} catch (error) {
|
|
5255
5400
|
this.logger.error("Failed to setup document model subgraph for @documentType: @error", documentModel.documentModel.global.id, error instanceof Error ? error.message : error);
|
|
5256
5401
|
this.logger.debug("@error", error);
|
|
@@ -5258,41 +5403,181 @@ var GraphQLManager = class {
|
|
|
5258
5403
|
}
|
|
5259
5404
|
return registeredNames;
|
|
5260
5405
|
}
|
|
5261
|
-
/**
|
|
5262
|
-
|
|
5406
|
+
/** The first subgraph named `name` in `subgraphsMap`. */
|
|
5407
|
+
#findByName(subgraphsMap, name) {
|
|
5408
|
+
for (const subgraphs of subgraphsMap.values()) {
|
|
5409
|
+
const found = subgraphs.find((it) => it.name === name);
|
|
5410
|
+
if (found) return found;
|
|
5411
|
+
}
|
|
5412
|
+
}
|
|
5413
|
+
/** Every registered subgraph named `name`, core or not, in any bucket: the
|
|
5414
|
+
* in-process handler map is keyed by bare name, so a name has one owner. */
|
|
5415
|
+
#holdersOf(name) {
|
|
5416
|
+
const holders = /* @__PURE__ */ new Set();
|
|
5417
|
+
for (const subgraphsMap of [this.coreSubgraphsMap, this.subgraphs]) for (const subgraphs of subgraphsMap.values()) for (const subgraph of subgraphs) if (subgraph.name === name) holders.add(subgraph);
|
|
5418
|
+
return holders;
|
|
5419
|
+
}
|
|
5420
|
+
/** Core subgraph names are reserved: no other subgraph may take one. */
|
|
5263
5421
|
#isCoreNameReserved(name) {
|
|
5264
|
-
|
|
5265
|
-
return false;
|
|
5422
|
+
return this.#findByName(this.coreSubgraphsMap, name) !== void 0;
|
|
5266
5423
|
}
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5424
|
+
/** Buckets whose mount paths a registration into `supergraph` occupies: a
|
|
5425
|
+
* named supergraph's subgraphs are mounted under `graphql` as well. */
|
|
5426
|
+
#mountBuckets(supergraph) {
|
|
5427
|
+
return supergraph === "" || supergraph === "graphql" ? [supergraph] : [supergraph, "graphql"];
|
|
5428
|
+
}
|
|
5429
|
+
#generated() {
|
|
5430
|
+
if (this.#generatedTypes?.models !== this.cachedDocumentModels) this.#generatedTypes = {
|
|
5431
|
+
models: this.cachedDocumentModels,
|
|
5432
|
+
types: getGeneratedDocumentModelTypes(this.cachedDocumentModels)
|
|
5433
|
+
};
|
|
5434
|
+
return this.#generatedTypes.types;
|
|
5435
|
+
}
|
|
5436
|
+
#schemaOptions(subgraph) {
|
|
5437
|
+
return {
|
|
5438
|
+
generated: this.#generated(),
|
|
5439
|
+
ownTypeNames: subgraph instanceof DocumentModelSubgraph ? subgraph.generatedTypeNames : void 0
|
|
5440
|
+
};
|
|
5441
|
+
}
|
|
5442
|
+
/** The generated type names `subgraph` redefines under the current models. */
|
|
5443
|
+
#typeCollisions(subgraph) {
|
|
5444
|
+
try {
|
|
5445
|
+
return findSubgraphTypeCollisions(this.#generated(), subgraph.typeDefs, this.#schemaOptions(subgraph).ownTypeNames);
|
|
5446
|
+
} catch {
|
|
5447
|
+
return [];
|
|
5271
5448
|
}
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5449
|
+
}
|
|
5450
|
+
/** Whether a model loaded since registration collides with `subgraph`'s
|
|
5451
|
+
* types. Each new collision is logged once. */
|
|
5452
|
+
#isExcludedForTypes(subgraph) {
|
|
5453
|
+
const collisions = this.#typeCollisions(subgraph);
|
|
5454
|
+
if (collisions.length === 0) {
|
|
5455
|
+
this.#loggedCollisions.delete(subgraph);
|
|
5456
|
+
return false;
|
|
5457
|
+
}
|
|
5458
|
+
const reason = new SubgraphTypeCollisionError(collisions).message;
|
|
5459
|
+
if (this.#loggedCollisions.get(subgraph) !== reason) {
|
|
5460
|
+
this.#loggedCollisions.set(subgraph, reason);
|
|
5461
|
+
this.logger.error("Excluding subgraph @name: @error", subgraph.name, reason);
|
|
5462
|
+
}
|
|
5463
|
+
return true;
|
|
5464
|
+
}
|
|
5465
|
+
/**
|
|
5466
|
+
* Whether `instance` may register, and what it replaces. A name has one
|
|
5467
|
+
* holder across every bucket: the same origin replaces it, a higher rank
|
|
5468
|
+
* (core > host > document models > package) evicts it, and anything else is
|
|
5469
|
+
* refused.
|
|
5470
|
+
*/
|
|
5471
|
+
#admit(instance, core, origin) {
|
|
5472
|
+
if (!core && this.#isCoreNameReserved(instance.name)) {
|
|
5473
|
+
this.logger.error("Rejecting subgraph @name: name is reserved by a registered core subgraph", instance.name);
|
|
5474
|
+
return { action: "reject" };
|
|
5475
|
+
}
|
|
5476
|
+
const holders = this.#holdersOf(instance.name);
|
|
5477
|
+
if (holders.has(instance)) return {
|
|
5478
|
+
action: "skip",
|
|
5479
|
+
existing: instance
|
|
5480
|
+
};
|
|
5481
|
+
const rivals = Array.from(holders).filter((holder) => this.#originOf(holder) !== origin);
|
|
5482
|
+
for (const holder of rivals) {
|
|
5483
|
+
const holderOrigin = this.#originOf(holder);
|
|
5484
|
+
if (rank(origin) <= rank(holderOrigin)) {
|
|
5485
|
+
this.logger.error("Rejecting subgraph @name from @origin: name is taken by a subgraph from @existing", instance.name, describeOrigin(origin), describeOrigin(holderOrigin));
|
|
5486
|
+
return { action: "reject" };
|
|
5487
|
+
}
|
|
5488
|
+
}
|
|
5489
|
+
const collisions = core ? [] : this.#typeCollisions(instance);
|
|
5490
|
+
if (collisions.length > 0) {
|
|
5491
|
+
const reason = new SubgraphTypeCollisionError(collisions).message;
|
|
5492
|
+
if (this.#loggedCollisions.get(instance) !== reason) {
|
|
5493
|
+
this.#loggedCollisions.set(instance, reason);
|
|
5494
|
+
this.logger.error("Rejecting subgraph @name: @error", instance.name, reason);
|
|
5495
|
+
}
|
|
5496
|
+
return { action: "reject" };
|
|
5497
|
+
}
|
|
5498
|
+
return {
|
|
5499
|
+
action: "add",
|
|
5500
|
+
replaces: Array.from(holders).filter((it) => !rivals.includes(it)),
|
|
5501
|
+
evicts: rivals
|
|
5502
|
+
};
|
|
5503
|
+
}
|
|
5504
|
+
#originOf(instance) {
|
|
5505
|
+
return this.#origins.get(instance) ?? HOST_ORIGIN;
|
|
5506
|
+
}
|
|
5507
|
+
async #addSubgraphInstance(subgraphInstance, supergraph = "", core = false, origin = HOST_ORIGIN) {
|
|
5508
|
+
if (core) origin = CORE_ORIGIN;
|
|
5509
|
+
const admission = this.#admit(subgraphInstance, core, origin);
|
|
5510
|
+
if (admission.action === "reject") return void 0;
|
|
5511
|
+
if (admission.action === "skip") {
|
|
5275
5512
|
this.logger.debug(`Skipping duplicate subgraph: ${subgraphInstance.name}`);
|
|
5276
|
-
return
|
|
5277
|
-
}
|
|
5278
|
-
|
|
5279
|
-
await
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5513
|
+
return admission.existing;
|
|
5514
|
+
}
|
|
5515
|
+
const { replaces, evicts } = admission;
|
|
5516
|
+
for (const replaced of replaces) await this.#removeSubgraphInstance(replaced);
|
|
5517
|
+
if (typeof origin === "string") {
|
|
5518
|
+
const refused = this.#packageClasses.get(origin)?.refused;
|
|
5519
|
+
if (refused?.get(subgraphInstance.name) === subgraphInstance) refused.delete(subgraphInstance.name);
|
|
5520
|
+
}
|
|
5521
|
+
await this.#runHook(() => subgraphInstance.onSetup?.());
|
|
5522
|
+
for (const evicted of evicts) {
|
|
5523
|
+
this.logger.error("Evicting subgraph @name from @existing: @origin outranks it", subgraphInstance.name, describeOrigin(this.#originOf(evicted)), describeOrigin(origin));
|
|
5524
|
+
await this.#removeSubgraphInstance(evicted);
|
|
5525
|
+
}
|
|
5526
|
+
const subgraphsMap = core ? this.coreSubgraphsMap : this.subgraphs;
|
|
5527
|
+
for (const bucket of this.#mountBuckets(supergraph)) {
|
|
5528
|
+
const subgraphs = subgraphsMap.get(bucket);
|
|
5529
|
+
if (subgraphs) subgraphs.push(subgraphInstance);
|
|
5530
|
+
else if (bucket === supergraph) subgraphsMap.set(bucket, [subgraphInstance]);
|
|
5531
|
+
}
|
|
5532
|
+
this.#origins.set(subgraphInstance, origin);
|
|
5533
|
+
if (origin !== HOST_ORIGIN && origin !== CORE_ORIGIN) {
|
|
5534
|
+
let instances = this.packageSubgraphs.get(origin);
|
|
5535
|
+
if (!instances) {
|
|
5536
|
+
instances = /* @__PURE__ */ new Set();
|
|
5537
|
+
this.packageSubgraphs.set(origin, instances);
|
|
5289
5538
|
}
|
|
5290
|
-
|
|
5539
|
+
instances.add(subgraphInstance);
|
|
5291
5540
|
}
|
|
5292
|
-
this.logger.info(`${
|
|
5541
|
+
this.logger.info(`${replaces.length + evicts.length > 0 ? "Replaced" : "Registered"} ${this.path.endsWith("/") ? this.path : this.path + "/"}${supergraph ? supergraph + "/" : ""}${subgraphInstance.name} subgraph.`);
|
|
5293
5542
|
return subgraphInstance;
|
|
5294
5543
|
}
|
|
5295
5544
|
/**
|
|
5545
|
+
* Take `instance` off the mount paths of `buckets`. It is torn down
|
|
5546
|
+
* entirely unless it is still registered in another bucket.
|
|
5547
|
+
*/
|
|
5548
|
+
async #detachSubgraph(instance, buckets) {
|
|
5549
|
+
if (![this.coreSubgraphsMap, this.subgraphs].some((map) => Array.from(map).some(([bucket, subgraphs]) => !buckets.includes(bucket) && subgraphs.includes(instance)))) return this.#removeSubgraphInstance(instance);
|
|
5550
|
+
for (const subgraphsMap of [this.coreSubgraphsMap, this.subgraphs]) for (const bucket of buckets) {
|
|
5551
|
+
const subgraphs = subgraphsMap.get(bucket);
|
|
5552
|
+
if (!subgraphs?.includes(instance)) continue;
|
|
5553
|
+
subgraphsMap.set(bucket, subgraphs.filter((it) => it !== instance));
|
|
5554
|
+
await this.#unmountSubgraph(instance, bucket);
|
|
5555
|
+
}
|
|
5556
|
+
}
|
|
5557
|
+
/** Unmount what `instance` serves at its path in `bucket`: route, handler
|
|
5558
|
+
* cache, SSE route, WebSocket handler and in-process handler. */
|
|
5559
|
+
async #unmountSubgraph(instance, bucket) {
|
|
5560
|
+
const subgraphPath = this.#getSubgraphPath(instance, bucket);
|
|
5561
|
+
if (this.subgraphHandlerCache.get(subgraphPath)?.subgraph !== instance) return;
|
|
5562
|
+
this.subgraphHandlerCache.delete(subgraphPath);
|
|
5563
|
+
const routeHandle = this.subgraphRouteHandles.get(subgraphPath);
|
|
5564
|
+
if (routeHandle !== void 0) {
|
|
5565
|
+
routeHandle.dispose();
|
|
5566
|
+
this.subgraphRouteHandles.delete(subgraphPath);
|
|
5567
|
+
}
|
|
5568
|
+
this.#disposeSSERoute(subgraphPath);
|
|
5569
|
+
if (this.#internalSubgraphHandlers.get(instance.name)?.path === subgraphPath) this.#internalSubgraphHandlers.delete(instance.name);
|
|
5570
|
+
const wsDisposer = this.subgraphWsDisposers.get(subgraphPath);
|
|
5571
|
+
if (wsDisposer) {
|
|
5572
|
+
this.subgraphWsDisposers.delete(subgraphPath);
|
|
5573
|
+
try {
|
|
5574
|
+
await wsDisposer.dispose();
|
|
5575
|
+
} catch (error) {
|
|
5576
|
+
this.logger.error("Error disposing subgraph websocket @name: @error", instance.name, error);
|
|
5577
|
+
}
|
|
5578
|
+
}
|
|
5579
|
+
}
|
|
5580
|
+
/**
|
|
5296
5581
|
* Tear down a subgraph instance: disconnect it, drop it from every
|
|
5297
5582
|
* bucket, unmount its route, dispose its WebSocket handler, and remove
|
|
5298
5583
|
* its internal handler. Used when a subgraph is replaced or its package
|
|
@@ -5300,44 +5585,62 @@ var GraphQLManager = class {
|
|
|
5300
5585
|
*/
|
|
5301
5586
|
async #removeSubgraphInstance(instance) {
|
|
5302
5587
|
try {
|
|
5303
|
-
await instance.onDisconnect?.();
|
|
5588
|
+
await this.#runHook(() => instance.onDisconnect?.());
|
|
5304
5589
|
} catch (error) {
|
|
5305
5590
|
this.logger.error("Error disconnecting subgraph @name: @error", instance.name, error);
|
|
5306
5591
|
}
|
|
5307
5592
|
for (const subgraphsMap of [this.coreSubgraphsMap, this.subgraphs]) for (const [bucket, subgraphs] of subgraphsMap.entries()) {
|
|
5308
5593
|
if (!subgraphs.includes(instance)) continue;
|
|
5309
5594
|
subgraphsMap.set(bucket, subgraphs.filter((it) => it !== instance));
|
|
5310
|
-
|
|
5311
|
-
this.subgraphHandlerCache.delete(subgraphPath);
|
|
5312
|
-
const routeHandle = this.subgraphRouteHandles.get(subgraphPath);
|
|
5313
|
-
if (routeHandle !== void 0) {
|
|
5314
|
-
routeHandle.dispose();
|
|
5315
|
-
this.subgraphRouteHandles.delete(subgraphPath);
|
|
5316
|
-
}
|
|
5317
|
-
this.#disposeSSERoute(subgraphPath);
|
|
5318
|
-
const wsDisposer = this.subgraphWsDisposers.get(subgraphPath);
|
|
5319
|
-
if (wsDisposer) {
|
|
5320
|
-
this.subgraphWsDisposers.delete(subgraphPath);
|
|
5321
|
-
try {
|
|
5322
|
-
await wsDisposer.dispose();
|
|
5323
|
-
} catch (error) {
|
|
5324
|
-
this.logger.error("Error disposing subgraph websocket @name: @error", instance.name, error);
|
|
5325
|
-
}
|
|
5326
|
-
}
|
|
5595
|
+
await this.#unmountSubgraph(instance, bucket);
|
|
5327
5596
|
}
|
|
5328
5597
|
if (this.#internalSubgraphHandlers.get(instance.name)?.subgraph === instance) this.#internalSubgraphHandlers.delete(instance.name);
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5598
|
+
const origin = this.#origins.get(instance);
|
|
5599
|
+
this.#origins.delete(instance);
|
|
5600
|
+
if (origin === void 0 || origin === HOST_ORIGIN || origin === CORE_ORIGIN) return;
|
|
5601
|
+
const instances = this.packageSubgraphs.get(origin);
|
|
5602
|
+
instances?.delete(instance);
|
|
5603
|
+
if (instances?.size === 0) this.packageSubgraphs.delete(origin);
|
|
5334
5604
|
}
|
|
5335
5605
|
/**
|
|
5336
5606
|
* Register a pre-constructed subgraph instance.
|
|
5337
5607
|
* Use this when you need to pass custom dependencies to a subgraph.
|
|
5338
5608
|
*/
|
|
5339
5609
|
async registerSubgraphInstance(subgraphInstance, supergraph = "", core = false) {
|
|
5340
|
-
return this.#addSubgraphInstance(subgraphInstance, supergraph, core);
|
|
5610
|
+
return this.#serialize(() => this.#addSubgraphInstance(subgraphInstance, supergraph, core));
|
|
5611
|
+
}
|
|
5612
|
+
#serialize(task) {
|
|
5613
|
+
if (this.#inHook.getStore()?.active) return task();
|
|
5614
|
+
const run = this.#registryChanges.then(() => this.#inHook.exit(task));
|
|
5615
|
+
this.#registryChanges = run.catch(() => void 0);
|
|
5616
|
+
return run;
|
|
5617
|
+
}
|
|
5618
|
+
async #runHook(hook) {
|
|
5619
|
+
const scope = { active: true };
|
|
5620
|
+
try {
|
|
5621
|
+
await this.#inHook.run(scope, hook);
|
|
5622
|
+
} finally {
|
|
5623
|
+
scope.active = false;
|
|
5624
|
+
}
|
|
5625
|
+
}
|
|
5626
|
+
/** Refresh the router after a registry change; scheduled rather than
|
|
5627
|
+
* awaited when called from inside one. */
|
|
5628
|
+
async #refreshRouter() {
|
|
5629
|
+
if (this.#inHook.getStore()?.active) {
|
|
5630
|
+
this.#scheduleRouterUpdate();
|
|
5631
|
+
return;
|
|
5632
|
+
}
|
|
5633
|
+
await this.updateRouter();
|
|
5634
|
+
}
|
|
5635
|
+
/** Not awaited: the debounced call never settles a promise whose timer a
|
|
5636
|
+
* later call replaced, so awaiting it in a registry change could wedge the
|
|
5637
|
+
* queue. */
|
|
5638
|
+
#scheduleRouterUpdate() {
|
|
5639
|
+
this.#inHook.exit(() => {
|
|
5640
|
+
this.updateRouter().catch((error) => {
|
|
5641
|
+
this.logger.error("Failed to update router: @error", error);
|
|
5642
|
+
});
|
|
5643
|
+
});
|
|
5341
5644
|
}
|
|
5342
5645
|
/**
|
|
5343
5646
|
* Get the base path used for subgraph registration.
|
|
@@ -5374,7 +5677,45 @@ var GraphQLManager = class {
|
|
|
5374
5677
|
* webhooks live under.
|
|
5375
5678
|
*/
|
|
5376
5679
|
async registerSubgraph(subgraph, supergraph = "", core = false, packageName) {
|
|
5377
|
-
|
|
5680
|
+
return this.#serialize(() => {
|
|
5681
|
+
const instance = this.#createSubgraphInstance(subgraph, packageName);
|
|
5682
|
+
if (packageName !== void 0 && !core) this.#recordPackageClass(packageName, supergraph, instance, subgraph);
|
|
5683
|
+
return this.#addSubgraphInstance(instance, supergraph, core, packageName ?? HOST_ORIGIN);
|
|
5684
|
+
});
|
|
5685
|
+
}
|
|
5686
|
+
#recordPackageClass(packageName, supergraph, instance, subgraph) {
|
|
5687
|
+
let entry = this.#packageClasses.get(packageName);
|
|
5688
|
+
if (!entry) {
|
|
5689
|
+
entry = {
|
|
5690
|
+
supergraph,
|
|
5691
|
+
classes: /* @__PURE__ */ new Map(),
|
|
5692
|
+
refused: /* @__PURE__ */ new Map()
|
|
5693
|
+
};
|
|
5694
|
+
this.#packageClasses.set(packageName, entry);
|
|
5695
|
+
}
|
|
5696
|
+
entry.classes.set(instance.name, subgraph);
|
|
5697
|
+
entry.refused.set(instance.name, instance);
|
|
5698
|
+
}
|
|
5699
|
+
/** Register package subgraphs that are missing because their name was
|
|
5700
|
+
* taken when they last tried, now that the name may be free. */
|
|
5701
|
+
async #restorePackageSubgraphs() {
|
|
5702
|
+
for (const [packageName, { supergraph, classes, refused }] of this.#packageClasses) {
|
|
5703
|
+
const registered = Array.from(this.packageSubgraphs.get(packageName) ?? [], (it) => it.name);
|
|
5704
|
+
for (const [name, subgraph] of classes) {
|
|
5705
|
+
if (registered.includes(name)) continue;
|
|
5706
|
+
if (this.#holdersOf(name).size > 0) continue;
|
|
5707
|
+
try {
|
|
5708
|
+
const instance = refused.get(name) ?? this.#createSubgraphInstance(subgraph, packageName);
|
|
5709
|
+
refused.set(name, instance);
|
|
5710
|
+
await this.#addSubgraphInstance(instance, supergraph, false, packageName);
|
|
5711
|
+
} catch (error) {
|
|
5712
|
+
this.logger.error("Failed to restore subgraph @name from @package: @error", name, packageName, error);
|
|
5713
|
+
}
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
}
|
|
5717
|
+
#createSubgraphInstance(subgraph, packageName) {
|
|
5718
|
+
return new subgraph({
|
|
5378
5719
|
http: this.scopeForPackage(packageName ?? "@powerhousedao/reactor-api"),
|
|
5379
5720
|
relationalDb: this.relationalDb,
|
|
5380
5721
|
analyticsStore: this.analyticsStore,
|
|
@@ -5388,7 +5729,44 @@ var GraphQLManager = class {
|
|
|
5388
5729
|
attachments: this.attachments,
|
|
5389
5730
|
inspection: this.inspection
|
|
5390
5731
|
});
|
|
5391
|
-
|
|
5732
|
+
}
|
|
5733
|
+
/**
|
|
5734
|
+
* Apply a package change: `packaged` holds every loaded package's subgraph
|
|
5735
|
+
* classes. Removals run before additions, so a name one package gives up
|
|
5736
|
+
* can be taken by another in the same change. Changes apply one at a time;
|
|
5737
|
+
* the router refresh is scheduled, not awaited.
|
|
5738
|
+
*/
|
|
5739
|
+
applyPackageSubgraphs(packaged, supergraph = "graphql") {
|
|
5740
|
+
return this.#serialize(() => this.#applyPackageSubgraphs(packaged, supergraph));
|
|
5741
|
+
}
|
|
5742
|
+
async #applyPackageSubgraphs(packaged, supergraph) {
|
|
5743
|
+
const known = /* @__PURE__ */ new Set([...this.#packageClasses.keys(), ...Array.from(this.packageSubgraphs.keys()).filter((origin) => typeof origin === "string")]);
|
|
5744
|
+
for (const packageName of known) if (!packaged.has(packageName)) await this.#teardownPackage(packageName);
|
|
5745
|
+
this.#packageClasses = /* @__PURE__ */ new Map();
|
|
5746
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
5747
|
+
for (const [packageName, classes] of packaged) {
|
|
5748
|
+
const instances = [];
|
|
5749
|
+
for (const subgraph of classes) try {
|
|
5750
|
+
const instance = this.#createSubgraphInstance(subgraph, packageName);
|
|
5751
|
+
this.#recordPackageClass(packageName, supergraph, instance, subgraph);
|
|
5752
|
+
instances.push(instance);
|
|
5753
|
+
} catch (error) {
|
|
5754
|
+
this.logger.error("Failed to create subgraph @subgraph from @package: @error", subgraph.name, packageName, error);
|
|
5755
|
+
}
|
|
5756
|
+
incoming.set(packageName, instances);
|
|
5757
|
+
await this.#pruneOrigin(packageName, new Set(instances.map((it) => it.name)));
|
|
5758
|
+
}
|
|
5759
|
+
for (const [packageName, instances] of incoming) {
|
|
5760
|
+
const registered = /* @__PURE__ */ new Set();
|
|
5761
|
+
for (const instance of instances) try {
|
|
5762
|
+
const result = await this.#addSubgraphInstance(instance, supergraph, false, packageName);
|
|
5763
|
+
if (result) registered.add(result.name);
|
|
5764
|
+
} catch (error) {
|
|
5765
|
+
this.logger.error("Failed to register subgraph @name from @package: @error", instance.name, packageName, error);
|
|
5766
|
+
}
|
|
5767
|
+
await this.#pruneOrigin(packageName, registered);
|
|
5768
|
+
}
|
|
5769
|
+
this.#scheduleRouterUpdate();
|
|
5392
5770
|
}
|
|
5393
5771
|
/**
|
|
5394
5772
|
* Tear down every subgraph instance registered from `packageName`:
|
|
@@ -5398,11 +5776,20 @@ var GraphQLManager = class {
|
|
|
5398
5776
|
* package has no registered subgraphs.
|
|
5399
5777
|
*/
|
|
5400
5778
|
async unregisterPackage(packageName) {
|
|
5779
|
+
if (await this.#serialize(async () => {
|
|
5780
|
+
if (!await this.#teardownPackage(packageName)) return false;
|
|
5781
|
+
await this.#restorePackageSubgraphs();
|
|
5782
|
+
return true;
|
|
5783
|
+
})) await this.#refreshRouter();
|
|
5784
|
+
}
|
|
5785
|
+
/** Release the package's routes and subgraphs; whether any subgraph went. */
|
|
5786
|
+
async #teardownPackage(packageName) {
|
|
5401
5787
|
this.#disposeHttpScope(packageName);
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
await this
|
|
5788
|
+
this.#packageClasses.delete(packageName);
|
|
5789
|
+
const instances = this.packageSubgraphs.get(packageName);
|
|
5790
|
+
if (!instances || instances.size === 0) return false;
|
|
5791
|
+
for (const instance of Array.from(instances)) await this.#removeSubgraphInstance(instance);
|
|
5792
|
+
return true;
|
|
5406
5793
|
}
|
|
5407
5794
|
/**
|
|
5408
5795
|
* Releases the package's HTTP scope: every route it mounted, and its webhook
|
|
@@ -5422,21 +5809,28 @@ var GraphQLManager = class {
|
|
|
5422
5809
|
* subgraphs. Refreshes the router if anything was removed.
|
|
5423
5810
|
*/
|
|
5424
5811
|
async prunePackageSubgraphs(packageName, keepNames) {
|
|
5425
|
-
|
|
5426
|
-
|
|
5812
|
+
if (await this.#serialize(async () => {
|
|
5813
|
+
const classes = this.#packageClasses.get(packageName)?.classes;
|
|
5814
|
+
for (const name of Array.from(classes?.keys() ?? [])) if (!keepNames.has(name)) classes?.delete(name);
|
|
5815
|
+
const pruned = await this.#pruneOrigin(packageName, keepNames);
|
|
5816
|
+
if (pruned > 0) await this.#restorePackageSubgraphs();
|
|
5817
|
+
return pruned;
|
|
5818
|
+
}) > 0) await this.#refreshRouter();
|
|
5819
|
+
}
|
|
5820
|
+
/** Remove the origin's subgraphs not named in `keepNames`; how many went. */
|
|
5821
|
+
async #pruneOrigin(origin, keepNames) {
|
|
5822
|
+
const instances = this.packageSubgraphs.get(origin);
|
|
5823
|
+
if (!instances) return 0;
|
|
5427
5824
|
let removed = 0;
|
|
5428
|
-
for (const
|
|
5825
|
+
for (const instance of Array.from(instances)) if (!keepNames.has(instance.name)) {
|
|
5429
5826
|
await this.#removeSubgraphInstance(instance);
|
|
5430
5827
|
removed++;
|
|
5431
5828
|
}
|
|
5432
|
-
|
|
5829
|
+
return removed;
|
|
5433
5830
|
}
|
|
5434
5831
|
/** Find a registered subgraph by name, core or package-contributed. */
|
|
5435
5832
|
getSubgraphByName(name) {
|
|
5436
|
-
|
|
5437
|
-
const found = subgraphs.find((subgraph) => subgraph.name === name);
|
|
5438
|
-
if (found) return found;
|
|
5439
|
-
}
|
|
5833
|
+
return this.#findByName(this.coreSubgraphsMap, name) ?? this.#findByName(this.subgraphs, name);
|
|
5440
5834
|
}
|
|
5441
5835
|
/** Whether a registered subgraph has a live handler, i.e. whether
|
|
5442
5836
|
* {@link executeSubgraphQuery} can reach it right now. */
|
|
@@ -5472,6 +5866,7 @@ var GraphQLManager = class {
|
|
|
5472
5866
|
updateRouter = debounce(this._updateRouter.bind(this), 1e3);
|
|
5473
5867
|
async _updateRouter() {
|
|
5474
5868
|
this.logger.debug("Updating router");
|
|
5869
|
+
await this.#setupSubgraphs(this.coreSubgraphsMap);
|
|
5475
5870
|
await this.#setupSubgraphs(this.subgraphs);
|
|
5476
5871
|
try {
|
|
5477
5872
|
await this.gatewayAdapter.updateSupergraph();
|
|
@@ -5521,20 +5916,20 @@ var GraphQLManager = class {
|
|
|
5521
5916
|
})
|
|
5522
5917
|
});
|
|
5523
5918
|
}
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5919
|
+
/** Replace the subgraphs of `supergraph` with `subgraphs`, under the same
|
|
5920
|
+
* name and type guards as any registration. */
|
|
5921
|
+
async setSupergraph(supergraph, subgraphs) {
|
|
5922
|
+
await this.#serialize(async () => {
|
|
5923
|
+
if (supergraph !== "" && !this.subgraphs.has("graphql")) this.subgraphs.set("graphql", []);
|
|
5924
|
+
let detached = false;
|
|
5925
|
+
for (const previous of [...this.subgraphs.get(supergraph) ?? []]) if (!subgraphs.includes(previous)) {
|
|
5926
|
+
await this.#detachSubgraph(previous, this.#mountBuckets(supergraph));
|
|
5927
|
+
detached = true;
|
|
5530
5928
|
}
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
if (globalSubgraphs) this.subgraphs.set("graphql", [...globalSubgraphs, ...accepted]);
|
|
5536
|
-
else this.subgraphs.set("graphql", accepted);
|
|
5537
|
-
return this.updateRouter();
|
|
5929
|
+
for (const subgraph of subgraphs) await this.#addSubgraphInstance(subgraph, supergraph, false, HOST_ORIGIN);
|
|
5930
|
+
if (detached) await this.#restorePackageSubgraphs();
|
|
5931
|
+
});
|
|
5932
|
+
return this.#refreshRouter();
|
|
5538
5933
|
}
|
|
5539
5934
|
async shutdown() {
|
|
5540
5935
|
this.logger.info("Shutting down GraphQL Manager");
|
|
@@ -5569,13 +5964,17 @@ var GraphQLManager = class {
|
|
|
5569
5964
|
for (const [supergraph, subgraphs] of subgraphsMap.entries()) for (const subgraph of subgraphs) {
|
|
5570
5965
|
this.logger.debug(`Setting up subgraph ${subgraph.name}`);
|
|
5571
5966
|
const subgraphPath = this.#getSubgraphPath(subgraph, supergraph);
|
|
5967
|
+
if (this.#isExcludedForTypes(subgraph)) {
|
|
5968
|
+
await this.#unmountSubgraph(subgraph, supergraph);
|
|
5969
|
+
continue;
|
|
5970
|
+
}
|
|
5572
5971
|
try {
|
|
5573
5972
|
const cached = this.subgraphHandlerCache.get(subgraphPath);
|
|
5574
5973
|
if (cached) {
|
|
5575
5974
|
if (cached.subgraph !== subgraph) this.logger.warn("Subgraph path @path already mounted by @kept; @name is shadowed and will not be mounted", subgraphPath, cached.subgraph.name, subgraph.name);
|
|
5576
5975
|
continue;
|
|
5577
5976
|
}
|
|
5578
|
-
const schema = createSchema(this.cachedDocumentModels, subgraph.resolvers, subgraph.typeDefs);
|
|
5977
|
+
const schema = createSchema(this.cachedDocumentModels, subgraph.resolvers, subgraph.typeDefs, this.#schemaOptions(subgraph));
|
|
5579
5978
|
const rawHandler = await this.gatewayAdapter.createHandler(schema, this.#makeContextFactory());
|
|
5580
5979
|
const fetchHandler = this.#composeFetchMiddleware(rawHandler);
|
|
5581
5980
|
this.subgraphHandlerCache.set(subgraphPath, {
|
|
@@ -5611,26 +6010,35 @@ var GraphQLManager = class {
|
|
|
5611
6010
|
if (supergraph === "") continue;
|
|
5612
6011
|
for (const subgraph of subgraphs) {
|
|
5613
6012
|
const subgraphPath = this.#getSubgraphPath(subgraph, supergraph);
|
|
5614
|
-
subgraphsMap.set(subgraphPath, subgraph);
|
|
6013
|
+
if (!subgraphsMap.has(subgraphPath)) subgraphsMap.set(subgraphPath, subgraph);
|
|
5615
6014
|
}
|
|
5616
6015
|
}
|
|
5617
6016
|
return subgraphsMap;
|
|
5618
6017
|
}
|
|
5619
6018
|
#buildSubgraphSchemaModule(subgraph) {
|
|
5620
|
-
return buildSubgraphSchemaModule(this.cachedDocumentModels, subgraph.resolvers, subgraph.typeDefs);
|
|
6019
|
+
return buildSubgraphSchemaModule(this.cachedDocumentModels, subgraph.resolvers, subgraph.typeDefs, this.#schemaOptions(subgraph));
|
|
5621
6020
|
}
|
|
5622
6021
|
#getSubgraphDefinitions() {
|
|
5623
6022
|
const subgraphs = this.#getAllSubgraphs();
|
|
5624
6023
|
const herokuOrLocal = process.env.HEROKU_APP_DEFAULT_DOMAIN_NAME ? `https://${process.env.HEROKU_APP_DEFAULT_DOMAIN_NAME}` : `http://localhost:${this.port}`;
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
6024
|
+
const definitions = [];
|
|
6025
|
+
for (const [subgraphPath, subgraph] of subgraphs) {
|
|
6026
|
+
if (this.#isExcludedForTypes(subgraph)) continue;
|
|
6027
|
+
let module;
|
|
6028
|
+
try {
|
|
6029
|
+
module = this.#buildSubgraphSchemaModule(subgraph);
|
|
6030
|
+
} catch (error) {
|
|
6031
|
+
this.logger.error("Excluding subgraph @name from the supergraph: @error", subgraph.name, error instanceof Error ? error.message : error);
|
|
6032
|
+
continue;
|
|
6033
|
+
}
|
|
6034
|
+
definitions.push({
|
|
5628
6035
|
name: subgraphPath.replace("/", ":"),
|
|
5629
6036
|
typeDefs: module.typeDefs,
|
|
5630
6037
|
resolvers: module.resolvers,
|
|
5631
6038
|
url: `${herokuOrLocal}${subgraphPath}`
|
|
5632
|
-
};
|
|
5633
|
-
}
|
|
6039
|
+
});
|
|
6040
|
+
}
|
|
6041
|
+
return definitions;
|
|
5634
6042
|
}
|
|
5635
6043
|
async #createSupergraphGateway() {
|
|
5636
6044
|
const superGraphPath = path.posix.join(this.path, "graphql");
|
|
@@ -5651,7 +6059,16 @@ var GraphQLManager = class {
|
|
|
5651
6059
|
*/
|
|
5652
6060
|
#setupSupergraphSSE(superGraphPath) {
|
|
5653
6061
|
const allSubgraphs = this.#getAllSubgraphs();
|
|
5654
|
-
const modules =
|
|
6062
|
+
const modules = [];
|
|
6063
|
+
for (const subgraph of allSubgraphs.values()) {
|
|
6064
|
+
if (!subgraph.hasSubscriptions) continue;
|
|
6065
|
+
if (this.#isExcludedForTypes(subgraph)) continue;
|
|
6066
|
+
try {
|
|
6067
|
+
modules.push(this.#buildSubgraphSchemaModule(subgraph));
|
|
6068
|
+
} catch (error) {
|
|
6069
|
+
this.logger.error("Excluding subgraph @name from supergraph SSE: @error", subgraph.name, error instanceof Error ? error.message : error);
|
|
6070
|
+
}
|
|
6071
|
+
}
|
|
5655
6072
|
if (modules.length === 0) {
|
|
5656
6073
|
this.#disposeSSERoute(superGraphPath);
|
|
5657
6074
|
return;
|
|
@@ -7602,10 +8019,10 @@ const ADMIN_USERS = getAdminUsers();
|
|
|
7602
8019
|
//#endregion
|
|
7603
8020
|
//#region src/graphql/system/version.ts
|
|
7604
8021
|
function getVersion() {
|
|
7605
|
-
return "6.2.3-dev.
|
|
8022
|
+
return "6.2.3-dev.55";
|
|
7606
8023
|
}
|
|
7607
8024
|
function getGitHash() {
|
|
7608
|
-
return "
|
|
8025
|
+
return "0d98e7d237fd518eeee791888782d2d3b5d1ff57";
|
|
7609
8026
|
}
|
|
7610
8027
|
function getGitUrl() {
|
|
7611
8028
|
return buildTreeUrl(getGitHash());
|
|
@@ -10252,7 +10669,7 @@ async function setupGraphQLManager({ httpAdapter, authFetchMiddleware, requireAu
|
|
|
10252
10669
|
driveStore
|
|
10253
10670
|
});
|
|
10254
10671
|
await graphqlManager.init(subgraphs.core, authFetchMiddleware, requireAuthFetchMiddleware);
|
|
10255
|
-
|
|
10672
|
+
await graphqlManager.applyPackageSubgraphs(subgraphs.extended);
|
|
10256
10673
|
await graphqlManager.updateRouter();
|
|
10257
10674
|
return graphqlManager;
|
|
10258
10675
|
}
|
|
@@ -10277,42 +10694,47 @@ function setupEventListeners(pkgManager, graphqlManager, reactorProcessorManager
|
|
|
10277
10694
|
for (const result of manifestResults) if (result.status === "error") defaultLogger.error(`Failed to register upgrade manifest: ${result.error.message}`);
|
|
10278
10695
|
}
|
|
10279
10696
|
}
|
|
10280
|
-
graphqlManager.regenerateDocumentModelSubgraphs()
|
|
10697
|
+
graphqlManager.regenerateDocumentModelSubgraphs().catch((error) => {
|
|
10698
|
+
defaultLogger.error("Document model change left subgraphs stale: @error", error);
|
|
10699
|
+
});
|
|
10281
10700
|
});
|
|
10282
|
-
let knownSubgraphPackages = /* @__PURE__ */ new Set();
|
|
10283
10701
|
pkgManager.onSubgraphsChange((packagedSubgraphs) => {
|
|
10284
|
-
(
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
for (const subgraph of subgraphs) {
|
|
10288
|
-
const instance = await graphqlManager.registerSubgraph(subgraph, "graphql", false, packageName);
|
|
10289
|
-
if (!instance) continue;
|
|
10290
|
-
incomingNames.add(instance.name);
|
|
10291
|
-
}
|
|
10292
|
-
await graphqlManager.prunePackageSubgraphs(packageName, incomingNames);
|
|
10293
|
-
}
|
|
10294
|
-
for (const packageName of knownSubgraphPackages) if (!packagedSubgraphs.has(packageName)) await graphqlManager.unregisterPackage(packageName);
|
|
10295
|
-
knownSubgraphPackages = new Set(packagedSubgraphs.keys());
|
|
10296
|
-
await graphqlManager.updateRouter();
|
|
10297
|
-
})();
|
|
10702
|
+
graphqlManager.applyPackageSubgraphs(packagedSubgraphs).catch((error) => {
|
|
10703
|
+
defaultLogger.error("Failed to apply package subgraphs: @error", error);
|
|
10704
|
+
});
|
|
10298
10705
|
});
|
|
10299
10706
|
let knownProcessorPackages = /* @__PURE__ */ new Set();
|
|
10300
10707
|
pkgManager.onProcessorsChange((processors) => {
|
|
10301
10708
|
(async () => {
|
|
10302
|
-
for (const packageName of knownProcessorPackages) if (!processors.has(packageName))
|
|
10709
|
+
for (const packageName of knownProcessorPackages) if (!processors.has(packageName)) try {
|
|
10710
|
+
await reactorProcessorManager.unregisterFactory(packageName);
|
|
10711
|
+
} catch (error) {
|
|
10712
|
+
defaultLogger.error("Failed to unregister processors of @package: @error", packageName, error);
|
|
10713
|
+
}
|
|
10303
10714
|
knownProcessorPackages = new Set(processors.keys());
|
|
10304
10715
|
for (const [packageName, fns] of processors) {
|
|
10305
|
-
|
|
10306
|
-
|
|
10716
|
+
try {
|
|
10717
|
+
await reactorProcessorManager.unregisterFactory(packageName);
|
|
10718
|
+
} catch (error) {
|
|
10719
|
+
defaultLogger.error("Failed to unregister processors of @package: @error", packageName, error);
|
|
10720
|
+
}
|
|
10721
|
+
const factories = await Promise.allSettled(fns.map(async (fn) => fn(moduleFor(packageName))));
|
|
10722
|
+
const validBuilders = [];
|
|
10723
|
+
for (const factory of factories) if (factory.status === "rejected") defaultLogger.error("Processor factory builder of @package failed: @error", packageName, factory.reason);
|
|
10724
|
+
else if (typeof factory.value === "function") validBuilders.push(factory.value);
|
|
10307
10725
|
if (!validBuilders.length) continue;
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10726
|
+
try {
|
|
10727
|
+
await reactorProcessorManager.registerFactory(packageName, async (driveHeader) => (await Promise.all(validBuilders.map(async (driveFactory) => {
|
|
10728
|
+
try {
|
|
10729
|
+
return await driveFactory(driveHeader);
|
|
10730
|
+
} catch (e) {
|
|
10731
|
+
defaultLogger.error(`Error creating processor for drive ${driveHeader.id}:`, e);
|
|
10732
|
+
return [];
|
|
10733
|
+
}
|
|
10734
|
+
}))).flat());
|
|
10735
|
+
} catch (error) {
|
|
10736
|
+
defaultLogger.error("Failed to register processors of @package: @error", packageName, error);
|
|
10737
|
+
}
|
|
10316
10738
|
}
|
|
10317
10739
|
})();
|
|
10318
10740
|
});
|
|
@@ -10911,7 +11333,7 @@ var PackageManagementService = class {
|
|
|
10911
11333
|
}
|
|
10912
11334
|
};
|
|
10913
11335
|
//#endregion
|
|
10914
|
-
export { ADMIN_USERS, ActionCandidateInputSchema, ActionContextInputSchema, ActionInputSchema, AddRelationshipDocument, AnalyticsSubgraph, AttachmentAccessFailed, AttachmentAccessService, AttachmentAccessUnavailable, AttachmentClientProvider, AuthDecision, AuthDecisionSchema, AuthEvaluationUnsupportedError, AuthService, AuthSubgraph, AuthenticationRequiredError, AuthorizationPolicy, AuthorizedAttachmentService, AuthorizedDocumentHandle, BaseSubgraph, CORE_PACKAGE_NAME, CanonicalDocumentIdResolutionError, ChannelMetaInputSchema, CreateDocumentDocument, CreateEmptyDocumentDocument, DeleteDocumentDocument, DeleteDocumentsDocument, DocumentChangeType, DocumentChangeTypeSchema, DocumentChangesDocument, DocumentOperationsFilterInputSchema, DocumentPermissionService, DocumentRelationshipFieldsFragmentDoc, EvaluateActionsDocument, ExecuteBatchDocument, ExecutionJobInputSchema, FindDocumentsDocument, ForbiddenError, GetCreateDefaultsDocument, GetDocumentDocument, GetDocumentIncomingRelationshipEdgesDocument, GetDocumentIncomingRelationshipsDocument, GetDocumentModelsDocument, GetDocumentOperationsDocument, GetDocumentOutgoingRelationshipEdgesDocument, GetDocumentOutgoingRelationshipsDocument, GetDocumentServedDocument, GetDocumentWithOperationsDocument, GetJobStatusDocument, GraphQLManager, HttpDocumentModelLoader, HttpPackageLoader, HttpRouteService, ImportPackageLoader, InMemoryPackageStorage, InspectionSubgraph, InvalidNamespaceError, JobChangesDocument, JobInfoFieldsFragmentDoc, MalformedStoredOperationError, MemoryWebhookStore, MoveRelationshipDocument, MutateDocumentAsyncDocument, MutateDocumentDocument, OperationContextInputSchema, OperationInputSchema, OperationWithContextInputSchema, OperationsFilterInputSchema, PACKAGE_ROUTE_SEGMENT, PGLITE_UTC_PARSERS, PackageManagementService, PackageManager, PackagesSubgraph, PagingInputSchema, PhDocumentFieldsFragmentDoc, PollSyncEnvelopesDocument, PrivacyPermissionAdapter, PropagationMode, PropagationModeSchema, PushSyncEnvelopesDocument, ReactorSignerAppInputSchema, ReactorSignerInputSchema, ReactorSignerUserInputSchema, ReactorSubgraph, RefusalNotRecordedError, RelationalWebhookStore, RemoteCursorInputSchema, RemoteFilterInputSchema, RemoveRelationshipDocument, RenameDocumentDocument, SearchFilterInputSchema, SetPreferredEditorDocument, SyncEnvelopeInputSchema, SyncEnvelopeType, SyncEnvelopeTypeSchema, SyncRefusalInputSchema, SystemSubgraph, TouchChannelDocument, TouchChannelInputSchema, UpdateRelationshipDocument, ViewFilterInputSchema, WEBHOOK_SEGMENT, WS_AUTH_CLOSE_REASONS, WS_CLOSE_REASON_AUTHENTICATION_REQUIRED, WS_CLOSE_REASON_BEARER_REJECTED, WebhookService, assertAttachmentPolicyReadsAllowed, assertAuthRequiredForDocumentPermissions, assertCredentialVerifierForSource, assertHostMountPath, assertRequireAuthenticatedCallerAllowed, assertSkipCredentialVerificationAllowed, buildGraphQlDocument, buildGraphQlDriveDocument, buildGraphqlOperation, buildGraphqlOperations, buildSubgraphSchemaModule, callerSubject, createAuthFetchMiddleware, createCanonicalDocumentIdResolver, createGatewayAdapter, createHttpAdapter, createInspectionResolvers, createMergedSchema, createReactorGraphQLClient, createReactorInspectionSource, createRenownCredentialVerifier, createSchema, createWsAuthHandlers, decodeExplorerUrlState, definedNonNullAnySchema, driveIdFromUrl, extractSubgraphs, extractSubgraphsFromModule, generateDocumentModelSchema, getAuthContext, getDbClient, getDocumentModelSchemaName, getDocumentModelTypeDefs, getExplorerPrefix, getGitHash, getGitUrl, getSdk, getUniqueDocumentModels, getUniqueUpgradeManifests, getVersion, initAnalyticsStoreSql, initializeAndStartAPI, inspectionTypeDefs, isDefinedNonNullAny, isExpectedLoaderMiss, isListedAdmin, isPostgresConnectionString, isSubgraphClass, namespacePath, namespaceSegments, newWebhookToken, parseDriveUrl, parseWebhookBody, piecesBaseUrl, redactHeaders, renderGraphqlPlayground, resolvePackageName, resolveRenownConfig, verifyWebhook };
|
|
11336
|
+
export { ADMIN_USERS, ActionCandidateInputSchema, ActionContextInputSchema, ActionInputSchema, AddRelationshipDocument, AnalyticsSubgraph, AttachmentAccessFailed, AttachmentAccessService, AttachmentAccessUnavailable, AttachmentClientProvider, AuthDecision, AuthDecisionSchema, AuthEvaluationUnsupportedError, AuthService, AuthSubgraph, AuthenticationRequiredError, AuthorizationPolicy, AuthorizedAttachmentService, AuthorizedDocumentHandle, BaseSubgraph, CORE_PACKAGE_NAME, CanonicalDocumentIdResolutionError, ChannelMetaInputSchema, CreateDocumentDocument, CreateEmptyDocumentDocument, DeleteDocumentDocument, DeleteDocumentsDocument, DocumentChangeType, DocumentChangeTypeSchema, DocumentChangesDocument, DocumentOperationsFilterInputSchema, DocumentPermissionService, DocumentRelationshipFieldsFragmentDoc, EvaluateActionsDocument, ExecuteBatchDocument, ExecutionJobInputSchema, FindDocumentsDocument, ForbiddenError, GetCreateDefaultsDocument, GetDocumentDocument, GetDocumentIncomingRelationshipEdgesDocument, GetDocumentIncomingRelationshipsDocument, GetDocumentModelsDocument, GetDocumentOperationsDocument, GetDocumentOutgoingRelationshipEdgesDocument, GetDocumentOutgoingRelationshipsDocument, GetDocumentServedDocument, GetDocumentWithOperationsDocument, GetJobStatusDocument, GraphQLManager, HttpDocumentModelLoader, HttpPackageLoader, HttpRouteService, ImportPackageLoader, InMemoryPackageStorage, InspectionSubgraph, InvalidNamespaceError, JobChangesDocument, JobInfoFieldsFragmentDoc, MalformedStoredOperationError, MemoryWebhookStore, MoveRelationshipDocument, MutateDocumentAsyncDocument, MutateDocumentDocument, OperationContextInputSchema, OperationInputSchema, OperationWithContextInputSchema, OperationsFilterInputSchema, PACKAGE_ROUTE_SEGMENT, PGLITE_UTC_PARSERS, PackageManagementService, PackageManager, PackagesSubgraph, PagingInputSchema, PhDocumentFieldsFragmentDoc, PollSyncEnvelopesDocument, PrivacyPermissionAdapter, PropagationMode, PropagationModeSchema, PushSyncEnvelopesDocument, ReactorSignerAppInputSchema, ReactorSignerInputSchema, ReactorSignerUserInputSchema, ReactorSubgraph, RefusalNotRecordedError, RelationalWebhookStore, RemoteCursorInputSchema, RemoteFilterInputSchema, RemoveRelationshipDocument, RenameDocumentDocument, SearchFilterInputSchema, SetPreferredEditorDocument, SubgraphTypeCollisionError, SyncEnvelopeInputSchema, SyncEnvelopeType, SyncEnvelopeTypeSchema, SyncRefusalInputSchema, SystemSubgraph, TouchChannelDocument, TouchChannelInputSchema, UpdateRelationshipDocument, ViewFilterInputSchema, WEBHOOK_SEGMENT, WS_AUTH_CLOSE_REASONS, WS_CLOSE_REASON_AUTHENTICATION_REQUIRED, WS_CLOSE_REASON_BEARER_REJECTED, WebhookService, assembleSubgraphTypeDefs, assertAttachmentPolicyReadsAllowed, assertAuthRequiredForDocumentPermissions, assertCredentialVerifierForSource, assertHostMountPath, assertRequireAuthenticatedCallerAllowed, assertSkipCredentialVerificationAllowed, buildGraphQlDocument, buildGraphQlDriveDocument, buildGraphqlOperation, buildGraphqlOperations, buildSubgraphSchemaModule, callerSubject, createAuthFetchMiddleware, createCanonicalDocumentIdResolver, createGatewayAdapter, createHttpAdapter, createInspectionResolvers, createMergedSchema, createReactorGraphQLClient, createReactorInspectionSource, createRenownCredentialVerifier, createSchema, createWsAuthHandlers, decodeExplorerUrlState, definedNonNullAnySchema, driveIdFromUrl, extractSubgraphs, extractSubgraphsFromModule, findSubgraphTypeCollisions, generateDocumentModelSchema, getAuthContext, getDbClient, getDocumentModelSchemaName, getDocumentModelTypeDefs, getExplorerPrefix, getGeneratedDocumentModelTypes, getGitHash, getGitUrl, getSdk, getUniqueDocumentModels, getUniqueUpgradeManifests, getVersion, initAnalyticsStoreSql, initializeAndStartAPI, inspectionTypeDefs, isDefinedNonNullAny, isExpectedLoaderMiss, isListedAdmin, isPostgresConnectionString, isSubgraphClass, namespacePath, namespaceSegments, newWebhookToken, parseDriveUrl, parseWebhookBody, piecesBaseUrl, redactHeaders, renderGraphqlPlayground, reservedTypeNames, reservedTypeNamesTaken, resolvePackageName, resolveRenownConfig, setupEventListeners, typeDefinitionNames, verifyWebhook };
|
|
10915
11337
|
|
|
10916
11338
|
//# sourceMappingURL=index.mjs.map
|
|
10917
|
-
//# debugId=
|
|
11339
|
+
//# debugId=258ec262-91c0-5680-9801-22cef42aa999
|