@cms0/cms0 0.2.7 → 0.2.9
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/README.md +28 -3
- package/dist/cjs/custom-types/registry.cjs +250 -5
- package/dist/cjs/index.cjs +342 -18
- package/dist/cjs/libs/cli/descriptor-builder-alt.cjs +237 -5
- package/dist/cjs/seo.cjs +226 -0
- package/dist/esm/custom-types/registry.js +250 -5
- package/dist/esm/index.js +338 -19
- package/dist/esm/libs/cli/descriptor-builder-alt.js +237 -5
- package/dist/esm/seo.js +220 -0
- package/dist/types/custom-types/index.d.ts +38 -0
- package/dist/types/custom-types/index.d.ts.map +1 -1
- package/dist/types/custom-types/registry.d.ts +19 -1
- package/dist/types/custom-types/registry.d.ts.map +1 -1
- package/dist/types/index.d.ts +39 -13
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/libs/cli/descriptor-builder-alt.d.ts.map +1 -1
- package/dist/types/seo.d.ts +18 -0
- package/dist/types/seo.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { computeUnionBranchKeys, } from "@cms0/shared";
|
|
1
2
|
const primitive = (type) => ({
|
|
2
3
|
kind: "primitive",
|
|
3
4
|
type,
|
|
@@ -49,6 +50,237 @@ const localizedRichTextDescriptor = {
|
|
|
49
50
|
type: "json",
|
|
50
51
|
customType: "LocalizedRichText",
|
|
51
52
|
};
|
|
53
|
+
function createUnionDescriptor(branches) {
|
|
54
|
+
return {
|
|
55
|
+
kind: "union",
|
|
56
|
+
anyOf: branches,
|
|
57
|
+
branchKeys: computeUnionBranchKeys(branches),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const localizedOrStringDescriptor = createUnionDescriptor([
|
|
61
|
+
localizedStringDescriptor,
|
|
62
|
+
{
|
|
63
|
+
kind: "primitive",
|
|
64
|
+
type: "string",
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
const keywordsDescriptor = createUnionDescriptor([
|
|
68
|
+
localizedStringDescriptor,
|
|
69
|
+
{
|
|
70
|
+
type: "array",
|
|
71
|
+
items: {
|
|
72
|
+
kind: "primitive",
|
|
73
|
+
type: "string",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
const robotsDescriptor = createUnionDescriptor([
|
|
78
|
+
{
|
|
79
|
+
kind: "primitive",
|
|
80
|
+
type: "boolean",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: "object",
|
|
84
|
+
properties: {
|
|
85
|
+
index: {
|
|
86
|
+
kind: "primitive",
|
|
87
|
+
type: "boolean",
|
|
88
|
+
optional: true,
|
|
89
|
+
nullable: false,
|
|
90
|
+
},
|
|
91
|
+
follow: {
|
|
92
|
+
kind: "primitive",
|
|
93
|
+
type: "boolean",
|
|
94
|
+
optional: true,
|
|
95
|
+
nullable: false,
|
|
96
|
+
},
|
|
97
|
+
nocache: {
|
|
98
|
+
kind: "primitive",
|
|
99
|
+
type: "boolean",
|
|
100
|
+
optional: true,
|
|
101
|
+
nullable: false,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
const alternatesDescriptor = {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
canonical: {
|
|
110
|
+
kind: "primitive",
|
|
111
|
+
type: "string",
|
|
112
|
+
optional: true,
|
|
113
|
+
nullable: false,
|
|
114
|
+
},
|
|
115
|
+
languages: {
|
|
116
|
+
kind: "primitive",
|
|
117
|
+
type: "json",
|
|
118
|
+
optional: true,
|
|
119
|
+
nullable: false,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
const imageOrStringDescriptor = createUnionDescriptor([
|
|
124
|
+
{
|
|
125
|
+
kind: "modelRef",
|
|
126
|
+
model: "Image",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
kind: "primitive",
|
|
130
|
+
type: "string",
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
const openGraphDescriptor = {
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: {
|
|
136
|
+
type: {
|
|
137
|
+
kind: "enum",
|
|
138
|
+
valueType: "string",
|
|
139
|
+
values: ["website", "article", "profile"],
|
|
140
|
+
optional: true,
|
|
141
|
+
nullable: false,
|
|
142
|
+
},
|
|
143
|
+
url: {
|
|
144
|
+
kind: "primitive",
|
|
145
|
+
type: "string",
|
|
146
|
+
optional: true,
|
|
147
|
+
nullable: false,
|
|
148
|
+
},
|
|
149
|
+
siteName: {
|
|
150
|
+
kind: "primitive",
|
|
151
|
+
type: "string",
|
|
152
|
+
optional: true,
|
|
153
|
+
nullable: false,
|
|
154
|
+
},
|
|
155
|
+
title: {
|
|
156
|
+
...localizedOrStringDescriptor,
|
|
157
|
+
optional: true,
|
|
158
|
+
nullable: false,
|
|
159
|
+
},
|
|
160
|
+
description: {
|
|
161
|
+
...localizedOrStringDescriptor,
|
|
162
|
+
optional: true,
|
|
163
|
+
nullable: false,
|
|
164
|
+
},
|
|
165
|
+
images: {
|
|
166
|
+
type: "array",
|
|
167
|
+
items: imageOrStringDescriptor,
|
|
168
|
+
optional: true,
|
|
169
|
+
nullable: false,
|
|
170
|
+
},
|
|
171
|
+
locale: {
|
|
172
|
+
kind: "primitive",
|
|
173
|
+
type: "string",
|
|
174
|
+
optional: true,
|
|
175
|
+
nullable: false,
|
|
176
|
+
},
|
|
177
|
+
alternateLocale: {
|
|
178
|
+
type: "array",
|
|
179
|
+
items: {
|
|
180
|
+
kind: "primitive",
|
|
181
|
+
type: "string",
|
|
182
|
+
},
|
|
183
|
+
optional: true,
|
|
184
|
+
nullable: false,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
const twitterDescriptor = {
|
|
189
|
+
type: "object",
|
|
190
|
+
properties: {
|
|
191
|
+
card: {
|
|
192
|
+
kind: "enum",
|
|
193
|
+
valueType: "string",
|
|
194
|
+
values: ["summary", "summary_large_image", "app", "player"],
|
|
195
|
+
optional: true,
|
|
196
|
+
nullable: false,
|
|
197
|
+
},
|
|
198
|
+
site: {
|
|
199
|
+
kind: "primitive",
|
|
200
|
+
type: "string",
|
|
201
|
+
optional: true,
|
|
202
|
+
nullable: false,
|
|
203
|
+
},
|
|
204
|
+
creator: {
|
|
205
|
+
kind: "primitive",
|
|
206
|
+
type: "string",
|
|
207
|
+
optional: true,
|
|
208
|
+
nullable: false,
|
|
209
|
+
},
|
|
210
|
+
title: {
|
|
211
|
+
...localizedOrStringDescriptor,
|
|
212
|
+
optional: true,
|
|
213
|
+
nullable: false,
|
|
214
|
+
},
|
|
215
|
+
description: {
|
|
216
|
+
...localizedOrStringDescriptor,
|
|
217
|
+
optional: true,
|
|
218
|
+
nullable: false,
|
|
219
|
+
},
|
|
220
|
+
images: {
|
|
221
|
+
type: "array",
|
|
222
|
+
items: imageOrStringDescriptor,
|
|
223
|
+
optional: true,
|
|
224
|
+
nullable: false,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
const seoDescriptor = {
|
|
229
|
+
type: "object",
|
|
230
|
+
customType: "Seo",
|
|
231
|
+
properties: {
|
|
232
|
+
title: {
|
|
233
|
+
...localizedOrStringDescriptor,
|
|
234
|
+
optional: true,
|
|
235
|
+
nullable: false,
|
|
236
|
+
},
|
|
237
|
+
description: {
|
|
238
|
+
...localizedOrStringDescriptor,
|
|
239
|
+
optional: true,
|
|
240
|
+
nullable: false,
|
|
241
|
+
},
|
|
242
|
+
keywords: {
|
|
243
|
+
...keywordsDescriptor,
|
|
244
|
+
optional: true,
|
|
245
|
+
nullable: false,
|
|
246
|
+
},
|
|
247
|
+
canonical: {
|
|
248
|
+
kind: "primitive",
|
|
249
|
+
type: "string",
|
|
250
|
+
optional: true,
|
|
251
|
+
nullable: false,
|
|
252
|
+
},
|
|
253
|
+
robots: {
|
|
254
|
+
...robotsDescriptor,
|
|
255
|
+
optional: true,
|
|
256
|
+
nullable: false,
|
|
257
|
+
},
|
|
258
|
+
alternates: {
|
|
259
|
+
...alternatesDescriptor,
|
|
260
|
+
optional: true,
|
|
261
|
+
nullable: false,
|
|
262
|
+
},
|
|
263
|
+
openGraph: {
|
|
264
|
+
...openGraphDescriptor,
|
|
265
|
+
optional: true,
|
|
266
|
+
nullable: false,
|
|
267
|
+
},
|
|
268
|
+
twitter: {
|
|
269
|
+
...twitterDescriptor,
|
|
270
|
+
optional: true,
|
|
271
|
+
nullable: false,
|
|
272
|
+
},
|
|
273
|
+
jsonLd: {
|
|
274
|
+
type: "array",
|
|
275
|
+
items: {
|
|
276
|
+
kind: "primitive",
|
|
277
|
+
type: "json",
|
|
278
|
+
},
|
|
279
|
+
optional: true,
|
|
280
|
+
nullable: false,
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
};
|
|
52
284
|
export const customModelDescriptors = {
|
|
53
285
|
File: fileDescriptor,
|
|
54
286
|
Image: imageDescriptor,
|
|
@@ -58,6 +290,7 @@ export const customInlineDescriptors = {
|
|
|
58
290
|
RichText: richTextDescriptor,
|
|
59
291
|
LocalizedString: localizedStringDescriptor,
|
|
60
292
|
LocalizedRichText: localizedRichTextDescriptor,
|
|
293
|
+
Seo: seoDescriptor,
|
|
61
294
|
};
|
|
62
295
|
export const customInlineTypeMetadata = {
|
|
63
296
|
RichText: {},
|
|
@@ -67,6 +300,7 @@ export const customInlineTypeMetadata = {
|
|
|
67
300
|
LocalizedRichText: {
|
|
68
301
|
includeId: { mapLikeFields: ["locales"] },
|
|
69
302
|
},
|
|
303
|
+
Seo: {},
|
|
70
304
|
};
|
|
71
305
|
export const customTypeDescriptors = {
|
|
72
306
|
...customModelDescriptors,
|
|
@@ -85,13 +319,20 @@ export function resolveCustomTypeDependencies(names) {
|
|
|
85
319
|
const name = queue.shift();
|
|
86
320
|
if (!name || resolved.has(name))
|
|
87
321
|
continue;
|
|
88
|
-
const
|
|
322
|
+
const modelDescriptor = customModelDescriptors[name];
|
|
323
|
+
const inlineDescriptor = customInlineDescriptors[name];
|
|
324
|
+
const descriptor = modelDescriptor ?? inlineDescriptor;
|
|
89
325
|
if (!descriptor)
|
|
90
326
|
continue;
|
|
91
327
|
resolved.add(name);
|
|
92
328
|
const refs = new Set();
|
|
93
|
-
|
|
94
|
-
|
|
329
|
+
if (modelDescriptor) {
|
|
330
|
+
for (const prop of Object.values(modelDescriptor.properties)) {
|
|
331
|
+
collectModelRefs(prop, refs);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
collectModelRefs(inlineDescriptor, refs);
|
|
95
336
|
}
|
|
96
337
|
refs.forEach((ref) => {
|
|
97
338
|
if (customTypeDescriptors[ref] && !resolved.has(ref)) {
|
|
@@ -106,11 +347,15 @@ function collectModelRefs(desc, out) {
|
|
|
106
347
|
out.add(desc.model);
|
|
107
348
|
return;
|
|
108
349
|
}
|
|
109
|
-
if (desc.type === "array") {
|
|
350
|
+
if ("type" in desc && desc.type === "array") {
|
|
110
351
|
collectModelRefs(desc.items, out);
|
|
111
352
|
return;
|
|
112
353
|
}
|
|
113
|
-
if (desc.type === "object") {
|
|
354
|
+
if ("type" in desc && desc.type === "object") {
|
|
114
355
|
Object.values(desc.properties).forEach((child) => collectModelRefs(child, out));
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (desc.kind === "union") {
|
|
359
|
+
desc.anyOf.forEach((branch) => collectModelRefs(branch, out));
|
|
115
360
|
}
|
|
116
361
|
}
|