@xyo-network/react-payload-diviner 7.5.7 → 7.5.11
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/browser/contexts/PayloadDiviner/use.d.ts.map +1 -1
- package/dist/browser/index.mjs +89 -122
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +97 -25
- package/src/contexts/DivinedPayload/Context.ts +0 -5
- package/src/contexts/DivinedPayload/Provider.tsx +0 -63
- package/src/contexts/DivinedPayload/State.ts +0 -9
- package/src/contexts/DivinedPayload/index.ts +0 -4
- package/src/contexts/DivinedPayload/use.ts +0 -5
- package/src/contexts/PayloadDiviner/Context.ts +0 -7
- package/src/contexts/PayloadDiviner/Provider.tsx +0 -34
- package/src/contexts/PayloadDiviner/State.ts +0 -8
- package/src/contexts/PayloadDiviner/index.ts +0 -4
- package/src/contexts/PayloadDiviner/use.ts +0 -97
- package/src/contexts/index.ts +0 -2
- package/src/index.ts +0 -1
- package/src/types/images.d.ts +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/use.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKrC,eAAO,MAAM,iBAAiB,GAAI,kBAAgB;;;;;qIAEjD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,GAAG,OAAO,EAC1D,OAAO,MAAM,KACZ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/use.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAKrC,eAAO,MAAM,iBAAiB,GAAI,kBAAgB;;;;;qIAEjD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,GAAG,OAAO,EAC1D,OAAO,MAAM,KACZ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,CAiC1E,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO,GAAG,OAAO,EAC3D,UAAU,MAAM,EAAE,KACjB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,SAAS,CA4CpF,CAAA"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/contexts/DivinedPayload/Context.ts
|
|
5
2
|
import { createContextEx } from "@xylabs/react-shared";
|
|
6
3
|
var DivinedPayloadContext = createContextEx();
|
|
@@ -9,7 +6,7 @@ var DivinedPayloadContext = createContextEx();
|
|
|
9
6
|
import { ErrorRender } from "@xylabs/react-error";
|
|
10
7
|
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
11
8
|
import { useBuildHuri } from "@xyo-network/react-payload-huri";
|
|
12
|
-
import
|
|
9
|
+
import { useMemo as useMemo2 } from "react";
|
|
13
10
|
import { useParams, useSearchParams } from "react-router-dom";
|
|
14
11
|
|
|
15
12
|
// src/contexts/PayloadDiviner/Context.ts
|
|
@@ -18,22 +15,27 @@ var PayloadDivinerContext = createContextEx2();
|
|
|
18
15
|
|
|
19
16
|
// src/contexts/PayloadDiviner/Provider.tsx
|
|
20
17
|
import { useResetState } from "@xylabs/react-hooks";
|
|
21
|
-
import
|
|
22
|
-
|
|
18
|
+
import { useMemo } from "react";
|
|
19
|
+
import { jsx } from "react/jsx-runtime";
|
|
20
|
+
var PayloadDivinerProvider = ({
|
|
21
|
+
diviner: divinerProp,
|
|
22
|
+
required = false,
|
|
23
|
+
children
|
|
24
|
+
}) => {
|
|
23
25
|
const [diviner, setDiviner] = useResetState(divinerProp);
|
|
24
26
|
const value = useMemo(() => ({
|
|
25
27
|
diviner: diviner === divinerProp ? diviner : void 0,
|
|
26
28
|
provided: true,
|
|
27
29
|
setDiviner
|
|
28
|
-
}), [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
30
|
+
}), [diviner, divinerProp, setDiviner]);
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
PayloadDivinerContext,
|
|
33
|
+
{
|
|
34
|
+
value,
|
|
35
|
+
children: diviner ? children : required ? null : children
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
};
|
|
37
39
|
|
|
38
40
|
// src/contexts/PayloadDiviner/use.ts
|
|
39
41
|
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
@@ -41,10 +43,10 @@ import { useContextEx } from "@xylabs/react-shared";
|
|
|
41
43
|
import { exists } from "@xylabs/sdk-js";
|
|
42
44
|
import { HuriSchema } from "@xyo-network/diviner-huri";
|
|
43
45
|
import { useEffect, useState } from "react";
|
|
44
|
-
var usePayloadDiviner =
|
|
46
|
+
var usePayloadDiviner = (required = false) => {
|
|
45
47
|
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
46
|
-
}
|
|
47
|
-
var useDivinePayload =
|
|
48
|
+
};
|
|
49
|
+
var useDivinePayload = (huri) => {
|
|
48
50
|
const { diviner } = usePayloadDiviner();
|
|
49
51
|
const [payload, setPayload] = useState();
|
|
50
52
|
const [error, setError] = useState();
|
|
@@ -52,42 +54,28 @@ var useDivinePayload = /* @__PURE__ */ __name((huri) => {
|
|
|
52
54
|
if (diviner) {
|
|
53
55
|
setPayload(void 0);
|
|
54
56
|
}
|
|
55
|
-
}, [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
]) ?? [];
|
|
70
|
-
if (mounted()) {
|
|
71
|
-
setPayload(payload2 ? payload2 : null);
|
|
72
|
-
}
|
|
73
|
-
} catch (ex) {
|
|
74
|
-
if (mounted()) {
|
|
75
|
-
setError(ex);
|
|
57
|
+
}, [diviner]);
|
|
58
|
+
useAsyncEffect(
|
|
59
|
+
async (mounted) => {
|
|
60
|
+
if (huri && diviner && payload === void 0) {
|
|
61
|
+
try {
|
|
62
|
+
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
63
|
+
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
64
|
+
if (mounted()) {
|
|
65
|
+
setPayload(payload2 || null);
|
|
66
|
+
}
|
|
67
|
+
} catch (ex) {
|
|
68
|
+
if (mounted()) {
|
|
69
|
+
setError(ex);
|
|
70
|
+
}
|
|
76
71
|
}
|
|
77
72
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return [
|
|
85
|
-
payload,
|
|
86
|
-
setPayload,
|
|
87
|
-
error
|
|
88
|
-
];
|
|
89
|
-
}, "useDivinePayload");
|
|
90
|
-
var useDivinePayloads = /* @__PURE__ */ __name((huriList) => {
|
|
73
|
+
},
|
|
74
|
+
[diviner, huri, payload]
|
|
75
|
+
);
|
|
76
|
+
return [payload, setPayload, error];
|
|
77
|
+
};
|
|
78
|
+
var useDivinePayloads = (huriList) => {
|
|
91
79
|
const { diviner } = usePayloadDiviner();
|
|
92
80
|
const [payloads, setPayloads] = useState();
|
|
93
81
|
const [errors, setErrors] = useState();
|
|
@@ -95,61 +83,42 @@ var useDivinePayloads = /* @__PURE__ */ __name((huriList) => {
|
|
|
95
83
|
if (diviner) {
|
|
96
84
|
setPayloads(void 0);
|
|
97
85
|
}
|
|
98
|
-
}, [
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
110
|
-
const [payload] = await diviner?.divine([
|
|
111
|
-
huriPayload
|
|
112
|
-
]) ?? [];
|
|
113
|
-
return payload;
|
|
114
|
-
}));
|
|
115
|
-
if (mounted()) {
|
|
116
|
-
setPayloads([
|
|
117
|
-
...payloads2.values()
|
|
118
|
-
].map((value) => value.status === "rejected" ? null : value.value));
|
|
119
|
-
setErrors([
|
|
120
|
-
...payloads2.values()
|
|
121
|
-
].map((value) => value.status === "rejected" ? new Error("divine failed", {
|
|
122
|
-
cause: value.reason
|
|
123
|
-
}) : void 0).filter(exists));
|
|
86
|
+
}, [diviner]);
|
|
87
|
+
useAsyncEffect(
|
|
88
|
+
async (mounted) => {
|
|
89
|
+
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`);
|
|
90
|
+
const payloads2 = await Promise.allSettled(
|
|
91
|
+
huriList.map(async (huri) => {
|
|
92
|
+
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
93
|
+
const [payload] = await diviner?.divine([huriPayload]) ?? [];
|
|
94
|
+
return payload;
|
|
95
|
+
})
|
|
96
|
+
);
|
|
124
97
|
if (mounted()) {
|
|
125
|
-
setPayloads([
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
98
|
+
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
99
|
+
setErrors(
|
|
100
|
+
[...payloads2.values()].map((value) => value.status === "rejected" ? new Error("divine failed", { cause: value.reason }) : void 0).filter(exists)
|
|
101
|
+
);
|
|
102
|
+
if (mounted()) {
|
|
103
|
+
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
104
|
+
setErrors(
|
|
105
|
+
[...payloads2.values()].map((value) => value.status === "rejected" ? new Error("divine failed", { cause: value.reason }) : void 0).filter(exists)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
133
108
|
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]);
|
|
140
|
-
return [
|
|
141
|
-
payloads,
|
|
142
|
-
setPayloads,
|
|
143
|
-
errors
|
|
144
|
-
];
|
|
145
|
-
}, "useDivinePayloads");
|
|
109
|
+
},
|
|
110
|
+
[diviner, huriList, payloads]
|
|
111
|
+
);
|
|
112
|
+
return [payloads, setPayloads, errors];
|
|
113
|
+
};
|
|
146
114
|
|
|
147
115
|
// src/contexts/DivinedPayload/use.ts
|
|
148
116
|
import { useContextEx as useContextEx2 } from "@xylabs/react-shared";
|
|
149
|
-
var useDivinedPayload =
|
|
117
|
+
var useDivinedPayload = () => useContextEx2(DivinedPayloadContext, "DivinedPayload", true);
|
|
150
118
|
|
|
151
119
|
// src/contexts/DivinedPayload/Provider.tsx
|
|
152
|
-
|
|
120
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
121
|
+
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
153
122
|
const { hash: hashParam } = useParams();
|
|
154
123
|
const huriFromHashParam = useBuildHuri(hashParam);
|
|
155
124
|
const [params] = useSearchParams();
|
|
@@ -162,29 +131,27 @@ var DivinedPayloadProvider = /* @__PURE__ */ __name(({ children, hash }) => {
|
|
|
162
131
|
payloadError,
|
|
163
132
|
provided: true,
|
|
164
133
|
setPayload
|
|
165
|
-
}), [
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
]);
|
|
170
|
-
return /* @__PURE__ */ React2.createElement(DivinedPayloadContext, {
|
|
171
|
-
value
|
|
172
|
-
}, children);
|
|
173
|
-
}, "DivinedPayloadProvider");
|
|
174
|
-
var DivinedPayloadWithHandleInner = /* @__PURE__ */ __name(({ children }) => {
|
|
134
|
+
}), [payload, payloadError, setPayload]);
|
|
135
|
+
return /* @__PURE__ */ jsx2(DivinedPayloadContext, { value, children });
|
|
136
|
+
};
|
|
137
|
+
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
175
138
|
const { payloadError } = useDivinedPayload();
|
|
176
|
-
return /* @__PURE__ */
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
139
|
+
return /* @__PURE__ */ jsx2(
|
|
140
|
+
ErrorRender,
|
|
141
|
+
{
|
|
142
|
+
error: payloadError ? {
|
|
143
|
+
message: payloadError.message,
|
|
144
|
+
schema: ModuleErrorSchema,
|
|
145
|
+
sources: []
|
|
146
|
+
} : void 0,
|
|
147
|
+
errorContext: "Divined Payload Provider",
|
|
148
|
+
children
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
153
|
+
return /* @__PURE__ */ jsx2(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ jsx2(DivinedPayloadWithHandleInner, { children }) });
|
|
154
|
+
};
|
|
188
155
|
export {
|
|
189
156
|
DivinedPayloadContext,
|
|
190
157
|
DivinedPayloadProvider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contexts/DivinedPayload/Context.ts","../../src/contexts/DivinedPayload/Provider.tsx","../../src/contexts/PayloadDiviner/Context.ts","../../src/contexts/PayloadDiviner/Provider.tsx","../../src/contexts/PayloadDiviner/use.ts","../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xylabs/react-shared'\n\nimport type { DivinedPayloadState } from './State.ts'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import { ErrorRender } from '@xylabs/react-error'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\nimport type { PropsWithChildren } from 'react'\nimport React, { useMemo } from 'react'\nimport { useParams, useSearchParams } from 'react-router-dom'\n\nimport { useDivinePayload } from '../PayloadDiviner/index.ts'\nimport { DivinedPayloadContext } from './Context.ts'\nimport type { DivinedPayloadState } from './State.ts'\nimport { useDivinedPayload } from './use.ts'\n\nexport interface DivinedPayloadProviderProps extends PropsWithChildren {\n hash?: string\n}\n\nexport const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({ children, hash }) => {\n const { hash: hashParam } = useParams()\n\n const huriFromHashParam = useBuildHuri(hashParam)\n\n const [params] = useSearchParams()\n const huriSearchParameter = params.get('huri')\n const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? '')\n const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam\n\n const [payload, setPayload, payloadError] = useDivinePayload(huriUri)\n\n const value: DivinedPayloadState = useMemo(() => ({\n payload, payloadError, provided: true, setPayload,\n }), [payload, payloadError, setPayload])\n\n return (\n <DivinedPayloadContext value={value}>\n {children}\n </DivinedPayloadContext>\n )\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<PropsWithChildren> = ({ children }) => {\n const { payloadError } = useDivinedPayload()\n\n return (\n <ErrorRender\n error={payloadError\n ? {\n message: payloadError.message, schema: ModuleErrorSchema, sources: [],\n }\n : undefined}\n errorContext=\"Divined Payload Provider\"\n >\n {children}\n </ErrorRender>\n )\n}\n\nexport const DivinedPayloadWithHandleProvider: React.FC<DivinedPayloadProviderProps> = ({ children, ...props }) => {\n return (\n <DivinedPayloadProvider {...props}>\n <DivinedPayloadWithHandleInner>{children}</DivinedPayloadWithHandleInner>\n </DivinedPayloadProvider>\n )\n}\n","import { createContextEx } from '@xylabs/react-shared'\n\nimport type { PayloadDivinerState } from './State.ts'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { useResetState } from '@xylabs/react-hooks'\nimport type { ContextExProviderProps } from '@xylabs/react-shared'\nimport type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport React, { useMemo } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\nimport type { PayloadDivinerState } from './State.ts'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: PayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({\n diviner: divinerProp, required = false, children,\n}) => {\n const [diviner, setDiviner] = useResetState<PayloadDiviner | undefined>(divinerProp)\n\n const value: PayloadDivinerState = useMemo(() => ({\n diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,\n }), [diviner, divinerProp, setDiviner])\n\n return (\n <PayloadDivinerContext\n value={value}\n >\n {diviner\n ? children\n : required\n ? null\n : children}\n </PayloadDivinerContext>\n )\n}\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { useContextEx } from '@xylabs/react-shared'\nimport { exists } from '@xylabs/sdk-js'\nimport type { HuriPayload } from '@xyo-network/diviner-huri'\nimport { HuriSchema } from '@xyo-network/diviner-huri'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type { Dispatch } from 'react'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\n\nexport const usePayloadDiviner = (required = false) => {\n return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)\n}\n\nexport const useDivinePayload = <T extends Payload = Payload>(\n huri?: string,\n): [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payload, setPayload] = useState<T | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n // we do this to clear the payload when the diviner changes\n if (diviner) {\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n if (huri && diviner && payload === undefined) {\n try {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n if (mounted()) {\n setPayload(payload ? (payload as T) : null)\n }\n } catch (ex) {\n if (mounted()) {\n setError(ex as Error)\n }\n }\n }\n },\n [diviner, huri, payload],\n )\n\n return [payload, setPayload, error]\n}\n\nexport const useDivinePayloads = <T extends Payload = Payload>(\n huriList: string[],\n): [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payloads, setPayloads] = useState<(T | null)[]>()\n const [errors, setErrors] = useState<Error[]>()\n\n useEffect(() => {\n if (diviner) {\n // clear payloads when diviner changes\n setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)\n const payloads = await Promise.allSettled(\n huriList.map(async (huri) => {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n return payload\n }),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","import { useContextEx } from '@xylabs/react-shared'\n\nimport { DivinedPayloadContext } from './Context.ts'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";;;;AAAA,SAASA,uBAAuB;AAIzB,IAAMC,wBAAwBD,gBAAAA;;;ACJrC,SAASE,mBAAmB;AAC5B,SAASC,yBAAyB;AAClC,SAASC,oBAAoB;AAE7B,OAAOC,UAASC,WAAAA,gBAAe;AAC/B,SAASC,WAAWC,uBAAuB;;;ACL3C,SAASC,mBAAAA,wBAAuB;AAIhC,IAAMC,wBAAwBD,iBAAAA;;;ACJ9B,SAASE,qBAAqB;AAG9B,OAAOC,SAASC,eAAe;AAUxB,IAAMC,yBAAgE,wBAAC,EAC5EC,SAASC,aAAaC,WAAW,OAAOC,SAAQ,MACjD;AACC,QAAM,CAACH,SAASI,UAAAA,IAAcC,cAA0CJ,WAAAA;AAExE,QAAMK,QAA6BC,QAAQ,OAAO;IAChDP,SAASA,YAAYC,cAAcD,UAAUQ;IAAWC,UAAU;IAAML;EAC1E,IAAI;IAACJ;IAASC;IAAaG;GAAW;AAEtC,SACE,sBAAA,cAACM,uBAAAA;IACCJ;KAECN,UACGG,WACAD,WACE,OACAC,QAAAA;AAGZ,GApB6E;;;ACb7E,SAASQ,sBAAsB;AAC/B,SAASC,oBAAoB;AAC7B,SAASC,cAAc;AAEvB,SAASC,kBAAkB;AAG3B,SAASC,WAAWC,gBAAgB;AAI7B,IAAMC,oBAAoB,wBAACC,WAAW,UAAK;AAChD,SAAOC,aAAaC,uBAAuB,kBAAkBF,QAAAA;AAC/D,GAFiC;AAI1B,IAAMG,mBAAmB,wBAC9BC,SAAAA;AAEA,QAAM,EAAEC,QAAO,IAAKN,kBAAAA;AACpB,QAAM,CAACO,SAASC,UAAAA,IAAcC,SAAAA;AAC9B,QAAM,CAACC,OAAOC,QAAAA,IAAYF,SAAAA;AAE1BG,YAAU,MAAA;AAER,QAAIN,SAAS;AACXE,iBAAWK,MAAAA;IACb;EACF,G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E;AAuBtE,IAAMsB,gCAA6D,wBAAC,EAAEtB,SAAQ,MAAE;AACrF,QAAM,EAAEe,aAAY,IAAKQ,kBAAAA;AAEzB,SACE,gBAAAH,OAAA,cAACI,aAAAA;IACCC,OAAOV,eACH;MACEW,SAASX,aAAaW;MAASC,QAAQC;MAAmBC,SAAS,CAAA;IACrE,IACAC;IACJC,cAAa;KAEZ/B,QAAAA;AAGP,GAf0E;AAiBnE,IAAMgC,mCAA0E,wBAAC,EAAEhC,UAAU,GAAGiC,MAAAA,MAAO;AAC5G,SACE,gBAAAb,OAAA,cAACrB,wBAA2BkC,OAC1B,gBAAAb,OAAA,cAACE,+BAAAA,MAA+BtB,QAAAA,CAAAA;AAGtC,GANuF;","names":["createContextEx","DivinedPayloadContext","ErrorRender","ModuleErrorSchema","useBuildHuri","React","useMemo","useParams","useSearchParams","createContextEx","PayloadDivinerContext","useResetState","React","useMemo","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useResetState","value","useMemo","undefined","provided","PayloadDivinerContext","useAsyncEffect","useContextEx","exists","HuriSchema","useEffect","useState","usePayloadDiviner","required","useContextEx","PayloadDivinerContext","useDivinePayload","huri","diviner","payload","setPayload","useState","error","setError","useEffect","undefined","useAsyncEffect","mounted","huriPayload","schema","HuriSchema","divine","ex","useDivinePayloads","huriList","payloads","setPayloads","errors","setErrors","console","log","JSON","stringify","Promise","allSettled","map","values","value","status","Error","cause","reason","filter","exists","useContextEx","useDivinedPayload","useContextEx","DivinedPayloadContext","DivinedPayloadProvider","children","hash","hashParam","useParams","huriFromHashParam","useBuildHuri","params","useSearchParams","huriSearchParameter","get","decodedHuriParam","decodeURIComponent","huriUri","payload","setPayload","payloadError","useDivinePayload","value","useMemo","provided","React","DivinedPayloadContext","DivinedPayloadWithHandleInner","useDivinedPayload","ErrorRender","error","message","schema","ModuleErrorSchema","sources","undefined","errorContext","DivinedPayloadWithHandleProvider","props"]}
|
|
1
|
+
{"version":3,"sources":["../../src/contexts/DivinedPayload/Context.ts","../../src/contexts/DivinedPayload/Provider.tsx","../../src/contexts/PayloadDiviner/Context.ts","../../src/contexts/PayloadDiviner/Provider.tsx","../../src/contexts/PayloadDiviner/use.ts","../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xylabs/react-shared'\n\nimport type { DivinedPayloadState } from './State.ts'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import { ErrorRender } from '@xylabs/react-error'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\nimport type { PropsWithChildren } from 'react'\nimport React, { useMemo } from 'react'\nimport { useParams, useSearchParams } from 'react-router-dom'\n\nimport { useDivinePayload } from '../PayloadDiviner/index.ts'\nimport { DivinedPayloadContext } from './Context.ts'\nimport type { DivinedPayloadState } from './State.ts'\nimport { useDivinedPayload } from './use.ts'\n\nexport interface DivinedPayloadProviderProps extends PropsWithChildren {\n hash?: string\n}\n\nexport const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({ children, hash }) => {\n const { hash: hashParam } = useParams()\n\n const huriFromHashParam = useBuildHuri(hashParam)\n\n const [params] = useSearchParams()\n const huriSearchParameter = params.get('huri')\n const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? '')\n const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam\n\n const [payload, setPayload, payloadError] = useDivinePayload(huriUri)\n\n const value: DivinedPayloadState = useMemo(() => ({\n payload, payloadError, provided: true, setPayload,\n }), [payload, payloadError, setPayload])\n\n return (\n <DivinedPayloadContext value={value}>\n {children}\n </DivinedPayloadContext>\n )\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<PropsWithChildren> = ({ children }) => {\n const { payloadError } = useDivinedPayload()\n\n return (\n <ErrorRender\n error={payloadError\n ? {\n message: payloadError.message, schema: ModuleErrorSchema, sources: [],\n }\n : undefined}\n errorContext=\"Divined Payload Provider\"\n >\n {children}\n </ErrorRender>\n )\n}\n\nexport const DivinedPayloadWithHandleProvider: React.FC<DivinedPayloadProviderProps> = ({ children, ...props }) => {\n return (\n <DivinedPayloadProvider {...props}>\n <DivinedPayloadWithHandleInner>{children}</DivinedPayloadWithHandleInner>\n </DivinedPayloadProvider>\n )\n}\n","import { createContextEx } from '@xylabs/react-shared'\n\nimport type { PayloadDivinerState } from './State.ts'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { useResetState } from '@xylabs/react-hooks'\nimport type { ContextExProviderProps } from '@xylabs/react-shared'\nimport type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport React, { useMemo } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\nimport type { PayloadDivinerState } from './State.ts'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: PayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({\n diviner: divinerProp, required = false, children,\n}) => {\n const [diviner, setDiviner] = useResetState<PayloadDiviner | undefined>(divinerProp)\n\n const value: PayloadDivinerState = useMemo(() => ({\n diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,\n }), [diviner, divinerProp, setDiviner])\n\n return (\n <PayloadDivinerContext\n value={value}\n >\n {diviner\n ? children\n : required\n ? null\n : children}\n </PayloadDivinerContext>\n )\n}\n","import { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { useContextEx } from '@xylabs/react-shared'\nimport { exists } from '@xylabs/sdk-js'\nimport type { HuriPayload } from '@xyo-network/diviner-huri'\nimport { HuriSchema } from '@xyo-network/diviner-huri'\nimport type { Payload } from '@xyo-network/payload-model'\nimport type { Dispatch } from 'react'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\n\nexport const usePayloadDiviner = (required = false) => {\n return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)\n}\n\nexport const useDivinePayload = <T extends Payload = Payload>(\n huri?: string,\n): [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payload, setPayload] = useState<T | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n // we do this to clear the payload when the diviner changes\n if (diviner) {\n // eslint-disable-next-line react-hooks/set-state-in-effect, react-x/set-state-in-effect\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n if (huri && diviner && payload === undefined) {\n try {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n if (mounted()) {\n setPayload((payload as T) || null)\n }\n } catch (ex) {\n if (mounted()) {\n setError(ex as Error)\n }\n }\n }\n },\n [diviner, huri, payload],\n )\n\n return [payload, setPayload, error]\n}\n\nexport const useDivinePayloads = <T extends Payload = Payload>(\n huriList: string[],\n): [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payloads, setPayloads] = useState<(T | null)[]>()\n const [errors, setErrors] = useState<Error[]>()\n\n useEffect(() => {\n if (diviner) {\n // clear payloads when diviner changes\n // eslint-disable-next-line react-hooks/set-state-in-effect, react-x/set-state-in-effect\n setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n async (mounted) => {\n console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)\n const payloads = await Promise.allSettled(\n huriList.map(async (huri) => {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n return payload\n }),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n (\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))\n ).filter(exists),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","import { useContextEx } from '@xylabs/react-shared'\n\nimport { DivinedPayloadContext } from './Context.ts'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,wBAAwB,gBAAqC;;;ACJ1E,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAE7B,SAAgB,WAAAA,gBAAe;AAC/B,SAAS,WAAW,uBAAuB;;;ACL3C,SAAS,mBAAAC,wBAAuB;AAIhC,IAAM,wBAAwBA,iBAAqC;;;ACJnE,SAAS,qBAAqB;AAG9B,SAAgB,eAAe;AAoB3B;AAVG,IAAM,yBAAgE,CAAC;AAAA,EAC5E,SAAS;AAAA,EAAa,WAAW;AAAA,EAAO;AAC1C,MAAM;AACJ,QAAM,CAAC,SAAS,UAAU,IAAI,cAA0C,WAAW;AAEnF,QAAM,QAA6B,QAAQ,OAAO;AAAA,IAChD,SAAS,YAAY,cAAc,UAAU;AAAA,IAAW,UAAU;AAAA,IAAM;AAAA,EAC1E,IAAI,CAAC,SAAS,aAAa,UAAU,CAAC;AAEtC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MAEC,oBACG,WACA,WACE,OACA;AAAA;AAAA,EACR;AAEJ;;;ACjCA,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AAEvB,SAAS,kBAAkB;AAG3B,SAAS,WAAW,gBAAgB;AAI7B,IAAM,oBAAoB,CAAC,WAAW,UAAU;AACrD,SAAO,aAAa,uBAAuB,kBAAkB,QAAQ;AACvE;AAEO,IAAM,mBAAmB,CAC9B,SAC8E;AAC9E,QAAM,EAAE,QAAQ,IAAI,kBAAkB;AACtC,QAAM,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BAAiB,OAAO;AAEpE,QAAM,QAA6BC,SAAQ,OAAO;AAAA,IAChD;AAAA,IAAS;AAAA,IAAc,UAAU;AAAA,IAAM;AAAA,EACzC,IAAI,CAAC,SAAS,cAAc,UAAU,CAAC;AAEvC,SACE,gBAAAD,KAAC,yBAAsB,OACpB,UACH;AAEJ;AAEO,IAAM,gCAA6D,CAAC,EAAE,SAAS,MAAM;AAC1F,QAAM,EAAE,aAAa,IAAI,kBAAkB;AAE3C,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,eACH;AAAA,QACE,SAAS,aAAa;AAAA,QAAS,QAAQ;AAAA,QAAmB,SAAS,CAAC;AAAA,MACtE,IACA;AAAA,MACJ,cAAa;AAAA,MAEZ;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,mCAA0E,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AACjH,SACE,gBAAAA,KAAC,0BAAwB,GAAG,OAC1B,0BAAAA,KAAC,iCAA+B,UAAS,GAC3C;AAEJ;","names":["useMemo","createContextEx","payload","payloads","useContextEx","useContextEx","jsx","useMemo"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/react-payload-diviner",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.11",
|
|
4
4
|
"description": "Common React library for all XYO projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xyo",
|
|
@@ -36,44 +36,116 @@
|
|
|
36
36
|
},
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
|
-
"module": "dist/browser/index.mjs",
|
|
40
|
-
"types": "dist/browser/index.d.ts",
|
|
41
39
|
"files": [
|
|
42
40
|
"dist",
|
|
43
|
-
"
|
|
41
|
+
"README.md"
|
|
44
42
|
],
|
|
45
43
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@xylabs/react-error": "~7.1.17",
|
|
48
|
-
"@xylabs/react-hooks": "~7.1.17",
|
|
49
|
-
"@xylabs/react-shared": "~7.1.17",
|
|
50
|
-
"@xylabs/sdk-js": "~5.0.90",
|
|
51
|
-
"@xyo-network/diviner-huri": "~5.3.17",
|
|
52
|
-
"@xyo-network/diviner-payload-abstract": "~5.3.17",
|
|
53
|
-
"@xyo-network/payload-model": "~5.3.17",
|
|
54
|
-
"@xyo-network/react-payload-huri": "7.5.7",
|
|
55
|
-
"react-router-dom": "^7.13.2"
|
|
44
|
+
"@xyo-network/react-payload-huri": "~7.5.11"
|
|
56
45
|
},
|
|
57
46
|
"devDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"@mui/material": "
|
|
47
|
+
"@bitauth/libauth": "~3.0.0",
|
|
48
|
+
"@mui/material": "^7.3.10",
|
|
49
|
+
"@opentelemetry/api": "^1.9.1",
|
|
50
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
51
|
+
"@scure/base": "~2.2.0",
|
|
52
|
+
"@types/node": "~25.6.0",
|
|
60
53
|
"@types/react": "^19.2.14",
|
|
61
|
-
"@xylabs/
|
|
62
|
-
"@xylabs/
|
|
63
|
-
"react": "
|
|
64
|
-
"react-
|
|
54
|
+
"@xylabs/react-async-effect": "~7.1.20",
|
|
55
|
+
"@xylabs/react-dialogs": "~7.1.20",
|
|
56
|
+
"@xylabs/react-error": "~7.1.20",
|
|
57
|
+
"@xylabs/react-hooks": "~7.1.20",
|
|
58
|
+
"@xylabs/react-promise": "~7.1.20",
|
|
59
|
+
"@xylabs/react-quick-tip-button": "~7.1.20",
|
|
60
|
+
"@xylabs/react-select": "~7.1.20",
|
|
61
|
+
"@xylabs/react-shared": "~7.1.20",
|
|
62
|
+
"@xylabs/sdk-js": "^5.0.100",
|
|
63
|
+
"@xylabs/threads": "~5.0.100",
|
|
64
|
+
"@xylabs/toolchain": "~7.11.9",
|
|
65
|
+
"@xylabs/tsconfig": "^7.11.9",
|
|
66
|
+
"@xylabs/tsconfig-dom": "^7.11.9",
|
|
67
|
+
"@xylabs/tsconfig-react": "~7.11.9",
|
|
68
|
+
"@xylabs/zod": "~5.0.100",
|
|
69
|
+
"@xyo-network/account": "~5.5.1",
|
|
70
|
+
"@xyo-network/account-model": "^5.5.1",
|
|
71
|
+
"@xyo-network/boundwitness-builder": "^5.5.1",
|
|
72
|
+
"@xyo-network/boundwitness-model": "^5.5.1",
|
|
73
|
+
"@xyo-network/boundwitness-wrapper": "~5.5.1",
|
|
74
|
+
"@xyo-network/config-payload-plugin": "~5.5.1",
|
|
75
|
+
"@xyo-network/diviner-huri": "~5.5.5",
|
|
76
|
+
"@xyo-network/diviner-model": "^5.5.5",
|
|
77
|
+
"@xyo-network/diviner-payload-abstract": "~5.5.5",
|
|
78
|
+
"@xyo-network/huri": "^5.5.1",
|
|
79
|
+
"@xyo-network/manifest-model": "~5.5.1",
|
|
80
|
+
"@xyo-network/network": "~5.5.1",
|
|
81
|
+
"@xyo-network/payload-builder": "^5.5.1",
|
|
82
|
+
"@xyo-network/payload-model": "^5.5.1",
|
|
83
|
+
"@xyo-network/query-payload-plugin": "~5.5.1",
|
|
84
|
+
"@xyo-network/wallet-model": "^5.5.1",
|
|
85
|
+
"async-mutex": "^0.5.0",
|
|
86
|
+
"axios": "^1.15.2",
|
|
87
|
+
"bn.js": "^5.2.3",
|
|
88
|
+
"buffer": "^6.0.3",
|
|
89
|
+
"chalk": "^5.6.2",
|
|
90
|
+
"debug": "~4.4.3",
|
|
91
|
+
"esbuild": "~0.28.0",
|
|
92
|
+
"eslint": "^10.2.1",
|
|
93
|
+
"ethers": "^6.16.0",
|
|
94
|
+
"hash-wasm": "~4.12.0",
|
|
95
|
+
"lru-cache": "^11.3.5",
|
|
96
|
+
"observable-fns": "~0.6.1",
|
|
97
|
+
"pako": "^2.1.0",
|
|
98
|
+
"react": "^19.2.5",
|
|
99
|
+
"react-dom": "^19.2.5",
|
|
100
|
+
"react-router-dom": "^7.14.2",
|
|
65
101
|
"typescript": "^5.9.3",
|
|
102
|
+
"wasm-feature-detect": "~1.8.0",
|
|
66
103
|
"zod": "^4.3.6"
|
|
67
104
|
},
|
|
68
105
|
"peerDependencies": {
|
|
69
|
-
"@mui/
|
|
70
|
-
"@
|
|
71
|
-
"
|
|
72
|
-
"react-
|
|
106
|
+
"@mui/material": "^7.3.10",
|
|
107
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
108
|
+
"@scure/base": "~2.2.0",
|
|
109
|
+
"@xylabs/react-async-effect": "~7.1.20",
|
|
110
|
+
"@xylabs/react-error": "~7.1.20",
|
|
111
|
+
"@xylabs/react-hooks": "~7.1.20",
|
|
112
|
+
"@xylabs/react-promise": "~7.1.20",
|
|
113
|
+
"@xylabs/react-quick-tip-button": "~7.1.20",
|
|
114
|
+
"@xylabs/react-select": "~7.1.20",
|
|
115
|
+
"@xylabs/react-shared": "~7.1.20",
|
|
116
|
+
"@xylabs/sdk-js": "^5.0.100",
|
|
117
|
+
"@xylabs/tsconfig": "^7.11.9",
|
|
118
|
+
"@xylabs/tsconfig-dom": "^7.11.9",
|
|
119
|
+
"@xyo-network/account": "~5.5.1",
|
|
120
|
+
"@xyo-network/account-model": "^5.5.1",
|
|
121
|
+
"@xyo-network/boundwitness-builder": "^5.5.1",
|
|
122
|
+
"@xyo-network/boundwitness-model": "^5.5.1",
|
|
123
|
+
"@xyo-network/boundwitness-wrapper": "~5.5.1",
|
|
124
|
+
"@xyo-network/config-payload-plugin": "~5.5.1",
|
|
125
|
+
"@xyo-network/diviner-huri": "~5.5.5",
|
|
126
|
+
"@xyo-network/diviner-model": "^5.5.5",
|
|
127
|
+
"@xyo-network/diviner-payload-abstract": "~5.5.5",
|
|
128
|
+
"@xyo-network/huri": "^5.5.1",
|
|
129
|
+
"@xyo-network/manifest-model": "~5.5.1",
|
|
130
|
+
"@xyo-network/network": "~5.5.1",
|
|
131
|
+
"@xyo-network/payload-builder": "^5.5.1",
|
|
132
|
+
"@xyo-network/payload-model": "^5.5.1",
|
|
133
|
+
"@xyo-network/query-payload-plugin": "~5.5.1",
|
|
134
|
+
"@xyo-network/wallet-model": "^5.5.1",
|
|
135
|
+
"async-mutex": "^0.5.0",
|
|
136
|
+
"bn.js": "^5.2.3",
|
|
137
|
+
"buffer": "^6.0.3",
|
|
138
|
+
"chalk": "^5.6.2",
|
|
139
|
+
"ethers": "^6.16.0",
|
|
140
|
+
"lru-cache": "^11.3.5",
|
|
141
|
+
"pako": "^2.1.0",
|
|
142
|
+
"react": "^19.2.5",
|
|
143
|
+
"react-dom": "^19.2.5",
|
|
144
|
+
"react-router-dom": "^7.14.2",
|
|
73
145
|
"zod": "^4.3.6"
|
|
74
146
|
},
|
|
75
147
|
"publishConfig": {
|
|
76
148
|
"access": "public"
|
|
77
149
|
},
|
|
78
150
|
"docs": "dist/docs.json"
|
|
79
|
-
}
|
|
151
|
+
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ErrorRender } from '@xylabs/react-error'
|
|
2
|
-
import { ModuleErrorSchema } from '@xyo-network/payload-model'
|
|
3
|
-
import { useBuildHuri } from '@xyo-network/react-payload-huri'
|
|
4
|
-
import type { PropsWithChildren } from 'react'
|
|
5
|
-
import React, { useMemo } from 'react'
|
|
6
|
-
import { useParams, useSearchParams } from 'react-router-dom'
|
|
7
|
-
|
|
8
|
-
import { useDivinePayload } from '../PayloadDiviner/index.ts'
|
|
9
|
-
import { DivinedPayloadContext } from './Context.ts'
|
|
10
|
-
import type { DivinedPayloadState } from './State.ts'
|
|
11
|
-
import { useDivinedPayload } from './use.ts'
|
|
12
|
-
|
|
13
|
-
export interface DivinedPayloadProviderProps extends PropsWithChildren {
|
|
14
|
-
hash?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({ children, hash }) => {
|
|
18
|
-
const { hash: hashParam } = useParams()
|
|
19
|
-
|
|
20
|
-
const huriFromHashParam = useBuildHuri(hashParam)
|
|
21
|
-
|
|
22
|
-
const [params] = useSearchParams()
|
|
23
|
-
const huriSearchParameter = params.get('huri')
|
|
24
|
-
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? '')
|
|
25
|
-
const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam
|
|
26
|
-
|
|
27
|
-
const [payload, setPayload, payloadError] = useDivinePayload(huriUri)
|
|
28
|
-
|
|
29
|
-
const value: DivinedPayloadState = useMemo(() => ({
|
|
30
|
-
payload, payloadError, provided: true, setPayload,
|
|
31
|
-
}), [payload, payloadError, setPayload])
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<DivinedPayloadContext value={value}>
|
|
35
|
-
{children}
|
|
36
|
-
</DivinedPayloadContext>
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const DivinedPayloadWithHandleInner: React.FC<PropsWithChildren> = ({ children }) => {
|
|
41
|
-
const { payloadError } = useDivinedPayload()
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<ErrorRender
|
|
45
|
-
error={payloadError
|
|
46
|
-
? {
|
|
47
|
-
message: payloadError.message, schema: ModuleErrorSchema, sources: [],
|
|
48
|
-
}
|
|
49
|
-
: undefined}
|
|
50
|
-
errorContext="Divined Payload Provider"
|
|
51
|
-
>
|
|
52
|
-
{children}
|
|
53
|
-
</ErrorRender>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const DivinedPayloadWithHandleProvider: React.FC<DivinedPayloadProviderProps> = ({ children, ...props }) => {
|
|
58
|
-
return (
|
|
59
|
-
<DivinedPayloadProvider {...props}>
|
|
60
|
-
<DivinedPayloadWithHandleInner>{children}</DivinedPayloadWithHandleInner>
|
|
61
|
-
</DivinedPayloadProvider>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ContextExState } from '@xylabs/react-shared'
|
|
2
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
3
|
-
import type { Dispatch } from 'react'
|
|
4
|
-
|
|
5
|
-
export type DivinedPayloadState = ContextExState<{
|
|
6
|
-
payload?: Payload | null
|
|
7
|
-
payloadError?: Error
|
|
8
|
-
setPayload?: Dispatch<Payload | null | undefined>
|
|
9
|
-
}>
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { useResetState } from '@xylabs/react-hooks'
|
|
2
|
-
import type { ContextExProviderProps } from '@xylabs/react-shared'
|
|
3
|
-
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
4
|
-
import React, { useMemo } from 'react'
|
|
5
|
-
|
|
6
|
-
import { PayloadDivinerContext } from './Context.ts'
|
|
7
|
-
import type { PayloadDivinerState } from './State.ts'
|
|
8
|
-
|
|
9
|
-
export type PayloadDivinerProviderProps = ContextExProviderProps<{
|
|
10
|
-
/** Required */
|
|
11
|
-
diviner?: PayloadDiviner
|
|
12
|
-
}>
|
|
13
|
-
|
|
14
|
-
export const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({
|
|
15
|
-
diviner: divinerProp, required = false, children,
|
|
16
|
-
}) => {
|
|
17
|
-
const [diviner, setDiviner] = useResetState<PayloadDiviner | undefined>(divinerProp)
|
|
18
|
-
|
|
19
|
-
const value: PayloadDivinerState = useMemo(() => ({
|
|
20
|
-
diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner,
|
|
21
|
-
}), [diviner, divinerProp, setDiviner])
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<PayloadDivinerContext
|
|
25
|
-
value={value}
|
|
26
|
-
>
|
|
27
|
-
{diviner
|
|
28
|
-
? children
|
|
29
|
-
: required
|
|
30
|
-
? null
|
|
31
|
-
: children}
|
|
32
|
-
</PayloadDivinerContext>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ContextExState } from '@xylabs/react-shared'
|
|
2
|
-
import type { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
3
|
-
import type { Dispatch } from 'react'
|
|
4
|
-
|
|
5
|
-
export type PayloadDivinerState = ContextExState<{
|
|
6
|
-
diviner?: PayloadDiviner
|
|
7
|
-
setDiviner?: Dispatch<PayloadDiviner>
|
|
8
|
-
}>
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { useAsyncEffect } from '@xylabs/react-async-effect'
|
|
2
|
-
import { useContextEx } from '@xylabs/react-shared'
|
|
3
|
-
import { exists } from '@xylabs/sdk-js'
|
|
4
|
-
import type { HuriPayload } from '@xyo-network/diviner-huri'
|
|
5
|
-
import { HuriSchema } from '@xyo-network/diviner-huri'
|
|
6
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
7
|
-
import type { Dispatch } from 'react'
|
|
8
|
-
import { useEffect, useState } from 'react'
|
|
9
|
-
|
|
10
|
-
import { PayloadDivinerContext } from './Context.ts'
|
|
11
|
-
|
|
12
|
-
export const usePayloadDiviner = (required = false) => {
|
|
13
|
-
return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const useDivinePayload = <T extends Payload = Payload>(
|
|
17
|
-
huri?: string,
|
|
18
|
-
): [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined] => {
|
|
19
|
-
const { diviner } = usePayloadDiviner()
|
|
20
|
-
const [payload, setPayload] = useState<T | null>()
|
|
21
|
-
const [error, setError] = useState<Error>()
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
// we do this to clear the payload when the diviner changes
|
|
25
|
-
if (diviner) {
|
|
26
|
-
setPayload(undefined)
|
|
27
|
-
}
|
|
28
|
-
}, [diviner])
|
|
29
|
-
|
|
30
|
-
useAsyncEffect(
|
|
31
|
-
async (mounted) => {
|
|
32
|
-
if (huri && diviner && payload === undefined) {
|
|
33
|
-
try {
|
|
34
|
-
const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }
|
|
35
|
-
const [payload] = (await diviner?.divine([huriPayload])) ?? []
|
|
36
|
-
if (mounted()) {
|
|
37
|
-
setPayload(payload ? (payload as T) : null)
|
|
38
|
-
}
|
|
39
|
-
} catch (ex) {
|
|
40
|
-
if (mounted()) {
|
|
41
|
-
setError(ex as Error)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
[diviner, huri, payload],
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
return [payload, setPayload, error]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const useDivinePayloads = <T extends Payload = Payload>(
|
|
53
|
-
huriList: string[],
|
|
54
|
-
): [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined] => {
|
|
55
|
-
const { diviner } = usePayloadDiviner()
|
|
56
|
-
const [payloads, setPayloads] = useState<(T | null)[]>()
|
|
57
|
-
const [errors, setErrors] = useState<Error[]>()
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (diviner) {
|
|
61
|
-
// clear payloads when diviner changes
|
|
62
|
-
setPayloads(undefined)
|
|
63
|
-
}
|
|
64
|
-
}, [diviner])
|
|
65
|
-
|
|
66
|
-
useAsyncEffect(
|
|
67
|
-
async (mounted) => {
|
|
68
|
-
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)
|
|
69
|
-
const payloads = await Promise.allSettled(
|
|
70
|
-
huriList.map(async (huri) => {
|
|
71
|
-
const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }
|
|
72
|
-
const [payload] = (await diviner?.divine([huriPayload])) ?? []
|
|
73
|
-
return payload
|
|
74
|
-
}),
|
|
75
|
-
)
|
|
76
|
-
if (mounted()) {
|
|
77
|
-
setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])
|
|
78
|
-
setErrors(
|
|
79
|
-
(
|
|
80
|
-
[...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))
|
|
81
|
-
).filter(exists),
|
|
82
|
-
)
|
|
83
|
-
if (mounted()) {
|
|
84
|
-
setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])
|
|
85
|
-
setErrors(
|
|
86
|
-
(
|
|
87
|
-
[...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined))
|
|
88
|
-
).filter(exists),
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
[diviner, huriList, payloads],
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
return [payloads, setPayloads, errors]
|
|
97
|
-
}
|
package/src/contexts/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './contexts/index.ts'
|