controlresell 0.0.1 → 0.0.2

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 { ZodSchema } from "zod";
2
+ export declare const safeJsonParse: <T>(json: string | null | undefined, schema: ZodSchema<T>) => T | undefined;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.safeJsonParse = void 0;
4
+ /*
5
+ * Safe parse JSON:
6
+ * - it checks for null or undefined
7
+ * - it checks that the value returned is corresponding to the schema
8
+ * - it catch any json parsing error (and returns undefined if there is one)
9
+ */
10
+ const safeJsonParse = (json, schema) => {
11
+ if (json === null || json === undefined)
12
+ return undefined;
13
+ try {
14
+ return schema.parse(JSON.parse(json));
15
+ }
16
+ catch {
17
+ return undefined;
18
+ }
19
+ };
20
+ exports.safeJsonParse = safeJsonParse;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * @file Automatically generated by barrelsby.
3
3
  */
4
+ export * from "./helpers/json";
4
5
  export * from "./models/items/item";
5
6
  export * from "./models/items/itemField";
7
+ export * from "./models/items/itemFieldValue";
6
8
  export * from "./models/users/user";
package/dist/index.js CHANGED
@@ -17,6 +17,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./helpers/json"), exports);
20
21
  __exportStar(require("./models/items/item"), exports);
21
22
  __exportStar(require("./models/items/itemField"), exports);
23
+ __exportStar(require("./models/items/itemFieldValue"), exports);
22
24
  __exportStar(require("./models/users/user"), exports);
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ export declare const ItemFieldValuePayloadSchema: z.ZodObject<{
3
+ field_id: z.ZodNumber;
4
+ value: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ value: string;
7
+ field_id: number;
8
+ }, {
9
+ value: string;
10
+ field_id: number;
11
+ }>;
12
+ export type ItemFieldValuePayload = z.infer<typeof ItemFieldValuePayloadSchema>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ItemFieldValuePayloadSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.ItemFieldValuePayloadSchema = zod_1.z.object({
6
+ field_id: zod_1.z.number(),
7
+ value: zod_1.z.string(),
8
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "controlresell",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",