@xyo-network/react-payload-diviner 2.64.9 → 2.65.0
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.cts +4 -4
- package/dist/browser/contexts/PayloadDiviner/use.d.cts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.mts +4 -4
- package/dist/browser/contexts/PayloadDiviner/use.d.mts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.ts +4 -4
- package/dist/browser/contexts/PayloadDiviner/use.d.ts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.cts +4 -4
- package/dist/node/contexts/PayloadDiviner/use.d.cts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.mts +4 -4
- package/dist/node/contexts/PayloadDiviner/use.d.mts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.ts +4 -4
- package/dist/node/contexts/PayloadDiviner/use.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/browser/contexts/DivinedPayload/Context.cjs +0 -28
- package/dist/browser/contexts/DivinedPayload/Context.cjs.map +0 -1
- package/dist/browser/contexts/DivinedPayload/Context.js +0 -7
- package/dist/browser/contexts/DivinedPayload/Context.js.map +0 -1
- package/dist/browser/contexts/DivinedPayload/Provider.cjs +0 -111
- package/dist/browser/contexts/DivinedPayload/Provider.cjs.map +0 -1
- package/dist/browser/contexts/DivinedPayload/Provider.js +0 -90
- package/dist/browser/contexts/DivinedPayload/Provider.js.map +0 -1
- package/dist/browser/contexts/DivinedPayload/State.cjs +0 -19
- package/dist/browser/contexts/DivinedPayload/State.cjs.map +0 -1
- package/dist/browser/contexts/DivinedPayload/State.js +0 -1
- package/dist/browser/contexts/DivinedPayload/State.js.map +0 -1
- package/dist/browser/contexts/DivinedPayload/index.cjs +0 -115
- package/dist/browser/contexts/DivinedPayload/index.cjs.map +0 -1
- package/dist/browser/contexts/DivinedPayload/index.js +0 -92
- package/dist/browser/contexts/DivinedPayload/index.js.map +0 -1
- package/dist/browser/contexts/DivinedPayload/use.cjs +0 -34
- package/dist/browser/contexts/DivinedPayload/use.cjs.map +0 -1
- package/dist/browser/contexts/DivinedPayload/use.js +0 -13
- package/dist/browser/contexts/DivinedPayload/use.js.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/Context.cjs +0 -28
- package/dist/browser/contexts/PayloadDiviner/Context.cjs.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/Context.js +0 -7
- package/dist/browser/contexts/PayloadDiviner/Context.js.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/Provider.cjs +0 -53
- package/dist/browser/contexts/PayloadDiviner/Provider.cjs.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/Provider.js +0 -32
- package/dist/browser/contexts/PayloadDiviner/Provider.js.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/State.cjs +0 -19
- package/dist/browser/contexts/PayloadDiviner/State.cjs.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/State.js +0 -1
- package/dist/browser/contexts/PayloadDiviner/State.js.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/index.cjs +0 -136
- package/dist/browser/contexts/PayloadDiviner/index.cjs.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/index.js +0 -113
- package/dist/browser/contexts/PayloadDiviner/index.js.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/use.cjs +0 -111
- package/dist/browser/contexts/PayloadDiviner/use.cjs.map +0 -1
- package/dist/browser/contexts/PayloadDiviner/use.js +0 -90
- package/dist/browser/contexts/PayloadDiviner/use.js.map +0 -1
- package/dist/browser/contexts/index.cjs +0 -182
- package/dist/browser/contexts/index.cjs.map +0 -1
- package/dist/browser/contexts/index.js +0 -159
- package/dist/browser/contexts/index.js.map +0 -1
- package/dist/browser/types/images.d.cjs +0 -2
- package/dist/browser/types/images.d.cjs.map +0 -1
- package/dist/browser/types/images.d.js +0 -1
- package/dist/browser/types/images.d.js.map +0 -1
- package/dist/docs.json +0 -1796
- package/dist/node/contexts/DivinedPayload/Context.cjs +0 -32
- package/dist/node/contexts/DivinedPayload/Context.cjs.map +0 -1
- package/dist/node/contexts/DivinedPayload/Context.js +0 -7
- package/dist/node/contexts/DivinedPayload/Context.js.map +0 -1
- package/dist/node/contexts/DivinedPayload/Provider.cjs +0 -117
- package/dist/node/contexts/DivinedPayload/Provider.cjs.map +0 -1
- package/dist/node/contexts/DivinedPayload/Provider.js +0 -90
- package/dist/node/contexts/DivinedPayload/Provider.js.map +0 -1
- package/dist/node/contexts/DivinedPayload/State.cjs +0 -19
- package/dist/node/contexts/DivinedPayload/State.cjs.map +0 -1
- package/dist/node/contexts/DivinedPayload/State.js +0 -1
- package/dist/node/contexts/DivinedPayload/State.js.map +0 -1
- package/dist/node/contexts/DivinedPayload/index.cjs +0 -123
- package/dist/node/contexts/DivinedPayload/index.cjs.map +0 -1
- package/dist/node/contexts/DivinedPayload/index.js +0 -92
- package/dist/node/contexts/DivinedPayload/index.js.map +0 -1
- package/dist/node/contexts/DivinedPayload/use.cjs +0 -38
- package/dist/node/contexts/DivinedPayload/use.cjs.map +0 -1
- package/dist/node/contexts/DivinedPayload/use.js +0 -13
- package/dist/node/contexts/DivinedPayload/use.js.map +0 -1
- package/dist/node/contexts/PayloadDiviner/Context.cjs +0 -32
- package/dist/node/contexts/PayloadDiviner/Context.cjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/Context.js +0 -7
- package/dist/node/contexts/PayloadDiviner/Context.js.map +0 -1
- package/dist/node/contexts/PayloadDiviner/Provider.cjs +0 -57
- package/dist/node/contexts/PayloadDiviner/Provider.cjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/Provider.js +0 -32
- package/dist/node/contexts/PayloadDiviner/Provider.js.map +0 -1
- package/dist/node/contexts/PayloadDiviner/State.cjs +0 -19
- package/dist/node/contexts/PayloadDiviner/State.cjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/State.js +0 -1
- package/dist/node/contexts/PayloadDiviner/State.js.map +0 -1
- package/dist/node/contexts/PayloadDiviner/index.cjs +0 -144
- package/dist/node/contexts/PayloadDiviner/index.cjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/index.js +0 -113
- package/dist/node/contexts/PayloadDiviner/index.js.map +0 -1
- package/dist/node/contexts/PayloadDiviner/use.cjs +0 -117
- package/dist/node/contexts/PayloadDiviner/use.cjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/use.js +0 -90
- package/dist/node/contexts/PayloadDiviner/use.js.map +0 -1
- package/dist/node/contexts/index.cjs +0 -195
- package/dist/node/contexts/index.cjs.map +0 -1
- package/dist/node/contexts/index.js +0 -159
- package/dist/node/contexts/index.js.map +0 -1
- package/dist/node/types/images.d.cjs +0 -2
- package/dist/node/types/images.d.cjs.map +0 -1
- package/dist/node/types/images.d.js +0 -1
- package/dist/node/types/images.d.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/index.ts","../../../../src/contexts/DivinedPayload/Context.tsx","../../../../src/contexts/DivinedPayload/Provider.tsx","../../../../src/contexts/PayloadDiviner/Context.ts","../../../../src/contexts/PayloadDiviner/use.ts","../../../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["export * from './Context'\nexport * from './Provider'\nexport * from './State'\nexport * from './use'\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import type { WithChildren } from '@xylabs/react-shared'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { ErrorRender } from '@xyo-network/react-error'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\nimport { useParams, useSearchParams } from 'react-router-dom'\n\nimport { useDivinePayload } from '../PayloadDiviner'\nimport { DivinedPayloadContext } from './Context'\nimport { useDivinedPayload } from './use'\n\nexport interface DivinedPayloadProviderProps extends WithChildren {\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 ? decodedHuriParam : huriFromHashParam)\n\n const [payload, setPayload, payloadError] = useDivinePayload(huriUri)\n\n return <DivinedPayloadContext.Provider value={{ payload, payloadError, provided: true, setPayload }}>{children}</DivinedPayloadContext.Provider>\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<WithChildren> = ({ children }) => {\n const { payloadError } = useDivinedPayload()\n\n return (\n <ErrorRender\n error={payloadError ? { message: payloadError.message, schema: ModuleErrorSchema, sources: [] } : 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 '@xyo-network/react-shared'\n\nimport { PayloadDivinerState } from './State'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { compact } from '@xylabs/lodash'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { HuriPayload, HuriSchema } from '@xyo-network/diviner'\nimport { Payload } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\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 if (diviner) {\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 compact([...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined))),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map((value) => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n compact(\n [...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined)),\n ),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadContext } from './Context'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAgC;AAIzB,IAAM,4BAAwB,qCAAqC;;;ACH1E,2BAAkC;AAClC,yBAA4B;AAC5B,gCAA6B;AAC7B,8BAA2C;;;ACJ3C,IAAAA,uBAAgC;AAIhC,IAAM,4BAAwB,sCAAqC;;;ACJnE,oBAAwB;AACxB,gCAA+B;AAC/B,qBAAwC;AAExC,IAAAC,uBAA6B;AAC7B,mBAA8C;AAIvC,IAAM,oBAAoB,CAAC,WAAW,UAAU;AACrD,aAAO,mCAAa,uBAAuB,kBAAkB,QAAQ;AACvE;AAEO,IAAM,mBAAmB,CAC9B,SAC8E;AAC9E,QAAM,EAAE,QAAQ,IAAI,kBAAkB;AACtC,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAmB;AACjD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAgB;AAE1C,8BAAU,MAAM;AACd,QAAI,SAAS;AACX,iBAAW,MAAS;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ;AAAA;AAAA,IAEE,OAAO,YAAY;AACjB,UAAI,QAAQ,WAAW,YAAY,QAAW;AAC5C,YAAI;AACF,gBAAM,cAA2B,EAAE,MAAM,CAAC,IAAI,GAAG,QAAQ,0BAAW;AACpE,gBAAM,CAACC,QAAO,IAAK,MAAM,SAAS,OAAO,CAAC,WAAW,CAAC,KAAM,CAAC;AAC7D,cAAI,QAAQ,GAAG;AACb,uBAAWA,WAAWA,WAAgB,IAAI;AAAA,UAC5C;AAAA,QACF,SAAS,IAAI;AACX,cAAI,QAAQ,GAAG;AACb,qBAAS,EAAW;AAAA,UACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,SAAS,MAAM,OAAO;AAAA,EACzB;AAEA,SAAO,CAAC,SAAS,YAAY,KAAK;AACpC;;;AC/CA,IAAAC,uBAA6B;AAItB,IAAM,oBAAoB,UAAM,mCAAa,uBAAuB,kBAAkB,IAAI;;;AHsBxF;AAZF,IAAM,yBAAgE,CAAC,EAAE,UAAU,KAAK,MAAM;AACnG,QAAM,EAAE,MAAM,UAAU,QAAI,mCAAU;AAEtC,QAAM,wBAAoB,wCAAa,SAAS;AAEhD,QAAM,CAAC,MAAM,QAAI,yCAAgB;AACjC,QAAM,sBAAsB,OAAO,IAAI,MAAM;AAC7C,QAAM,mBAAmB,mBAAmB,uBAAuB,EAAE;AACrE,QAAM,UAAU,SAAS,mBAAmB,mBAAmB;AAE/D,QAAM,CAAC,SAAS,YAAY,YAAY,IAAI,iBAAiB,OAAO;AAEpE,SAAO,4CAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,SAAS,cAAc,UAAU,MAAM,WAAW,GAAI,UAAS;AACjH;AAEO,IAAM,gCAAwD,CAAC,EAAE,SAAS,MAAM;AACrF,QAAM,EAAE,aAAa,IAAI,kBAAkB;AAE3C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,eAAe,EAAE,SAAS,aAAa,SAAS,QAAQ,wCAAmB,SAAS,CAAC,EAAE,IAAI;AAAA,MAClG,cAAa;AAAA,MAEZ;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,mCAA0E,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AACjH,SACE,4CAAC,0BAAwB,GAAG,OAC1B,sDAAC,iCAA+B,UAAS,GAC3C;AAEJ;","names":["import_react_shared","import_react_shared","payload","import_react_shared"]}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// src/contexts/DivinedPayload/Context.tsx
|
|
2
|
-
import { createContextEx } from "@xyo-network/react-shared";
|
|
3
|
-
var DivinedPayloadContext = createContextEx();
|
|
4
|
-
|
|
5
|
-
// src/contexts/DivinedPayload/Provider.tsx
|
|
6
|
-
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
7
|
-
import { ErrorRender } from "@xyo-network/react-error";
|
|
8
|
-
import { useBuildHuri } from "@xyo-network/react-payload-huri";
|
|
9
|
-
import { useParams, useSearchParams } from "react-router-dom";
|
|
10
|
-
|
|
11
|
-
// src/contexts/PayloadDiviner/Context.ts
|
|
12
|
-
import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
|
|
13
|
-
var PayloadDivinerContext = createContextEx2();
|
|
14
|
-
|
|
15
|
-
// src/contexts/PayloadDiviner/use.ts
|
|
16
|
-
import { compact } from "@xylabs/lodash";
|
|
17
|
-
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
18
|
-
import { HuriSchema } from "@xyo-network/diviner";
|
|
19
|
-
import { useContextEx } from "@xyo-network/react-shared";
|
|
20
|
-
import { useEffect, useState } from "react";
|
|
21
|
-
var usePayloadDiviner = (required = false) => {
|
|
22
|
-
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
23
|
-
};
|
|
24
|
-
var useDivinePayload = (huri) => {
|
|
25
|
-
const { diviner } = usePayloadDiviner();
|
|
26
|
-
const [payload, setPayload] = useState();
|
|
27
|
-
const [error, setError] = useState();
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (diviner) {
|
|
30
|
-
setPayload(void 0);
|
|
31
|
-
}
|
|
32
|
-
}, [diviner]);
|
|
33
|
-
useAsyncEffect(
|
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
async (mounted) => {
|
|
36
|
-
if (huri && diviner && payload === void 0) {
|
|
37
|
-
try {
|
|
38
|
-
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
39
|
-
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
40
|
-
if (mounted()) {
|
|
41
|
-
setPayload(payload2 ? payload2 : null);
|
|
42
|
-
}
|
|
43
|
-
} catch (ex) {
|
|
44
|
-
if (mounted()) {
|
|
45
|
-
setError(ex);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
[diviner, huri, payload]
|
|
51
|
-
);
|
|
52
|
-
return [payload, setPayload, error];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/contexts/DivinedPayload/use.ts
|
|
56
|
-
import { useContextEx as useContextEx2 } from "@xyo-network/react-shared";
|
|
57
|
-
var useDivinedPayload = () => useContextEx2(DivinedPayloadContext, "DivinedPayload", true);
|
|
58
|
-
|
|
59
|
-
// src/contexts/DivinedPayload/Provider.tsx
|
|
60
|
-
import { jsx } from "react/jsx-runtime";
|
|
61
|
-
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
62
|
-
const { hash: hashParam } = useParams();
|
|
63
|
-
const huriFromHashParam = useBuildHuri(hashParam);
|
|
64
|
-
const [params] = useSearchParams();
|
|
65
|
-
const huriSearchParameter = params.get("huri");
|
|
66
|
-
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
67
|
-
const huriUri = hash ?? (decodedHuriParam ? decodedHuriParam : huriFromHashParam);
|
|
68
|
-
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
69
|
-
return /* @__PURE__ */ jsx(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
70
|
-
};
|
|
71
|
-
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
72
|
-
const { payloadError } = useDivinedPayload();
|
|
73
|
-
return /* @__PURE__ */ jsx(
|
|
74
|
-
ErrorRender,
|
|
75
|
-
{
|
|
76
|
-
error: payloadError ? { message: payloadError.message, schema: ModuleErrorSchema, sources: [] } : void 0,
|
|
77
|
-
errorContext: "Divined Payload Provider",
|
|
78
|
-
children
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
83
|
-
return /* @__PURE__ */ jsx(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ jsx(DivinedPayloadWithHandleInner, { children }) });
|
|
84
|
-
};
|
|
85
|
-
export {
|
|
86
|
-
DivinedPayloadContext,
|
|
87
|
-
DivinedPayloadProvider,
|
|
88
|
-
DivinedPayloadWithHandleInner,
|
|
89
|
-
DivinedPayloadWithHandleProvider,
|
|
90
|
-
useDivinedPayload
|
|
91
|
-
};
|
|
92
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Context.tsx","../../../../src/contexts/DivinedPayload/Provider.tsx","../../../../src/contexts/PayloadDiviner/Context.ts","../../../../src/contexts/PayloadDiviner/use.ts","../../../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import type { WithChildren } from '@xylabs/react-shared'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport { ErrorRender } from '@xyo-network/react-error'\nimport { useBuildHuri } from '@xyo-network/react-payload-huri'\nimport { useParams, useSearchParams } from 'react-router-dom'\n\nimport { useDivinePayload } from '../PayloadDiviner'\nimport { DivinedPayloadContext } from './Context'\nimport { useDivinedPayload } from './use'\n\nexport interface DivinedPayloadProviderProps extends WithChildren {\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 ? decodedHuriParam : huriFromHashParam)\n\n const [payload, setPayload, payloadError] = useDivinePayload(huriUri)\n\n return <DivinedPayloadContext.Provider value={{ payload, payloadError, provided: true, setPayload }}>{children}</DivinedPayloadContext.Provider>\n}\n\nexport const DivinedPayloadWithHandleInner: React.FC<WithChildren> = ({ children }) => {\n const { payloadError } = useDivinedPayload()\n\n return (\n <ErrorRender\n error={payloadError ? { message: payloadError.message, schema: ModuleErrorSchema, sources: [] } : 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 '@xyo-network/react-shared'\n\nimport { PayloadDivinerState } from './State'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { compact } from '@xylabs/lodash'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { HuriPayload, HuriSchema } from '@xyo-network/diviner'\nimport { Payload } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\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 if (diviner) {\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 compact([...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined))),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map((value) => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n compact(\n [...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined)),\n ),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadContext } from './Context'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,wBAAwB,gBAAqC;;;ACH1E,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,WAAW,uBAAuB;;;ACJ3C,SAAS,mBAAAA,wBAAuB;AAIhC,IAAM,wBAAwBA,iBAAqC;;;ACJnE,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAsB,kBAAkB;AAExC,SAAS,oBAAoB;AAC7B,SAAmB,WAAW,gBAAgB;AAIvC,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,CAAC,SAAS,UAAU,IAAI,SAAmB;AACjD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAgB;AAE1C,YAAU,MAAM;AACd,QAAI,SAAS;AACX,iBAAW,MAAS;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ;AAAA;AAAA,IAEE,OAAO,YAAY;AACjB,UAAI,QAAQ,WAAW,YAAY,QAAW;AAC5C,YAAI;AACF,gBAAM,cAA2B,EAAE,MAAM,CAAC,IAAI,GAAG,QAAQ,WAAW;AACpE,gBAAM,CAACC,QAAO,IAAK,MAAM,SAAS,OAAO,CAAC,WAAW,CAAC,KAAM,CAAC;AAC7D,cAAI,QAAQ,GAAG;AACb,uBAAWA,WAAWA,WAAgB,IAAI;AAAA,UAC5C;AAAA,QACF,SAAS,IAAI;AACX,cAAI,QAAQ,GAAG;AACb,qBAAS,EAAW;AAAA,UACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,SAAS,MAAM,OAAO;AAAA,EACzB;AAEA,SAAO,CAAC,SAAS,YAAY,KAAK;AACpC;;;AC/CA,SAAS,gBAAAC,qBAAoB;AAItB,IAAM,oBAAoB,MAAMC,cAAa,uBAAuB,kBAAkB,IAAI;;;AHsBxF;AAZF,IAAM,yBAAgE,CAAC,EAAE,UAAU,KAAK,MAAM;AACnG,QAAM,EAAE,MAAM,UAAU,IAAI,UAAU;AAEtC,QAAM,oBAAoB,aAAa,SAAS;AAEhD,QAAM,CAAC,MAAM,IAAI,gBAAgB;AACjC,QAAM,sBAAsB,OAAO,IAAI,MAAM;AAC7C,QAAM,mBAAmB,mBAAmB,uBAAuB,EAAE;AACrE,QAAM,UAAU,SAAS,mBAAmB,mBAAmB;AAE/D,QAAM,CAAC,SAAS,YAAY,YAAY,IAAI,iBAAiB,OAAO;AAEpE,SAAO,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,SAAS,cAAc,UAAU,MAAM,WAAW,GAAI,UAAS;AACjH;AAEO,IAAM,gCAAwD,CAAC,EAAE,SAAS,MAAM;AACrF,QAAM,EAAE,aAAa,IAAI,kBAAkB;AAE3C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,eAAe,EAAE,SAAS,aAAa,SAAS,QAAQ,mBAAmB,SAAS,CAAC,EAAE,IAAI;AAAA,MAClG,cAAa;AAAA,MAEZ;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,mCAA0E,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AACjH,SACE,oBAAC,0BAAwB,GAAG,OAC1B,8BAAC,iCAA+B,UAAS,GAC3C;AAEJ;","names":["createContextEx","payload","useContextEx","useContextEx"]}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/contexts/DivinedPayload/use.ts
|
|
21
|
-
var use_exports = {};
|
|
22
|
-
__export(use_exports, {
|
|
23
|
-
useDivinedPayload: () => useDivinedPayload
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(use_exports);
|
|
26
|
-
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
27
|
-
|
|
28
|
-
// src/contexts/DivinedPayload/Context.tsx
|
|
29
|
-
var import_react_shared = require("@xyo-network/react-shared");
|
|
30
|
-
var DivinedPayloadContext = (0, import_react_shared.createContextEx)();
|
|
31
|
-
|
|
32
|
-
// src/contexts/DivinedPayload/use.ts
|
|
33
|
-
var useDivinedPayload = () => (0, import_react_shared2.useContextEx)(DivinedPayloadContext, "DivinedPayload", true);
|
|
34
|
-
//# sourceMappingURL=use.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/use.ts","../../../../src/contexts/DivinedPayload/Context.tsx"],"sourcesContent":["import { useContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadContext } from './Context'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,uBAA6B;;;ACA7B,0BAAgC;AAIzB,IAAM,4BAAwB,qCAAqC;;;ADAnE,IAAM,oBAAoB,UAAM,mCAAa,uBAAuB,kBAAkB,IAAI;","names":["import_react_shared"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/contexts/DivinedPayload/use.ts
|
|
2
|
-
import { useContextEx } from "@xyo-network/react-shared";
|
|
3
|
-
|
|
4
|
-
// src/contexts/DivinedPayload/Context.tsx
|
|
5
|
-
import { createContextEx } from "@xyo-network/react-shared";
|
|
6
|
-
var DivinedPayloadContext = createContextEx();
|
|
7
|
-
|
|
8
|
-
// src/contexts/DivinedPayload/use.ts
|
|
9
|
-
var useDivinedPayload = () => useContextEx(DivinedPayloadContext, "DivinedPayload", true);
|
|
10
|
-
export {
|
|
11
|
-
useDivinedPayload
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=use.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/use.ts","../../../../src/contexts/DivinedPayload/Context.tsx"],"sourcesContent":["import { useContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadContext } from './Context'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,uBAAuB;AAIzB,IAAM,wBAAwB,gBAAqC;;;ADAnE,IAAM,oBAAoB,MAAM,aAAa,uBAAuB,kBAAkB,IAAI;","names":[]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/contexts/PayloadDiviner/Context.ts
|
|
21
|
-
var Context_exports = {};
|
|
22
|
-
__export(Context_exports, {
|
|
23
|
-
PayloadDivinerContext: () => PayloadDivinerContext
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(Context_exports);
|
|
26
|
-
var import_react_shared = require("@xyo-network/react-shared");
|
|
27
|
-
var PayloadDivinerContext = (0, import_react_shared.createContextEx)();
|
|
28
|
-
//# sourceMappingURL=Context.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/PayloadDiviner/Context.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { PayloadDivinerState } from './State'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC;AAIhC,IAAM,4BAAwB,qCAAqC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/PayloadDiviner/Context.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { PayloadDivinerState } from './State'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIhC,IAAM,wBAAwB,gBAAqC;","names":[]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/contexts/PayloadDiviner/Provider.tsx
|
|
21
|
-
var Provider_exports = {};
|
|
22
|
-
__export(Provider_exports, {
|
|
23
|
-
PayloadDivinerProvider: () => PayloadDivinerProvider
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(Provider_exports);
|
|
26
|
-
var import_react = require("react");
|
|
27
|
-
|
|
28
|
-
// src/contexts/PayloadDiviner/Context.ts
|
|
29
|
-
var import_react_shared = require("@xyo-network/react-shared");
|
|
30
|
-
var PayloadDivinerContext = (0, import_react_shared.createContextEx)();
|
|
31
|
-
|
|
32
|
-
// src/contexts/PayloadDiviner/Provider.tsx
|
|
33
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
-
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
35
|
-
const [diviner, setDiviner] = (0, import_react.useState)(divinerProp);
|
|
36
|
-
(0, import_react.useEffect)(() => {
|
|
37
|
-
if (divinerProp) {
|
|
38
|
-
setDiviner(divinerProp);
|
|
39
|
-
}
|
|
40
|
-
}, [divinerProp]);
|
|
41
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
42
|
-
PayloadDivinerContext.Provider,
|
|
43
|
-
{
|
|
44
|
-
value: {
|
|
45
|
-
diviner: diviner === divinerProp ? diviner : void 0,
|
|
46
|
-
provided: true,
|
|
47
|
-
setDiviner
|
|
48
|
-
},
|
|
49
|
-
children: diviner ? children : required ? null : children
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
//# sourceMappingURL=Provider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/PayloadDiviner/Provider.tsx","../../../../src/contexts/PayloadDiviner/Context.ts"],"sourcesContent":["import { AbstractPayloadDiviner } from '@xyo-network/diviner'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: AbstractPayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<AbstractPayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n return (\n <PayloadDivinerContext.Provider\n value={{\n diviner: diviner === divinerProp ? diviner : undefined,\n provided: true,\n setDiviner,\n }}\n >\n {diviner ? children : required ? null : children}\n </PayloadDivinerContext.Provider>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { PayloadDivinerState } from './State'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAoC;;;ACFpC,0BAAgC;AAIhC,IAAM,4BAAwB,qCAAqC;;;ADiB/D;AAVG,IAAM,yBAAgE,CAAC,EAAE,SAAS,aAAa,WAAW,OAAO,SAAS,MAAM;AACrI,QAAM,CAAC,SAAS,UAAU,QAAI,uBAA6C,WAAW;AAEtF,8BAAU,MAAM;AACd,QAAI,aAAa;AACf,iBAAW,WAAW;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAEhB,SACE;AAAA,IAAC,sBAAsB;AAAA,IAAtB;AAAA,MACC,OAAO;AAAA,QACL,SAAS,YAAY,cAAc,UAAU;AAAA,QAC7C,UAAU;AAAA,QACV;AAAA,MACF;AAAA,MAEC,oBAAU,WAAW,WAAW,OAAO;AAAA;AAAA,EAC1C;AAEJ;","names":[]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// src/contexts/PayloadDiviner/Provider.tsx
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
|
|
4
|
-
// src/contexts/PayloadDiviner/Context.ts
|
|
5
|
-
import { createContextEx } from "@xyo-network/react-shared";
|
|
6
|
-
var PayloadDivinerContext = createContextEx();
|
|
7
|
-
|
|
8
|
-
// src/contexts/PayloadDiviner/Provider.tsx
|
|
9
|
-
import { jsx } from "react/jsx-runtime";
|
|
10
|
-
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
11
|
-
const [diviner, setDiviner] = useState(divinerProp);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
if (divinerProp) {
|
|
14
|
-
setDiviner(divinerProp);
|
|
15
|
-
}
|
|
16
|
-
}, [divinerProp]);
|
|
17
|
-
return /* @__PURE__ */ jsx(
|
|
18
|
-
PayloadDivinerContext.Provider,
|
|
19
|
-
{
|
|
20
|
-
value: {
|
|
21
|
-
diviner: diviner === divinerProp ? diviner : void 0,
|
|
22
|
-
provided: true,
|
|
23
|
-
setDiviner
|
|
24
|
-
},
|
|
25
|
-
children: diviner ? children : required ? null : children
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
export {
|
|
30
|
-
PayloadDivinerProvider
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=Provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/PayloadDiviner/Provider.tsx","../../../../src/contexts/PayloadDiviner/Context.ts"],"sourcesContent":["import { AbstractPayloadDiviner } from '@xyo-network/diviner'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: AbstractPayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<AbstractPayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n return (\n <PayloadDivinerContext.Provider\n value={{\n diviner: diviner === divinerProp ? diviner : undefined,\n provided: true,\n setDiviner,\n }}\n >\n {diviner ? children : required ? null : children}\n </PayloadDivinerContext.Provider>\n )\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { PayloadDivinerState } from './State'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n"],"mappings":";AAEA,SAAS,WAAW,gBAAgB;;;ACFpC,SAAS,uBAAuB;AAIhC,IAAM,wBAAwB,gBAAqC;;;ADiB/D;AAVG,IAAM,yBAAgE,CAAC,EAAE,SAAS,aAAa,WAAW,OAAO,SAAS,MAAM;AACrI,QAAM,CAAC,SAAS,UAAU,IAAI,SAA6C,WAAW;AAEtF,YAAU,MAAM;AACd,QAAI,aAAa;AACf,iBAAW,WAAW;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAEhB,SACE;AAAA,IAAC,sBAAsB;AAAA,IAAtB;AAAA,MACC,OAAO;AAAA,QACL,SAAS,YAAY,cAAc,UAAU;AAAA,QAC7C,UAAU;AAAA,QACV;AAAA,MACF;AAAA,MAEC,oBAAU,WAAW,WAAW,OAAO;AAAA;AAAA,EAC1C;AAEJ;","names":[]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/contexts/PayloadDiviner/State.ts
|
|
17
|
-
var State_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(State_exports);
|
|
19
|
-
//# sourceMappingURL=State.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/PayloadDiviner/State.ts"],"sourcesContent":["import { AbstractPayloadDiviner } from '@xyo-network/diviner'\nimport { Dispatch } from 'react'\n\nexport interface PayloadDivinerState {\n diviner?: AbstractPayloadDiviner\n setDiviner?: Dispatch<AbstractPayloadDiviner>\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=State.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/contexts/PayloadDiviner/index.ts
|
|
21
|
-
var PayloadDiviner_exports = {};
|
|
22
|
-
__export(PayloadDiviner_exports, {
|
|
23
|
-
PayloadDivinerContext: () => PayloadDivinerContext,
|
|
24
|
-
PayloadDivinerProvider: () => PayloadDivinerProvider,
|
|
25
|
-
useDivinePayload: () => useDivinePayload,
|
|
26
|
-
useDivinePayloads: () => useDivinePayloads,
|
|
27
|
-
usePayloadDiviner: () => usePayloadDiviner
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(PayloadDiviner_exports);
|
|
30
|
-
|
|
31
|
-
// src/contexts/PayloadDiviner/Context.ts
|
|
32
|
-
var import_react_shared = require("@xyo-network/react-shared");
|
|
33
|
-
var PayloadDivinerContext = (0, import_react_shared.createContextEx)();
|
|
34
|
-
|
|
35
|
-
// src/contexts/PayloadDiviner/Provider.tsx
|
|
36
|
-
var import_react = require("react");
|
|
37
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
-
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
39
|
-
const [diviner, setDiviner] = (0, import_react.useState)(divinerProp);
|
|
40
|
-
(0, import_react.useEffect)(() => {
|
|
41
|
-
if (divinerProp) {
|
|
42
|
-
setDiviner(divinerProp);
|
|
43
|
-
}
|
|
44
|
-
}, [divinerProp]);
|
|
45
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
46
|
-
PayloadDivinerContext.Provider,
|
|
47
|
-
{
|
|
48
|
-
value: {
|
|
49
|
-
diviner: diviner === divinerProp ? diviner : void 0,
|
|
50
|
-
provided: true,
|
|
51
|
-
setDiviner
|
|
52
|
-
},
|
|
53
|
-
children: diviner ? children : required ? null : children
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// src/contexts/PayloadDiviner/use.ts
|
|
59
|
-
var import_lodash = require("@xylabs/lodash");
|
|
60
|
-
var import_react_async_effect = require("@xylabs/react-async-effect");
|
|
61
|
-
var import_diviner = require("@xyo-network/diviner");
|
|
62
|
-
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
63
|
-
var import_react2 = require("react");
|
|
64
|
-
var usePayloadDiviner = (required = false) => {
|
|
65
|
-
return (0, import_react_shared2.useContextEx)(PayloadDivinerContext, "PayloadDiviner", required);
|
|
66
|
-
};
|
|
67
|
-
var useDivinePayload = (huri) => {
|
|
68
|
-
const { diviner } = usePayloadDiviner();
|
|
69
|
-
const [payload, setPayload] = (0, import_react2.useState)();
|
|
70
|
-
const [error, setError] = (0, import_react2.useState)();
|
|
71
|
-
(0, import_react2.useEffect)(() => {
|
|
72
|
-
if (diviner) {
|
|
73
|
-
setPayload(void 0);
|
|
74
|
-
}
|
|
75
|
-
}, [diviner]);
|
|
76
|
-
(0, import_react_async_effect.useAsyncEffect)(
|
|
77
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
-
async (mounted) => {
|
|
79
|
-
if (huri && diviner && payload === void 0) {
|
|
80
|
-
try {
|
|
81
|
-
const huriPayload = { huri: [huri], schema: import_diviner.HuriSchema };
|
|
82
|
-
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
83
|
-
if (mounted()) {
|
|
84
|
-
setPayload(payload2 ? payload2 : null);
|
|
85
|
-
}
|
|
86
|
-
} catch (ex) {
|
|
87
|
-
if (mounted()) {
|
|
88
|
-
setError(ex);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
[diviner, huri, payload]
|
|
94
|
-
);
|
|
95
|
-
return [payload, setPayload, error];
|
|
96
|
-
};
|
|
97
|
-
var useDivinePayloads = (huriList) => {
|
|
98
|
-
const { diviner } = usePayloadDiviner();
|
|
99
|
-
const [payloads, setPayloads] = (0, import_react2.useState)();
|
|
100
|
-
const [errors, setErrors] = (0, import_react2.useState)();
|
|
101
|
-
(0, import_react2.useEffect)(() => {
|
|
102
|
-
if (diviner) {
|
|
103
|
-
setPayloads(void 0);
|
|
104
|
-
}
|
|
105
|
-
}, [diviner]);
|
|
106
|
-
(0, import_react_async_effect.useAsyncEffect)(
|
|
107
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
108
|
-
async (mounted) => {
|
|
109
|
-
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`);
|
|
110
|
-
const payloads2 = await Promise.allSettled(
|
|
111
|
-
huriList.map(async (huri) => {
|
|
112
|
-
const huriPayload = { huri: [huri], schema: import_diviner.HuriSchema };
|
|
113
|
-
const [payload] = await diviner?.divine([huriPayload]) ?? [];
|
|
114
|
-
return payload;
|
|
115
|
-
})
|
|
116
|
-
);
|
|
117
|
-
if (mounted()) {
|
|
118
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
119
|
-
setErrors(
|
|
120
|
-
(0, import_lodash.compact)([...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0))
|
|
121
|
-
);
|
|
122
|
-
if (mounted()) {
|
|
123
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
124
|
-
setErrors(
|
|
125
|
-
(0, import_lodash.compact)(
|
|
126
|
-
[...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0)
|
|
127
|
-
)
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
[diviner, huriList, payloads]
|
|
133
|
-
);
|
|
134
|
-
return [payloads, setPayloads, errors];
|
|
135
|
-
};
|
|
136
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/PayloadDiviner/index.ts","../../../../src/contexts/PayloadDiviner/Context.ts","../../../../src/contexts/PayloadDiviner/Provider.tsx","../../../../src/contexts/PayloadDiviner/use.ts"],"sourcesContent":["export * from './Context'\nexport * from './Provider'\nexport * from './State'\nexport * from './use'\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { PayloadDivinerState } from './State'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { AbstractPayloadDiviner } from '@xyo-network/diviner'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: AbstractPayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<AbstractPayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n return (\n <PayloadDivinerContext.Provider\n value={{\n diviner: diviner === divinerProp ? diviner : undefined,\n provided: true,\n setDiviner,\n }}\n >\n {diviner ? children : required ? null : children}\n </PayloadDivinerContext.Provider>\n )\n}\n","import { compact } from '@xylabs/lodash'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { HuriPayload, HuriSchema } from '@xyo-network/diviner'\nimport { Payload } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\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 if (diviner) {\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\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 compact([...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined))),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map((value) => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n compact(\n [...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined)),\n ),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n"],"mappings":"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","names":["import_react_shared","import_react","payload","payloads"]}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// src/contexts/PayloadDiviner/Context.ts
|
|
2
|
-
import { createContextEx } from "@xyo-network/react-shared";
|
|
3
|
-
var PayloadDivinerContext = createContextEx();
|
|
4
|
-
|
|
5
|
-
// src/contexts/PayloadDiviner/Provider.tsx
|
|
6
|
-
import { useEffect, useState } from "react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
9
|
-
const [diviner, setDiviner] = useState(divinerProp);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (divinerProp) {
|
|
12
|
-
setDiviner(divinerProp);
|
|
13
|
-
}
|
|
14
|
-
}, [divinerProp]);
|
|
15
|
-
return /* @__PURE__ */ jsx(
|
|
16
|
-
PayloadDivinerContext.Provider,
|
|
17
|
-
{
|
|
18
|
-
value: {
|
|
19
|
-
diviner: diviner === divinerProp ? diviner : void 0,
|
|
20
|
-
provided: true,
|
|
21
|
-
setDiviner
|
|
22
|
-
},
|
|
23
|
-
children: diviner ? children : required ? null : children
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// src/contexts/PayloadDiviner/use.ts
|
|
29
|
-
import { compact } from "@xylabs/lodash";
|
|
30
|
-
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
31
|
-
import { HuriSchema } from "@xyo-network/diviner";
|
|
32
|
-
import { useContextEx } from "@xyo-network/react-shared";
|
|
33
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
34
|
-
var usePayloadDiviner = (required = false) => {
|
|
35
|
-
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
36
|
-
};
|
|
37
|
-
var useDivinePayload = (huri) => {
|
|
38
|
-
const { diviner } = usePayloadDiviner();
|
|
39
|
-
const [payload, setPayload] = useState2();
|
|
40
|
-
const [error, setError] = useState2();
|
|
41
|
-
useEffect2(() => {
|
|
42
|
-
if (diviner) {
|
|
43
|
-
setPayload(void 0);
|
|
44
|
-
}
|
|
45
|
-
}, [diviner]);
|
|
46
|
-
useAsyncEffect(
|
|
47
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
|
-
async (mounted) => {
|
|
49
|
-
if (huri && diviner && payload === void 0) {
|
|
50
|
-
try {
|
|
51
|
-
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
52
|
-
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
53
|
-
if (mounted()) {
|
|
54
|
-
setPayload(payload2 ? payload2 : null);
|
|
55
|
-
}
|
|
56
|
-
} catch (ex) {
|
|
57
|
-
if (mounted()) {
|
|
58
|
-
setError(ex);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
[diviner, huri, payload]
|
|
64
|
-
);
|
|
65
|
-
return [payload, setPayload, error];
|
|
66
|
-
};
|
|
67
|
-
var useDivinePayloads = (huriList) => {
|
|
68
|
-
const { diviner } = usePayloadDiviner();
|
|
69
|
-
const [payloads, setPayloads] = useState2();
|
|
70
|
-
const [errors, setErrors] = useState2();
|
|
71
|
-
useEffect2(() => {
|
|
72
|
-
if (diviner) {
|
|
73
|
-
setPayloads(void 0);
|
|
74
|
-
}
|
|
75
|
-
}, [diviner]);
|
|
76
|
-
useAsyncEffect(
|
|
77
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
-
async (mounted) => {
|
|
79
|
-
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`);
|
|
80
|
-
const payloads2 = await Promise.allSettled(
|
|
81
|
-
huriList.map(async (huri) => {
|
|
82
|
-
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
83
|
-
const [payload] = await diviner?.divine([huriPayload]) ?? [];
|
|
84
|
-
return payload;
|
|
85
|
-
})
|
|
86
|
-
);
|
|
87
|
-
if (mounted()) {
|
|
88
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
89
|
-
setErrors(
|
|
90
|
-
compact([...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0))
|
|
91
|
-
);
|
|
92
|
-
if (mounted()) {
|
|
93
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
94
|
-
setErrors(
|
|
95
|
-
compact(
|
|
96
|
-
[...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0)
|
|
97
|
-
)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
[diviner, huriList, payloads]
|
|
103
|
-
);
|
|
104
|
-
return [payloads, setPayloads, errors];
|
|
105
|
-
};
|
|
106
|
-
export {
|
|
107
|
-
PayloadDivinerContext,
|
|
108
|
-
PayloadDivinerProvider,
|
|
109
|
-
useDivinePayload,
|
|
110
|
-
useDivinePayloads,
|
|
111
|
-
usePayloadDiviner
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=index.js.map
|