controlresell 0.0.2 → 0.0.4

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.
@@ -0,0 +1,2 @@
1
+ import { z } from "zod";
2
+ export declare const legacy: <T extends z.ZodTypeAny>(schema: T) => T;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.legacy = void 0;
4
+ const zod_1 = require("zod");
5
+ const toCamelCase = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
6
+ const toSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
7
+ const snakeToCamel = (schema) => zod_1.z.preprocess((data) => {
8
+ if (typeof data !== "object" || data === null)
9
+ return data;
10
+ const converted = Object.fromEntries(Object.entries(data).map(([key, value]) => [toCamelCase(key), value]));
11
+ return { ...data, ...converted };
12
+ }, schema);
13
+ const addSnakeCaseKeys = (schema) => schema.transform((data) => {
14
+ if (typeof data !== "object" || data === null)
15
+ return data;
16
+ const converted = Object.fromEntries(Object.entries(data).map(([key, value]) => [toSnakeCase(key), value]));
17
+ return { ...data, ...converted };
18
+ });
19
+ const legacy = (schema) => addSnakeCaseKeys(snakeToCamel(schema));
20
+ exports.legacy = legacy;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  * @file Automatically generated by barrelsby.
3
3
  */
4
4
  export * from "./helpers/json";
5
+ export * from "./helpers/legacy";
6
+ export * from "./models/primitives";
5
7
  export * from "./models/items/item";
6
8
  export * from "./models/items/itemField";
7
9
  export * from "./models/items/itemFieldValue";
package/dist/index.js CHANGED
@@ -18,6 +18,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  __exportStar(require("./helpers/json"), exports);
21
+ __exportStar(require("./helpers/legacy"), exports);
22
+ __exportStar(require("./models/primitives"), exports);
21
23
  __exportStar(require("./models/items/item"), exports);
22
24
  __exportStar(require("./models/items/itemField"), exports);
23
25
  __exportStar(require("./models/items/itemFieldValue"), exports);
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
2
  export declare const ItemFieldValuePayloadSchema: z.ZodObject<{
3
- field_id: z.ZodNumber;
3
+ fieldId: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
4
4
  value: z.ZodString;
5
5
  }, "strip", z.ZodTypeAny, {
6
6
  value: string;
7
- field_id: number;
7
+ fieldId: string | number;
8
8
  }, {
9
9
  value: string;
10
- field_id: number;
10
+ fieldId: string | number;
11
11
  }>;
12
12
  export type ItemFieldValuePayload = z.infer<typeof ItemFieldValuePayloadSchema>;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ItemFieldValuePayloadSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- exports.ItemFieldValuePayloadSchema = zod_1.z.object({
6
- field_id: zod_1.z.number(),
5
+ const legacy_1 = require("../../helpers/legacy");
6
+ const primitives_1 = require("../primitives");
7
+ exports.ItemFieldValuePayloadSchema = (0, legacy_1.legacy)(zod_1.z.object({
8
+ fieldId: primitives_1.IdSchema,
7
9
  value: zod_1.z.string(),
8
- });
10
+ }));
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ export declare const IdSchema: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
3
+ export type Id = z.infer<typeof IdSchema>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IdSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.IdSchema = zod_1.z.union([
6
+ zod_1.z.number(), zod_1.z.string().uuid(),
7
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "controlresell",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
@@ -10,7 +10,8 @@
10
10
  "scripts": {
11
11
  "generate-index": "barrelsby --delete --directory src",
12
12
  "build": "npm run generate-index && tsc",
13
- "test": "echo \"Error: no test specified\" && exit 1"
13
+ "test": "echo \"Error: no test specified\" && exit 1",
14
+ "lint": "eslint ."
14
15
  },
15
16
  "keywords": [],
16
17
  "author": "",
@@ -18,7 +19,7 @@
18
19
  "description": "",
19
20
  "devDependencies": {
20
21
  "@eslint/js": "^9.21.0",
21
- "@guimauvedigital/eslint-plugin-safety": "^1.0.8",
22
+ "@guimauvedigital/eslint-plugin-safety": "^1.0.9",
22
23
  "barrelsby": "^2.8.1",
23
24
  "eslint": "^9.21.0",
24
25
  "globals": "^16.0.0",