@xyo-network/react-payload-diviner 2.81.9 → 2.82.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/DivinedPayload/Context.d.cts +1 -1
- package/dist/browser/contexts/DivinedPayload/Context.d.cts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/Context.d.mts +1 -1
- package/dist/browser/contexts/DivinedPayload/Context.d.mts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/Context.d.ts +1 -1
- package/dist/browser/contexts/DivinedPayload/Context.d.ts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/Provider.d.cts +1 -0
- package/dist/browser/contexts/DivinedPayload/Provider.d.cts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/Provider.d.mts +1 -0
- package/dist/browser/contexts/DivinedPayload/Provider.d.mts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/Provider.d.ts +1 -0
- package/dist/browser/contexts/DivinedPayload/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/index.d.cts +4 -4
- package/dist/browser/contexts/DivinedPayload/index.d.cts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/index.d.mts +4 -4
- package/dist/browser/contexts/DivinedPayload/index.d.mts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/index.d.ts +4 -4
- package/dist/browser/contexts/DivinedPayload/index.d.ts.map +1 -1
- package/dist/browser/contexts/DivinedPayload/use.d.cts +1 -1
- package/dist/browser/contexts/DivinedPayload/use.d.mts +1 -1
- package/dist/browser/contexts/DivinedPayload/use.d.ts +1 -1
- package/dist/browser/contexts/PayloadDiviner/Context.d.cts +1 -1
- package/dist/browser/contexts/PayloadDiviner/Context.d.mts +1 -1
- package/dist/browser/contexts/PayloadDiviner/Context.d.ts +1 -1
- package/dist/browser/contexts/PayloadDiviner/Provider.d.cts +1 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.d.cts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/Provider.d.mts +1 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.d.mts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/Provider.d.ts +1 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/index.d.cts +4 -4
- package/dist/browser/contexts/PayloadDiviner/index.d.cts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/index.d.mts +4 -4
- package/dist/browser/contexts/PayloadDiviner/index.d.mts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/index.d.ts +4 -4
- package/dist/browser/contexts/PayloadDiviner/index.d.ts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.cts +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.cts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.mts +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.mts.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.ts +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.d.ts.map +1 -1
- package/dist/browser/contexts/index.d.cts +2 -2
- package/dist/browser/contexts/index.d.mts +2 -2
- package/dist/browser/contexts/index.d.ts +2 -2
- package/dist/browser/index.cjs +138 -90
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.d.cts +1 -1
- package/dist/browser/index.d.mts +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.mjs +201 -0
- package/dist/browser/index.mjs.map +1 -0
- package/dist/neutral/contexts/DivinedPayload/Context.d.cts +1 -1
- package/dist/neutral/contexts/DivinedPayload/Context.d.cts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/Context.d.mts +1 -1
- package/dist/neutral/contexts/DivinedPayload/Context.d.mts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/Context.d.ts +1 -1
- package/dist/neutral/contexts/DivinedPayload/Context.d.ts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/Provider.d.cts +1 -0
- package/dist/neutral/contexts/DivinedPayload/Provider.d.cts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/Provider.d.mts +1 -0
- package/dist/neutral/contexts/DivinedPayload/Provider.d.mts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/Provider.d.ts +1 -0
- package/dist/neutral/contexts/DivinedPayload/Provider.d.ts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/index.d.cts +4 -4
- package/dist/neutral/contexts/DivinedPayload/index.d.cts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/index.d.mts +4 -4
- package/dist/neutral/contexts/DivinedPayload/index.d.mts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/index.d.ts +4 -4
- package/dist/neutral/contexts/DivinedPayload/index.d.ts.map +1 -1
- package/dist/neutral/contexts/DivinedPayload/use.d.cts +1 -1
- package/dist/neutral/contexts/DivinedPayload/use.d.mts +1 -1
- package/dist/neutral/contexts/DivinedPayload/use.d.ts +1 -1
- package/dist/neutral/contexts/PayloadDiviner/Context.d.cts +1 -1
- package/dist/neutral/contexts/PayloadDiviner/Context.d.mts +1 -1
- package/dist/neutral/contexts/PayloadDiviner/Context.d.ts +1 -1
- package/dist/neutral/contexts/PayloadDiviner/Provider.d.cts +1 -0
- package/dist/neutral/contexts/PayloadDiviner/Provider.d.cts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/Provider.d.mts +1 -0
- package/dist/neutral/contexts/PayloadDiviner/Provider.d.mts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/Provider.d.ts +1 -0
- package/dist/neutral/contexts/PayloadDiviner/Provider.d.ts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/index.d.cts +4 -4
- package/dist/neutral/contexts/PayloadDiviner/index.d.cts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/index.d.mts +4 -4
- package/dist/neutral/contexts/PayloadDiviner/index.d.mts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/index.d.ts +4 -4
- package/dist/neutral/contexts/PayloadDiviner/index.d.ts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/use.d.cts +1 -1
- package/dist/neutral/contexts/PayloadDiviner/use.d.cts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/use.d.mts +1 -1
- package/dist/neutral/contexts/PayloadDiviner/use.d.mts.map +1 -1
- package/dist/neutral/contexts/PayloadDiviner/use.d.ts +1 -1
- package/dist/neutral/contexts/PayloadDiviner/use.d.ts.map +1 -1
- package/dist/neutral/contexts/index.d.cts +2 -2
- package/dist/neutral/contexts/index.d.mts +2 -2
- package/dist/neutral/contexts/index.d.ts +2 -2
- package/dist/neutral/index.cjs +138 -90
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.d.cts +1 -1
- package/dist/neutral/index.d.mts +1 -1
- package/dist/neutral/index.d.ts +1 -1
- package/dist/neutral/index.mjs +201 -0
- package/dist/neutral/index.mjs.map +1 -0
- package/dist/node/contexts/DivinedPayload/Context.d.cts +1 -1
- package/dist/node/contexts/DivinedPayload/Context.d.cts.map +1 -1
- package/dist/node/contexts/DivinedPayload/Context.d.mts +1 -1
- package/dist/node/contexts/DivinedPayload/Context.d.mts.map +1 -1
- package/dist/node/contexts/DivinedPayload/Context.d.ts +1 -1
- package/dist/node/contexts/DivinedPayload/Context.d.ts.map +1 -1
- package/dist/node/contexts/DivinedPayload/Provider.d.cts +1 -0
- package/dist/node/contexts/DivinedPayload/Provider.d.cts.map +1 -1
- package/dist/node/contexts/DivinedPayload/Provider.d.mts +1 -0
- package/dist/node/contexts/DivinedPayload/Provider.d.mts.map +1 -1
- package/dist/node/contexts/DivinedPayload/Provider.d.ts +1 -0
- package/dist/node/contexts/DivinedPayload/Provider.d.ts.map +1 -1
- package/dist/node/contexts/DivinedPayload/index.d.cts +4 -4
- package/dist/node/contexts/DivinedPayload/index.d.cts.map +1 -1
- package/dist/node/contexts/DivinedPayload/index.d.mts +4 -4
- package/dist/node/contexts/DivinedPayload/index.d.mts.map +1 -1
- package/dist/node/contexts/DivinedPayload/index.d.ts +4 -4
- package/dist/node/contexts/DivinedPayload/index.d.ts.map +1 -1
- package/dist/node/contexts/DivinedPayload/use.d.cts +1 -1
- package/dist/node/contexts/DivinedPayload/use.d.mts +1 -1
- package/dist/node/contexts/DivinedPayload/use.d.ts +1 -1
- package/dist/node/contexts/PayloadDiviner/Context.d.cts +1 -1
- package/dist/node/contexts/PayloadDiviner/Context.d.mts +1 -1
- package/dist/node/contexts/PayloadDiviner/Context.d.ts +1 -1
- package/dist/node/contexts/PayloadDiviner/Provider.d.cts +1 -0
- package/dist/node/contexts/PayloadDiviner/Provider.d.cts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/Provider.d.mts +1 -0
- package/dist/node/contexts/PayloadDiviner/Provider.d.mts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/Provider.d.ts +1 -0
- package/dist/node/contexts/PayloadDiviner/Provider.d.ts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/index.d.cts +4 -4
- package/dist/node/contexts/PayloadDiviner/index.d.cts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/index.d.mts +4 -4
- package/dist/node/contexts/PayloadDiviner/index.d.mts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/index.d.ts +4 -4
- package/dist/node/contexts/PayloadDiviner/index.d.ts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.cts +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.cts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.mts +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.mts.map +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.ts +1 -1
- package/dist/node/contexts/PayloadDiviner/use.d.ts.map +1 -1
- package/dist/node/contexts/index.d.cts +2 -2
- package/dist/node/contexts/index.d.mts +2 -2
- package/dist/node/contexts/index.d.ts +2 -2
- package/dist/node/index.cjs +138 -90
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +1 -1
- package/dist/node/index.d.mts +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.mjs +201 -0
- package/dist/node/index.mjs.map +1 -0
- package/package.json +16 -16
- package/src/contexts/DivinedPayload/{Context.tsx → Context.ts} +1 -1
- package/src/contexts/DivinedPayload/Provider.tsx +5 -3
- package/src/contexts/DivinedPayload/index.ts +4 -4
- package/src/contexts/DivinedPayload/use.ts +1 -1
- package/src/contexts/PayloadDiviner/Context.ts +1 -1
- package/src/contexts/PayloadDiviner/Provider.tsx +10 -12
- package/src/contexts/PayloadDiviner/index.ts +4 -4
- package/src/contexts/PayloadDiviner/use.ts +5 -7
- package/src/contexts/index.ts +2 -2
- package/src/index.ts +1 -1
- package/dist/browser/index.js +0 -161
- package/dist/browser/index.js.map +0 -1
- package/dist/neutral/index.js +0 -161
- package/dist/neutral/index.js.map +0 -1
- package/dist/node/index.js +0 -161
- package/dist/node/index.js.map +0 -1
|
@@ -0,0 +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 '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State.ts'\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 React from 'react'\nimport { useParams, useSearchParams } from 'react-router-dom'\n\nimport { useDivinePayload } from '../PayloadDiviner/index.ts'\nimport { DivinedPayloadContext } from './Context.ts'\nimport { useDivinedPayload } from './use.ts'\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 ?? huriFromHashParam\n\n const [payload, setPayload, payloadError] = useDivinePayload(huriUri)\n\n // eslint-disable-next-line @eslint-react/no-unstable-context-value\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.ts'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport React, { useEffect, useMemo, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.ts'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: PayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<PayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n const value = useMemo(() => ({ diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner }), [diviner, divinerProp, setDiviner])\n\n return (\n <PayloadDivinerContext.Provider\n value={value}\n >\n {diviner\n ? children\n : required\n ? null\n : 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-huri'\nimport { Payload, WithMeta } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, 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 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 WithMeta<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 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(\n [...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined)),\n ),\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' ? new 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.ts'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";;;;AAAA,SAASA,uBAAuB;AAIzB,IAAMC,wBAAwBD,gBAAAA;;;ACHrC,SAASE,yBAAyB;AAClC,SAASC,mBAAmB;AAC5B,SAASC,oBAAoB;AAC7B,OAAOC,YAAW;AAClB,SAASC,WAAWC,uBAAuB;;;ACL3C,SAASC,mBAAAA,wBAAuB;AAIhC,IAAMC,wBAAwBD,iBAAAA;;;ACF9B,OAAOE,SAASC,WAAWC,SAASC,gBAAgB;AAS7C,IAAMC,yBAAgE,wBAAC,EAAEC,SAASC,aAAaC,WAAW,OAAOC,SAAQ,MAAE;AAChI,QAAM,CAACH,SAASI,UAAAA,IAAcC,SAAqCJ,WAAAA;AAEnEK,YAAU,MAAA;AACR,QAAIL,aAAa;AACfG,iBAAWH,WAAAA;IACb;EACF,GAAG;IAACA;GAAY;AAEhB,QAAMM,QAAQC,QAAQ,OAAO;IAAER,SAASA,YAAYC,cAAcD,UAAU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B,IAAMC,oBAAoB,6BAAMC,cAAaC,uBAAuB,kBAAkB,IAAA,GAA5D;;;AJW1B,IAAMC,yBAAgE,wBAAC,EAAEC,UAAUC,KAAI,MAAE;AAC9F,QAAM,EAAEA,MAAMC,UAAS,IAAKC,UAAAA;AAE5B,QAAMC,oBAAoBC,aAAaH,SAAAA;AAEvC,QAAM,CAACI,MAAAA,IAAUC,gBAAAA;AACjB,QAAMC,sBAAsBF,OAAOG,IAAI,MAAA;AACvC,QAAMC,mBAAmBC,mBAAmBH,uBAAuB,EAAA;AACnE,QAAMI,UAAUX,QAAQS,oBAAoBN;AAE5C,QAAM,CAACS,SAASC,YAAYC,YAAAA,IAAgBC,iBAAiBJ,OAAAA;AAG7D,SAAO,gBAAAK,OAAA,cAACC,sBAAsBC,UAAQ;IAACC,OAAO;MAAEP;MAASE;MAAcM,UAAU;MAAMP;IAAW;KAAId,QAAAA;AACxG,GAd6E;AAgBtE,IAAMsB,gCAAwD,wBAAC,EAAEtB,SAAQ,MAAE;AAChF,QAAM,EAAEe,aAAY,IAAKQ,kBAAAA;AAEzB,SACE,gBAAAN,OAAA,cAACO,aAAAA;IACCC,OAAOV,eAAe;MAAEW,SAASX,aAAaW;MAASC,QAAQC;MAAmBC,SAAS,CAAA;IAAG,IAAIC;IAClGC,cAAa;KAEZ/B,QAAAA;AAGP,GAXqE;AAa9D,IAAMgC,mCAA0E,wBAAC,EAAEhC,UAAU,GAAGiC,MAAAA,MAAO;AAC5G,SACE,gBAAAhB,OAAA,cAAClB,wBAA2BkC,OAC1B,gBAAAhB,OAAA,cAACK,+BAAAA,MAA+BtB,QAAAA,CAAAA;AAGtC,GANuF;","names":["createContextEx","DivinedPayloadContext","ModuleErrorSchema","ErrorRender","useBuildHuri","React","useParams","useSearchParams","createContextEx","PayloadDivinerContext","React","useEffect","useMemo","useState","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useState","useEffect","value","useMemo","undefined","provided","PayloadDivinerContext","Provider","compact","useAsyncEffect","HuriSchema","useContextEx","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","compact","Error","cause","reason","useContextEx","useDivinedPayload","useContextEx","DivinedPayloadContext","DivinedPayloadProvider","children","hash","hashParam","useParams","huriFromHashParam","useBuildHuri","params","useSearchParams","huriSearchParameter","get","decodedHuriParam","decodeURIComponent","huriUri","payload","setPayload","payloadError","useDivinePayload","React","DivinedPayloadContext","Provider","value","provided","DivinedPayloadWithHandleInner","useDivinedPayload","ErrorRender","error","message","schema","ModuleErrorSchema","sources","undefined","errorContext","DivinedPayloadWithHandleProvider","props"]}
|
package/package.json
CHANGED
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/lodash": "^3.6.
|
|
14
|
-
"@xylabs/react-async-effect": "^3.4.
|
|
15
|
-
"@xylabs/react-shared": "^3.4.
|
|
16
|
-
"@xyo-network/diviner-huri": "^2.
|
|
17
|
-
"@xyo-network/diviner-payload-abstract": "^2.
|
|
18
|
-
"@xyo-network/payload-model": "^2.
|
|
19
|
-
"@xyo-network/react-error": "^2.
|
|
20
|
-
"@xyo-network/react-payload-huri": "^2.
|
|
21
|
-
"@xyo-network/react-shared": "^2.
|
|
22
|
-
"react-router-dom": "^6.
|
|
13
|
+
"@xylabs/lodash": "^3.6.12",
|
|
14
|
+
"@xylabs/react-async-effect": "^3.4.2",
|
|
15
|
+
"@xylabs/react-shared": "^3.4.2",
|
|
16
|
+
"@xyo-network/diviner-huri": "^2.111.3",
|
|
17
|
+
"@xyo-network/diviner-payload-abstract": "^2.111.3",
|
|
18
|
+
"@xyo-network/payload-model": "^2.111.3",
|
|
19
|
+
"@xyo-network/react-error": "^2.82.0",
|
|
20
|
+
"@xyo-network/react-payload-huri": "^2.82.0",
|
|
21
|
+
"@xyo-network/react-shared": "^2.82.0",
|
|
22
|
+
"react-router-dom": "^6.26.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
25
|
+
"@xylabs/ts-scripts-yarn3": "^3.15.16",
|
|
26
26
|
"typescript": "^5.5.4"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"node": {
|
|
40
40
|
"import": {
|
|
41
41
|
"types": "./dist/node/index.d.mts",
|
|
42
|
-
"default": "./dist/node/index.
|
|
42
|
+
"default": "./dist/node/index.mjs"
|
|
43
43
|
},
|
|
44
44
|
"require": {
|
|
45
45
|
"types": "./dist/node/index.d.cts",
|
|
@@ -49,19 +49,19 @@
|
|
|
49
49
|
"browser": {
|
|
50
50
|
"import": {
|
|
51
51
|
"types": "./dist/browser/index.d.mts",
|
|
52
|
-
"default": "./dist/browser/index.
|
|
52
|
+
"default": "./dist/browser/index.mjs"
|
|
53
53
|
},
|
|
54
54
|
"require": {
|
|
55
55
|
"types": "./dist/browser/index.d.cts",
|
|
56
56
|
"default": "./dist/browser/index.cjs"
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
"default": "./dist/browser/index.
|
|
59
|
+
"default": "./dist/browser/index.mjs"
|
|
60
60
|
},
|
|
61
61
|
"./package.json": "./package.json"
|
|
62
62
|
},
|
|
63
63
|
"main": "dist/browser/index.cjs",
|
|
64
|
-
"module": "dist/browser/index.
|
|
64
|
+
"module": "dist/browser/index.mjs",
|
|
65
65
|
"homepage": "https://xyo.network",
|
|
66
66
|
"keywords": [
|
|
67
67
|
"xyo",
|
|
@@ -83,6 +83,6 @@
|
|
|
83
83
|
},
|
|
84
84
|
"sideEffects": false,
|
|
85
85
|
"types": "dist/browser/index.d.ts",
|
|
86
|
-
"version": "2.
|
|
86
|
+
"version": "2.82.0",
|
|
87
87
|
"type": "module"
|
|
88
88
|
}
|
|
@@ -2,11 +2,12 @@ import type { WithChildren } from '@xylabs/react-shared'
|
|
|
2
2
|
import { ModuleErrorSchema } from '@xyo-network/payload-model'
|
|
3
3
|
import { ErrorRender } from '@xyo-network/react-error'
|
|
4
4
|
import { useBuildHuri } from '@xyo-network/react-payload-huri'
|
|
5
|
+
import React from 'react'
|
|
5
6
|
import { useParams, useSearchParams } from 'react-router-dom'
|
|
6
7
|
|
|
7
|
-
import { useDivinePayload } from '../PayloadDiviner/index.
|
|
8
|
-
import { DivinedPayloadContext } from './Context.
|
|
9
|
-
import { useDivinedPayload } from './use.
|
|
8
|
+
import { useDivinePayload } from '../PayloadDiviner/index.ts'
|
|
9
|
+
import { DivinedPayloadContext } from './Context.ts'
|
|
10
|
+
import { useDivinedPayload } from './use.ts'
|
|
10
11
|
|
|
11
12
|
export interface DivinedPayloadProviderProps extends WithChildren {
|
|
12
13
|
hash?: string
|
|
@@ -24,6 +25,7 @@ export const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps> = ({
|
|
|
24
25
|
|
|
25
26
|
const [payload, setPayload, payloadError] = useDivinePayload(huriUri)
|
|
26
27
|
|
|
28
|
+
// eslint-disable-next-line @eslint-react/no-unstable-context-value
|
|
27
29
|
return <DivinedPayloadContext.Provider value={{ payload, payloadError, provided: true, setPayload }}>{children}</DivinedPayloadContext.Provider>
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './Context.
|
|
2
|
-
export * from './Provider.
|
|
3
|
-
export * from './State.
|
|
4
|
-
export * from './use.
|
|
1
|
+
export * from './Context.ts'
|
|
2
|
+
export * from './Provider.tsx'
|
|
3
|
+
export * from './State.ts'
|
|
4
|
+
export * from './use.ts'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContextEx } from '@xyo-network/react-shared'
|
|
2
2
|
|
|
3
|
-
import { DivinedPayloadContext } from './Context.
|
|
3
|
+
import { DivinedPayloadContext } from './Context.ts'
|
|
4
4
|
|
|
5
5
|
export const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'
|
|
2
2
|
import { ContextExProviderProps } from '@xyo-network/react-shared'
|
|
3
|
-
import { useEffect, useState } from 'react'
|
|
3
|
+
import React, { useEffect, useMemo, useState } from 'react'
|
|
4
4
|
|
|
5
|
-
import { PayloadDivinerContext } from './Context.
|
|
5
|
+
import { PayloadDivinerContext } from './Context.ts'
|
|
6
6
|
|
|
7
7
|
export type PayloadDivinerProviderProps = ContextExProviderProps<{
|
|
8
8
|
/** Required */
|
|
@@ -18,19 +18,17 @@ export const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({
|
|
|
18
18
|
}
|
|
19
19
|
}, [divinerProp])
|
|
20
20
|
|
|
21
|
+
const value = useMemo(() => ({ diviner: diviner === divinerProp ? diviner : undefined, provided: true, setDiviner }), [diviner, divinerProp, setDiviner])
|
|
22
|
+
|
|
21
23
|
return (
|
|
22
24
|
<PayloadDivinerContext.Provider
|
|
23
|
-
value={
|
|
24
|
-
diviner: diviner === divinerProp ? diviner : undefined,
|
|
25
|
-
provided: true,
|
|
26
|
-
setDiviner,
|
|
27
|
-
}}
|
|
25
|
+
value={value}
|
|
28
26
|
>
|
|
29
|
-
{diviner
|
|
30
|
-
children
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
{diviner
|
|
28
|
+
? children
|
|
29
|
+
: required
|
|
30
|
+
? null
|
|
31
|
+
: children}
|
|
34
32
|
</PayloadDivinerContext.Provider>
|
|
35
33
|
)
|
|
36
34
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './Context.
|
|
2
|
-
export * from './Provider.
|
|
3
|
-
export * from './State.
|
|
4
|
-
export * from './use.
|
|
1
|
+
export * from './Context.ts'
|
|
2
|
+
export * from './Provider.tsx'
|
|
3
|
+
export * from './State.ts'
|
|
4
|
+
export * from './use.ts'
|
|
@@ -5,7 +5,7 @@ import { Payload, WithMeta } from '@xyo-network/payload-model'
|
|
|
5
5
|
import { useContextEx } from '@xyo-network/react-shared'
|
|
6
6
|
import { Dispatch, useEffect, useState } from 'react'
|
|
7
7
|
|
|
8
|
-
import { PayloadDivinerContext } from './Context.
|
|
8
|
+
import { PayloadDivinerContext } from './Context.ts'
|
|
9
9
|
|
|
10
10
|
export const usePayloadDiviner = (required = false) => {
|
|
11
11
|
return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)
|
|
@@ -25,7 +25,6 @@ export const useDivinePayload = <T extends Payload = Payload>(
|
|
|
25
25
|
}, [diviner])
|
|
26
26
|
|
|
27
27
|
useAsyncEffect(
|
|
28
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
28
|
async (mounted) => {
|
|
30
29
|
if (huri && diviner && payload === undefined) {
|
|
31
30
|
try {
|
|
@@ -61,7 +60,6 @@ export const useDivinePayloads = <T extends Payload = Payload>(
|
|
|
61
60
|
}, [diviner])
|
|
62
61
|
|
|
63
62
|
useAsyncEffect(
|
|
64
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
63
|
async (mounted) => {
|
|
66
64
|
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)
|
|
67
65
|
const payloads = await Promise.allSettled(
|
|
@@ -72,17 +70,17 @@ export const useDivinePayloads = <T extends Payload = Payload>(
|
|
|
72
70
|
}),
|
|
73
71
|
)
|
|
74
72
|
if (mounted()) {
|
|
75
|
-
setPayloads([...payloads.values()].map(
|
|
73
|
+
setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])
|
|
76
74
|
setErrors(
|
|
77
75
|
compact(
|
|
78
|
-
[...payloads.values()].map(
|
|
76
|
+
[...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined)),
|
|
79
77
|
),
|
|
80
78
|
)
|
|
81
79
|
if (mounted()) {
|
|
82
|
-
setPayloads([...payloads.values()].map(
|
|
80
|
+
setPayloads([...payloads.values()].map(value => (value.status === 'rejected' ? null : value.value)) as (T | null)[])
|
|
83
81
|
setErrors(
|
|
84
82
|
compact(
|
|
85
|
-
[...payloads.values()].map(
|
|
83
|
+
[...payloads.values()].map(value => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined)),
|
|
86
84
|
),
|
|
87
85
|
)
|
|
88
86
|
}
|
package/src/contexts/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './DivinedPayload/index.
|
|
2
|
-
export * from './PayloadDiviner/index.
|
|
1
|
+
export * from './DivinedPayload/index.ts'
|
|
2
|
+
export * from './PayloadDiviner/index.ts'
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './contexts/index.
|
|
1
|
+
export * from './contexts/index.ts'
|
package/dist/browser/index.js
DELETED
|
@@ -1,161 +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/Provider.tsx
|
|
16
|
-
import { useEffect, useState } from "react";
|
|
17
|
-
import { jsx } from "react/jsx-runtime";
|
|
18
|
-
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
19
|
-
const [diviner, setDiviner] = useState(divinerProp);
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (divinerProp) {
|
|
22
|
-
setDiviner(divinerProp);
|
|
23
|
-
}
|
|
24
|
-
}, [divinerProp]);
|
|
25
|
-
return /* @__PURE__ */ jsx(
|
|
26
|
-
PayloadDivinerContext.Provider,
|
|
27
|
-
{
|
|
28
|
-
value: {
|
|
29
|
-
diviner: diviner === divinerProp ? diviner : void 0,
|
|
30
|
-
provided: true,
|
|
31
|
-
setDiviner
|
|
32
|
-
},
|
|
33
|
-
children: diviner ? children : required ? null : children
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/contexts/PayloadDiviner/use.ts
|
|
39
|
-
import { compact } from "@xylabs/lodash";
|
|
40
|
-
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
41
|
-
import { HuriSchema } from "@xyo-network/diviner-huri";
|
|
42
|
-
import { useContextEx } from "@xyo-network/react-shared";
|
|
43
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
44
|
-
var usePayloadDiviner = (required = false) => {
|
|
45
|
-
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
46
|
-
};
|
|
47
|
-
var useDivinePayload = (huri) => {
|
|
48
|
-
const { diviner } = usePayloadDiviner();
|
|
49
|
-
const [payload, setPayload] = useState2();
|
|
50
|
-
const [error, setError] = useState2();
|
|
51
|
-
useEffect2(() => {
|
|
52
|
-
if (diviner) {
|
|
53
|
-
setPayload(void 0);
|
|
54
|
-
}
|
|
55
|
-
}, [diviner]);
|
|
56
|
-
useAsyncEffect(
|
|
57
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
async (mounted) => {
|
|
59
|
-
if (huri && diviner && payload === void 0) {
|
|
60
|
-
try {
|
|
61
|
-
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
62
|
-
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
63
|
-
if (mounted()) {
|
|
64
|
-
setPayload(payload2 ? payload2 : null);
|
|
65
|
-
}
|
|
66
|
-
} catch (ex) {
|
|
67
|
-
if (mounted()) {
|
|
68
|
-
setError(ex);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
[diviner, huri, payload]
|
|
74
|
-
);
|
|
75
|
-
return [payload, setPayload, error];
|
|
76
|
-
};
|
|
77
|
-
var useDivinePayloads = (huriList) => {
|
|
78
|
-
const { diviner } = usePayloadDiviner();
|
|
79
|
-
const [payloads, setPayloads] = useState2();
|
|
80
|
-
const [errors, setErrors] = useState2();
|
|
81
|
-
useEffect2(() => {
|
|
82
|
-
if (diviner) {
|
|
83
|
-
setPayloads(void 0);
|
|
84
|
-
}
|
|
85
|
-
}, [diviner]);
|
|
86
|
-
useAsyncEffect(
|
|
87
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
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
|
-
);
|
|
97
|
-
if (mounted()) {
|
|
98
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
99
|
-
setErrors(
|
|
100
|
-
compact(
|
|
101
|
-
[...payloads2.values()].map((value) => value.status === "rejected" ? new Error("divine failed", { cause: value.reason }) : void 0)
|
|
102
|
-
)
|
|
103
|
-
);
|
|
104
|
-
if (mounted()) {
|
|
105
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
106
|
-
setErrors(
|
|
107
|
-
compact(
|
|
108
|
-
[...payloads2.values()].map((value) => value.status === "rejected" ? new Error("divine failed", { cause: value.reason }) : void 0)
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
[diviner, huriList, payloads]
|
|
115
|
-
);
|
|
116
|
-
return [payloads, setPayloads, errors];
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// src/contexts/DivinedPayload/use.ts
|
|
120
|
-
import { useContextEx as useContextEx2 } from "@xyo-network/react-shared";
|
|
121
|
-
var useDivinedPayload = () => useContextEx2(DivinedPayloadContext, "DivinedPayload", true);
|
|
122
|
-
|
|
123
|
-
// src/contexts/DivinedPayload/Provider.tsx
|
|
124
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
125
|
-
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
126
|
-
const { hash: hashParam } = useParams();
|
|
127
|
-
const huriFromHashParam = useBuildHuri(hashParam);
|
|
128
|
-
const [params] = useSearchParams();
|
|
129
|
-
const huriSearchParameter = params.get("huri");
|
|
130
|
-
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
131
|
-
const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam;
|
|
132
|
-
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
133
|
-
return /* @__PURE__ */ jsx2(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
134
|
-
};
|
|
135
|
-
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
136
|
-
const { payloadError } = useDivinedPayload();
|
|
137
|
-
return /* @__PURE__ */ jsx2(
|
|
138
|
-
ErrorRender,
|
|
139
|
-
{
|
|
140
|
-
error: payloadError ? { message: payloadError.message, schema: ModuleErrorSchema, sources: [] } : void 0,
|
|
141
|
-
errorContext: "Divined Payload Provider",
|
|
142
|
-
children
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
147
|
-
return /* @__PURE__ */ jsx2(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ jsx2(DivinedPayloadWithHandleInner, { children }) });
|
|
148
|
-
};
|
|
149
|
-
export {
|
|
150
|
-
DivinedPayloadContext,
|
|
151
|
-
DivinedPayloadProvider,
|
|
152
|
-
DivinedPayloadWithHandleInner,
|
|
153
|
-
DivinedPayloadWithHandleProvider,
|
|
154
|
-
PayloadDivinerContext,
|
|
155
|
-
PayloadDivinerProvider,
|
|
156
|
-
useDivinePayload,
|
|
157
|
-
useDivinePayloads,
|
|
158
|
-
useDivinedPayload,
|
|
159
|
-
usePayloadDiviner
|
|
160
|
-
};
|
|
161
|
-
//# 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/Provider.tsx","../../src/contexts/PayloadDiviner/use.ts","../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State.js'\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/index.js'\nimport { DivinedPayloadContext } from './Context.js'\nimport { useDivinedPayload } from './use.js'\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 ?? 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.js'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.js'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: PayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<PayloadDiviner | 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 ?\n children\n : required ?\n null\n : 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-huri'\nimport { Payload, WithMeta } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.js'\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 WithMeta<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(\n [...payloads.values()].map((value) => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined)),\n ),\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' ? new 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.js'\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;;;ACFnE,SAAS,WAAW,gBAAgB;AAmBhC;AAVG,IAAM,yBAAgE,CAAC,EAAE,SAAS,aAAa,WAAW,OAAO,SAAS,MAAM;AACrI,QAAM,CAAC,SAAS,UAAU,IAAI,SAAqC,WAAW;AAE9E,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;A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ACvC;;;AC9FA,SAAS,gBAAAC,qBAAoB;AAItB,IAAM,oBAAoB,MAAMC,cAAa,uBAAuB,kBAAkB,IAAI;;;AJsBxF,gBAAAC,YAAA;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,QAAQ,oBAAoB;AAE5C,QAAM,CAAC,SAAS,YAAY,YAAY,IAAI,iBAAiB,OAAO;AAEpE,SAAO,gBAAAA,KAAC,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,gBAAAA;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,gBAAAA,KAAC,0BAAwB,GAAG,OAC1B,0BAAAA,KAAC,iCAA+B,UAAS,GAC3C;AAEJ;","names":["createContextEx","useEffect","useState","useState","useEffect","payload","payloads","useContextEx","useContextEx","jsx"]}
|
package/dist/neutral/index.js
DELETED
|
@@ -1,161 +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/Provider.tsx
|
|
16
|
-
import { useEffect, useState } from "react";
|
|
17
|
-
import { jsx } from "react/jsx-runtime";
|
|
18
|
-
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
19
|
-
const [diviner, setDiviner] = useState(divinerProp);
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
if (divinerProp) {
|
|
22
|
-
setDiviner(divinerProp);
|
|
23
|
-
}
|
|
24
|
-
}, [divinerProp]);
|
|
25
|
-
return /* @__PURE__ */ jsx(
|
|
26
|
-
PayloadDivinerContext.Provider,
|
|
27
|
-
{
|
|
28
|
-
value: {
|
|
29
|
-
diviner: diviner === divinerProp ? diviner : void 0,
|
|
30
|
-
provided: true,
|
|
31
|
-
setDiviner
|
|
32
|
-
},
|
|
33
|
-
children: diviner ? children : required ? null : children
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// src/contexts/PayloadDiviner/use.ts
|
|
39
|
-
import { compact } from "@xylabs/lodash";
|
|
40
|
-
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
41
|
-
import { HuriSchema } from "@xyo-network/diviner-huri";
|
|
42
|
-
import { useContextEx } from "@xyo-network/react-shared";
|
|
43
|
-
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
44
|
-
var usePayloadDiviner = (required = false) => {
|
|
45
|
-
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
46
|
-
};
|
|
47
|
-
var useDivinePayload = (huri) => {
|
|
48
|
-
const { diviner } = usePayloadDiviner();
|
|
49
|
-
const [payload, setPayload] = useState2();
|
|
50
|
-
const [error, setError] = useState2();
|
|
51
|
-
useEffect2(() => {
|
|
52
|
-
if (diviner) {
|
|
53
|
-
setPayload(void 0);
|
|
54
|
-
}
|
|
55
|
-
}, [diviner]);
|
|
56
|
-
useAsyncEffect(
|
|
57
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
async (mounted) => {
|
|
59
|
-
if (huri && diviner && payload === void 0) {
|
|
60
|
-
try {
|
|
61
|
-
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
62
|
-
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
63
|
-
if (mounted()) {
|
|
64
|
-
setPayload(payload2 ? payload2 : null);
|
|
65
|
-
}
|
|
66
|
-
} catch (ex) {
|
|
67
|
-
if (mounted()) {
|
|
68
|
-
setError(ex);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
[diviner, huri, payload]
|
|
74
|
-
);
|
|
75
|
-
return [payload, setPayload, error];
|
|
76
|
-
};
|
|
77
|
-
var useDivinePayloads = (huriList) => {
|
|
78
|
-
const { diviner } = usePayloadDiviner();
|
|
79
|
-
const [payloads, setPayloads] = useState2();
|
|
80
|
-
const [errors, setErrors] = useState2();
|
|
81
|
-
useEffect2(() => {
|
|
82
|
-
if (diviner) {
|
|
83
|
-
setPayloads(void 0);
|
|
84
|
-
}
|
|
85
|
-
}, [diviner]);
|
|
86
|
-
useAsyncEffect(
|
|
87
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
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
|
-
);
|
|
97
|
-
if (mounted()) {
|
|
98
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
99
|
-
setErrors(
|
|
100
|
-
compact(
|
|
101
|
-
[...payloads2.values()].map((value) => value.status === "rejected" ? new Error("divine failed", { cause: value.reason }) : void 0)
|
|
102
|
-
)
|
|
103
|
-
);
|
|
104
|
-
if (mounted()) {
|
|
105
|
-
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
106
|
-
setErrors(
|
|
107
|
-
compact(
|
|
108
|
-
[...payloads2.values()].map((value) => value.status === "rejected" ? new Error("divine failed", { cause: value.reason }) : void 0)
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
[diviner, huriList, payloads]
|
|
115
|
-
);
|
|
116
|
-
return [payloads, setPayloads, errors];
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// src/contexts/DivinedPayload/use.ts
|
|
120
|
-
import { useContextEx as useContextEx2 } from "@xyo-network/react-shared";
|
|
121
|
-
var useDivinedPayload = () => useContextEx2(DivinedPayloadContext, "DivinedPayload", true);
|
|
122
|
-
|
|
123
|
-
// src/contexts/DivinedPayload/Provider.tsx
|
|
124
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
125
|
-
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
126
|
-
const { hash: hashParam } = useParams();
|
|
127
|
-
const huriFromHashParam = useBuildHuri(hashParam);
|
|
128
|
-
const [params] = useSearchParams();
|
|
129
|
-
const huriSearchParameter = params.get("huri");
|
|
130
|
-
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
131
|
-
const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam;
|
|
132
|
-
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
133
|
-
return /* @__PURE__ */ jsx2(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
134
|
-
};
|
|
135
|
-
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
136
|
-
const { payloadError } = useDivinedPayload();
|
|
137
|
-
return /* @__PURE__ */ jsx2(
|
|
138
|
-
ErrorRender,
|
|
139
|
-
{
|
|
140
|
-
error: payloadError ? { message: payloadError.message, schema: ModuleErrorSchema, sources: [] } : void 0,
|
|
141
|
-
errorContext: "Divined Payload Provider",
|
|
142
|
-
children
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
147
|
-
return /* @__PURE__ */ jsx2(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ jsx2(DivinedPayloadWithHandleInner, { children }) });
|
|
148
|
-
};
|
|
149
|
-
export {
|
|
150
|
-
DivinedPayloadContext,
|
|
151
|
-
DivinedPayloadProvider,
|
|
152
|
-
DivinedPayloadWithHandleInner,
|
|
153
|
-
DivinedPayloadWithHandleProvider,
|
|
154
|
-
PayloadDivinerContext,
|
|
155
|
-
PayloadDivinerProvider,
|
|
156
|
-
useDivinePayload,
|
|
157
|
-
useDivinePayloads,
|
|
158
|
-
useDivinedPayload,
|
|
159
|
-
usePayloadDiviner
|
|
160
|
-
};
|
|
161
|
-
//# 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/Provider.tsx","../../src/contexts/PayloadDiviner/use.ts","../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State.js'\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/index.js'\nimport { DivinedPayloadContext } from './Context.js'\nimport { useDivinedPayload } from './use.js'\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 ?? 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.js'\n\nconst PayloadDivinerContext = createContextEx<PayloadDivinerState>()\n\nexport { PayloadDivinerContext }\n","import { PayloadDiviner } from '@xyo-network/diviner-payload-abstract'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.js'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: PayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<PayloadDiviner | 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 ?\n children\n : required ?\n null\n : 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-huri'\nimport { Payload, WithMeta } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context.js'\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 WithMeta<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(\n [...payloads.values()].map((value) => (value.status === 'rejected' ? new Error('divine failed', { cause: value.reason }) : undefined)),\n ),\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' ? new 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.js'\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;;;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