@ic-reactor/core 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 (123) hide show
  1. package/dist/client.d.ts +161 -0
  2. package/dist/client.d.ts.map +1 -0
  3. package/dist/client.js +499 -0
  4. package/dist/client.js.map +1 -0
  5. package/dist/display/helper.d.ts +10 -0
  6. package/dist/display/helper.d.ts.map +1 -0
  7. package/dist/display/helper.js +67 -0
  8. package/dist/display/helper.js.map +1 -0
  9. package/dist/display/index.d.ts +4 -0
  10. package/dist/display/index.d.ts.map +1 -0
  11. package/dist/display/index.js +4 -0
  12. package/dist/display/index.js.map +1 -0
  13. package/dist/display/types.d.ts +31 -0
  14. package/dist/display/types.d.ts.map +1 -0
  15. package/dist/display/types.js +2 -0
  16. package/dist/display/types.js.map +1 -0
  17. package/dist/display/visitor.d.ts +28 -0
  18. package/dist/display/visitor.d.ts.map +1 -0
  19. package/dist/display/visitor.js +318 -0
  20. package/dist/display/visitor.js.map +1 -0
  21. package/dist/display-reactor.d.ts +245 -0
  22. package/dist/display-reactor.d.ts.map +1 -0
  23. package/dist/display-reactor.js +331 -0
  24. package/dist/display-reactor.js.map +1 -0
  25. package/dist/errors/index.d.ts +118 -0
  26. package/dist/errors/index.d.ts.map +1 -0
  27. package/dist/errors/index.js +204 -0
  28. package/dist/errors/index.js.map +1 -0
  29. package/dist/index.d.ts +9 -8
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +9 -47
  32. package/dist/index.js.map +1 -0
  33. package/dist/reactor.d.ts +133 -0
  34. package/dist/reactor.d.ts.map +1 -0
  35. package/dist/reactor.js +325 -0
  36. package/dist/reactor.js.map +1 -0
  37. package/dist/types/client.d.ts +89 -0
  38. package/dist/types/client.d.ts.map +1 -0
  39. package/dist/types/client.js +2 -0
  40. package/dist/types/client.js.map +1 -0
  41. package/dist/types/index.d.ts +6 -0
  42. package/dist/types/index.d.ts.map +1 -0
  43. package/dist/types/index.js +6 -0
  44. package/dist/types/index.js.map +1 -0
  45. package/dist/types/reactor.d.ts +117 -0
  46. package/dist/types/reactor.d.ts.map +1 -0
  47. package/dist/types/reactor.js +2 -0
  48. package/dist/types/reactor.js.map +1 -0
  49. package/dist/types/result.d.ts +48 -0
  50. package/dist/types/result.d.ts.map +1 -0
  51. package/dist/types/result.js +2 -0
  52. package/dist/types/result.js.map +1 -0
  53. package/dist/types/transform.d.ts +7 -0
  54. package/dist/types/transform.d.ts.map +1 -0
  55. package/dist/types/transform.js +2 -0
  56. package/dist/types/transform.js.map +1 -0
  57. package/dist/types/variant.d.ts +18 -0
  58. package/dist/types/variant.d.ts.map +1 -0
  59. package/dist/types/variant.js +2 -0
  60. package/dist/types/variant.js.map +1 -0
  61. package/dist/utils/agent.d.ts +30 -1
  62. package/dist/utils/agent.d.ts.map +1 -0
  63. package/dist/utils/agent.js +118 -16
  64. package/dist/utils/agent.js.map +1 -0
  65. package/dist/utils/candid.d.ts +39 -1
  66. package/dist/utils/candid.d.ts.map +1 -0
  67. package/dist/utils/candid.js +76 -16
  68. package/dist/utils/candid.js.map +1 -0
  69. package/dist/utils/constants.d.ts +3 -4
  70. package/dist/utils/constants.d.ts.map +1 -0
  71. package/dist/utils/constants.js +7 -11
  72. package/dist/utils/constants.js.map +1 -0
  73. package/dist/utils/helper.d.ts +16 -39
  74. package/dist/utils/helper.d.ts.map +1 -0
  75. package/dist/utils/helper.js +53 -155
  76. package/dist/utils/helper.js.map +1 -0
  77. package/dist/utils/index.d.ts +4 -5
  78. package/dist/utils/index.d.ts.map +1 -0
  79. package/dist/utils/index.js +5 -49
  80. package/dist/utils/index.js.map +1 -0
  81. package/dist/utils/polling.d.ts +176 -0
  82. package/dist/utils/polling.d.ts.map +1 -0
  83. package/dist/utils/polling.js +170 -0
  84. package/dist/utils/polling.js.map +1 -0
  85. package/dist/version.d.ts +5 -0
  86. package/dist/version.d.ts.map +1 -0
  87. package/dist/version.js +5 -0
  88. package/dist/version.js.map +1 -0
  89. package/package.json +65 -39
  90. package/LICENSE.md +0 -8
  91. package/README.md +0 -283
  92. package/dist/classes/actor/index.d.ts +0 -34
  93. package/dist/classes/actor/index.js +0 -245
  94. package/dist/classes/actor/types.d.ts +0 -113
  95. package/dist/classes/actor/types.js +0 -2
  96. package/dist/classes/adapter/index.d.ts +0 -19
  97. package/dist/classes/adapter/index.js +0 -140
  98. package/dist/classes/adapter/types.d.ts +0 -14
  99. package/dist/classes/adapter/types.js +0 -2
  100. package/dist/classes/agent/index.d.ts +0 -37
  101. package/dist/classes/agent/index.js +0 -221
  102. package/dist/classes/agent/types.d.ts +0 -87
  103. package/dist/classes/agent/types.js +0 -2
  104. package/dist/classes/index.d.ts +0 -3
  105. package/dist/classes/index.js +0 -19
  106. package/dist/classes/types.d.ts +0 -15
  107. package/dist/classes/types.js +0 -20
  108. package/dist/createActorManager.d.ts +0 -12
  109. package/dist/createActorManager.js +0 -17
  110. package/dist/createAgentManager.d.ts +0 -12
  111. package/dist/createAgentManager.js +0 -17
  112. package/dist/createCandidAdapter.d.ts +0 -11
  113. package/dist/createCandidAdapter.js +0 -16
  114. package/dist/createReactorCore.d.ts +0 -10
  115. package/dist/createReactorCore.js +0 -112
  116. package/dist/createReactorStore.d.ts +0 -11
  117. package/dist/createReactorStore.js +0 -31
  118. package/dist/types.d.ts +0 -96
  119. package/dist/types.js +0 -17
  120. package/dist/utils/hash.d.ts +0 -12
  121. package/dist/utils/hash.js +0 -70
  122. package/dist/utils/principal.d.ts +0 -1
  123. package/dist/utils/principal.js +0 -17
@@ -0,0 +1,7 @@
1
+ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
2
+ type Last<T> = UnionToIntersection<T extends any ? (x: T) => void : never> extends (x: infer L) => void ? L : never;
3
+ export type UnionToTuple<T, L = Last<T>> = [T] extends [never] ? [] : [...UnionToTuple<Exclude<T, L>>, L];
4
+ export type IsBlobType<T> = T extends Uint8Array | number[] ? true : false;
5
+ export type IsOptionalType<T> = [T] extends [[] | [any]] ? true : false;
6
+ export {};
7
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/types/transform.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAC7E,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CAAA;AAGT,KAAK,IAAI,CAAC,CAAC,IACT,mBAAmB,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAClE,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CAAA;AAIX,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC1D,EAAE,GACF,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAEvC,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,UAAU,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,KAAK,CAAA;AAE1E,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/types/transform.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ export type IsCandidVariant<T> = [T] extends [CandidVariantToIntersection<T>] ? false : true;
2
+ export type CandidVariantToIntersection<U> = (U extends object ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
3
+ export type CandidVariantKey<T> = T extends any ? keyof T : never;
4
+ export type CandidVariantValue<T, K extends CandidVariantKey<T>> = T extends Record<K, infer U> ? U : never;
5
+ export type CandidVariant<T> = IsCandidVariant<T> extends true ? {
6
+ _type: CandidVariantKey<T> & string;
7
+ } & {
8
+ [K in CandidVariantKey<T> & string as CandidVariantValue<T, K> extends null ? never : K]: CandidVariantValue<T, K>;
9
+ } : T;
10
+ /**
11
+ * A type that represents the extracted key and value from a variant
12
+ * Designed to be used with the extractVariant function
13
+ */
14
+ export type CandidKeyValue<T> = T extends infer U ? [
15
+ CandidVariantKey<U> & string,
16
+ CandidVariantValue<U, CandidVariantKey<U> & string>
17
+ ] : never;
18
+ //# sourceMappingURL=variant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variant.d.ts","sourceRoot":"","sources":["../../src/types/variant.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,GACzE,KAAK,GACL,IAAI,CAAA;AAER,MAAM,MAAM,2BAA2B,CAAC,CAAC,IAAI,CAC3C,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAC1C,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,GAC1B,CAAC,GACD,KAAK,CAAA;AAET,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,MAAM,CAAC,GAAG,KAAK,CAAA;AAEjE,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,IAC7D,CAAC,SAAS,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAE1C,MAAM,MAAM,aAAa,CAAC,CAAC,IACzB,eAAe,CAAC,CAAC,CAAC,SAAS,IAAI,GAC3B;IACE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAA;CACpC,GAAG;KACD,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,kBAAkB,CACtD,CAAC,EACD,CAAC,CACF,SAAS,IAAI,GACV,KAAK,GACL,CAAC,GAAG,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC;CACjC,GACD,CAAC,CAAA;AAEP;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAC7C;IACE,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM;IAC5B,kBAAkB,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;CACpD,GACD,KAAK,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=variant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variant.js","sourceRoot":"","sources":["../../src/types/variant.ts"],"names":[],"mappings":""}
@@ -1 +1,30 @@
1
- export * from "@dfinity/agent";
1
+ import type { ApiQueryResponse, HttpAgent, PollingOptions, SubmitResponse } from "@icp-sdk/core/agent";
2
+ import { Principal } from "@icp-sdk/core/principal";
3
+ /**
4
+ * Process a query call response following the exact logic from @icp-sdk/core/agent Actor.
5
+ *
6
+ * @param response - The query call response options
7
+ * @returns The raw reply bytes
8
+ * @throws CallError if the query was rejected
9
+ */
10
+ export declare function processQueryCallResponse(response: ApiQueryResponse, canisterId: Principal, methodName: string): Uint8Array;
11
+ /**
12
+ * Process an update call response following the exact logic from @icp-sdk/core/agent Actor.
13
+ *
14
+ * This handles:
15
+ * - V4 responses with embedded certificate (sync call response)
16
+ * - V2 responses with immediate rejection
17
+ * - 202 responses that require polling
18
+ *
19
+ * @param result - The submit response from agent.call()
20
+ * @param canisterId - The target canister ID
21
+ * @param methodName - The method name being called
22
+ * @param agent - The HTTP agent
23
+ * @param pollingOptions - Options for polling
24
+ * @param blsVerify - Optional BLS verification function
25
+ * @returns The raw reply bytes
26
+ * @throws RejectError if the call was rejected
27
+ * @throws UnknownError if the response format is unexpected
28
+ */
29
+ export declare function processUpdateCallResponse(result: SubmitResponse, canisterId: Principal, methodName: string, agent: HttpAgent, pollingOptions: PollingOptions): Promise<Uint8Array>;
30
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EAET,cAAc,EACd,cAAc,EACf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAuBnD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,SAAS,EACrB,UAAU,EAAE,MAAM,GACjB,UAAU,CAqBZ;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,SAAS,EACrB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,SAAS,EAChB,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,UAAU,CAAC,CA4GrB"}
@@ -1,17 +1,119 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
1
+ import { isV2ResponseBody, isV4ResponseBody, Certificate, lookupResultToBuffer, pollForResponse, QueryResponseStatus, UncertifiedRejectErrorCode, RejectError, UncertifiedRejectUpdateErrorCode, CertifiedRejectErrorCode, MissingRootKeyErrorCode, ExternalError, UnknownError, UnexpectedErrorCode, } from "@icp-sdk/core/agent";
2
+ // ══════════════════════════════════════════════════════════════════════
3
+ // QUERY CALL RESPONSE PROCESSING
4
+ // ══════════════════════════════════════════════════════════════════════
5
+ /**
6
+ * Process a query call response following the exact logic from @icp-sdk/core/agent Actor.
7
+ *
8
+ * @param response - The query call response options
9
+ * @returns The raw reply bytes
10
+ * @throws CallError if the query was rejected
11
+ */
12
+ export function processQueryCallResponse(response, canisterId, methodName) {
13
+ switch (response.status) {
14
+ case QueryResponseStatus.Rejected: {
15
+ const uncertifiedRejectErrorCode = new UncertifiedRejectErrorCode(response.requestId, response.reject_code, response.reject_message, response.error_code, response.signatures);
16
+ uncertifiedRejectErrorCode.callContext = {
17
+ canisterId,
18
+ methodName,
19
+ httpDetails: response.httpDetails,
20
+ };
21
+ throw RejectError.fromCode(uncertifiedRejectErrorCode);
22
+ }
23
+ case QueryResponseStatus.Replied:
24
+ return response.reply.arg;
7
25
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("@dfinity/agent"), exports);
26
+ }
27
+ // ══════════════════════════════════════════════════════════════════════
28
+ // UPDATE CALL RESPONSE PROCESSING
29
+ // ══════════════════════════════════════════════════════════════════════
30
+ /**
31
+ * Process an update call response following the exact logic from @icp-sdk/core/agent Actor.
32
+ *
33
+ * This handles:
34
+ * - V4 responses with embedded certificate (sync call response)
35
+ * - V2 responses with immediate rejection
36
+ * - 202 responses that require polling
37
+ *
38
+ * @param result - The submit response from agent.call()
39
+ * @param canisterId - The target canister ID
40
+ * @param methodName - The method name being called
41
+ * @param agent - The HTTP agent
42
+ * @param pollingOptions - Options for polling
43
+ * @param blsVerify - Optional BLS verification function
44
+ * @returns The raw reply bytes
45
+ * @throws RejectError if the call was rejected
46
+ * @throws UnknownError if the response format is unexpected
47
+ */
48
+ export async function processUpdateCallResponse(result, canisterId, methodName, agent, pollingOptions) {
49
+ let reply;
50
+ let certificate;
51
+ if (isV4ResponseBody(result.response.body)) {
52
+ if (agent.rootKey == null) {
53
+ throw ExternalError.fromCode(new MissingRootKeyErrorCode());
54
+ }
55
+ const cert = result.response.body.certificate;
56
+ certificate = await Certificate.create({
57
+ certificate: cert,
58
+ rootKey: agent.rootKey,
59
+ principal: { canisterId },
60
+ agent,
61
+ });
62
+ const path = [new TextEncoder().encode("request_status"), result.requestId];
63
+ const status = new TextDecoder().decode(lookupResultToBuffer(certificate.lookup_path([...path, "status"])));
64
+ switch (status) {
65
+ case "replied":
66
+ reply = lookupResultToBuffer(certificate.lookup_path([...path, "reply"]));
67
+ break;
68
+ case "rejected": {
69
+ // Find rejection details in the certificate
70
+ const rejectCode = new Uint8Array(lookupResultToBuffer(certificate.lookup_path([...path, "reject_code"])))[0];
71
+ const rejectMessage = new TextDecoder().decode(lookupResultToBuffer(certificate.lookup_path([...path, "reject_message"])));
72
+ const error_code_buf = lookupResultToBuffer(certificate.lookup_path([...path, "error_code"]));
73
+ const error_code = error_code_buf
74
+ ? new TextDecoder().decode(error_code_buf)
75
+ : undefined;
76
+ const certifiedRejectErrorCode = new CertifiedRejectErrorCode(result.requestId, rejectCode, rejectMessage, error_code);
77
+ certifiedRejectErrorCode.callContext = {
78
+ canisterId,
79
+ methodName,
80
+ httpDetails: result.response,
81
+ };
82
+ throw RejectError.fromCode(certifiedRejectErrorCode);
83
+ }
84
+ }
85
+ }
86
+ else if (isV2ResponseBody(result.response.body)) {
87
+ const { reject_code, reject_message, error_code } = result.response.body;
88
+ const errorCode = new UncertifiedRejectUpdateErrorCode(result.requestId, reject_code, reject_message, error_code);
89
+ errorCode.callContext = {
90
+ canisterId,
91
+ methodName,
92
+ httpDetails: result.response,
93
+ };
94
+ throw RejectError.fromCode(errorCode);
95
+ }
96
+ // Fall back to polling if we receive an Accepted response code
97
+ if (result.response.status === 202) {
98
+ // Contains the certificate and the reply from the boundary node
99
+ const response = await pollForResponse(agent, canisterId, result.requestId, pollingOptions);
100
+ certificate = response.certificate;
101
+ reply = response.reply;
102
+ }
103
+ if (reply !== undefined) {
104
+ return reply;
105
+ }
106
+ // Unexpected response format
107
+ const httpDetails = {
108
+ ...result.response,
109
+ requestDetails: result.requestDetails,
110
+ };
111
+ const errorCode = new UnexpectedErrorCode(`Call was returned undefined. We cannot determine if the call was successful or not.`);
112
+ errorCode.callContext = {
113
+ canisterId,
114
+ methodName,
115
+ httpDetails,
116
+ };
117
+ throw UnknownError.fromCode(errorCode);
118
+ }
119
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/utils/agent.ts"],"names":[],"mappings":"AASA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,0BAA0B,EAC1B,WAAW,EACX,gCAAgC,EAChC,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,mBAAmB,GACpB,MAAM,qBAAqB,CAAA;AAE5B,yEAAyE;AACzE,iCAAiC;AACjC,yEAAyE;AAEzE;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA0B,EAC1B,UAAqB,EACrB,UAAkB;IAElB,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;QACxB,KAAK,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;YAClC,MAAM,0BAA0B,GAAG,IAAI,0BAA0B,CAC/D,QAAQ,CAAC,SAAS,EAClB,QAAQ,CAAC,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I,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;QACxE,MAAM,SAAS,GAAG,IAAI,gCAAgC,CACpD,MAAM,CAAC,SAAS,EAChB,WAAW,EACX,cAAc,EACd,UAAU,CACX,CAAA;QACD,SAAS,CAAC,WAAW,GAAG;YACtB,UAAU;YACV,UAAU;YACV,WAAW,EAAE,MAAM,CAAC,QAAQ;SAC7B,CAAA;QACD,MAAM,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACvC,CAAC;IAED,+DAA+D;IAC/D,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACnC,gEAAgE;QAChE,MAAM,QAAQ,GAAG,MAAM,eAAe,CACpC,KAAK,EACL,UAAU,EACV,MAAM,CAAC,SAAS,EAChB,cAAc,CACf,CAAA;QACD,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAA;QAClC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAA;IACxB,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,6BAA6B;IAC7B,MAAM,WAAW,GAAG;QAClB,GAAG,MAAM,CAAC,QAAQ;QAClB,cAAc,EAAE,MAAM,CAAC,cAAc;KACf,CAAA;IACxB,MAAM,SAAS,GAAG,IAAI,mBAAmB,CACvC,qFAAqF,CACtF,CAAA;IACD,SAAS,CAAC,WAAW,GAAG;QACtB,UAAU;QACV,UAAU;QACV,WAAW;KACZ,CAAA;IACD,MAAM,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACxC,CAAC"}
@@ -1 +1,39 @@
1
- export * from "@dfinity/candid";
1
+ import { CandidVariant, CandidVariantKey, CandidVariantValue, CandidKeyValue } from "../types";
2
+ /**
3
+ * Creates a Candid variant from a string value.
4
+ * @param str - The string to convert into a variant
5
+ * @returns An object representing the Candid variant
6
+ */
7
+ export declare function createNullVariant<T extends string>(str: T): Record<T, null>;
8
+ /**
9
+ * Creates a Candid variant from a record.
10
+ * @param variant - The record to convert into a variant
11
+ * @returns An object representing the Candid variant
12
+ */
13
+ export declare function createVariant<T extends Record<string, any>>(variant: T): CandidVariant<T>;
14
+ /**
15
+ * Extract variant key and value from a variant type
16
+ * Works with types like:
17
+ * type User = { 'Business': BusinessUser } | { 'Individual': IndividualUser }
18
+ *
19
+ * @template T - The variant type
20
+ * @returns A tuple containing the key and value of the variant
21
+ * @throws Error if the variant object does not have exactly one key
22
+ */
23
+ export declare function getVariantKeyValue<T extends Record<string, any>>(variant: T): CandidKeyValue<T>;
24
+ /**
25
+ * Extracts the key from a Candid variant type.
26
+ * Variants in Candid are represented as objects with a single key-value pair.
27
+ * @param variant - The variant object
28
+ * @returns The key of the variant
29
+ */
30
+ export declare function getVariantKey<T extends Record<string, any>>(variant: T): CandidVariantKey<T>;
31
+ /**
32
+ * Extracts the value from a Candid variant type.
33
+ * @param variant - The variant object
34
+ * @returns The value associated with the variant's key
35
+ */
36
+ export declare function getVariantValue<T extends Record<string, any>, K extends CandidVariantKey<T> = CandidVariantKey<T>>(variant: T): CandidVariantValue<T, K>;
37
+ export declare function getVariantValueByKey<T extends Record<string, any>, K extends CandidVariantKey<T>>(variant: T, key: K): CandidVariantValue<T, K>;
38
+ export declare function isKeyMatchVariant<T extends Record<string, any>, K extends CandidVariantKey<T>>(variant: T, key: K): variant is T & Record<K, unknown>;
39
+ //# sourceMappingURL=candid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"candid.d.ts","sourceRoot":"","sources":["../../src/utils/candid.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACf,MAAM,UAAU,CAAA;AAEjB;;;;GAIG;AACH,wBAAg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,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAEvD"}
@@ -1,17 +1,77 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
1
+ /**
2
+ * Creates a Candid variant from a string value.
3
+ * @param str - The string to convert into a variant
4
+ * @returns An object representing the Candid variant
5
+ */
6
+ export function createNullVariant(str) {
7
+ return { [str]: null };
8
+ }
9
+ /**
10
+ * Creates a Candid variant from a record.
11
+ * @param variant - The record to convert into a variant
12
+ * @returns An object representing the Candid variant
13
+ */
14
+ export function createVariant(variant) {
15
+ const keys = Object.keys(variant);
16
+ if (keys.length !== 1) {
17
+ throw new Error(`
18
+ Invalid variant: must have exactly one key but found ${keys.length} keys: ${keys.map((key) => `${key}: ${variant[key]}`)}
19
+ `);
7
20
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("@dfinity/candid"), exports);
21
+ const key = keys[0];
22
+ const value = variant[key];
23
+ return {
24
+ _type: key,
25
+ ...(value !== null ? { [key]: value } : {}),
26
+ };
27
+ }
28
+ /**
29
+ * Extract variant key and value from a variant type
30
+ * Works with types like:
31
+ * type User = { 'Business': BusinessUser } | { 'Individual': IndividualUser }
32
+ *
33
+ * @template T - The variant type
34
+ * @returns A tuple containing the key and value of the variant
35
+ * @throws Error if the variant object does not have exactly one key
36
+ */
37
+ export function getVariantKeyValue(variant) {
38
+ const keys = Object.keys(variant);
39
+ if (keys.length !== 1) {
40
+ const msg = `Invalid variant: must have exactly one key but found ${keys.length} keys: ${keys}`;
41
+ throw new Error(msg);
42
+ }
43
+ const key = keys[0];
44
+ const value = variant[key];
45
+ return [key, value];
46
+ }
47
+ /**
48
+ * Extracts the key from a Candid variant type.
49
+ * Variants in Candid are represented as objects with a single key-value pair.
50
+ * @param variant - The variant object
51
+ * @returns The key of the variant
52
+ */
53
+ export function getVariantKey(variant) {
54
+ const keys = Object.keys(variant);
55
+ if (keys.length !== 1) {
56
+ throw new Error(`Invalid variant: must have exactly one key but found ${keys}`);
57
+ }
58
+ return keys[0];
59
+ }
60
+ /**
61
+ * Extracts the value from a Candid variant type.
62
+ * @param variant - The variant object
63
+ * @returns The value associated with the variant's key
64
+ */
65
+ export function getVariantValue(variant) {
66
+ return variant[getVariantKey(variant)];
67
+ }
68
+ export function getVariantValueByKey(variant, key) {
69
+ if (getVariantKey(variant) !== key) {
70
+ throw new Error(`Variant key mismatch: expected ${key}, got ${getVariantKey(variant)}`);
71
+ }
72
+ return variant[key];
73
+ }
74
+ export function isKeyMatchVariant(variant, key) {
75
+ return getVariantKey(variant) === key;
76
+ }
77
+ //# sourceMappingURL=candid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"candid.js","sourceRoot":"","sources":["../../src/utils/candid.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAmB,GAAM;IACxD,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAqB,CAAA;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAU;IAEV,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC;6DACyC,IAAI,CAAC,MAAM,UAAU,IAAI,CAAC,GAAG,CAClF,CAAC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OAAU;IACV,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAGlC,OAAU,EAAE,GAAM;IAClB,IAAI,aAAa,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,kCAAkC,GAAG,SAAS,aAAa,CAAC,OAAO,CAAC,EAAE,CACvE,CAAA;IACH,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAA;AACrB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAG/B,OAAU,EAAE,GAAM;IAClB,OAAO,aAAa,CAAC,OAAO,CAAC,KAAK,GAAG,CAAA;AACvC,CAAC"}
@@ -2,7 +2,6 @@ export declare const REMOTE_HOSTS: string[];
2
2
  export declare const LOCAL_HOSTS: string[];
3
3
  export declare const IC_HOST_NETWORK_URI = "https://ic0.app";
4
4
  export declare const LOCAL_HOST_NETWORK_URI = "http://127.0.0.1:4943";
5
- export declare const DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
6
- export declare const DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
7
- export declare const IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
8
- export declare const LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
5
+ export declare const IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app";
6
+ export declare const LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943";
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,UAAgC,CAAA;AAEzD,eAAO,MAAM,WAAW,UAA6B,CAAA;AAErD,eAAO,MAAM,mBAAmB,oBAAoB,CAAA;AAEpD,eAAO,MAAM,sBAAsB,0BAA0B,CAAA;AAE7D,eAAO,MAAM,6BAA6B,6BAA6B,CAAA;AAEvE,eAAO,MAAM,gCAAgC,sDACQ,CAAA"}
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LOCAL_INTERNET_IDENTITY_PROVIDER = exports.IC_INTERNET_IDENTITY_PROVIDER = exports.DEFAULT_IC_DIDJS_ID = exports.DEFAULT_LOCAL_DIDJS_ID = exports.LOCAL_HOST_NETWORK_URI = exports.IC_HOST_NETWORK_URI = exports.LOCAL_HOSTS = exports.REMOTE_HOSTS = void 0;
4
- exports.REMOTE_HOSTS = [".github.dev", ".gitpod.io"];
5
- exports.LOCAL_HOSTS = ["localhost", "127.0.0.1"];
6
- exports.IC_HOST_NETWORK_URI = "https://ic0.app";
7
- exports.LOCAL_HOST_NETWORK_URI = "http://127.0.0.1:4943";
8
- exports.DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
9
- exports.DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
10
- exports.IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
11
- exports.LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
1
+ export const REMOTE_HOSTS = [".github.dev", ".gitpod.io"];
2
+ export const LOCAL_HOSTS = ["localhost", "127.0.0.1"];
3
+ export const IC_HOST_NETWORK_URI = "https://ic0.app";
4
+ export const LOCAL_HOST_NETWORK_URI = "http://127.0.0.1:4943";
5
+ export const IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app";
6
+ export const LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943";
7
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;AAEzD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;AAErD,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAA;AAEpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAA;AAE7D,MAAM,CAAC,MAAM,6BAA6B,GAAG,0BAA0B,CAAA;AAEvE,MAAM,CAAC,MAAM,gCAAgC,GAC3C,mDAAmD,CAAA"}
@@ -1,21 +1,5 @@
1
- import { DevtoolsOptions } from "zustand/middleware";
2
- import type { CompiledResult, BaseActor, CandidDefenition, IDL, ExtractOk, StoreWithAllMiddleware } from "../types";
3
- /**
4
- * No operation function that does nothing.
5
- * It can be used as a placeholder or for logging purposes.
6
- */
7
- export declare function noop(): void;
8
- /**
9
- * Creates a Zustand store with optional DevTools middleware.
10
- *
11
- * @param initialState - The initial state of the store.
12
- * @param config - Configuration options for DevTools.
13
- * @returns A Zustand store with DevTools enabled if configured, otherwise a standard store.
14
- */
15
- export declare function createStoreWithOptionalDevtools<T extends object>(initialState: T, config: DevtoolsOptions & {
16
- withDevtools?: boolean;
17
- }): StoreWithAllMiddleware<T>;
18
- export declare const importCandidDefinition: (candidDef: string) => Promise<CandidDefenition>;
1
+ import { OkResult } from "../types";
2
+ export declare const generateKey: (args: any[]) => string;
19
3
  /**
20
4
  * Checks if the current environment is local or development.
21
5
  *
@@ -36,29 +20,22 @@ export declare const getProcessEnvNetwork: () => string;
36
20
  */
37
21
  export declare function getNetworkByHostname(hostname: string): "local" | "remote" | "ic";
38
22
  /**
39
- * Checks if a given IDL function is a query.
40
- *
41
- * @param func - The IDL function to check.
42
- * @returns `true` if the function is a query or composite query, otherwise `false`.
43
- */
44
- export declare function isQuery(func: IDL.FuncClass): boolean;
45
- export declare const jsonToString: (json: unknown, space?: number) => string;
46
- export declare const generateRequestHash: (args?: unknown[]) => `0x${string}`;
47
- export declare const generateHash: (field?: unknown) => `0x${string}`;
48
- export declare const generateActorHash: (actor: BaseActor) => `0x${string}`;
49
- export declare const stringToHash: (str: string) => `0x${string}`;
50
- /**
51
- * Helper function for extracting the value from a compiled result { Ok: T } or { Err: E }
23
+ * Helper function for extracting the value from a compiled result { Ok: T } or throw a CanisterError if { Err: E }
24
+ * Supports both uppercase (Ok/Err - Rust) and lowercase (ok/err - Motoko) conventions.
52
25
  *
53
26
  * @param result - The compiled result to extract from.
54
- * @returns A `CompiledResult` object indicating success or failure.
27
+ * @returns The extracted value from the compiled result.
28
+ * @throws CanisterError with the typed error value if result is { Err: E } or { err: E }
55
29
  */
56
- export declare function createCompiledResult<T>(result: T): CompiledResult<T>;
30
+ export declare function extractOkResult<T>(result: T): OkResult<T>;
31
+ export declare const isNullish: (value: unknown) => value is null | undefined;
32
+ export declare const nonNullish: <T>(value: T | null | undefined) => value is T;
33
+ export declare const uint8ArrayToHex: (bytes: Uint8Array | number[]) => `0x${string}`;
34
+ export declare const hexToUint8Array: (hex: string) => Uint8Array<ArrayBuffer>;
57
35
  /**
58
- * Helper function for extracting the value from a compiled result { Ok: T } or throw the error if { Err: E }
59
- *
60
- * @param result - The compiled result to extract from.
61
- * @returns The extracted value from the compiled result.
62
- * @throws The error from the compiled result.
36
+ * Converts a JSON-serializable value to a string, handling BigInt values.
37
+ * @param value - The value to convert
38
+ * @returns A string representation of the value
63
39
  */
64
- export declare function extractOkResult<T>(result: T): ExtractOk<T>;
40
+ export declare const jsonToString: (value: any) => string;
41
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/utils/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,eAAO,MAAM,WAAW,GAAI,MAAM,GAAG,EAAE,WAItC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,eAElC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,cAGhC,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,GACf,OAAO,GAAG,QAAQ,GAAG,IAAI,CAQ3B;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CA0BzD;AAED,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAAI,GAAG,SACpB,CAAA;AAEvC,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,KAAG,KAAK,IAAI,CAC9B,CAAA;AAEvC,eAAO,MAAM,eAAe,GAC1B,OAAO,UAAU,GAAG,MAAM,EAAE,KAC3B,KAAK,MAAM,EAKb,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,KAAG,UAAU,CAAC,WAAW,CAOnE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,GAAG,KAAG,MAMzC,CAAA"}