@relyio/sdk 0.13.0 → 0.15.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/CHANGELOG.md +150 -0
- package/dist/{chunk-DEDIJKHY.cjs → chunk-3BHDGUNS.cjs} +1554 -3250
- package/dist/{chunk-3NPPMGB6.js → chunk-5UMY6CS4.js} +2 -2
- package/dist/{chunk-EW23SZPX.js → chunk-PCFTJLEP.js} +540 -262
- package/dist/{chunk-6NGJXLOR.js → chunk-PXA5ONIU.js} +1553 -3240
- package/dist/{chunk-Z6GLWSSD.cjs → chunk-RSHMA4KT.cjs} +2 -2
- package/dist/{chunk-FOSM4LMM.cjs → chunk-X4KSS7PP.cjs} +539 -262
- package/dist/client/index.cjs +3 -3
- package/dist/client/index.d.cts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/{include-paths-Bs5FhNw2.d.cts → define-content-type-B2gQZkTy.d.cts} +3697 -2585
- package/dist/{include-paths-Cb7iPCW2.d.ts → define-content-type-Ds5rCAYl.d.ts} +3697 -2585
- package/dist/{define-schema-sWJ8Zn7C.d.cts → define-schema-Cm_5y3ei.d.cts} +238 -356
- package/dist/{define-schema-UHViXKiv.d.ts → define-schema-CxpIYFFR.d.ts} +238 -356
- package/dist/index-DQ7eTUPQ.d.ts +3090 -0
- package/dist/{index--_u1nPHv.d.cts → index-DY64WjZM.d.cts} +2 -2
- package/dist/{index-8DozAWsA.d.ts → index-Db3_tmYf.d.ts} +2 -2
- package/dist/index-F0UuHpRj.d.cts +3090 -0
- package/dist/index.cjs +90 -130
- package/dist/index.d.cts +16 -23
- package/dist/index.d.ts +16 -23
- package/dist/index.js +4 -4
- package/dist/rich-text/index.cjs +11 -11
- package/dist/rich-text/index.d.cts +2 -2
- package/dist/rich-text/index.d.ts +2 -2
- package/dist/rich-text/index.js +1 -1
- package/dist/schema/index.cjs +33 -37
- package/dist/schema/index.d.cts +33 -18
- package/dist/schema/index.d.ts +33 -18
- package/dist/schema/index.js +1 -1
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/index-BT0L8xJj.d.cts +0 -3717
- package/dist/index-CPjJ25R4.d.ts +0 -3717
|
@@ -4,11 +4,362 @@ var chunkMWMSFIWN_cjs = require('./chunk-MWMSFIWN.cjs');
|
|
|
4
4
|
|
|
5
5
|
/* RelyIO SDK - Built with ❤️ by the RelyIO Team */
|
|
6
6
|
|
|
7
|
+
// src/schema/fields/keyed.ts
|
|
8
|
+
var KEYED_FIELD_OPTIONS = [
|
|
9
|
+
"displayName",
|
|
10
|
+
"description",
|
|
11
|
+
"ui",
|
|
12
|
+
"ai",
|
|
13
|
+
"rules",
|
|
14
|
+
"localized",
|
|
15
|
+
"fallback",
|
|
16
|
+
"deprecated"
|
|
17
|
+
];
|
|
18
|
+
function keyedField(type, options) {
|
|
19
|
+
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`fields.${type} takes one options object: the id-first form, fields.${type}('id', { config }), was removed in 0.14. Write the Field under its key, as id: fields.${type}({ \u2026 })`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return { _tag: "keyedField", type, options: { ...options } };
|
|
25
|
+
}
|
|
26
|
+
chunkMWMSFIWN_cjs.__name(keyedField, "keyedField");
|
|
27
|
+
function labelFromKey(key) {
|
|
28
|
+
const words = key.replace(/[_\-\s]+/g, " ").replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").trim().split(/\s+/).filter((word) => word.length > 0);
|
|
29
|
+
return words.map((word, index) => {
|
|
30
|
+
const acronym = word.length > 1 && word === word.toUpperCase() && /[A-Z]/.test(word);
|
|
31
|
+
const cased = acronym ? word : word.toLowerCase();
|
|
32
|
+
return index === 0 ? cased.charAt(0).toUpperCase() + cased.slice(1) : cased;
|
|
33
|
+
}).join(" ");
|
|
34
|
+
}
|
|
35
|
+
chunkMWMSFIWN_cjs.__name(labelFromKey, "labelFromKey");
|
|
36
|
+
function isKeyedField(value) {
|
|
37
|
+
return typeof value === "object" && value !== null && value._tag === "keyedField";
|
|
38
|
+
}
|
|
39
|
+
chunkMWMSFIWN_cjs.__name(isKeyedField, "isKeyedField");
|
|
40
|
+
function localizationOf(localized, id) {
|
|
41
|
+
if (localized === true) return true;
|
|
42
|
+
if (typeof localized === "object" && localized !== null && !Array.isArray(localized)) {
|
|
43
|
+
const { requiredLocales, fallback } = localized;
|
|
44
|
+
return {
|
|
45
|
+
enabled: true,
|
|
46
|
+
...requiredLocales !== void 0 && { requiredLocales },
|
|
47
|
+
...fallback !== void 0 && { fallback }
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Field '${id}' has localized: ${JSON.stringify(localized)}. It takes true, or { requiredLocales, fallback } \u2014 leave it out for a Field every locale shares`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
chunkMWMSFIWN_cjs.__name(localizationOf, "localizationOf");
|
|
55
|
+
function compileKeyedField(id, field) {
|
|
56
|
+
const config = {};
|
|
57
|
+
const shared = {};
|
|
58
|
+
const sharedNames = new Set(KEYED_FIELD_OPTIONS);
|
|
59
|
+
for (const [key, value] of Object.entries(field.options)) {
|
|
60
|
+
if (value === void 0) continue;
|
|
61
|
+
if (sharedNames.has(key)) shared[key] = value;
|
|
62
|
+
else config[key] = value;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
type: field.type,
|
|
67
|
+
...Object.keys(config).length > 0 && { config },
|
|
68
|
+
ui: {
|
|
69
|
+
displayName: typeof shared.displayName === "string" ? shared.displayName : labelFromKey(id),
|
|
70
|
+
...shared.description !== void 0 && { description: shared.description },
|
|
71
|
+
...shared.ui !== void 0 && { options: shared.ui }
|
|
72
|
+
},
|
|
73
|
+
...shared.ai !== void 0 && { ai: shared.ai },
|
|
74
|
+
...shared.rules !== void 0 && { rules: shared.rules },
|
|
75
|
+
...shared.localized !== void 0 && { localization: localizationOf(shared.localized, id) },
|
|
76
|
+
...shared.fallback !== void 0 && { fallback: shared.fallback },
|
|
77
|
+
...shared.deprecated !== void 0 && { deprecated: shared.deprecated }
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
chunkMWMSFIWN_cjs.__name(compileKeyedField, "compileKeyedField");
|
|
81
|
+
function isSection(value) {
|
|
82
|
+
return typeof value === "object" && value !== null && !("type" in value) && "fields" in value && Array.isArray(value.fields);
|
|
83
|
+
}
|
|
84
|
+
chunkMWMSFIWN_cjs.__name(isSection, "isSection");
|
|
85
|
+
function notKeyed(id) {
|
|
86
|
+
return new Error(
|
|
87
|
+
`Field '${id}' is not written in the keyed form: under a key, write it without an id, as fields.shortText({ \u2026 })`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
chunkMWMSFIWN_cjs.__name(notKeyed, "notKeyed");
|
|
91
|
+
function compileKeyedFields(fields2) {
|
|
92
|
+
return Object.entries(fields2).map(([id, field]) => {
|
|
93
|
+
if (isSection(field)) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`'${id}' is a fieldset, and a settings group holds no Sections: write its Fields beside the others`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (!isKeyedField(field)) throw notKeyed(id);
|
|
99
|
+
return compileKeyedField(id, field);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
chunkMWMSFIWN_cjs.__name(compileKeyedFields, "compileKeyedFields");
|
|
103
|
+
function compileKeyedMembers(members) {
|
|
104
|
+
const compiled = Object.entries(members).map(([id, member]) => {
|
|
105
|
+
if (isKeyedField(member)) return compileKeyedField(id, member);
|
|
106
|
+
if (!isSection(member)) throw notKeyed(id);
|
|
107
|
+
if (member.id !== id) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Section '${id}' holds fieldset '${member.id}': a Section's key is its fieldset's id, so write it as ${member.id}: \u2026`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return member;
|
|
113
|
+
});
|
|
114
|
+
refuseAFieldIdTwice(compiled);
|
|
115
|
+
return compiled;
|
|
116
|
+
}
|
|
117
|
+
chunkMWMSFIWN_cjs.__name(compileKeyedMembers, "compileKeyedMembers");
|
|
118
|
+
function fieldPaths(members, prefix) {
|
|
119
|
+
return members.flatMap((member) => {
|
|
120
|
+
if (isSection(member)) return fieldPaths(member.fields, `${prefix}${member.id}.`);
|
|
121
|
+
const { id } = member;
|
|
122
|
+
return [[id, `${prefix}${id}`]];
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
chunkMWMSFIWN_cjs.__name(fieldPaths, "fieldPaths");
|
|
126
|
+
function refuseAFieldIdTwice(members) {
|
|
127
|
+
const firstPath = /* @__PURE__ */ new Map();
|
|
128
|
+
for (const [id, path] of fieldPaths(members, "")) {
|
|
129
|
+
const first = firstPath.get(id);
|
|
130
|
+
if (first !== void 0) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Field '${id}' is declared twice, at '${first}' and at '${path}': a Section's Fields join the record it sits in, so a Field id is used once across its Sections`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
firstPath.set(id, path);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
chunkMWMSFIWN_cjs.__name(refuseAFieldIdTwice, "refuseAFieldIdTwice");
|
|
139
|
+
|
|
140
|
+
// src/schema/define-content-type.ts
|
|
141
|
+
function fieldset(id, config) {
|
|
142
|
+
if (Array.isArray(config.fields)) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`fieldset('${id}') takes its fields as a record, each Field under its id: the list form was removed in 0.14`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
id,
|
|
149
|
+
displayName: config.displayName ?? labelFromKey(id),
|
|
150
|
+
...config.description !== void 0 && { description: config.description },
|
|
151
|
+
...config.collapsed !== void 0 && { collapsedByDefault: config.collapsed },
|
|
152
|
+
...config.ai !== void 0 && { ai: config.ai },
|
|
153
|
+
fields: compileKeyedMembers(config.fields)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
chunkMWMSFIWN_cjs.__name(fieldset, "fieldset");
|
|
157
|
+
function keyedSettings(config) {
|
|
158
|
+
return {
|
|
159
|
+
...config.displayName !== void 0 && { displayName: config.displayName },
|
|
160
|
+
...config.displayNamePlural !== void 0 && { displayNamePlural: config.displayNamePlural },
|
|
161
|
+
...config.description !== void 0 && { description: config.description },
|
|
162
|
+
...config.ai !== void 0 && { ai: config.ai },
|
|
163
|
+
...config.displayField !== void 0 && { displayField: config.displayField },
|
|
164
|
+
...config.accessTags !== void 0 && { accessTags: config.accessTags },
|
|
165
|
+
...config.workflow !== void 0 && { workflow: config.workflow }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
chunkMWMSFIWN_cjs.__name(keyedSettings, "keyedSettings");
|
|
169
|
+
function idFormRemoved(builder, name) {
|
|
170
|
+
return new Error(
|
|
171
|
+
`${builder}('${name}', \u2026) is the id-first form, removed in 0.14: write ${builder}({ \u2026 }) under its key in defineSchema`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
chunkMWMSFIWN_cjs.__name(idFormRemoved, "idFormRemoved");
|
|
175
|
+
function defineContentType(config) {
|
|
176
|
+
if (typeof config === "string") throw idFormRemoved("defineContentType", config);
|
|
177
|
+
return {
|
|
178
|
+
_tag: "contentType",
|
|
179
|
+
...keyedSettings(config),
|
|
180
|
+
// Written only when given, so a TypeScript type and its YAML twin hash alike (REL-1458)
|
|
181
|
+
...config.hierarchical !== void 0 && { hierarchical: config.hierarchical },
|
|
182
|
+
fields: compileKeyedMembers(config.fields)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
chunkMWMSFIWN_cjs.__name(defineContentType, "defineContentType");
|
|
186
|
+
|
|
187
|
+
// src/schema/keyed-declarations.ts
|
|
188
|
+
function isList(value) {
|
|
189
|
+
return Array.isArray(value);
|
|
190
|
+
}
|
|
191
|
+
chunkMWMSFIWN_cjs.__name(isList, "isList");
|
|
192
|
+
function isKeyed(value, tag) {
|
|
193
|
+
return typeof value === "object" && value !== null && value._tag === tag;
|
|
194
|
+
}
|
|
195
|
+
chunkMWMSFIWN_cjs.__name(isKeyed, "isKeyed");
|
|
196
|
+
|
|
197
|
+
// src/schema/define-role.ts
|
|
198
|
+
var BUILT_IN_ROLES = ["admin", "editor", "viewer"];
|
|
199
|
+
var ROLE_ACTIONS = [
|
|
200
|
+
"create",
|
|
201
|
+
"read",
|
|
202
|
+
"update",
|
|
203
|
+
"delete",
|
|
204
|
+
"publish",
|
|
205
|
+
"unpublish",
|
|
206
|
+
"duplicate",
|
|
207
|
+
"comment",
|
|
208
|
+
"approveElevated"
|
|
209
|
+
];
|
|
210
|
+
var BUILT_IN_ROLE_ACTIONS = {
|
|
211
|
+
admin: ["create", "read", "update", "delete", "publish", "unpublish", "duplicate", "comment"],
|
|
212
|
+
editor: ["create", "read", "update", "delete", "publish", "unpublish", "duplicate", "comment"],
|
|
213
|
+
viewer: ["read", "comment"]
|
|
214
|
+
};
|
|
215
|
+
function defineRole(config) {
|
|
216
|
+
if (typeof config === "string") throw idFormRemoved("defineRole", config);
|
|
217
|
+
return { ...config, _tag: "keyedRole" };
|
|
218
|
+
}
|
|
219
|
+
chunkMWMSFIWN_cjs.__name(defineRole, "defineRole");
|
|
220
|
+
function compileKeyedRoles(roles) {
|
|
221
|
+
return Object.entries(roles).map(([id, role]) => {
|
|
222
|
+
if (!isKeyed(role, "keyedRole")) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Role '${id}' is not written in the keyed form: under a key, write it without an id, as defineRole({ \u2026 })`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
const { _tag: _keyed, displayName, ...config } = role;
|
|
228
|
+
return roleDefinition(id, { ...config, displayName: displayName ?? labelFromKey(id) });
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
chunkMWMSFIWN_cjs.__name(compileKeyedRoles, "compileKeyedRoles");
|
|
232
|
+
function roleDefinition(id, config) {
|
|
233
|
+
if (!id || id.length === 0) {
|
|
234
|
+
throw new Error("Role ID is required");
|
|
235
|
+
}
|
|
236
|
+
const roleIdPattern = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$|^[a-z][a-zA-Z0-9]*$/;
|
|
237
|
+
if (!roleIdPattern.test(id)) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`Role ID '${id}' must be kebab-case (e.g., blog-editor) or camelCase (e.g., blogEditor)`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
if (BUILT_IN_ROLES.includes(id)) {
|
|
243
|
+
throw new Error(`Role ID '${id}' cannot use a built-in role name (admin, editor, viewer)`);
|
|
244
|
+
}
|
|
245
|
+
if (!config.displayName || config.displayName.length === 0) {
|
|
246
|
+
throw new Error("Role displayName is required");
|
|
247
|
+
}
|
|
248
|
+
const hasBaseRole = config.baseRole !== void 0;
|
|
249
|
+
const hasIncludes = Array.isArray(config.includes) && config.includes.length > 0;
|
|
250
|
+
const hasPermissions = Array.isArray(config.permissions) && config.permissions.length > 0;
|
|
251
|
+
const hasHiddenFields = config.fields !== void 0 && Array.isArray(config.fields.hidden) && config.fields.hidden.length > 0;
|
|
252
|
+
const hasReadonlyFields = config.fields !== void 0 && Array.isArray(config.fields.readonly) && config.fields.readonly.length > 0;
|
|
253
|
+
const hasFields = hasHiddenFields || hasReadonlyFields;
|
|
254
|
+
if (!hasBaseRole && !hasIncludes && !hasPermissions && !hasFields) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`Role '${id}' must have at least one of: 'baseRole', 'includes', or permissions (with tags/actions or fields)`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (Array.isArray(config.permissions) && config.permissions.length > 0) {
|
|
260
|
+
for (const perm of config.permissions) {
|
|
261
|
+
if (perm.tags.length === 0) {
|
|
262
|
+
throw new Error(`Permission in role '${id}' must have at least one tag`);
|
|
263
|
+
}
|
|
264
|
+
if (perm.actions.length === 0) {
|
|
265
|
+
throw new Error(`Permission in role '${id}' must have at least one action`);
|
|
266
|
+
}
|
|
267
|
+
for (const action of perm.actions) {
|
|
268
|
+
if (!ROLE_ACTIONS.includes(action)) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`Invalid action '${action}' in role '${id}'. Valid actions: ${ROLE_ACTIONS.join(", ")}`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
_tag: "role",
|
|
278
|
+
id,
|
|
279
|
+
displayName: config.displayName,
|
|
280
|
+
...config.description !== void 0 && { description: config.description },
|
|
281
|
+
...config.baseRole !== void 0 && { baseRole: config.baseRole },
|
|
282
|
+
...config.includes !== void 0 && { includes: config.includes },
|
|
283
|
+
...config.permissions !== void 0 && { permissions: config.permissions },
|
|
284
|
+
...config.fields !== void 0 && { fields: config.fields }
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
chunkMWMSFIWN_cjs.__name(roleDefinition, "roleDefinition");
|
|
288
|
+
function isRoleDefinition(value) {
|
|
289
|
+
return typeof value === "object" && value !== null && "_tag" in value && value._tag === "role";
|
|
290
|
+
}
|
|
291
|
+
chunkMWMSFIWN_cjs.__name(isRoleDefinition, "isRoleDefinition");
|
|
292
|
+
function isBuiltInRole(roleId) {
|
|
293
|
+
return BUILT_IN_ROLES.includes(roleId);
|
|
294
|
+
}
|
|
295
|
+
chunkMWMSFIWN_cjs.__name(isBuiltInRole, "isBuiltInRole");
|
|
296
|
+
function getBuiltInRoleActions(roleId) {
|
|
297
|
+
return BUILT_IN_ROLE_ACTIONS[roleId];
|
|
298
|
+
}
|
|
299
|
+
chunkMWMSFIWN_cjs.__name(getBuiltInRoleActions, "getBuiltInRoleActions");
|
|
300
|
+
|
|
301
|
+
// src/schema/define-view.ts
|
|
302
|
+
function defineView(config) {
|
|
303
|
+
if (typeof config === "string") throw idFormRemoved("defineView", config);
|
|
304
|
+
return { ...config, _tag: "keyedView" };
|
|
305
|
+
}
|
|
306
|
+
chunkMWMSFIWN_cjs.__name(defineView, "defineView");
|
|
307
|
+
function compileKeyedViews(views) {
|
|
308
|
+
return Object.entries(views).map(([id, view]) => {
|
|
309
|
+
if (!isKeyed(view, "keyedView")) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`View '${id}' is not written in the keyed form: under a key, write it without an id, as defineView({ \u2026 })`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
const { _tag: _keyed, name, ...config } = view;
|
|
315
|
+
return viewDefinition(id, { ...config, name: name ?? labelFromKey(id) });
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
chunkMWMSFIWN_cjs.__name(compileKeyedViews, "compileKeyedViews");
|
|
319
|
+
function viewDefinition(id, config) {
|
|
320
|
+
if (!id.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) {
|
|
321
|
+
throw new Error(
|
|
322
|
+
`View ID '${id}' must start with a letter and contain only letters, numbers, underscores, and hyphens`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
if (!config.name || config.name.length === 0) {
|
|
326
|
+
throw new Error(`View '${id}' must have a name`);
|
|
327
|
+
}
|
|
328
|
+
if (config.metadataFields && config.metadataFields.length > 3) {
|
|
329
|
+
throw new Error(`View '${id}' can have at most 3 metadata fields`);
|
|
330
|
+
}
|
|
331
|
+
if (!config.scope?.type) {
|
|
332
|
+
throw new Error(`View '${id}' must have a valid scope`);
|
|
333
|
+
}
|
|
334
|
+
const grouped = (config.filters ?? []).findIndex(
|
|
335
|
+
(filter) => typeof filter === "object" && filter !== null && "conditions" in filter
|
|
336
|
+
);
|
|
337
|
+
if (grouped !== -1) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
`View '${id}' filter ${grouped} is a filter group: a view's filters are a flat list, joined by AND. List each of its conditions as a filter of its own, or use 'isAnyOf' for an OR within one field.`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
if (config.slug !== void 0 && !/^[a-z][a-z0-9-]*$/.test(config.slug)) {
|
|
343
|
+
throw new Error(
|
|
344
|
+
`View '${id}' slug '${config.slug}' must be lowercase, start with a letter, and contain only letters, numbers, and hyphens`
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
return {
|
|
348
|
+
_tag: "view",
|
|
349
|
+
id,
|
|
350
|
+
...config
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
chunkMWMSFIWN_cjs.__name(viewDefinition, "viewDefinition");
|
|
354
|
+
|
|
7
355
|
// src/schema/define-schema.ts
|
|
8
356
|
function defineSchema(config) {
|
|
9
357
|
if (config.contentTypes == null) {
|
|
10
358
|
throw new Error("Schema must declare contentTypes (an empty object declares none)");
|
|
11
359
|
}
|
|
360
|
+
refuseOneDefinitionUnderTwoKeys(config);
|
|
361
|
+
const roles = config.roles === void 0 ? void 0 : listed("roles", config.roles, compileKeyedRoles);
|
|
362
|
+
const views = config.views === void 0 ? void 0 : listed("views", config.views, compileKeyedViews);
|
|
12
363
|
if (config.locales && config.locales.length > 0) {
|
|
13
364
|
const defaultLocales = config.locales.filter((l) => l.default === true);
|
|
14
365
|
if (defaultLocales.length === 0) {
|
|
@@ -36,9 +387,9 @@ function defineSchema(config) {
|
|
|
36
387
|
}
|
|
37
388
|
}
|
|
38
389
|
}
|
|
39
|
-
if (
|
|
390
|
+
if (roles && roles.length > 0) {
|
|
40
391
|
const roleIds = /* @__PURE__ */ new Set();
|
|
41
|
-
for (const role of
|
|
392
|
+
for (const role of roles) {
|
|
42
393
|
if (roleIds.has(role.id)) {
|
|
43
394
|
throw new Error(`Duplicate role ID '${role.id}'`);
|
|
44
395
|
}
|
|
@@ -47,7 +398,7 @@ function defineSchema(config) {
|
|
|
47
398
|
}
|
|
48
399
|
if (config.workflow) {
|
|
49
400
|
const builtInRoles = /* @__PURE__ */ new Set(["admin", "editor", "viewer"]);
|
|
50
|
-
const customRoleIds = new Set(
|
|
401
|
+
const customRoleIds = new Set(roles?.map((r) => r.id) ?? []);
|
|
51
402
|
const allRoleIds = /* @__PURE__ */ new Set([...builtInRoles, ...customRoleIds]);
|
|
52
403
|
for (const stage of config.workflow.stages ?? []) {
|
|
53
404
|
if (stage.allowedRoles) {
|
|
@@ -84,9 +435,9 @@ function defineSchema(config) {
|
|
|
84
435
|
}
|
|
85
436
|
}
|
|
86
437
|
}
|
|
87
|
-
if (
|
|
438
|
+
if (views && views.length > 0) {
|
|
88
439
|
const viewIds = /* @__PURE__ */ new Set();
|
|
89
|
-
for (const view of
|
|
440
|
+
for (const view of views) {
|
|
90
441
|
if (viewIds.has(view.id)) {
|
|
91
442
|
throw new Error(`Duplicate view ID '${view.id}'`);
|
|
92
443
|
}
|
|
@@ -96,17 +447,76 @@ function defineSchema(config) {
|
|
|
96
447
|
return {
|
|
97
448
|
_tag: "schema",
|
|
98
449
|
...config.locales !== void 0 && { locales: config.locales },
|
|
99
|
-
contentTypes: config.contentTypes,
|
|
100
|
-
singletonContentTypes:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
450
|
+
contentTypes: withKeys(config.contentTypes, "labelled"),
|
|
451
|
+
singletonContentTypes: withKeys(
|
|
452
|
+
config.singletonContentTypes ?? {},
|
|
453
|
+
"labelled"
|
|
454
|
+
),
|
|
455
|
+
queries: withKeys(config.queries ?? {}, "unlabelled"),
|
|
456
|
+
settingsGroups: config.settingsGroups && withKeys(config.settingsGroups, "labelled"),
|
|
457
|
+
...config.assetTypes && { assetTypes: withKeys(config.assetTypes, "labelled") },
|
|
458
|
+
// A keyed record's list is the one it compiled to, each item under its key as its id — what
|
|
459
|
+
// `RolesAsList` and `ViewsAsList` say, which is all the casts say
|
|
460
|
+
...roles !== void 0 && { roles },
|
|
105
461
|
...config.workflow && { workflow: config.workflow },
|
|
106
|
-
...
|
|
462
|
+
...views !== void 0 && { views }
|
|
107
463
|
};
|
|
108
464
|
}
|
|
109
465
|
chunkMWMSFIWN_cjs.__name(defineSchema, "defineSchema");
|
|
466
|
+
function listed(section, keyed, compile) {
|
|
467
|
+
if (Array.isArray(keyed)) {
|
|
468
|
+
throw new Error(
|
|
469
|
+
`defineSchema takes ${section} as a record, each under its id: the list form was removed in 0.14`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
return compile(keyed);
|
|
473
|
+
}
|
|
474
|
+
chunkMWMSFIWN_cjs.__name(listed, "listed");
|
|
475
|
+
function withKeys(items, labels) {
|
|
476
|
+
return Object.fromEntries(
|
|
477
|
+
Object.entries(items).map(([key, definition]) => {
|
|
478
|
+
const written = definition;
|
|
479
|
+
if (written.name !== void 0) return [key, definition];
|
|
480
|
+
return [
|
|
481
|
+
key,
|
|
482
|
+
{
|
|
483
|
+
...definition,
|
|
484
|
+
name: key,
|
|
485
|
+
...labels === "labelled" && written.displayName === void 0 && { displayName: labelFromKey(key) }
|
|
486
|
+
}
|
|
487
|
+
];
|
|
488
|
+
})
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
chunkMWMSFIWN_cjs.__name(withKeys, "withKeys");
|
|
492
|
+
var KEYED_SECTIONS = [
|
|
493
|
+
"contentTypes",
|
|
494
|
+
"singletonContentTypes",
|
|
495
|
+
"assetTypes",
|
|
496
|
+
"queries",
|
|
497
|
+
"settingsGroups",
|
|
498
|
+
"roles",
|
|
499
|
+
"views"
|
|
500
|
+
];
|
|
501
|
+
function refuseOneDefinitionUnderTwoKeys(config) {
|
|
502
|
+
const seen = /* @__PURE__ */ new Map();
|
|
503
|
+
for (const section of KEYED_SECTIONS) {
|
|
504
|
+
const items = config[section];
|
|
505
|
+
if (items === null || typeof items !== "object" || Array.isArray(items)) continue;
|
|
506
|
+
for (const [key, definition] of Object.entries(items)) {
|
|
507
|
+
if (definition === null || typeof definition !== "object") continue;
|
|
508
|
+
const path = `${section}.${key}`;
|
|
509
|
+
const first = seen.get(definition);
|
|
510
|
+
if (first !== void 0) {
|
|
511
|
+
throw new Error(
|
|
512
|
+
`One definition is registered under two keys, '${first}' and '${path}': each key deploys a declaration of its own, so give each key its own definition`
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
seen.set(definition, path);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
chunkMWMSFIWN_cjs.__name(refuseOneDefinitionUnderTwoKeys, "refuseOneDefinitionUnderTwoKeys");
|
|
110
520
|
|
|
111
521
|
// src/schema/define-locale.ts
|
|
112
522
|
var BCP47_PATTERN = /^[a-z]{2}(-[A-Z]{2})?$/;
|
|
@@ -180,193 +590,87 @@ function buildFallbackChain(localeCode, locales, maxDepth = 10) {
|
|
|
180
590
|
}
|
|
181
591
|
chunkMWMSFIWN_cjs.__name(buildFallbackChain, "buildFallbackChain");
|
|
182
592
|
|
|
183
|
-
// src/schema/define-content-type.ts
|
|
184
|
-
function fieldset(id, config) {
|
|
185
|
-
return {
|
|
186
|
-
id,
|
|
187
|
-
displayName: config.displayName,
|
|
188
|
-
description: config.description,
|
|
189
|
-
...config.collapsedByDefault !== void 0 && {
|
|
190
|
-
collapsedByDefault: config.collapsedByDefault
|
|
191
|
-
},
|
|
192
|
-
ai: config.ai,
|
|
193
|
-
fields: config.fields
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
chunkMWMSFIWN_cjs.__name(fieldset, "fieldset");
|
|
197
|
-
function defineContentType(name, config) {
|
|
198
|
-
return {
|
|
199
|
-
_tag: "contentType",
|
|
200
|
-
name,
|
|
201
|
-
displayName: config.displayName,
|
|
202
|
-
displayNamePlural: config.displayNamePlural,
|
|
203
|
-
description: config.description,
|
|
204
|
-
ai: config.ai,
|
|
205
|
-
displayField: config.displayField,
|
|
206
|
-
// Written only when given: it was `false` whenever not, so the same content type was one
|
|
207
|
-
// definition from YAML and another from TypeScript, with a different schemaHash (REL-1458)
|
|
208
|
-
...config.hierarchical !== void 0 && { hierarchical: config.hierarchical },
|
|
209
|
-
...config.accessTags !== void 0 && { accessTags: config.accessTags },
|
|
210
|
-
...config.workflow !== void 0 && { workflow: config.workflow },
|
|
211
|
-
fields: config.fields
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
chunkMWMSFIWN_cjs.__name(defineContentType, "defineContentType");
|
|
215
|
-
|
|
216
593
|
// src/schema/define-singleton.ts
|
|
217
|
-
function
|
|
594
|
+
function defineSingleton(config) {
|
|
595
|
+
if (typeof config === "string") throw idFormRemoved("defineSingleton", config);
|
|
218
596
|
return {
|
|
219
597
|
_tag: "singletonContentType",
|
|
220
|
-
|
|
221
|
-
displayName: config.displayName,
|
|
222
|
-
displayNamePlural: config.displayNamePlural,
|
|
223
|
-
description: config.description,
|
|
224
|
-
ai: config.ai,
|
|
225
|
-
displayField: config.displayField,
|
|
598
|
+
...keyedSettings(config),
|
|
226
599
|
// Written only when given, as a content type's is (REL-1458)
|
|
227
600
|
...config.hierarchical !== void 0 && { hierarchical: config.hierarchical },
|
|
228
|
-
|
|
229
|
-
// Its config type took `workflow` and this dropped it, so a singleton's workflow never deployed
|
|
230
|
-
...config.workflow !== void 0 && { workflow: config.workflow },
|
|
231
|
-
fields: config.fields
|
|
601
|
+
fields: compileKeyedMembers(config.fields)
|
|
232
602
|
};
|
|
233
603
|
}
|
|
234
|
-
chunkMWMSFIWN_cjs.__name(
|
|
235
|
-
var defineSingleton = defineSingletonContentType;
|
|
604
|
+
chunkMWMSFIWN_cjs.__name(defineSingleton, "defineSingleton");
|
|
236
605
|
|
|
237
606
|
// src/schema/define-settings-group.ts
|
|
238
|
-
function defineSettingsGroup(
|
|
607
|
+
function defineSettingsGroup(config) {
|
|
608
|
+
if (typeof config === "string") throw idFormRemoved("defineSettingsGroup", config);
|
|
239
609
|
return {
|
|
240
610
|
_tag: "settingsGroup",
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
ai: config.ai,
|
|
611
|
+
...config.displayName !== void 0 && { displayName: config.displayName },
|
|
612
|
+
...config.description !== void 0 && { description: config.description },
|
|
613
|
+
...config.ai !== void 0 && { ai: config.ai },
|
|
245
614
|
...config.accessTags !== void 0 && { accessTags: config.accessTags },
|
|
246
|
-
fields: config.fields
|
|
615
|
+
fields: compileKeyedFields(config.fields)
|
|
247
616
|
};
|
|
248
617
|
}
|
|
249
618
|
chunkMWMSFIWN_cjs.__name(defineSettingsGroup, "defineSettingsGroup");
|
|
250
619
|
|
|
251
620
|
// src/schema/define-asset-type.ts
|
|
252
|
-
function
|
|
621
|
+
function refuseKindKeys(config, what) {
|
|
253
622
|
const kindKeys = ["image", "video", "file"].filter((k) => config[k] !== void 0);
|
|
254
623
|
if (kindKeys.length === 0) {
|
|
255
|
-
throw new Error(
|
|
624
|
+
throw new Error(`${what} must declare exactly one kind key: image, video, or file`);
|
|
256
625
|
}
|
|
257
626
|
if (kindKeys.length > 1) {
|
|
258
627
|
throw new Error(
|
|
259
|
-
|
|
628
|
+
`${what} declares multiple kind keys (${kindKeys.join(", ")}); exactly one is allowed`
|
|
260
629
|
);
|
|
261
630
|
}
|
|
631
|
+
}
|
|
632
|
+
chunkMWMSFIWN_cjs.__name(refuseKindKeys, "refuseKindKeys");
|
|
633
|
+
function defineAssetType(config) {
|
|
634
|
+
if (typeof config === "string") throw idFormRemoved("defineAssetType", config);
|
|
635
|
+
refuseKindKeys(config, "An asset type");
|
|
262
636
|
return {
|
|
263
637
|
_tag: "assetType",
|
|
264
|
-
|
|
265
|
-
displayName: config.displayName,
|
|
266
|
-
displayNamePlural: config.displayNamePlural,
|
|
267
|
-
description: config.description,
|
|
268
|
-
ai: config.ai,
|
|
269
|
-
displayField: config.displayField,
|
|
270
|
-
// An empty list too, as a content type's and a settings group's are kept (REL-1457, REL-1458)
|
|
271
|
-
...config.accessTags !== void 0 && { accessTags: config.accessTags },
|
|
272
|
-
...config.workflow !== void 0 && { workflow: config.workflow },
|
|
638
|
+
...keyedSettings(config),
|
|
273
639
|
...config.image !== void 0 && { image: config.image },
|
|
274
640
|
...config.video !== void 0 && { video: config.video },
|
|
275
641
|
...config.file !== void 0 && { file: config.file },
|
|
276
|
-
...config.fields !== void 0 && { fields: config.fields }
|
|
642
|
+
...config.fields !== void 0 && { fields: compileKeyedMembers(config.fields) }
|
|
277
643
|
};
|
|
278
644
|
}
|
|
279
645
|
chunkMWMSFIWN_cjs.__name(defineAssetType, "defineAssetType");
|
|
280
646
|
|
|
281
|
-
// src/schema/define-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
"
|
|
285
|
-
"read",
|
|
286
|
-
"update",
|
|
287
|
-
"delete",
|
|
288
|
-
"publish",
|
|
289
|
-
"unpublish",
|
|
290
|
-
"duplicate",
|
|
291
|
-
"comment",
|
|
292
|
-
"approveElevated"
|
|
293
|
-
];
|
|
294
|
-
var BUILT_IN_ROLE_ACTIONS = {
|
|
295
|
-
admin: ["create", "read", "update", "delete", "publish", "unpublish", "duplicate", "comment"],
|
|
296
|
-
editor: ["create", "read", "update", "delete", "publish", "unpublish", "duplicate", "comment"],
|
|
297
|
-
viewer: ["read", "comment"]
|
|
298
|
-
};
|
|
299
|
-
function defineRole(id, config) {
|
|
300
|
-
if (!id || id.length === 0) {
|
|
301
|
-
throw new Error("Role ID is required");
|
|
302
|
-
}
|
|
303
|
-
const roleIdPattern = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$|^[a-z][a-zA-Z0-9]*$/;
|
|
304
|
-
if (!roleIdPattern.test(id)) {
|
|
305
|
-
throw new Error(
|
|
306
|
-
`Role ID '${id}' must be kebab-case (e.g., blog-editor) or camelCase (e.g., blogEditor)`
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
if (BUILT_IN_ROLES.includes(id)) {
|
|
310
|
-
throw new Error(`Role ID '${id}' cannot use a built-in role name (admin, editor, viewer)`);
|
|
311
|
-
}
|
|
312
|
-
if (!config.displayName || config.displayName.length === 0) {
|
|
313
|
-
throw new Error("Role displayName is required");
|
|
314
|
-
}
|
|
315
|
-
const hasBaseRole = config.baseRole !== void 0;
|
|
316
|
-
const hasIncludes = Array.isArray(config.includes) && config.includes.length > 0;
|
|
317
|
-
const hasPermissions = Array.isArray(config.permissions) && config.permissions.length > 0;
|
|
318
|
-
const hasHiddenFields = config.fields !== void 0 && Array.isArray(config.fields.hidden) && config.fields.hidden.length > 0;
|
|
319
|
-
const hasReadonlyFields = config.fields !== void 0 && Array.isArray(config.fields.readonly) && config.fields.readonly.length > 0;
|
|
320
|
-
const hasFields = hasHiddenFields || hasReadonlyFields;
|
|
321
|
-
if (!hasBaseRole && !hasIncludes && !hasPermissions && !hasFields) {
|
|
322
|
-
throw new Error(
|
|
323
|
-
`Role '${id}' must have at least one of: 'baseRole', 'includes', or permissions (with tags/actions or fields)`
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
if (Array.isArray(config.permissions) && config.permissions.length > 0) {
|
|
327
|
-
for (const perm of config.permissions) {
|
|
328
|
-
if (perm.tags.length === 0) {
|
|
329
|
-
throw new Error(`Permission in role '${id}' must have at least one tag`);
|
|
330
|
-
}
|
|
331
|
-
if (perm.actions.length === 0) {
|
|
332
|
-
throw new Error(`Permission in role '${id}' must have at least one action`);
|
|
333
|
-
}
|
|
334
|
-
for (const action of perm.actions) {
|
|
335
|
-
if (!ROLE_ACTIONS.includes(action)) {
|
|
336
|
-
throw new Error(
|
|
337
|
-
`Invalid action '${action}' in role '${id}'. Valid actions: ${ROLE_ACTIONS.join(", ")}`
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return {
|
|
344
|
-
_tag: "role",
|
|
345
|
-
id,
|
|
346
|
-
displayName: config.displayName,
|
|
347
|
-
...config.description !== void 0 && { description: config.description },
|
|
348
|
-
...config.baseRole !== void 0 && { baseRole: config.baseRole },
|
|
349
|
-
...config.includes !== void 0 && { includes: config.includes },
|
|
350
|
-
...config.permissions !== void 0 && { permissions: config.permissions },
|
|
351
|
-
...config.fields !== void 0 && { fields: config.fields }
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
chunkMWMSFIWN_cjs.__name(defineRole, "defineRole");
|
|
355
|
-
function isRoleDefinition(value) {
|
|
356
|
-
return typeof value === "object" && value !== null && "_tag" in value && value._tag === "role";
|
|
357
|
-
}
|
|
358
|
-
chunkMWMSFIWN_cjs.__name(isRoleDefinition, "isRoleDefinition");
|
|
359
|
-
function isBuiltInRole(roleId) {
|
|
360
|
-
return BUILT_IN_ROLES.includes(roleId);
|
|
647
|
+
// src/schema/define-workflow.ts
|
|
648
|
+
function defineWorkflowStage(config) {
|
|
649
|
+
if (typeof config === "string") throw idFormRemoved("defineWorkflowStage", config);
|
|
650
|
+
return { ...config, _tag: "keyedWorkflowStage" };
|
|
361
651
|
}
|
|
362
|
-
chunkMWMSFIWN_cjs.__name(
|
|
363
|
-
function
|
|
364
|
-
|
|
652
|
+
chunkMWMSFIWN_cjs.__name(defineWorkflowStage, "defineWorkflowStage");
|
|
653
|
+
function compileKeyedStages(stages) {
|
|
654
|
+
const seen = /* @__PURE__ */ new Map();
|
|
655
|
+
return Object.entries(stages).map(([id, stage]) => {
|
|
656
|
+
if (!isKeyed(stage, "keyedWorkflowStage")) {
|
|
657
|
+
throw new Error(
|
|
658
|
+
`Workflow stage '${id}' is not written in the keyed form: under a key, write it without an id, as defineWorkflowStage({ \u2026 })`
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
const first = seen.get(stage);
|
|
662
|
+
if (first !== void 0) {
|
|
663
|
+
throw new Error(
|
|
664
|
+
`One stage is registered under two keys, '${first}' and '${id}': each key is a stage of its own, so give each key its own defineWorkflowStage({ \u2026 })`
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
seen.set(stage, id);
|
|
668
|
+
const { _tag: _keyed, displayName, ...config } = stage;
|
|
669
|
+
return stageDefinition(id, { ...config, displayName: displayName ?? labelFromKey(id) });
|
|
670
|
+
});
|
|
365
671
|
}
|
|
366
|
-
chunkMWMSFIWN_cjs.__name(
|
|
367
|
-
|
|
368
|
-
// src/schema/define-workflow.ts
|
|
369
|
-
function defineWorkflowStage(id, config) {
|
|
672
|
+
chunkMWMSFIWN_cjs.__name(compileKeyedStages, "compileKeyedStages");
|
|
673
|
+
function stageDefinition(id, config) {
|
|
370
674
|
if (!id || id.length === 0) {
|
|
371
675
|
throw new Error("Workflow stage ID is required");
|
|
372
676
|
}
|
|
@@ -413,10 +717,16 @@ function defineWorkflowStage(id, config) {
|
|
|
413
717
|
...config.escalation !== void 0 && { escalation: config.escalation }
|
|
414
718
|
};
|
|
415
719
|
}
|
|
416
|
-
chunkMWMSFIWN_cjs.__name(
|
|
720
|
+
chunkMWMSFIWN_cjs.__name(stageDefinition, "stageDefinition");
|
|
417
721
|
function defineWorkflow(config) {
|
|
722
|
+
if (config.stages !== void 0 && isList(config.stages)) {
|
|
723
|
+
throw new Error(
|
|
724
|
+
"defineWorkflow takes its stages as a record keyed by stage id, in the order content moves through them: the list form was removed in 0.14 \u2014 write stages: { review: defineWorkflowStage({ \u2026 }) }"
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
const stages = config.stages === void 0 ? void 0 : compileKeyedStages(config.stages);
|
|
418
728
|
const stageIds = /* @__PURE__ */ new Set();
|
|
419
|
-
for (const stage of
|
|
729
|
+
for (const stage of stages ?? []) {
|
|
420
730
|
if (stageIds.has(stage.id)) {
|
|
421
731
|
throw new Error(`Duplicate workflow stage ID '${stage.id}'`);
|
|
422
732
|
}
|
|
@@ -425,7 +735,7 @@ function defineWorkflow(config) {
|
|
|
425
735
|
return {
|
|
426
736
|
_tag: "workflow",
|
|
427
737
|
...config.enabled !== void 0 && { enabled: config.enabled },
|
|
428
|
-
...
|
|
738
|
+
...stages !== void 0 && { stages }
|
|
429
739
|
};
|
|
430
740
|
}
|
|
431
741
|
chunkMWMSFIWN_cjs.__name(defineWorkflow, "defineWorkflow");
|
|
@@ -484,45 +794,9 @@ function isFinalWorkflowStage(workflow, stageId) {
|
|
|
484
794
|
}
|
|
485
795
|
chunkMWMSFIWN_cjs.__name(isFinalWorkflowStage, "isFinalWorkflowStage");
|
|
486
796
|
|
|
487
|
-
// src/schema/define-view.ts
|
|
488
|
-
function defineView(id, config) {
|
|
489
|
-
if (!id.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) {
|
|
490
|
-
throw new Error(
|
|
491
|
-
`View ID '${id}' must start with a letter and contain only letters, numbers, underscores, and hyphens`
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
if (!config.name || config.name.length === 0) {
|
|
495
|
-
throw new Error(`View '${id}' must have a name`);
|
|
496
|
-
}
|
|
497
|
-
if (config.metadataFields && config.metadataFields.length > 3) {
|
|
498
|
-
throw new Error(`View '${id}' can have at most 3 metadata fields`);
|
|
499
|
-
}
|
|
500
|
-
if (!config.scope?.type) {
|
|
501
|
-
throw new Error(`View '${id}' must have a valid scope`);
|
|
502
|
-
}
|
|
503
|
-
const grouped = (config.filters ?? []).findIndex(
|
|
504
|
-
(filter) => typeof filter === "object" && filter !== null && "conditions" in filter
|
|
505
|
-
);
|
|
506
|
-
if (grouped !== -1) {
|
|
507
|
-
throw new Error(
|
|
508
|
-
`View '${id}' filter ${grouped} is a filter group: a view's filters are a flat list, joined by AND. List each of its conditions as a filter of its own, or use 'isAnyOf' for an OR within one field.`
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
if (config.slug !== void 0 && !/^[a-z][a-z0-9-]*$/.test(config.slug)) {
|
|
512
|
-
throw new Error(
|
|
513
|
-
`View '${id}' slug '${config.slug}' must be lowercase, start with a letter, and contain only letters, numbers, and hyphens`
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
return {
|
|
517
|
-
_tag: "view",
|
|
518
|
-
id,
|
|
519
|
-
...config
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
chunkMWMSFIWN_cjs.__name(defineView, "defineView");
|
|
523
|
-
|
|
524
797
|
// src/schema/define-query.ts
|
|
525
|
-
function defineQuery(
|
|
798
|
+
function defineQuery(config) {
|
|
799
|
+
if (typeof config === "string") throw idFormRemoved("defineQuery", config);
|
|
526
800
|
if (!config.fetch && !config.aggregate && !config.search) {
|
|
527
801
|
throw new Error("Query must have at least one of: fetch, aggregate or search");
|
|
528
802
|
}
|
|
@@ -531,7 +805,6 @@ function defineQuery(name, config) {
|
|
|
531
805
|
}
|
|
532
806
|
return {
|
|
533
807
|
_tag: "query",
|
|
534
|
-
name,
|
|
535
808
|
type: config.type,
|
|
536
809
|
endpoint: config.endpoint,
|
|
537
810
|
description: config.description,
|
|
@@ -574,95 +847,100 @@ chunkMWMSFIWN_cjs.__export(fields_exports, {
|
|
|
574
847
|
});
|
|
575
848
|
|
|
576
849
|
// src/schema/fields/builders.ts
|
|
577
|
-
function
|
|
578
|
-
return
|
|
579
|
-
id,
|
|
580
|
-
type,
|
|
581
|
-
...options.config !== void 0 && { config: options.config },
|
|
582
|
-
...options.ui !== void 0 && { ui: options.ui },
|
|
583
|
-
...options.ai !== void 0 && { ai: options.ai },
|
|
584
|
-
// An empty list too: dropping it made a YAML field and a TypeScript one two definitions (REL-1458)
|
|
585
|
-
...options.rules !== void 0 && { rules: options.rules },
|
|
586
|
-
...options.localization !== void 0 && { localization: options.localization },
|
|
587
|
-
...options.fallback !== void 0 && { fallback: options.fallback },
|
|
588
|
-
...options.deprecated !== void 0 && { deprecated: options.deprecated }
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
chunkMWMSFIWN_cjs.__name(createField, "createField");
|
|
592
|
-
function shortText(id, options = {}) {
|
|
593
|
-
return createField(id, "shortText", options);
|
|
850
|
+
function shortText(options = {}) {
|
|
851
|
+
return keyedField("shortText", options);
|
|
594
852
|
}
|
|
595
853
|
chunkMWMSFIWN_cjs.__name(shortText, "shortText");
|
|
596
|
-
function longText(
|
|
597
|
-
return
|
|
854
|
+
function longText(options = {}) {
|
|
855
|
+
return keyedField("longText", options);
|
|
598
856
|
}
|
|
599
857
|
chunkMWMSFIWN_cjs.__name(longText, "longText");
|
|
600
|
-
function richText(
|
|
601
|
-
return
|
|
858
|
+
function richText(options = {}) {
|
|
859
|
+
return keyedField("richText", options);
|
|
602
860
|
}
|
|
603
861
|
chunkMWMSFIWN_cjs.__name(richText, "richText");
|
|
604
|
-
function table(
|
|
605
|
-
return
|
|
862
|
+
function table(options = {}) {
|
|
863
|
+
return keyedField("table", options);
|
|
606
864
|
}
|
|
607
865
|
chunkMWMSFIWN_cjs.__name(table, "table");
|
|
608
|
-
function code(
|
|
609
|
-
return
|
|
866
|
+
function code(options = {}) {
|
|
867
|
+
return keyedField("code", options);
|
|
610
868
|
}
|
|
611
869
|
chunkMWMSFIWN_cjs.__name(code, "code");
|
|
612
|
-
function slug(
|
|
613
|
-
return
|
|
870
|
+
function slug(options = {}) {
|
|
871
|
+
return keyedField("slug", options);
|
|
614
872
|
}
|
|
615
873
|
chunkMWMSFIWN_cjs.__name(slug, "slug");
|
|
616
|
-
function url(
|
|
617
|
-
return
|
|
874
|
+
function url(options = {}) {
|
|
875
|
+
return keyedField("url", options);
|
|
618
876
|
}
|
|
619
877
|
chunkMWMSFIWN_cjs.__name(url, "url");
|
|
620
|
-
function email(
|
|
621
|
-
return
|
|
878
|
+
function email(options = {}) {
|
|
879
|
+
return keyedField("email", options);
|
|
622
880
|
}
|
|
623
881
|
chunkMWMSFIWN_cjs.__name(email, "email");
|
|
624
|
-
function integer(
|
|
625
|
-
return
|
|
882
|
+
function integer(options = {}) {
|
|
883
|
+
return keyedField("integer", options);
|
|
626
884
|
}
|
|
627
885
|
chunkMWMSFIWN_cjs.__name(integer, "integer");
|
|
628
|
-
function decimal(
|
|
629
|
-
return
|
|
886
|
+
function decimal(options = {}) {
|
|
887
|
+
return keyedField("decimal", options);
|
|
630
888
|
}
|
|
631
889
|
chunkMWMSFIWN_cjs.__name(decimal, "decimal");
|
|
632
|
-
function boolean(
|
|
633
|
-
return
|
|
890
|
+
function boolean(options = {}) {
|
|
891
|
+
return keyedField("boolean", options);
|
|
634
892
|
}
|
|
635
893
|
chunkMWMSFIWN_cjs.__name(boolean, "boolean");
|
|
636
|
-
function
|
|
637
|
-
|
|
894
|
+
function enumOptionsList(options) {
|
|
895
|
+
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
896
|
+
throw new Error(
|
|
897
|
+
"An enum's options in the keyed form are a value-to-label map, { draft: 'Draft', live: 'Live' }, in the order the editor shows them"
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
return Object.entries(options).map(([value, label]) => {
|
|
901
|
+
if (/^(0|[1-9]\d*)$/.test(value)) {
|
|
902
|
+
throw new Error(
|
|
903
|
+
`An enum option's value '${value}' is a whole number, which a value-to-label map cannot keep in the order it was written: JavaScript orders such keys first`
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
if (typeof label !== "string") {
|
|
907
|
+
throw new Error(`An enum option's label must be a string: '${value}' has ${String(label)}`);
|
|
908
|
+
}
|
|
909
|
+
return { value, label };
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
chunkMWMSFIWN_cjs.__name(enumOptionsList, "enumOptionsList");
|
|
913
|
+
function enumField(options) {
|
|
914
|
+
const written = options;
|
|
915
|
+
return keyedField("enum", { ...written, options: enumOptionsList(written.options) });
|
|
638
916
|
}
|
|
639
917
|
chunkMWMSFIWN_cjs.__name(enumField, "enumField");
|
|
640
|
-
function date(
|
|
641
|
-
return
|
|
918
|
+
function date(options = {}) {
|
|
919
|
+
return keyedField("date", options);
|
|
642
920
|
}
|
|
643
921
|
chunkMWMSFIWN_cjs.__name(date, "date");
|
|
644
|
-
function dateTime(
|
|
645
|
-
return
|
|
922
|
+
function dateTime(options = {}) {
|
|
923
|
+
return keyedField("dateTime", options);
|
|
646
924
|
}
|
|
647
925
|
chunkMWMSFIWN_cjs.__name(dateTime, "dateTime");
|
|
648
|
-
function reference(
|
|
649
|
-
return
|
|
926
|
+
function reference(options) {
|
|
927
|
+
return keyedField("reference", options);
|
|
650
928
|
}
|
|
651
929
|
chunkMWMSFIWN_cjs.__name(reference, "reference");
|
|
652
|
-
function tags(
|
|
653
|
-
return
|
|
930
|
+
function tags(options = {}) {
|
|
931
|
+
return keyedField("tags", options);
|
|
654
932
|
}
|
|
655
933
|
chunkMWMSFIWN_cjs.__name(tags, "tags");
|
|
656
|
-
function list(
|
|
657
|
-
return
|
|
934
|
+
function list(options = {}) {
|
|
935
|
+
return keyedField("list", options);
|
|
658
936
|
}
|
|
659
937
|
chunkMWMSFIWN_cjs.__name(list, "list");
|
|
660
|
-
function object(
|
|
661
|
-
return
|
|
938
|
+
function object(options) {
|
|
939
|
+
return keyedField("object", options);
|
|
662
940
|
}
|
|
663
941
|
chunkMWMSFIWN_cjs.__name(object, "object");
|
|
664
|
-
function json(
|
|
665
|
-
return
|
|
942
|
+
function json(options = {}) {
|
|
943
|
+
return keyedField("json", options);
|
|
666
944
|
}
|
|
667
945
|
chunkMWMSFIWN_cjs.__name(json, "json");
|
|
668
946
|
|
|
@@ -682,7 +960,6 @@ exports.defineRole = defineRole;
|
|
|
682
960
|
exports.defineSchema = defineSchema;
|
|
683
961
|
exports.defineSettingsGroup = defineSettingsGroup;
|
|
684
962
|
exports.defineSingleton = defineSingleton;
|
|
685
|
-
exports.defineSingletonContentType = defineSingletonContentType;
|
|
686
963
|
exports.defineView = defineView;
|
|
687
964
|
exports.defineWorkflow = defineWorkflow;
|
|
688
965
|
exports.defineWorkflowStage = defineWorkflowStage;
|
|
@@ -702,5 +979,5 @@ exports.isLocaleDefinition = isLocaleDefinition;
|
|
|
702
979
|
exports.isRoleDefinition = isRoleDefinition;
|
|
703
980
|
exports.isWorkflowDefinition = isWorkflowDefinition;
|
|
704
981
|
exports.isWorkflowStageDefinition = isWorkflowStageDefinition;
|
|
705
|
-
//# sourceMappingURL=chunk-
|
|
706
|
-
//# sourceMappingURL=chunk-
|
|
982
|
+
//# sourceMappingURL=chunk-X4KSS7PP.cjs.map
|
|
983
|
+
//# sourceMappingURL=chunk-X4KSS7PP.cjs.map
|