@equinor/apollo-utils 0.1.5 → 0.1.7

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,46 @@
1
+ import { PrimitiveAtom } from 'jotai';
2
+ import { AtomFamily } from 'jotai/vanilla/utils/atomFamily';
3
+ import { z } from 'zod';
4
+
5
+ type ValidationErrorMap<T> = Map<keyof T, {
6
+ message: string;
7
+ code: string;
8
+ }>;
9
+
10
+ declare function createValidator<S extends z.ZodTypeAny>(schema: S): {
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;
14
+ };
15
+
16
+ type FormState<T> = {
17
+ status: 'editing' | 'pending';
18
+ values: T;
19
+ errors?: ValidationErrorMap<T>;
20
+ isValid?: boolean;
21
+ };
22
+ type FormFamilyParam = {
23
+ id: number | string;
24
+ } & Record<string, unknown>;
25
+
26
+ declare function createFormFamily<E extends Record<string, unknown>>(): AtomFamily<FormFamilyParam, PrimitiveAtom<FormState<E> | undefined> & {
27
+ init: FormState<E> | undefined;
28
+ }>;
29
+ type FormFamily<T> = AtomFamily<FormFamilyParam, PrimitiveAtom<FormState<T> | undefined>>;
30
+ type FormValidator = ReturnType<typeof createValidator>;
31
+ type UseFormFamilyUtilsOptions = {
32
+ validator?: FormValidator;
33
+ };
34
+ declare function useFormFamilyUtils<T>(family: FormFamily<T>, options?: UseFormFamilyUtilsOptions): {
35
+ useFormStateAtom: (param: FormFamilyParam) => [FormState<T> | undefined, (args_0: FormState<T> | ((prev: FormState<T> | undefined) => FormState<T> | undefined) | undefined) => void];
36
+ useFormState: (param: FormFamilyParam) => FormState<T> | undefined;
37
+ useUpdateFormMutation: (param: FormFamilyParam) => (update: Partial<T>) => void;
38
+ useFormMutations(param: FormFamilyParam): {
39
+ update: (update: Partial<T>) => void;
40
+ initializeForm: (entity: T) => void;
41
+ resetForm: () => void;
42
+ };
43
+ };
44
+ declare function useFormFamilyMutation<T>(family: FormFamily<T>, param: FormFamilyParam, validator?: FormValidator): (update: Partial<T>) => void;
45
+
46
+ export { type FormFamilyParam, type FormState, type ValidationErrorMap, createFormFamily, createValidator, useFormFamilyMutation, useFormFamilyUtils };
package/dist/index.d.ts CHANGED
@@ -43,4 +43,4 @@ declare function useFormFamilyUtils<T>(family: FormFamily<T>, options?: UseFormF
43
43
  };
44
44
  declare function useFormFamilyMutation<T>(family: FormFamily<T>, param: FormFamilyParam, validator?: FormValidator): (update: Partial<T>) => void;
45
45
 
46
- export { FormFamilyParam, FormState, ValidationErrorMap, createFormFamily, createValidator, useFormFamilyMutation, useFormFamilyUtils };
46
+ export { type FormFamilyParam, type FormState, type ValidationErrorMap, createFormFamily, createValidator, useFormFamilyMutation, useFormFamilyUtils };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-utils",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -19,14 +19,14 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "jotai": "^2.0.1",
22
- "tsup": "^6.6.3",
23
- "zod": "^3.20.6"
22
+ "tsup": "^8.0.1",
23
+ "zod": "^3.22.3"
24
24
  },
25
25
  "peerDependencies": {
26
- "@equinor/eds-core-react": "^0.27.0",
26
+ "@equinor/eds-core-react": "^0.35.1",
27
27
  "react": "^18.2.0",
28
28
  "react-dom": "^18.2.0",
29
- "styled-components": "^5.3.7"
29
+ "styled-components": "^5.3.11"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@testing-library/react": "^13.4.0",
@@ -35,7 +35,7 @@
35
35
  "@types/react-dom": "^18.0.1",
36
36
  "@types/styled-components": "^5.1.26",
37
37
  "@vitest/ui": "^0.28.5",
38
- "eslint": "^8.34.0",
38
+ "eslint": "^8.56.0",
39
39
  "eslint-config-custom": "*",
40
40
  "jsdom": "^21.1.0",
41
41
  "tsconfig": "*",