@equinor/apollo-utils 1.0.1 → 1.0.3
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -41
- package/dist/index.mjs +11 -44
- package/package.json +29 -23
package/dist/index.d.mts
CHANGED
|
@@ -8,8 +8,8 @@ type ValidationErrorMap<T> = Map<keyof T, {
|
|
|
8
8
|
}>;
|
|
9
9
|
|
|
10
10
|
declare function createValidator<S extends z.ZodTypeAny>(schema: S): {
|
|
11
|
-
validate: <E extends z.infer<typeof schema>>(entity: E) => ValidationErrorMap<
|
|
12
|
-
validateAsync: <E extends z.infer<typeof schema>>(entity: z.infer<typeof schema>) => Promise<ValidationErrorMap<
|
|
11
|
+
validate: <E extends z.infer<typeof schema>>(entity: E) => ValidationErrorMap<z.core.output<S>> | undefined;
|
|
12
|
+
validateAsync: <E extends z.infer<typeof schema>>(entity: z.infer<typeof schema>) => Promise<ValidationErrorMap<z.core.output<S>> | undefined>;
|
|
13
13
|
getSchema(): S;
|
|
14
14
|
};
|
|
15
15
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ type ValidationErrorMap<T> = Map<keyof T, {
|
|
|
8
8
|
}>;
|
|
9
9
|
|
|
10
10
|
declare function createValidator<S extends z.ZodTypeAny>(schema: S): {
|
|
11
|
-
validate: <E extends z.infer<typeof schema>>(entity: E) => ValidationErrorMap<
|
|
12
|
-
validateAsync: <E extends z.infer<typeof schema>>(entity: z.infer<typeof schema>) => Promise<ValidationErrorMap<
|
|
11
|
+
validate: <E extends z.infer<typeof schema>>(entity: E) => ValidationErrorMap<z.core.output<S>> | undefined;
|
|
12
|
+
validateAsync: <E extends z.infer<typeof schema>>(entity: z.infer<typeof schema>) => Promise<ValidationErrorMap<z.core.output<S>> | undefined>;
|
|
13
13
|
getSchema(): S;
|
|
14
14
|
};
|
|
15
15
|
|
package/dist/index.js
CHANGED
|
@@ -2,21 +2,7 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
6
|
var __export = (target, all) => {
|
|
21
7
|
for (var name in all)
|
|
22
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,26 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
30
16
|
return to;
|
|
31
17
|
};
|
|
32
18
|
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
|
-
};
|
|
53
19
|
|
|
54
20
|
// src/index.ts
|
|
55
21
|
var index_exports = {};
|
|
@@ -66,7 +32,7 @@ var import_jotai = require("jotai");
|
|
|
66
32
|
var import_utils = require("jotai/utils");
|
|
67
33
|
function createFormFamily() {
|
|
68
34
|
return (0, import_utils.atomFamily)(
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Deprecated file
|
|
70
36
|
(_param) => (0, import_jotai.atom)(void 0),
|
|
71
37
|
(a, b) => a.id === b.id
|
|
72
38
|
);
|
|
@@ -97,8 +63,11 @@ function useFormFamilyMutation(family, param, validator) {
|
|
|
97
63
|
return (update) => {
|
|
98
64
|
return mutate((previous) => {
|
|
99
65
|
if (!previous) return;
|
|
100
|
-
const updatedValues =
|
|
101
|
-
|
|
66
|
+
const updatedValues = {
|
|
67
|
+
...previous.values,
|
|
68
|
+
...update
|
|
69
|
+
};
|
|
70
|
+
const errors = validator?.validate(updatedValues);
|
|
102
71
|
return {
|
|
103
72
|
status: "editing",
|
|
104
73
|
values: updatedValues,
|
|
@@ -117,11 +86,12 @@ function createValidator(schema) {
|
|
|
117
86
|
if (validation.success) return void 0;
|
|
118
87
|
return prepareErrors(validation);
|
|
119
88
|
},
|
|
120
|
-
|
|
121
|
-
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- This file is deprecated
|
|
90
|
+
validateAsync: async (entity) => {
|
|
91
|
+
const validation = await schema.safeParseAsync(entity);
|
|
122
92
|
if (validation.success) return void 0;
|
|
123
93
|
return prepareErrors(validation);
|
|
124
|
-
}
|
|
94
|
+
},
|
|
125
95
|
getSchema() {
|
|
126
96
|
return schema;
|
|
127
97
|
}
|
|
@@ -129,7 +99,7 @@ function createValidator(schema) {
|
|
|
129
99
|
}
|
|
130
100
|
function prepareErrors(errorValidation) {
|
|
131
101
|
return new Map(
|
|
132
|
-
errorValidation.error.
|
|
102
|
+
errorValidation.error.issues.map((error) => [
|
|
133
103
|
error.path[0],
|
|
134
104
|
{ message: error.message, code: error.code }
|
|
135
105
|
])
|
package/dist/index.mjs
CHANGED
|
@@ -1,46 +1,9 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
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
|
-
};
|
|
37
|
-
|
|
38
1
|
// src/jotai-form/formUtils.ts
|
|
39
2
|
import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
40
3
|
import { atomFamily } from "jotai/utils";
|
|
41
4
|
function createFormFamily() {
|
|
42
5
|
return atomFamily(
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Deprecated file
|
|
44
7
|
(_param) => atom(void 0),
|
|
45
8
|
(a, b) => a.id === b.id
|
|
46
9
|
);
|
|
@@ -71,8 +34,11 @@ function useFormFamilyMutation(family, param, validator) {
|
|
|
71
34
|
return (update) => {
|
|
72
35
|
return mutate((previous) => {
|
|
73
36
|
if (!previous) return;
|
|
74
|
-
const updatedValues =
|
|
75
|
-
|
|
37
|
+
const updatedValues = {
|
|
38
|
+
...previous.values,
|
|
39
|
+
...update
|
|
40
|
+
};
|
|
41
|
+
const errors = validator?.validate(updatedValues);
|
|
76
42
|
return {
|
|
77
43
|
status: "editing",
|
|
78
44
|
values: updatedValues,
|
|
@@ -91,11 +57,12 @@ function createValidator(schema) {
|
|
|
91
57
|
if (validation.success) return void 0;
|
|
92
58
|
return prepareErrors(validation);
|
|
93
59
|
},
|
|
94
|
-
|
|
95
|
-
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- This file is deprecated
|
|
61
|
+
validateAsync: async (entity) => {
|
|
62
|
+
const validation = await schema.safeParseAsync(entity);
|
|
96
63
|
if (validation.success) return void 0;
|
|
97
64
|
return prepareErrors(validation);
|
|
98
|
-
}
|
|
65
|
+
},
|
|
99
66
|
getSchema() {
|
|
100
67
|
return schema;
|
|
101
68
|
}
|
|
@@ -103,7 +70,7 @@ function createValidator(schema) {
|
|
|
103
70
|
}
|
|
104
71
|
function prepareErrors(errorValidation) {
|
|
105
72
|
return new Map(
|
|
106
|
-
errorValidation.error.
|
|
73
|
+
errorValidation.error.issues.map((error) => [
|
|
107
74
|
error.path[0],
|
|
108
75
|
{ message: error.message, code: error.code }
|
|
109
76
|
])
|
package/package.json
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/apollo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
8
15
|
"files": [
|
|
9
16
|
"dist/**"
|
|
10
17
|
],
|
|
11
18
|
"dependencies": {
|
|
12
|
-
"jotai": "
|
|
13
|
-
"zod": "
|
|
19
|
+
"jotai": "2.17.1",
|
|
20
|
+
"zod": "4.3.6"
|
|
14
21
|
},
|
|
15
22
|
"devDependencies": {
|
|
16
|
-
"@equinor/eds-core-react": "
|
|
17
|
-
"@testing-library/react": "
|
|
18
|
-
"@
|
|
19
|
-
"@types/react": "
|
|
20
|
-
"@types/
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"react": "
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"@equinor/cpl-
|
|
31
|
-
"@equinor/cpl-typescript-config": "0.0.2"
|
|
23
|
+
"@equinor/eds-core-react": "2.3.4",
|
|
24
|
+
"@testing-library/react": "16.3.2",
|
|
25
|
+
"@types/react": "19.2.13",
|
|
26
|
+
"@types/react-dom": "19.2.3",
|
|
27
|
+
"@types/styled-components": "5.1.36",
|
|
28
|
+
"@vitest/ui": "4.0.18",
|
|
29
|
+
"eslint": "10.0.0",
|
|
30
|
+
"jsdom": "28.0.0",
|
|
31
|
+
"react": "19.2.4",
|
|
32
|
+
"react-dom": "19.2.4",
|
|
33
|
+
"styled-components": "6.3.9",
|
|
34
|
+
"tsup": "8.5.1",
|
|
35
|
+
"vitest": "4.0.18",
|
|
36
|
+
"@equinor/cpl-eslint-config": "1.0.4",
|
|
37
|
+
"@equinor/cpl-typescript-config": "0.0.5"
|
|
32
38
|
},
|
|
33
39
|
"peerDependencies": {
|
|
34
40
|
"@equinor/eds-core-react": ">=2.2.0",
|
|
35
|
-
"react": "
|
|
36
|
-
"react-dom": "
|
|
37
|
-
"styled-components": "
|
|
38
|
-
"tsup": "
|
|
41
|
+
"react": ">=18.2.0 <20",
|
|
42
|
+
"react-dom": ">=18.2.0 <20",
|
|
43
|
+
"styled-components": ">=5.3.11",
|
|
44
|
+
"tsup": ">=8.0.1"
|
|
39
45
|
},
|
|
40
46
|
"publishConfig": {
|
|
41
47
|
"access": "public"
|