@cmssy/core 19.1.0 → 19.2.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.
- package/dist/{csp-AuptG-R-.d.ts → csp-BdigosQo.d.ts} +8 -10
- package/dist/{csp-Dtp9S9TS.d.cts → csp-GwcubV3k.d.cts} +8 -10
- package/dist/index.cjs +156 -152
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +156 -153
- package/dist/internal/locale.cjs +156 -5
- package/dist/internal/locale.d.cts +1 -1
- package/dist/internal/locale.d.ts +1 -1
- package/dist/internal/locale.js +156 -5
- package/dist/internal.cjs +202 -186
- package/dist/internal.d.cts +66 -10
- package/dist/internal.d.ts +66 -10
- package/dist/internal.js +202 -186
- package/dist/{locale-BCguiP54.d.ts → locale-BGUsgy8p.d.ts} +11 -2
- package/dist/{locale-CsDPiYGF.d.cts → locale-DLGQgiu5.d.cts} +11 -2
- package/dist/preflight.cjs +171 -17
- package/dist/preflight.js +171 -17
- package/dist/testing.cjs +2 -0
- package/dist/testing.js +2 -0
- package/package.json +1 -1
package/dist/internal.d.ts
CHANGED
|
@@ -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,
|
|
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-
|
|
5
|
-
export { C as CMSSY_LOCALE_HEADER,
|
|
6
|
-
import { Q as QueryScopedOptions } from './csp-
|
|
7
|
-
export {
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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.
|
|
155
|
+
var CMSSY_CORE_VERSION = "19.2.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
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
460
|
+
devPreview: true
|
|
302
461
|
},
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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;
|
|
@@ -425,7 +583,7 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
|
|
|
425
583
|
label
|
|
426
584
|
});
|
|
427
585
|
}
|
|
428
|
-
var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
|
|
586
|
+
var SITE_CONFIG_QUERY = typedOperation(`query PublicSiteConfig($workspaceSlug: String!) {
|
|
429
587
|
public {
|
|
430
588
|
siteConfig(workspaceSlug: $workspaceSlug) {
|
|
431
589
|
id
|
|
@@ -441,8 +599,8 @@ var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
|
|
|
441
599
|
}
|
|
442
600
|
}
|
|
443
601
|
}
|
|
444
|
-
}
|
|
445
|
-
var MODEL_DEFINITIONS_QUERY = `query PublicModelDefinitions($workspaceId: String!) {
|
|
602
|
+
}`);
|
|
603
|
+
var MODEL_DEFINITIONS_QUERY = typedOperation(`query PublicModelDefinitions($workspaceId: String!) {
|
|
446
604
|
public {
|
|
447
605
|
model {
|
|
448
606
|
definitions(workspaceId: $workspaceId) {
|
|
@@ -450,8 +608,8 @@ var MODEL_DEFINITIONS_QUERY = `query PublicModelDefinitions($workspaceId: String
|
|
|
450
608
|
}
|
|
451
609
|
}
|
|
452
610
|
}
|
|
453
|
-
}
|
|
454
|
-
var MODEL_RECORDS_QUERY = `query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $locale: String, $limit: Int, $offset: Int, $populate: [String!]) {
|
|
611
|
+
}`);
|
|
612
|
+
var MODEL_RECORDS_QUERY = typedOperation(`query PublicModelRecords($workspaceId: String!, $modelSlug: String!, $filter: JSON, $sort: String, $locale: String, $limit: Int, $offset: Int, $populate: [String!]) {
|
|
455
613
|
public {
|
|
456
614
|
model {
|
|
457
615
|
records(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, sort: $sort, locale: $locale, limit: $limit, offset: $offset, populate: $populate) {
|
|
@@ -461,8 +619,9 @@ var MODEL_RECORDS_QUERY = `query PublicModelRecords($workspaceId: String!, $mode
|
|
|
461
619
|
}
|
|
462
620
|
}
|
|
463
621
|
}
|
|
464
|
-
}
|
|
465
|
-
var FORM_QUERY =
|
|
622
|
+
}`);
|
|
623
|
+
var FORM_QUERY = typedOperation(
|
|
624
|
+
`query PublicForm($formId: ID!) {
|
|
466
625
|
public {
|
|
467
626
|
form {
|
|
468
627
|
get(formId: $formId) {
|
|
@@ -483,8 +642,9 @@ var FORM_QUERY = `query PublicForm($formId: ID!) {
|
|
|
483
642
|
}
|
|
484
643
|
}
|
|
485
644
|
}
|
|
486
|
-
}
|
|
487
|
-
|
|
645
|
+
}`
|
|
646
|
+
);
|
|
647
|
+
var SUBMIT_FORM_MUTATION = typedOperation(`mutation SubmitForm($formId: ID!, $input: SubmitFormInput!) {
|
|
488
648
|
public {
|
|
489
649
|
form {
|
|
490
650
|
submit(formId: $formId, input: $input) {
|
|
@@ -492,7 +652,7 @@ var SUBMIT_FORM_MUTATION = `mutation SubmitForm($formId: ID!, $input: SubmitForm
|
|
|
492
652
|
}
|
|
493
653
|
}
|
|
494
654
|
}
|
|
495
|
-
}
|
|
655
|
+
}`);
|
|
496
656
|
|
|
497
657
|
// src/data/settings-client.ts
|
|
498
658
|
async function fetchSiteConfig(config, options = {}) {
|
|
@@ -538,154 +698,6 @@ function clearWorkspaceIdCache() {
|
|
|
538
698
|
workspaceIdCache.clear();
|
|
539
699
|
}
|
|
540
700
|
|
|
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
701
|
// src/data/client.ts
|
|
690
702
|
function createCmssyClient(input) {
|
|
691
703
|
const config = {
|
|
@@ -739,7 +751,7 @@ function createCmssyClient(input) {
|
|
|
739
751
|
}
|
|
740
752
|
|
|
741
753
|
// src/data/block-content.ts
|
|
742
|
-
var RECORDS_BY_IDS_QUERY = `query PublicRecordsByIds($workspaceId: String!, $ids: [String!]!, $locale: String) {
|
|
754
|
+
var RECORDS_BY_IDS_QUERY = typedOperation(`query PublicRecordsByIds($workspaceId: String!, $ids: [String!]!, $locale: String) {
|
|
743
755
|
public {
|
|
744
756
|
model {
|
|
745
757
|
recordsByIds(workspaceId: $workspaceId, ids: $ids, locale: $locale) {
|
|
@@ -747,7 +759,7 @@ var RECORDS_BY_IDS_QUERY = `query PublicRecordsByIds($workspaceId: String!, $ids
|
|
|
747
759
|
}
|
|
748
760
|
}
|
|
749
761
|
}
|
|
750
|
-
}
|
|
762
|
+
}`);
|
|
751
763
|
var BY_IDS_CHUNK = 50;
|
|
752
764
|
var COLLECTION_DEFAULT_LIMIT = 50;
|
|
753
765
|
function relationModel(field) {
|
|
@@ -1014,7 +1026,11 @@ async function resolveForms(config, blocks, schemas, locale, defaultLocale, opti
|
|
|
1014
1026
|
const entries = await Promise.all(
|
|
1015
1027
|
ids.map(async (id) => {
|
|
1016
1028
|
try {
|
|
1017
|
-
const data = await client.queryScoped(
|
|
1029
|
+
const data = await client.queryScoped(
|
|
1030
|
+
FORM_QUERY,
|
|
1031
|
+
{ formId: id },
|
|
1032
|
+
options
|
|
1033
|
+
);
|
|
1018
1034
|
return [id, data.public.form.get];
|
|
1019
1035
|
} catch (err) {
|
|
1020
1036
|
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<
|
|
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,
|
|
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<
|
|
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,
|
|
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 };
|