@equinor/apollo-utils 0.1.0 → 0.1.1
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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +38 -6
- package/dist/index.mjs +38 -6
- package/package.json +1 -1
- package/src/zod-validation/utils.ts +18 -6
package/.turbo/turbo-build.log
CHANGED
|
@@ -5,10 +5,10 @@ $ tsup src/index.ts --format esm,cjs --dts --external react
|
|
|
5
5
|
[34mCLI[39m Target: es6
|
|
6
6
|
[34mESM[39m Build start
|
|
7
7
|
[34mCJS[39m Build start
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
8
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m3.48 KB[39m
|
|
9
|
+
[32mESM[39m ⚡️ Build success in 85ms
|
|
10
|
+
[32mCJS[39m [1mdist/index.js [22m[32m4.62 KB[39m
|
|
11
|
+
[32mCJS[39m ⚡️ Build success in 86ms
|
|
12
12
|
[34mDTS[39m Build start
|
|
13
|
-
[32mDTS[39m ⚡️ Build success in
|
|
14
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
13
|
+
[32mDTS[39m ⚡️ Build success in 4462ms
|
|
14
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m2.00 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ type ValidationErrorMap<T> = Map<keyof T, {
|
|
|
9
9
|
|
|
10
10
|
declare function createValidator<S extends z.ZodTypeAny>(schema: S): {
|
|
11
11
|
validate: <E extends z.TypeOf<S>>(entity: E) => ValidationErrorMap<E> | undefined;
|
|
12
|
+
validateAsync: <E_1 extends z.TypeOf<S>>(entity: z.infer<typeof schema>) => Promise<ValidationErrorMap<E_1> | undefined>;
|
|
13
|
+
getSchema(): S;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
type FormState<T> = {
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
30
30
|
return to;
|
|
31
31
|
};
|
|
32
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
33
53
|
|
|
34
54
|
// src/index.ts
|
|
35
55
|
var src_exports = {};
|
|
@@ -97,15 +117,27 @@ function createValidator(schema) {
|
|
|
97
117
|
const validation = schema.safeParse(entity);
|
|
98
118
|
if (validation.success)
|
|
99
119
|
return void 0;
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
120
|
+
return prepareErrors(validation);
|
|
121
|
+
},
|
|
122
|
+
validateAsync: (entity) => __async(this, null, function* () {
|
|
123
|
+
const validation = yield schema.safeParseAsync(entity);
|
|
124
|
+
if (validation.success)
|
|
125
|
+
return void 0;
|
|
126
|
+
return prepareErrors(validation);
|
|
127
|
+
}),
|
|
128
|
+
getSchema() {
|
|
129
|
+
return schema;
|
|
106
130
|
}
|
|
107
131
|
};
|
|
108
132
|
}
|
|
133
|
+
function prepareErrors(errorValidation) {
|
|
134
|
+
return new Map(
|
|
135
|
+
errorValidation.error.errors.map((error) => [
|
|
136
|
+
error.path[0],
|
|
137
|
+
{ message: error.message, code: error.code }
|
|
138
|
+
])
|
|
139
|
+
);
|
|
140
|
+
}
|
|
109
141
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
142
|
0 && (module.exports = {
|
|
111
143
|
createFormFamily,
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,26 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
var fulfilled = (value) => {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var rejected = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.throw(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
17
37
|
|
|
18
38
|
// src/jotai-form/formUtils.ts
|
|
19
39
|
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
@@ -71,15 +91,27 @@ function createValidator(schema) {
|
|
|
71
91
|
const validation = schema.safeParse(entity);
|
|
72
92
|
if (validation.success)
|
|
73
93
|
return void 0;
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
94
|
+
return prepareErrors(validation);
|
|
95
|
+
},
|
|
96
|
+
validateAsync: (entity) => __async(this, null, function* () {
|
|
97
|
+
const validation = yield schema.safeParseAsync(entity);
|
|
98
|
+
if (validation.success)
|
|
99
|
+
return void 0;
|
|
100
|
+
return prepareErrors(validation);
|
|
101
|
+
}),
|
|
102
|
+
getSchema() {
|
|
103
|
+
return schema;
|
|
80
104
|
}
|
|
81
105
|
};
|
|
82
106
|
}
|
|
107
|
+
function prepareErrors(errorValidation) {
|
|
108
|
+
return new Map(
|
|
109
|
+
errorValidation.error.errors.map((error) => [
|
|
110
|
+
error.path[0],
|
|
111
|
+
{ message: error.message, code: error.code }
|
|
112
|
+
])
|
|
113
|
+
);
|
|
114
|
+
}
|
|
83
115
|
export {
|
|
84
116
|
createFormFamily,
|
|
85
117
|
createValidator,
|
package/package.json
CHANGED
|
@@ -6,12 +6,24 @@ export function createValidator<S extends z.ZodTypeAny>(schema: S) {
|
|
|
6
6
|
validate: <E extends z.infer<typeof schema>>(entity: E) => {
|
|
7
7
|
const validation = schema.safeParse(entity)
|
|
8
8
|
if (validation.success) return undefined
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
return prepareErrors<E>(validation)
|
|
10
|
+
},
|
|
11
|
+
validateAsync: async <E extends z.infer<typeof schema>>(entity: z.infer<typeof schema>) => {
|
|
12
|
+
const validation = await schema.safeParseAsync(entity)
|
|
13
|
+
if (validation.success) return undefined
|
|
14
|
+
return prepareErrors<E>(validation)
|
|
15
|
+
},
|
|
16
|
+
getSchema() {
|
|
17
|
+
return schema
|
|
15
18
|
},
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
|
|
22
|
+
function prepareErrors<E extends Record<string, unknown>>(errorValidation: z.SafeParseError<E>) {
|
|
23
|
+
return new Map(
|
|
24
|
+
errorValidation.error.errors.map((error) => [
|
|
25
|
+
error.path[0] as keyof E,
|
|
26
|
+
{ message: error.message, code: error.code },
|
|
27
|
+
])
|
|
28
|
+
) as ValidationErrorMap<E>
|
|
29
|
+
}
|