@cms0/shared 0.0.4 → 0.0.5

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.
@@ -15,6 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.delay = void 0;
18
- __exportStar(require("./validation"), exports);
18
+ __exportStar(require("./validation.js"), exports);
19
19
  const delay = (ms) => new Promise((res) => setTimeout(res, ms));
20
20
  exports.delay = delay;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,2 @@
1
+ export * from "./validation.js";
2
+ export const delay = (ms) => new Promise((res) => setTimeout(res, ms));
@@ -0,0 +1,72 @@
1
+ import { z } from "zod";
2
+ // Map custom primitive-models (or types) you defined
3
+ const customTypeSchemas = {
4
+ Asset: z.object({ id: z.string(), url: z.string().url() }),
5
+ RichText: z.object({ html: z.string(), delta: z.array(z.any()) }),
6
+ Url: z.string().url(),
7
+ };
8
+ function convertDescriptorToZod(desc, modelZodSchemas, opts = {}) {
9
+ const applyOptionality = (schema) => {
10
+ let out = schema;
11
+ if (desc.nullable || opts.loose)
12
+ out = out.nullable();
13
+ if (desc.optional || opts.loose)
14
+ out = out.optional();
15
+ return out;
16
+ };
17
+ if (desc.kind === "primitive") {
18
+ switch (desc.type) {
19
+ case "string":
20
+ return applyOptionality(z.string());
21
+ case "number":
22
+ return applyOptionality(z.number());
23
+ case "boolean":
24
+ return applyOptionality(z.boolean());
25
+ case "json":
26
+ return applyOptionality(z.any());
27
+ }
28
+ }
29
+ if (desc.kind === "modelRef") {
30
+ const schema = modelZodSchemas[desc.model];
31
+ const base = schema ?? z.any();
32
+ // For loose schemas (root singletons), accept either the object or just an id.
33
+ const withId = opts.loose ? z.union([base, z.string()]) : base;
34
+ return applyOptionality(withId);
35
+ }
36
+ if (desc.type === "object" && desc.properties) {
37
+ const shape = {};
38
+ for (const [key, valueDesc] of Object.entries(desc.properties)) {
39
+ shape[key] = convertDescriptorToZod(valueDesc, modelZodSchemas, opts);
40
+ }
41
+ const objectSchema = opts.loose ? z.object(shape).partial() : z.object(shape);
42
+ return applyOptionality(objectSchema);
43
+ }
44
+ if (desc.type === "array" && desc.items) {
45
+ return applyOptionality(z.array(convertDescriptorToZod(desc.items, modelZodSchemas, opts)));
46
+ }
47
+ if (typeof desc.type === "string") {
48
+ const custom = customTypeSchemas[desc.type];
49
+ if (custom) {
50
+ return applyOptionality(custom);
51
+ }
52
+ }
53
+ return applyOptionality(z.any());
54
+ }
55
+ export function buildZodSchemasFromDescriptor(descriptor) {
56
+ const modelZodSchemas = {};
57
+ const zodSchemas = {};
58
+ for (const [modelName, modelDesc] of Object.entries(descriptor.models)) {
59
+ const shape = {};
60
+ for (const [propName, propDesc] of Object.entries(modelDesc.properties)) {
61
+ shape[propName] = convertDescriptorToZod(propDesc, modelZodSchemas);
62
+ }
63
+ modelZodSchemas[modelName] = z.object(shape);
64
+ }
65
+ for (const [rootKey, rootDesc] of Object.entries(descriptor.roots)) {
66
+ // Root schemas are used for singleton PATCH; make nested structures loose/optional.
67
+ zodSchemas[rootKey] = convertDescriptorToZod(rootDesc, modelZodSchemas, {
68
+ loose: true,
69
+ });
70
+ }
71
+ return { zodSchemas, modelZodSchemas };
72
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./validation.js";
2
+ export declare const delay: (ms: number) => Promise<unknown>;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAEhC,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,qBAA8C,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAW,MAAM,KAAK,CAAC;AASjC,MAAM,M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AAQ,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH,CAAC;AAsEF,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,cAAc;;;EAoBvE"}
package/package.json CHANGED
@@ -1,25 +1,27 @@
1
1
  {
2
2
  "name": "@cms0/shared",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
+ "type": "module",
4
5
  "private": false,
5
6
  "publishConfig": {
6
7
  "access": "restricted"
7
8
  },
8
- "main": "dist/index.js",
9
- "types": "./dist/index.d.ts",
9
+ "main": "./dist/cjs/index.js",
10
+ "module": "./dist/esm/index.js",
11
+ "types": "./dist/types/index.d.ts",
10
12
  "files": [
11
13
  "dist"
12
14
  ],
13
15
  "exports": {
14
16
  ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js",
17
- "require": "./dist/index.js"
17
+ "types": "./dist/types/index.d.ts",
18
+ "import": "./dist/esm/index.js",
19
+ "require": "./dist/cjs/index.js"
18
20
  },
19
21
  "./*": {
20
- "types": "./dist/*.d.ts",
21
- "import": "./dist/*.js",
22
- "require": "./dist/*.js"
22
+ "types": "./dist/types/*.d.ts",
23
+ "import": "./dist/esm/*.js",
24
+ "require": "./dist/cjs/*.js"
23
25
  }
24
26
  },
25
27
  "dependencies": {
@@ -31,7 +33,11 @@
31
33
  "@cms0/typescript-config": "0.0.1"
32
34
  },
33
35
  "scripts": {
34
- "build": "tsc",
36
+ "build": "pnpm run build:clean && pnpm run build:esm && pnpm run build:cjs && pnpm run build:post",
37
+ "build:clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true });\"",
38
+ "build:esm": "tsc -p tsconfig.json",
39
+ "build:cjs": "tsc -p tsconfig.cjs.json",
40
+ "build:post": "node -e \"const fs=require('fs');fs.mkdirSync('dist/cjs',{recursive:true});fs.writeFileSync('dist/cjs/package.json','{\\\"type\\\":\\\"commonjs\\\"}\\\\n');\"",
35
41
  "dev": "tsc -b --watch"
36
42
  }
37
43
  }
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./validation";
2
- export declare const delay: (ms: number) => Promise<unknown>;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,qBAA8C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAW,MAAM,KAAK,CAAC;AASjC,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAErE,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3E;IACE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACD;IACE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,eA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