@powerhousedao/reactor-api 6.2.3-dev.8 → 6.2.3-dev.80
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/README.md +7 -2
- package/dist/{adapter-gateway-apollo-CxJNBVyD.mjs → adapter-gateway-apollo-D-EdZ4e-.mjs} +23 -23
- package/dist/adapter-gateway-apollo-D-EdZ4e-.mjs.map +1 -0
- package/dist/{adapter-gateway-mercurius-CZVy88Za.mjs → adapter-gateway-mercurius-CdxLge5p.mjs} +4 -12
- package/dist/adapter-gateway-mercurius-CdxLge5p.mjs.map +1 -0
- package/dist/{adapter-http-express-B39rPhqH.mjs → adapter-http-express-P0t-mdMV.mjs} +10 -10
- package/dist/adapter-http-express-P0t-mdMV.mjs.map +1 -0
- package/dist/{adapter-http-fastify-BwXO6rqE.mjs → adapter-http-fastify-D0OP5q9K.mjs} +13 -12
- package/dist/adapter-http-fastify-D0OP5q9K.mjs.map +1 -0
- package/dist/base-document-models-D-cmBBYJ.mjs +1583 -0
- package/dist/base-document-models-D-cmBBYJ.mjs.map +1 -0
- package/dist/create-schema-Dio_7akA.d.mts +159 -0
- package/dist/create-schema-Dio_7akA.d.mts.map +1 -0
- package/dist/error-info-BaEL50f5.mjs +486 -0
- package/dist/error-info-BaEL50f5.mjs.map +1 -0
- package/dist/index.d.mts +3083 -980
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6848 -2736
- package/dist/index.mjs.map +1 -1
- package/dist/package-subgraph-check-C0PD_Tj9.mjs +138 -0
- package/dist/package-subgraph-check-C0PD_Tj9.mjs.map +1 -0
- package/dist/pglite-like-CKQEL_Q0.d.mts +27 -0
- package/dist/pglite-like-CKQEL_Q0.d.mts.map +1 -0
- package/dist/pglite-node-DGms6Ssa.mjs +715 -0
- package/dist/pglite-node-DGms6Ssa.mjs.map +1 -0
- package/dist/rolldown-runtime-8H4AJuhK.mjs +16 -0
- package/dist/run-node-handler-CQjyjOuN.mjs +52 -0
- package/dist/run-node-handler-CQjyjOuN.mjs.map +1 -0
- package/dist/src/graphql/subgraph-types.d.mts +43 -0
- package/dist/src/graphql/subgraph-types.d.mts.map +1 -0
- package/dist/src/graphql/subgraph-types.mjs +14 -0
- package/dist/src/graphql/subgraph-types.mjs.map +1 -0
- package/dist/src/packages/https-hooks.d.mts +4 -4
- package/dist/src/packages/https-hooks.d.mts.map +1 -1
- package/dist/src/packages/https-hooks.mjs +2 -2
- package/dist/src/packages/https-hooks.mjs.map +1 -1
- package/dist/src/packages/vite-loader.d.mts +30 -9
- package/dist/src/packages/vite-loader.d.mts.map +1 -1
- package/dist/src/packages/vite-loader.mjs +198 -85
- package/dist/src/packages/vite-loader.mjs.map +1 -1
- package/dist/src/pglite/pglite-node.d.mts +393 -0
- package/dist/src/pglite/pglite-node.d.mts.map +1 -0
- package/dist/src/pglite/pglite-node.mjs +5 -0
- package/dist/src/pglite/worker/entry.d.mts +2 -0
- package/dist/src/pglite/worker/entry.mjs +251 -0
- package/dist/src/pglite/worker/entry.mjs.map +1 -0
- package/dist/subgraph-extraction-BA9WKjn1.mjs +1877 -0
- package/dist/subgraph-extraction-BA9WKjn1.mjs.map +1 -0
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs +10 -0
- package/dist/subgraph-schema-owner-BEjuk2Xv.mjs.map +1 -0
- package/dist/types-PXB1ctpi.d.mts +99 -0
- package/dist/types-PXB1ctpi.d.mts.map +1 -0
- package/package.json +30 -21
- package/dist/adapter-gateway-apollo-CxJNBVyD.mjs.map +0 -1
- package/dist/adapter-gateway-apollo-DowrX6E_.mjs +0 -4
- package/dist/adapter-gateway-mercurius-CZVy88Za.mjs.map +0 -1
- package/dist/adapter-gateway-stitching-CaZjvRzx.mjs +0 -316
- package/dist/adapter-gateway-stitching-CaZjvRzx.mjs.map +0 -1
- package/dist/adapter-http-express-B39rPhqH.mjs.map +0 -1
- package/dist/adapter-http-fastify-BwXO6rqE.mjs.map +0 -1
- package/dist/path-normalize-BOQwY9wR.mjs +0 -23
- package/dist/path-normalize-BOQwY9wR.mjs.map +0 -1
- package/dist/types-DcYyNcHJ.d.mts +0 -48
- package/dist/types-DcYyNcHJ.d.mts.map +0 -1
- package/dist/utils-XWVecaNn.mjs +0 -653
- package/dist/utils-XWVecaNn.mjs.map +0 -1
- package/dist/websocket-DncAB9XK.mjs +0 -18
- package/dist/websocket-DncAB9XK.mjs.map +0 -1
|
@@ -0,0 +1,1583 @@
|
|
|
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]="15ba8214-2497-5db6-b2f0-f5342ed231ba")}catch(e){}}();
|
|
3
|
+
import { childLogger, documentModelDocumentModelModule } from "document-model";
|
|
4
|
+
import { gql } from "graphql-tag";
|
|
5
|
+
import { GraphQLScalarType, Kind, Lexer, Source, TokenKind, isTypeDefinitionNode, isTypeExtensionNode, parse, print, valueFromASTUntyped, visit } from "graphql";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { scalarCatalog } from "document-model/scalars";
|
|
8
|
+
import { GraphQLJSON, GraphQLJSONObject } from "graphql-type-json";
|
|
9
|
+
import { inspect, isDeepStrictEqual } from "node:util";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { buildSubgraphSchema } from "@apollo/subgraph";
|
|
12
|
+
import { camelCase, kebabCase, pascalCase } from "change-case";
|
|
13
|
+
import { reactorDriveDocumentModelModule } from "@powerhousedao/reactor-drive";
|
|
14
|
+
import { ReactorGroupV1 } from "@powerhousedao/reactor-group";
|
|
15
|
+
import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
|
|
16
|
+
//#region src/graphql/auth/schema.graphql
|
|
17
|
+
var schema_default$1 = "# Auth Subgraph Schema\n# Contains all document permission and authorization related types\n\nscalar DateTime\n\n# Permission levels for documents\nenum DocumentPermissionLevel {\n # Can fetch and read the document\n READ\n # Can push updates and modify the document\n WRITE\n # Can manage document permissions and settings\n ADMIN\n}\n\n# Document permission entry\ntype DocumentPermissionEntry {\n documentId: String!\n userAddress: String!\n permission: DocumentPermissionLevel!\n grantedBy: String!\n createdAt: DateTime!\n updatedAt: DateTime!\n}\n\n# Operation user permission entry\ntype OperationUserPermission {\n documentId: String!\n operationType: String!\n userAddress: String!\n grantedBy: String!\n createdAt: DateTime!\n}\n\n# Combined document access info\ntype DocumentAccessInfo {\n documentId: String!\n permissions: [DocumentPermissionEntry!]!\n}\n\n# Operation permissions info\ntype OperationPermissionsInfo {\n documentId: String!\n operationType: String!\n userPermissions: [OperationUserPermission!]!\n}\n\n# Document protection info\ntype DocumentProtectionInfo {\n documentId: String!\n protected: Boolean!\n ownerAddress: String\n}\n\ntype Query {\n # Get permissions for a document (requires ADMIN permission or global admin)\n documentAccess(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n ): DocumentAccessInfo!\n\n # Get protection status for a document (requires ADMIN permission or global admin)\n documentProtection(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n ): DocumentProtectionInfo!\n\n # Get all documents the current user has explicit access to\n userDocumentPermissions: [DocumentPermissionEntry!]!\n\n # Get operation permissions for a document and operation type\n # (requires ADMIN permission or global admin)\n operationPermissions(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n ): OperationPermissionsInfo!\n\n # Check if the current user can execute a specific operation on a document\n canExecuteOperation(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n ): Boolean!\n}\n\ntype Mutation {\n # Set document protection status (requires ADMIN permission or global admin)\n setDocumentProtection(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n protected: Boolean!\n ): DocumentProtectionInfo!\n\n # Transfer document ownership (requires ADMIN permission or global admin)\n transferDocumentOwnership(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n newOwnerAddress: String!\n ): DocumentProtectionInfo!\n\n # Grant a user permission on a document (requires ADMIN permission or global admin)\n grantDocumentPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n userAddress: String!\n permission: DocumentPermissionLevel!\n ): DocumentPermissionEntry!\n\n # Revoke a user's permission on a document (requires ADMIN permission or global admin)\n revokeDocumentPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n userAddress: String!\n ): Boolean!\n\n # --- Operation Permissions ---\n\n # Grant a user permission to execute an operation on a document\n grantOperationPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n userAddress: String!\n ): OperationUserPermission!\n\n # Revoke a user's permission to execute an operation\n revokeOperationPermission(\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n operationType: String!\n userAddress: String!\n ): Boolean!\n}\n";
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/scalar-types.ts
|
|
20
|
+
const EMPTY_SCALAR_REGISTRY = /* @__PURE__ */ new Map();
|
|
21
|
+
function sameScalarRegistry(a, b) {
|
|
22
|
+
if (a.size !== b.size) return false;
|
|
23
|
+
for (const [name, scalar] of a) {
|
|
24
|
+
const other = b.get(name);
|
|
25
|
+
if (other?.definition !== scalar.definition || other.packageName !== scalar.packageName) return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
const catalogScalarSdl = scalarCatalog.map(({ name }) => `scalar ${name}`).join("\n");
|
|
30
|
+
const catalogResolvers = Object.fromEntries(scalarCatalog.map(({ name }) => [name, new GraphQLScalarType({
|
|
31
|
+
serialize: (value) => value,
|
|
32
|
+
parseValue: (value) => value,
|
|
33
|
+
parseLiteral: valueFromASTUntyped,
|
|
34
|
+
...name === "JSONObject" ? GraphQLJSONObject.toConfig() : name === "Unknown" ? GraphQLJSON.toConfig() : {},
|
|
35
|
+
name
|
|
36
|
+
})]));
|
|
37
|
+
function hasVariable(ast) {
|
|
38
|
+
let found = false;
|
|
39
|
+
visit(ast, { Variable() {
|
|
40
|
+
found = true;
|
|
41
|
+
} });
|
|
42
|
+
return found;
|
|
43
|
+
}
|
|
44
|
+
function losslessJson(value) {
|
|
45
|
+
try {
|
|
46
|
+
const json = JSON.parse(JSON.stringify(value));
|
|
47
|
+
return isDeepStrictEqual(json, value) ? { json } : void 0;
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function show(value) {
|
|
53
|
+
try {
|
|
54
|
+
return losslessJson(value) ? JSON.stringify(value) : inspect(value, {
|
|
55
|
+
customInspect: false,
|
|
56
|
+
breakLength: Infinity
|
|
57
|
+
});
|
|
58
|
+
} catch {
|
|
59
|
+
return "a value that cannot be printed";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Validates with the definition's schema and accepts only a canonical value. */
|
|
63
|
+
function registeredScalarType(definition) {
|
|
64
|
+
const check = (value) => {
|
|
65
|
+
const result = definition.schema.safeParse(value);
|
|
66
|
+
if (!result.success) throw new Error(`${definition.name}: ${z.prettifyError(result.error)}`);
|
|
67
|
+
const output = losslessJson(result.data);
|
|
68
|
+
if (!output) throw new Error(`${definition.name}: the schema output is not JSON: ${show(result.data)}`);
|
|
69
|
+
const reparsed = definition.schema.safeParse(output.json);
|
|
70
|
+
if (reparsed.success && isDeepStrictEqual(reparsed.data, result.data)) return result.data;
|
|
71
|
+
const outcome = reparsed.success ? `parses to ${show(reparsed.data)}.` : `fails it: ${z.prettifyError(reparsed.error)}`;
|
|
72
|
+
throw new Error(`${definition.name}: the schema must accept its own output unchanged, but ${show(result.data)} ${outcome}`);
|
|
73
|
+
};
|
|
74
|
+
return new GraphQLScalarType({
|
|
75
|
+
name: definition.name,
|
|
76
|
+
description: definition.description,
|
|
77
|
+
serialize: (value) => value,
|
|
78
|
+
parseValue: check,
|
|
79
|
+
parseLiteral: (ast, variables) => {
|
|
80
|
+
if (variables == null && hasVariable(ast)) return null;
|
|
81
|
+
return check(valueFromASTUntyped(ast, variables));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/utils/create-schema.ts
|
|
87
|
+
const logger = childLogger(["reactor-api", "create-schema"]);
|
|
88
|
+
/**
|
|
89
|
+
* Revision type - matches the definition in reactor/schema.graphql.
|
|
90
|
+
* Used by PHDocument and document mutation results.
|
|
91
|
+
*/
|
|
92
|
+
const RevisionType = `
|
|
93
|
+
type Revision {
|
|
94
|
+
scope: String!
|
|
95
|
+
revision: Int!
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
/**
|
|
99
|
+
* A subgraph defines a type whose name the generated document-model schema
|
|
100
|
+
* owns, so one of the two definitions would be lost.
|
|
101
|
+
*/
|
|
102
|
+
var SubgraphTypeCollisionError = class extends Error {
|
|
103
|
+
typeNames;
|
|
104
|
+
constructor(typeNames) {
|
|
105
|
+
super(`Subgraph defines types reserved by the document-model schema: ${typeNames.join(", ")}`);
|
|
106
|
+
this.name = "SubgraphTypeCollisionError";
|
|
107
|
+
this.typeNames = typeNames;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Type-system definition kinds that GraphQL requires to be uniquely named.
|
|
112
|
+
* A subgraph SDL with two definitions sharing a name fails federation
|
|
113
|
+
* composition ("There can be only one type named X"), which is fatal to the
|
|
114
|
+
* whole gateway. We dedupe these by name; field/operation/extension nodes are
|
|
115
|
+
* left untouched.
|
|
116
|
+
*/
|
|
117
|
+
const TYPE_DEFINITION_KINDS = /* @__PURE__ */ new Set([
|
|
118
|
+
Kind.OBJECT_TYPE_DEFINITION,
|
|
119
|
+
Kind.ENUM_TYPE_DEFINITION,
|
|
120
|
+
Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
121
|
+
Kind.INTERFACE_TYPE_DEFINITION,
|
|
122
|
+
Kind.UNION_TYPE_DEFINITION,
|
|
123
|
+
Kind.SCALAR_TYPE_DEFINITION
|
|
124
|
+
]);
|
|
125
|
+
/**
|
|
126
|
+
* Drop duplicate type-system definitions by name, keeping the first occurrence.
|
|
127
|
+
* Deduping is by name across ALL kinds (a `type` and an `enum` sharing a name
|
|
128
|
+
* collide in GraphQL too), so the first definition of a given name wins
|
|
129
|
+
* regardless of kind. State types are emitted before operation types, so
|
|
130
|
+
* keep-first preserves the authoritative state definition. This heals a document
|
|
131
|
+
* model that defines the same name twice (global+local, state+operation, or
|
|
132
|
+
* twice in one scope) so the assembled subgraph SDL composes instead of crashing
|
|
133
|
+
* the gateway (Sentry #917).
|
|
134
|
+
*/
|
|
135
|
+
const dedupeTypeDefinitions = (definitions, seen = /* @__PURE__ */ new Set()) => definitions.filter((def) => {
|
|
136
|
+
const name = typeDefinitionName(def);
|
|
137
|
+
if (name === void 0) return true;
|
|
138
|
+
if (seen.has(name)) {
|
|
139
|
+
logger.debug(`Dropping duplicate type definition: ${name}`);
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
seen.add(name);
|
|
143
|
+
return true;
|
|
144
|
+
});
|
|
145
|
+
function typeDefinitionName(def) {
|
|
146
|
+
if (!TYPE_DEFINITION_KINDS.has(def.kind)) return void 0;
|
|
147
|
+
return def.name?.value;
|
|
148
|
+
}
|
|
149
|
+
const EMPTY_DOCUMENT = {
|
|
150
|
+
kind: Kind.DOCUMENT,
|
|
151
|
+
definitions: []
|
|
152
|
+
};
|
|
153
|
+
const OUTPUT_TYPE_KINDS = [
|
|
154
|
+
Kind.OBJECT_TYPE_DEFINITION,
|
|
155
|
+
Kind.OBJECT_TYPE_EXTENSION,
|
|
156
|
+
Kind.ENUM_TYPE_DEFINITION,
|
|
157
|
+
Kind.ENUM_TYPE_EXTENSION,
|
|
158
|
+
Kind.UNION_TYPE_DEFINITION,
|
|
159
|
+
Kind.UNION_TYPE_EXTENSION,
|
|
160
|
+
Kind.INTERFACE_TYPE_DEFINITION,
|
|
161
|
+
Kind.INTERFACE_TYPE_EXTENSION
|
|
162
|
+
];
|
|
163
|
+
const STATE_PREFIX_KINDS = new Set(OUTPUT_TYPE_KINDS);
|
|
164
|
+
const ALL_PREFIX_KINDS = /* @__PURE__ */ new Set([
|
|
165
|
+
...OUTPUT_TYPE_KINDS,
|
|
166
|
+
Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
167
|
+
Kind.INPUT_OBJECT_TYPE_EXTENSION
|
|
168
|
+
]);
|
|
169
|
+
const TYPE_NAME_KINDS = /* @__PURE__ */ new Set([
|
|
170
|
+
...ALL_PREFIX_KINDS,
|
|
171
|
+
Kind.SCALAR_TYPE_DEFINITION,
|
|
172
|
+
Kind.SCALAR_TYPE_EXTENSION,
|
|
173
|
+
Kind.NAMED_TYPE
|
|
174
|
+
]);
|
|
175
|
+
const LOCAL_STATE_STUBS = /* @__PURE__ */ new Set([
|
|
176
|
+
"AccountSnapshotLocalState",
|
|
177
|
+
"BudgetStatementLocalState",
|
|
178
|
+
"ScopeFrameworkLocalState"
|
|
179
|
+
]);
|
|
180
|
+
/** Parse SDL; blank or comment-only input yields an empty document. */
|
|
181
|
+
function parseSdl(sdl) {
|
|
182
|
+
const source = new Source(sdl);
|
|
183
|
+
if (new Lexer(source).advance().kind === TokenKind.EOF) return EMPTY_DOCUMENT;
|
|
184
|
+
try {
|
|
185
|
+
return parse(source, { noLocation: true });
|
|
186
|
+
} catch (error) {
|
|
187
|
+
const withoutSemicolons = sdl.replaceAll(";", "");
|
|
188
|
+
if (withoutSemicolons === sdl) throw error;
|
|
189
|
+
return parse(withoutSemicolons, { noLocation: true });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function definedTypeNames(doc, kinds) {
|
|
193
|
+
return doc.definitions.filter((def) => kinds.has(def.kind)).map((def) => def.name.value);
|
|
194
|
+
}
|
|
195
|
+
/** Prefix type definition names and type references found in `names`. */
|
|
196
|
+
function prefixTypeNames(doc, prefix, names) {
|
|
197
|
+
return visit(doc, { enter(node) {
|
|
198
|
+
if (!TYPE_NAME_KINDS.has(node.kind)) return void 0;
|
|
199
|
+
const { name } = node;
|
|
200
|
+
if (!names.has(name.value)) return void 0;
|
|
201
|
+
return {
|
|
202
|
+
...node,
|
|
203
|
+
name: {
|
|
204
|
+
...name,
|
|
205
|
+
value: `${prefix}_${name.value}`
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
} });
|
|
209
|
+
}
|
|
210
|
+
/** State schema definitions without inputs, `DateTime` or the given object types. */
|
|
211
|
+
function stateTypeDefinitions(sdl, droppedObjectTypes = /* @__PURE__ */ new Set()) {
|
|
212
|
+
return parseSdl(sdl).definitions.filter((def) => def.kind !== Kind.INPUT_OBJECT_TYPE_DEFINITION && def.kind !== Kind.INPUT_OBJECT_TYPE_EXTENSION && !(def.kind === Kind.SCALAR_TYPE_DEFINITION && def.name.value === "DateTime") && !(def.kind === Kind.OBJECT_TYPE_DEFINITION && droppedObjectTypes.has(def.name.value)));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Prefixed operation schemas per module. The first definition of each module
|
|
216
|
+
* carries a "Module: <Name>" description unless it has its own.
|
|
217
|
+
*/
|
|
218
|
+
function buildModuleSchemas(specification, documentName, allTypeNames, hasValidSchema) {
|
|
219
|
+
const names = new Set(allTypeNames);
|
|
220
|
+
return specification?.modules.map((module) => {
|
|
221
|
+
const definitions = module.operations.filter((op) => hasValidSchema(op.schema)).flatMap((op) => {
|
|
222
|
+
const doc = parseSdl(op.schema ?? "");
|
|
223
|
+
return prefixTypeNames(doc, documentName, /* @__PURE__ */ new Set([...names, ...definedTypeNames(doc, ALL_PREFIX_KINDS)])).definitions;
|
|
224
|
+
});
|
|
225
|
+
if (definitions.length === 0) return "";
|
|
226
|
+
const [first, ...rest] = definitions;
|
|
227
|
+
const header = "description" in first && !first.description ? {
|
|
228
|
+
...first,
|
|
229
|
+
description: {
|
|
230
|
+
kind: Kind.STRING,
|
|
231
|
+
value: `Module: ${pascalCase(module.name)}`,
|
|
232
|
+
block: true
|
|
233
|
+
}
|
|
234
|
+
} : first;
|
|
235
|
+
return print({
|
|
236
|
+
kind: Kind.DOCUMENT,
|
|
237
|
+
definitions: [header, ...rest]
|
|
238
|
+
});
|
|
239
|
+
}).filter(Boolean).join("\n") ?? "";
|
|
240
|
+
}
|
|
241
|
+
const buildSubgraphSchemaModule = (documentModels, resolvers, typeDefs, options = {}) => {
|
|
242
|
+
const generated = options.generated ?? getGeneratedDocumentModelTypes(documentModels, void 0, options.scalars);
|
|
243
|
+
const newResolvers = {
|
|
244
|
+
...catalogResolvers,
|
|
245
|
+
...Object.fromEntries(Array.from(generated.scalars, ([name, { definition }]) => [name, registeredScalarType(definition)])),
|
|
246
|
+
...resolvers,
|
|
247
|
+
JSONObject: catalogResolvers.JSONObject,
|
|
248
|
+
Unknown: catalogResolvers.Unknown
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
typeDefs: assembleSubgraphTypeDefs(generated, typeDefs, options.ownTypeNames),
|
|
252
|
+
resolvers: newResolvers
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
const createSchema = (documentModels, resolvers, typeDefs, options = {}) => {
|
|
256
|
+
return buildSubgraphSchema([buildSubgraphSchemaModule(documentModels, resolvers, typeDefs, options)]);
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Create a merged GraphQL schema from multiple subgraph modules.
|
|
260
|
+
* Uses buildSubgraphSchema's array overload to combine type definitions
|
|
261
|
+
* and resolvers from multiple subgraphs into a single executable schema.
|
|
262
|
+
*/
|
|
263
|
+
const createMergedSchema = (modules) => {
|
|
264
|
+
return buildSubgraphSchema(modules);
|
|
265
|
+
};
|
|
266
|
+
function getDocumentModelSchemaName(documentModel) {
|
|
267
|
+
return pascalCase(documentModel.name.replaceAll("/", " "));
|
|
268
|
+
}
|
|
269
|
+
/** The name the model's own subgraph registers under. */
|
|
270
|
+
function getDocumentModelSubgraphName(documentModel) {
|
|
271
|
+
return kebabCase(documentModel.name);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The generated document-model types followed by the subgraph's own. Throws
|
|
275
|
+
* {@link SubgraphTypeCollisionError} when the subgraph defines a generated
|
|
276
|
+
* name not in `ownTypeNames`.
|
|
277
|
+
*/
|
|
278
|
+
const getDocumentModelTypeDefs = (documentModels, typeDefs, ownTypeNames) => assembleSubgraphTypeDefs(getGeneratedDocumentModelTypes(documentModels), typeDefs, ownTypeNames);
|
|
279
|
+
/** Names of the type definitions in `doc`. */
|
|
280
|
+
function typeDefinitionNames(doc) {
|
|
281
|
+
return new Set(doc.definitions.map(typeDefinitionName).filter((name) => name !== void 0));
|
|
282
|
+
}
|
|
283
|
+
/** The definitions `documentModel` adds to the generated schema. */
|
|
284
|
+
function documentModelDefinitions(documentModel) {
|
|
285
|
+
const dmSchemaName = getDocumentModelSchemaName(documentModel);
|
|
286
|
+
const latestSpec = documentModel.specifications.at(-1);
|
|
287
|
+
const globalSchema = latestSpec?.state.global.schema ?? "";
|
|
288
|
+
const localSchema = latestSpec?.state.local.schema ?? "";
|
|
289
|
+
const definitions = [...stateTypeDefinitions(globalSchema), ...stateTypeDefinitions(localSchema, LOCAL_STATE_STUBS)];
|
|
290
|
+
const stateDoc = {
|
|
291
|
+
kind: Kind.DOCUMENT,
|
|
292
|
+
definitions
|
|
293
|
+
};
|
|
294
|
+
const prefixed = prefixTypeNames(stateDoc, dmSchemaName, new Set(definedTypeNames(stateDoc, STATE_PREFIX_KINDS)));
|
|
295
|
+
const documentType = parseSdl(`
|
|
296
|
+
type ${dmSchemaName} implements IDocument {
|
|
297
|
+
id: String!
|
|
298
|
+
name: String!
|
|
299
|
+
documentType: String!
|
|
300
|
+
operations(skip: Int, first: Int): [Operation!]!
|
|
301
|
+
revision: Int!
|
|
302
|
+
createdAtUtcIso: DateTime!
|
|
303
|
+
lastModifiedAtUtcIso: DateTime!
|
|
304
|
+
${dmSchemaName !== "DocumentModel" ? `initialState: ${dmSchemaName}_${dmSchemaName}State!` : ""}
|
|
305
|
+
${dmSchemaName !== "DocumentModel" ? `state: ${dmSchemaName}_${dmSchemaName}State!` : ""}
|
|
306
|
+
stateJSON: JSONObject
|
|
307
|
+
}`);
|
|
308
|
+
return [...prefixed.definitions, ...documentType.definitions];
|
|
309
|
+
}
|
|
310
|
+
function addScalarFlags(definitions, into) {
|
|
311
|
+
for (const def of definitions) {
|
|
312
|
+
const name = typeDefinitionName(def);
|
|
313
|
+
if (name === void 0) continue;
|
|
314
|
+
const scalar = def.kind === Kind.SCALAR_TYPE_DEFINITION;
|
|
315
|
+
into.set(name, scalar && (into.get(name) ?? true));
|
|
316
|
+
}
|
|
317
|
+
return into;
|
|
318
|
+
}
|
|
319
|
+
let fixedGeneratedTypes;
|
|
320
|
+
/**
|
|
321
|
+
* Type names no document model may generate: the root types, the generated
|
|
322
|
+
* types every schema carries, and the types of `coreTypeDefs`.
|
|
323
|
+
*/
|
|
324
|
+
function reservedTypeNames(coreTypeDefs) {
|
|
325
|
+
fixedGeneratedTypes ??= addScalarFlags(getGeneratedDocumentModelTypes([]).definitions, /* @__PURE__ */ new Map());
|
|
326
|
+
const reserved = new Map([
|
|
327
|
+
["Query", false],
|
|
328
|
+
["Mutation", false],
|
|
329
|
+
["Subscription", false],
|
|
330
|
+
...fixedGeneratedTypes
|
|
331
|
+
]);
|
|
332
|
+
for (const typeDefs of coreTypeDefs) addScalarFlags(typeDefs.definitions, reserved);
|
|
333
|
+
return reserved;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The reserved names `documentModel`'s generated types take. A scalar may
|
|
337
|
+
* repeat a reserved scalar: the duplicate is dropped on assembly.
|
|
338
|
+
*/
|
|
339
|
+
function reservedTypeNamesTaken(documentModel, reserved, definitions = documentModelDefinitions(documentModel.documentModel.global)) {
|
|
340
|
+
const generated = addScalarFlags(definitions, /* @__PURE__ */ new Map());
|
|
341
|
+
return Array.from(generated).filter(([name, scalar]) => reserved.has(name) && !(scalar && reserved.get(name))).map(([name]) => name);
|
|
342
|
+
}
|
|
343
|
+
const CATALOG_SCALARS = gql`
|
|
344
|
+
${catalogScalarSdl}
|
|
345
|
+
`.definitions;
|
|
346
|
+
const HOST_TYPES = gql`
|
|
347
|
+
type PHOperationContext {
|
|
348
|
+
signer: Signer
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
type Signer {
|
|
352
|
+
user: SignerUser
|
|
353
|
+
app: SignerApp
|
|
354
|
+
signatures: [String!]!
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
type SignerUser {
|
|
358
|
+
address: String!
|
|
359
|
+
networkId: String!
|
|
360
|
+
chainId: Int!
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
type SignerApp {
|
|
364
|
+
name: String!
|
|
365
|
+
key: String!
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
type Operation {
|
|
369
|
+
id: String!
|
|
370
|
+
type: String!
|
|
371
|
+
index: Int!
|
|
372
|
+
timestampUtcMs: DateTime!
|
|
373
|
+
hash: String!
|
|
374
|
+
skip: Int
|
|
375
|
+
inputText: String
|
|
376
|
+
error: String
|
|
377
|
+
context: PHOperationContext
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
interface IDocument {
|
|
381
|
+
id: String!
|
|
382
|
+
name: String!
|
|
383
|
+
documentType: String!
|
|
384
|
+
revision: Int!
|
|
385
|
+
createdAtUtcIso: DateTime!
|
|
386
|
+
lastModifiedAtUtcIso: DateTime!
|
|
387
|
+
operations(first: Int, skip: Int): [Operation!]!
|
|
388
|
+
stateJSON: JSONObject
|
|
389
|
+
}
|
|
390
|
+
`.definitions;
|
|
391
|
+
/**
|
|
392
|
+
* A federation gateway composes this SDL, not the schema built from it, so the
|
|
393
|
+
* description is declared here as well as on the resolver.
|
|
394
|
+
*/
|
|
395
|
+
function generatedHead(scalars) {
|
|
396
|
+
return [
|
|
397
|
+
...CATALOG_SCALARS,
|
|
398
|
+
...Array.from(scalars, ([name, { definition }]) => ({
|
|
399
|
+
kind: Kind.SCALAR_TYPE_DEFINITION,
|
|
400
|
+
name: {
|
|
401
|
+
kind: Kind.NAME,
|
|
402
|
+
value: name
|
|
403
|
+
},
|
|
404
|
+
description: definition.description === void 0 ? void 0 : {
|
|
405
|
+
kind: Kind.STRING,
|
|
406
|
+
value: definition.description,
|
|
407
|
+
block: true
|
|
408
|
+
}
|
|
409
|
+
})),
|
|
410
|
+
...HOST_TYPES
|
|
411
|
+
];
|
|
412
|
+
}
|
|
413
|
+
const GENERATED_TAIL = gql`
|
|
414
|
+
type GqlDocument implements IDocument {
|
|
415
|
+
id: String!
|
|
416
|
+
name: String!
|
|
417
|
+
documentType: String!
|
|
418
|
+
revision: Int!
|
|
419
|
+
createdAtUtcIso: DateTime!
|
|
420
|
+
lastModifiedAtUtcIso: DateTime!
|
|
421
|
+
operations(first: Int, skip: Int): [Operation!]!
|
|
422
|
+
stateJSON: JSONObject
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
type DriveDocument implements IDocument {
|
|
426
|
+
id: String!
|
|
427
|
+
name: String!
|
|
428
|
+
documentType: String!
|
|
429
|
+
revision: Int!
|
|
430
|
+
createdAtUtcIso: DateTime!
|
|
431
|
+
lastModifiedAtUtcIso: DateTime!
|
|
432
|
+
operations(first: Int, skip: Int): [Operation!]!
|
|
433
|
+
stateJSON: JSONObject
|
|
434
|
+
}
|
|
435
|
+
`.definitions;
|
|
436
|
+
/**
|
|
437
|
+
* The generated schema for `documentModels`. `schemas` supplies models'
|
|
438
|
+
* definitions already built; the others are built here.
|
|
439
|
+
*/
|
|
440
|
+
function getGeneratedDocumentModelTypes(documentModels, schemas, scalars = EMPTY_SCALAR_REGISTRY) {
|
|
441
|
+
return generatedTypesFrom(documentModels.map((model) => ({
|
|
442
|
+
global: model.documentModel.global,
|
|
443
|
+
generated: schemas?.get(model)?.generated
|
|
444
|
+
})), scalars);
|
|
445
|
+
}
|
|
446
|
+
/** {@link getGeneratedDocumentModelTypes} from the models' global states. */
|
|
447
|
+
function generatedTypesOf(documentModels) {
|
|
448
|
+
return generatedTypesFrom(documentModels.map((global) => ({ global })), EMPTY_SCALAR_REGISTRY);
|
|
449
|
+
}
|
|
450
|
+
function generatedTypesFrom(documentModels, scalars) {
|
|
451
|
+
const modelDefinitions = [];
|
|
452
|
+
const addedDocumentModels = /* @__PURE__ */ new Set();
|
|
453
|
+
documentModels.forEach(({ global, generated }) => {
|
|
454
|
+
const dmSchemaName = getDocumentModelSchemaName(global);
|
|
455
|
+
if (addedDocumentModels.has(dmSchemaName)) {
|
|
456
|
+
logger.debug(`Skipping document model with duplicate name: ${dmSchemaName}`);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
addedDocumentModels.add(dmSchemaName);
|
|
460
|
+
modelDefinitions.push(...generated ?? documentModelDefinitions(global));
|
|
461
|
+
});
|
|
462
|
+
const definitions = dedupeTypeDefinitions([
|
|
463
|
+
...generatedHead(scalars),
|
|
464
|
+
...modelDefinitions,
|
|
465
|
+
...GENERATED_TAIL
|
|
466
|
+
]);
|
|
467
|
+
return {
|
|
468
|
+
definitions,
|
|
469
|
+
names: new Set(definitions.map(typeDefinitionName).filter((name) => name !== void 0)),
|
|
470
|
+
scalars
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
const hasValidSchema = (schema) => !!(schema && /\b(input|type|enum|union|interface)\s+\w+/.test(schema));
|
|
474
|
+
/** Whether any operation of the latest specification has a schema. */
|
|
475
|
+
function hasOperationSchemas(documentModel) {
|
|
476
|
+
const specification = documentModel.specifications.at(-1);
|
|
477
|
+
if (!specification) return false;
|
|
478
|
+
return specification.modules.some((module) => module.operations.some((op) => hasValidSchema(op.schema)));
|
|
479
|
+
}
|
|
480
|
+
/** The types of a document model's own subgraph. */
|
|
481
|
+
function documentModelSubgraphTypes(documentModel) {
|
|
482
|
+
const typeDefs = generateDocumentModelSchema(documentModel, { useNewApi: true });
|
|
483
|
+
return {
|
|
484
|
+
typeDefs,
|
|
485
|
+
typeNames: typeDefinitionNames(typeDefs)
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
const toError = (error) => error instanceof Error ? error : new Error(String(error));
|
|
489
|
+
/** Build `subgraph` over the generated types of `documentModel` alone. */
|
|
490
|
+
function checkBuilds(documentModel, generated, subgraph) {
|
|
491
|
+
buildSubgraphSchema([{ typeDefs: assembleSubgraphTypeDefs(getGeneratedDocumentModelTypes([documentModel], /* @__PURE__ */ new Map([[documentModel, { generated }]])), subgraph?.typeDefs ?? EMPTY_DOCUMENT, subgraph?.typeNames) }]);
|
|
492
|
+
}
|
|
493
|
+
/** Throws when the generated types every subgraph carries do not build. */
|
|
494
|
+
function buildDocumentModelSchema(documentModel, options = {}) {
|
|
495
|
+
const generated = documentModelDefinitions(documentModel.documentModel.global);
|
|
496
|
+
if (options.subgraph === false || !hasOperationSchemas(documentModel.documentModel.global)) {
|
|
497
|
+
checkBuilds(documentModel, generated);
|
|
498
|
+
return { generated };
|
|
499
|
+
}
|
|
500
|
+
try {
|
|
501
|
+
const subgraph = documentModelSubgraphTypes(documentModel.documentModel.global);
|
|
502
|
+
checkBuilds(documentModel, generated, subgraph);
|
|
503
|
+
return {
|
|
504
|
+
generated,
|
|
505
|
+
subgraph
|
|
506
|
+
};
|
|
507
|
+
} catch (error) {
|
|
508
|
+
checkBuilds(documentModel, generated);
|
|
509
|
+
return {
|
|
510
|
+
generated,
|
|
511
|
+
subgraphError: toError(error)
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/** Hash of everything {@link buildDocumentModelSchema} reads. */
|
|
516
|
+
function schemaSourceKey(documentModel) {
|
|
517
|
+
const { name, specifications } = documentModel.documentModel.global;
|
|
518
|
+
return createHash("sha256").update(JSON.stringify([name, specifications.at(-1)])).digest("base64");
|
|
519
|
+
}
|
|
520
|
+
/** Schemas and failures by source hash, for the last resolve's models only. */
|
|
521
|
+
var DocumentModelSchemaCache = class {
|
|
522
|
+
#entries = /* @__PURE__ */ new Map();
|
|
523
|
+
#build;
|
|
524
|
+
constructor(build = buildDocumentModelSchema) {
|
|
525
|
+
this.#build = build;
|
|
526
|
+
}
|
|
527
|
+
resolve(documentModels) {
|
|
528
|
+
const entries = /* @__PURE__ */ new Map();
|
|
529
|
+
const resolved = documentModels.map((model) => {
|
|
530
|
+
let key;
|
|
531
|
+
let entry;
|
|
532
|
+
try {
|
|
533
|
+
key = schemaSourceKey(model);
|
|
534
|
+
entry = entries.get(key) ?? this.#entries.get(key);
|
|
535
|
+
} catch (error) {
|
|
536
|
+
key = `unkeyed:${model.documentModel.global.id}`;
|
|
537
|
+
entry = toError(error);
|
|
538
|
+
}
|
|
539
|
+
if (entry === void 0) try {
|
|
540
|
+
entry = this.#build(model);
|
|
541
|
+
} catch (error) {
|
|
542
|
+
entry = toError(error);
|
|
543
|
+
}
|
|
544
|
+
entries.set(key, entry);
|
|
545
|
+
return entry instanceof Error ? {
|
|
546
|
+
model,
|
|
547
|
+
key,
|
|
548
|
+
error: entry
|
|
549
|
+
} : {
|
|
550
|
+
model,
|
|
551
|
+
key,
|
|
552
|
+
schema: entry
|
|
553
|
+
};
|
|
554
|
+
});
|
|
555
|
+
this.#entries = entries;
|
|
556
|
+
return resolved;
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
/**
|
|
560
|
+
* Names of the generated types `typeDefs` redefines, other than those a
|
|
561
|
+
* model's own subgraph may repeat. Scalars are dropped on assembly, so they
|
|
562
|
+
* never collide.
|
|
563
|
+
*/
|
|
564
|
+
function findSubgraphTypeCollisions(generated, typeDefs, ownTypeNames) {
|
|
565
|
+
const collisions = [];
|
|
566
|
+
for (const def of typeDefs.definitions) {
|
|
567
|
+
if (def.kind === Kind.SCALAR_TYPE_DEFINITION) continue;
|
|
568
|
+
const name = typeDefinitionName(def);
|
|
569
|
+
if (name === void 0 || !generated.names.has(name)) continue;
|
|
570
|
+
if (ownTypeNames?.has(name)) continue;
|
|
571
|
+
collisions.push(name);
|
|
572
|
+
}
|
|
573
|
+
return collisions;
|
|
574
|
+
}
|
|
575
|
+
/** Throws {@link SubgraphTypeCollisionError}; see {@link getDocumentModelTypeDefs}. */
|
|
576
|
+
function assembleSubgraphTypeDefs(generated, typeDefs, ownTypeNames) {
|
|
577
|
+
const collisions = findSubgraphTypeCollisions(generated, typeDefs, ownTypeNames);
|
|
578
|
+
if (collisions.length > 0) throw new SubgraphTypeCollisionError(collisions);
|
|
579
|
+
const subgraphDefinitions = typeDefs.definitions.filter((def) => def.kind !== Kind.SCALAR_TYPE_DEFINITION);
|
|
580
|
+
return {
|
|
581
|
+
kind: Kind.DOCUMENT,
|
|
582
|
+
definitions: [...generated.definitions, ...dedupeTypeDefinitions(subgraphDefinitions, new Set(generated.names))]
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Extract the names of types defined in a GraphQL schema.
|
|
587
|
+
* Unparseable schemas yield no names.
|
|
588
|
+
*/
|
|
589
|
+
function extractTypeNames(schema) {
|
|
590
|
+
try {
|
|
591
|
+
return definedTypeNames(parseSdl(schema), ALL_PREFIX_KINDS);
|
|
592
|
+
} catch (error) {
|
|
593
|
+
logger.debug(`Skipping unparseable schema: ${String(error)}`);
|
|
594
|
+
return [];
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Print the input type definitions of a GraphQL schema.
|
|
599
|
+
* @param excludeTypeNames - Input type names to leave out
|
|
600
|
+
*/
|
|
601
|
+
function extractInputTypeDefinitions(schema, excludeTypeNames = /* @__PURE__ */ new Set()) {
|
|
602
|
+
const definitions = parseSdl(schema).definitions.filter((def) => def.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION && !excludeTypeNames.has(def.name.value));
|
|
603
|
+
if (definitions.length === 0) return "";
|
|
604
|
+
return print({
|
|
605
|
+
kind: Kind.DOCUMENT,
|
|
606
|
+
definitions
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Extract the root state type name from a scope's GraphQL schema.
|
|
611
|
+
* Uses the naming convention: {DocumentName}State for global,
|
|
612
|
+
* {DocumentName}{PascalScope}State for other scopes (e.g., DocumentDriveLocalState).
|
|
613
|
+
* Falls back to the last ObjectTypeDefinition (root types are conventionally last).
|
|
614
|
+
*/
|
|
615
|
+
function extractRootTypeName(schema, documentName, scopeName) {
|
|
616
|
+
try {
|
|
617
|
+
const ast = parse(schema);
|
|
618
|
+
const candidates = [`${documentName}${scopeName === "global" ? "" : pascalCase(scopeName)}State`, `${documentName}${pascalCase(scopeName)}State`];
|
|
619
|
+
let lastObjectType = null;
|
|
620
|
+
for (const def of ast.definitions) if (def.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
621
|
+
if (candidates.includes(def.name.value)) return def.name.value;
|
|
622
|
+
lastObjectType = def.name.value;
|
|
623
|
+
}
|
|
624
|
+
return lastObjectType;
|
|
625
|
+
} catch {}
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Convert a GraphQL output type AST node to an optional input type string.
|
|
630
|
+
* Strips non-null markers and converts object type references to Input suffix.
|
|
631
|
+
*/
|
|
632
|
+
function convertTypeNodeToInput(typeNode, objectNames, unionNames, interfaceNames) {
|
|
633
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE && typeNode.type) return convertTypeNodeToInput(typeNode.type, objectNames, unionNames, interfaceNames);
|
|
634
|
+
if (typeNode.kind === Kind.LIST_TYPE && typeNode.type) return `[${convertTypeNodeToInput(typeNode.type, objectNames, unionNames, interfaceNames)}]`;
|
|
635
|
+
if (typeNode.kind === Kind.NAMED_TYPE && typeNode.name) {
|
|
636
|
+
const name = typeNode.name.value;
|
|
637
|
+
if (objectNames.has(name)) return `${name}Input`;
|
|
638
|
+
if (unionNames.has(name) || interfaceNames.has(name)) return "JSONObject";
|
|
639
|
+
return name;
|
|
640
|
+
}
|
|
641
|
+
return "JSONObject";
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Generate GraphQL input type definitions from a state schema string.
|
|
645
|
+
* Converts output type definitions to input types with all fields optional.
|
|
646
|
+
* - Object type references get Input suffix
|
|
647
|
+
* - Union/interface references become JSONObject
|
|
648
|
+
* - Enums and scalars remain unchanged
|
|
649
|
+
*/
|
|
650
|
+
function generateStateInputTypes(stateSchema, excludeTypeNames) {
|
|
651
|
+
if (!stateSchema || !stateSchema.trim()) return "";
|
|
652
|
+
let ast;
|
|
653
|
+
try {
|
|
654
|
+
ast = parse(stateSchema);
|
|
655
|
+
} catch {
|
|
656
|
+
return "";
|
|
657
|
+
}
|
|
658
|
+
const enumNames = /* @__PURE__ */ new Set();
|
|
659
|
+
const unionNames = /* @__PURE__ */ new Set();
|
|
660
|
+
const interfaceNames = /* @__PURE__ */ new Set();
|
|
661
|
+
const objectNames = /* @__PURE__ */ new Set();
|
|
662
|
+
const existingInputNames = /* @__PURE__ */ new Set();
|
|
663
|
+
for (const def of ast.definitions) switch (def.kind) {
|
|
664
|
+
case Kind.ENUM_TYPE_DEFINITION:
|
|
665
|
+
enumNames.add(def.name.value);
|
|
666
|
+
break;
|
|
667
|
+
case Kind.UNION_TYPE_DEFINITION:
|
|
668
|
+
unionNames.add(def.name.value);
|
|
669
|
+
break;
|
|
670
|
+
case Kind.INTERFACE_TYPE_DEFINITION:
|
|
671
|
+
interfaceNames.add(def.name.value);
|
|
672
|
+
break;
|
|
673
|
+
case Kind.OBJECT_TYPE_DEFINITION:
|
|
674
|
+
objectNames.add(def.name.value);
|
|
675
|
+
break;
|
|
676
|
+
case Kind.INPUT_OBJECT_TYPE_DEFINITION: existingInputNames.add(def.name.value);
|
|
677
|
+
}
|
|
678
|
+
const inputTypes = [];
|
|
679
|
+
for (const def of ast.definitions) {
|
|
680
|
+
if (def.kind !== Kind.OBJECT_TYPE_DEFINITION) continue;
|
|
681
|
+
const inputName = `${def.name.value}Input`;
|
|
682
|
+
if (existingInputNames.has(inputName)) continue;
|
|
683
|
+
if (excludeTypeNames?.has(inputName)) continue;
|
|
684
|
+
const fields = def.fields ?? [];
|
|
685
|
+
if (fields.length === 0) continue;
|
|
686
|
+
const inputFields = fields.map((field) => {
|
|
687
|
+
return ` ${field.name.value}: ${convertTypeNodeToInput(field.type, objectNames, unionNames, interfaceNames)}`;
|
|
688
|
+
});
|
|
689
|
+
inputTypes.push(`input ${def.name.value}Input {\n${inputFields.join("\n")}\n}`);
|
|
690
|
+
}
|
|
691
|
+
return inputTypes.join("\n\n");
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Apply type prefixes to GraphQL schema to namespace types and avoid collisions.
|
|
695
|
+
* Inlined from @powerhousedao/common/utils to avoid ES module import issues.
|
|
696
|
+
* @param {string} schema - GraphQL schema string
|
|
697
|
+
* @param {string} prefix - Prefix to apply to type names
|
|
698
|
+
* @param {string[]} externalTypeNames - Type names from other schemas to also prefix
|
|
699
|
+
* @returns {string} Schema with prefixed types
|
|
700
|
+
*/
|
|
701
|
+
function applyGraphQLTypePrefixes(schema, prefix, externalTypeNames = []) {
|
|
702
|
+
if (!schema || !schema.trim()) return schema;
|
|
703
|
+
const doc = parseSdl(schema);
|
|
704
|
+
const names = /* @__PURE__ */ new Set([...definedTypeNames(doc, ALL_PREFIX_KINDS), ...externalTypeNames]);
|
|
705
|
+
if (names.size === 0) return schema;
|
|
706
|
+
return print(prefixTypeNames(doc, prefix, names));
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Generate a GraphQL schema for a document model.
|
|
710
|
+
*
|
|
711
|
+
* @param documentModel - The document model global state
|
|
712
|
+
* @param options - Schema generation options
|
|
713
|
+
* @returns GraphQL DocumentNode
|
|
714
|
+
*/
|
|
715
|
+
function generateDocumentModelSchema(documentModel, options = {}) {
|
|
716
|
+
const { useNewApi = false } = options;
|
|
717
|
+
const specification = documentModel.specifications.at(-1);
|
|
718
|
+
const documentName = getDocumentModelSchemaName(documentModel);
|
|
719
|
+
const globalStateSchema = specification?.state.global.schema;
|
|
720
|
+
const localStateSchema = specification?.state.local.schema;
|
|
721
|
+
const globalStateTypeNames = extractTypeNames(globalStateSchema ?? "");
|
|
722
|
+
const localStateTypeNames = extractTypeNames(localStateSchema ?? "");
|
|
723
|
+
const stateTypeNames = [...globalStateTypeNames, ...localStateTypeNames];
|
|
724
|
+
const allOperationTypeNames = specification?.modules.flatMap((module) => module.operations.flatMap((op) => extractTypeNames(op.schema ?? ""))) ?? [];
|
|
725
|
+
const allTypeNames = [.../* @__PURE__ */ new Set([...stateTypeNames, ...allOperationTypeNames])];
|
|
726
|
+
const operationInputTypeNames = new Set(allOperationTypeNames);
|
|
727
|
+
const prefixedStateInputTypes = applyGraphQLTypePrefixes(extractInputTypeDefinitions(globalStateSchema ?? "", operationInputTypeNames), documentName, allTypeNames);
|
|
728
|
+
if (useNewApi) return generateNewApiSchema(documentName, specification, prefixedStateInputTypes, allTypeNames, hasValidSchema);
|
|
729
|
+
return generateLegacyApiSchema(documentName, specification, prefixedStateInputTypes, allTypeNames, hasValidSchema);
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Generate legacy API schema with nested queries
|
|
733
|
+
*/
|
|
734
|
+
function generateLegacyApiSchema(documentName, specification, prefixedStateInputTypes, allTypeNames, hasValidSchema) {
|
|
735
|
+
const createDocumentMutation = `${documentName}_createDocument(name:String!, driveId:String): String`;
|
|
736
|
+
const operationMutations = specification?.modules.flatMap((module) => module.operations.filter((op) => op.name && hasValidSchema(op.schema)).map((op) => `${documentName}_${camelCase(op.name)}(
|
|
737
|
+
driveId: String, docId: PHID, input: ${documentName}_${pascalCase(op.name)}Input): Int`)).join("\n ") ?? "";
|
|
738
|
+
const moduleSchemas = buildModuleSchemas(specification, documentName, allTypeNames, hasValidSchema);
|
|
739
|
+
return gql`
|
|
740
|
+
"""
|
|
741
|
+
Queries: ${documentName} Document
|
|
742
|
+
"""
|
|
743
|
+
|
|
744
|
+
type ${documentName}Queries {
|
|
745
|
+
getDocument(docId: PHID!, driveId: PHID): ${documentName}
|
|
746
|
+
getDocuments(driveId: String!): [${documentName}!]
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
type Query {
|
|
750
|
+
${documentName}: ${documentName}Queries
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
"""
|
|
754
|
+
Mutations: ${documentName}
|
|
755
|
+
"""
|
|
756
|
+
type Mutation {
|
|
757
|
+
${createDocumentMutation}
|
|
758
|
+
|
|
759
|
+
${operationMutations}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
${prefixedStateInputTypes ? `"""
|
|
763
|
+
Input Types from State Schema
|
|
764
|
+
"""
|
|
765
|
+
${prefixedStateInputTypes}` : ""}
|
|
766
|
+
|
|
767
|
+
${moduleSchemas}`;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Generate new API schema with flat queries, typed state, and async mutations.
|
|
771
|
+
* Note: State schema types are NOT included here because they are already defined
|
|
772
|
+
* in getDocumentModelTypeDefs() which is used during schema composition.
|
|
773
|
+
* Including them here would cause duplicate type definitions.
|
|
774
|
+
*/
|
|
775
|
+
function generateNewApiSchema(documentName, specification, prefixedStateInputTypes, allTypeNames, hasValidSchema) {
|
|
776
|
+
const stateType = `${documentName}_FullState!`;
|
|
777
|
+
const sharedBaseTypes = `
|
|
778
|
+
"""Hash configuration for document state"""
|
|
779
|
+
type ${documentName}_PHHashConfig {
|
|
780
|
+
algorithm: String!
|
|
781
|
+
encoding: String!
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
"""Document scope state (same for all document types)"""
|
|
785
|
+
type ${documentName}_PHDocumentScopeState {
|
|
786
|
+
version: Int!
|
|
787
|
+
hash: ${documentName}_PHHashConfig!
|
|
788
|
+
isDeleted: Boolean
|
|
789
|
+
deletedAtUtcIso: String
|
|
790
|
+
deletedBy: String
|
|
791
|
+
deletionReason: String
|
|
792
|
+
}
|
|
793
|
+
`;
|
|
794
|
+
const hasLocalStateType = (specification?.state.local.schema ?? "").includes(`type ${documentName}LocalState`);
|
|
795
|
+
const fullStateType = `
|
|
796
|
+
"""Full state with all scopes for ${documentName}"""
|
|
797
|
+
type ${documentName}_FullState {
|
|
798
|
+
auth: JSONObject!
|
|
799
|
+
document: ${documentName}_PHDocumentScopeState!
|
|
800
|
+
global: ${documentName === "DocumentModel" ? `${documentName}_${documentName}GlobalState!` : `${documentName}_${documentName}State!`}
|
|
801
|
+
local: ${!hasLocalStateType ? "JSONObject!" : `${documentName}_${documentName}LocalState!`}
|
|
802
|
+
}
|
|
803
|
+
`;
|
|
804
|
+
const commonInputTypes = `
|
|
805
|
+
input ${documentName}_ViewFilterInput {
|
|
806
|
+
branch: String
|
|
807
|
+
scopes: [String!]
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
input ${documentName}_PagingInput {
|
|
811
|
+
limit: Int
|
|
812
|
+
offset: Int
|
|
813
|
+
cursor: String
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
input ${documentName}_SearchFilterInput {
|
|
817
|
+
parentId: String
|
|
818
|
+
identifiers: [String!] @deprecated(reason: "Ignored. Filter by parentId.")
|
|
819
|
+
}
|
|
820
|
+
`;
|
|
821
|
+
const revisionType = RevisionType;
|
|
822
|
+
const resultTypes = `
|
|
823
|
+
"""
|
|
824
|
+
Mutation result type for ${documentName} operations with typed state.
|
|
825
|
+
Matches ReactorSubgraph PHDocument pattern with revisionsList.
|
|
826
|
+
"""
|
|
827
|
+
type ${documentName}MutationResult {
|
|
828
|
+
id: String!
|
|
829
|
+
slug: String
|
|
830
|
+
preferredEditor: String
|
|
831
|
+
name: String!
|
|
832
|
+
documentType: String!
|
|
833
|
+
state: ${stateType}
|
|
834
|
+
revisionsList: [Revision!]!
|
|
835
|
+
createdAtUtcIso: DateTime!
|
|
836
|
+
lastModifiedAtUtcIso: DateTime!
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
"""
|
|
840
|
+
Document with children for ${documentName}
|
|
841
|
+
"""
|
|
842
|
+
type ${documentName}_DocumentWithChildren {
|
|
843
|
+
document: ${documentName}MutationResult!
|
|
844
|
+
childIds: [String!]!
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
"""
|
|
848
|
+
Paginated result type for ${documentName} documents
|
|
849
|
+
"""
|
|
850
|
+
type ${documentName}_DocumentResultPage {
|
|
851
|
+
items: [${documentName}MutationResult!]!
|
|
852
|
+
hasNextPage: Boolean!
|
|
853
|
+
hasPreviousPage: Boolean!
|
|
854
|
+
cursor: String
|
|
855
|
+
}
|
|
856
|
+
`;
|
|
857
|
+
const queries = `
|
|
858
|
+
type ${documentName}Queries {
|
|
859
|
+
"""Get a specific ${documentName} document by identifier"""
|
|
860
|
+
document(idOrSlug: String, identifier: String @deprecated(reason: "Use idOrSlug."), view: ${documentName}_ViewFilterInput): ${documentName}_DocumentWithChildren
|
|
861
|
+
|
|
862
|
+
"""Get all ${documentName} documents (paged)"""
|
|
863
|
+
documents(paging: ${documentName}_PagingInput): ${documentName}_DocumentResultPage!
|
|
864
|
+
|
|
865
|
+
"""Find ${documentName} documents by search criteria"""
|
|
866
|
+
findDocuments(search: ${documentName}_SearchFilterInput, view: ${documentName}_ViewFilterInput, paging: ${documentName}_PagingInput): ${documentName}_DocumentResultPage!
|
|
867
|
+
|
|
868
|
+
"""Get outgoing relationships of a ${documentName} document"""
|
|
869
|
+
documentOutgoingRelationships(sourceIdOrSlug: String, sourceIdentifier: String @deprecated(reason: "Use sourceIdOrSlug."), relationshipType: String!, view: ${documentName}_ViewFilterInput, paging: ${documentName}_PagingInput): ${documentName}_DocumentResultPage!
|
|
870
|
+
|
|
871
|
+
"""Get incoming relationships to a ${documentName} document"""
|
|
872
|
+
documentIncomingRelationships(targetIdOrSlug: String, targetIdentifier: String @deprecated(reason: "Use targetIdOrSlug."), relationshipType: String!, view: ${documentName}_ViewFilterInput, paging: ${documentName}_PagingInput): ${documentName}_DocumentResultPage!
|
|
873
|
+
}
|
|
874
|
+
`;
|
|
875
|
+
let initialStateInputSchema = "";
|
|
876
|
+
if (specification) {
|
|
877
|
+
const scopeFields = [];
|
|
878
|
+
const generatedInputTypeParts = [];
|
|
879
|
+
for (const [scopeName, scopeState] of Object.entries(specification.state)) {
|
|
880
|
+
const schema = scopeState.schema ?? "";
|
|
881
|
+
if (hasValidSchema(schema)) {
|
|
882
|
+
const rootTypeName = extractRootTypeName(schema, documentName, scopeName);
|
|
883
|
+
if (!rootTypeName) {
|
|
884
|
+
scopeFields.push(` ${scopeName}: JSONObject`);
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
const scopeInputTypes = generateStateInputTypes(schema, new Set(allTypeNames));
|
|
888
|
+
if (!scopeInputTypes) {
|
|
889
|
+
scopeFields.push(` ${scopeName}: JSONObject`);
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
const prefixedScopeInputTypes = applyGraphQLTypePrefixes(scopeInputTypes, documentName, allTypeNames);
|
|
893
|
+
scopeFields.push(` ${scopeName}: ${documentName}_${rootTypeName}Input`);
|
|
894
|
+
generatedInputTypeParts.push(prefixedScopeInputTypes);
|
|
895
|
+
} else scopeFields.push(` ${scopeName}: JSONObject`);
|
|
896
|
+
}
|
|
897
|
+
if (scopeFields.length > 0) {
|
|
898
|
+
const inputTypeDefs = generatedInputTypeParts.join("\n\n");
|
|
899
|
+
const wrapper = `input ${documentName}_InitialStateInput {\n${scopeFields.join("\n")}\n}`;
|
|
900
|
+
initialStateInputSchema = inputTypeDefs ? `${inputTypeDefs}\n\n${wrapper}` : wrapper;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
const createDocumentMutation = initialStateInputSchema ? `createDocument(name: String!, parentIdOrSlug: String, parentIdentifier: String @deprecated(reason: "Use parentIdOrSlug."), slug: String, preferredEditor: String, initialState: ${documentName}_InitialStateInput): ${documentName}MutationResult!` : `createDocument(name: String!, parentIdOrSlug: String, parentIdentifier: String @deprecated(reason: "Use parentIdOrSlug."), preferredEditor: String): ${documentName}MutationResult!`;
|
|
904
|
+
const createEmptyDocumentMutation = `createEmptyDocument(parentIdOrSlug: String, parentIdentifier: String @deprecated(reason: "Use parentIdOrSlug.")): ${documentName}MutationResult!`;
|
|
905
|
+
const operationMutations = specification?.modules.flatMap((module) => module.operations.filter((op) => op.name && hasValidSchema(op.schema)).flatMap((op) => [`${camelCase(op.name)}(documentIdOrSlug: String, docId: PHID @deprecated(reason: "Use documentIdOrSlug."), input: ${documentName}_${pascalCase(op.name)}Input!): ${documentName}MutationResult!`, `${camelCase(op.name)}Async(documentIdOrSlug: String, docId: PHID @deprecated(reason: "Use documentIdOrSlug."), input: ${documentName}_${pascalCase(op.name)}Input!): String!`])).join("\n ") ?? "";
|
|
906
|
+
const moduleSchemas = buildModuleSchemas(specification, documentName, allTypeNames, hasValidSchema);
|
|
907
|
+
return gql`
|
|
908
|
+
${catalogScalarSdl}
|
|
909
|
+
|
|
910
|
+
${revisionType}
|
|
911
|
+
|
|
912
|
+
${sharedBaseTypes}
|
|
913
|
+
|
|
914
|
+
${fullStateType}
|
|
915
|
+
|
|
916
|
+
${commonInputTypes}
|
|
917
|
+
|
|
918
|
+
${resultTypes}
|
|
919
|
+
|
|
920
|
+
"""
|
|
921
|
+
Queries: ${documentName} Document
|
|
922
|
+
"""
|
|
923
|
+
${queries}
|
|
924
|
+
|
|
925
|
+
"""
|
|
926
|
+
Mutations: ${documentName}
|
|
927
|
+
"""
|
|
928
|
+
type ${documentName}Mutations {
|
|
929
|
+
${createDocumentMutation}
|
|
930
|
+
${createEmptyDocumentMutation}
|
|
931
|
+
|
|
932
|
+
${operationMutations}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
type Query {
|
|
936
|
+
${documentName}: ${documentName}Queries!
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
type Mutation {
|
|
940
|
+
${documentName}: ${documentName}Mutations!
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
${prefixedStateInputTypes ? `"""
|
|
944
|
+
Input Types from State Schema
|
|
945
|
+
"""
|
|
946
|
+
${prefixedStateInputTypes}` : ""}
|
|
947
|
+
|
|
948
|
+
${initialStateInputSchema ? `"""
|
|
949
|
+
Input Types for Initial State
|
|
950
|
+
"""
|
|
951
|
+
${initialStateInputSchema}` : ""}
|
|
952
|
+
|
|
953
|
+
${moduleSchemas}`;
|
|
954
|
+
}
|
|
955
|
+
//#endregion
|
|
956
|
+
//#region src/graphql/subgraph-type-ownership.ts
|
|
957
|
+
const ROOT_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
958
|
+
"Query",
|
|
959
|
+
"Mutation",
|
|
960
|
+
"Subscription"
|
|
961
|
+
]);
|
|
962
|
+
const byName = (nodes) => nodes && [...nodes].sort((a, b) => a.name.value < b.name.value ? -1 : a.name.value > b.name.value ? 1 : 0);
|
|
963
|
+
/** Printed without descriptions, with named members in name order. */
|
|
964
|
+
function normalizeDefinition(node) {
|
|
965
|
+
const normalized = visit(node, { leave(current) {
|
|
966
|
+
const copy = { ...current };
|
|
967
|
+
delete copy.loc;
|
|
968
|
+
if ("description" in copy) copy.description = void 0;
|
|
969
|
+
if (current.kind === Kind.STRING) copy.block = false;
|
|
970
|
+
for (const key of [
|
|
971
|
+
"fields",
|
|
972
|
+
"arguments",
|
|
973
|
+
"interfaces"
|
|
974
|
+
]) if (Array.isArray(copy[key])) copy[key] = byName(copy[key]);
|
|
975
|
+
if (current.kind === Kind.ENUM_TYPE_DEFINITION || current.kind === Kind.ENUM_TYPE_EXTENSION) copy.values = byName(current.values);
|
|
976
|
+
if (current.kind === Kind.UNION_TYPE_DEFINITION || current.kind === Kind.UNION_TYPE_EXTENSION) copy.types = byName(current.types);
|
|
977
|
+
return copy;
|
|
978
|
+
} });
|
|
979
|
+
return print(normalized);
|
|
980
|
+
}
|
|
981
|
+
function isScalar(def) {
|
|
982
|
+
return def.kind === Kind.SCALAR_TYPE_DEFINITION || def.kind === Kind.SCALAR_TYPE_EXTENSION;
|
|
983
|
+
}
|
|
984
|
+
/** Type and root-field claims, without scalars or generated types. */
|
|
985
|
+
function collectSubgraphClaims(typeDefs, generatedNames) {
|
|
986
|
+
const types = /* @__PURE__ */ new Map();
|
|
987
|
+
const claims = /* @__PURE__ */ new Map();
|
|
988
|
+
for (const def of typeDefs.definitions) {
|
|
989
|
+
if (!isTypeDefinitionNode(def) && !isTypeExtensionNode(def)) continue;
|
|
990
|
+
if (isScalar(def)) continue;
|
|
991
|
+
const node = def;
|
|
992
|
+
const name = node.name.value;
|
|
993
|
+
if (ROOT_TYPE_NAMES.has(name)) {
|
|
994
|
+
if (!("fields" in node)) continue;
|
|
995
|
+
for (const field of node.fields ?? []) {
|
|
996
|
+
const key = `${name}.${field.name.value}`;
|
|
997
|
+
const definition = normalizeDefinition(field);
|
|
998
|
+
const previous = claims.get(key);
|
|
999
|
+
claims.set(key, previous === void 0 ? definition : `${previous}\n${definition}`);
|
|
1000
|
+
}
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
if (isTypeDefinitionNode(node) && generatedNames.has(name)) continue;
|
|
1004
|
+
const nodes = types.get(name) ?? [];
|
|
1005
|
+
nodes.push(node);
|
|
1006
|
+
types.set(name, nodes);
|
|
1007
|
+
}
|
|
1008
|
+
for (const [name, nodes] of types) {
|
|
1009
|
+
const merged = mergeTypeNodes(nodes);
|
|
1010
|
+
claims.set(name, merged ? normalizeDefinition(merged) : nodes.map(normalizeDefinition).sort().join("\n"));
|
|
1011
|
+
}
|
|
1012
|
+
return claims;
|
|
1013
|
+
}
|
|
1014
|
+
const EXTENSION_KINDS = {
|
|
1015
|
+
[Kind.OBJECT_TYPE_DEFINITION]: Kind.OBJECT_TYPE_EXTENSION,
|
|
1016
|
+
[Kind.INTERFACE_TYPE_DEFINITION]: Kind.INTERFACE_TYPE_EXTENSION,
|
|
1017
|
+
[Kind.UNION_TYPE_DEFINITION]: Kind.UNION_TYPE_EXTENSION,
|
|
1018
|
+
[Kind.ENUM_TYPE_DEFINITION]: Kind.ENUM_TYPE_EXTENSION,
|
|
1019
|
+
[Kind.INPUT_OBJECT_TYPE_DEFINITION]: Kind.INPUT_OBJECT_TYPE_EXTENSION
|
|
1020
|
+
};
|
|
1021
|
+
/** One definition plus its same-kind extensions, as a single definition. */
|
|
1022
|
+
function mergeTypeNodes(nodes) {
|
|
1023
|
+
if (nodes.length === 1) return nodes[0];
|
|
1024
|
+
const definitions = nodes.filter(isTypeDefinitionNode);
|
|
1025
|
+
if (definitions.length !== 1) return void 0;
|
|
1026
|
+
const [definition] = definitions;
|
|
1027
|
+
const extensionKind = EXTENSION_KINDS[definition.kind];
|
|
1028
|
+
const merged = { ...definition };
|
|
1029
|
+
for (const node of nodes) {
|
|
1030
|
+
if (node === definition) continue;
|
|
1031
|
+
if (node.kind !== extensionKind) return void 0;
|
|
1032
|
+
const members = node;
|
|
1033
|
+
for (const key of [
|
|
1034
|
+
"fields",
|
|
1035
|
+
"interfaces",
|
|
1036
|
+
"values",
|
|
1037
|
+
"types",
|
|
1038
|
+
"directives"
|
|
1039
|
+
]) {
|
|
1040
|
+
const extra = members[key];
|
|
1041
|
+
if (extra) merged[key] = [...merged[key] ?? [], ...extra];
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
return merged;
|
|
1045
|
+
}
|
|
1046
|
+
function isRootFieldClaim(claim) {
|
|
1047
|
+
return claim.includes(".");
|
|
1048
|
+
}
|
|
1049
|
+
/** Candidates, in priority order, that lose a claim to an earlier one. */
|
|
1050
|
+
function resolveClaimOwnership(candidates) {
|
|
1051
|
+
const owners = /* @__PURE__ */ new Map();
|
|
1052
|
+
const excluded = /* @__PURE__ */ new Map();
|
|
1053
|
+
for (const { candidate, name, claims } of candidates) {
|
|
1054
|
+
const conflicts = [];
|
|
1055
|
+
for (const [claim, definition] of claims) {
|
|
1056
|
+
const owned = owners.get(claim);
|
|
1057
|
+
if (owned && (isRootFieldClaim(claim) || owned.definition !== definition)) conflicts.push({
|
|
1058
|
+
claim,
|
|
1059
|
+
owner: owned.owner
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
if (conflicts.length > 0) {
|
|
1063
|
+
excluded.set(candidate, conflicts);
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
for (const [claim, definition] of claims) if (!owners.has(claim)) owners.set(claim, {
|
|
1067
|
+
definition,
|
|
1068
|
+
owner: name
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
return excluded;
|
|
1072
|
+
}
|
|
1073
|
+
function describeOwnershipConflicts(conflicts) {
|
|
1074
|
+
return `claims owned by another subgraph: ${conflicts.map(({ claim, owner }) => `${claim} (owned by "${owner}")`).join(", ")}`;
|
|
1075
|
+
}
|
|
1076
|
+
//#endregion
|
|
1077
|
+
//#region src/graphql/subgraph-admission.ts
|
|
1078
|
+
/** Where a subgraph came from; a package origin is the package name. */
|
|
1079
|
+
const CORE_ORIGIN = Symbol("core");
|
|
1080
|
+
const DOCUMENT_MODEL_ORIGIN = Symbol("document-models");
|
|
1081
|
+
const HOST_ORIGIN = Symbol("host");
|
|
1082
|
+
function describeOrigin(origin) {
|
|
1083
|
+
if (origin === CORE_ORIGIN) return "core";
|
|
1084
|
+
if (origin === DOCUMENT_MODEL_ORIGIN) return "document models";
|
|
1085
|
+
if (origin === HOST_ORIGIN) return "the host";
|
|
1086
|
+
return `package ${origin}`;
|
|
1087
|
+
}
|
|
1088
|
+
function rank(origin) {
|
|
1089
|
+
if (origin === CORE_ORIGIN) return 3;
|
|
1090
|
+
if (origin === HOST_ORIGIN) return 2;
|
|
1091
|
+
if (origin === DOCUMENT_MODEL_ORIGIN) return 1;
|
|
1092
|
+
return 0;
|
|
1093
|
+
}
|
|
1094
|
+
/** Usable models; a refused latest version refuses every version of its model. */
|
|
1095
|
+
function admitDocumentModels(resolved, reserved) {
|
|
1096
|
+
const latest = new Set(filterLatestDocumentModelVersions(resolved.map(({ model }) => model)));
|
|
1097
|
+
const candidates = [];
|
|
1098
|
+
for (const { model, key, schema, error } of resolved) {
|
|
1099
|
+
if (!schema) {
|
|
1100
|
+
const reason = `has an unusable schema: ${error.message}`;
|
|
1101
|
+
candidates.push({
|
|
1102
|
+
model,
|
|
1103
|
+
key,
|
|
1104
|
+
refusal: {
|
|
1105
|
+
reason,
|
|
1106
|
+
subgraphOnly: false
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
continue;
|
|
1110
|
+
}
|
|
1111
|
+
const taken = reservedTypeNamesTaken(model, reserved, schema.generated);
|
|
1112
|
+
if (taken.length > 0) {
|
|
1113
|
+
const reason = `generates reserved type names: ${taken.join(", ")}`;
|
|
1114
|
+
candidates.push({
|
|
1115
|
+
model,
|
|
1116
|
+
key,
|
|
1117
|
+
refusal: {
|
|
1118
|
+
reason,
|
|
1119
|
+
subgraphOnly: false
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1124
|
+
const refusal = schema.subgraphError && {
|
|
1125
|
+
reason: `has an unusable subgraph schema: ${schema.subgraphError.message}`,
|
|
1126
|
+
subgraphOnly: true
|
|
1127
|
+
};
|
|
1128
|
+
candidates.push({
|
|
1129
|
+
model,
|
|
1130
|
+
key,
|
|
1131
|
+
schema,
|
|
1132
|
+
refusal
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
const refusedModels = new Set(candidates.filter(({ model, refusal }) => refusal && latest.has(model)).map(({ model }) => model.documentModel.global.name));
|
|
1136
|
+
const admission = {
|
|
1137
|
+
admitted: [],
|
|
1138
|
+
schemas: /* @__PURE__ */ new Map(),
|
|
1139
|
+
refusals: []
|
|
1140
|
+
};
|
|
1141
|
+
for (const { model, key, schema, refusal } of candidates) {
|
|
1142
|
+
const everyVersion = latest.has(model);
|
|
1143
|
+
if (!everyVersion && refusedModels.has(model.documentModel.global.name)) continue;
|
|
1144
|
+
if (refusal) admission.refusals.push({
|
|
1145
|
+
model,
|
|
1146
|
+
key,
|
|
1147
|
+
version: specVersion(model),
|
|
1148
|
+
everyVersion,
|
|
1149
|
+
...refusal
|
|
1150
|
+
});
|
|
1151
|
+
if (schema) {
|
|
1152
|
+
admission.schemas.set(model, schema);
|
|
1153
|
+
admission.admitted.push(model);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return admission;
|
|
1157
|
+
}
|
|
1158
|
+
const DOCUMENT_MODELS_TO_EXCLUDE = [];
|
|
1159
|
+
const specVersion = (model) => model.documentModel.global.specifications.at(-1)?.version ?? 0;
|
|
1160
|
+
/** The latest version of each document model. */
|
|
1161
|
+
function filterLatestDocumentModelVersions(documentModels) {
|
|
1162
|
+
const latestByName = /* @__PURE__ */ new Map();
|
|
1163
|
+
for (const documentModel of documentModels) {
|
|
1164
|
+
const name = documentModel.documentModel.global.name;
|
|
1165
|
+
const existing = latestByName.get(name);
|
|
1166
|
+
if (!existing || specVersion(documentModel) > specVersion(existing)) latestByName.set(name, documentModel);
|
|
1167
|
+
}
|
|
1168
|
+
return Array.from(latestByName.values());
|
|
1169
|
+
}
|
|
1170
|
+
/** The admitted models that serve a subgraph of their own, with its types. */
|
|
1171
|
+
function documentModelSubgraphSources(admitted, schemas) {
|
|
1172
|
+
const sources = [];
|
|
1173
|
+
for (const model of filterLatestDocumentModelVersions(admitted)) {
|
|
1174
|
+
if (DOCUMENT_MODELS_TO_EXCLUDE.includes(model.documentModel.global.id)) continue;
|
|
1175
|
+
const types = schemas.get(model)?.subgraph;
|
|
1176
|
+
if (types) sources.push({
|
|
1177
|
+
model,
|
|
1178
|
+
types
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
return sources;
|
|
1182
|
+
}
|
|
1183
|
+
/** Same origin replaces, higher rank evicts, else refused; core names never move (#2972). */
|
|
1184
|
+
function decideAdmission(candidate, origin, holders, collisions) {
|
|
1185
|
+
if (origin !== CORE_ORIGIN && holders.some((holder) => holder.origin === CORE_ORIGIN)) return {
|
|
1186
|
+
action: "reject",
|
|
1187
|
+
reason: "core name"
|
|
1188
|
+
};
|
|
1189
|
+
if (holders.some(({ holder }) => holder === candidate)) return { action: "skip" };
|
|
1190
|
+
const rivals = holders.filter((holder) => holder.origin !== origin);
|
|
1191
|
+
for (const rival of rivals) if (rank(origin) <= rank(rival.origin)) return {
|
|
1192
|
+
action: "reject",
|
|
1193
|
+
reason: "rank",
|
|
1194
|
+
holderOrigin: rival.origin
|
|
1195
|
+
};
|
|
1196
|
+
const found = origin === CORE_ORIGIN ? [] : collisions();
|
|
1197
|
+
if (found.length > 0) return {
|
|
1198
|
+
action: "reject",
|
|
1199
|
+
reason: "collision",
|
|
1200
|
+
collisions: found
|
|
1201
|
+
};
|
|
1202
|
+
return {
|
|
1203
|
+
action: "add",
|
|
1204
|
+
replaces: holders.filter((holder) => holder.origin === origin).map(({ holder }) => holder),
|
|
1205
|
+
evicts: rivals.map(({ holder }) => holder)
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
/** The order origins first registered in, and names within each. */
|
|
1209
|
+
var RegistrationOrder = class {
|
|
1210
|
+
#origins = /* @__PURE__ */ new Map();
|
|
1211
|
+
record(origin, name) {
|
|
1212
|
+
let entry = this.#origins.get(origin);
|
|
1213
|
+
if (!entry) {
|
|
1214
|
+
entry = {
|
|
1215
|
+
order: this.#origins.size,
|
|
1216
|
+
names: /* @__PURE__ */ new Map()
|
|
1217
|
+
};
|
|
1218
|
+
this.#origins.set(origin, entry);
|
|
1219
|
+
}
|
|
1220
|
+
if (!entry.names.has(name)) entry.names.set(name, entry.names.size);
|
|
1221
|
+
}
|
|
1222
|
+
of(origin, name) {
|
|
1223
|
+
const entry = this.#origins.get(origin);
|
|
1224
|
+
return [entry?.order ?? Infinity, entry?.names.get(name) ?? Infinity];
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
/** Rank, then first registration. */
|
|
1228
|
+
function byClaimPriority(members, originOf, nameOf, order) {
|
|
1229
|
+
return Array.from(members, (member) => {
|
|
1230
|
+
const origin = originOf(member);
|
|
1231
|
+
return {
|
|
1232
|
+
member,
|
|
1233
|
+
priority: [-rank(origin), ...order.of(origin, nameOf(member))]
|
|
1234
|
+
};
|
|
1235
|
+
}).sort((a, b) => {
|
|
1236
|
+
const i = a.priority.findIndex((value, j) => value !== b.priority[j]);
|
|
1237
|
+
return i === -1 ? 0 : a.priority[i] - b.priority[i];
|
|
1238
|
+
}).map(({ member }) => member);
|
|
1239
|
+
}
|
|
1240
|
+
/** Members that lose a claim: claims go by byClaimPriority. */
|
|
1241
|
+
function supergraphClaimLosers(members, order) {
|
|
1242
|
+
return resolveClaimOwnership(byClaimPriority(members, (member) => member.origin, (member) => member.name, order).map((member) => ({
|
|
1243
|
+
candidate: member.member,
|
|
1244
|
+
name: member.name,
|
|
1245
|
+
claims: member.claims
|
|
1246
|
+
})));
|
|
1247
|
+
}
|
|
1248
|
+
//#endregion
|
|
1249
|
+
//#region src/graphql/inspection/admin-schema.ts
|
|
1250
|
+
const inspectionAdminTypeDefs = gql`
|
|
1251
|
+
"""
|
|
1252
|
+
The levers a listed admin may pull. Only served when the host enables
|
|
1253
|
+
inspection-admin; every field refuses any other caller.
|
|
1254
|
+
"""
|
|
1255
|
+
type InspectionAdmin {
|
|
1256
|
+
"Processor retry and rerun are served."
|
|
1257
|
+
processors: Boolean!
|
|
1258
|
+
"The catch-up priority can be set."
|
|
1259
|
+
catchUpPriority: Boolean!
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
type Query {
|
|
1263
|
+
inspectionAdmin: InspectionAdmin!
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
type Mutation {
|
|
1267
|
+
"Clears a processor's error and replays from its cursor."
|
|
1268
|
+
inspectionRetryProcessor(processorId: String!): Boolean!
|
|
1269
|
+
"""
|
|
1270
|
+
Replays a processor. With clear, it and the processors sharing its clear
|
|
1271
|
+
scope are cleared and replayed from their floor; otherwise its cursor moves
|
|
1272
|
+
back to fromOrdinal, between its floor and its cursor. Answers once the
|
|
1273
|
+
replay ends or has run for two seconds; its progress shows in the
|
|
1274
|
+
processor's lastOrdinal, and a later failure in its status and the log.
|
|
1275
|
+
"""
|
|
1276
|
+
inspectionRerunProcessor(
|
|
1277
|
+
processorId: String!
|
|
1278
|
+
clear: Boolean!
|
|
1279
|
+
fromOrdinal: Float!
|
|
1280
|
+
): Boolean!
|
|
1281
|
+
"""
|
|
1282
|
+
Sets the pace of processor backfills: mode dynamic hands the level to the
|
|
1283
|
+
load controller (level must be absent); mode fixed holds level, 0-7.
|
|
1284
|
+
"""
|
|
1285
|
+
inspectionSetCatchUpPriority(mode: String!, level: Int): Boolean!
|
|
1286
|
+
}
|
|
1287
|
+
`;
|
|
1288
|
+
//#endregion
|
|
1289
|
+
//#region src/graphql/inspection/schema.ts
|
|
1290
|
+
const inspectionTypeDefs = gql`
|
|
1291
|
+
type ReactorStorageFacts {
|
|
1292
|
+
engine: String!
|
|
1293
|
+
persistence: String!
|
|
1294
|
+
durable: Boolean!
|
|
1295
|
+
selfHeal: Boolean!
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
type InspectorAccess {
|
|
1299
|
+
admin: Boolean!
|
|
1300
|
+
sql: Boolean!
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
"""
|
|
1304
|
+
What this reactor reports about itself. access is null unless the caller is
|
|
1305
|
+
one of the host's admins.
|
|
1306
|
+
"""
|
|
1307
|
+
type ReactorInfo {
|
|
1308
|
+
storage: ReactorStorageFacts!
|
|
1309
|
+
workflows: Boolean!
|
|
1310
|
+
syncChannels: [String!]!
|
|
1311
|
+
access: InspectorAccess
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
type InspectionDocumentModel {
|
|
1315
|
+
documentType: String!
|
|
1316
|
+
name: String!
|
|
1317
|
+
version: Int!
|
|
1318
|
+
supportedVersions: [Int!]!
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
type InspectionDrive {
|
|
1322
|
+
driveId: String!
|
|
1323
|
+
name: String!
|
|
1324
|
+
branch: String!
|
|
1325
|
+
collectionId: String!
|
|
1326
|
+
documentType: String!
|
|
1327
|
+
nodeCount: Int!
|
|
1328
|
+
fileCount: Int!
|
|
1329
|
+
folderCount: Int!
|
|
1330
|
+
otherNodeCount: Int!
|
|
1331
|
+
unreadableNodeCount: Int!
|
|
1332
|
+
icon: String
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
type InspectionDrivePage {
|
|
1336
|
+
results: [InspectionDrive!]!
|
|
1337
|
+
nextCursor: String
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
type InspectionDriveIntegrityRef {
|
|
1341
|
+
id: String!
|
|
1342
|
+
documentType: String!
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
type InspectionDriveIntegrity {
|
|
1346
|
+
driveId: String!
|
|
1347
|
+
checkedNodeCount: Int!
|
|
1348
|
+
totalFileNodeCount: Int!
|
|
1349
|
+
"""
|
|
1350
|
+
File nodes whose document is missing or not served to you; the two are
|
|
1351
|
+
reported alike so a withheld document's existence does not leak.
|
|
1352
|
+
"""
|
|
1353
|
+
missingDocuments: [InspectionDriveIntegrityRef!]!
|
|
1354
|
+
unsupportedTypes: [InspectionDriveIntegrityRef!]!
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
type InspectionAttachmentInfo {
|
|
1358
|
+
present: Boolean!
|
|
1359
|
+
storeKind: String!
|
|
1360
|
+
hasReplicator: Boolean!
|
|
1361
|
+
replicatorRunning: Boolean!
|
|
1362
|
+
backlogScanned: Boolean!
|
|
1363
|
+
refsSeen: Int!
|
|
1364
|
+
held: Int!
|
|
1365
|
+
bytesHeld: Float!
|
|
1366
|
+
queued: Int!
|
|
1367
|
+
fetching: Int!
|
|
1368
|
+
pendingFetches: Int!
|
|
1369
|
+
waiting: Int!
|
|
1370
|
+
notFound: Int!
|
|
1371
|
+
failed: Int!
|
|
1372
|
+
lastError: String
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
"""
|
|
1376
|
+
A queued job without its actions or operations.
|
|
1377
|
+
"""
|
|
1378
|
+
type InspectionQueueJob {
|
|
1379
|
+
id: String!
|
|
1380
|
+
kind: String!
|
|
1381
|
+
documentId: String!
|
|
1382
|
+
scope: String!
|
|
1383
|
+
branch: String!
|
|
1384
|
+
status: String!
|
|
1385
|
+
actionCount: Int!
|
|
1386
|
+
operationCount: Int!
|
|
1387
|
+
retryCount: Int!
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
type InspectionQueueState {
|
|
1391
|
+
isPaused: Boolean!
|
|
1392
|
+
totalPending: Int!
|
|
1393
|
+
totalExecuting: Int!
|
|
1394
|
+
pendingJobs: [InspectionQueueJob!]!
|
|
1395
|
+
executingJobs: [InspectionQueueJob!]!
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
type InspectionProcessor {
|
|
1399
|
+
processorId: String!
|
|
1400
|
+
factoryId: String!
|
|
1401
|
+
driveId: String!
|
|
1402
|
+
processorIndex: Int!
|
|
1403
|
+
lastOrdinal: Float!
|
|
1404
|
+
status: String!
|
|
1405
|
+
lastError: String
|
|
1406
|
+
lastErrorTimestampUtcMs: Float
|
|
1407
|
+
floor: Float!
|
|
1408
|
+
clearable: Boolean!
|
|
1409
|
+
runFrom: Float!
|
|
1410
|
+
phase: String!
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
"""
|
|
1414
|
+
What one catch-up priority level sets. giveWay is stop (level 0: no page is
|
|
1415
|
+
read until the level rises), pause (pauseMs between pages), yield (one
|
|
1416
|
+
event-loop turn) or none.
|
|
1417
|
+
"""
|
|
1418
|
+
type InspectionCatchUpLevelSettings {
|
|
1419
|
+
slots: Int!
|
|
1420
|
+
pageSize: Int!
|
|
1421
|
+
pauseMs: Int!
|
|
1422
|
+
giveWay: String!
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
"""
|
|
1426
|
+
The host's load over its last window, as the dynamic controller read it.
|
|
1427
|
+
"""
|
|
1428
|
+
type InspectionCatchUpLoadSample {
|
|
1429
|
+
requests: Int!
|
|
1430
|
+
p95LatencyMs: Float!
|
|
1431
|
+
eventLoopDelayMs: Float!
|
|
1432
|
+
idleForMs: Float!
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
"""
|
|
1436
|
+
The pace of processor backfills. mode is fixed or dynamic; level is 0-7.
|
|
1437
|
+
sample is null until a dynamic tick has sampled the host's load.
|
|
1438
|
+
"""
|
|
1439
|
+
type InspectionCatchUpPriority {
|
|
1440
|
+
mode: String!
|
|
1441
|
+
level: Int!
|
|
1442
|
+
settings: InspectionCatchUpLevelSettings!
|
|
1443
|
+
reason: String!
|
|
1444
|
+
sample: InspectionCatchUpLoadSample
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
"""
|
|
1448
|
+
healthy means something only when tracked; an untracked store reports false.
|
|
1449
|
+
"""
|
|
1450
|
+
type InspectionStorageHealth {
|
|
1451
|
+
tracked: Boolean!
|
|
1452
|
+
healthy: Boolean!
|
|
1453
|
+
everRecreated: Boolean!
|
|
1454
|
+
recreateCount: Int!
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
"""
|
|
1458
|
+
Issues in scopes the caller may not read are left out.
|
|
1459
|
+
"""
|
|
1460
|
+
type InspectionValidation {
|
|
1461
|
+
documentId: String!
|
|
1462
|
+
isConsistent: Boolean!
|
|
1463
|
+
keyframeIssues: [JSONObject!]!
|
|
1464
|
+
snapshotIssues: [JSONObject!]!
|
|
1465
|
+
streamOrderIssues: [JSONObject!]!
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
type InspectionCursor {
|
|
1469
|
+
cursorType: String!
|
|
1470
|
+
cursorOrdinal: Float!
|
|
1471
|
+
lastSyncedAtUtcMs: Float
|
|
1472
|
+
liveAckOrdinal: Float!
|
|
1473
|
+
liveLatestOrdinal: Float!
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
type InspectionMailboxDepths {
|
|
1477
|
+
inbox: Int!
|
|
1478
|
+
outbox: Int!
|
|
1479
|
+
deadLetter: Int!
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
type InspectionConnectionHealth {
|
|
1483
|
+
snapshot: JSONObject!
|
|
1484
|
+
neverSucceeded: Boolean!
|
|
1485
|
+
stalenessMs: Float
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
type InspectionRemote {
|
|
1489
|
+
remoteName: String!
|
|
1490
|
+
remoteId: String!
|
|
1491
|
+
inboxCursor: InspectionCursor!
|
|
1492
|
+
outboxCursor: InspectionCursor!
|
|
1493
|
+
mailboxDepths: InspectionMailboxDepths!
|
|
1494
|
+
connection: InspectionConnectionHealth!
|
|
1495
|
+
meta: JSONObject!
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
"""
|
|
1499
|
+
A dead letter without its operations.
|
|
1500
|
+
"""
|
|
1501
|
+
type InspectionDeadLetter {
|
|
1502
|
+
id: String!
|
|
1503
|
+
jobId: String!
|
|
1504
|
+
documentId: String!
|
|
1505
|
+
branch: String!
|
|
1506
|
+
scopes: [String!]!
|
|
1507
|
+
errorType: String!
|
|
1508
|
+
errorMessage: String!
|
|
1509
|
+
operationCount: Int!
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
type InspectionDeadLetterPage {
|
|
1513
|
+
remoteName: String!
|
|
1514
|
+
results: [InspectionDeadLetter!]!
|
|
1515
|
+
nextCursor: String
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
"""
|
|
1519
|
+
Reads only. info and documentModels serve every caller; drive and document
|
|
1520
|
+
reads are made as the caller through the reactor read gate; the rest need
|
|
1521
|
+
one of the host's admins.
|
|
1522
|
+
"""
|
|
1523
|
+
type ReactorInspection {
|
|
1524
|
+
info: ReactorInfo!
|
|
1525
|
+
documentModels: [InspectionDocumentModel!]!
|
|
1526
|
+
drives(cursor: String, limit: Int): InspectionDrivePage!
|
|
1527
|
+
"""
|
|
1528
|
+
Reads every file node's document. Throttled per caller.
|
|
1529
|
+
"""
|
|
1530
|
+
driveIntegrity(driveId: String!, branch: String!): InspectionDriveIntegrity!
|
|
1531
|
+
attachmentInfo: InspectionAttachmentInfo!
|
|
1532
|
+
queueState: InspectionQueueState!
|
|
1533
|
+
processors: [InspectionProcessor!]!
|
|
1534
|
+
catchUpStatus: JSONObject!
|
|
1535
|
+
catchUpPriority: InspectionCatchUpPriority!
|
|
1536
|
+
storageHealth: InspectionStorageHealth!
|
|
1537
|
+
"""
|
|
1538
|
+
Replays the whole document; expensive. Throttled per caller.
|
|
1539
|
+
"""
|
|
1540
|
+
validateDocument(documentId: String!, branch: String): InspectionValidation!
|
|
1541
|
+
remotes: [InspectionRemote!]!
|
|
1542
|
+
remote(remoteName: String!): InspectionRemote!
|
|
1543
|
+
deadLetters(
|
|
1544
|
+
remoteName: String!
|
|
1545
|
+
cursor: String
|
|
1546
|
+
limit: Int
|
|
1547
|
+
): InspectionDeadLetterPage!
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
type Query {
|
|
1551
|
+
inspection: ReactorInspection!
|
|
1552
|
+
}
|
|
1553
|
+
`;
|
|
1554
|
+
//#endregion
|
|
1555
|
+
//#region src/graphql/reactor/schema.graphql
|
|
1556
|
+
var schema_default = "# Scalar types (for codegen - also defined in create-schema.ts)\nscalar JSONObject\nscalar DateTime\n\n# Input types\ninput PagingInput {\n limit: Int\n offset: Int\n cursor: String\n}\n\ninput ViewFilterInput {\n branch: String\n scopes: [String!]\n}\n\ninput SearchFilterInput {\n type: String\n parentId: String\n identifiers: [String!]\n @deprecated(reason: \"Ignored. Filter by type or parentId.\")\n}\n\ninput OperationsFilterInput {\n documentIdOrSlug: String\n documentId: String @deprecated(reason: \"Use documentIdOrSlug.\")\n branch: String\n scopes: [String!]\n actionTypes: [String!]\n sinceRevision: Int\n timestampFrom: String\n timestampTo: String\n}\n\n\"A consistency token's coordinate, as ConsistencyCoordinate reports it.\"\ninput ConsistencyCoordinateInput {\n documentId: String!\n scope: String!\n branch: String!\n operationIndex: Int!\n}\n\n\"\"\"\nA consistency token, as JobInfo.consistencyToken reports it. A read given one\nwaits until the read models it reads from hold every coordinate it names.\n\"\"\"\ninput ConsistencyTokenInput {\n version: Int!\n createdAtUtcIso: String!\n coordinates: [ConsistencyCoordinateInput!]!\n}\n\ninput DocumentOperationsFilterInput {\n branch: String\n scopes: [String!]\n actionTypes: [String!]\n sinceRevision: Int\n timestampFrom: String\n timestampTo: String\n}\n\n# Enums\nenum PropagationMode {\n CASCADE\n ORPHAN\n}\n\nenum DocumentChangeType {\n CREATED\n DELETED\n UPDATED\n PARENT_ADDED\n PARENT_REMOVED\n CHILD_ADDED\n CHILD_REMOVED\n}\n\n# Object types\ntype DocumentModelGlobalState {\n id: String!\n name: String!\n namespace: String\n version: String\n specification: JSONObject!\n}\n\ntype DocumentModelResultPage {\n items: [DocumentModelGlobalState!]!\n hasNextPage: Boolean!\n hasPreviousPage: Boolean!\n cursor: String\n}\n\ntype Revision {\n scope: String!\n revision: Int!\n}\n\ntype PHDocument {\n id: String!\n slug: String\n preferredEditor: String\n meta: JSONObject\n protocolVersions: JSONObject\n name: String!\n documentType: String!\n state: JSONObject!\n revisionsList: [Revision!]!\n createdAtUtcIso: DateTime!\n lastModifiedAtUtcIso: DateTime!\n operations(\n filter: DocumentOperationsFilterInput\n paging: PagingInput\n ): ReactorOperationResultPage\n}\n\ntype PHDocumentResultPage {\n items: [PHDocument!]!\n hasNextPage: Boolean!\n hasPreviousPage: Boolean!\n cursor: String\n}\n\n# A directed edge between two documents, with the metadata recorded against it.\ntype DocumentRelationship {\n sourceId: String!\n targetId: String!\n relationshipType: String!\n metadata: JSONObject\n createdAt: DateTime!\n updatedAt: DateTime!\n}\n\ntype DocumentRelationshipResultPage {\n items: [DocumentRelationship!]!\n hasNextPage: Boolean!\n hasPreviousPage: Boolean!\n cursor: String\n}\n\ntype ReactorOperationResultPage {\n items: [ReactorOperation!]!\n hasNextPage: Boolean!\n hasPreviousPage: Boolean!\n cursor: String\n}\n\ntype DeadLetterInfo {\n documentId: String!\n error: String!\n \"\"\"\n How the origin classified the failure. A peer needs this to mirror the origin's\n quarantine decision; without it a held auth operation would freeze the document\n on the peer side while the origin kept syncing.\n \"\"\"\n errorType: String\n jobId: String!\n branch: String!\n scopes: [String!]!\n operationCount: Int!\n}\n\ntype PollSyncEnvelopesResult {\n envelopes: [SyncEnvelope!]!\n ackOrdinal: Int!\n deadLetters: [DeadLetterInfo!]!\n hasMore: Boolean!\n # The server's current manifest revision\n manifestRevision: String\n # The client's manifest revision as the server holds it\n peerManifestRevision: String\n}\n\ntype SyncHoldReason {\n protocol: String!\n version: Int!\n peerSupports: [Int!]!\n}\n\n# A document held back from a remote whose peer cannot run its versions\ntype SyncHold {\n remoteName: String!\n documentId: String!\n branch: String!\n reason: SyncHoldReason!\n heldAtUtcMs: String!\n}\n\ntype PeerAgreementMember {\n remoteName: String!\n # False for a peer that announced nothing: it gets the baselines\n announced: Boolean!\n protocols: JSONObject!\n features: JSONObject!\n}\n\ntype PeerAgreementLimit {\n protocol: String!\n # The remotes whose peers lack the version new documents would take\n remoteNames: [String!]!\n}\n\ntype PeerAgreement {\n collectionId: String!\n local: JSONObject!\n members: [PeerAgreementMember!]!\n limitedBy: [PeerAgreementLimit!]!\n}\n\n# The kind of a drive node.\nenum DriveNodeKind {\n FILE\n FOLDER\n}\n\n# A file node: the document it names, placed in a drive.\ntype DriveFileNode {\n id: ID!\n driveId: ID!\n name: String!\n parentFolder: ID\n documentType: String!\n}\n\n# A folder node.\ntype DriveFolderNode {\n id: ID!\n driveId: ID!\n name: String!\n parentFolder: ID\n}\n\n# A drive node, of any drive document type.\nunion DriveNode = DriveFileNode | DriveFolderNode\n\n# A page of drive nodes. nextCursor resumes after the last node served.\ntype DriveNodePage {\n results: [DriveNode!]!\n nextCursor: String\n hasMore: Boolean!\n}\n\ntype DocumentWithChildren {\n document: PHDocument!\n childIds: [String!]!\n}\n\n# What a new document gets when its creator chooses nothing\ntype CreateDefaults {\n # \"legacy\" or \"v2-required\"; a client refuses a value it does not know\n signaturePolicy: String!\n protocolVersions: JSONObject!\n}\n\ntype MoveRelationshipResult {\n source: PHDocument!\n target: PHDocument!\n}\n\ntype ConsistencyCoordinate {\n documentId: String!\n scope: String!\n branch: String!\n operationIndex: Int!\n}\n\n\"\"\"\nThe write positions a job reached, for read-after-write. Only meaningful once\nthe job has completed.\n\"\"\"\ntype ConsistencyToken {\n version: Int!\n createdAtUtcIso: String!\n coordinates: [ConsistencyCoordinate!]!\n}\n\n\"The batch a job was submitted in.\"\ntype JobBatchMeta {\n batchId: String!\n batchJobIds: [String!]!\n}\n\ntype JobInfo {\n id: String!\n\n \"\"\"\n The document the job operates on. Empty for a job this server does not know,\n which then comes back FAILED with \"Job not found\".\n \"\"\"\n documentId: String!\n status: String!\n\n \"\"\"\n What the job produced, once it has produced anything. Null until then, which\n is the state every job is in when it is handed back from a submission.\n \"\"\"\n result: JSONObject\n\n error: String\n\n \"The error's class name, such as `DocumentAlreadyExistsError`, when it failed.\"\n errorName: String\n createdAt: DateTime!\n completedAt: DateTime\n consistencyToken: ConsistencyToken!\n meta: JobBatchMeta!\n}\n\n\"\"\"\nOne job's outcome within a batch, pairing the plan key the caller gave with the\njob that applied it. Mirrors one entry of the `Record<string, JobInfo>` that\n`IReactor.executeBatch` returns (packages/reactor/src/core/types.ts).\n\"\"\"\ntype BatchJobResult {\n key: String!\n job: JobInfo!\n}\n\n\"\"\"\nThe outcome of a batch mutation, one entry per job the request named. The wire\nshape of `BatchExecutionResult` (`{ jobs }`), keyed on each entry by the plan\nkey rather than by position so the client can rebuild the record. The batch is\nnot atomic: each job commits on its own and a failed job releases its\ndependents, so each entry's status says what happened to that job, and\nre-submitting re-applies the jobs that succeeded.\n\"\"\"\ntype BatchExecutionResult {\n jobs: [BatchJobResult!]!\n}\n\ntype DocumentChangeEvent {\n type: DocumentChangeType!\n documents: [PHDocument!]!\n context: DocumentChangeContext\n}\n\ntype DocumentChangeContext {\n parentId: String\n childId: String\n}\n\ntype JobChangeEvent {\n jobId: String!\n status: String!\n\n \"\"\"\n What the job produced, once it has produced anything. Nullable for the same\n reason as `JobInfo.result`: a job that has not written yet has produced\n nothing, and an empty object would claim otherwise.\n \"\"\"\n result: JSONObject\n\n error: String\n}\n\ntype ReactorSignerUser {\n address: String!\n networkId: String!\n chainId: Int!\n}\n\ntype ReactorSignerApp {\n name: String!\n key: String!\n}\n\ntype ReactorSigner {\n user: ReactorSignerUser\n app: ReactorSignerApp\n signatures: [String!]!\n}\n\ntype ActionContext {\n signer: ReactorSigner\n}\n\ntype Action {\n id: String!\n type: String!\n timestampUtcMs: String!\n input: JSONObject!\n scope: String!\n context: ActionContext\n}\n\n\"\"\"\nOne operation an authorization preflight predicts a verdict for.\n\n`input` is what a conditional grant reads, so a candidate standing for a\nfilled-in form carries that form's input. Omitting it predicts the verdict an\nempty input earns, not the verdict the filled-in form will get.\n\"\"\"\ninput ActionCandidateInput {\n scope: String!\n type: String!\n input: JSONObject\n}\n\nenum AuthDecision {\n ALLOW\n DENY\n}\n\n\"\"\"\nOne candidate's predicted verdict. `reason` carries the refusal a DENY is\nrecorded with, and is null on an ALLOW.\n\"\"\"\ntype ActionEvaluation {\n decision: AuthDecision!\n reason: String\n}\n\n\"\"\"\nThe predicted verdicts for a set of candidates, in the order they were given,\nwith the aggregates a caller branches on.\n\nThe aggregates are redundant -- a verdict is binary -- and all four are returned\nso a caller reads the one its question is phrased in rather than negating\nanother. Over no candidates every aggregate is false: nothing is allowed and\nnothing is denied.\n\"\"\"\ntype ActionEvaluations {\n evaluations: [ActionEvaluation!]!\n allAllowed: Boolean!\n anyAllowed: Boolean!\n allDenied: Boolean!\n anyDenied: Boolean!\n}\n\n# Input types for sync operations\n\"\"\"\nAn action's context, as a caller submits it.\n\nDeclares every field `ActionContext` carries, because an input object rejects a\nfield it does not declare: an action stamped with the head it applies to - which\nis what a signing client sends - is refused outright if these are missing, and\nthat refusal is a whole-request one, not a per-field one.\n\n`prevOpHash` and `prevOpIndex` are the scope head the action was composed\nagainst. They are recorded rather than enforced; a signature is verified from\nthe params carried in its own tuple, which do not include them.\n\"\"\"\ninput ActionContextInput {\n \"\"\"\n The index of the last operation in the scope the action applies to.\n \"\"\"\n prevOpIndex: Int\n\n \"\"\"\n The hash of the state the action applies to.\n \"\"\"\n prevOpHash: String\n\n \"\"\"\n Covers replay of an operation that would otherwise be a no-op.\n \"\"\"\n nonce: String\n\n signer: ReactorSignerInput\n}\n\ninput ReactorSignerInput {\n user: ReactorSignerUserInput\n app: ReactorSignerAppInput\n signatures: [String!]!\n}\n\ninput ReactorSignerUserInput {\n address: String!\n networkId: String!\n chainId: Int!\n}\n\ninput ReactorSignerAppInput {\n name: String!\n key: String!\n}\n\ninput ActionInput {\n id: String!\n type: String!\n timestampUtcMs: String!\n input: JSONObject!\n scope: String!\n context: ActionContextInput\n}\n\n\"\"\"\nOne mutation job of a batch, mirroring the reactor's `ExecutionJobPlan`\n(packages/reactor/src/core/types.ts). The batch runs its jobs in dependency\norder only, not atomically: each job commits on its own with no batch rollback,\nand a failed job still releases its dependents.\n\n`documentIdOrSlug` is the document the job's actions apply to -- an id that does\nnot yet exist when the job's actions create it. `actions` are coerced against\n`ActionInput` and passed through exactly as `execute` does, so a client-signed\naction keeps its signature. `scope` is the single scope every action in the job\nshares, and `dependsOn` names the plan keys this job is ordered after. `branch`\ndefaults to `main`.\n\"\"\"\ninput ExecutionJobInput {\n key: String!\n documentIdOrSlug: String!\n scope: String!\n branch: String\n actions: [ActionInput!]!\n dependsOn: [String!]!\n}\n\n# Synchronization types\ntype ReactorOperation {\n index: Int!\n timestampUtcMs: String!\n hash: String!\n skip: Int!\n error: String\n deniedReason: String\n id: String\n action: Action!\n}\n\ninput OperationInput {\n index: Int!\n timestampUtcMs: String!\n hash: String!\n skip: Int!\n error: String\n deniedReason: String\n id: String\n action: ActionInput!\n}\n\ntype OperationContext {\n documentId: String!\n documentType: String!\n scope: String!\n branch: String!\n ordinal: Int!\n}\n\ninput OperationContextInput {\n documentId: String!\n documentType: String!\n scope: String!\n branch: String!\n ordinal: Int!\n}\n\ntype OperationWithContext {\n operation: ReactorOperation!\n context: OperationContext!\n}\n\ninput OperationWithContextInput {\n operation: OperationInput!\n context: OperationContextInput!\n}\n\ntype ChannelMeta {\n id: String!\n}\n\ninput ChannelMetaInput {\n id: String!\n}\n\ntype RemoteCursor {\n remoteName: String!\n cursorOrdinal: Int!\n lastSyncedAtUtcMs: String\n}\n\ninput RemoteCursorInput {\n remoteName: String!\n cursorOrdinal: Int!\n lastSyncedAtUtcMs: String\n}\n\nenum SyncEnvelopeType {\n OPERATIONS\n ACK\n}\n\ntype SyncEnvelope {\n type: SyncEnvelopeType!\n channelMeta: ChannelMeta!\n operations: [OperationWithContext!]\n cursor: RemoteCursor\n key: String\n dependsOn: [String!]\n}\n\ninput SyncEnvelopeInput {\n type: SyncEnvelopeType!\n channelMeta: ChannelMetaInput!\n operations: [OperationWithContextInput!]\n cursor: RemoteCursorInput\n key: String\n dependsOn: [String!]\n}\n\ninput RemoteFilterInput {\n documentId: [String!]!\n scope: [String!]!\n branch: String!\n}\n\ninput SyncRefusalInput {\n documentId: String!\n branch: String!\n # \"marker\" for a refused purge marker; absent for UNSUPPORTED_PROTOCOL\n kind: String\n}\n\ninput TouchChannelInput {\n id: String!\n name: String!\n collectionId: String!\n filter: RemoteFilterInput!\n sinceTimestampUtcMs: String!\n # The client's peer manifest; absent from a client without peer agreement\n manifest: JSONObject\n}\n\ntype TouchChannelResult {\n success: Boolean!\n ackOrdinal: Int!\n # The server's peer manifest\n manifest: JSONObject\n}\n\ntype Query {\n # Get document models for a namespace\n documentModels(\n namespace: String\n paging: PagingInput\n ): DocumentModelResultPage!\n\n # Get a specific document by ID or slug\n document(\n idOrSlug: String\n identifier: String @deprecated(reason: \"Use idOrSlug.\")\n view: ViewFilterInput\n consistency: ConsistencyTokenInput\n ): DocumentWithChildren\n\n # Get outgoing relationships of a given type from a source document\n documentOutgoingRelationships(\n sourceIdOrSlug: String\n sourceIdentifier: String @deprecated(reason: \"Use sourceIdOrSlug.\")\n relationshipType: String!\n view: ViewFilterInput\n paging: PagingInput\n consistency: ConsistencyTokenInput\n ): PHDocumentResultPage!\n\n # Get incoming relationships of a given type to a target document\n documentIncomingRelationships(\n targetIdOrSlug: String\n targetIdentifier: String @deprecated(reason: \"Use targetIdOrSlug.\")\n relationshipType: String!\n view: ViewFilterInput\n paging: PagingInput\n consistency: ConsistencyTokenInput\n ): PHDocumentResultPage!\n\n # Get the outgoing relationship edges of a source document. Unlike\n # documentOutgoingRelationships, which returns the documents at the far end,\n # this returns the edges themselves, carrying their metadata and timestamps.\n # Omit relationshipType to return edges of every type.\n documentOutgoingRelationshipEdges(\n sourceIdOrSlug: String\n sourceIdentifier: String @deprecated(reason: \"Use sourceIdOrSlug.\")\n relationshipType: String\n view: ViewFilterInput\n paging: PagingInput\n consistency: ConsistencyTokenInput\n ): DocumentRelationshipResultPage!\n\n # Get the incoming relationship edges of a target document. Unlike\n # documentIncomingRelationships, which returns the documents at the far end,\n # this returns the edges themselves, carrying their metadata and timestamps.\n # Omit relationshipType to return edges of every type.\n documentIncomingRelationshipEdges(\n targetIdOrSlug: String\n targetIdentifier: String @deprecated(reason: \"Use targetIdOrSlug.\")\n relationshipType: String\n view: ViewFilterInput\n paging: PagingInput\n consistency: ConsistencyTokenInput\n ): DocumentRelationshipResultPage!\n\n # Find documents by search criteria\n findDocuments(\n search: SearchFilterInput\n view: ViewFilterInput\n paging: PagingInput\n consistency: ConsistencyTokenInput\n ): PHDocumentResultPage!\n\n # Get job status\n jobStatus(jobId: String!): JobInfo\n\n # Whether findDocuments would serve the document to the caller. Absent or\n # withheld is false; a server that cannot decide answers with an error.\n documentServed(idOrSlug: String!, view: ViewFilterInput): Boolean!\n\n # The signature policy and protocol versions a new document gets, under the\n # parent when one is named. A parent the caller may not read is refused.\n # With documentType, protocolVersions fit that type's reducer.\n createDefaults(parentIdOrSlug: String, documentType: String): CreateDefaults!\n\n # Get operations for a document with filtering and pagination\n documentOperations(\n filter: OperationsFilterInput!\n paging: PagingInput\n ): ReactorOperationResultPage!\n\n \"\"\"\n Predicts whether the calling subject would be admitted to execute each of a\n set of candidate operations, without submitting any of them. A UI asks this to\n disable a control rather than offer an action that fails on submit.\n\n The answer is a prediction, not a promise:\n\n - Real admission compiles an append condition over everything it read and the\n store enforces it at write time. A preflight reads no future, so a policy\n change landing between this answer and the submit changes the verdict. The\n submit path stays the only authority.\n - The verdict is evaluated at the stream heads, so it is correct for a\n candidate about to be submitted. A backdated submission is out of contract;\n the reactor decides that one by position.\n - A candidate whose verdict depends on its input has to carry that input, since\n a conditional grant reads it.\n\n The subject is the authenticated caller and cannot be named in the request:\n answering for an arbitrary subject would disclose what a policy grants\n somebody else. It carries both the caller's address and the did:key of the app\n instance whose token authenticated the request, so a policy naming either\n matches the same principal the write path presents.\n\n Requires the reactor's authEnforcement feature flag. Without it the reactor\n holds no decision model, so this fails with extensions.code\n AUTH_EVALUATION_UNSUPPORTED rather than guessing.\n \"\"\"\n evaluateActions(\n documentIdOrSlug: String\n documentIdentifier: String @deprecated(reason: \"Use documentIdOrSlug.\")\n branch: String\n candidates: [ActionCandidateInput!]!\n ): ActionEvaluations!\n\n \"\"\"\n Polls for sync envelopes from a channel.\n\n An operation stored before the API required an action id cannot be\n represented by this schema, and rather than serving a partial response beside\n a bare non-null violation, this fails with extensions.code\n MALFORMED_STORED_OPERATION naming the operation. That code means the failure\n is worth polling through: the document holding the operation needs repairing,\n but the channel serves every other document, and a peer that stopped polling\n would stop receiving those too.\n \"\"\"\n pollSyncEnvelopes(\n channelId: String!\n outboxAck: Int!\n outboxLatest: Int!\n # The client's manifest revision; absent from a client without peer agreement\n manifestRevision: String\n # Documents the client refused from earlier polls: held, or a refused marker\n refusals: [SyncRefusalInput!]\n ): PollSyncEnvelopesResult!\n\n # Supreme admin, or the address the named remote's channel is bound to\n syncHolds(remoteName: String, documentId: String): [SyncHold!]!\n\n # Supreme admin, or an address bound to a channel in the collection\n peerAgreement(collectionId: String!): PeerAgreement!\n\n # A drive's nodes, for every drive document type. Omit parentFolder for every\n # node in the drive; pass null for the root level. A drive the caller may not\n # read lists nothing, and a file node is listed only with its document.\n driveNodes(\n driveId: ID!\n parentFolder: ID\n paging: PagingInput\n kind: DriveNodeKind\n ): DriveNodePage!\n\n # One drive node; null when absent or withheld from the caller.\n driveNode(driveId: ID!, id: ID!): DriveNode\n\n # Every node under root (inclusive) the caller may read.\n driveDescendants(driveId: ID!, root: ID!): [DriveNode!]!\n}\n\ntype Mutation {\n # Create a new document\n createDocument(\n document: JSONObject!\n parentIdOrSlug: String\n parentIdentifier: String @deprecated(reason: \"Use parentIdOrSlug.\")\n ): PHDocument!\n\n # Create an empty document of specified type\n createEmptyDocument(\n documentType: String!\n parentIdOrSlug: String\n parentIdentifier: String @deprecated(reason: \"Use parentIdOrSlug.\")\n ): PHDocument!\n\n \"\"\"\n Applies actions to a document and waits for the result.\n\n Each action is coerced against `ActionInput`, so one missing a field the wire\n declares is refused before any work starts. The id in particular: it is hashed\n into the operation id and replay dedupes by it, so an action without one is\n stored under an operation id shared by every id-less operation on the same\n document, scope and branch.\n\n Named for `IReactorClient.execute`, which this is the wire form of. `branch`\n defaults to `main`.\n \"\"\"\n execute(\n documentIdOrSlug: String\n documentIdentifier: String @deprecated(reason: \"Use documentIdOrSlug.\")\n actions: [ActionInput!]!\n branch: String\n ): PHDocument!\n\n \"\"\"\n Submits actions to a document and returns the job that will apply them.\n\n Coerced exactly as `execute` is, so a malformed action is refused here rather\n than surfacing later as a failed job. Returns the job rather than only its id,\n so a caller has the status and the creation time it would otherwise have to\n ask for; `result` is null until the job produces one.\n \"\"\"\n executeAsync(\n documentIdOrSlug: String\n documentIdentifier: String @deprecated(reason: \"Use documentIdOrSlug.\")\n actions: [ActionInput!]!\n branch: String\n ): JobInfo!\n\n \"\"\"\n Applies multiple mutation jobs in dependency order and waits for all of them,\n the wire form of `IReactorClient.executeBatch`. Each job's actions are coerced\n against `ActionInput` exactly as `execute` is, so client-signed actions pass\n through unchanged, and `dependsOn` orders the jobs. It is synchronous: the jobs\n are applied and awaited before the result returns, so every returned `JobInfo`\n is a completed one rather than the pending receipt the in-process reactor hands\n back. A batch is ordering, not a transaction: each job commits on its own, and\n a failed job still releases the jobs that depend on it, so any job, before or\n after a failure, may have committed. A failed job is therefore returned as a\n FAILED entry with its `error` and `errorName`, beside the final state of every\n other job, rather than failing the mutation. The mutation itself fails only\n when no job state can be reported.\n\n A job carrying `CREATE_DOCUMENT` must be the batch's only job, with the create\n as its first action naming the job's document. Its other actions may only be\n an `UPGRADE_DOCUMENT` of the new document and `ADD_RELATIONSHIP`s targeting\n it. It is authorized like `createDocument`: write on every source of those\n relationships, or the right to create when there is none.\n \"\"\"\n executeBatch(jobs: [ExecutionJobInput!]!): BatchExecutionResult!\n\n # Apply actions to a document (synchronous)\n mutateDocument(\n documentIdentifier: String!\n actions: [JSONObject!]!\n view: ViewFilterInput\n ): PHDocument!\n @deprecated(\n reason: \"Use execute. Actions here are untyped, so a malformed one is refused by a hand-written check rather than by the schema, and `view.scopes` is accepted but ignored.\"\n )\n\n # Submit actions to a document (asynchronous)\n mutateDocumentAsync(\n documentIdentifier: String!\n actions: [JSONObject!]!\n view: ViewFilterInput\n ): String!\n @deprecated(\n reason: \"Use executeAsync, which is typed and returns the job rather than only its id.\"\n )\n\n # Rename a document\n renameDocument(\n documentIdOrSlug: String\n documentIdentifier: String @deprecated(reason: \"Use documentIdOrSlug.\")\n name: String!\n branch: String\n ): PHDocument!\n\n # Update the preferred editor recorded in the document header meta.\n # Pass null/omit to clear it.\n setPreferredEditor(\n documentIdOrSlug: String\n documentIdentifier: String @deprecated(reason: \"Use documentIdOrSlug.\")\n preferredEditor: String\n branch: String\n ): PHDocument!\n\n # Add a relationship between two documents. Adding one that already exists is\n # a no-op, metadata included -- use updateRelationship to change an edge.\n addRelationship(\n sourceIdOrSlug: String\n sourceIdentifier: String @deprecated(reason: \"Use sourceIdOrSlug.\")\n targetIdOrSlug: String\n targetIdentifier: String @deprecated(reason: \"Use targetIdOrSlug.\")\n relationshipType: String!\n metadata: JSONObject\n branch: String\n ): PHDocument!\n\n # Replace the metadata of an existing relationship, preserving its createdAt.\n # Omitting metadata, or passing null, clears it.\n updateRelationship(\n sourceIdOrSlug: String\n sourceIdentifier: String @deprecated(reason: \"Use sourceIdOrSlug.\")\n targetIdOrSlug: String\n targetIdentifier: String @deprecated(reason: \"Use targetIdOrSlug.\")\n relationshipType: String!\n metadata: JSONObject\n branch: String\n ): PHDocument!\n\n # Remove a relationship between two documents\n removeRelationship(\n sourceIdOrSlug: String\n sourceIdentifier: String @deprecated(reason: \"Use sourceIdOrSlug.\")\n targetIdOrSlug: String\n targetIdentifier: String @deprecated(reason: \"Use targetIdOrSlug.\")\n relationshipType: String!\n branch: String\n ): PHDocument!\n\n # Move a relationship from one source to another\n moveRelationship(\n sourceParentIdOrSlug: String\n sourceParentIdentifier: String\n @deprecated(reason: \"Use sourceParentIdOrSlug.\")\n targetParentIdOrSlug: String\n targetParentIdentifier: String\n @deprecated(reason: \"Use targetParentIdOrSlug.\")\n targetIdOrSlug: String\n targetIdentifier: String @deprecated(reason: \"Use targetIdOrSlug.\")\n relationshipType: String!\n branch: String\n ): MoveRelationshipResult!\n\n # Delete a single document\n deleteDocument(\n idOrSlug: String\n identifier: String @deprecated(reason: \"Use idOrSlug.\")\n propagate: PropagationMode\n ): Boolean!\n\n # Delete multiple documents\n deleteDocuments(\n idsOrSlugs: [String!]\n identifiers: [String!] @deprecated(reason: \"Use idsOrSlugs.\")\n propagate: PropagationMode\n ): Boolean!\n\n # Touch (create or update) a channel for sync\n touchChannel(input: TouchChannelInput!): TouchChannelResult!\n\n # Push sync envelopes to a channel\n pushSyncEnvelopes(\n envelopes: [SyncEnvelopeInput!]!\n # The server's manifest revision the client gated these envelopes under\n peerManifestRevision: String\n ): Boolean!\n}\n\ntype Subscription {\n # Subscribe to document changes\n documentChanges(\n search: SearchFilterInput\n view: ViewFilterInput\n ): DocumentChangeEvent!\n\n # Subscribe to job changes\n jobChanges(jobId: String!): JobChangeEvent!\n}\n";
|
|
1557
|
+
//#endregion
|
|
1558
|
+
//#region src/graphql/system/schema.ts
|
|
1559
|
+
const systemTypeDefs = gql`
|
|
1560
|
+
type SystemInfo {
|
|
1561
|
+
version: String!
|
|
1562
|
+
gitHash: String!
|
|
1563
|
+
gitUrl: String
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
type Query {
|
|
1567
|
+
system: SystemInfo!
|
|
1568
|
+
}
|
|
1569
|
+
`;
|
|
1570
|
+
//#endregion
|
|
1571
|
+
//#region src/packages/base-document-models.ts
|
|
1572
|
+
/** The models every host loads before any package's, by source package. */
|
|
1573
|
+
const baseDocumentModels = [
|
|
1574
|
+
["document-drive", driveDocumentModelModule],
|
|
1575
|
+
["document-model", documentModelDocumentModelModule],
|
|
1576
|
+
["reactor-drive", reactorDriveDocumentModelModule],
|
|
1577
|
+
["reactor-group", ReactorGroupV1]
|
|
1578
|
+
];
|
|
1579
|
+
//#endregion
|
|
1580
|
+
export { getDocumentModelSubgraphName as A, createMergedSchema as C, generateDocumentModelSchema as D, findSubgraphTypeCollisions as E, reservedTypeNamesTaken as F, typeDefinitionNames as I, EMPTY_SCALAR_REGISTRY as L, getGeneratedDocumentModelTypes as M, hasOperationSchemas as N, generatedTypesOf as O, reservedTypeNames as P, sameScalarRegistry as R, buildSubgraphSchemaModule as S, documentModelSubgraphTypes as T, describeOwnershipConflicts as _, inspectionAdminTypeDefs as a, assembleSubgraphTypeDefs as b, HOST_ORIGIN as c, byClaimPriority as d, decideAdmission as f, collectSubgraphClaims as g, supergraphClaimLosers as h, inspectionTypeDefs as i, getDocumentModelTypeDefs as j, getDocumentModelSchemaName as k, RegistrationOrder as l, documentModelSubgraphSources as m, systemTypeDefs as n, CORE_ORIGIN as o, describeOrigin as p, schema_default as r, DOCUMENT_MODEL_ORIGIN as s, baseDocumentModels as t, admitDocumentModels as u, DocumentModelSchemaCache as v, createSchema as w, buildDocumentModelSchema as x, SubgraphTypeCollisionError as y, schema_default$1 as z };
|
|
1581
|
+
|
|
1582
|
+
//# sourceMappingURL=base-document-models-D-cmBBYJ.mjs.map
|
|
1583
|
+
//# debugId=15ba8214-2497-5db6-b2f0-f5342ed231ba
|