@cms0/cms0 0.0.1 → 0.0.3

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 ADDED
@@ -0,0 +1,31 @@
1
+ # @cms0/cms0
2
+
3
+ Typed client + schema tooling for cms0.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @cms0/cms0
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { cms0 } from "@cms0/cms0";
15
+ import type { Image } from "@cms0/cms0/custom-types";
16
+
17
+ type RootSchema = {
18
+ images: Image[];
19
+ };
20
+
21
+ export const data = cms0<RootSchema>({
22
+ apiConfig: {
23
+ baseUrl: import.meta.env.VITE_CMS0_API_BASEURL,
24
+ key: import.meta.env.VITE_CMS0_API_KEY,
25
+ },
26
+ });
27
+ ```
28
+
29
+ ## Custom Types
30
+
31
+ See `CUSTOM_TYPES.md` for the built-in custom types you can reference.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.customInlineTypeNames = exports.customModelTypeNames = exports.customTypeNames = exports.customTypeDescriptors = exports.customInlineDescriptors = exports.customModelDescriptors = void 0;
4
+ exports.resolveCustomTypeDependencies = resolveCustomTypeDependencies;
5
+ const primitive = (type) => ({
6
+ kind: "primitive",
7
+ type,
8
+ optional: false,
9
+ nullable: false,
10
+ });
11
+ const fileFieldDescriptors = {
12
+ name: primitive("string"),
13
+ filename: primitive("string"),
14
+ extension: primitive("string"),
15
+ mimeType: primitive("string"),
16
+ size: primitive("number"),
17
+ };
18
+ const fileDescriptor = {
19
+ kind: "model",
20
+ properties: fileFieldDescriptors,
21
+ };
22
+ const imageDescriptor = {
23
+ kind: "model",
24
+ properties: {
25
+ ...fileFieldDescriptors,
26
+ width: primitive("number"),
27
+ height: primitive("number"),
28
+ alt: { kind: "primitive", type: "string", optional: true, nullable: false },
29
+ },
30
+ };
31
+ const videoDescriptor = {
32
+ kind: "model",
33
+ properties: {
34
+ ...fileFieldDescriptors,
35
+ width: primitive("number"),
36
+ height: primitive("number"),
37
+ length: primitive("number"),
38
+ alt: { kind: "primitive", type: "string", optional: true, nullable: false },
39
+ },
40
+ };
41
+ const richTextDescriptor = {
42
+ kind: "primitive",
43
+ type: "json",
44
+ customType: "RichText",
45
+ };
46
+ const localizedStringDescriptor = {
47
+ type: "array",
48
+ items: {
49
+ type: "object",
50
+ properties: {
51
+ locale: primitive("string"),
52
+ isDefault: primitive("boolean"),
53
+ value: primitive("string"),
54
+ },
55
+ },
56
+ customType: "LocalizedString",
57
+ };
58
+ const localizedRichTextDescriptor = {
59
+ type: "array",
60
+ items: {
61
+ type: "object",
62
+ properties: {
63
+ locale: primitive("string"),
64
+ isDefault: primitive("boolean"),
65
+ value: primitive("json"),
66
+ html: primitive("string"),
67
+ },
68
+ },
69
+ customType: "LocalizedRichText",
70
+ };
71
+ exports.customModelDescriptors = {
72
+ File: fileDescriptor,
73
+ Image: imageDescriptor,
74
+ Video: videoDescriptor,
75
+ };
76
+ exports.customInlineDescriptors = {
77
+ RichText: richTextDescriptor,
78
+ LocalizedString: localizedStringDescriptor,
79
+ LocalizedRichText: localizedRichTextDescriptor,
80
+ };
81
+ exports.customTypeDescriptors = {
82
+ ...exports.customModelDescriptors,
83
+ ...exports.customInlineDescriptors,
84
+ };
85
+ exports.customTypeNames = new Set(Object.keys(exports.customTypeDescriptors));
86
+ exports.customModelTypeNames = new Set(Object.keys(exports.customModelDescriptors));
87
+ exports.customInlineTypeNames = new Set(Object.keys(exports.customInlineDescriptors));
88
+ function resolveCustomTypeDependencies(names) {
89
+ const resolved = new Set();
90
+ const queue = Array.from(names);
91
+ while (queue.length) {
92
+ const name = queue.shift();
93
+ if (!name || resolved.has(name))
94
+ continue;
95
+ const descriptor = exports.customModelDescriptors[name];
96
+ if (!descriptor)
97
+ continue;
98
+ resolved.add(name);
99
+ const refs = new Set();
100
+ for (const prop of Object.values(descriptor.properties)) {
101
+ collectModelRefs(prop, refs);
102
+ }
103
+ refs.forEach((ref) => {
104
+ if (exports.customTypeDescriptors[ref] && !resolved.has(ref)) {
105
+ queue.push(ref);
106
+ }
107
+ });
108
+ }
109
+ return resolved;
110
+ }
111
+ function collectModelRefs(desc, out) {
112
+ if (desc.kind === "modelRef") {
113
+ out.add(desc.model);
114
+ return;
115
+ }
116
+ if (desc.type === "array") {
117
+ collectModelRefs(desc.items, out);
118
+ return;
119
+ }
120
+ if (desc.type === "object") {
121
+ Object.values(desc.properties).forEach((child) => collectModelRefs(child, out));
122
+ }
123
+ }
@@ -1,523 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schemaDescriptor = void 0;
4
- // Auto-generated schema descriptor
4
+ // Auto-generated fallback schema descriptor
5
5
  exports.schemaDescriptor = {
6
- "models": {
7
- "BlogPost": {
8
- "kind": "model",
9
- "properties": {
10
- "title": {
11
- "kind": "primitive",
12
- "type": "string",
13
- "optional": false,
14
- "nullable": false
15
- },
16
- "description": {
17
- "kind": "primitive",
18
- "type": "string",
19
- "optional": false,
20
- "nullable": false
21
- },
22
- "content": {
23
- "kind": "primitive",
24
- "type": "string",
25
- "optional": false,
26
- "nullable": false
27
- }
28
- }
29
- },
30
- "Author": {
31
- "kind": "model",
32
- "properties": {
33
- "profile": {
34
- "kind": "primitive",
35
- "type": "string",
36
- "optional": false,
37
- "nullable": false
38
- },
39
- "name": {
40
- "kind": "primitive",
41
- "type": "string",
42
- "optional": false,
43
- "nullable": false
44
- }
45
- }
46
- },
47
- "Testimonial": {
48
- "kind": "model",
49
- "properties": {
50
- "content": {
51
- "kind": "primitive",
52
- "type": "string",
53
- "optional": false,
54
- "nullable": false
55
- },
56
- "author": {
57
- "kind": "modelRef",
58
- "model": "Author",
59
- "optional": false,
60
- "nullable": false
61
- },
62
- "companies": {
63
- "type": "array",
64
- "items": {
65
- "type": "object",
66
- "properties": {
67
- "name": {
68
- "kind": "primitive",
69
- "type": "string",
70
- "optional": false,
71
- "nullable": false
72
- },
73
- "value": {
74
- "kind": "primitive",
75
- "type": "number",
76
- "optional": false,
77
- "nullable": false
78
- }
79
- },
80
- "optional": false,
81
- "nullable": false
82
- },
83
- "optional": false,
84
- "nullable": false
85
- }
86
- }
87
- }
88
- },
89
- "roots": {
90
- "blogsPage": {
91
- "type": "object",
92
- "properties": {
93
- "headline": {
94
- "kind": "primitive",
95
- "type": "string",
96
- "optional": false,
97
- "nullable": false
98
- },
99
- "blogs": {
100
- "type": "array",
101
- "items": {
102
- "kind": "modelRef",
103
- "model": "BlogPost",
104
- "optional": false,
105
- "nullable": false
106
- },
107
- "optional": false,
108
- "nullable": false
109
- },
110
- "links": {
111
- "type": "array",
112
- "items": {
113
- "type": "object",
114
- "properties": {
115
- "url": {
116
- "kind": "primitive",
117
- "type": "string",
118
- "optional": false,
119
- "nullable": false
120
- },
121
- "text": {
122
- "kind": "primitive",
123
- "type": "string",
124
- "optional": false,
125
- "nullable": false
126
- },
127
- "images": {
128
- "type": "array",
129
- "items": {
130
- "type": "object",
131
- "properties": {
132
- "url": {
133
- "kind": "primitive",
134
- "type": "string",
135
- "optional": false,
136
- "nullable": false
137
- },
138
- "alt": {
139
- "kind": "primitive",
140
- "type": "string",
141
- "optional": false,
142
- "nullable": false
143
- }
144
- },
145
- "optional": false,
146
- "nullable": false
147
- },
148
- "optional": false,
149
- "nullable": false
150
- }
151
- },
152
- "optional": false,
153
- "nullable": false
154
- },
155
- "optional": false,
156
- "nullable": false
157
- }
158
- },
159
- "optional": false,
160
- "nullable": false
161
- },
162
- "homePage": {
163
- "type": "object",
164
- "properties": {
165
- "headline": {
166
- "kind": "primitive",
167
- "type": "string",
168
- "optional": false,
169
- "nullable": false
170
- },
171
- "numberOfProjects": {
172
- "type": "array",
173
- "items": {
174
- "kind": "primitive",
175
- "type": "number",
176
- "optional": false,
177
- "nullable": false
178
- },
179
- "optional": false,
180
- "nullable": false
181
- },
182
- "numberOfView": {
183
- "kind": "primitive",
184
- "type": "number",
185
- "optional": false,
186
- "nullable": false
187
- },
188
- "section1": {
189
- "type": "object",
190
- "properties": {
191
- "title": {
192
- "kind": "primitive",
193
- "type": "string",
194
- "optional": false,
195
- "nullable": false
196
- },
197
- "subtitle": {
198
- "kind": "primitive",
199
- "type": "string",
200
- "optional": false,
201
- "nullable": false
202
- },
203
- "mentor": {
204
- "kind": "modelRef",
205
- "model": "Author",
206
- "optional": false,
207
- "nullable": false
208
- },
209
- "features": {
210
- "type": "array",
211
- "items": {
212
- "type": "object",
213
- "properties": {
214
- "headline": {
215
- "kind": "primitive",
216
- "type": "string",
217
- "optional": false,
218
- "nullable": false
219
- },
220
- "images": {
221
- "type": "array",
222
- "items": {
223
- "kind": "primitive",
224
- "type": "string",
225
- "optional": false,
226
- "nullable": false
227
- },
228
- "optional": false,
229
- "nullable": false
230
- }
231
- },
232
- "optional": false,
233
- "nullable": false
234
- },
235
- "optional": false,
236
- "nullable": false
237
- },
238
- "link": {
239
- "type": "object",
240
- "properties": {
241
- "text": {
242
- "kind": "primitive",
243
- "type": "string",
244
- "optional": false,
245
- "nullable": false
246
- },
247
- "url": {
248
- "kind": "primitive",
249
- "type": "string",
250
- "optional": false,
251
- "nullable": false
252
- },
253
- "image": {
254
- "type": "object",
255
- "properties": {
256
- "type": {
257
- "kind": "primitive",
258
- "type": "string",
259
- "optional": false,
260
- "nullable": false
261
- },
262
- "name": {
263
- "kind": "primitive",
264
- "type": "string",
265
- "optional": false,
266
- "nullable": false
267
- }
268
- },
269
- "optional": false,
270
- "nullable": false
271
- }
272
- },
273
- "optional": false,
274
- "nullable": false
275
- }
276
- },
277
- "optional": false,
278
- "nullable": false
279
- },
280
- "mentor": {
281
- "kind": "modelRef",
282
- "model": "Author",
283
- "optional": false,
284
- "nullable": false
285
- },
286
- "isActive": {
287
- "kind": "primitive",
288
- "type": "boolean",
289
- "optional": false,
290
- "nullable": false
291
- },
292
- "age": {
293
- "kind": "primitive",
294
- "type": "number",
295
- "optional": false,
296
- "nullable": false
297
- },
298
- "testimonials": {
299
- "type": "array",
300
- "items": {
301
- "kind": "modelRef",
302
- "model": "Testimonial",
303
- "optional": false,
304
- "nullable": false
305
- },
306
- "optional": false,
307
- "nullable": false
308
- },
309
- "links": {
310
- "type": "array",
311
- "items": {
312
- "type": "object",
313
- "properties": {
314
- "text": {
315
- "kind": "primitive",
316
- "type": "string",
317
- "optional": false,
318
- "nullable": false
319
- },
320
- "url": {
321
- "kind": "primitive",
322
- "type": "string",
323
- "optional": false,
324
- "nullable": false
325
- },
326
- "author": {
327
- "kind": "modelRef",
328
- "model": "Author",
329
- "optional": false,
330
- "nullable": false
331
- },
332
- "foods": {
333
- "type": "array",
334
- "items": {
335
- "type": "object",
336
- "properties": {
337
- "name": {
338
- "kind": "primitive",
339
- "type": "string",
340
- "optional": false,
341
- "nullable": false
342
- },
343
- "cost": {
344
- "kind": "primitive",
345
- "type": "number",
346
- "optional": false,
347
- "nullable": false
348
- }
349
- },
350
- "optional": false,
351
- "nullable": false
352
- },
353
- "optional": false,
354
- "nullable": false
355
- },
356
- "section": {
357
- "type": "object",
358
- "properties": {
359
- "name": {
360
- "kind": "primitive",
361
- "type": "string",
362
- "optional": false,
363
- "nullable": false
364
- },
365
- "description": {
366
- "kind": "primitive",
367
- "type": "string",
368
- "optional": false,
369
- "nullable": false
370
- },
371
- "drinks": {
372
- "type": "array",
373
- "items": {
374
- "type": "object",
375
- "properties": {
376
- "name": {
377
- "kind": "primitive",
378
- "type": "string",
379
- "optional": false,
380
- "nullable": false
381
- },
382
- "filled": {
383
- "kind": "primitive",
384
- "type": "boolean",
385
- "optional": false,
386
- "nullable": false
387
- }
388
- },
389
- "optional": false,
390
- "nullable": false
391
- },
392
- "optional": false,
393
- "nullable": false
394
- }
395
- },
396
- "optional": false,
397
- "nullable": false
398
- }
399
- },
400
- "optional": false,
401
- "nullable": false
402
- },
403
- "optional": false,
404
- "nullable": false
405
- }
406
- },
407
- "optional": false,
408
- "nullable": false
409
- },
410
- "blogPosts": {
411
- "type": "array",
412
- "items": {
413
- "kind": "modelRef",
414
- "model": "BlogPost",
415
- "optional": false,
416
- "nullable": false
417
- },
418
- "optional": false,
419
- "nullable": false
420
- },
421
- "links": {
422
- "type": "array",
423
- "items": {
424
- "type": "object",
425
- "properties": {
426
- "text": {
427
- "kind": "primitive",
428
- "type": "string",
429
- "optional": false,
430
- "nullable": false
431
- },
432
- "url": {
433
- "kind": "primitive",
434
- "type": "string",
435
- "optional": false,
436
- "nullable": false
437
- }
438
- },
439
- "optional": false,
440
- "nullable": false
441
- },
442
- "optional": false,
443
- "nullable": false
444
- },
445
- "images": {
446
- "type": "array",
447
- "items": {
448
- "kind": "primitive",
449
- "type": "string",
450
- "optional": false,
451
- "nullable": false
452
- },
453
- "optional": false,
454
- "nullable": false
455
- },
456
- "aboutUsPage": {
457
- "type": "object",
458
- "properties": {
459
- "headline": {
460
- "kind": "primitive",
461
- "type": "string",
462
- "optional": false,
463
- "nullable": false
464
- },
465
- "description": {
466
- "kind": "primitive",
467
- "type": "string",
468
- "optional": false,
469
- "nullable": false
470
- },
471
- "title": {
472
- "kind": "primitive",
473
- "type": "string",
474
- "optional": false,
475
- "nullable": false
476
- },
477
- "numberOfEmployees": {
478
- "kind": "primitive",
479
- "type": "number",
480
- "optional": false,
481
- "nullable": false
482
- },
483
- "blogs": {
484
- "type": "array",
485
- "items": {
486
- "kind": "modelRef",
487
- "model": "BlogPost",
488
- "optional": false,
489
- "nullable": false
490
- },
491
- "optional": false,
492
- "nullable": false
493
- },
494
- "employees": {
495
- "type": "array",
496
- "items": {
497
- "type": "object",
498
- "properties": {
499
- "name": {
500
- "kind": "primitive",
501
- "type": "string",
502
- "optional": false,
503
- "nullable": false
504
- },
505
- "salary": {
506
- "kind": "primitive",
507
- "type": "number",
508
- "optional": false,
509
- "nullable": false
510
- }
511
- },
512
- "optional": false,
513
- "nullable": false
514
- },
515
- "optional": false,
516
- "nullable": false
517
- }
518
- },
519
- "optional": false,
520
- "nullable": false
521
- }
522
- }
6
+ models: {},
7
+ roots: {},
523
8
  };