@cmssy/core 19.1.1 → 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.
@@ -1,7 +1,158 @@
1
1
  import { brandingFieldNames } 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(document) {
135
+ if (typeof document === "string") return document;
136
+ if (!document || typeof document !== "object") {
137
+ throw new TypeError(
138
+ "cmssy: expected a GraphQL document - a query string, a TypedDocumentString, or a TypedDocumentNode"
139
+ );
140
+ }
141
+ const loc = document.loc;
142
+ if (typeof loc?.source?.body === "string") return loc.source.body;
143
+ if (document.kind === "Document") {
144
+ const printed = printDocumentNode(document);
145
+ if (printed.trim()) return printed;
146
+ }
147
+ const asString = String(document);
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.2.0" ;
5
156
  var CMSSY_USER_AGENT = `@cmssy/core/${CMSSY_CORE_VERSION}`;
6
157
 
7
158
  // src/data/http.ts
@@ -50,7 +201,7 @@ function resolveRetryPolicy(retry) {
50
201
  throw new Error(
51
202
  `cmssy: unknown retry mode "${retry}" - use ${Object.keys(
52
203
  CMSSY_RETRY_MODES
53
- ).map((name) => `"${name}"`).join(" or ")}, false, or a retry policy object`
204
+ ).map((name2) => `"${name2}"`).join(" or ")}, false, or a retry policy object`
54
205
  );
55
206
  }
56
207
  return mode;
@@ -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,
@@ -208,7 +359,7 @@ async function graphqlRequest(config, query, variables, options = {}, label = "r
208
359
  label
209
360
  });
210
361
  }
211
- var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
362
+ var SITE_CONFIG_QUERY = typedOperation(`query PublicSiteConfig($workspaceSlug: String!) {
212
363
  public {
213
364
  siteConfig(workspaceSlug: $workspaceSlug) {
214
365
  id
@@ -224,7 +375,7 @@ var SITE_CONFIG_QUERY = `query PublicSiteConfig($workspaceSlug: String!) {
224
375
  }
225
376
  }
226
377
  }
227
- }`;
378
+ }`);
228
379
 
229
380
  // src/data/settings-client.ts
230
381
  var workspaceIdCache = /* @__PURE__ */ new Map();