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.
- package/dist/helpers/legacy.d.ts +2 -1
- package/dist/helpers/legacy.js +5 -31
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/models/items/itemFieldValue.d.ts +3 -3
- package/dist/models/items/itemFieldValue.js +5 -3
- package/dist/models/primitives.d.ts +3 -0
- package/dist/models/primitives.js +7 -0
- package/package.json +1 -1
package/dist/helpers/legacy.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const legacy: <T extends z.ZodTypeAny>(schema: T) => T;
|
package/dist/helpers/legacy.js
CHANGED
|
@@ -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 };
|
|
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 };
|
|
17
|
+
return { ...data, ...converted };
|
|
21
18
|
});
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
3
|
+
fieldId: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
|
|
4
4
|
value: z.ZodString;
|
|
5
5
|
}, "strip", z.ZodTypeAny, {
|
|
6
6
|
value: string;
|
|
7
|
-
|
|
7
|
+
fieldId: string | number;
|
|
8
8
|
}, {
|
|
9
9
|
value: string;
|
|
10
|
-
|
|
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
|
-
|
|
6
|
-
|
|
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
|
+
}));
|