@cms0/cms0 0.0.1

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.
Files changed (70) hide show
  1. package/bin/cms0.js +30 -0
  2. package/dist/cjs/cli.cjs +7 -0
  3. package/dist/cjs/config.cjs +6 -0
  4. package/dist/cjs/generated/schema-descriptor.cjs +523 -0
  5. package/dist/cjs/index.cjs +48 -0
  6. package/dist/cjs/libs/cli/build.cjs +14 -0
  7. package/dist/cjs/libs/cli/cli.cjs +64 -0
  8. package/dist/cjs/libs/cli/config-loader.cjs +211 -0
  9. package/dist/cjs/libs/cli/descriptor-builder-alt.cjs +221 -0
  10. package/dist/cjs/libs/cli/descriptor-builder.cjs +232 -0
  11. package/dist/cjs/libs/cli/descriptor-writer.cjs +23 -0
  12. package/dist/cjs/libs/cli/index.cjs +10 -0
  13. package/dist/cjs/libs/cli/paths.cjs +28 -0
  14. package/dist/cjs/libs/cli/publisher.cjs +103 -0
  15. package/dist/cjs/libs/cli/types.cjs +3 -0
  16. package/dist/cjs/libs/cli/watcher.cjs +34 -0
  17. package/dist/cjs/schema-descriptors.cjs +5 -0
  18. package/dist/cjs/utils/index.cjs +2 -0
  19. package/dist/esm/cli.js +5 -0
  20. package/dist/esm/config.js +3 -0
  21. package/dist/esm/generated/schema-descriptor.js +520 -0
  22. package/dist/esm/index.js +45 -0
  23. package/dist/esm/libs/cli/build.js +12 -0
  24. package/dist/esm/libs/cli/cli.js +62 -0
  25. package/dist/esm/libs/cli/config-loader.js +168 -0
  26. package/dist/esm/libs/cli/descriptor-builder-alt.js +216 -0
  27. package/dist/esm/libs/cli/descriptor-builder.js +227 -0
  28. package/dist/esm/libs/cli/descriptor-writer.js +18 -0
  29. package/dist/esm/libs/cli/index.js +4 -0
  30. package/dist/esm/libs/cli/paths.js +21 -0
  31. package/dist/esm/libs/cli/publisher.js +101 -0
  32. package/dist/esm/libs/cli/types.js +2 -0
  33. package/dist/esm/libs/cli/watcher.js +29 -0
  34. package/dist/esm/schema-descriptors.js +1 -0
  35. package/dist/esm/utils/index.js +1 -0
  36. package/dist/types/cli.d.ts +3 -0
  37. package/dist/types/cli.d.ts.map +1 -0
  38. package/dist/types/config.d.ts +22 -0
  39. package/dist/types/config.d.ts.map +1 -0
  40. package/dist/types/generated/schema-descriptor.d.ts +520 -0
  41. package/dist/types/generated/schema-descriptor.d.ts.map +1 -0
  42. package/dist/types/index.d.ts +14 -0
  43. package/dist/types/index.d.ts.map +1 -0
  44. package/dist/types/libs/cli/build.d.ts +5 -0
  45. package/dist/types/libs/cli/build.d.ts.map +1 -0
  46. package/dist/types/libs/cli/cli.d.ts +3 -0
  47. package/dist/types/libs/cli/cli.d.ts.map +1 -0
  48. package/dist/types/libs/cli/config-loader.d.ts +12 -0
  49. package/dist/types/libs/cli/config-loader.d.ts.map +1 -0
  50. package/dist/types/libs/cli/descriptor-builder-alt.d.ts +5 -0
  51. package/dist/types/libs/cli/descriptor-builder-alt.d.ts.map +1 -0
  52. package/dist/types/libs/cli/descriptor-builder.d.ts +5 -0
  53. package/dist/types/libs/cli/descriptor-builder.d.ts.map +1 -0
  54. package/dist/types/libs/cli/descriptor-writer.d.ts +4 -0
  55. package/dist/types/libs/cli/descriptor-writer.d.ts.map +1 -0
  56. package/dist/types/libs/cli/index.d.ts +4 -0
  57. package/dist/types/libs/cli/index.d.ts.map +1 -0
  58. package/dist/types/libs/cli/paths.d.ts +4 -0
  59. package/dist/types/libs/cli/paths.d.ts.map +1 -0
  60. package/dist/types/libs/cli/publisher.d.ts +5 -0
  61. package/dist/types/libs/cli/publisher.d.ts.map +1 -0
  62. package/dist/types/libs/cli/types.d.ts +8 -0
  63. package/dist/types/libs/cli/types.d.ts.map +1 -0
  64. package/dist/types/libs/cli/watcher.d.ts +5 -0
  65. package/dist/types/libs/cli/watcher.d.ts.map +1 -0
  66. package/dist/types/schema-descriptors.d.ts +2 -0
  67. package/dist/types/schema-descriptors.d.ts.map +1 -0
  68. package/dist/types/utils/index.d.ts +2 -0
  69. package/dist/types/utils/index.d.ts.map +1 -0
  70. package/package.json +74 -0
@@ -0,0 +1,520 @@
1
+ // Auto-generated schema descriptor
2
+ export const schemaDescriptor = {
3
+ "models": {
4
+ "BlogPost": {
5
+ "kind": "model",
6
+ "properties": {
7
+ "title": {
8
+ "kind": "primitive",
9
+ "type": "string",
10
+ "optional": false,
11
+ "nullable": false
12
+ },
13
+ "description": {
14
+ "kind": "primitive",
15
+ "type": "string",
16
+ "optional": false,
17
+ "nullable": false
18
+ },
19
+ "content": {
20
+ "kind": "primitive",
21
+ "type": "string",
22
+ "optional": false,
23
+ "nullable": false
24
+ }
25
+ }
26
+ },
27
+ "Author": {
28
+ "kind": "model",
29
+ "properties": {
30
+ "profile": {
31
+ "kind": "primitive",
32
+ "type": "string",
33
+ "optional": false,
34
+ "nullable": false
35
+ },
36
+ "name": {
37
+ "kind": "primitive",
38
+ "type": "string",
39
+ "optional": false,
40
+ "nullable": false
41
+ }
42
+ }
43
+ },
44
+ "Testimonial": {
45
+ "kind": "model",
46
+ "properties": {
47
+ "content": {
48
+ "kind": "primitive",
49
+ "type": "string",
50
+ "optional": false,
51
+ "nullable": false
52
+ },
53
+ "author": {
54
+ "kind": "modelRef",
55
+ "model": "Author",
56
+ "optional": false,
57
+ "nullable": false
58
+ },
59
+ "companies": {
60
+ "type": "array",
61
+ "items": {
62
+ "type": "object",
63
+ "properties": {
64
+ "name": {
65
+ "kind": "primitive",
66
+ "type": "string",
67
+ "optional": false,
68
+ "nullable": false
69
+ },
70
+ "value": {
71
+ "kind": "primitive",
72
+ "type": "number",
73
+ "optional": false,
74
+ "nullable": false
75
+ }
76
+ },
77
+ "optional": false,
78
+ "nullable": false
79
+ },
80
+ "optional": false,
81
+ "nullable": false
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "roots": {
87
+ "blogsPage": {
88
+ "type": "object",
89
+ "properties": {
90
+ "headline": {
91
+ "kind": "primitive",
92
+ "type": "string",
93
+ "optional": false,
94
+ "nullable": false
95
+ },
96
+ "blogs": {
97
+ "type": "array",
98
+ "items": {
99
+ "kind": "modelRef",
100
+ "model": "BlogPost",
101
+ "optional": false,
102
+ "nullable": false
103
+ },
104
+ "optional": false,
105
+ "nullable": false
106
+ },
107
+ "links": {
108
+ "type": "array",
109
+ "items": {
110
+ "type": "object",
111
+ "properties": {
112
+ "url": {
113
+ "kind": "primitive",
114
+ "type": "string",
115
+ "optional": false,
116
+ "nullable": false
117
+ },
118
+ "text": {
119
+ "kind": "primitive",
120
+ "type": "string",
121
+ "optional": false,
122
+ "nullable": false
123
+ },
124
+ "images": {
125
+ "type": "array",
126
+ "items": {
127
+ "type": "object",
128
+ "properties": {
129
+ "url": {
130
+ "kind": "primitive",
131
+ "type": "string",
132
+ "optional": false,
133
+ "nullable": false
134
+ },
135
+ "alt": {
136
+ "kind": "primitive",
137
+ "type": "string",
138
+ "optional": false,
139
+ "nullable": false
140
+ }
141
+ },
142
+ "optional": false,
143
+ "nullable": false
144
+ },
145
+ "optional": false,
146
+ "nullable": false
147
+ }
148
+ },
149
+ "optional": false,
150
+ "nullable": false
151
+ },
152
+ "optional": false,
153
+ "nullable": false
154
+ }
155
+ },
156
+ "optional": false,
157
+ "nullable": false
158
+ },
159
+ "homePage": {
160
+ "type": "object",
161
+ "properties": {
162
+ "headline": {
163
+ "kind": "primitive",
164
+ "type": "string",
165
+ "optional": false,
166
+ "nullable": false
167
+ },
168
+ "numberOfProjects": {
169
+ "type": "array",
170
+ "items": {
171
+ "kind": "primitive",
172
+ "type": "number",
173
+ "optional": false,
174
+ "nullable": false
175
+ },
176
+ "optional": false,
177
+ "nullable": false
178
+ },
179
+ "numberOfView": {
180
+ "kind": "primitive",
181
+ "type": "number",
182
+ "optional": false,
183
+ "nullable": false
184
+ },
185
+ "section1": {
186
+ "type": "object",
187
+ "properties": {
188
+ "title": {
189
+ "kind": "primitive",
190
+ "type": "string",
191
+ "optional": false,
192
+ "nullable": false
193
+ },
194
+ "subtitle": {
195
+ "kind": "primitive",
196
+ "type": "string",
197
+ "optional": false,
198
+ "nullable": false
199
+ },
200
+ "mentor": {
201
+ "kind": "modelRef",
202
+ "model": "Author",
203
+ "optional": false,
204
+ "nullable": false
205
+ },
206
+ "features": {
207
+ "type": "array",
208
+ "items": {
209
+ "type": "object",
210
+ "properties": {
211
+ "headline": {
212
+ "kind": "primitive",
213
+ "type": "string",
214
+ "optional": false,
215
+ "nullable": false
216
+ },
217
+ "images": {
218
+ "type": "array",
219
+ "items": {
220
+ "kind": "primitive",
221
+ "type": "string",
222
+ "optional": false,
223
+ "nullable": false
224
+ },
225
+ "optional": false,
226
+ "nullable": false
227
+ }
228
+ },
229
+ "optional": false,
230
+ "nullable": false
231
+ },
232
+ "optional": false,
233
+ "nullable": false
234
+ },
235
+ "link": {
236
+ "type": "object",
237
+ "properties": {
238
+ "text": {
239
+ "kind": "primitive",
240
+ "type": "string",
241
+ "optional": false,
242
+ "nullable": false
243
+ },
244
+ "url": {
245
+ "kind": "primitive",
246
+ "type": "string",
247
+ "optional": false,
248
+ "nullable": false
249
+ },
250
+ "image": {
251
+ "type": "object",
252
+ "properties": {
253
+ "type": {
254
+ "kind": "primitive",
255
+ "type": "string",
256
+ "optional": false,
257
+ "nullable": false
258
+ },
259
+ "name": {
260
+ "kind": "primitive",
261
+ "type": "string",
262
+ "optional": false,
263
+ "nullable": false
264
+ }
265
+ },
266
+ "optional": false,
267
+ "nullable": false
268
+ }
269
+ },
270
+ "optional": false,
271
+ "nullable": false
272
+ }
273
+ },
274
+ "optional": false,
275
+ "nullable": false
276
+ },
277
+ "mentor": {
278
+ "kind": "modelRef",
279
+ "model": "Author",
280
+ "optional": false,
281
+ "nullable": false
282
+ },
283
+ "isActive": {
284
+ "kind": "primitive",
285
+ "type": "boolean",
286
+ "optional": false,
287
+ "nullable": false
288
+ },
289
+ "age": {
290
+ "kind": "primitive",
291
+ "type": "number",
292
+ "optional": false,
293
+ "nullable": false
294
+ },
295
+ "testimonials": {
296
+ "type": "array",
297
+ "items": {
298
+ "kind": "modelRef",
299
+ "model": "Testimonial",
300
+ "optional": false,
301
+ "nullable": false
302
+ },
303
+ "optional": false,
304
+ "nullable": false
305
+ },
306
+ "links": {
307
+ "type": "array",
308
+ "items": {
309
+ "type": "object",
310
+ "properties": {
311
+ "text": {
312
+ "kind": "primitive",
313
+ "type": "string",
314
+ "optional": false,
315
+ "nullable": false
316
+ },
317
+ "url": {
318
+ "kind": "primitive",
319
+ "type": "string",
320
+ "optional": false,
321
+ "nullable": false
322
+ },
323
+ "author": {
324
+ "kind": "modelRef",
325
+ "model": "Author",
326
+ "optional": false,
327
+ "nullable": false
328
+ },
329
+ "foods": {
330
+ "type": "array",
331
+ "items": {
332
+ "type": "object",
333
+ "properties": {
334
+ "name": {
335
+ "kind": "primitive",
336
+ "type": "string",
337
+ "optional": false,
338
+ "nullable": false
339
+ },
340
+ "cost": {
341
+ "kind": "primitive",
342
+ "type": "number",
343
+ "optional": false,
344
+ "nullable": false
345
+ }
346
+ },
347
+ "optional": false,
348
+ "nullable": false
349
+ },
350
+ "optional": false,
351
+ "nullable": false
352
+ },
353
+ "section": {
354
+ "type": "object",
355
+ "properties": {
356
+ "name": {
357
+ "kind": "primitive",
358
+ "type": "string",
359
+ "optional": false,
360
+ "nullable": false
361
+ },
362
+ "description": {
363
+ "kind": "primitive",
364
+ "type": "string",
365
+ "optional": false,
366
+ "nullable": false
367
+ },
368
+ "drinks": {
369
+ "type": "array",
370
+ "items": {
371
+ "type": "object",
372
+ "properties": {
373
+ "name": {
374
+ "kind": "primitive",
375
+ "type": "string",
376
+ "optional": false,
377
+ "nullable": false
378
+ },
379
+ "filled": {
380
+ "kind": "primitive",
381
+ "type": "boolean",
382
+ "optional": false,
383
+ "nullable": false
384
+ }
385
+ },
386
+ "optional": false,
387
+ "nullable": false
388
+ },
389
+ "optional": false,
390
+ "nullable": false
391
+ }
392
+ },
393
+ "optional": false,
394
+ "nullable": false
395
+ }
396
+ },
397
+ "optional": false,
398
+ "nullable": false
399
+ },
400
+ "optional": false,
401
+ "nullable": false
402
+ }
403
+ },
404
+ "optional": false,
405
+ "nullable": false
406
+ },
407
+ "blogPosts": {
408
+ "type": "array",
409
+ "items": {
410
+ "kind": "modelRef",
411
+ "model": "BlogPost",
412
+ "optional": false,
413
+ "nullable": false
414
+ },
415
+ "optional": false,
416
+ "nullable": false
417
+ },
418
+ "links": {
419
+ "type": "array",
420
+ "items": {
421
+ "type": "object",
422
+ "properties": {
423
+ "text": {
424
+ "kind": "primitive",
425
+ "type": "string",
426
+ "optional": false,
427
+ "nullable": false
428
+ },
429
+ "url": {
430
+ "kind": "primitive",
431
+ "type": "string",
432
+ "optional": false,
433
+ "nullable": false
434
+ }
435
+ },
436
+ "optional": false,
437
+ "nullable": false
438
+ },
439
+ "optional": false,
440
+ "nullable": false
441
+ },
442
+ "images": {
443
+ "type": "array",
444
+ "items": {
445
+ "kind": "primitive",
446
+ "type": "string",
447
+ "optional": false,
448
+ "nullable": false
449
+ },
450
+ "optional": false,
451
+ "nullable": false
452
+ },
453
+ "aboutUsPage": {
454
+ "type": "object",
455
+ "properties": {
456
+ "headline": {
457
+ "kind": "primitive",
458
+ "type": "string",
459
+ "optional": false,
460
+ "nullable": false
461
+ },
462
+ "description": {
463
+ "kind": "primitive",
464
+ "type": "string",
465
+ "optional": false,
466
+ "nullable": false
467
+ },
468
+ "title": {
469
+ "kind": "primitive",
470
+ "type": "string",
471
+ "optional": false,
472
+ "nullable": false
473
+ },
474
+ "numberOfEmployees": {
475
+ "kind": "primitive",
476
+ "type": "number",
477
+ "optional": false,
478
+ "nullable": false
479
+ },
480
+ "blogs": {
481
+ "type": "array",
482
+ "items": {
483
+ "kind": "modelRef",
484
+ "model": "BlogPost",
485
+ "optional": false,
486
+ "nullable": false
487
+ },
488
+ "optional": false,
489
+ "nullable": false
490
+ },
491
+ "employees": {
492
+ "type": "array",
493
+ "items": {
494
+ "type": "object",
495
+ "properties": {
496
+ "name": {
497
+ "kind": "primitive",
498
+ "type": "string",
499
+ "optional": false,
500
+ "nullable": false
501
+ },
502
+ "salary": {
503
+ "kind": "primitive",
504
+ "type": "number",
505
+ "optional": false,
506
+ "nullable": false
507
+ }
508
+ },
509
+ "optional": false,
510
+ "nullable": false
511
+ },
512
+ "optional": false,
513
+ "nullable": false
514
+ }
515
+ },
516
+ "optional": false,
517
+ "nullable": false
518
+ }
519
+ }
520
+ };
@@ -0,0 +1,45 @@
1
+ import { schemaDescriptor } from "@cms0/cms0/schema-descriptors";
2
+ import { buildZodSchemasFromDescriptor, } from "@cms0/shared";
3
+ /**
4
+ * Initializes the CMS SDK for a given schema.
5
+ * @param config configuration including API base URL or database URL.
6
+ * @returns an object with typed accessors matching the schema.
7
+ */
8
+ export function cms0(config) {
9
+ const baseUrl = config.apiConfig?.baseUrl?.replace(/\/$/, "") ?? "";
10
+ const apiKey = config.apiConfig?.key;
11
+ console.log("apiKey: ", apiKey);
12
+ return new Proxy({}, {
13
+ get(target, prop) {
14
+ if (!(prop in schemaDescriptor.roots)) {
15
+ throw new Error(`Unknown schema key '${prop}'`);
16
+ }
17
+ return async () => {
18
+ const url = `${baseUrl}/${prop}`;
19
+ const res = await fetch(url, {
20
+ method: "GET",
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
24
+ },
25
+ });
26
+ if (!res.ok) {
27
+ throw new Error(`Request failed for '${prop}' with status ${res.status}: ${res.statusText}`);
28
+ }
29
+ const data = await res.json();
30
+ // Validate via Zod
31
+ const { zodSchemas } = buildZodSchemasFromDescriptor(schemaDescriptor);
32
+ const schema = zodSchemas[prop];
33
+ if (!schema) {
34
+ // If no schema found, return the raw data
35
+ return data;
36
+ }
37
+ const result = schema.safeParse(data);
38
+ if (!result.success) {
39
+ throw new Error(`Invalid data received for '${prop}': ${JSON.stringify(result.error.format())}`);
40
+ }
41
+ return result.data;
42
+ };
43
+ },
44
+ });
45
+ }
@@ -0,0 +1,12 @@
1
+ // Single-shot build that compiles the descriptor, writes it, and publishes it.
2
+ import { buildDescriptorAlt as buildDescriptor } from "./descriptor-builder-alt.js";
3
+ import { descriptorOutPath } from "./paths.js";
4
+ import { publishDescriptor } from "./publisher.js";
5
+ import { writeDescriptorFile } from "./descriptor-writer.js";
6
+ function buildOnce(resolved) {
7
+ const descriptor = buildDescriptor(resolved);
8
+ writeDescriptorFile(descriptor, descriptorOutPath);
9
+ publishDescriptor(resolved, descriptor);
10
+ return descriptor;
11
+ }
12
+ export { buildOnce };
@@ -0,0 +1,62 @@
1
+ // CLI entry point: parse arguments, load config, and trigger build/watch modes.
2
+ import { pathToFileURL } from "url";
3
+ import { buildOnce } from "./build.js";
4
+ import { loadUserConfig, resolvePaths } from "./config-loader.js";
5
+ import { startWatcher } from "./watcher.js";
6
+ async function runFromCli() {
7
+ const args = process.argv.slice(2);
8
+ let mode = "build";
9
+ let configArg;
10
+ for (let i = 0; i < args.length; i++) {
11
+ const arg = args[i];
12
+ if (arg === "watch" || arg === "build" || arg === "dev") {
13
+ mode = arg;
14
+ }
15
+ else if (arg === "--config") {
16
+ configArg = args[i + 1];
17
+ i++;
18
+ }
19
+ else if (arg && arg.startsWith("--config=")) {
20
+ configArg = arg.split("=")[1];
21
+ }
22
+ }
23
+ const loaded = await loadUserConfig(configArg);
24
+ if (!loaded)
25
+ return;
26
+ const resolved = resolvePaths(loaded.path, loaded.config);
27
+ console.log("resolved: ", resolved);
28
+ if (mode === "watch") {
29
+ startWatcher(resolved);
30
+ return;
31
+ }
32
+ if (mode === "dev") {
33
+ startWatcher(resolved);
34
+ return;
35
+ }
36
+ buildOnce(resolved);
37
+ }
38
+ // ESM/CJS-safe main check without import.meta syntax in the source so CJS builds succeed.
39
+ const isDirectRun = (() => {
40
+ const argv1 = process.argv[1];
41
+ if (!argv1)
42
+ return false;
43
+ if (typeof module !== "undefined" && typeof require !== "undefined") {
44
+ if (require.main === module)
45
+ return true;
46
+ }
47
+ // Use Function to access import.meta.url only when supported to avoid CJS parse errors.
48
+ const metaUrl = (() => {
49
+ try {
50
+ // eslint-disable-next-line no-new-func
51
+ return Function("return import.meta.url")();
52
+ }
53
+ catch {
54
+ return undefined;
55
+ }
56
+ })();
57
+ return metaUrl ? metaUrl === pathToFileURL(argv1).href : false;
58
+ })();
59
+ if (isDirectRun) {
60
+ runFromCli();
61
+ }
62
+ export { runFromCli };