@ic-reactor/react 2.0.1 → 3.0.0-beta.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.
Files changed (155) hide show
  1. package/README.md +105 -79
  2. package/dist/createActorHooks.d.ts +39 -0
  3. package/dist/createActorHooks.d.ts.map +1 -0
  4. package/dist/createActorHooks.js +30 -0
  5. package/dist/createActorHooks.js.map +1 -0
  6. package/dist/createAuthHooks.d.ts +37 -0
  7. package/dist/createAuthHooks.d.ts.map +1 -0
  8. package/dist/createAuthHooks.js +94 -0
  9. package/dist/createAuthHooks.js.map +1 -0
  10. package/dist/createInfiniteQuery.d.ts +129 -0
  11. package/dist/createInfiniteQuery.d.ts.map +1 -0
  12. package/dist/createInfiniteQuery.js +160 -0
  13. package/dist/createInfiniteQuery.js.map +1 -0
  14. package/dist/createMutation.d.ts +19 -0
  15. package/dist/createMutation.d.ts.map +1 -0
  16. package/dist/createMutation.js +98 -0
  17. package/dist/createMutation.js.map +1 -0
  18. package/dist/createQuery.d.ts +20 -0
  19. package/dist/createQuery.d.ts.map +1 -0
  20. package/dist/createQuery.js +111 -0
  21. package/dist/createQuery.js.map +1 -0
  22. package/dist/createSuspenseInfiniteQuery.d.ts +122 -0
  23. package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -0
  24. package/dist/createSuspenseInfiniteQuery.js +160 -0
  25. package/dist/createSuspenseInfiniteQuery.js.map +1 -0
  26. package/dist/createSuspenseQuery.d.ts +25 -0
  27. package/dist/createSuspenseQuery.d.ts.map +1 -0
  28. package/dist/createSuspenseQuery.js +116 -0
  29. package/dist/createSuspenseQuery.js.map +1 -0
  30. package/dist/hooks/index.d.ts +6 -2
  31. package/dist/hooks/index.d.ts.map +1 -0
  32. package/dist/hooks/index.js +6 -18
  33. package/dist/hooks/index.js.map +1 -0
  34. package/dist/hooks/useActorInfiniteQuery.d.ts +37 -0
  35. package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -0
  36. package/dist/hooks/useActorInfiniteQuery.js +33 -0
  37. package/dist/hooks/useActorInfiniteQuery.js.map +1 -0
  38. package/dist/hooks/useActorMutation.d.ts +23 -0
  39. package/dist/hooks/useActorMutation.d.ts.map +1 -0
  40. package/dist/hooks/useActorMutation.js +39 -0
  41. package/dist/hooks/useActorMutation.js.map +1 -0
  42. package/dist/hooks/useActorQuery.d.ts +32 -0
  43. package/dist/hooks/useActorQuery.d.ts.map +1 -0
  44. package/dist/hooks/useActorQuery.js +35 -0
  45. package/dist/hooks/useActorQuery.js.map +1 -0
  46. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +36 -0
  47. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -0
  48. package/dist/hooks/useActorSuspenseInfiniteQuery.js +33 -0
  49. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -0
  50. package/dist/hooks/useActorSuspenseQuery.d.ts +32 -0
  51. package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -0
  52. package/dist/hooks/useActorSuspenseQuery.js +36 -0
  53. package/dist/hooks/useActorSuspenseQuery.js.map +1 -0
  54. package/dist/index.d.ts +11 -8
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/index.js +17 -49
  57. package/dist/index.js.map +1 -0
  58. package/dist/types.d.ts +232 -13
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +5 -22
  61. package/dist/types.js.map +1 -0
  62. package/dist/validation.d.ts +131 -0
  63. package/dist/validation.d.ts.map +1 -0
  64. package/dist/validation.js +125 -0
  65. package/dist/validation.js.map +1 -0
  66. package/package.json +70 -35
  67. package/LICENSE.md +0 -8
  68. package/dist/context/actor/create.d.ts +0 -63
  69. package/dist/context/actor/create.js +0 -119
  70. package/dist/context/actor/hooks/useActorInterface.d.ts +0 -4
  71. package/dist/context/actor/hooks/useActorInterface.js +0 -10
  72. package/dist/context/actor/hooks/useActorState.d.ts +0 -21
  73. package/dist/context/actor/hooks/useActorState.js +0 -25
  74. package/dist/context/actor/hooks/useActorStore.d.ts +0 -32
  75. package/dist/context/actor/hooks/useActorStore.js +0 -36
  76. package/dist/context/actor/hooks/useInitializeActor.d.ts +0 -6
  77. package/dist/context/actor/hooks/useInitializeActor.js +0 -10
  78. package/dist/context/actor/hooks/useMethod.d.ts +0 -29
  79. package/dist/context/actor/hooks/useMethod.js +0 -34
  80. package/dist/context/actor/hooks/useMethodAttributes.d.ts +0 -7
  81. package/dist/context/actor/hooks/useMethodAttributes.js +0 -11
  82. package/dist/context/actor/hooks/useMethodNames.d.ts +0 -7
  83. package/dist/context/actor/hooks/useMethodNames.js +0 -11
  84. package/dist/context/actor/hooks/useQueryCall.d.ts +0 -28
  85. package/dist/context/actor/hooks/useQueryCall.js +0 -33
  86. package/dist/context/actor/hooks/useUpdateCall.d.ts +0 -29
  87. package/dist/context/actor/hooks/useUpdateCall.js +0 -34
  88. package/dist/context/actor/hooks/useVisitMethod.d.ts +0 -8
  89. package/dist/context/actor/hooks/useVisitMethod.js +0 -13
  90. package/dist/context/actor/hooks/useVisitService.d.ts +0 -8
  91. package/dist/context/actor/hooks/useVisitService.js +0 -13
  92. package/dist/context/actor/index.d.ts +0 -16
  93. package/dist/context/actor/index.js +0 -33
  94. package/dist/context/actor/provider.d.ts +0 -71
  95. package/dist/context/actor/provider.js +0 -75
  96. package/dist/context/actor/types.d.ts +0 -35
  97. package/dist/context/actor/types.js +0 -2
  98. package/dist/context/adapter/create.d.ts +0 -2
  99. package/dist/context/adapter/create.js +0 -102
  100. package/dist/context/adapter/hooks/useCandidAdapter.d.ts +0 -23
  101. package/dist/context/adapter/hooks/useCandidAdapter.js +0 -27
  102. package/dist/context/adapter/hooks/useCandidEvaluation.d.ts +0 -5
  103. package/dist/context/adapter/hooks/useCandidEvaluation.js +0 -9
  104. package/dist/context/adapter/index.d.ts +0 -6
  105. package/dist/context/adapter/index.js +0 -24
  106. package/dist/context/adapter/provider.d.ts +0 -23
  107. package/dist/context/adapter/provider.js +0 -27
  108. package/dist/context/adapter/types.d.ts +0 -52
  109. package/dist/context/adapter/types.js +0 -2
  110. package/dist/context/agent/create.d.ts +0 -74
  111. package/dist/context/agent/create.js +0 -104
  112. package/dist/context/agent/hooks/useAgent.d.ts +0 -14
  113. package/dist/context/agent/hooks/useAgent.js +0 -18
  114. package/dist/context/agent/hooks/useAgentManager.d.ts +0 -14
  115. package/dist/context/agent/hooks/useAgentManager.js +0 -18
  116. package/dist/context/agent/hooks/useAgentState.d.ts +0 -21
  117. package/dist/context/agent/hooks/useAgentState.js +0 -25
  118. package/dist/context/agent/hooks/useAuth.d.ts +0 -57
  119. package/dist/context/agent/hooks/useAuth.js +0 -61
  120. package/dist/context/agent/hooks/useAuthState.d.ts +0 -19
  121. package/dist/context/agent/hooks/useAuthState.js +0 -23
  122. package/dist/context/agent/hooks/useUserPrincipal.d.ts +0 -17
  123. package/dist/context/agent/hooks/useUserPrincipal.js +0 -21
  124. package/dist/context/agent/index.d.ts +0 -12
  125. package/dist/context/agent/index.js +0 -29
  126. package/dist/context/agent/provider.d.ts +0 -28
  127. package/dist/context/agent/provider.js +0 -32
  128. package/dist/context/agent/types.d.ts +0 -17
  129. package/dist/context/agent/types.js +0 -2
  130. package/dist/core.d.ts +0 -1
  131. package/dist/core.js +0 -9
  132. package/dist/createReactor.d.ts +0 -49
  133. package/dist/createReactor.js +0 -69
  134. package/dist/helpers/actorHooks.d.ts +0 -18
  135. package/dist/helpers/actorHooks.js +0 -283
  136. package/dist/helpers/agentHooks.d.ts +0 -3
  137. package/dist/helpers/agentHooks.js +0 -22
  138. package/dist/helpers/authHooks.d.ts +0 -2
  139. package/dist/helpers/authHooks.js +0 -120
  140. package/dist/helpers/extractActorContext.d.ts +0 -4
  141. package/dist/helpers/extractActorContext.js +0 -44
  142. package/dist/helpers/extractAgentContext.d.ts +0 -28
  143. package/dist/helpers/extractAgentContext.js +0 -59
  144. package/dist/helpers/index.d.ts +0 -5
  145. package/dist/helpers/index.js +0 -21
  146. package/dist/helpers/types.d.ts +0 -222
  147. package/dist/helpers/types.js +0 -2
  148. package/dist/hooks/types.d.ts +0 -22
  149. package/dist/hooks/types.js +0 -2
  150. package/dist/hooks/useActor.d.ts +0 -67
  151. package/dist/hooks/useActor.js +0 -197
  152. package/dist/hooks/useActorManager.d.ts +0 -68
  153. package/dist/hooks/useActorManager.js +0 -75
  154. package/dist/utils.d.ts +0 -1
  155. package/dist/utils.js +0 -17
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Validation utilities for React
3
+ *
4
+ * Helpers for working with ValidationError in React components,
5
+ * especially for form integration.
6
+ */
7
+ import { ValidationError, isValidationError, ValidationIssue } from "@ic-reactor/core";
8
+ export { isValidationError, ValidationError };
9
+ export type { ValidationIssue };
10
+ /**
11
+ * A map of field names to error messages.
12
+ * This format is compatible with most form libraries.
13
+ */
14
+ export type FieldErrors = Record<string, string>;
15
+ /**
16
+ * A map of field names to arrays of error messages.
17
+ * Use when you need to show multiple errors per field.
18
+ */
19
+ export type FieldErrorsMultiple = Record<string, string[]>;
20
+ /**
21
+ * Options for mapValidationErrors
22
+ */
23
+ export interface MapValidationErrorsOptions {
24
+ /**
25
+ * If true, returns all messages for each field as an array.
26
+ * If false (default), returns only the first message for each field.
27
+ */
28
+ multiple?: boolean;
29
+ }
30
+ /**
31
+ * Maps validation error issues to a simple field -> message object.
32
+ * Returns the first error message for each field path.
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * const { mutate } = useActorMutation({
37
+ * functionName: "transfer",
38
+ * onError: (error) => {
39
+ * if (isValidationError(error)) {
40
+ * const fieldErrors = mapValidationErrors(error)
41
+ * // { to: "Recipient is required", amount: "Must be a number" }
42
+ *
43
+ * // Use with React Hook Form
44
+ * Object.entries(fieldErrors).forEach(([field, message]) => {
45
+ * form.setError(field, { message })
46
+ * })
47
+ * }
48
+ * }
49
+ * })
50
+ * ```
51
+ */
52
+ export declare function mapValidationErrors(error: ValidationError): FieldErrors;
53
+ export declare function mapValidationErrors(error: ValidationError, options: {
54
+ multiple: true;
55
+ }): FieldErrorsMultiple;
56
+ export declare function mapValidationErrors(error: ValidationError, options: {
57
+ multiple: false;
58
+ }): FieldErrors;
59
+ /**
60
+ * Gets error message for a specific field from a ValidationError.
61
+ * Returns undefined if no error exists for that field.
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * if (isValidationError(error)) {
66
+ * const toError = getFieldError(error, "to")
67
+ * const amountError = getFieldError(error, "amount")
68
+ * }
69
+ * ```
70
+ */
71
+ export declare function getFieldError(error: ValidationError, fieldName: string): string | undefined;
72
+ /**
73
+ * Gets all error messages for a specific field from a ValidationError.
74
+ * Returns empty array if no errors exist for that field.
75
+ *
76
+ * @example
77
+ * ```tsx
78
+ * if (isValidationError(error)) {
79
+ * const amountErrors = getFieldErrors(error, "amount")
80
+ * // ["Amount is required", "Amount must be positive"]
81
+ * }
82
+ * ```
83
+ */
84
+ export declare function getFieldErrors(error: ValidationError, fieldName: string): string[];
85
+ /**
86
+ * Checks if a given error is a ValidationError and optionally
87
+ * extracts field errors in one step.
88
+ *
89
+ * @example
90
+ * ```tsx
91
+ * const { mutateAsync } = useActorMutation({ functionName: "transfer" })
92
+ *
93
+ * const handleSubmit = async (data) => {
94
+ * try {
95
+ * await mutateAsync([data])
96
+ * } catch (error) {
97
+ * const fieldErrors = extractValidationErrors(error)
98
+ * if (fieldErrors) {
99
+ * // Handle validation errors
100
+ * Object.entries(fieldErrors).forEach(([field, message]) => {
101
+ * form.setError(field, { message })
102
+ * })
103
+ * } else {
104
+ * // Handle other errors
105
+ * console.error(error)
106
+ * }
107
+ * }
108
+ * }
109
+ * ```
110
+ */
111
+ export declare function extractValidationErrors(error: unknown): FieldErrors | null;
112
+ /**
113
+ * React hook-friendly error handler that extracts validation errors.
114
+ * Returns a callback suitable for onError handlers.
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * const [fieldErrors, setFieldErrors] = useState<FieldErrors>({})
119
+ *
120
+ * const { mutate } = useActorMutation({
121
+ * functionName: "transfer",
122
+ * onError: handleValidationError(setFieldErrors),
123
+ * })
124
+ *
125
+ * // In JSX
126
+ * <input name="to" />
127
+ * {fieldErrors.to && <span className="error">{fieldErrors.to}</span>}
128
+ * ```
129
+ */
130
+ export declare function handleValidationError(setFieldErrors: (errors: FieldErrors) => void, onOtherError?: (error: Error) => void): (error: Error) => void;
131
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAA;AAC7C,YAAY,EAAE,eAAe,EAAE,CAAA;AAE/B;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEhD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE1D;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,WAAW,CAAA;AACxE,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAC1B,mBAAmB,CAAA;AACtB,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAA;CAAE,GAC3B,WAAW,CAAA;AA2Bd;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAGpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,MAAM,GAChB,MAAM,EAAE,CAIV;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAK1E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,EAC7C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GACpC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CASxB"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Validation utilities for React
3
+ *
4
+ * Helpers for working with ValidationError in React components,
5
+ * especially for form integration.
6
+ */
7
+ import { ValidationError, isValidationError, } from "@ic-reactor/core";
8
+ // Re-export for convenience
9
+ export { isValidationError, ValidationError };
10
+ export function mapValidationErrors(error, options) {
11
+ if (options?.multiple) {
12
+ const result = {};
13
+ for (const issue of error.issues) {
14
+ const fieldName = String(issue.path[0] ?? "");
15
+ if (!result[fieldName]) {
16
+ result[fieldName] = [];
17
+ }
18
+ result[fieldName].push(issue.message);
19
+ }
20
+ return result;
21
+ }
22
+ const result = {};
23
+ for (const issue of error.issues) {
24
+ const fieldName = String(issue.path[0] ?? "");
25
+ if (!result[fieldName]) {
26
+ result[fieldName] = issue.message;
27
+ }
28
+ }
29
+ return result;
30
+ }
31
+ /**
32
+ * Gets error message for a specific field from a ValidationError.
33
+ * Returns undefined if no error exists for that field.
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * if (isValidationError(error)) {
38
+ * const toError = getFieldError(error, "to")
39
+ * const amountError = getFieldError(error, "amount")
40
+ * }
41
+ * ```
42
+ */
43
+ export function getFieldError(error, fieldName) {
44
+ const issue = error.issues.find((i) => String(i.path[0]) === fieldName);
45
+ return issue?.message;
46
+ }
47
+ /**
48
+ * Gets all error messages for a specific field from a ValidationError.
49
+ * Returns empty array if no errors exist for that field.
50
+ *
51
+ * @example
52
+ * ```tsx
53
+ * if (isValidationError(error)) {
54
+ * const amountErrors = getFieldErrors(error, "amount")
55
+ * // ["Amount is required", "Amount must be positive"]
56
+ * }
57
+ * ```
58
+ */
59
+ export function getFieldErrors(error, fieldName) {
60
+ return error.issues
61
+ .filter((i) => String(i.path[0]) === fieldName)
62
+ .map((i) => i.message);
63
+ }
64
+ /**
65
+ * Checks if a given error is a ValidationError and optionally
66
+ * extracts field errors in one step.
67
+ *
68
+ * @example
69
+ * ```tsx
70
+ * const { mutateAsync } = useActorMutation({ functionName: "transfer" })
71
+ *
72
+ * const handleSubmit = async (data) => {
73
+ * try {
74
+ * await mutateAsync([data])
75
+ * } catch (error) {
76
+ * const fieldErrors = extractValidationErrors(error)
77
+ * if (fieldErrors) {
78
+ * // Handle validation errors
79
+ * Object.entries(fieldErrors).forEach(([field, message]) => {
80
+ * form.setError(field, { message })
81
+ * })
82
+ * } else {
83
+ * // Handle other errors
84
+ * console.error(error)
85
+ * }
86
+ * }
87
+ * }
88
+ * ```
89
+ */
90
+ export function extractValidationErrors(error) {
91
+ if (isValidationError(error)) {
92
+ return mapValidationErrors(error);
93
+ }
94
+ return null;
95
+ }
96
+ /**
97
+ * React hook-friendly error handler that extracts validation errors.
98
+ * Returns a callback suitable for onError handlers.
99
+ *
100
+ * @example
101
+ * ```tsx
102
+ * const [fieldErrors, setFieldErrors] = useState<FieldErrors>({})
103
+ *
104
+ * const { mutate } = useActorMutation({
105
+ * functionName: "transfer",
106
+ * onError: handleValidationError(setFieldErrors),
107
+ * })
108
+ *
109
+ * // In JSX
110
+ * <input name="to" />
111
+ * {fieldErrors.to && <span className="error">{fieldErrors.to}</span>}
112
+ * ```
113
+ */
114
+ export function handleValidationError(setFieldErrors, onOtherError) {
115
+ return (error) => {
116
+ const fieldErrors = extractValidationErrors(error);
117
+ if (fieldErrors) {
118
+ setFieldErrors(fieldErrors);
119
+ }
120
+ else if (onOtherError) {
121
+ onOtherError(error);
122
+ }
123
+ };
124
+ }
125
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,iBAAiB,GAElB,MAAM,kBAAkB,CAAA;AAEzB,4BAA4B;AAC5B,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAA;AAyD7C,MAAM,UAAU,mBAAmB,CACjC,KAAsB,EACtB,OAAoC;IAEpC,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC;QACtB,MAAM,MAAM,GAAwB,EAAE,CAAA;QACtC,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;YAC7C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;gBACvB,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAA;YACxB,CAAC;YACD,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACvC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED,MAAM,MAAM,GAAgB,EAAE,CAAA;IAC9B,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAC7C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,OAAO,CAAA;QACnC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAsB,EACtB,SAAiB;IAEjB,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAA;IACvE,OAAO,KAAK,EAAE,OAAO,CAAA;AACvB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAsB,EACtB,SAAiB;IAEjB,OAAO,KAAK,CAAC,MAAM;SAChB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SAC9C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,qBAAqB,CACnC,cAA6C,EAC7C,YAAqC;IAErC,OAAO,CAAC,KAAY,EAAE,EAAE;QACtB,MAAM,WAAW,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAA;QAClD,IAAI,WAAW,EAAE,CAAC;YAChB,cAAc,CAAC,WAAW,CAAC,CAAA;QAC7B,CAAC;aAAM,IAAI,YAAY,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,52 +1,87 @@
1
1
  {
2
2
  "name": "@ic-reactor/react",
3
- "version": "2.0.1",
4
- "description": "A React library for interacting with Internet Computer canisters",
3
+ "version": "3.0.0-beta.1",
4
+ "description": "IC Reactor React Library",
5
5
  "main": "dist/index.js",
6
+ "module": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
7
17
  "files": [
8
- "dist/*"
18
+ "dist",
19
+ "README.md"
9
20
  ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "test": "vitest run",
24
+ "size": "size-limit",
25
+ "analyze": "size-limit --why"
26
+ },
10
27
  "repository": {
11
28
  "type": "git",
12
- "url": "git@github.com:b3hr4d/ic-reactor.git"
29
+ "url": "https://github.com/B3Pay/ic-reactor",
30
+ "directory": "packages/react"
13
31
  },
32
+ "bugs": {
33
+ "url": "https://github.com/B3Pay/ic-reactor/issues"
34
+ },
35
+ "homepage": "https://ic-reactor.dev",
14
36
  "keywords": [
15
- "actor",
16
- "react",
17
- "candid",
37
+ "internet-computer",
38
+ "icp",
18
39
  "dfinity",
40
+ "react",
41
+ "hooks",
19
42
  "web3",
20
- "dapp"
43
+ "blockchain",
44
+ "canister",
45
+ "tanstack-query"
21
46
  ],
22
- "author": "b3hr4d",
47
+ "author": "Behrad Deylami",
23
48
  "license": "MIT",
24
- "bugs": {
25
- "url": "https://github.com/b3hr4d/ic-reactor/issues"
26
- },
27
- "homepage": "https://b3pay.github.io/ic-reactor/modules/react.html",
28
- "scripts": {
29
- "test": "bun test",
30
- "start": "bun run tsc watch",
31
- "build": "bun run tsc",
32
- "clean": "bun run rimraf dist && bun run rimraf umd"
33
- },
34
- "engines": {
35
- "node": ">=22.0.0"
36
- },
37
- "dependencies": {
38
- "@ic-reactor/core": "2.0.1",
39
- "zustand": "^5.0.6",
40
- "zustand-utils": "^2.1.0"
41
- },
42
49
  "peerDependencies": {
43
- "@dfinity/agent": "^3.1.0",
44
- "@dfinity/auth-client": "^3.1.0",
45
- "@dfinity/candid": "^3.1.0",
46
- "@dfinity/identity": "^3.1.0",
47
- "@dfinity/principal": "^3.1.0",
48
- "react": ">=19.0.0",
49
- "zustand": "^5.0.6"
50
+ "react": ">=18.0.0",
51
+ "react-dom": ">=18.0.0",
52
+ "@ic-reactor/core": "workspace:^",
53
+ "@tanstack/react-query": "^5.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@icp-sdk/auth": "^5.0.0",
57
+ "@icp-sdk/core": "^5.0.0",
58
+ "@ic-reactor/core": "workspace:^",
59
+ "@size-limit/preset-small-lib": "^11.2.0",
60
+ "@tanstack/react-query": "^5.90",
61
+ "@testing-library/dom": "^10.4.1",
62
+ "@testing-library/jest-dom": "^6.9.1",
63
+ "@testing-library/react": "^16.3.1",
64
+ "@types/react": "^19.2.7",
65
+ "@types/react-dom": "^19.2.3",
66
+ "fake-indexeddb": "^6.2.5",
67
+ "jsdom": "^27.4.0",
68
+ "react": "^19.2.3",
69
+ "react-dom": "^19.2.3",
70
+ "size-limit": "^11.2.0",
71
+ "vitest": "^4.0.16"
50
72
  },
51
- "gitHead": "1c8f5bfc6b0fea9347602beeebd6443f79d7d54e"
73
+ "size-limit": [
74
+ {
75
+ "name": "React Library",
76
+ "path": "dist/index.js",
77
+ "limit": "30 KB",
78
+ "gzip": true,
79
+ "ignore": [
80
+ "react",
81
+ "react-dom",
82
+ "@ic-reactor/core",
83
+ "@tanstack/react-query"
84
+ ]
85
+ }
86
+ ]
52
87
  }
package/LICENSE.md DELETED
@@ -1,8 +0,0 @@
1
- The MIT License (MIT)
2
- Copyright © 2023 B3Pay
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,63 +0,0 @@
1
- import type { BaseActor } from "../../types";
2
- import type { CreateActorContextParameters, CreateActorContextReturnType } from "./types";
3
- /**
4
- * Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
5
- * This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
6
- *
7
- * @param reactorParameters A partial configuration object for the actor context, allowing customization and specification of actor-related settings.
8
- * - `canisterId`: The default Canister ID to be used if not overridden in the `ActorProvider` component.
9
- * - Other configurations can include properties related to the actor's interaction, such as agent options or authentication requirements.
10
- *
11
- * @returns An object containing the `ActorProvider` component and various hooks for interacting with the actor.
12
- * - `ActorProvider`: A context provider component that allows child components to access and interact with the configured actor.
13
- * - Hooks: Custom hooks derived from the actor context, facilitating interactions like querying or updating the actor's state.
14
- *
15
- * @example
16
- * ```jsx
17
- * import React from 'react';
18
- * import { createActorContext } from '@ic-reactor/react';
19
- * import { backend, canisterId, idlFactory } from './declarations/candid'; // Assuming 'declarations/candid' is where your actor interface is defined.
20
- *
21
- * // Initialize the actor context with configuration options
22
- * const { ActorProvider, useActorState, useQueryCall, useUpdateCall } = createActorContext<typeof backend>({
23
- * canisterId,
24
- * idlFactory, // Optional, wrap the ActorProvider with CandidAdapterProvider
25
- * });
26
- *
27
- * // A sample component that utilizes the actor context
28
- * const App = () => (
29
- * <AgentProvider>
30
- * <ActorProvider>
31
- * <div>
32
- * <h1>IC Actor Interaction Example</h1>
33
- * <ActorComponent />
34
- * </div>
35
- * </ActorProvider>
36
- * </AgentProvider>
37
- * );
38
- *
39
- * export default App;
40
- *
41
- * // A sample component that uses the actor hooks
42
- * const ActorComponent = () => {
43
- * const { data, loading, error } = useQueryCall({
44
- * functionName: 'backendMethodName',
45
- * args: [],
46
- * refetchInterval: 10000,
47
- * refetchOnMount: true,
48
- * });
49
-
50
- * return (
51
- * <div>
52
- * {loading && <p>Loading...</p>}
53
- * {error && <p>Error: {error.message}</p>}
54
- * {data && <p>Actor data: {data}</p>}
55
- * </div>
56
- * );
57
- * };
58
- * ```
59
- *
60
- * This function streamlines the process of setting up a context for IC actor interactions within a React app,
61
- * it provides a type-safe and efficient way to manage actor state and interactions.
62
- */
63
- export declare function createActorContext<A = BaseActor>(contextConfig?: CreateActorContextParameters): CreateActorContextReturnType<A>;
@@ -1,119 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createActorContext = createActorContext;
7
- const react_1 = __importDefault(require("react"));
8
- const useActor_1 = require("../../hooks/useActor");
9
- const extractActorContext_1 = require("../../helpers/extractActorContext");
10
- const useActorManager_1 = require("../../hooks/useActorManager");
11
- /**
12
- * Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
13
- * This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
14
- *
15
- * @param reactorParameters A partial configuration object for the actor context, allowing customization and specification of actor-related settings.
16
- * - `canisterId`: The default Canister ID to be used if not overridden in the `ActorProvider` component.
17
- * - Other configurations can include properties related to the actor's interaction, such as agent options or authentication requirements.
18
- *
19
- * @returns An object containing the `ActorProvider` component and various hooks for interacting with the actor.
20
- * - `ActorProvider`: A context provider component that allows child components to access and interact with the configured actor.
21
- * - Hooks: Custom hooks derived from the actor context, facilitating interactions like querying or updating the actor's state.
22
- *
23
- * @example
24
- * ```jsx
25
- * import React from 'react';
26
- * import { createActorContext } from '@ic-reactor/react';
27
- * import { backend, canisterId, idlFactory } from './declarations/candid'; // Assuming 'declarations/candid' is where your actor interface is defined.
28
- *
29
- * // Initialize the actor context with configuration options
30
- * const { ActorProvider, useActorState, useQueryCall, useUpdateCall } = createActorContext<typeof backend>({
31
- * canisterId,
32
- * idlFactory, // Optional, wrap the ActorProvider with CandidAdapterProvider
33
- * });
34
- *
35
- * // A sample component that utilizes the actor context
36
- * const App = () => (
37
- * <AgentProvider>
38
- * <ActorProvider>
39
- * <div>
40
- * <h1>IC Actor Interaction Example</h1>
41
- * <ActorComponent />
42
- * </div>
43
- * </ActorProvider>
44
- * </AgentProvider>
45
- * );
46
- *
47
- * export default App;
48
- *
49
- * // A sample component that uses the actor hooks
50
- * const ActorComponent = () => {
51
- * const { data, loading, error } = useQueryCall({
52
- * functionName: 'backendMethodName',
53
- * args: [],
54
- * refetchInterval: 10000,
55
- * refetchOnMount: true,
56
- * });
57
-
58
- * return (
59
- * <div>
60
- * {loading && <p>Loading...</p>}
61
- * {error && <p>Error: {error.message}</p>}
62
- * {data && <p>Actor data: {data}</p>}
63
- * </div>
64
- * );
65
- * };
66
- * ```
67
- *
68
- * This function streamlines the process of setting up a context for IC actor interactions within a React app,
69
- * it provides a type-safe and efficient way to manage actor state and interactions.
70
- */
71
- function createActorContext(contextConfig = {}) {
72
- const { canisterId: defaultCanisterId, ...defaultConfig } = contextConfig;
73
- const ActorContext = react_1.default.createContext(null);
74
- const ActorProvider = ({ children, fetchingComponent, canisterId = defaultCanisterId, errorComponent = (error) => react_1.default.createElement("div", null, error), loadingComponent = react_1.default.createElement("div", null, "Loading canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating..."), ...restConfig }) => {
75
- if (!canisterId) {
76
- throw new Error("canisterId is required");
77
- }
78
- const config = react_1.default.useMemo(() => ({
79
- ...defaultConfig,
80
- ...restConfig,
81
- }), [defaultConfig, restConfig]);
82
- const { fetchError, isAuthenticating: authenticating, initializeActor, hooks, } = (0, useActor_1.useActor)({
83
- canisterId,
84
- ...config,
85
- });
86
- const useInitializeActor = react_1.default.useCallback(() => {
87
- return initializeActor;
88
- }, [initializeActor]);
89
- const ActorChildren = ({ useActorState }) => {
90
- const { isInitializing, isInitialized, error } = useActorState();
91
- return isInitializing
92
- ? loadingComponent
93
- : isInitialized
94
- ? children
95
- : error
96
- ? errorComponent(error.message)
97
- : null;
98
- };
99
- return (react_1.default.createElement(ActorContext.Provider, { value: { ...hooks, useInitializeActor } },
100
- fetchingComponent,
101
- hooks === null ? (fetchError ? (errorComponent(fetchError)) : authenticating ? (authenticatingComponent) : (loadingComponent)) : (react_1.default.createElement(ActorChildren, { useActorState: hooks.useActorState }, children))));
102
- };
103
- ActorProvider.displayName = "ActorProvider";
104
- const ActorHookProvider = ({ hooks, children, }) => {
105
- return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, children));
106
- };
107
- const ActorManagerProvider = ({ actorManager, children, }) => {
108
- const { hooks } = (0, useActorManager_1.useActorManager)({
109
- actorManager,
110
- });
111
- return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, children));
112
- };
113
- return {
114
- ActorProvider,
115
- ActorHookProvider,
116
- ActorManagerProvider,
117
- ...(0, extractActorContext_1.extractActorContext)(ActorContext),
118
- };
119
- }
@@ -1,4 +0,0 @@
1
- /**
2
- *
3
- */
4
- export declare function useActorInterface(): import("@dfinity/candid/lib/esm/idl").ServiceClass;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useActorInterface = useActorInterface;
4
- const __1 = require("..");
5
- /**
6
- *
7
- */
8
- function useActorInterface() {
9
- return __1.ActorHooks.useActorInterface();
10
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Hook for accessing the current state of the actor, including the canister ID.
3
- *
4
- * @returns An object containing the current state of the actor from Zustand's store and the canister ID.
5
- * @example
6
- * ```tsx
7
- * function ActorStateComponent() {
8
- * const { canisterId, initializing, error, initialized } = useActorState();
9
- *
10
- * return (
11
- * <div>
12
- * <p>Canister ID: {canisterId}</p>
13
- * <p>Initializing: {initializing.toString()}</p>
14
- * <p>Initialized: {initialized.toString()}</p>
15
- * <p>Error: {error?.message}</p>
16
- * </div>
17
- * );
18
- * }
19
- *```
20
- */
21
- export declare const useActorState: () => import("../../../types").UseActorStateReturnType;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useActorState = void 0;
4
- const __1 = require("..");
5
- /**
6
- * Hook for accessing the current state of the actor, including the canister ID.
7
- *
8
- * @returns An object containing the current state of the actor from Zustand's store and the canister ID.
9
- * @example
10
- * ```tsx
11
- * function ActorStateComponent() {
12
- * const { canisterId, initializing, error, initialized } = useActorState();
13
- *
14
- * return (
15
- * <div>
16
- * <p>Canister ID: {canisterId}</p>
17
- * <p>Initializing: {initializing.toString()}</p>
18
- * <p>Initialized: {initialized.toString()}</p>
19
- * <p>Error: {error?.message}</p>
20
- * </div>
21
- * );
22
- * }
23
- *```
24
- */
25
- exports.useActorState = __1.ActorHooks.useActorState;