@cmssy/core 10.5.2 → 10.6.1

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.
@@ -62,12 +62,38 @@ type CmssyEnvConfig = Omit<CmssyConfig, "org" | "workspaceSlug" | "draftSecret">
62
62
  */
63
63
  declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyConfig;
64
64
 
65
+ /**
66
+ * Accepting a *typed* document, not a string, is what makes a query's variables
67
+ * and its result checked together. graphql-codegen emits one of three shapes,
68
+ * and the SDK takes all of them so an app never has to care which mode its
69
+ * codegen runs in - or add `graphql` to its runtime dependencies to print an
70
+ * AST it already has.
71
+ */
72
+ /**
73
+ * A document that carries its result and variable types. Structurally
74
+ * compatible with `TypedDocumentNode` (`@graphql-typed-document-node/core`) and
75
+ * with graphql-codegen's `TypedDocumentString`, both of which declare the same
76
+ * phantom `__apiType`.
77
+ */
78
+ interface CmssyTypedDocument<Result, Variables> {
79
+ __apiType?: (variables: Variables) => Result;
80
+ }
81
+
65
82
  interface QueryScopedOptions extends GraphqlRequestOptions {
66
83
  workspaceId?: string;
67
84
  }
68
85
  interface CmssyClient {
69
86
  readonly config: CmssyClientConfig;
87
+ /**
88
+ * Hand it a document that carries its types (what graphql-codegen emits, in
89
+ * either mode) and the variables are checked and the result inferred; hand it
90
+ * a query string and it behaves exactly as before. Same method, no second
91
+ * way to do the same thing.
92
+ */
93
+ query<Result, Variables>(document: CmssyTypedDocument<Result, Variables>, variables: Variables, options?: GraphqlRequestOptions): Promise<Result>;
70
94
  query<T = unknown>(document: string, variables?: Record<string, unknown>, options?: GraphqlRequestOptions): Promise<T>;
95
+ /** {@link CmssyClient.query} with the workspace id resolved and injected. */
96
+ queryScoped<Result, Variables>(document: CmssyTypedDocument<Result, Variables>, variables: Omit<Variables, "workspaceId">, options?: QueryScopedOptions): Promise<Result>;
71
97
  queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
72
98
  resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
73
99
  }
@@ -186,4 +212,4 @@ declare function toCspOrigin(origin: string): string;
186
212
  declare function cmssyCspHeaders(options: CmssyCspOptions): Record<string, string>;
187
213
  declare function applyCmssyCsp<T extends MutableHeaders>(response: T, options: CmssyCspOptions): T;
188
214
 
189
- export { type AppToEditorMessage as A, type BoundsMessage as B, type ClickMessage as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, type SelectMessage as S, type CmssyClient as a, type CmssyConfig as b, type CmssyCspOptions as c, type CmssyEnvConfig as d, type ParentReadyMessage as e, type PatchMessage as f, type PostTarget as g, applyCmssyCsp as h, createCmssyClient as i, defineCmssyConfig as j, isProtocolCompatible as k, postToEditor as l, cmssyCspHeaders as m, normalizeOrigin as n, isDevelopment as o, parseEditorMessage as p, resolveInitialTarget as q, resolveEditorOrigin as r, toCspOrigin as t };
215
+ export { type AppToEditorMessage as A, type BoundsMessage as B, type ClickMessage as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, type SelectMessage as S, type CmssyClient as a, type CmssyConfig as b, type CmssyCspOptions as c, type CmssyEnvConfig as d, type CmssyTypedDocument as e, type ParentReadyMessage as f, type PatchMessage as g, type PostTarget as h, applyCmssyCsp as i, createCmssyClient as j, defineCmssyConfig as k, isProtocolCompatible as l, postToEditor as m, normalizeOrigin as n, cmssyCspHeaders as o, parseEditorMessage as p, isDevelopment as q, resolveEditorOrigin as r, resolveInitialTarget as s, toCspOrigin as t };
@@ -62,12 +62,38 @@ type CmssyEnvConfig = Omit<CmssyConfig, "org" | "workspaceSlug" | "draftSecret">
62
62
  */
63
63
  declare function defineCmssyConfig(config: CmssyEnvConfig): CmssyConfig;
64
64
 
65
+ /**
66
+ * Accepting a *typed* document, not a string, is what makes a query's variables
67
+ * and its result checked together. graphql-codegen emits one of three shapes,
68
+ * and the SDK takes all of them so an app never has to care which mode its
69
+ * codegen runs in - or add `graphql` to its runtime dependencies to print an
70
+ * AST it already has.
71
+ */
72
+ /**
73
+ * A document that carries its result and variable types. Structurally
74
+ * compatible with `TypedDocumentNode` (`@graphql-typed-document-node/core`) and
75
+ * with graphql-codegen's `TypedDocumentString`, both of which declare the same
76
+ * phantom `__apiType`.
77
+ */
78
+ interface CmssyTypedDocument<Result, Variables> {
79
+ __apiType?: (variables: Variables) => Result;
80
+ }
81
+
65
82
  interface QueryScopedOptions extends GraphqlRequestOptions {
66
83
  workspaceId?: string;
67
84
  }
68
85
  interface CmssyClient {
69
86
  readonly config: CmssyClientConfig;
87
+ /**
88
+ * Hand it a document that carries its types (what graphql-codegen emits, in
89
+ * either mode) and the variables are checked and the result inferred; hand it
90
+ * a query string and it behaves exactly as before. Same method, no second
91
+ * way to do the same thing.
92
+ */
93
+ query<Result, Variables>(document: CmssyTypedDocument<Result, Variables>, variables: Variables, options?: GraphqlRequestOptions): Promise<Result>;
70
94
  query<T = unknown>(document: string, variables?: Record<string, unknown>, options?: GraphqlRequestOptions): Promise<T>;
95
+ /** {@link CmssyClient.query} with the workspace id resolved and injected. */
96
+ queryScoped<Result, Variables>(document: CmssyTypedDocument<Result, Variables>, variables: Omit<Variables, "workspaceId">, options?: QueryScopedOptions): Promise<Result>;
71
97
  queryScoped<T = unknown>(document: string, variables?: Record<string, unknown>, options?: QueryScopedOptions): Promise<T>;
72
98
  resolveWorkspaceId(options?: GraphqlRequestOptions): Promise<string>;
73
99
  }
@@ -186,4 +212,4 @@ declare function toCspOrigin(origin: string): string;
186
212
  declare function cmssyCspHeaders(options: CmssyCspOptions): Record<string, string>;
187
213
  declare function applyCmssyCsp<T extends MutableHeaders>(response: T, options: CmssyCspOptions): T;
188
214
 
189
- export { type AppToEditorMessage as A, type BoundsMessage as B, type ClickMessage as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, type SelectMessage as S, type CmssyClient as a, type CmssyConfig as b, type CmssyCspOptions as c, type CmssyEnvConfig as d, type ParentReadyMessage as e, type PatchMessage as f, type PostTarget as g, applyCmssyCsp as h, createCmssyClient as i, defineCmssyConfig as j, isProtocolCompatible as k, postToEditor as l, cmssyCspHeaders as m, normalizeOrigin as n, isDevelopment as o, parseEditorMessage as p, resolveInitialTarget as q, resolveEditorOrigin as r, toCspOrigin as t };
215
+ export { type AppToEditorMessage as A, type BoundsMessage as B, type ClickMessage as C, DEFAULT_CMSSY_EDITOR_ORIGINS as D, type EditorToAppMessage as E, PROTOCOL_VERSION as P, type QueryScopedOptions as Q, type ReadyMessage as R, type SelectMessage as S, type CmssyClient as a, type CmssyConfig as b, type CmssyCspOptions as c, type CmssyEnvConfig as d, type CmssyTypedDocument as e, type ParentReadyMessage as f, type PatchMessage as g, type PostTarget as h, applyCmssyCsp as i, createCmssyClient as j, defineCmssyConfig as k, isProtocolCompatible as l, postToEditor as m, normalizeOrigin as n, cmssyCspHeaders as o, parseEditorMessage as p, isDevelopment as q, resolveEditorOrigin as r, resolveInitialTarget as s, toCspOrigin as t };
package/dist/index.cjs CHANGED
@@ -202,6 +202,154 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
202
202
  });
203
203
  }
204
204
 
205
+ // src/data/document.ts
206
+ function isNode(value) {
207
+ return typeof value === "object" && value !== null && typeof value.kind === "string";
208
+ }
209
+ function name(node) {
210
+ return isNode(node) ? String(node.value ?? "") : "";
211
+ }
212
+ function printValue(node) {
213
+ if (!isNode(node)) return "null";
214
+ const value = node.value;
215
+ switch (node.kind) {
216
+ case "Variable":
217
+ return `$${name(node.name)}`;
218
+ case "IntValue":
219
+ case "FloatValue":
220
+ case "BooleanValue":
221
+ return String(value);
222
+ case "StringValue":
223
+ return node.block ? `"""
224
+ ${String(value)}
225
+ """` : JSON.stringify(String(value));
226
+ case "EnumValue":
227
+ return String(value);
228
+ case "NullValue":
229
+ return "null";
230
+ case "ListValue":
231
+ return `[${(node.values ?? []).map(printValue).join(", ")}]`;
232
+ case "ObjectValue":
233
+ return `{${(node.fields ?? []).map(
234
+ (field) => `${name(field.name)}: ${printValue(
235
+ field.value
236
+ )}`
237
+ ).join(", ")}}`;
238
+ default:
239
+ return "null";
240
+ }
241
+ }
242
+ function printType(node) {
243
+ if (!isNode(node)) return "";
244
+ switch (node.kind) {
245
+ case "NonNullType":
246
+ return `${printType(node.type)}!`;
247
+ case "ListType":
248
+ return `[${printType(node.type)}]`;
249
+ default:
250
+ return name(node.name);
251
+ }
252
+ }
253
+ function printArguments(node) {
254
+ const args = node.arguments ?? [];
255
+ if (args.length === 0) return "";
256
+ return `(${args.map(
257
+ (arg) => `${name(arg.name)}: ${printValue(
258
+ arg.value
259
+ )}`
260
+ ).join(", ")})`;
261
+ }
262
+ function printDirectives(node) {
263
+ const directives = node.directives ?? [];
264
+ if (directives.length === 0) return "";
265
+ return ` ${directives.map(
266
+ (directive) => `@${name(directive.name)}${printArguments(directive)}`
267
+ ).join(" ")}`;
268
+ }
269
+ function printSelectionSet(node, depth) {
270
+ if (!isNode(node)) return "";
271
+ const selections = node.selections ?? [];
272
+ if (selections.length === 0) return "";
273
+ const pad = " ".repeat(depth + 1);
274
+ const body = selections.map((selection) => `${pad}${printSelection(selection, depth + 1)}`).join("\n");
275
+ return ` {
276
+ ${body}
277
+ ${" ".repeat(depth)}}`;
278
+ }
279
+ function printSelection(node, depth) {
280
+ if (node.kind === "FragmentSpread") {
281
+ return `...${name(node.name)}${printDirectives(node)}`;
282
+ }
283
+ if (node.kind === "InlineFragment") {
284
+ const condition = node.typeCondition;
285
+ const on = isNode(condition) ? ` on ${name(condition.name)}` : "";
286
+ return `...${on}${printDirectives(node)}${printSelectionSet(
287
+ node.selectionSet,
288
+ depth
289
+ )}`;
290
+ }
291
+ const alias = node.alias;
292
+ const prefix = isNode(alias) ? `${name(alias)}: ` : "";
293
+ return `${prefix}${name(node.name)}${printArguments(
294
+ node
295
+ )}${printDirectives(node)}${printSelectionSet(
296
+ node.selectionSet,
297
+ depth
298
+ )}`;
299
+ }
300
+ function printVariableDefinitions(node) {
301
+ const definitions = node.variableDefinitions ?? [];
302
+ if (definitions.length === 0) return "";
303
+ return `(${definitions.map((definition) => {
304
+ const variable = definition.variable;
305
+ const declared = `$${name(
306
+ isNode(variable) ? variable.name : void 0
307
+ )}: ${printType(definition.type)}`;
308
+ const defaultValue = definition.defaultValue;
309
+ return isNode(defaultValue) ? `${declared} = ${printValue(defaultValue)}` : declared;
310
+ }).join(", ")})`;
311
+ }
312
+ function printDefinition(node) {
313
+ if (node.kind === "FragmentDefinition") {
314
+ const condition = node.typeCondition;
315
+ const on = isNode(condition) ? name(condition.name) : "";
316
+ return `fragment ${name(node.name)} on ${on}${printDirectives(
317
+ node
318
+ )}${printSelectionSet(node.selectionSet, 0)}`;
319
+ }
320
+ const operation = String(
321
+ node.operation ?? "query"
322
+ );
323
+ const operationName = name(node.name);
324
+ const head = operationName ? `${operation} ${operationName}` : operation;
325
+ return `${head}${printVariableDefinitions(node)}${printDirectives(
326
+ node
327
+ )}${printSelectionSet(node.selectionSet, 0)}`;
328
+ }
329
+ function printDocumentNode(node) {
330
+ const definitions = node.definitions ?? [];
331
+ return definitions.map(printDefinition).join("\n\n");
332
+ }
333
+ function documentText(document2) {
334
+ if (typeof document2 === "string") return document2;
335
+ if (!document2 || typeof document2 !== "object") {
336
+ throw new TypeError(
337
+ "cmssy: expected a GraphQL document - a query string, a TypedDocumentString, or a TypedDocumentNode"
338
+ );
339
+ }
340
+ const loc = document2.loc;
341
+ if (typeof loc?.source?.body === "string") return loc.source.body;
342
+ if (document2.kind === "Document") {
343
+ const printed = printDocumentNode(document2);
344
+ if (printed.trim()) return printed;
345
+ }
346
+ const asString = String(document2);
347
+ if (asString && asString !== "[object Object]") return asString;
348
+ throw new TypeError(
349
+ "cmssy: could not read the query text off the given document"
350
+ );
351
+ }
352
+
205
353
  // src/data/queries.ts
206
354
  var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
207
355
  public {
@@ -266,32 +414,41 @@ function createCmssyClient(input) {
266
414
  }
267
415
  return inFlight;
268
416
  }
269
- return {
417
+ function query(document2, variables, options) {
418
+ return graphqlRequest(
419
+ config,
420
+ document2,
421
+ variables,
422
+ options,
423
+ "graphql operation"
424
+ );
425
+ }
426
+ async function queryScoped(document2, variables, options = {}) {
427
+ const { workspaceId: provided, headers, ...rest } = options;
428
+ const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
429
+ const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
430
+ const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
431
+ return graphqlRequest(
432
+ config,
433
+ document2,
434
+ scopedVariables,
435
+ { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
436
+ "graphql operation"
437
+ );
438
+ }
439
+ const client = {
270
440
  config,
271
441
  resolveWorkspaceId: resolveWorkspaceId2,
272
- query(document2, variables = {}, options) {
273
- return graphqlRequest(
274
- config,
275
- document2,
276
- variables,
277
- options,
278
- "graphql operation"
279
- );
280
- },
281
- async queryScoped(document2, variables = {}, options = {}) {
282
- const { workspaceId: provided, headers, ...rest } = options;
283
- const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
284
- const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
285
- const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
286
- return graphqlRequest(
287
- config,
288
- document2,
289
- scopedVariables,
290
- { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
291
- "graphql operation"
292
- );
293
- }
442
+ // One implementation behind both overloads: a string passes through
443
+ // documentText untouched, a typed document gives up its query text.
444
+ query: ((document2, variables = {}, options) => query(documentText(document2), variables, options)),
445
+ queryScoped: ((document2, variables = {}, options = {}) => queryScoped(
446
+ documentText(document2),
447
+ variables,
448
+ options
449
+ ))
294
450
  };
451
+ return client;
295
452
  }
296
453
 
297
454
  // src/fields.ts
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AppToEditorMessage, B as BoundsMessage, C as ClickMessage, a as CmssyClient, b as CmssyConfig, c as CmssyCspOptions, d as CmssyEnvConfig, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, P as PROTOCOL_VERSION, e as ParentReadyMessage, f as PatchMessage, g as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, S as SelectMessage, h as applyCmssyCsp, i as createCmssyClient, j as defineCmssyConfig, k as isProtocolCompatible, n as normalizeOrigin, p as parseEditorMessage, l as postToEditor, r as resolveEditorOrigin } from './csp-BityT_ug.cjs';
1
+ export { A as AppToEditorMessage, B as BoundsMessage, C as ClickMessage, a as CmssyClient, b as CmssyConfig, c as CmssyCspOptions, d as CmssyEnvConfig, e as CmssyTypedDocument, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, P as PROTOCOL_VERSION, f as ParentReadyMessage, g as PatchMessage, h as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, S as SelectMessage, i as applyCmssyCsp, j as createCmssyClient, k as defineCmssyConfig, l as isProtocolCompatible, n as normalizeOrigin, p as parseEditorMessage, m as postToEditor, r as resolveEditorOrigin } from './csp-Bzrk_BeO.cjs';
2
2
  export { C as CMSSY_LOCALE_HEADER, G as GraphqlRequestOptions, g as graphqlRequest, l as localizeHref } from './locale-C7sA46qu.cjs';
3
3
  export { C as CmssyRequestError, D as DEFAULT_CMSSY_API_URL, F as FetchLike, a as FetchLikeResponse, b as FetchPageOptions, R as RetryPolicy } from './content-client-CJQ-nafm.cjs';
4
4
  import * as _cmssy_types from '@cmssy/types';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AppToEditorMessage, B as BoundsMessage, C as ClickMessage, a as CmssyClient, b as CmssyConfig, c as CmssyCspOptions, d as CmssyEnvConfig, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, P as PROTOCOL_VERSION, e as ParentReadyMessage, f as PatchMessage, g as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, S as SelectMessage, h as applyCmssyCsp, i as createCmssyClient, j as defineCmssyConfig, k as isProtocolCompatible, n as normalizeOrigin, p as parseEditorMessage, l as postToEditor, r as resolveEditorOrigin } from './csp-DJ17P3PN.js';
1
+ export { A as AppToEditorMessage, B as BoundsMessage, C as ClickMessage, a as CmssyClient, b as CmssyConfig, c as CmssyCspOptions, d as CmssyEnvConfig, e as CmssyTypedDocument, D as DEFAULT_CMSSY_EDITOR_ORIGINS, E as EditorToAppMessage, P as PROTOCOL_VERSION, f as ParentReadyMessage, g as PatchMessage, h as PostTarget, Q as QueryScopedOptions, R as ReadyMessage, S as SelectMessage, i as applyCmssyCsp, j as createCmssyClient, k as defineCmssyConfig, l as isProtocolCompatible, n as normalizeOrigin, p as parseEditorMessage, m as postToEditor, r as resolveEditorOrigin } from './csp-B7ElkvAp.js';
2
2
  export { C as CMSSY_LOCALE_HEADER, G as GraphqlRequestOptions, g as graphqlRequest, l as localizeHref } from './locale-Ox_qVlNy.js';
3
3
  export { C as CmssyRequestError, D as DEFAULT_CMSSY_API_URL, F as FetchLike, a as FetchLikeResponse, b as FetchPageOptions, R as RetryPolicy } from './content-client-CJQ-nafm.js';
4
4
  import * as _cmssy_types from '@cmssy/types';
package/dist/index.js CHANGED
@@ -200,6 +200,154 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
200
200
  });
201
201
  }
202
202
 
203
+ // src/data/document.ts
204
+ function isNode(value) {
205
+ return typeof value === "object" && value !== null && typeof value.kind === "string";
206
+ }
207
+ function name(node) {
208
+ return isNode(node) ? String(node.value ?? "") : "";
209
+ }
210
+ function printValue(node) {
211
+ if (!isNode(node)) return "null";
212
+ const value = node.value;
213
+ switch (node.kind) {
214
+ case "Variable":
215
+ return `$${name(node.name)}`;
216
+ case "IntValue":
217
+ case "FloatValue":
218
+ case "BooleanValue":
219
+ return String(value);
220
+ case "StringValue":
221
+ return node.block ? `"""
222
+ ${String(value)}
223
+ """` : JSON.stringify(String(value));
224
+ case "EnumValue":
225
+ return String(value);
226
+ case "NullValue":
227
+ return "null";
228
+ case "ListValue":
229
+ return `[${(node.values ?? []).map(printValue).join(", ")}]`;
230
+ case "ObjectValue":
231
+ return `{${(node.fields ?? []).map(
232
+ (field) => `${name(field.name)}: ${printValue(
233
+ field.value
234
+ )}`
235
+ ).join(", ")}}`;
236
+ default:
237
+ return "null";
238
+ }
239
+ }
240
+ function printType(node) {
241
+ if (!isNode(node)) return "";
242
+ switch (node.kind) {
243
+ case "NonNullType":
244
+ return `${printType(node.type)}!`;
245
+ case "ListType":
246
+ return `[${printType(node.type)}]`;
247
+ default:
248
+ return name(node.name);
249
+ }
250
+ }
251
+ function printArguments(node) {
252
+ const args = node.arguments ?? [];
253
+ if (args.length === 0) return "";
254
+ return `(${args.map(
255
+ (arg) => `${name(arg.name)}: ${printValue(
256
+ arg.value
257
+ )}`
258
+ ).join(", ")})`;
259
+ }
260
+ function printDirectives(node) {
261
+ const directives = node.directives ?? [];
262
+ if (directives.length === 0) return "";
263
+ return ` ${directives.map(
264
+ (directive) => `@${name(directive.name)}${printArguments(directive)}`
265
+ ).join(" ")}`;
266
+ }
267
+ function printSelectionSet(node, depth) {
268
+ if (!isNode(node)) return "";
269
+ const selections = node.selections ?? [];
270
+ if (selections.length === 0) return "";
271
+ const pad = " ".repeat(depth + 1);
272
+ const body = selections.map((selection) => `${pad}${printSelection(selection, depth + 1)}`).join("\n");
273
+ return ` {
274
+ ${body}
275
+ ${" ".repeat(depth)}}`;
276
+ }
277
+ function printSelection(node, depth) {
278
+ if (node.kind === "FragmentSpread") {
279
+ return `...${name(node.name)}${printDirectives(node)}`;
280
+ }
281
+ if (node.kind === "InlineFragment") {
282
+ const condition = node.typeCondition;
283
+ const on = isNode(condition) ? ` on ${name(condition.name)}` : "";
284
+ return `...${on}${printDirectives(node)}${printSelectionSet(
285
+ node.selectionSet,
286
+ depth
287
+ )}`;
288
+ }
289
+ const alias = node.alias;
290
+ const prefix = isNode(alias) ? `${name(alias)}: ` : "";
291
+ return `${prefix}${name(node.name)}${printArguments(
292
+ node
293
+ )}${printDirectives(node)}${printSelectionSet(
294
+ node.selectionSet,
295
+ depth
296
+ )}`;
297
+ }
298
+ function printVariableDefinitions(node) {
299
+ const definitions = node.variableDefinitions ?? [];
300
+ if (definitions.length === 0) return "";
301
+ return `(${definitions.map((definition) => {
302
+ const variable = definition.variable;
303
+ const declared = `$${name(
304
+ isNode(variable) ? variable.name : void 0
305
+ )}: ${printType(definition.type)}`;
306
+ const defaultValue = definition.defaultValue;
307
+ return isNode(defaultValue) ? `${declared} = ${printValue(defaultValue)}` : declared;
308
+ }).join(", ")})`;
309
+ }
310
+ function printDefinition(node) {
311
+ if (node.kind === "FragmentDefinition") {
312
+ const condition = node.typeCondition;
313
+ const on = isNode(condition) ? name(condition.name) : "";
314
+ return `fragment ${name(node.name)} on ${on}${printDirectives(
315
+ node
316
+ )}${printSelectionSet(node.selectionSet, 0)}`;
317
+ }
318
+ const operation = String(
319
+ node.operation ?? "query"
320
+ );
321
+ const operationName = name(node.name);
322
+ const head = operationName ? `${operation} ${operationName}` : operation;
323
+ return `${head}${printVariableDefinitions(node)}${printDirectives(
324
+ node
325
+ )}${printSelectionSet(node.selectionSet, 0)}`;
326
+ }
327
+ function printDocumentNode(node) {
328
+ const definitions = node.definitions ?? [];
329
+ return definitions.map(printDefinition).join("\n\n");
330
+ }
331
+ function documentText(document2) {
332
+ if (typeof document2 === "string") return document2;
333
+ if (!document2 || typeof document2 !== "object") {
334
+ throw new TypeError(
335
+ "cmssy: expected a GraphQL document - a query string, a TypedDocumentString, or a TypedDocumentNode"
336
+ );
337
+ }
338
+ const loc = document2.loc;
339
+ if (typeof loc?.source?.body === "string") return loc.source.body;
340
+ if (document2.kind === "Document") {
341
+ const printed = printDocumentNode(document2);
342
+ if (printed.trim()) return printed;
343
+ }
344
+ const asString = String(document2);
345
+ if (asString && asString !== "[object Object]") return asString;
346
+ throw new TypeError(
347
+ "cmssy: could not read the query text off the given document"
348
+ );
349
+ }
350
+
203
351
  // src/data/queries.ts
204
352
  var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
205
353
  public {
@@ -264,32 +412,41 @@ function createCmssyClient(input) {
264
412
  }
265
413
  return inFlight;
266
414
  }
267
- return {
415
+ function query(document2, variables, options) {
416
+ return graphqlRequest(
417
+ config,
418
+ document2,
419
+ variables,
420
+ options,
421
+ "graphql operation"
422
+ );
423
+ }
424
+ async function queryScoped(document2, variables, options = {}) {
425
+ const { workspaceId: provided, headers, ...rest } = options;
426
+ const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
427
+ const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
428
+ const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
429
+ return graphqlRequest(
430
+ config,
431
+ document2,
432
+ scopedVariables,
433
+ { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
434
+ "graphql operation"
435
+ );
436
+ }
437
+ const client = {
268
438
  config,
269
439
  resolveWorkspaceId: resolveWorkspaceId2,
270
- query(document2, variables = {}, options) {
271
- return graphqlRequest(
272
- config,
273
- document2,
274
- variables,
275
- options,
276
- "graphql operation"
277
- );
278
- },
279
- async queryScoped(document2, variables = {}, options = {}) {
280
- const { workspaceId: provided, headers, ...rest } = options;
281
- const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
282
- const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
283
- const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
284
- return graphqlRequest(
285
- config,
286
- document2,
287
- scopedVariables,
288
- { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
289
- "graphql operation"
290
- );
291
- }
440
+ // One implementation behind both overloads: a string passes through
441
+ // documentText untouched, a typed document gives up its query text.
442
+ query: ((document2, variables = {}, options) => query(documentText(document2), variables, options)),
443
+ queryScoped: ((document2, variables = {}, options = {}) => queryScoped(
444
+ documentText(document2),
445
+ variables,
446
+ options
447
+ ))
292
448
  };
449
+ return client;
293
450
  }
294
451
 
295
452
  // src/fields.ts
package/dist/internal.cjs CHANGED
@@ -468,6 +468,154 @@ function clearWorkspaceIdCache() {
468
468
  workspaceIdCache.clear();
469
469
  }
470
470
 
471
+ // src/data/document.ts
472
+ function isNode(value) {
473
+ return typeof value === "object" && value !== null && typeof value.kind === "string";
474
+ }
475
+ function name(node) {
476
+ return isNode(node) ? String(node.value ?? "") : "";
477
+ }
478
+ function printValue(node) {
479
+ if (!isNode(node)) return "null";
480
+ const value = node.value;
481
+ switch (node.kind) {
482
+ case "Variable":
483
+ return `$${name(node.name)}`;
484
+ case "IntValue":
485
+ case "FloatValue":
486
+ case "BooleanValue":
487
+ return String(value);
488
+ case "StringValue":
489
+ return node.block ? `"""
490
+ ${String(value)}
491
+ """` : JSON.stringify(String(value));
492
+ case "EnumValue":
493
+ return String(value);
494
+ case "NullValue":
495
+ return "null";
496
+ case "ListValue":
497
+ return `[${(node.values ?? []).map(printValue).join(", ")}]`;
498
+ case "ObjectValue":
499
+ return `{${(node.fields ?? []).map(
500
+ (field) => `${name(field.name)}: ${printValue(
501
+ field.value
502
+ )}`
503
+ ).join(", ")}}`;
504
+ default:
505
+ return "null";
506
+ }
507
+ }
508
+ function printType(node) {
509
+ if (!isNode(node)) return "";
510
+ switch (node.kind) {
511
+ case "NonNullType":
512
+ return `${printType(node.type)}!`;
513
+ case "ListType":
514
+ return `[${printType(node.type)}]`;
515
+ default:
516
+ return name(node.name);
517
+ }
518
+ }
519
+ function printArguments(node) {
520
+ const args = node.arguments ?? [];
521
+ if (args.length === 0) return "";
522
+ return `(${args.map(
523
+ (arg) => `${name(arg.name)}: ${printValue(
524
+ arg.value
525
+ )}`
526
+ ).join(", ")})`;
527
+ }
528
+ function printDirectives(node) {
529
+ const directives = node.directives ?? [];
530
+ if (directives.length === 0) return "";
531
+ return ` ${directives.map(
532
+ (directive) => `@${name(directive.name)}${printArguments(directive)}`
533
+ ).join(" ")}`;
534
+ }
535
+ function printSelectionSet(node, depth) {
536
+ if (!isNode(node)) return "";
537
+ const selections = node.selections ?? [];
538
+ if (selections.length === 0) return "";
539
+ const pad = " ".repeat(depth + 1);
540
+ const body = selections.map((selection) => `${pad}${printSelection(selection, depth + 1)}`).join("\n");
541
+ return ` {
542
+ ${body}
543
+ ${" ".repeat(depth)}}`;
544
+ }
545
+ function printSelection(node, depth) {
546
+ if (node.kind === "FragmentSpread") {
547
+ return `...${name(node.name)}${printDirectives(node)}`;
548
+ }
549
+ if (node.kind === "InlineFragment") {
550
+ const condition = node.typeCondition;
551
+ const on = isNode(condition) ? ` on ${name(condition.name)}` : "";
552
+ return `...${on}${printDirectives(node)}${printSelectionSet(
553
+ node.selectionSet,
554
+ depth
555
+ )}`;
556
+ }
557
+ const alias = node.alias;
558
+ const prefix = isNode(alias) ? `${name(alias)}: ` : "";
559
+ return `${prefix}${name(node.name)}${printArguments(
560
+ node
561
+ )}${printDirectives(node)}${printSelectionSet(
562
+ node.selectionSet,
563
+ depth
564
+ )}`;
565
+ }
566
+ function printVariableDefinitions(node) {
567
+ const definitions = node.variableDefinitions ?? [];
568
+ if (definitions.length === 0) return "";
569
+ return `(${definitions.map((definition) => {
570
+ const variable = definition.variable;
571
+ const declared = `$${name(
572
+ isNode(variable) ? variable.name : void 0
573
+ )}: ${printType(definition.type)}`;
574
+ const defaultValue = definition.defaultValue;
575
+ return isNode(defaultValue) ? `${declared} = ${printValue(defaultValue)}` : declared;
576
+ }).join(", ")})`;
577
+ }
578
+ function printDefinition(node) {
579
+ if (node.kind === "FragmentDefinition") {
580
+ const condition = node.typeCondition;
581
+ const on = isNode(condition) ? name(condition.name) : "";
582
+ return `fragment ${name(node.name)} on ${on}${printDirectives(
583
+ node
584
+ )}${printSelectionSet(node.selectionSet, 0)}`;
585
+ }
586
+ const operation = String(
587
+ node.operation ?? "query"
588
+ );
589
+ const operationName = name(node.name);
590
+ const head = operationName ? `${operation} ${operationName}` : operation;
591
+ return `${head}${printVariableDefinitions(node)}${printDirectives(
592
+ node
593
+ )}${printSelectionSet(node.selectionSet, 0)}`;
594
+ }
595
+ function printDocumentNode(node) {
596
+ const definitions = node.definitions ?? [];
597
+ return definitions.map(printDefinition).join("\n\n");
598
+ }
599
+ function documentText(document2) {
600
+ if (typeof document2 === "string") return document2;
601
+ if (!document2 || typeof document2 !== "object") {
602
+ throw new TypeError(
603
+ "cmssy: expected a GraphQL document - a query string, a TypedDocumentString, or a TypedDocumentNode"
604
+ );
605
+ }
606
+ const loc = document2.loc;
607
+ if (typeof loc?.source?.body === "string") return loc.source.body;
608
+ if (document2.kind === "Document") {
609
+ const printed = printDocumentNode(document2);
610
+ if (printed.trim()) return printed;
611
+ }
612
+ const asString = String(document2);
613
+ if (asString && asString !== "[object Object]") return asString;
614
+ throw new TypeError(
615
+ "cmssy: could not read the query text off the given document"
616
+ );
617
+ }
618
+
471
619
  // src/data/client.ts
472
620
  function createCmssyClient(input) {
473
621
  const config = {
@@ -488,32 +636,41 @@ function createCmssyClient(input) {
488
636
  }
489
637
  return inFlight;
490
638
  }
491
- return {
639
+ function query(document2, variables, options) {
640
+ return graphqlRequest(
641
+ config,
642
+ document2,
643
+ variables,
644
+ options,
645
+ "graphql operation"
646
+ );
647
+ }
648
+ async function queryScoped(document2, variables, options = {}) {
649
+ const { workspaceId: provided, headers, ...rest } = options;
650
+ const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
651
+ const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
652
+ const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
653
+ return graphqlRequest(
654
+ config,
655
+ document2,
656
+ scopedVariables,
657
+ { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
658
+ "graphql operation"
659
+ );
660
+ }
661
+ const client = {
492
662
  config,
493
663
  resolveWorkspaceId: resolveWorkspaceId2,
494
- query(document2, variables = {}, options) {
495
- return graphqlRequest(
496
- config,
497
- document2,
498
- variables,
499
- options,
500
- "graphql operation"
501
- );
502
- },
503
- async queryScoped(document2, variables = {}, options = {}) {
504
- const { workspaceId: provided, headers, ...rest } = options;
505
- const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
506
- const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
507
- const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
508
- return graphqlRequest(
509
- config,
510
- document2,
511
- scopedVariables,
512
- { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
513
- "graphql operation"
514
- );
515
- }
664
+ // One implementation behind both overloads: a string passes through
665
+ // documentText untouched, a typed document gives up its query text.
666
+ query: ((document2, variables = {}, options) => query(documentText(document2), variables, options)),
667
+ queryScoped: ((document2, variables = {}, options = {}) => queryScoped(
668
+ documentText(document2),
669
+ variables,
670
+ options
671
+ ))
516
672
  };
673
+ return client;
517
674
  }
518
675
 
519
676
  // src/data/resolve-forms.ts
@@ -3,8 +3,8 @@ import { CmssyFormDefinition, BuildBlockContextExtra, CmssyBlockContext, CmssyCl
3
3
  export { CmssySiteLocales } from '@cmssy/types';
4
4
  import { G as GraphqlRequestOptions } from './locale-C7sA46qu.cjs';
5
5
  export { C as CMSSY_LOCALE_HEADER, b as buildLocaleSwitchHref, a as localeForPath, c as localeForPathname, l as localizeHref, d as localizeHtmlLinks, s as splitCmssyLocale } from './locale-C7sA46qu.cjs';
6
- import { Q as QueryScopedOptions } from './csp-BityT_ug.cjs';
7
- export { m as cmssyCspHeaders, o as isDevelopment, q as resolveInitialTarget, t as toCspOrigin } from './csp-BityT_ug.cjs';
6
+ import { Q as QueryScopedOptions } from './csp-Bzrk_BeO.cjs';
7
+ export { o as cmssyCspHeaders, q as isDevelopment, s as resolveInitialTarget, t as toCspOrigin } from './csp-Bzrk_BeO.cjs';
8
8
  export { localesFromSiteConfig, localizedPath, resolveSiteLocales, splitLocaleFromPath } from './internal/locale.cjs';
9
9
 
10
10
  declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n public {\n siteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n branding {\n brandName\n logoUrl\n logoDarkUrl\n faviconUrl\n ogImageUrl\n }\n }\n }\n}";
@@ -3,8 +3,8 @@ import { CmssyFormDefinition, BuildBlockContextExtra, CmssyBlockContext, CmssyCl
3
3
  export { CmssySiteLocales } from '@cmssy/types';
4
4
  import { G as GraphqlRequestOptions } from './locale-Ox_qVlNy.js';
5
5
  export { C as CMSSY_LOCALE_HEADER, b as buildLocaleSwitchHref, a as localeForPath, c as localeForPathname, l as localizeHref, d as localizeHtmlLinks, s as splitCmssyLocale } from './locale-Ox_qVlNy.js';
6
- import { Q as QueryScopedOptions } from './csp-DJ17P3PN.js';
7
- export { m as cmssyCspHeaders, o as isDevelopment, q as resolveInitialTarget, t as toCspOrigin } from './csp-DJ17P3PN.js';
6
+ import { Q as QueryScopedOptions } from './csp-B7ElkvAp.js';
7
+ export { o as cmssyCspHeaders, q as isDevelopment, s as resolveInitialTarget, t as toCspOrigin } from './csp-B7ElkvAp.js';
8
8
  export { localesFromSiteConfig, localizedPath, resolveSiteLocales, splitLocaleFromPath } from './internal/locale.js';
9
9
 
10
10
  declare const SITE_CONFIG_QUERY = "query PublicSiteConfig($workspaceSlug: String!) {\n public {\n siteConfig(workspaceSlug: $workspaceSlug) {\n id\n workspaceId\n siteName\n defaultLanguage\n enabledLanguages\n enabledFeatures\n notFoundPageId\n previewUrl\n branding {\n brandName\n logoUrl\n logoDarkUrl\n faviconUrl\n ogImageUrl\n }\n }\n }\n}";
package/dist/internal.js CHANGED
@@ -466,6 +466,154 @@ function clearWorkspaceIdCache() {
466
466
  workspaceIdCache.clear();
467
467
  }
468
468
 
469
+ // src/data/document.ts
470
+ function isNode(value) {
471
+ return typeof value === "object" && value !== null && typeof value.kind === "string";
472
+ }
473
+ function name(node) {
474
+ return isNode(node) ? String(node.value ?? "") : "";
475
+ }
476
+ function printValue(node) {
477
+ if (!isNode(node)) return "null";
478
+ const value = node.value;
479
+ switch (node.kind) {
480
+ case "Variable":
481
+ return `$${name(node.name)}`;
482
+ case "IntValue":
483
+ case "FloatValue":
484
+ case "BooleanValue":
485
+ return String(value);
486
+ case "StringValue":
487
+ return node.block ? `"""
488
+ ${String(value)}
489
+ """` : JSON.stringify(String(value));
490
+ case "EnumValue":
491
+ return String(value);
492
+ case "NullValue":
493
+ return "null";
494
+ case "ListValue":
495
+ return `[${(node.values ?? []).map(printValue).join(", ")}]`;
496
+ case "ObjectValue":
497
+ return `{${(node.fields ?? []).map(
498
+ (field) => `${name(field.name)}: ${printValue(
499
+ field.value
500
+ )}`
501
+ ).join(", ")}}`;
502
+ default:
503
+ return "null";
504
+ }
505
+ }
506
+ function printType(node) {
507
+ if (!isNode(node)) return "";
508
+ switch (node.kind) {
509
+ case "NonNullType":
510
+ return `${printType(node.type)}!`;
511
+ case "ListType":
512
+ return `[${printType(node.type)}]`;
513
+ default:
514
+ return name(node.name);
515
+ }
516
+ }
517
+ function printArguments(node) {
518
+ const args = node.arguments ?? [];
519
+ if (args.length === 0) return "";
520
+ return `(${args.map(
521
+ (arg) => `${name(arg.name)}: ${printValue(
522
+ arg.value
523
+ )}`
524
+ ).join(", ")})`;
525
+ }
526
+ function printDirectives(node) {
527
+ const directives = node.directives ?? [];
528
+ if (directives.length === 0) return "";
529
+ return ` ${directives.map(
530
+ (directive) => `@${name(directive.name)}${printArguments(directive)}`
531
+ ).join(" ")}`;
532
+ }
533
+ function printSelectionSet(node, depth) {
534
+ if (!isNode(node)) return "";
535
+ const selections = node.selections ?? [];
536
+ if (selections.length === 0) return "";
537
+ const pad = " ".repeat(depth + 1);
538
+ const body = selections.map((selection) => `${pad}${printSelection(selection, depth + 1)}`).join("\n");
539
+ return ` {
540
+ ${body}
541
+ ${" ".repeat(depth)}}`;
542
+ }
543
+ function printSelection(node, depth) {
544
+ if (node.kind === "FragmentSpread") {
545
+ return `...${name(node.name)}${printDirectives(node)}`;
546
+ }
547
+ if (node.kind === "InlineFragment") {
548
+ const condition = node.typeCondition;
549
+ const on = isNode(condition) ? ` on ${name(condition.name)}` : "";
550
+ return `...${on}${printDirectives(node)}${printSelectionSet(
551
+ node.selectionSet,
552
+ depth
553
+ )}`;
554
+ }
555
+ const alias = node.alias;
556
+ const prefix = isNode(alias) ? `${name(alias)}: ` : "";
557
+ return `${prefix}${name(node.name)}${printArguments(
558
+ node
559
+ )}${printDirectives(node)}${printSelectionSet(
560
+ node.selectionSet,
561
+ depth
562
+ )}`;
563
+ }
564
+ function printVariableDefinitions(node) {
565
+ const definitions = node.variableDefinitions ?? [];
566
+ if (definitions.length === 0) return "";
567
+ return `(${definitions.map((definition) => {
568
+ const variable = definition.variable;
569
+ const declared = `$${name(
570
+ isNode(variable) ? variable.name : void 0
571
+ )}: ${printType(definition.type)}`;
572
+ const defaultValue = definition.defaultValue;
573
+ return isNode(defaultValue) ? `${declared} = ${printValue(defaultValue)}` : declared;
574
+ }).join(", ")})`;
575
+ }
576
+ function printDefinition(node) {
577
+ if (node.kind === "FragmentDefinition") {
578
+ const condition = node.typeCondition;
579
+ const on = isNode(condition) ? name(condition.name) : "";
580
+ return `fragment ${name(node.name)} on ${on}${printDirectives(
581
+ node
582
+ )}${printSelectionSet(node.selectionSet, 0)}`;
583
+ }
584
+ const operation = String(
585
+ node.operation ?? "query"
586
+ );
587
+ const operationName = name(node.name);
588
+ const head = operationName ? `${operation} ${operationName}` : operation;
589
+ return `${head}${printVariableDefinitions(node)}${printDirectives(
590
+ node
591
+ )}${printSelectionSet(node.selectionSet, 0)}`;
592
+ }
593
+ function printDocumentNode(node) {
594
+ const definitions = node.definitions ?? [];
595
+ return definitions.map(printDefinition).join("\n\n");
596
+ }
597
+ function documentText(document2) {
598
+ if (typeof document2 === "string") return document2;
599
+ if (!document2 || typeof document2 !== "object") {
600
+ throw new TypeError(
601
+ "cmssy: expected a GraphQL document - a query string, a TypedDocumentString, or a TypedDocumentNode"
602
+ );
603
+ }
604
+ const loc = document2.loc;
605
+ if (typeof loc?.source?.body === "string") return loc.source.body;
606
+ if (document2.kind === "Document") {
607
+ const printed = printDocumentNode(document2);
608
+ if (printed.trim()) return printed;
609
+ }
610
+ const asString = String(document2);
611
+ if (asString && asString !== "[object Object]") return asString;
612
+ throw new TypeError(
613
+ "cmssy: could not read the query text off the given document"
614
+ );
615
+ }
616
+
469
617
  // src/data/client.ts
470
618
  function createCmssyClient(input) {
471
619
  const config = {
@@ -486,32 +634,41 @@ function createCmssyClient(input) {
486
634
  }
487
635
  return inFlight;
488
636
  }
489
- return {
637
+ function query(document2, variables, options) {
638
+ return graphqlRequest(
639
+ config,
640
+ document2,
641
+ variables,
642
+ options,
643
+ "graphql operation"
644
+ );
645
+ }
646
+ async function queryScoped(document2, variables, options = {}) {
647
+ const { workspaceId: provided, headers, ...rest } = options;
648
+ const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
649
+ const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
650
+ const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
651
+ return graphqlRequest(
652
+ config,
653
+ document2,
654
+ scopedVariables,
655
+ { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
656
+ "graphql operation"
657
+ );
658
+ }
659
+ const client = {
490
660
  config,
491
661
  resolveWorkspaceId: resolveWorkspaceId2,
492
- query(document2, variables = {}, options) {
493
- return graphqlRequest(
494
- config,
495
- document2,
496
- variables,
497
- options,
498
- "graphql operation"
499
- );
500
- },
501
- async queryScoped(document2, variables = {}, options = {}) {
502
- const { workspaceId: provided, headers, ...rest } = options;
503
- const workspaceId = provided ?? await resolveWorkspaceId2({ ...rest, headers });
504
- const hasWorkspaceId = variables.workspaceId !== void 0 && variables.workspaceId !== null;
505
- const scopedVariables = /\$workspaceId\b/.test(document2) && !hasWorkspaceId ? { ...variables, workspaceId } : variables;
506
- return graphqlRequest(
507
- config,
508
- document2,
509
- scopedVariables,
510
- { ...rest, headers: { ...headers, "x-workspace-id": workspaceId } },
511
- "graphql operation"
512
- );
513
- }
662
+ // One implementation behind both overloads: a string passes through
663
+ // documentText untouched, a typed document gives up its query text.
664
+ query: ((document2, variables = {}, options) => query(documentText(document2), variables, options)),
665
+ queryScoped: ((document2, variables = {}, options = {}) => queryScoped(
666
+ documentText(document2),
667
+ variables,
668
+ options
669
+ ))
514
670
  };
671
+ return client;
515
672
  }
516
673
 
517
674
  // src/data/resolve-forms.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/core",
3
- "version": "10.5.2",
3
+ "version": "10.6.1",
4
4
  "description": "Framework-agnostic cmssy gateway: GraphQL client, block/field system, editor protocol. No React, no Next.",
5
5
  "keywords": [
6
6
  "cmssy",