@cmssy/core 19.1.1 → 19.3.0

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,17 +1,73 @@
1
1
  export { g as fetchLayouts, h as fetchPage, j as fetchPageById, k as fetchPageMeta, l as fetchPages, r as resolveApiUrl } from './content-client-DhcHP8ln.js';
2
- import { CmssyFormDefinition, BuildBlockContextExtra, CmssyBlockContext, CmssyClientConfig, CmssySiteConfig, FieldDefinition, RawBlock, CmssyLayoutGroup } from '@cmssy/types';
2
+ import { CmssyFormDefinition, CmssyModelDefinition, CmssyRecordList, CmssySiteConfig, CmssyFormSubmitResponse, SubmitFormInput, BuildBlockContextExtra, CmssyBlockContext, CmssyClientConfig, FieldDefinition, RawBlock, CmssyLayoutGroup } from '@cmssy/types';
3
3
  export { CmssySiteLocales } from '@cmssy/types';
4
- import { G as GraphqlRequestOptions } from './locale-BCguiP54.js';
5
- export { C as CMSSY_LOCALE_HEADER, a as localeForPath, b as localeForPathname, l as localizeHref, c as resolveSiteLocales, s as splitCmssyLocale, d as splitLocaleFromPath } from './locale-BCguiP54.js';
6
- import { Q as QueryScopedOptions } from './csp-AuptG-R-.js';
7
- export { F as cmssyCspHeaders, G as isDevelopment, H as layoutRegionIds, J as resolveInitialTarget, K as toCspOrigin } from './csp-AuptG-R-.js';
4
+ import { a as CmssyOperation, G as GraphqlRequestOptions } from './locale-BGUsgy8p.js';
5
+ export { C as CMSSY_LOCALE_HEADER, d as localeForPath, e as localeForPathname, l as localizeHref, f as resolveSiteLocales, s as splitCmssyLocale, h as splitLocaleFromPath } from './locale-BGUsgy8p.js';
6
+ import { Q as QueryScopedOptions } from './csp-BdigosQo.js';
7
+ export { G as cmssyCspHeaders, H as isDevelopment, J as layoutRegionIds, K as resolveInitialTarget, L as toCspOrigin } from './csp-BdigosQo.js';
8
8
  export { localizedPath } from './internal/locale.js';
9
9
 
10
- declare const SITE_CONFIG_QUERY: string;
11
- declare const MODEL_DEFINITIONS_QUERY = "query PublicModelDefinitions($workspaceId: String!) {\n public {\n model {\n definitions(workspaceId: $workspaceId) {\n id name slug description icon color displayField recordCount\n }\n }\n }\n}";
12
- declare const MODEL_RECORDS_QUERY = "query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $locale: String, $limit: Int, $offset: Int, $populate: [String!]) {\n public {\n model {\n records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, sort: $sort, locale: $locale, limit: $limit, offset: $offset, populate: $populate) {\n items { id modelId data status createdAt updatedAt }\n total\n hasMore\n }\n }\n }\n}";
13
- declare const FORM_QUERY = "query PublicForm($formId: ID!) {\n public {\n form {\n get(formId: $formId) {\n id\n name\n slug\n description\n fields {\n id name fieldType label placeholder helpText\n defaultValue width order showWhen requiredWhen\n options { value label disabled }\n validation { required minLength maxLength minValue maxValue pattern customMessage }\n }\n settings {\n actionType submitButtonLabel successMessage errorMessage\n redirectUrl requireLogin\n }\n }\n }\n }\n}";
14
- declare const SUBMIT_FORM_MUTATION = "mutation SubmitForm($formId: ID!, $input: SubmitFormInput!) {\n public {\n form {\n submit(formId: $formId, input: $input) {\n success message submissionId redirectUrl\n }\n }\n }\n}";
10
+ interface SiteConfigVariables {
11
+ workspaceSlug: string;
12
+ }
13
+ interface SiteConfigResult {
14
+ public: {
15
+ siteConfig: CmssySiteConfig | null;
16
+ };
17
+ }
18
+ declare const SITE_CONFIG_QUERY: CmssyOperation<SiteConfigResult, SiteConfigVariables>;
19
+ interface ModelDefinitionsVariables {
20
+ workspaceId: string;
21
+ }
22
+ interface ModelDefinitionsResult {
23
+ public: {
24
+ model: {
25
+ definitions: CmssyModelDefinition[];
26
+ };
27
+ };
28
+ }
29
+ declare const MODEL_DEFINITIONS_QUERY: CmssyOperation<ModelDefinitionsResult, ModelDefinitionsVariables>;
30
+ interface ModelRecordsVariables {
31
+ workspaceId: string;
32
+ modelSlug: string;
33
+ filter?: Record<string, unknown> | null;
34
+ sort?: string | null;
35
+ locale?: string | null;
36
+ limit?: number | null;
37
+ offset?: number | null;
38
+ populate?: string[] | null;
39
+ }
40
+ interface ModelRecordsResult {
41
+ public: {
42
+ model: {
43
+ records: CmssyRecordList;
44
+ };
45
+ };
46
+ }
47
+ declare const MODEL_RECORDS_QUERY: CmssyOperation<ModelRecordsResult, ModelRecordsVariables>;
48
+ interface FormVariables {
49
+ formId: string;
50
+ }
51
+ interface FormResult {
52
+ public: {
53
+ form: {
54
+ get: CmssyFormDefinition | null;
55
+ };
56
+ };
57
+ }
58
+ declare const FORM_QUERY: CmssyOperation<FormResult, FormVariables>;
59
+ interface SubmitFormVariables {
60
+ formId: string;
61
+ input: SubmitFormInput;
62
+ }
63
+ interface SubmitFormResult {
64
+ public: {
65
+ form: {
66
+ submit: CmssyFormSubmitResponse;
67
+ };
68
+ };
69
+ }
70
+ declare const SUBMIT_FORM_MUTATION: CmssyOperation<SubmitFormResult, SubmitFormVariables>;
15
71
 
16
72
  declare function buildBlockContext(locale: string, defaultLocale: string, enabledLocales?: string[], isPreview?: boolean, forms?: Record<string, CmssyFormDefinition>, extra?: BuildBlockContextExtra): CmssyBlockContext;
17
73
 
package/dist/internal.js CHANGED
@@ -1,7 +1,158 @@
1
1
  import { brandingFieldNames, DEFAULT_LAYOUT_REGIONS } from '@cmssy/types';
2
2
 
3
+ // src/data/document.ts
4
+ function typedOperation(text) {
5
+ return text;
6
+ }
7
+ function isNode(value) {
8
+ return typeof value === "object" && value !== null && typeof value.kind === "string";
9
+ }
10
+ function name(node) {
11
+ return isNode(node) ? String(node.value ?? "") : "";
12
+ }
13
+ function printValue(node) {
14
+ if (!isNode(node)) return "null";
15
+ const value = node.value;
16
+ switch (node.kind) {
17
+ case "Variable":
18
+ return `$${name(node.name)}`;
19
+ case "IntValue":
20
+ case "FloatValue":
21
+ case "BooleanValue":
22
+ return String(value);
23
+ case "StringValue":
24
+ return node.block ? `"""
25
+ ${String(value)}
26
+ """` : JSON.stringify(String(value));
27
+ case "EnumValue":
28
+ return String(value);
29
+ case "NullValue":
30
+ return "null";
31
+ case "ListValue":
32
+ return `[${(node.values ?? []).map(printValue).join(", ")}]`;
33
+ case "ObjectValue":
34
+ return `{${(node.fields ?? []).map(
35
+ (field) => `${name(field.name)}: ${printValue(
36
+ field.value
37
+ )}`
38
+ ).join(", ")}}`;
39
+ default:
40
+ return "null";
41
+ }
42
+ }
43
+ function printType(node) {
44
+ if (!isNode(node)) return "";
45
+ switch (node.kind) {
46
+ case "NonNullType":
47
+ return `${printType(node.type)}!`;
48
+ case "ListType":
49
+ return `[${printType(node.type)}]`;
50
+ default:
51
+ return name(node.name);
52
+ }
53
+ }
54
+ function printArguments(node) {
55
+ const args = node.arguments ?? [];
56
+ if (args.length === 0) return "";
57
+ return `(${args.map(
58
+ (arg) => `${name(arg.name)}: ${printValue(
59
+ arg.value
60
+ )}`
61
+ ).join(", ")})`;
62
+ }
63
+ function printDirectives(node) {
64
+ const directives = node.directives ?? [];
65
+ if (directives.length === 0) return "";
66
+ return ` ${directives.map(
67
+ (directive) => `@${name(directive.name)}${printArguments(directive)}`
68
+ ).join(" ")}`;
69
+ }
70
+ function printSelectionSet(node, depth) {
71
+ if (!isNode(node)) return "";
72
+ const selections = node.selections ?? [];
73
+ if (selections.length === 0) return "";
74
+ const pad = " ".repeat(depth + 1);
75
+ const body = selections.map((selection) => `${pad}${printSelection(selection, depth + 1)}`).join("\n");
76
+ return ` {
77
+ ${body}
78
+ ${" ".repeat(depth)}}`;
79
+ }
80
+ function printSelection(node, depth) {
81
+ if (node.kind === "FragmentSpread") {
82
+ return `...${name(node.name)}${printDirectives(node)}`;
83
+ }
84
+ if (node.kind === "InlineFragment") {
85
+ const condition = node.typeCondition;
86
+ const on = isNode(condition) ? ` on ${name(condition.name)}` : "";
87
+ return `...${on}${printDirectives(node)}${printSelectionSet(
88
+ node.selectionSet,
89
+ depth
90
+ )}`;
91
+ }
92
+ const alias = node.alias;
93
+ const prefix = isNode(alias) ? `${name(alias)}: ` : "";
94
+ return `${prefix}${name(node.name)}${printArguments(
95
+ node
96
+ )}${printDirectives(node)}${printSelectionSet(
97
+ node.selectionSet,
98
+ depth
99
+ )}`;
100
+ }
101
+ function printVariableDefinitions(node) {
102
+ const definitions = node.variableDefinitions ?? [];
103
+ if (definitions.length === 0) return "";
104
+ return `(${definitions.map((definition) => {
105
+ const variable = definition.variable;
106
+ const declared = `$${name(
107
+ isNode(variable) ? variable.name : void 0
108
+ )}: ${printType(definition.type)}`;
109
+ const defaultValue = definition.defaultValue;
110
+ return isNode(defaultValue) ? `${declared} = ${printValue(defaultValue)}` : declared;
111
+ }).join(", ")})`;
112
+ }
113
+ function printDefinition(node) {
114
+ if (node.kind === "FragmentDefinition") {
115
+ const condition = node.typeCondition;
116
+ const on = isNode(condition) ? name(condition.name) : "";
117
+ return `fragment ${name(node.name)} on ${on}${printDirectives(
118
+ node
119
+ )}${printSelectionSet(node.selectionSet, 0)}`;
120
+ }
121
+ const operation = String(
122
+ node.operation ?? "query"
123
+ );
124
+ const operationName = name(node.name);
125
+ const head = operationName ? `${operation} ${operationName}` : operation;
126
+ return `${head}${printVariableDefinitions(node)}${printDirectives(
127
+ node
128
+ )}${printSelectionSet(node.selectionSet, 0)}`;
129
+ }
130
+ function printDocumentNode(node) {
131
+ const definitions = node.definitions ?? [];
132
+ return definitions.map(printDefinition).join("\n\n");
133
+ }
134
+ function documentText(document2) {
135
+ if (typeof document2 === "string") return document2;
136
+ if (!document2 || typeof document2 !== "object") {
137
+ throw new TypeError(
138
+ "cmssy: expected a GraphQL document - a query string, a TypedDocumentString, or a TypedDocumentNode"
139
+ );
140
+ }
141
+ const loc = document2.loc;
142
+ if (typeof loc?.source?.body === "string") return loc.source.body;
143
+ if (document2.kind === "Document") {
144
+ const printed = printDocumentNode(document2);
145
+ if (printed.trim()) return printed;
146
+ }
147
+ const asString = String(document2);
148
+ if (asString && asString !== "[object Object]") return asString;
149
+ throw new TypeError(
150
+ "cmssy: could not read the query text off the given document"
151
+ );
152
+ }
153
+
3
154
  // src/version.ts
4
- var CMSSY_CORE_VERSION = "19.1.1" ;
155
+ var CMSSY_CORE_VERSION = "19.3.0" ;
5
156
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
6
157
 
7
158
  // src/data/http.ts
@@ -144,7 +295,7 @@ async function postGraphql(url, query, variables, options) {
144
295
  "user-agent": CMSSY_USER_AGENT,
145
296
  ...options.headers
146
297
  },
147
- body: JSON.stringify({ query, variables }),
298
+ body: JSON.stringify({ query: documentText(query), variables }),
148
299
  signal: options.signal
149
300
  },
150
301
  options.retry,
@@ -196,7 +347,7 @@ function resolvePublicUrl(config) {
196
347
  const base = resolveApiUrl(config.apiUrl).replace(/\/graphql\/?$/, "");
197
348
  return `${base}/public/${config.org}/${config.workspaceSlug}/graphql`;
198
349
  }
199
- var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
350
+ var PUBLIC_PAGE_QUERY = typedOperation(`query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String) {
200
351
  public {
201
352
  page {
202
353
  get(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret) {
@@ -208,8 +359,8 @@ var PUBLIC_PAGE_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String
208
359
  }
209
360
  }
210
361
  }
211
- }`;
212
- var PUBLIC_PAGE_DEV_QUERY = `query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String, $devPreview: Boolean) {
362
+ }`);
363
+ var PUBLIC_PAGE_DEV_QUERY = typedOperation(`query PublicPage($workspaceSlug: String!, $slug: String!, $previewSecret: String, $devPreview: Boolean) {
213
364
  public {
214
365
  page {
215
366
  get(workspaceSlug: $workspaceSlug, slug: $slug, previewSecret: $previewSecret, devPreview: $devPreview) {
@@ -221,8 +372,8 @@ var PUBLIC_PAGE_DEV_QUERY = `query PublicPage($workspaceSlug: String!, $slug: St
221
372
  }
222
373
  }
223
374
  }
224
- }`;
225
- var PUBLIC_PAGE_BY_ID_QUERY = `query PublicPageById($workspaceSlug: String!, $pageId: ID!) {
375
+ }`);
376
+ var PUBLIC_PAGE_BY_ID_QUERY = typedOperation(`query PublicPageById($workspaceSlug: String!, $pageId: ID!) {
226
377
  public {
227
378
  page {
228
379
  getById(workspaceSlug: $workspaceSlug, pageId: $pageId) {
@@ -233,8 +384,8 @@ var PUBLIC_PAGE_BY_ID_QUERY = `query PublicPageById($workspaceSlug: String!, $pa
233
384
  }
234
385
  }
235
386
  }
236
- }`;
237
- var PUBLIC_PAGES_QUERY = `query PublicPages($workspaceSlug: String!) {
387
+ }`);
388
+ var PUBLIC_PAGES_QUERY = typedOperation(`query PublicPages($workspaceSlug: String!) {
238
389
  public {
239
390
  page {
240
391
  list(workspaceSlug: $workspaceSlug) {
@@ -245,8 +396,8 @@ var PUBLIC_PAGES_QUERY = `query PublicPages($workspaceSlug: String!) {
245
396
  }
246
397
  }
247
398
  }
248
- }`;
249
- var PUBLIC_PAGE_META_QUERY = `query PublicPageMeta($workspaceSlug: String!, $slug: String!) {
399
+ }`);
400
+ var PUBLIC_PAGE_META_QUERY = typedOperation(`query PublicPageMeta($workspaceSlug: String!, $slug: String!) {
250
401
  public {
251
402
  page {
252
403
  get(workspaceSlug: $workspaceSlug, slug: $slug) {
@@ -258,8 +409,8 @@ var PUBLIC_PAGE_META_QUERY = `query PublicPageMeta($workspaceSlug: String!, $slu
258
409
  }
259
410
  }
260
411
  }
261
- }`;
262
- var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!, $pageSlug: String!, $previewSecret: String) {
412
+ }`);
413
+ var PUBLIC_PAGE_LAYOUTS_QUERY = typedOperation(`query PublicPageLayouts($workspaceSlug: String!, $pageSlug: String!, $previewSecret: String) {
263
414
  public {
264
415
  page {
265
416
  layouts(workspaceSlug: $workspaceSlug, pageSlug: $pageSlug, previewSecret: $previewSecret) {
@@ -269,7 +420,7 @@ var PUBLIC_PAGE_LAYOUTS_QUERY = `query PublicPageLayouts($workspaceSlug: String!
269
420
  }
270
421
  }
271
422
  }
272
- }`;
423
+ }`);
273
424
  function normalizeSlug(path) {
274
425
  if (Array.isArray(path)) {
275
426
  const joined = path.filter(Boolean).join("/");
@@ -291,22 +442,29 @@ async function fetchPage(config, path, options = {}) {
291
442
  headers["x-workspace-id"] = options.workspaceId;
292
443
  }
293
444
  }
294
- const data = await postGraphql(
295
- resolvePublicUrl(config),
296
- devPreview ? PUBLIC_PAGE_DEV_QUERY : PUBLIC_PAGE_QUERY,
445
+ const requestOptions = {
446
+ fetch: options.fetch,
447
+ signal: options.signal,
448
+ headers,
449
+ retry: options.retry ?? "build",
450
+ label: "page fetch"
451
+ };
452
+ const url = resolvePublicUrl(config);
453
+ const data = devPreview ? await postGraphql(
454
+ url,
455
+ PUBLIC_PAGE_DEV_QUERY,
297
456
  {
298
457
  workspaceSlug: config.workspaceSlug,
299
458
  slug,
300
459
  previewSecret,
301
- ...devPreview ? { devPreview: true } : {}
460
+ devPreview: true
302
461
  },
303
- {
304
- fetch: options.fetch,
305
- signal: options.signal,
306
- headers,
307
- retry: options.retry ?? "build",
308
- label: "page fetch"
309
- }
462
+ requestOptions
463
+ ) : await postGraphql(
464
+ url,
465
+ PUBLIC_PAGE_QUERY,
466
+ { workspaceSlug: config.workspaceSlug, slug, previewSecret },
467
+ requestOptions
310
468
  );
311
469
  const page = data?.public?.page?.get;
312
470
  if (!page) return null;
@@ -407,8 +565,9 @@ function getBlockContentForLanguage(content, locale, defaultLocale = "en", avail
407
565
  if (!(isLocale(key) && isPlainObject(value))) nonTranslatable[key] = value;
408
566
  }
409
567
  const fallbackKey = Object.keys(localeMap)[0];
410
- const chosen = localeMap[locale] ?? localeMap[defaultLocale] ?? localeMap[fallbackKey];
411
- return { ...nonTranslatable, ...chosen };
568
+ const base = localeMap[defaultLocale] ?? localeMap[fallbackKey];
569
+ const active = localeMap[locale] ?? base;
570
+ return { ...nonTranslatable, ...base, ...active };
412
571
  }
413
572
  function asBucket(value) {
414
573
  return isPlainObject(value) ? value : {};
@@ -425,7 +584,7 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
425
584
  label
426
585
  });
427
586
  }
428
- var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
587
+ var SITE_CONFIG_QUERY = typedOperation(`query PublicSiteConfig($workspaceSlug: String!) {
429
588
  public {
430
589
  siteConfig(workspaceSlug: $workspaceSlug) {
431
590
  id
@@ -441,8 +600,8 @@ var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
441
600
  }
442
601
  }
443
602
  }
444
- }`;
445
- var MODEL_DEFINITIONS_QUERY = `query PublicModelDefinitions($workspaceId: String!) {
603
+ }`);
604
+ var MODEL_DEFINITIONS_QUERY = typedOperation(`query PublicModelDefinitions($workspaceId: String!) {
446
605
  public {
447
606
  model {
448
607
  definitions(workspaceId: $workspaceId) {
@@ -450,8 +609,8 @@ var MODEL_DEFINITIONS_QUERY = `query PublicModelDefinitions($workspaceId: String
450
609
  }
451
610
  }
452
611
  }
453
- }`;
454
- var MODEL_RECORDS_QUERY = `query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $locale: String, $limit: Int, $offset: Int, $populate: [String!]) {
612
+ }`);
613
+ var MODEL_RECORDS_QUERY = typedOperation(`query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $locale: String, $limit: Int, $offset: Int, $populate: [String!]) {
455
614
  public {
456
615
  model {
457
616
  records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, sort: $sort, locale: $locale, limit: $limit, offset: $offset, populate: $populate) {
@@ -461,8 +620,9 @@ var MODEL_RECORDS_QUERY = `query PublicModelRecords($workspaceId: String!, $mode
461
620
  }
462
621
  }
463
622
  }
464
- }`;
465
- var FORM_QUERY = `query PublicForm($formId: ID!) {
623
+ }`);
624
+ var FORM_QUERY = typedOperation(
625
+ `query PublicForm($formId: ID!) {
466
626
  public {
467
627
  form {
468
628
  get(formId: $formId) {
@@ -483,8 +643,9 @@ var FORM_QUERY = `query PublicForm($formId: ID!) {
483
643
  }
484
644
  }
485
645
  }
486
- }`;
487
- var SUBMIT_FORM_MUTATION = `mutation SubmitForm($formId: ID!, $input: SubmitFormInput!) {
646
+ }`
647
+ );
648
+ var SUBMIT_FORM_MUTATION = typedOperation(`mutation SubmitForm($formId: ID!, $input: SubmitFormInput!) {
488
649
  public {
489
650
  form {
490
651
  submit(formId: $formId, input: $input) {
@@ -492,7 +653,7 @@ var SUBMIT_FORM_MUTATION = `mutation SubmitForm($formId: ID!, $input: SubmitForm
492
653
  }
493
654
  }
494
655
  }
495
- }`;
656
+ }`);
496
657
 
497
658
  // src/data/settings-client.ts
498
659
  async function fetchSiteConfig(config, options = {}) {
@@ -538,154 +699,6 @@ function clearWorkspaceIdCache() {
538
699
  workspaceIdCache.clear();
539
700
  }
540
701
 
541
- // src/data/document.ts
542
- function isNode(value) {
543
- return typeof value === "object" && value !== null && typeof value.kind === "string";
544
- }
545
- function name(node) {
546
- return isNode(node) ? String(node.value ?? "") : "";
547
- }
548
- function printValue(node) {
549
- if (!isNode(node)) return "null";
550
- const value = node.value;
551
- switch (node.kind) {
552
- case "Variable":
553
- return `$${name(node.name)}`;
554
- case "IntValue":
555
- case "FloatValue":
556
- case "BooleanValue":
557
- return String(value);
558
- case "StringValue":
559
- return node.block ? `"""
560
- ${String(value)}
561
- """` : JSON.stringify(String(value));
562
- case "EnumValue":
563
- return String(value);
564
- case "NullValue":
565
- return "null";
566
- case "ListValue":
567
- return `[${(node.values ?? []).map(printValue).join(", ")}]`;
568
- case "ObjectValue":
569
- return `{${(node.fields ?? []).map(
570
- (field) => `${name(field.name)}: ${printValue(
571
- field.value
572
- )}`
573
- ).join(", ")}}`;
574
- default:
575
- return "null";
576
- }
577
- }
578
- function printType(node) {
579
- if (!isNode(node)) return "";
580
- switch (node.kind) {
581
- case "NonNullType":
582
- return `${printType(node.type)}!`;
583
- case "ListType":
584
- return `[${printType(node.type)}]`;
585
- default:
586
- return name(node.name);
587
- }
588
- }
589
- function printArguments(node) {
590
- const args = node.arguments ?? [];
591
- if (args.length === 0) return "";
592
- return `(${args.map(
593
- (arg) => `${name(arg.name)}: ${printValue(
594
- arg.value
595
- )}`
596
- ).join(", ")})`;
597
- }
598
- function printDirectives(node) {
599
- const directives = node.directives ?? [];
600
- if (directives.length === 0) return "";
601
- return ` ${directives.map(
602
- (directive) => `@${name(directive.name)}${printArguments(directive)}`
603
- ).join(" ")}`;
604
- }
605
- function printSelectionSet(node, depth) {
606
- if (!isNode(node)) return "";
607
- const selections = node.selections ?? [];
608
- if (selections.length === 0) return "";
609
- const pad = " ".repeat(depth + 1);
610
- const body = selections.map((selection) => `${pad}${printSelection(selection, depth + 1)}`).join("\n");
611
- return ` {
612
- ${body}
613
- ${" ".repeat(depth)}}`;
614
- }
615
- function printSelection(node, depth) {
616
- if (node.kind === "FragmentSpread") {
617
- return `...${name(node.name)}${printDirectives(node)}`;
618
- }
619
- if (node.kind === "InlineFragment") {
620
- const condition = node.typeCondition;
621
- const on = isNode(condition) ? ` on ${name(condition.name)}` : "";
622
- return `...${on}${printDirectives(node)}${printSelectionSet(
623
- node.selectionSet,
624
- depth
625
- )}`;
626
- }
627
- const alias = node.alias;
628
- const prefix = isNode(alias) ? `${name(alias)}: ` : "";
629
- return `${prefix}${name(node.name)}${printArguments(
630
- node
631
- )}${printDirectives(node)}${printSelectionSet(
632
- node.selectionSet,
633
- depth
634
- )}`;
635
- }
636
- function printVariableDefinitions(node) {
637
- const definitions = node.variableDefinitions ?? [];
638
- if (definitions.length === 0) return "";
639
- return `(${definitions.map((definition) => {
640
- const variable = definition.variable;
641
- const declared = `$${name(
642
- isNode(variable) ? variable.name : void 0
643
- )}: ${printType(definition.type)}`;
644
- const defaultValue = definition.defaultValue;
645
- return isNode(defaultValue) ? `${declared} = ${printValue(defaultValue)}` : declared;
646
- }).join(", ")})`;
647
- }
648
- function printDefinition(node) {
649
- if (node.kind === "FragmentDefinition") {
650
- const condition = node.typeCondition;
651
- const on = isNode(condition) ? name(condition.name) : "";
652
- return `fragment ${name(node.name)} on ${on}${printDirectives(
653
- node
654
- )}${printSelectionSet(node.selectionSet, 0)}`;
655
- }
656
- const operation = String(
657
- node.operation ?? "query"
658
- );
659
- const operationName = name(node.name);
660
- const head = operationName ? `${operation} ${operationName}` : operation;
661
- return `${head}${printVariableDefinitions(node)}${printDirectives(
662
- node
663
- )}${printSelectionSet(node.selectionSet, 0)}`;
664
- }
665
- function printDocumentNode(node) {
666
- const definitions = node.definitions ?? [];
667
- return definitions.map(printDefinition).join("\n\n");
668
- }
669
- function documentText(document2) {
670
- if (typeof document2 === "string") return document2;
671
- if (!document2 || typeof document2 !== "object") {
672
- throw new TypeError(
673
- "cmssy: expected a GraphQL document - a query string, a TypedDocumentString, or a TypedDocumentNode"
674
- );
675
- }
676
- const loc = document2.loc;
677
- if (typeof loc?.source?.body === "string") return loc.source.body;
678
- if (document2.kind === "Document") {
679
- const printed = printDocumentNode(document2);
680
- if (printed.trim()) return printed;
681
- }
682
- const asString = String(document2);
683
- if (asString && asString !== "[object Object]") return asString;
684
- throw new TypeError(
685
- "cmssy: could not read the query text off the given document"
686
- );
687
- }
688
-
689
702
  // src/data/client.ts
690
703
  function createCmssyClient(input) {
691
704
  const config = {
@@ -739,7 +752,7 @@ function createCmssyClient(input) {
739
752
  }
740
753
 
741
754
  // src/data/block-content.ts
742
- var RECORDS_BY_IDS_QUERY = `query PublicRecordsByIds($workspaceId: String!, $ids: [String!]!, $locale: String) {
755
+ var RECORDS_BY_IDS_QUERY = typedOperation(`query PublicRecordsByIds($workspaceId: String!, $ids: [String!]!, $locale: String) {
743
756
  public {
744
757
  model {
745
758
  recordsByIds(workspaceId: $workspaceId, ids: $ids, locale: $locale) {
@@ -747,7 +760,7 @@ var RECORDS_BY_IDS_QUERY = `query PublicRecordsByIds($workspaceId: String!, $ids
747
760
  }
748
761
  }
749
762
  }
750
- }`;
763
+ }`);
751
764
  var BY_IDS_CHUNK = 50;
752
765
  var COLLECTION_DEFAULT_LIMIT = 50;
753
766
  function relationModel(field) {
@@ -1014,7 +1027,11 @@ async function resolveForms(config, blocks, schemas, locale, defaultLocale, opti
1014
1027
  const entries = await Promise.all(
1015
1028
  ids.map(async (id) => {
1016
1029
  try {
1017
- const data = await client.queryScoped(FORM_QUERY, { formId: id }, options);
1030
+ const data = await client.queryScoped(
1031
+ FORM_QUERY,
1032
+ { formId: id },
1033
+ options
1034
+ );
1018
1035
  return [id, data.public.form.get];
1019
1036
  } catch (err) {
1020
1037
  if (typeof console !== "undefined") {
@@ -1,6 +1,15 @@
1
1
  import { CmssyClientConfig, CmssyLocaleContext, CmssySiteLocales } from '@cmssy/types';
2
2
  import { F as FetchLike, R as RetryOption } from './content-client-DhcHP8ln.js';
3
3
 
4
+ interface CmssyTypedDocument<Result, Variables> {
5
+ __apiType?: (variables: Variables) => Result;
6
+ }
7
+ type CmssyOperation<Result, Variables> = string & CmssyTypedDocument<Result, Variables>;
8
+ type CmssyOperationInput<Result, Variables> = (string & {
9
+ __apiType?: never;
10
+ }) | CmssyTypedDocument<Result, Variables>;
11
+ declare function typedOperation<Result, Variables>(text: string): CmssyOperation<Result, Variables>;
12
+
4
13
  interface GraphqlRequestOptions {
5
14
  fetch?: FetchLike;
6
15
  signal?: AbortSignal;
@@ -8,7 +17,7 @@ interface GraphqlRequestOptions {
8
17
  public?: boolean;
9
18
  retry?: RetryOption;
10
19
  }
11
- declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
20
+ declare function graphqlRequest<Result = unknown, Variables = Record<string, unknown>>(config: CmssyClientConfig, query: CmssyOperationInput<Result, Variables>, variables: Variables, options?: GraphqlRequestOptions, label?: string): Promise<Result>;
12
21
 
13
22
  declare function localizeHref(href: string, locale: CmssyLocaleContext): string;
14
23
 
@@ -27,4 +36,4 @@ declare function splitCmssyLocale(config: CmssyClientConfig, path: string[] | un
27
36
  }>;
28
37
  declare function localeForPath(config: CmssyClientConfig, path: string | string[]): Promise<string>;
29
38
 
30
- export { CMSSY_LOCALE_HEADER as C, type GraphqlRequestOptions as G, localeForPath as a, localeForPathname as b, resolveSiteLocales as c, splitLocaleFromPath as d, graphqlRequest as g, localizeHref as l, resolveCmssyLocale as r, splitCmssyLocale as s };
39
+ export { CMSSY_LOCALE_HEADER as C, type GraphqlRequestOptions as G, type CmssyOperation as a, type CmssyOperationInput as b, type CmssyTypedDocument as c, localeForPath as d, localeForPathname as e, resolveSiteLocales as f, graphqlRequest as g, splitLocaleFromPath as h, localizeHref as l, resolveCmssyLocale as r, splitCmssyLocale as s, typedOperation as t };
@@ -1,6 +1,15 @@
1
1
  import { CmssyClientConfig, CmssyLocaleContext, CmssySiteLocales } from '@cmssy/types';
2
2
  import { F as FetchLike, R as RetryOption } from './content-client-DhcHP8ln.cjs';
3
3
 
4
+ interface CmssyTypedDocument<Result, Variables> {
5
+ __apiType?: (variables: Variables) => Result;
6
+ }
7
+ type CmssyOperation<Result, Variables> = string & CmssyTypedDocument<Result, Variables>;
8
+ type CmssyOperationInput<Result, Variables> = (string & {
9
+ __apiType?: never;
10
+ }) | CmssyTypedDocument<Result, Variables>;
11
+ declare function typedOperation<Result, Variables>(text: string): CmssyOperation<Result, Variables>;
12
+
4
13
  interface GraphqlRequestOptions {
5
14
  fetch?: FetchLike;
6
15
  signal?: AbortSignal;
@@ -8,7 +17,7 @@ interface GraphqlRequestOptions {
8
17
  public?: boolean;
9
18
  retry?: RetryOption;
10
19
  }
11
- declare function graphqlRequest<T>(config: CmssyClientConfig, query: string, variables: Record<string, unknown>, options?: GraphqlRequestOptions, label?: string): Promise<T>;
20
+ declare function graphqlRequest<Result = unknown, Variables = Record<string, unknown>>(config: CmssyClientConfig, query: CmssyOperationInput<Result, Variables>, variables: Variables, options?: GraphqlRequestOptions, label?: string): Promise<Result>;
12
21
 
13
22
  declare function localizeHref(href: string, locale: CmssyLocaleContext): string;
14
23
 
@@ -27,4 +36,4 @@ declare function splitCmssyLocale(config: CmssyClientConfig, path: string[] | un
27
36
  }>;
28
37
  declare function localeForPath(config: CmssyClientConfig, path: string | string[]): Promise<string>;
29
38
 
30
- export { CMSSY_LOCALE_HEADER as C, type GraphqlRequestOptions as G, localeForPath as a, localeForPathname as b, resolveSiteLocales as c, splitLocaleFromPath as d, graphqlRequest as g, localizeHref as l, resolveCmssyLocale as r, splitCmssyLocale as s };
39
+ export { CMSSY_LOCALE_HEADER as C, type GraphqlRequestOptions as G, type CmssyOperation as a, type CmssyOperationInput as b, type CmssyTypedDocument as c, localeForPath as d, localeForPathname as e, resolveSiteLocales as f, graphqlRequest as g, splitLocaleFromPath as h, localizeHref as l, resolveCmssyLocale as r, splitCmssyLocale as s, typedOperation as t };