@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import { Dispatch } from 'react';
|
|
3
|
-
export declare const usePayloadDiviner: (required?: boolean) => Omit<import("./State.
|
|
3
|
+
export declare const usePayloadDiviner: (required?: boolean) => Omit<import("./State.ts").PayloadDivinerState & import("@xyo-network/react-shared").ContextExState, "provided">;
|
|
4
4
|
export declare const useDivinePayload: <T extends Payload = {
|
|
5
5
|
schema: string;
|
|
6
6
|
} & import("@xyo-network/payload-model").PayloadFields>(huri?: string) => [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/use.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAY,MAAM,4BAA4B,CAAA;AAE9D,OAAO,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAA;AAIrD,eAAO,MAAM,iBAAiB,yIAE7B,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO;;+DACzC,MAAM,KACZ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/use.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAY,MAAM,4BAA4B,CAAA;AAE9D,OAAO,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAA;AAIrD,eAAO,MAAM,iBAAiB,yIAE7B,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO;;+DACzC,MAAM,KACZ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,CA+B1E,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,OAAO;;kEACvC,MAAM,EAAE,KACjB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,SAAS,CA0CpF,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './DivinedPayload/index.
|
|
2
|
-
export * from './PayloadDiviner/index.
|
|
1
|
+
export * from './DivinedPayload/index.ts';
|
|
2
|
+
export * from './PayloadDiviner/index.ts';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './DivinedPayload/index.
|
|
2
|
-
export * from './PayloadDiviner/index.
|
|
1
|
+
export * from './DivinedPayload/index.ts';
|
|
2
|
+
export * from './PayloadDiviner/index.ts';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './DivinedPayload/index.
|
|
2
|
-
export * from './PayloadDiviner/index.
|
|
1
|
+
export * from './DivinedPayload/index.ts';
|
|
2
|
+
export * from './PayloadDiviner/index.ts';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
9
|
var __export = (target, all) => {
|
|
7
10
|
for (var name in all)
|
|
8
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
18
|
}
|
|
16
19
|
return to;
|
|
17
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
18
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
30
|
|
|
20
31
|
// src/index.ts
|
|
@@ -33,7 +44,7 @@ __export(src_exports, {
|
|
|
33
44
|
});
|
|
34
45
|
module.exports = __toCommonJS(src_exports);
|
|
35
46
|
|
|
36
|
-
// src/contexts/DivinedPayload/Context.
|
|
47
|
+
// src/contexts/DivinedPayload/Context.ts
|
|
37
48
|
var import_react_shared = require("@xyo-network/react-shared");
|
|
38
49
|
var DivinedPayloadContext = (0, import_react_shared.createContextEx)();
|
|
39
50
|
|
|
@@ -41,6 +52,7 @@ var DivinedPayloadContext = (0, import_react_shared.createContextEx)();
|
|
|
41
52
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
42
53
|
var import_react_error = require("@xyo-network/react-error");
|
|
43
54
|
var import_react_payload_huri = require("@xyo-network/react-payload-huri");
|
|
55
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
44
56
|
var import_react_router_dom = require("react-router-dom");
|
|
45
57
|
|
|
46
58
|
// src/contexts/PayloadDiviner/Context.ts
|
|
@@ -48,27 +60,29 @@ var import_react_shared2 = require("@xyo-network/react-shared");
|
|
|
48
60
|
var PayloadDivinerContext = (0, import_react_shared2.createContextEx)();
|
|
49
61
|
|
|
50
62
|
// src/contexts/PayloadDiviner/Provider.tsx
|
|
51
|
-
var import_react = require("react");
|
|
52
|
-
var
|
|
53
|
-
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
63
|
+
var import_react = __toESM(require("react"), 1);
|
|
64
|
+
var PayloadDivinerProvider = /* @__PURE__ */ __name(({ diviner: divinerProp, required = false, children }) => {
|
|
54
65
|
const [diviner, setDiviner] = (0, import_react.useState)(divinerProp);
|
|
55
66
|
(0, import_react.useEffect)(() => {
|
|
56
67
|
if (divinerProp) {
|
|
57
68
|
setDiviner(divinerProp);
|
|
58
69
|
}
|
|
59
|
-
}, [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
);
|
|
71
|
-
|
|
70
|
+
}, [
|
|
71
|
+
divinerProp
|
|
72
|
+
]);
|
|
73
|
+
const value = (0, import_react.useMemo)(() => ({
|
|
74
|
+
diviner: diviner === divinerProp ? diviner : void 0,
|
|
75
|
+
provided: true,
|
|
76
|
+
setDiviner
|
|
77
|
+
}), [
|
|
78
|
+
diviner,
|
|
79
|
+
divinerProp,
|
|
80
|
+
setDiviner
|
|
81
|
+
]);
|
|
82
|
+
return /* @__PURE__ */ import_react.default.createElement(PayloadDivinerContext.Provider, {
|
|
83
|
+
value
|
|
84
|
+
}, diviner ? children : required ? null : children);
|
|
85
|
+
}, "PayloadDivinerProvider");
|
|
72
86
|
|
|
73
87
|
// src/contexts/PayloadDiviner/use.ts
|
|
74
88
|
var import_lodash = require("@xylabs/lodash");
|
|
@@ -76,10 +90,10 @@ var import_react_async_effect = require("@xylabs/react-async-effect");
|
|
|
76
90
|
var import_diviner_huri = require("@xyo-network/diviner-huri");
|
|
77
91
|
var import_react_shared3 = require("@xyo-network/react-shared");
|
|
78
92
|
var import_react2 = require("react");
|
|
79
|
-
var usePayloadDiviner = (required = false) => {
|
|
93
|
+
var usePayloadDiviner = /* @__PURE__ */ __name((required = false) => {
|
|
80
94
|
return (0, import_react_shared3.useContextEx)(PayloadDivinerContext, "PayloadDiviner", required);
|
|
81
|
-
};
|
|
82
|
-
var useDivinePayload = (huri) => {
|
|
95
|
+
}, "usePayloadDiviner");
|
|
96
|
+
var useDivinePayload = /* @__PURE__ */ __name((huri) => {
|
|
83
97
|
const { diviner } = usePayloadDiviner();
|
|
84
98
|
const [payload, setPayload] = (0, import_react2.useState)();
|
|
85
99
|
const [error, setError] = (0, import_react2.useState)();
|
|
@@ -87,29 +101,42 @@ var useDivinePayload = (huri) => {
|
|
|
87
101
|
if (diviner) {
|
|
88
102
|
setPayload(void 0);
|
|
89
103
|
}
|
|
90
|
-
}, [
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
}, [
|
|
105
|
+
diviner
|
|
106
|
+
]);
|
|
107
|
+
(0, import_react_async_effect.useAsyncEffect)(async (mounted) => {
|
|
108
|
+
if (huri && diviner && payload === void 0) {
|
|
109
|
+
try {
|
|
110
|
+
const huriPayload = {
|
|
111
|
+
huri: [
|
|
112
|
+
huri
|
|
113
|
+
],
|
|
114
|
+
schema: import_diviner_huri.HuriSchema
|
|
115
|
+
};
|
|
116
|
+
const [payload2] = await (diviner == null ? void 0 : diviner.divine([
|
|
117
|
+
huriPayload
|
|
118
|
+
])) ?? [];
|
|
119
|
+
if (mounted()) {
|
|
120
|
+
setPayload(payload2 ? payload2 : null);
|
|
121
|
+
}
|
|
122
|
+
} catch (ex) {
|
|
123
|
+
if (mounted()) {
|
|
124
|
+
setError(ex);
|
|
105
125
|
}
|
|
106
126
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
127
|
+
}
|
|
128
|
+
}, [
|
|
129
|
+
diviner,
|
|
130
|
+
huri,
|
|
131
|
+
payload
|
|
132
|
+
]);
|
|
133
|
+
return [
|
|
134
|
+
payload,
|
|
135
|
+
setPayload,
|
|
136
|
+
error
|
|
137
|
+
];
|
|
138
|
+
}, "useDivinePayload");
|
|
139
|
+
var useDivinePayloads = /* @__PURE__ */ __name((huriList) => {
|
|
113
140
|
const { diviner } = usePayloadDiviner();
|
|
114
141
|
const [payloads, setPayloads] = (0, import_react2.useState)();
|
|
115
142
|
const [errors, setErrors] = (0, import_react2.useState)();
|
|
@@ -117,47 +144,61 @@ var useDivinePayloads = (huriList) => {
|
|
|
117
144
|
if (diviner) {
|
|
118
145
|
setPayloads(void 0);
|
|
119
146
|
}
|
|
120
|
-
}, [
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
147
|
+
}, [
|
|
148
|
+
diviner
|
|
149
|
+
]);
|
|
150
|
+
(0, import_react_async_effect.useAsyncEffect)(async (mounted) => {
|
|
151
|
+
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`);
|
|
152
|
+
const payloads2 = await Promise.allSettled(huriList.map(async (huri) => {
|
|
153
|
+
const huriPayload = {
|
|
154
|
+
huri: [
|
|
155
|
+
huri
|
|
156
|
+
],
|
|
157
|
+
schema: import_diviner_huri.HuriSchema
|
|
158
|
+
};
|
|
159
|
+
const [payload] = await (diviner == null ? void 0 : diviner.divine([
|
|
160
|
+
huriPayload
|
|
161
|
+
])) ?? [];
|
|
162
|
+
return payload;
|
|
163
|
+
}));
|
|
164
|
+
if (mounted()) {
|
|
165
|
+
setPayloads([
|
|
166
|
+
...payloads2.values()
|
|
167
|
+
].map((value) => value.status === "rejected" ? null : value.value));
|
|
168
|
+
setErrors((0, import_lodash.compact)([
|
|
169
|
+
...payloads2.values()
|
|
170
|
+
].map((value) => value.status === "rejected" ? new Error("divine failed", {
|
|
171
|
+
cause: value.reason
|
|
172
|
+
}) : void 0)));
|
|
132
173
|
if (mounted()) {
|
|
133
|
-
setPayloads([
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
)
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
setErrors(
|
|
142
|
-
(0, import_lodash.compact)(
|
|
143
|
-
[...payloads2.values()].map((value) => value.status === "rejected" ? new Error("divine failed", { cause: value.reason }) : void 0)
|
|
144
|
-
)
|
|
145
|
-
);
|
|
146
|
-
}
|
|
174
|
+
setPayloads([
|
|
175
|
+
...payloads2.values()
|
|
176
|
+
].map((value) => value.status === "rejected" ? null : value.value));
|
|
177
|
+
setErrors((0, import_lodash.compact)([
|
|
178
|
+
...payloads2.values()
|
|
179
|
+
].map((value) => value.status === "rejected" ? new Error("divine failed", {
|
|
180
|
+
cause: value.reason
|
|
181
|
+
}) : void 0)));
|
|
147
182
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
183
|
+
}
|
|
184
|
+
}, [
|
|
185
|
+
diviner,
|
|
186
|
+
huriList,
|
|
187
|
+
payloads
|
|
188
|
+
]);
|
|
189
|
+
return [
|
|
190
|
+
payloads,
|
|
191
|
+
setPayloads,
|
|
192
|
+
errors
|
|
193
|
+
];
|
|
194
|
+
}, "useDivinePayloads");
|
|
153
195
|
|
|
154
196
|
// src/contexts/DivinedPayload/use.ts
|
|
155
197
|
var import_react_shared4 = require("@xyo-network/react-shared");
|
|
156
|
-
var useDivinedPayload = () => (0, import_react_shared4.useContextEx)(DivinedPayloadContext, "DivinedPayload", true);
|
|
198
|
+
var useDivinedPayload = /* @__PURE__ */ __name(() => (0, import_react_shared4.useContextEx)(DivinedPayloadContext, "DivinedPayload", true), "useDivinedPayload");
|
|
157
199
|
|
|
158
200
|
// src/contexts/DivinedPayload/Provider.tsx
|
|
159
|
-
var
|
|
160
|
-
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
201
|
+
var DivinedPayloadProvider = /* @__PURE__ */ __name(({ children, hash }) => {
|
|
161
202
|
const { hash: hashParam } = (0, import_react_router_dom.useParams)();
|
|
162
203
|
const huriFromHashParam = (0, import_react_payload_huri.useBuildHuri)(hashParam);
|
|
163
204
|
const [params] = (0, import_react_router_dom.useSearchParams)();
|
|
@@ -165,22 +206,29 @@ var DivinedPayloadProvider = ({ children, hash }) => {
|
|
|
165
206
|
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
166
207
|
const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam;
|
|
167
208
|
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
168
|
-
return /* @__PURE__ */
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
{
|
|
175
|
-
error: payloadError ? { message: payloadError.message, schema: import_payload_model.ModuleErrorSchema, sources: [] } : void 0,
|
|
176
|
-
errorContext: "Divined Payload Provider",
|
|
177
|
-
children
|
|
209
|
+
return /* @__PURE__ */ import_react3.default.createElement(DivinedPayloadContext.Provider, {
|
|
210
|
+
value: {
|
|
211
|
+
payload,
|
|
212
|
+
payloadError,
|
|
213
|
+
provided: true,
|
|
214
|
+
setPayload
|
|
178
215
|
}
|
|
179
|
-
);
|
|
180
|
-
};
|
|
181
|
-
var
|
|
182
|
-
|
|
183
|
-
|
|
216
|
+
}, children);
|
|
217
|
+
}, "DivinedPayloadProvider");
|
|
218
|
+
var DivinedPayloadWithHandleInner = /* @__PURE__ */ __name(({ children }) => {
|
|
219
|
+
const { payloadError } = useDivinedPayload();
|
|
220
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_error.ErrorRender, {
|
|
221
|
+
error: payloadError ? {
|
|
222
|
+
message: payloadError.message,
|
|
223
|
+
schema: import_payload_model.ModuleErrorSchema,
|
|
224
|
+
sources: []
|
|
225
|
+
} : void 0,
|
|
226
|
+
errorContext: "Divined Payload Provider"
|
|
227
|
+
}, children);
|
|
228
|
+
}, "DivinedPayloadWithHandleInner");
|
|
229
|
+
var DivinedPayloadWithHandleProvider = /* @__PURE__ */ __name(({ children, ...props }) => {
|
|
230
|
+
return /* @__PURE__ */ import_react3.default.createElement(DivinedPayloadProvider, props, /* @__PURE__ */ import_react3.default.createElement(DivinedPayloadWithHandleInner, null, children));
|
|
231
|
+
}, "DivinedPayloadWithHandleProvider");
|
|
184
232
|
// Annotate the CommonJS export names for ESM import in node:
|
|
185
233
|
0 && (module.exports = {
|
|
186
234
|
DivinedPayloadContext,
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../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":["export * from './contexts/index.js'\n","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;AAAA;AAAA;AAAA;AAAA;A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E,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,6CAAC,0BAAwB,GAAG,OAC1B,uDAAC,iCAA+B,UAAS,GAC3C;AAEJ;","names":["import_react_shared","import_react_shared","import_react","payload","payloads","import_react_shared","import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../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":["export * from './contexts/index.ts'\n","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;;;;;;;;;;;;;;;;ACAA,0BAAgC;AAIzB,IAAMA,4BAAwBC,qCAAAA;;;ACHrC,2BAAkC;AAClC,yBAA4B;AAC5B,gCAA6B;AAC7B,IAAAC,gBAAkB;AAClB,8BAA2C;;;ACL3C,IAAAC,uBAAgC;AAIhC,IAAMC,4BAAwBC,sCAAAA;;;ACF9B,mBAAoD;AAS7C,IAAMC,yBAAgE,wBAAC,EAAEC,SAASC,aAAaC,WAAW,OAAOC,SAAQ,MAAE;AAChI,QAAM,CAACH,SAASI,UAAAA,QAAcC,uBAAqCJ,WAAAA;AAEnEK,8BAAU,MAAA;AACR,QAAIL,aAAa;AACfG,iBAAWH,WAAAA;IACb;EACF,GAAG;IAACA;GAAY;AAEhB,QAAMM,YAAQC,sBAAQ,OAAO;IAAER,SAASA,YAAYC,cAAcD,UAAUS;IAAWC,UAAU;IAAMN;EAAW,IAAI;IAACJ;IAASC;IAAaG;GAAW;AAExJ,SACE,6BAAAO,QAAA,cAACC,sBAAsBC,UAAQ;IAC7BN;KAECP,UACGG,WACAD,WACE,OACAC,QAAAA;AAGZ,GAtB6E;;;ACX7E,oBAAwB;AACxB,gCAA+B;AAC/B,0BAAwC;AAExC,IAAAW,uBAA6B;AAC7B,IAAAC,gBA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,QAAMC,mBAAmBC,mBAAmBH,uBAAuB,EAAA;AACnE,QAAMI,UAAUX,QAAQS,oBAAoBN;AAE5C,QAAM,CAACS,SAASC,YAAYC,YAAAA,IAAgBC,iBAAiBJ,OAAAA;AAG7D,SAAO,8BAAAK,QAAA,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,8BAAAN,QAAA,cAACO,gCAAAA;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,8BAAAhB,QAAA,cAAClB,wBAA2BkC,OAC1B,8BAAAhB,QAAA,cAACK,+BAAAA,MAA+BtB,QAAAA,CAAAA;AAGtC,GANuF;","names":["DivinedPayloadContext","createContextEx","import_react","import_react_shared","PayloadDivinerContext","createContextEx","PayloadDivinerProvider","diviner","divinerProp","required","children","setDiviner","useState","useEffect","value","useMemo","undefined","provided","React","PayloadDivinerContext","Provider","import_react_shared","import_react","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","import_react_shared","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/dist/node/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './contexts/index.
|
|
1
|
+
export * from './contexts/index.ts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './contexts/index.
|
|
1
|
+
export * from './contexts/index.ts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './contexts/index.
|
|
1
|
+
export * from './contexts/index.ts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/contexts/DivinedPayload/Context.ts
|
|
5
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
6
|
+
var DivinedPayloadContext = createContextEx();
|
|
7
|
+
|
|
8
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
9
|
+
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
10
|
+
import { ErrorRender } from "@xyo-network/react-error";
|
|
11
|
+
import { useBuildHuri } from "@xyo-network/react-payload-huri";
|
|
12
|
+
import React2 from "react";
|
|
13
|
+
import { useParams, useSearchParams } from "react-router-dom";
|
|
14
|
+
|
|
15
|
+
// src/contexts/PayloadDiviner/Context.ts
|
|
16
|
+
import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
|
|
17
|
+
var PayloadDivinerContext = createContextEx2();
|
|
18
|
+
|
|
19
|
+
// src/contexts/PayloadDiviner/Provider.tsx
|
|
20
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
21
|
+
var PayloadDivinerProvider = /* @__PURE__ */ __name(({ diviner: divinerProp, required = false, children }) => {
|
|
22
|
+
const [diviner, setDiviner] = useState(divinerProp);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (divinerProp) {
|
|
25
|
+
setDiviner(divinerProp);
|
|
26
|
+
}
|
|
27
|
+
}, [
|
|
28
|
+
divinerProp
|
|
29
|
+
]);
|
|
30
|
+
const value = useMemo(() => ({
|
|
31
|
+
diviner: diviner === divinerProp ? diviner : void 0,
|
|
32
|
+
provided: true,
|
|
33
|
+
setDiviner
|
|
34
|
+
}), [
|
|
35
|
+
diviner,
|
|
36
|
+
divinerProp,
|
|
37
|
+
setDiviner
|
|
38
|
+
]);
|
|
39
|
+
return /* @__PURE__ */ React.createElement(PayloadDivinerContext.Provider, {
|
|
40
|
+
value
|
|
41
|
+
}, diviner ? children : required ? null : children);
|
|
42
|
+
}, "PayloadDivinerProvider");
|
|
43
|
+
|
|
44
|
+
// src/contexts/PayloadDiviner/use.ts
|
|
45
|
+
import { compact } from "@xylabs/lodash";
|
|
46
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
47
|
+
import { HuriSchema } from "@xyo-network/diviner-huri";
|
|
48
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
49
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
50
|
+
var usePayloadDiviner = /* @__PURE__ */ __name((required = false) => {
|
|
51
|
+
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
52
|
+
}, "usePayloadDiviner");
|
|
53
|
+
var useDivinePayload = /* @__PURE__ */ __name((huri) => {
|
|
54
|
+
const { diviner } = usePayloadDiviner();
|
|
55
|
+
const [payload, setPayload] = useState2();
|
|
56
|
+
const [error, setError] = useState2();
|
|
57
|
+
useEffect2(() => {
|
|
58
|
+
if (diviner) {
|
|
59
|
+
setPayload(void 0);
|
|
60
|
+
}
|
|
61
|
+
}, [
|
|
62
|
+
diviner
|
|
63
|
+
]);
|
|
64
|
+
useAsyncEffect(async (mounted) => {
|
|
65
|
+
if (huri && diviner && payload === void 0) {
|
|
66
|
+
try {
|
|
67
|
+
const huriPayload = {
|
|
68
|
+
huri: [
|
|
69
|
+
huri
|
|
70
|
+
],
|
|
71
|
+
schema: HuriSchema
|
|
72
|
+
};
|
|
73
|
+
const [payload2] = await (diviner == null ? void 0 : diviner.divine([
|
|
74
|
+
huriPayload
|
|
75
|
+
])) ?? [];
|
|
76
|
+
if (mounted()) {
|
|
77
|
+
setPayload(payload2 ? payload2 : null);
|
|
78
|
+
}
|
|
79
|
+
} catch (ex) {
|
|
80
|
+
if (mounted()) {
|
|
81
|
+
setError(ex);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
diviner,
|
|
87
|
+
huri,
|
|
88
|
+
payload
|
|
89
|
+
]);
|
|
90
|
+
return [
|
|
91
|
+
payload,
|
|
92
|
+
setPayload,
|
|
93
|
+
error
|
|
94
|
+
];
|
|
95
|
+
}, "useDivinePayload");
|
|
96
|
+
var useDivinePayloads = /* @__PURE__ */ __name((huriList) => {
|
|
97
|
+
const { diviner } = usePayloadDiviner();
|
|
98
|
+
const [payloads, setPayloads] = useState2();
|
|
99
|
+
const [errors, setErrors] = useState2();
|
|
100
|
+
useEffect2(() => {
|
|
101
|
+
if (diviner) {
|
|
102
|
+
setPayloads(void 0);
|
|
103
|
+
}
|
|
104
|
+
}, [
|
|
105
|
+
diviner
|
|
106
|
+
]);
|
|
107
|
+
useAsyncEffect(async (mounted) => {
|
|
108
|
+
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`);
|
|
109
|
+
const payloads2 = await Promise.allSettled(huriList.map(async (huri) => {
|
|
110
|
+
const huriPayload = {
|
|
111
|
+
huri: [
|
|
112
|
+
huri
|
|
113
|
+
],
|
|
114
|
+
schema: HuriSchema
|
|
115
|
+
};
|
|
116
|
+
const [payload] = await (diviner == null ? void 0 : diviner.divine([
|
|
117
|
+
huriPayload
|
|
118
|
+
])) ?? [];
|
|
119
|
+
return payload;
|
|
120
|
+
}));
|
|
121
|
+
if (mounted()) {
|
|
122
|
+
setPayloads([
|
|
123
|
+
...payloads2.values()
|
|
124
|
+
].map((value) => value.status === "rejected" ? null : value.value));
|
|
125
|
+
setErrors(compact([
|
|
126
|
+
...payloads2.values()
|
|
127
|
+
].map((value) => value.status === "rejected" ? new Error("divine failed", {
|
|
128
|
+
cause: value.reason
|
|
129
|
+
}) : void 0)));
|
|
130
|
+
if (mounted()) {
|
|
131
|
+
setPayloads([
|
|
132
|
+
...payloads2.values()
|
|
133
|
+
].map((value) => value.status === "rejected" ? null : value.value));
|
|
134
|
+
setErrors(compact([
|
|
135
|
+
...payloads2.values()
|
|
136
|
+
].map((value) => value.status === "rejected" ? new Error("divine failed", {
|
|
137
|
+
cause: value.reason
|
|
138
|
+
}) : void 0)));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}, [
|
|
142
|
+
diviner,
|
|
143
|
+
huriList,
|
|
144
|
+
payloads
|
|
145
|
+
]);
|
|
146
|
+
return [
|
|
147
|
+
payloads,
|
|
148
|
+
setPayloads,
|
|
149
|
+
errors
|
|
150
|
+
];
|
|
151
|
+
}, "useDivinePayloads");
|
|
152
|
+
|
|
153
|
+
// src/contexts/DivinedPayload/use.ts
|
|
154
|
+
import { useContextEx as useContextEx2 } from "@xyo-network/react-shared";
|
|
155
|
+
var useDivinedPayload = /* @__PURE__ */ __name(() => useContextEx2(DivinedPayloadContext, "DivinedPayload", true), "useDivinedPayload");
|
|
156
|
+
|
|
157
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
158
|
+
var DivinedPayloadProvider = /* @__PURE__ */ __name(({ children, hash }) => {
|
|
159
|
+
const { hash: hashParam } = useParams();
|
|
160
|
+
const huriFromHashParam = useBuildHuri(hashParam);
|
|
161
|
+
const [params] = useSearchParams();
|
|
162
|
+
const huriSearchParameter = params.get("huri");
|
|
163
|
+
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
164
|
+
const huriUri = hash ?? decodedHuriParam ?? huriFromHashParam;
|
|
165
|
+
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
166
|
+
return /* @__PURE__ */ React2.createElement(DivinedPayloadContext.Provider, {
|
|
167
|
+
value: {
|
|
168
|
+
payload,
|
|
169
|
+
payloadError,
|
|
170
|
+
provided: true,
|
|
171
|
+
setPayload
|
|
172
|
+
}
|
|
173
|
+
}, children);
|
|
174
|
+
}, "DivinedPayloadProvider");
|
|
175
|
+
var DivinedPayloadWithHandleInner = /* @__PURE__ */ __name(({ children }) => {
|
|
176
|
+
const { payloadError } = useDivinedPayload();
|
|
177
|
+
return /* @__PURE__ */ React2.createElement(ErrorRender, {
|
|
178
|
+
error: payloadError ? {
|
|
179
|
+
message: payloadError.message,
|
|
180
|
+
schema: ModuleErrorSchema,
|
|
181
|
+
sources: []
|
|
182
|
+
} : void 0,
|
|
183
|
+
errorContext: "Divined Payload Provider"
|
|
184
|
+
}, children);
|
|
185
|
+
}, "DivinedPayloadWithHandleInner");
|
|
186
|
+
var DivinedPayloadWithHandleProvider = /* @__PURE__ */ __name(({ children, ...props }) => {
|
|
187
|
+
return /* @__PURE__ */ React2.createElement(DivinedPayloadProvider, props, /* @__PURE__ */ React2.createElement(DivinedPayloadWithHandleInner, null, children));
|
|
188
|
+
}, "DivinedPayloadWithHandleProvider");
|
|
189
|
+
export {
|
|
190
|
+
DivinedPayloadContext,
|
|
191
|
+
DivinedPayloadProvider,
|
|
192
|
+
DivinedPayloadWithHandleInner,
|
|
193
|
+
DivinedPayloadWithHandleProvider,
|
|
194
|
+
PayloadDivinerContext,
|
|
195
|
+
PayloadDivinerProvider,
|
|
196
|
+
useDivinePayload,
|
|
197
|
+
useDivinePayloads,
|
|
198
|
+
useDivinedPayload,
|
|
199
|
+
usePayloadDiviner
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=index.mjs.map
|