@powerhousedao/reactor-api 6.2.3-dev.94 → 6.2.3-dev.95

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.
@@ -1,15 +1,15 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5196867a-cd79-5e29-9a40-a98ed396d70d")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="392c1b84-7a7a-5715-91f3-f9595a6367d3")}catch(e){}}();
3
3
  import { childLogger, documentModelDocumentModelModule, inspectDocumentModelDefinition, projectDocumentModelGraphQL } from "document-model";
4
4
  import { gql } from "graphql-tag";
5
5
  import { GraphQLScalarType, Kind, Lexer, Source, TokenKind, isTypeDefinitionNode, isTypeExtensionNode, parse, print, valueFromASTUntyped, visit } from "graphql";
6
6
  import { createHash } from "node:crypto";
7
7
  import { scalarCatalog } from "document-model/scalars";
8
+ import { camelCase, kebabCase, pascalCase } from "change-case";
8
9
  import { GraphQLJSON, GraphQLJSONObject } from "graphql-type-json";
9
10
  import { inspect, isDeepStrictEqual } from "node:util";
10
11
  import { z } from "zod";
11
12
  import { buildSubgraphSchema } from "@apollo/subgraph";
12
- import { camelCase, kebabCase, pascalCase } from "change-case";
13
13
  import { reactorDriveDocumentModelModule } from "@powerhousedao/reactor-drive";
14
14
  import { ReactorGroupV1 } from "@powerhousedao/reactor-group";
15
15
  import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
@@ -83,217 +83,6 @@ function registeredScalarType(definition) {
83
83
  });
84
84
  }
85
85
  //#endregion
86
- //#region src/graphql/document-model-schema/schema-ast.ts
87
- const EMPTY_DOCUMENT = {
88
- kind: Kind.DOCUMENT,
89
- definitions: []
90
- };
91
- const OUTPUT_TYPE_KINDS = [
92
- Kind.OBJECT_TYPE_DEFINITION,
93
- Kind.OBJECT_TYPE_EXTENSION,
94
- Kind.ENUM_TYPE_DEFINITION,
95
- Kind.ENUM_TYPE_EXTENSION,
96
- Kind.UNION_TYPE_DEFINITION,
97
- Kind.UNION_TYPE_EXTENSION,
98
- Kind.INTERFACE_TYPE_DEFINITION,
99
- Kind.INTERFACE_TYPE_EXTENSION
100
- ];
101
- const STATE_PREFIX_KINDS = new Set(OUTPUT_TYPE_KINDS);
102
- const ALL_PREFIX_KINDS = /* @__PURE__ */ new Set([
103
- ...OUTPUT_TYPE_KINDS,
104
- Kind.INPUT_OBJECT_TYPE_DEFINITION,
105
- Kind.INPUT_OBJECT_TYPE_EXTENSION
106
- ]);
107
- const TYPE_NAME_KINDS = /* @__PURE__ */ new Set([
108
- ...ALL_PREFIX_KINDS,
109
- Kind.SCALAR_TYPE_DEFINITION,
110
- Kind.SCALAR_TYPE_EXTENSION,
111
- Kind.NAMED_TYPE
112
- ]);
113
- const LOCAL_STATE_STUBS = /* @__PURE__ */ new Set([
114
- "AccountSnapshotLocalState",
115
- "BudgetStatementLocalState",
116
- "ScopeFrameworkLocalState"
117
- ]);
118
- /** Parse SDL; blank or comment-only input yields an empty document. */
119
- function parseSdl(sdl) {
120
- const source = new Source(sdl);
121
- if (new Lexer(source).advance().kind === TokenKind.EOF) return EMPTY_DOCUMENT;
122
- try {
123
- return parse(source, { noLocation: true });
124
- } catch (error) {
125
- const withoutSemicolons = sdl.replaceAll(";", "");
126
- if (withoutSemicolons === sdl) throw error;
127
- return parse(withoutSemicolons, { noLocation: true });
128
- }
129
- }
130
- function definedTypeNames(doc, kinds) {
131
- return doc.definitions.filter((def) => kinds.has(def.kind)).map((def) => def.name.value);
132
- }
133
- /** Prefix type definition names and type references found in `names`. */
134
- function prefixTypeNames(doc, prefix, names) {
135
- return visit(doc, { enter(node) {
136
- if (!TYPE_NAME_KINDS.has(node.kind)) return void 0;
137
- const { name } = node;
138
- if (!names.has(name.value)) return void 0;
139
- return {
140
- ...node,
141
- name: {
142
- ...name,
143
- value: `${prefix}_${name.value}`
144
- }
145
- };
146
- } });
147
- }
148
- /** State schema definitions without inputs, `DateTime` or the given object types. */
149
- function stateDefinitions(doc, droppedObjectTypes = /* @__PURE__ */ new Set()) {
150
- return doc.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)));
151
- }
152
- /** The state types and the document type a model adds to the generated schema. */
153
- function generatedModelDefinitions(dmSchemaName, global, local) {
154
- const stateDoc = {
155
- kind: Kind.DOCUMENT,
156
- definitions: [...stateDefinitions(global), ...stateDefinitions(local, LOCAL_STATE_STUBS)]
157
- };
158
- const prefixed = prefixTypeNames(stateDoc, dmSchemaName, new Set(definedTypeNames(stateDoc, STATE_PREFIX_KINDS)));
159
- const documentType = parseSdl(`
160
- type ${dmSchemaName} implements IDocument {
161
- id: String!
162
- name: String!
163
- documentType: String!
164
- operations(skip: Int, first: Int): [Operation!]!
165
- revision: Int!
166
- createdAtUtcIso: DateTime!
167
- lastModifiedAtUtcIso: DateTime!
168
- ${dmSchemaName !== "DocumentModel" ? `initialState: ${dmSchemaName}_${dmSchemaName}State!` : ""}
169
- ${dmSchemaName !== "DocumentModel" ? `state: ${dmSchemaName}_${dmSchemaName}State!` : ""}
170
- stateJSON: JSONObject
171
- }`);
172
- return [...prefixed.definitions, ...documentType.definitions];
173
- }
174
- /**
175
- * Print the input type definitions of a schema document.
176
- * @param excludeTypeNames - Input type names to leave out
177
- */
178
- function printInputTypeDefinitions(doc, excludeTypeNames = /* @__PURE__ */ new Set()) {
179
- const definitions = doc.definitions.filter((def) => def.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION && !excludeTypeNames.has(def.name.value));
180
- if (definitions.length === 0) return "";
181
- return print({
182
- kind: Kind.DOCUMENT,
183
- definitions
184
- });
185
- }
186
- /**
187
- * Apply type prefixes to GraphQL schema to namespace types and avoid collisions.
188
- * Inlined from @powerhousedao/common/utils to avoid ES module import issues.
189
- * @param {string} schema - GraphQL schema string
190
- * @param {string} prefix - Prefix to apply to type names
191
- * @param {string[]} externalTypeNames - Type names from other schemas to also prefix
192
- * @returns {string} Schema with prefixed types
193
- */
194
- function applyGraphQLTypePrefixes(schema, prefix, externalTypeNames = []) {
195
- if (!schema || !schema.trim()) return schema;
196
- const doc = parseSdl(schema);
197
- const names = /* @__PURE__ */ new Set([...definedTypeNames(doc, ALL_PREFIX_KINDS), ...externalTypeNames]);
198
- if (names.size === 0) return schema;
199
- return print(prefixTypeNames(doc, prefix, names));
200
- }
201
- function printModuleOperations(operations, documentName, names) {
202
- const definitions = operations.flatMap((doc) => {
203
- return prefixTypeNames(doc, documentName, /* @__PURE__ */ new Set([...names, ...definedTypeNames(doc, ALL_PREFIX_KINDS)])).definitions;
204
- });
205
- return definitions.length === 0 ? null : print({
206
- kind: Kind.DOCUMENT,
207
- definitions
208
- });
209
- }
210
- function globalStateTypeName(documentName) {
211
- return documentName === "DocumentModel" ? `${documentName}_${documentName}GlobalState` : `${documentName}_${documentName}State`;
212
- }
213
- /**
214
- * Extract the root state type name from a scope's GraphQL schema.
215
- * Uses the naming convention: {DocumentName}State for global,
216
- * {DocumentName}{PascalScope}State for other scopes (e.g., DocumentDriveLocalState).
217
- * Falls back to the last ObjectTypeDefinition (root types are conventionally last).
218
- */
219
- function rootTypeName(ast, documentName, scopeName) {
220
- const candidates = [`${documentName}${scopeName === "global" ? "" : pascalCase(scopeName)}State`, `${documentName}${pascalCase(scopeName)}State`];
221
- let lastObjectType = null;
222
- for (const def of ast.definitions) if (def.kind === Kind.OBJECT_TYPE_DEFINITION) {
223
- if (candidates.includes(def.name.value)) return def.name.value;
224
- lastObjectType = def.name.value;
225
- }
226
- return lastObjectType;
227
- }
228
- /**
229
- * Convert a GraphQL output type AST node to an optional input type string.
230
- * Strips non-null markers and converts object type references to Input suffix.
231
- */
232
- function convertTypeNodeToInput(typeNode, objectNames, unionNames, interfaceNames) {
233
- if (typeNode.kind === Kind.NON_NULL_TYPE && typeNode.type) return convertTypeNodeToInput(typeNode.type, objectNames, unionNames, interfaceNames);
234
- if (typeNode.kind === Kind.LIST_TYPE && typeNode.type) return `[${convertTypeNodeToInput(typeNode.type, objectNames, unionNames, interfaceNames)}]`;
235
- if (typeNode.kind === Kind.NAMED_TYPE && typeNode.name) {
236
- const name = typeNode.name.value;
237
- if (objectNames.has(name)) return `${name}Input`;
238
- if (unionNames.has(name) || interfaceNames.has(name)) return "JSONObject";
239
- return name;
240
- }
241
- return "JSONObject";
242
- }
243
- /**
244
- * Generate GraphQL input type definitions from a state schema document.
245
- * Converts output type definitions to input types with all fields optional.
246
- * - Object type references get Input suffix
247
- * - Union/interface references become JSONObject
248
- * - Enums and scalars remain unchanged
249
- */
250
- function stateInputTypes(ast, excludeTypeNames) {
251
- const enumNames = /* @__PURE__ */ new Set();
252
- const unionNames = /* @__PURE__ */ new Set();
253
- const interfaceNames = /* @__PURE__ */ new Set();
254
- const objectNames = /* @__PURE__ */ new Set();
255
- const existingInputNames = /* @__PURE__ */ new Set();
256
- for (const def of ast.definitions) switch (def.kind) {
257
- case Kind.ENUM_TYPE_DEFINITION:
258
- enumNames.add(def.name.value);
259
- break;
260
- case Kind.UNION_TYPE_DEFINITION:
261
- unionNames.add(def.name.value);
262
- break;
263
- case Kind.INTERFACE_TYPE_DEFINITION:
264
- interfaceNames.add(def.name.value);
265
- break;
266
- case Kind.OBJECT_TYPE_DEFINITION:
267
- objectNames.add(def.name.value);
268
- break;
269
- case Kind.INPUT_OBJECT_TYPE_DEFINITION: existingInputNames.add(def.name.value);
270
- }
271
- const inputTypes = [];
272
- for (const def of ast.definitions) {
273
- if (def.kind !== Kind.OBJECT_TYPE_DEFINITION) continue;
274
- const inputName = `${def.name.value}Input`;
275
- if (existingInputNames.has(inputName)) continue;
276
- if (excludeTypeNames?.has(inputName)) continue;
277
- const fields = def.fields ?? [];
278
- if (fields.length === 0) continue;
279
- const inputFields = fields.map((field) => {
280
- return ` ${field.name.value}: ${convertTypeNodeToInput(field.type, objectNames, unionNames, interfaceNames)}`;
281
- });
282
- inputTypes.push(`input ${def.name.value}Input {\n${inputFields.join("\n")}\n}`);
283
- }
284
- return inputTypes.join("\n\n");
285
- }
286
- function scopeInitialState(ast, documentName, scopeName, allTypeNames) {
287
- const rootName = rootTypeName(ast, documentName, scopeName);
288
- if (!rootName) return { type: "JSONObject" };
289
- const scopeInputTypes = stateInputTypes(ast, new Set(allTypeNames));
290
- if (!scopeInputTypes) return { type: "JSONObject" };
291
- return {
292
- type: `${documentName}_${rootName}Input`,
293
- inputTypes: applyGraphQLTypePrefixes(scopeInputTypes, documentName, allTypeNames)
294
- };
295
- }
296
- //#endregion
297
86
  //#region src/graphql/model-schema-templates.ts
298
87
  /**
299
88
  * Revision type - matches the definition in reactor/schema.graphql.
@@ -531,6 +320,217 @@ function generateNewApiSchema(projection) {
531
320
  ${printModuleSchemas(projection.modules)}`;
532
321
  }
533
322
  //#endregion
323
+ //#region src/graphql/document-model-schema/schema-ast.ts
324
+ const EMPTY_DOCUMENT = {
325
+ kind: Kind.DOCUMENT,
326
+ definitions: []
327
+ };
328
+ const OUTPUT_TYPE_KINDS = [
329
+ Kind.OBJECT_TYPE_DEFINITION,
330
+ Kind.OBJECT_TYPE_EXTENSION,
331
+ Kind.ENUM_TYPE_DEFINITION,
332
+ Kind.ENUM_TYPE_EXTENSION,
333
+ Kind.UNION_TYPE_DEFINITION,
334
+ Kind.UNION_TYPE_EXTENSION,
335
+ Kind.INTERFACE_TYPE_DEFINITION,
336
+ Kind.INTERFACE_TYPE_EXTENSION
337
+ ];
338
+ const STATE_PREFIX_KINDS = new Set(OUTPUT_TYPE_KINDS);
339
+ const ALL_PREFIX_KINDS = /* @__PURE__ */ new Set([
340
+ ...OUTPUT_TYPE_KINDS,
341
+ Kind.INPUT_OBJECT_TYPE_DEFINITION,
342
+ Kind.INPUT_OBJECT_TYPE_EXTENSION
343
+ ]);
344
+ const TYPE_NAME_KINDS = /* @__PURE__ */ new Set([
345
+ ...ALL_PREFIX_KINDS,
346
+ Kind.SCALAR_TYPE_DEFINITION,
347
+ Kind.SCALAR_TYPE_EXTENSION,
348
+ Kind.NAMED_TYPE
349
+ ]);
350
+ const LOCAL_STATE_STUBS = /* @__PURE__ */ new Set([
351
+ "AccountSnapshotLocalState",
352
+ "BudgetStatementLocalState",
353
+ "ScopeFrameworkLocalState"
354
+ ]);
355
+ /** Parse SDL; blank or comment-only input yields an empty document. */
356
+ function parseSdl(sdl) {
357
+ const source = new Source(sdl);
358
+ if (new Lexer(source).advance().kind === TokenKind.EOF) return EMPTY_DOCUMENT;
359
+ try {
360
+ return parse(source, { noLocation: true });
361
+ } catch (error) {
362
+ const withoutSemicolons = sdl.replaceAll(";", "");
363
+ if (withoutSemicolons === sdl) throw error;
364
+ return parse(withoutSemicolons, { noLocation: true });
365
+ }
366
+ }
367
+ function definedTypeNames(doc, kinds) {
368
+ return doc.definitions.filter((def) => kinds.has(def.kind)).map((def) => def.name.value);
369
+ }
370
+ /** Prefix type definition names and type references found in `names`. */
371
+ function prefixTypeNames(doc, prefix, names) {
372
+ return visit(doc, { enter(node) {
373
+ if (!TYPE_NAME_KINDS.has(node.kind)) return void 0;
374
+ const { name } = node;
375
+ if (!names.has(name.value)) return void 0;
376
+ return {
377
+ ...node,
378
+ name: {
379
+ ...name,
380
+ value: `${prefix}_${name.value}`
381
+ }
382
+ };
383
+ } });
384
+ }
385
+ /** State schema definitions without inputs, `DateTime` or the given object types. */
386
+ function stateDefinitions(doc, droppedObjectTypes = /* @__PURE__ */ new Set()) {
387
+ return doc.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)));
388
+ }
389
+ /** The state types and the document type a model adds to the generated schema. */
390
+ function generatedModelDefinitions(dmSchemaName, global, local) {
391
+ const stateDoc = {
392
+ kind: Kind.DOCUMENT,
393
+ definitions: [...stateDefinitions(global), ...stateDefinitions(local, LOCAL_STATE_STUBS)]
394
+ };
395
+ const prefixed = prefixTypeNames(stateDoc, dmSchemaName, new Set(definedTypeNames(stateDoc, STATE_PREFIX_KINDS)));
396
+ const documentType = parseSdl(`
397
+ type ${dmSchemaName} implements IDocument {
398
+ id: String!
399
+ name: String!
400
+ documentType: String!
401
+ operations(skip: Int, first: Int): [Operation!]!
402
+ revision: Int!
403
+ createdAtUtcIso: DateTime!
404
+ lastModifiedAtUtcIso: DateTime!
405
+ ${dmSchemaName !== "DocumentModel" ? `initialState: ${dmSchemaName}_${dmSchemaName}State!` : ""}
406
+ ${dmSchemaName !== "DocumentModel" ? `state: ${dmSchemaName}_${dmSchemaName}State!` : ""}
407
+ stateJSON: JSONObject
408
+ }`);
409
+ return [...prefixed.definitions, ...documentType.definitions];
410
+ }
411
+ /**
412
+ * Print the input type definitions of a schema document.
413
+ * @param excludeTypeNames - Input type names to leave out
414
+ */
415
+ function printInputTypeDefinitions(doc, excludeTypeNames = /* @__PURE__ */ new Set()) {
416
+ const definitions = doc.definitions.filter((def) => def.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION && !excludeTypeNames.has(def.name.value));
417
+ if (definitions.length === 0) return "";
418
+ return print({
419
+ kind: Kind.DOCUMENT,
420
+ definitions
421
+ });
422
+ }
423
+ /**
424
+ * Apply type prefixes to GraphQL schema to namespace types and avoid collisions.
425
+ * Inlined from @powerhousedao/common/utils to avoid ES module import issues.
426
+ * @param {string} schema - GraphQL schema string
427
+ * @param {string} prefix - Prefix to apply to type names
428
+ * @param {string[]} externalTypeNames - Type names from other schemas to also prefix
429
+ * @returns {string} Schema with prefixed types
430
+ */
431
+ function applyGraphQLTypePrefixes(schema, prefix, externalTypeNames = []) {
432
+ if (!schema || !schema.trim()) return schema;
433
+ const doc = parseSdl(schema);
434
+ const names = /* @__PURE__ */ new Set([...definedTypeNames(doc, ALL_PREFIX_KINDS), ...externalTypeNames]);
435
+ if (names.size === 0) return schema;
436
+ return print(prefixTypeNames(doc, prefix, names));
437
+ }
438
+ function printModuleOperations(operations, documentName, names) {
439
+ const definitions = operations.flatMap((doc) => {
440
+ return prefixTypeNames(doc, documentName, /* @__PURE__ */ new Set([...names, ...definedTypeNames(doc, ALL_PREFIX_KINDS)])).definitions;
441
+ });
442
+ return definitions.length === 0 ? null : print({
443
+ kind: Kind.DOCUMENT,
444
+ definitions
445
+ });
446
+ }
447
+ function globalStateTypeName(documentName) {
448
+ return documentName === "DocumentModel" ? `${documentName}_${documentName}GlobalState` : `${documentName}_${documentName}State`;
449
+ }
450
+ /**
451
+ * Extract the root state type name from a scope's GraphQL schema.
452
+ * Uses the naming convention: {DocumentName}State for global,
453
+ * {DocumentName}{PascalScope}State for other scopes (e.g., DocumentDriveLocalState).
454
+ * Falls back to the last ObjectTypeDefinition (root types are conventionally last).
455
+ */
456
+ function rootTypeName(ast, documentName, scopeName) {
457
+ const candidates = [`${documentName}${scopeName === "global" ? "" : pascalCase(scopeName)}State`, `${documentName}${pascalCase(scopeName)}State`];
458
+ let lastObjectType = null;
459
+ for (const def of ast.definitions) if (def.kind === Kind.OBJECT_TYPE_DEFINITION) {
460
+ if (candidates.includes(def.name.value)) return def.name.value;
461
+ lastObjectType = def.name.value;
462
+ }
463
+ return lastObjectType;
464
+ }
465
+ /**
466
+ * Convert a GraphQL output type AST node to an optional input type string.
467
+ * Strips non-null markers and converts object type references to Input suffix.
468
+ */
469
+ function convertTypeNodeToInput(typeNode, objectNames, unionNames, interfaceNames) {
470
+ if (typeNode.kind === Kind.NON_NULL_TYPE && typeNode.type) return convertTypeNodeToInput(typeNode.type, objectNames, unionNames, interfaceNames);
471
+ if (typeNode.kind === Kind.LIST_TYPE && typeNode.type) return `[${convertTypeNodeToInput(typeNode.type, objectNames, unionNames, interfaceNames)}]`;
472
+ if (typeNode.kind === Kind.NAMED_TYPE && typeNode.name) {
473
+ const name = typeNode.name.value;
474
+ if (objectNames.has(name)) return `${name}Input`;
475
+ if (unionNames.has(name) || interfaceNames.has(name)) return "JSONObject";
476
+ return name;
477
+ }
478
+ return "JSONObject";
479
+ }
480
+ /**
481
+ * Generate GraphQL input type definitions from a state schema document.
482
+ * Converts output type definitions to input types with all fields optional.
483
+ * - Object type references get Input suffix
484
+ * - Union/interface references become JSONObject
485
+ * - Enums and scalars remain unchanged
486
+ */
487
+ function stateInputTypes(ast, excludeTypeNames) {
488
+ const enumNames = /* @__PURE__ */ new Set();
489
+ const unionNames = /* @__PURE__ */ new Set();
490
+ const interfaceNames = /* @__PURE__ */ new Set();
491
+ const objectNames = /* @__PURE__ */ new Set();
492
+ const existingInputNames = /* @__PURE__ */ new Set();
493
+ for (const def of ast.definitions) switch (def.kind) {
494
+ case Kind.ENUM_TYPE_DEFINITION:
495
+ enumNames.add(def.name.value);
496
+ break;
497
+ case Kind.UNION_TYPE_DEFINITION:
498
+ unionNames.add(def.name.value);
499
+ break;
500
+ case Kind.INTERFACE_TYPE_DEFINITION:
501
+ interfaceNames.add(def.name.value);
502
+ break;
503
+ case Kind.OBJECT_TYPE_DEFINITION:
504
+ objectNames.add(def.name.value);
505
+ break;
506
+ case Kind.INPUT_OBJECT_TYPE_DEFINITION: existingInputNames.add(def.name.value);
507
+ }
508
+ const inputTypes = [];
509
+ for (const def of ast.definitions) {
510
+ if (def.kind !== Kind.OBJECT_TYPE_DEFINITION) continue;
511
+ const inputName = `${def.name.value}Input`;
512
+ if (existingInputNames.has(inputName)) continue;
513
+ if (excludeTypeNames?.has(inputName)) continue;
514
+ const fields = def.fields ?? [];
515
+ if (fields.length === 0) continue;
516
+ const inputFields = fields.map((field) => {
517
+ return ` ${field.name.value}: ${convertTypeNodeToInput(field.type, objectNames, unionNames, interfaceNames)}`;
518
+ });
519
+ inputTypes.push(`input ${def.name.value}Input {\n${inputFields.join("\n")}\n}`);
520
+ }
521
+ return inputTypes.join("\n\n");
522
+ }
523
+ function scopeInitialState(ast, documentName, scopeName, allTypeNames) {
524
+ const rootName = rootTypeName(ast, documentName, scopeName);
525
+ if (!rootName) return { type: "JSONObject" };
526
+ const scopeInputTypes = stateInputTypes(ast, new Set(allTypeNames));
527
+ if (!scopeInputTypes) return { type: "JSONObject" };
528
+ return {
529
+ type: `${documentName}_${rootName}Input`,
530
+ inputTypes: applyGraphQLTypePrefixes(scopeInputTypes, documentName, allTypeNames)
531
+ };
532
+ }
533
+ //#endregion
534
534
  //#region src/graphql/document-model-schema/model-projection.ts
535
535
  function buildModelProjection(documentName, documents) {
536
536
  const allTypeNames = [.../* @__PURE__ */ new Set([...documents.stateTypeNames, ...documents.operationTypeNames])];
@@ -778,31 +778,48 @@ function structuredDefinitionDigest(model) {
778
778
  /**
779
779
  * The one place a host selects how a document model's schema is built: from
780
780
  * its structured definition when it carries a valid, matching one, else from
781
- * its stored SDL.
781
+ * its stored SDL. Logs nothing; `fallback` says why a definition is not served.
782
782
  */
783
- function documentModelSchemaSource(model) {
783
+ function selectDocumentModelSchemaSource(model) {
784
784
  const { global } = model.documentModel;
785
785
  let inspection;
786
786
  try {
787
787
  inspection = inspectDocumentModelDefinition(model);
788
788
  } catch (error) {
789
- warnOnce(global.id, "unreadable", error);
790
- return storedSchemaSource(global);
791
- }
792
- if (inspection.kind === "stored") {
793
- if (inspection.reason === "invalid" || inspection.reason === "mismatch") warnOnce(global.id, inspection.reason, inspection.diagnostics);
794
- return storedSchemaSource(global);
789
+ return {
790
+ source: storedSchemaSource(global),
791
+ fallback: {
792
+ reason: "unreadable",
793
+ error
794
+ }
795
+ };
795
796
  }
797
+ if (inspection.kind === "stored") return {
798
+ source: storedSchemaSource(global),
799
+ ...(inspection.reason === "invalid" || inspection.reason === "mismatch") && { fallback: {
800
+ reason: inspection.reason,
801
+ diagnostics: inspection.diagnostics
802
+ } }
803
+ };
796
804
  const entry = project(inspection);
797
- if ("error" in entry) {
798
- warnOnce(global.id, "unreadable", entry.error);
799
- return storedSchemaSource(global);
800
- }
805
+ if ("error" in entry) return {
806
+ source: storedSchemaSource(global),
807
+ fallback: {
808
+ reason: "unreadable",
809
+ error: entry.error
810
+ }
811
+ };
801
812
  let source = entry.sources.get(global.name);
802
813
  if (source === void 0) {
803
814
  source = structuredSchemaSource(entry.projection, global);
804
815
  entry.sources.set(global.name, source);
805
816
  }
817
+ return { source };
818
+ }
819
+ /** {@link selectDocumentModelSchemaSource}, logging a fallback once per document type and reason. */
820
+ function documentModelSchemaSource(model) {
821
+ const { source, fallback } = selectDocumentModelSchemaSource(model);
822
+ if (fallback !== void 0) warnOnce(model.documentModel.global.id, fallback.reason, "diagnostics" in fallback ? fallback.diagnostics : fallback.error);
806
823
  return source;
807
824
  }
808
825
  //#endregion
@@ -2054,7 +2071,7 @@ const baseDocumentModels = [
2054
2071
  ["reactor-group", ReactorGroupV1]
2055
2072
  ];
2056
2073
  //#endregion
2057
- export { getDocumentModelTypeDefs as A, schema_default$1 as B, createMergedSchema as C, generateDocumentModelSchema as D, findSubgraphTypeCollisions as E, typeDefinitionNames as F, documentModelSchemaSource as I, getDocumentModelSchemaName as L, hasOperationSchemas as M, reservedTypeNames as N, generatedTypesOf as O, reservedTypeNamesTaken as P, EMPTY_SCALAR_REGISTRY 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, getGeneratedDocumentModelTypes as j, getDocumentModelSubgraphName 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, sameScalarRegistry as z };
2074
+ export { getDocumentModelTypeDefs as A, sameScalarRegistry as B, createMergedSchema as C, generateDocumentModelSchema as D, findSubgraphTypeCollisions as E, typeDefinitionNames as F, documentModelSchemaSource as I, selectDocumentModelSchemaSource as L, hasOperationSchemas as M, reservedTypeNames as N, generatedTypesOf as O, reservedTypeNamesTaken as P, getDocumentModelSchemaName as R, buildSubgraphSchemaModule as S, documentModelSubgraphTypes as T, schema_default$1 as V, 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, getGeneratedDocumentModelTypes as j, getDocumentModelSubgraphName 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, EMPTY_SCALAR_REGISTRY as z };
2058
2075
 
2059
- //# sourceMappingURL=base-document-models-577xnrmL.mjs.map
2060
- //# debugId=5196867a-cd79-5e29-9a40-a98ed396d70d
2076
+ //# sourceMappingURL=base-document-models-CCYv5XxL.mjs.map
2077
+ //# debugId=392c1b84-7a7a-5715-91f3-f9595a6367d3