controlresell 0.0.3 → 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.
@@ -1 +1,2 @@
1
- export {};
1
+ import { z } from "zod";
2
+ export declare const legacy: <T extends z.ZodTypeAny>(schema: T) => T;
@@ -1,46 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.legacy = void 0;
3
4
  const zod_1 = require("zod");
4
- // Function to convert snake_case to camelCase
5
5
  const toCamelCase = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
6
- // Function to convert camelCase to snake_case
7
6
  const toSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
8
- // Preprocessing function to handle input
9
7
  const snakeToCamel = (schema) => zod_1.z.preprocess((data) => {
10
8
  if (typeof data !== "object" || data === null)
11
9
  return data;
12
10
  const converted = Object.fromEntries(Object.entries(data).map(([key, value]) => [toCamelCase(key), value]));
13
- return { ...data, ...converted }; // Preserve both keys
11
+ return { ...data, ...converted };
14
12
  }, schema);
15
- // Post-processing function to add snake_case keys back
16
13
  const addSnakeCaseKeys = (schema) => schema.transform((data) => {
17
14
  if (typeof data !== "object" || data === null)
18
15
  return data;
19
16
  const converted = Object.fromEntries(Object.entries(data).map(([key, value]) => [toSnakeCase(key), value]));
20
- return { ...data, ...converted }; // Preserve both keys
17
+ return { ...data, ...converted };
21
18
  });
22
- // Define your schema
23
- const schema = addSnakeCaseKeys(snakeToCamel(zod_1.z.object({
24
- firstName: zod_1.z.string(),
25
- lastName: zod_1.z.string(),
26
- age: zod_1.z.number(),
27
- })));
28
- // Example input with snake_case
29
- const input = {
30
- first_name: "John",
31
- last_name: "Doe",
32
- age: 30,
33
- };
34
- // Parsing input
35
- const parsed = schema.parse(input);
36
- console.log(parsed);
37
- /*
38
- Output:
39
- {
40
- firstName: 'John',
41
- lastName: 'Doe',
42
- age: 30,
43
- first_name: 'John',
44
- last_name: 'Doe'
45
- }
46
- */
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.3",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",