@xyo-network/react-payload-diviner 2.64.0-rc.7 → 2.64.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/contexts/DivinedPayload/Context.cjs +28 -0
- package/dist/{node/contexts/DivinedPayload/Context.mjs.map → browser/contexts/DivinedPayload/Context.cjs.map} +1 -1
- package/dist/browser/contexts/DivinedPayload/Context.d.cts +4 -0
- package/dist/browser/contexts/DivinedPayload/Context.d.cts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/Context.js +2 -1
- package/dist/browser/contexts/DivinedPayload/Context.js.map +1 -1
- package/dist/browser/contexts/DivinedPayload/Provider.cjs +111 -0
- package/dist/browser/contexts/DivinedPayload/Provider.cjs.map +1 -0
- package/dist/browser/contexts/DivinedPayload/Provider.d.cts +9 -0
- package/dist/browser/contexts/DivinedPayload/Provider.d.cts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/Provider.js +59 -7
- package/dist/browser/contexts/DivinedPayload/Provider.js.map +1 -1
- package/dist/browser/contexts/DivinedPayload/State.cjs +19 -0
- package/dist/browser/contexts/DivinedPayload/State.cjs.map +1 -0
- package/dist/browser/contexts/DivinedPayload/State.d.cts +9 -0
- package/dist/browser/contexts/DivinedPayload/State.d.cts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/index.cjs +115 -0
- package/dist/browser/contexts/DivinedPayload/index.cjs.map +1 -0
- package/dist/browser/contexts/DivinedPayload/index.d.cts +5 -0
- package/dist/browser/contexts/DivinedPayload/index.d.cts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/index.js +91 -4
- package/dist/browser/contexts/DivinedPayload/index.js.map +1 -1
- package/dist/browser/contexts/DivinedPayload/use.cjs +34 -0
- package/dist/browser/contexts/DivinedPayload/use.cjs.map +1 -0
- package/dist/browser/contexts/DivinedPayload/use.d.cts +2 -0
- package/dist/browser/contexts/DivinedPayload/use.d.cts.map +1 -0
- package/dist/browser/contexts/DivinedPayload/use.js +8 -2
- package/dist/browser/contexts/DivinedPayload/use.js.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/Context.cjs +28 -0
- package/dist/{node/contexts/PayloadDiviner/Context.mjs.map → browser/contexts/PayloadDiviner/Context.cjs.map} +1 -1
- package/dist/browser/contexts/PayloadDiviner/Context.d.cts +5 -0
- package/dist/browser/contexts/PayloadDiviner/Context.d.cts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/Context.js +2 -1
- package/dist/browser/contexts/PayloadDiviner/Context.js.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/Provider.cjs +53 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.cjs.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.d.cts +9 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.d.cts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/Provider.js +9 -3
- package/dist/browser/contexts/PayloadDiviner/Provider.js.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/State.cjs +19 -0
- package/dist/browser/contexts/PayloadDiviner/State.cjs.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/State.d.cts +7 -0
- package/dist/browser/contexts/PayloadDiviner/State.d.cts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/index.cjs +136 -0
- package/dist/browser/contexts/PayloadDiviner/index.cjs.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/index.d.cts +5 -0
- package/dist/browser/contexts/PayloadDiviner/index.d.cts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/index.js +112 -4
- package/dist/browser/contexts/PayloadDiviner/index.js.map +1 -1
- package/dist/browser/contexts/PayloadDiviner/use.cjs +111 -0
- package/dist/browser/contexts/PayloadDiviner/use.cjs.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/use.d.cts +13 -0
- package/dist/browser/contexts/PayloadDiviner/use.d.cts.map +1 -0
- package/dist/browser/contexts/PayloadDiviner/use.js +10 -4
- package/dist/browser/contexts/PayloadDiviner/use.js.map +1 -1
- package/dist/browser/contexts/index.cjs +182 -0
- package/dist/browser/contexts/index.cjs.map +1 -0
- package/dist/browser/contexts/index.d.cts +3 -0
- package/dist/browser/contexts/index.d.cts.map +1 -0
- package/dist/browser/contexts/index.js +158 -2
- package/dist/browser/contexts/index.js.map +1 -1
- package/dist/browser/index.cjs +182 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +2 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.js +158 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types/images.d.cjs +2 -0
- package/dist/docs.json +1796 -0
- package/dist/node/contexts/DivinedPayload/Context.cjs +32 -0
- package/dist/node/contexts/DivinedPayload/Context.cjs.map +1 -0
- package/dist/node/contexts/DivinedPayload/Context.d.cts +4 -0
- package/dist/node/contexts/DivinedPayload/Context.d.cts.map +1 -0
- package/dist/node/contexts/DivinedPayload/Context.js +5 -28
- package/dist/node/contexts/DivinedPayload/Context.js.map +1 -1
- package/dist/node/contexts/DivinedPayload/Provider.cjs +117 -0
- package/dist/node/contexts/DivinedPayload/Provider.cjs.map +1 -0
- package/dist/node/contexts/DivinedPayload/Provider.d.cts +9 -0
- package/dist/node/contexts/DivinedPayload/Provider.d.cts.map +1 -0
- package/dist/node/contexts/DivinedPayload/Provider.js +73 -47
- package/dist/node/contexts/DivinedPayload/Provider.js.map +1 -1
- package/dist/node/contexts/DivinedPayload/State.cjs +19 -0
- package/dist/node/contexts/DivinedPayload/State.cjs.map +1 -0
- package/dist/node/contexts/DivinedPayload/State.d.cts +9 -0
- package/dist/node/contexts/DivinedPayload/State.d.cts.map +1 -0
- package/dist/node/contexts/DivinedPayload/State.js +0 -16
- package/dist/node/contexts/DivinedPayload/State.js.map +1 -1
- package/dist/node/contexts/DivinedPayload/index.cjs +123 -0
- package/dist/node/contexts/DivinedPayload/index.cjs.map +1 -0
- package/dist/node/contexts/DivinedPayload/index.d.cts +5 -0
- package/dist/node/contexts/DivinedPayload/index.d.cts.map +1 -0
- package/dist/node/contexts/DivinedPayload/index.js +90 -27
- package/dist/node/contexts/DivinedPayload/index.js.map +1 -1
- package/dist/node/contexts/DivinedPayload/use.cjs +38 -0
- package/dist/node/contexts/DivinedPayload/use.cjs.map +1 -0
- package/dist/node/contexts/DivinedPayload/use.d.cts +2 -0
- package/dist/node/contexts/DivinedPayload/use.d.cts.map +1 -0
- package/dist/node/contexts/DivinedPayload/use.js +11 -29
- package/dist/node/contexts/DivinedPayload/use.js.map +1 -1
- package/dist/node/contexts/PayloadDiviner/Context.cjs +32 -0
- package/dist/node/contexts/PayloadDiviner/Context.cjs.map +1 -0
- package/dist/node/contexts/PayloadDiviner/Context.d.cts +5 -0
- package/dist/node/contexts/PayloadDiviner/Context.d.cts.map +1 -0
- package/dist/node/contexts/PayloadDiviner/Context.js +5 -28
- package/dist/node/contexts/PayloadDiviner/Context.js.map +1 -1
- package/dist/node/contexts/PayloadDiviner/Provider.cjs +57 -0
- package/dist/node/contexts/PayloadDiviner/Provider.cjs.map +1 -0
- package/dist/node/contexts/PayloadDiviner/Provider.d.cts +9 -0
- package/dist/node/contexts/PayloadDiviner/Provider.d.cts.map +1 -0
- package/dist/node/contexts/PayloadDiviner/Provider.js +16 -34
- package/dist/node/contexts/PayloadDiviner/Provider.js.map +1 -1
- package/dist/node/contexts/PayloadDiviner/State.cjs +19 -0
- package/dist/node/contexts/PayloadDiviner/State.cjs.map +1 -0
- package/dist/node/contexts/PayloadDiviner/State.d.cts +7 -0
- package/dist/node/contexts/PayloadDiviner/State.d.cts.map +1 -0
- package/dist/node/contexts/PayloadDiviner/State.js +0 -16
- package/dist/node/contexts/PayloadDiviner/State.js.map +1 -1
- package/dist/node/contexts/PayloadDiviner/index.cjs +144 -0
- package/dist/node/contexts/PayloadDiviner/index.cjs.map +1 -0
- package/dist/node/contexts/PayloadDiviner/index.d.cts +5 -0
- package/dist/node/contexts/PayloadDiviner/index.d.cts.map +1 -0
- package/dist/node/contexts/PayloadDiviner/index.js +111 -27
- package/dist/node/contexts/PayloadDiviner/index.js.map +1 -1
- package/dist/node/contexts/PayloadDiviner/use.cjs +117 -0
- package/dist/node/contexts/PayloadDiviner/use.cjs.map +1 -0
- package/dist/node/contexts/PayloadDiviner/use.d.cts +13 -0
- package/dist/node/contexts/PayloadDiviner/use.d.cts.map +1 -0
- package/dist/node/contexts/PayloadDiviner/use.js +32 -52
- package/dist/node/contexts/PayloadDiviner/use.js.map +1 -1
- package/dist/node/contexts/index.cjs +195 -0
- package/dist/node/contexts/index.cjs.map +1 -0
- package/dist/node/contexts/index.d.cts +3 -0
- package/dist/node/contexts/index.d.cts.map +1 -0
- package/dist/node/contexts/index.js +158 -24
- package/dist/node/contexts/index.js.map +1 -1
- package/dist/node/index.cjs +195 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +2 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +158 -22
- package/dist/node/index.js.map +1 -1
- package/dist/node/types/images.d.cjs +2 -0
- package/dist/node/types/images.d.js +0 -1
- package/package.json +19 -19
- package/dist/node/contexts/DivinedPayload/Context.mjs +0 -6
- package/dist/node/contexts/DivinedPayload/Provider.mjs +0 -38
- package/dist/node/contexts/DivinedPayload/Provider.mjs.map +0 -1
- package/dist/node/contexts/DivinedPayload/State.mjs +0 -1
- package/dist/node/contexts/DivinedPayload/index.mjs +0 -5
- package/dist/node/contexts/DivinedPayload/index.mjs.map +0 -1
- package/dist/node/contexts/DivinedPayload/use.mjs +0 -7
- package/dist/node/contexts/DivinedPayload/use.mjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/Context.mjs +0 -6
- package/dist/node/contexts/PayloadDiviner/Provider.mjs +0 -26
- package/dist/node/contexts/PayloadDiviner/Provider.mjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/State.mjs +0 -1
- package/dist/node/contexts/PayloadDiviner/index.mjs +0 -5
- package/dist/node/contexts/PayloadDiviner/index.mjs.map +0 -1
- package/dist/node/contexts/PayloadDiviner/use.mjs +0 -84
- package/dist/node/contexts/PayloadDiviner/use.mjs.map +0 -1
- package/dist/node/contexts/index.mjs +0 -3
- package/dist/node/contexts/index.mjs.map +0 -1
- package/dist/node/index.mjs +0 -2
- package/dist/node/index.mjs.map +0 -1
- package/dist/node/types/images.d.mjs +0 -1
- package/dist/node/types/images.d.mjs.map +0 -1
- /package/dist/{node/contexts/DivinedPayload/State.mjs.map → browser/types/images.d.cjs.map} +0 -0
- /package/dist/node/{contexts/PayloadDiviner/State.mjs.map → types/images.d.cjs.map} +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
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/Context.tsx
|
|
21
|
+
var Context_exports = {};
|
|
22
|
+
__export(Context_exports, {
|
|
23
|
+
DivinedPayloadContext: () => DivinedPayloadContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(Context_exports);
|
|
26
|
+
var import_react_shared = require("@xyo-network/react-shared");
|
|
27
|
+
var DivinedPayloadContext = (0, import_react_shared.createContextEx)();
|
|
28
|
+
//# sourceMappingURL=Context.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Context.tsx"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Context.tsx"],"sourcesContent":["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,0BAAgC;AAIzB,IAAM,4BAAwB,qCAAqC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Context.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAE7C,eAAO,MAAM,qBAAqB,mGAAyC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Context.tsx"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n"],"mappings":"AAAA,SAAS,uBAAuB;AAIzB,
|
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Context.tsx"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,wBAAwB,gBAAqC;","names":[]}
|
|
@@ -0,0 +1,111 @@
|
|
|
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/Provider.tsx
|
|
21
|
+
var Provider_exports = {};
|
|
22
|
+
__export(Provider_exports, {
|
|
23
|
+
DivinedPayloadProvider: () => DivinedPayloadProvider,
|
|
24
|
+
DivinedPayloadWithHandleInner: () => DivinedPayloadWithHandleInner,
|
|
25
|
+
DivinedPayloadWithHandleProvider: () => DivinedPayloadWithHandleProvider
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(Provider_exports);
|
|
28
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
29
|
+
var import_react_error = require("@xyo-network/react-error");
|
|
30
|
+
var import_react_payload_huri = require("@xyo-network/react-payload-huri");
|
|
31
|
+
var import_react_router_dom = require("react-router-dom");
|
|
32
|
+
|
|
33
|
+
// src/contexts/PayloadDiviner/Context.ts
|
|
34
|
+
var import_react_shared = require("@xyo-network/react-shared");
|
|
35
|
+
var PayloadDivinerContext = (0, import_react_shared.createContextEx)();
|
|
36
|
+
|
|
37
|
+
// src/contexts/PayloadDiviner/use.ts
|
|
38
|
+
var import_lodash = require("@xylabs/lodash");
|
|
39
|
+
var import_react_async_effect = require("@xylabs/react-async-effect");
|
|
40
|
+
var import_diviner = require("@xyo-network/diviner");
|
|
41
|
+
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
var usePayloadDiviner = (required = false) => {
|
|
44
|
+
return (0, import_react_shared2.useContextEx)(PayloadDivinerContext, "PayloadDiviner", required);
|
|
45
|
+
};
|
|
46
|
+
var useDivinePayload = (huri) => {
|
|
47
|
+
const { diviner } = usePayloadDiviner();
|
|
48
|
+
const [payload, setPayload] = (0, import_react.useState)();
|
|
49
|
+
const [error, setError] = (0, import_react.useState)();
|
|
50
|
+
(0, import_react.useEffect)(() => {
|
|
51
|
+
if (diviner) {
|
|
52
|
+
setPayload(void 0);
|
|
53
|
+
}
|
|
54
|
+
}, [diviner]);
|
|
55
|
+
(0, import_react_async_effect.useAsyncEffect)(
|
|
56
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
+
async (mounted) => {
|
|
58
|
+
if (huri && diviner && payload === void 0) {
|
|
59
|
+
try {
|
|
60
|
+
const huriPayload = { huri: [huri], schema: import_diviner.HuriSchema };
|
|
61
|
+
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
62
|
+
if (mounted()) {
|
|
63
|
+
setPayload(payload2 ? payload2 : null);
|
|
64
|
+
}
|
|
65
|
+
} catch (ex) {
|
|
66
|
+
if (mounted()) {
|
|
67
|
+
setError(ex);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
[diviner, huri, payload]
|
|
73
|
+
);
|
|
74
|
+
return [payload, setPayload, error];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/contexts/DivinedPayload/Context.tsx
|
|
78
|
+
var import_react_shared3 = require("@xyo-network/react-shared");
|
|
79
|
+
var DivinedPayloadContext = (0, import_react_shared3.createContextEx)();
|
|
80
|
+
|
|
81
|
+
// src/contexts/DivinedPayload/use.ts
|
|
82
|
+
var import_react_shared4 = require("@xyo-network/react-shared");
|
|
83
|
+
var useDivinedPayload = () => (0, import_react_shared4.useContextEx)(DivinedPayloadContext, "DivinedPayload", true);
|
|
84
|
+
|
|
85
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
86
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
87
|
+
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
88
|
+
const { hash: hashParam } = (0, import_react_router_dom.useParams)();
|
|
89
|
+
const huriFromHashParam = (0, import_react_payload_huri.useBuildHuri)(hashParam);
|
|
90
|
+
const [params] = (0, import_react_router_dom.useSearchParams)();
|
|
91
|
+
const huriSearchParameter = params.get("huri");
|
|
92
|
+
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
93
|
+
const huriUri = hash ?? (decodedHuriParam ? decodedHuriParam : huriFromHashParam);
|
|
94
|
+
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
95
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
96
|
+
};
|
|
97
|
+
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
98
|
+
const { payloadError } = useDivinedPayload();
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
100
|
+
import_react_error.ErrorRender,
|
|
101
|
+
{
|
|
102
|
+
error: payloadError ? { message: payloadError.message, schema: import_payload_model.ModuleErrorSchema, sources: [] } : void 0,
|
|
103
|
+
errorContext: "Divined Payload Provider",
|
|
104
|
+
children
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DivinedPayloadWithHandleInner, { children }) });
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=Provider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Provider.tsx","../../../../src/contexts/PayloadDiviner/Context.ts","../../../../src/contexts/PayloadDiviner/use.ts","../../../../src/contexts/DivinedPayload/Context.tsx","../../../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["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 { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\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;AACA,2BAAkC;AAClC,yBAA4B;AAC5B,gCAA6B;AAC7B,8BAA2C;;;ACJ3C,0BAAgC;AAIhC,IAAM,4BAAwB,qCAAqC;;;ACJnE,oBAAwB;AACxB,gCAA+B;AAC/B,qBAAwC;AAExC,IAAAA,uBAA6B;AAC7B,mBAA8C;AAIvC,IAAM,oBAAoB,CAAC,WAAW,UAAU;AACrD,aAAO,mCAAa,uBAAuB,kBAAkB,QA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AAM,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","payload","import_react_shared","import_react_shared"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { WithChildren } from '@xylabs/react-shared';
|
|
3
|
+
export interface DivinedPayloadProviderProps extends WithChildren {
|
|
4
|
+
hash?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const DivinedPayloadProvider: React.FC<DivinedPayloadProviderProps>;
|
|
7
|
+
export declare const DivinedPayloadWithHandleInner: React.FC<WithChildren>;
|
|
8
|
+
export declare const DivinedPayloadWithHandleProvider: React.FC<DivinedPayloadProviderProps>;
|
|
9
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Provider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAUxD,MAAM,WAAW,2BAA4B,SAAQ,YAAY;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAaxE,CAAA;AAED,eAAO,MAAM,6BAA6B,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAWhE,CAAA;AAED,eAAO,MAAM,gCAAgC,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAMlF,CAAA"}
|
|
@@ -1,12 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
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
5
|
import { useParams, useSearchParams } from "react-router-dom";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
6
|
+
|
|
7
|
+
// src/contexts/PayloadDiviner/Context.ts
|
|
8
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
9
|
+
var PayloadDivinerContext = createContextEx();
|
|
10
|
+
|
|
11
|
+
// src/contexts/PayloadDiviner/use.ts
|
|
12
|
+
import { compact } from "@xylabs/lodash";
|
|
13
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
14
|
+
import { HuriSchema } from "@xyo-network/diviner";
|
|
15
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
16
|
+
import { useEffect, useState } from "react";
|
|
17
|
+
var usePayloadDiviner = (required = false) => {
|
|
18
|
+
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
19
|
+
};
|
|
20
|
+
var useDivinePayload = (huri) => {
|
|
21
|
+
const { diviner } = usePayloadDiviner();
|
|
22
|
+
const [payload, setPayload] = useState();
|
|
23
|
+
const [error, setError] = useState();
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (diviner) {
|
|
26
|
+
setPayload(void 0);
|
|
27
|
+
}
|
|
28
|
+
}, [diviner]);
|
|
29
|
+
useAsyncEffect(
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
+
async (mounted) => {
|
|
32
|
+
if (huri && diviner && payload === void 0) {
|
|
33
|
+
try {
|
|
34
|
+
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
35
|
+
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
36
|
+
if (mounted()) {
|
|
37
|
+
setPayload(payload2 ? payload2 : null);
|
|
38
|
+
}
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
if (mounted()) {
|
|
41
|
+
setError(ex);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
[diviner, huri, payload]
|
|
47
|
+
);
|
|
48
|
+
return [payload, setPayload, error];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/contexts/DivinedPayload/Context.tsx
|
|
52
|
+
import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
|
|
53
|
+
var DivinedPayloadContext = createContextEx2();
|
|
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 }) => {
|
|
10
62
|
const { hash: hashParam } = useParams();
|
|
11
63
|
const huriFromHashParam = useBuildHuri(hashParam);
|
|
12
64
|
const [params] = useSearchParams();
|
|
@@ -16,7 +68,7 @@ const DivinedPayloadProvider = ({ children, hash }) => {
|
|
|
16
68
|
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
17
69
|
return /* @__PURE__ */ jsx(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
18
70
|
};
|
|
19
|
-
|
|
71
|
+
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
20
72
|
const { payloadError } = useDivinedPayload();
|
|
21
73
|
return /* @__PURE__ */ jsx(
|
|
22
74
|
ErrorRender,
|
|
@@ -27,7 +79,7 @@ const DivinedPayloadWithHandleInner = ({ children }) => {
|
|
|
27
79
|
}
|
|
28
80
|
);
|
|
29
81
|
};
|
|
30
|
-
|
|
82
|
+
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
31
83
|
return /* @__PURE__ */ jsx(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ jsx(DivinedPayloadWithHandleInner, { children }) });
|
|
32
84
|
};
|
|
33
85
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Provider.tsx"],"sourcesContent":["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"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/Provider.tsx","../../../../src/contexts/PayloadDiviner/Context.ts","../../../../src/contexts/PayloadDiviner/use.ts","../../../../src/contexts/DivinedPayload/Context.tsx","../../../../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["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 { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\n\nexport const DivinedPayloadContext = createContextEx<DivinedPayloadState>()\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadContext } from './Context'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";AACA,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,WAAW,uBAAuB;;;ACJ3C,SAAS,uBAAuB;AAIhC,IAAM,wBAAwB,gBAAqC;;;ACJnE,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAsB,kBAAkB;AAExC,SAAS,oBAAoB;AA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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":["payload","createContextEx","useContextEx","useContextEx"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
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/DivinedPayload/State.ts
|
|
17
|
+
var State_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(State_exports);
|
|
19
|
+
//# sourceMappingURL=State.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/State.ts"],"sourcesContent":["import { Payload } from '@xyo-network/payload-model'\nimport { ContextExState } from '@xyo-network/react-shared'\nimport { Dispatch } from 'react'\n\nexport interface DivinedPayloadState extends ContextExState {\n payload?: Payload | null\n payloadError?: Error\n setPayload?: Dispatch<Payload | null | undefined>\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
2
|
+
import { ContextExState } from '@xyo-network/react-shared';
|
|
3
|
+
import { Dispatch } from 'react';
|
|
4
|
+
export interface DivinedPayloadState extends ContextExState {
|
|
5
|
+
payload?: Payload | null;
|
|
6
|
+
payloadError?: Error;
|
|
7
|
+
setPayload?: Dispatch<Payload | null | undefined>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=State.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/State.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,MAAM,WAAW,mBAAoB,SAAQ,cAAc;IACzD,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACxB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,UAAU,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;CAClD"}
|
|
@@ -0,0 +1,115 @@
|
|
|
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/index.ts
|
|
21
|
+
var DivinedPayload_exports = {};
|
|
22
|
+
__export(DivinedPayload_exports, {
|
|
23
|
+
DivinedPayloadContext: () => DivinedPayloadContext,
|
|
24
|
+
DivinedPayloadProvider: () => DivinedPayloadProvider,
|
|
25
|
+
DivinedPayloadWithHandleInner: () => DivinedPayloadWithHandleInner,
|
|
26
|
+
DivinedPayloadWithHandleProvider: () => DivinedPayloadWithHandleProvider,
|
|
27
|
+
useDivinedPayload: () => useDivinedPayload
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(DivinedPayload_exports);
|
|
30
|
+
|
|
31
|
+
// src/contexts/DivinedPayload/Context.tsx
|
|
32
|
+
var import_react_shared = require("@xyo-network/react-shared");
|
|
33
|
+
var DivinedPayloadContext = (0, import_react_shared.createContextEx)();
|
|
34
|
+
|
|
35
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
36
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
37
|
+
var import_react_error = require("@xyo-network/react-error");
|
|
38
|
+
var import_react_payload_huri = require("@xyo-network/react-payload-huri");
|
|
39
|
+
var import_react_router_dom = require("react-router-dom");
|
|
40
|
+
|
|
41
|
+
// src/contexts/PayloadDiviner/Context.ts
|
|
42
|
+
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
43
|
+
var PayloadDivinerContext = (0, import_react_shared2.createContextEx)();
|
|
44
|
+
|
|
45
|
+
// src/contexts/PayloadDiviner/use.ts
|
|
46
|
+
var import_lodash = require("@xylabs/lodash");
|
|
47
|
+
var import_react_async_effect = require("@xylabs/react-async-effect");
|
|
48
|
+
var import_diviner = require("@xyo-network/diviner");
|
|
49
|
+
var import_react_shared3 = require("@xyo-network/react-shared");
|
|
50
|
+
var import_react = require("react");
|
|
51
|
+
var usePayloadDiviner = (required = false) => {
|
|
52
|
+
return (0, import_react_shared3.useContextEx)(PayloadDivinerContext, "PayloadDiviner", required);
|
|
53
|
+
};
|
|
54
|
+
var useDivinePayload = (huri) => {
|
|
55
|
+
const { diviner } = usePayloadDiviner();
|
|
56
|
+
const [payload, setPayload] = (0, import_react.useState)();
|
|
57
|
+
const [error, setError] = (0, import_react.useState)();
|
|
58
|
+
(0, import_react.useEffect)(() => {
|
|
59
|
+
if (diviner) {
|
|
60
|
+
setPayload(void 0);
|
|
61
|
+
}
|
|
62
|
+
}, [diviner]);
|
|
63
|
+
(0, import_react_async_effect.useAsyncEffect)(
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
async (mounted) => {
|
|
66
|
+
if (huri && diviner && payload === void 0) {
|
|
67
|
+
try {
|
|
68
|
+
const huriPayload = { huri: [huri], schema: import_diviner.HuriSchema };
|
|
69
|
+
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
70
|
+
if (mounted()) {
|
|
71
|
+
setPayload(payload2 ? payload2 : null);
|
|
72
|
+
}
|
|
73
|
+
} catch (ex) {
|
|
74
|
+
if (mounted()) {
|
|
75
|
+
setError(ex);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
[diviner, huri, payload]
|
|
81
|
+
);
|
|
82
|
+
return [payload, setPayload, error];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/contexts/DivinedPayload/use.ts
|
|
86
|
+
var import_react_shared4 = require("@xyo-network/react-shared");
|
|
87
|
+
var useDivinedPayload = () => (0, import_react_shared4.useContextEx)(DivinedPayloadContext, "DivinedPayload", true);
|
|
88
|
+
|
|
89
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
90
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
91
|
+
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
92
|
+
const { hash: hashParam } = (0, import_react_router_dom.useParams)();
|
|
93
|
+
const huriFromHashParam = (0, import_react_payload_huri.useBuildHuri)(hashParam);
|
|
94
|
+
const [params] = (0, import_react_router_dom.useSearchParams)();
|
|
95
|
+
const huriSearchParameter = params.get("huri");
|
|
96
|
+
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
97
|
+
const huriUri = hash ?? (decodedHuriParam ? decodedHuriParam : huriFromHashParam);
|
|
98
|
+
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
100
|
+
};
|
|
101
|
+
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
102
|
+
const { payloadError } = useDivinedPayload();
|
|
103
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
104
|
+
import_react_error.ErrorRender,
|
|
105
|
+
{
|
|
106
|
+
error: payloadError ? { message: payloadError.message, schema: import_payload_model.ModuleErrorSchema, sources: [] } : void 0,
|
|
107
|
+
errorContext: "Divined Payload Provider",
|
|
108
|
+
children
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
113
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DivinedPayloadWithHandleInner, { children }) });
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;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,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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA"}
|
|
@@ -1,5 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
};
|
|
5
92
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/contexts/DivinedPayload/
|
|
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,w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