@xyo-network/react-payload-diviner 2.61.0 → 2.62.3
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/contexts/DivinedPayload/Context.d.mts.map +1 -0
- package/dist/contexts/DivinedPayload/Context.d.ts +4 -0
- package/dist/contexts/DivinedPayload/Context.d.ts.map +1 -0
- package/dist/contexts/DivinedPayload/Provider.d.mts.map +1 -0
- package/dist/contexts/DivinedPayload/Provider.d.ts +9 -0
- package/dist/contexts/DivinedPayload/Provider.d.ts.map +1 -0
- package/dist/contexts/DivinedPayload/State.d.mts.map +1 -0
- package/dist/contexts/DivinedPayload/State.d.ts +9 -0
- package/dist/contexts/DivinedPayload/State.d.ts.map +1 -0
- package/dist/contexts/DivinedPayload/index.d.mts.map +1 -0
- package/dist/contexts/DivinedPayload/index.d.ts.map +1 -0
- package/dist/contexts/DivinedPayload/use.d.mts.map +1 -0
- package/dist/contexts/DivinedPayload/use.d.ts +2 -0
- package/dist/contexts/DivinedPayload/use.d.ts.map +1 -0
- package/dist/contexts/PayloadDiviner/Context.d.mts.map +1 -0
- package/dist/contexts/PayloadDiviner/Context.d.ts +5 -0
- package/dist/contexts/PayloadDiviner/Context.d.ts.map +1 -0
- package/dist/contexts/PayloadDiviner/Provider.d.mts.map +1 -0
- package/dist/contexts/PayloadDiviner/Provider.d.ts +9 -0
- package/dist/contexts/PayloadDiviner/Provider.d.ts.map +1 -0
- package/dist/contexts/PayloadDiviner/State.d.mts.map +1 -0
- package/dist/contexts/PayloadDiviner/State.d.ts +7 -0
- package/dist/contexts/PayloadDiviner/State.d.ts.map +1 -0
- package/dist/{esm/contexts/DivinedPayload/index.js → contexts/PayloadDiviner/index.d.mts} +1 -1
- package/dist/contexts/PayloadDiviner/index.d.mts.map +1 -0
- package/dist/{esm/contexts/PayloadDiviner/index.js → contexts/PayloadDiviner/index.d.ts} +1 -1
- package/dist/contexts/PayloadDiviner/index.d.ts.map +1 -0
- package/dist/contexts/PayloadDiviner/use.d.mts +13 -0
- package/dist/contexts/PayloadDiviner/use.d.mts.map +1 -0
- package/dist/contexts/PayloadDiviner/use.d.ts +13 -0
- package/dist/contexts/PayloadDiviner/use.d.ts.map +1 -0
- package/dist/contexts/index.d.mts.map +1 -0
- package/dist/{esm/contexts/index.js → contexts/index.d.ts} +1 -1
- package/dist/contexts/index.d.ts.map +1 -0
- package/dist/docs.json +1712 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/{types/index.d.ts.map → index.d.ts.map} +1 -1
- package/dist/index.js +195 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +159 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +30 -22
- package/dist/cjs/contexts/DivinedPayload/Context.js +0 -6
- package/dist/cjs/contexts/DivinedPayload/Context.js.map +0 -1
- package/dist/cjs/contexts/DivinedPayload/Provider.js +0 -34
- package/dist/cjs/contexts/DivinedPayload/Provider.js.map +0 -1
- package/dist/cjs/contexts/DivinedPayload/State.js +0 -3
- package/dist/cjs/contexts/DivinedPayload/State.js.map +0 -1
- package/dist/cjs/contexts/DivinedPayload/index.js +0 -8
- package/dist/cjs/contexts/DivinedPayload/index.js.map +0 -1
- package/dist/cjs/contexts/DivinedPayload/use.js +0 -8
- package/dist/cjs/contexts/DivinedPayload/use.js.map +0 -1
- package/dist/cjs/contexts/PayloadDiviner/Context.js +0 -7
- package/dist/cjs/contexts/PayloadDiviner/Context.js.map +0 -1
- package/dist/cjs/contexts/PayloadDiviner/Provider.js +0 -21
- package/dist/cjs/contexts/PayloadDiviner/Provider.js.map +0 -1
- package/dist/cjs/contexts/PayloadDiviner/State.js +0 -3
- package/dist/cjs/contexts/PayloadDiviner/State.js.map +0 -1
- package/dist/cjs/contexts/PayloadDiviner/index.js +0 -8
- package/dist/cjs/contexts/PayloadDiviner/index.js.map +0 -1
- package/dist/cjs/contexts/PayloadDiviner/use.js +0 -77
- package/dist/cjs/contexts/PayloadDiviner/use.js.map +0 -1
- package/dist/cjs/contexts/index.js +0 -6
- package/dist/cjs/contexts/index.js.map +0 -1
- package/dist/cjs/index.js +0 -5
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/contexts/DivinedPayload/Context.js +0 -3
- package/dist/esm/contexts/DivinedPayload/Context.js.map +0 -1
- package/dist/esm/contexts/DivinedPayload/Provider.js +0 -26
- package/dist/esm/contexts/DivinedPayload/Provider.js.map +0 -1
- package/dist/esm/contexts/DivinedPayload/State.js +0 -2
- package/dist/esm/contexts/DivinedPayload/State.js.map +0 -1
- package/dist/esm/contexts/DivinedPayload/index.js.map +0 -1
- package/dist/esm/contexts/DivinedPayload/use.js +0 -4
- package/dist/esm/contexts/DivinedPayload/use.js.map +0 -1
- package/dist/esm/contexts/PayloadDiviner/Context.js +0 -4
- package/dist/esm/contexts/PayloadDiviner/Context.js.map +0 -1
- package/dist/esm/contexts/PayloadDiviner/Provider.js +0 -17
- package/dist/esm/contexts/PayloadDiviner/Provider.js.map +0 -1
- package/dist/esm/contexts/PayloadDiviner/State.js +0 -2
- package/dist/esm/contexts/PayloadDiviner/State.js.map +0 -1
- package/dist/esm/contexts/PayloadDiviner/index.js.map +0 -1
- package/dist/esm/contexts/PayloadDiviner/use.js +0 -68
- package/dist/esm/contexts/PayloadDiviner/use.js.map +0 -1
- package/dist/esm/contexts/index.js.map +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +0 -1
- package/dist/types/contexts/DivinedPayload/Context.d.ts.map +0 -1
- package/dist/types/contexts/DivinedPayload/Provider.d.ts.map +0 -1
- package/dist/types/contexts/DivinedPayload/State.d.ts.map +0 -1
- package/dist/types/contexts/DivinedPayload/index.d.ts.map +0 -1
- package/dist/types/contexts/DivinedPayload/use.d.ts.map +0 -1
- package/dist/types/contexts/PayloadDiviner/Context.d.ts.map +0 -1
- package/dist/types/contexts/PayloadDiviner/Provider.d.ts.map +0 -1
- package/dist/types/contexts/PayloadDiviner/State.d.ts.map +0 -1
- package/dist/types/contexts/PayloadDiviner/index.d.ts.map +0 -1
- package/dist/types/contexts/PayloadDiviner/use.d.ts +0 -13
- package/dist/types/contexts/PayloadDiviner/use.d.ts.map +0 -1
- package/dist/types/contexts/index.d.ts.map +0 -1
- /package/dist/{types/contexts/DivinedPayload/Context.d.ts → contexts/DivinedPayload/Context.d.mts} +0 -0
- /package/dist/{types/contexts/DivinedPayload/Provider.d.ts → contexts/DivinedPayload/Provider.d.mts} +0 -0
- /package/dist/{types/contexts/DivinedPayload/State.d.ts → contexts/DivinedPayload/State.d.mts} +0 -0
- /package/dist/{types/contexts/DivinedPayload/index.d.ts → contexts/DivinedPayload/index.d.mts} +0 -0
- /package/dist/{types/contexts/PayloadDiviner → contexts/DivinedPayload}/index.d.ts +0 -0
- /package/dist/{types/contexts/DivinedPayload/use.d.ts → contexts/DivinedPayload/use.d.mts} +0 -0
- /package/dist/{types/contexts/PayloadDiviner/Context.d.ts → contexts/PayloadDiviner/Context.d.mts} +0 -0
- /package/dist/{types/contexts/PayloadDiviner/Provider.d.ts → contexts/PayloadDiviner/Provider.d.mts} +0 -0
- /package/dist/{types/contexts/PayloadDiviner/State.d.ts → contexts/PayloadDiviner/State.d.mts} +0 -0
- /package/dist/{types/contexts/index.d.ts → contexts/index.d.mts} +0 -0
- /package/dist/{types/index.d.ts → index.d.mts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
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/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
DivinedPayloadContext: () => DivinedPayloadContext,
|
|
24
|
+
DivinedPayloadProvider: () => DivinedPayloadProvider,
|
|
25
|
+
DivinedPayloadWithHandleInner: () => DivinedPayloadWithHandleInner,
|
|
26
|
+
DivinedPayloadWithHandleProvider: () => DivinedPayloadWithHandleProvider,
|
|
27
|
+
PayloadDivinerContext: () => PayloadDivinerContext,
|
|
28
|
+
PayloadDivinerProvider: () => PayloadDivinerProvider,
|
|
29
|
+
useDivinePayload: () => useDivinePayload,
|
|
30
|
+
useDivinePayloads: () => useDivinePayloads,
|
|
31
|
+
useDivinedPayload: () => useDivinedPayload,
|
|
32
|
+
usePayloadDiviner: () => usePayloadDiviner
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
|
|
36
|
+
// src/contexts/DivinedPayload/Context.tsx
|
|
37
|
+
var import_react_shared = require("@xyo-network/react-shared");
|
|
38
|
+
var DivinedPayloadContext = (0, import_react_shared.createContextEx)();
|
|
39
|
+
|
|
40
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
41
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
42
|
+
var import_react_error = require("@xyo-network/react-error");
|
|
43
|
+
var import_react_payload_huri = require("@xyo-network/react-payload-huri");
|
|
44
|
+
var import_react_router_dom = require("react-router-dom");
|
|
45
|
+
|
|
46
|
+
// src/contexts/PayloadDiviner/Context.ts
|
|
47
|
+
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
48
|
+
var PayloadDivinerContext = (0, import_react_shared2.createContextEx)();
|
|
49
|
+
|
|
50
|
+
// src/contexts/PayloadDiviner/Provider.tsx
|
|
51
|
+
var import_react = require("react");
|
|
52
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
|
+
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
54
|
+
const [diviner, setDiviner] = (0, import_react.useState)(divinerProp);
|
|
55
|
+
(0, import_react.useEffect)(() => {
|
|
56
|
+
if (divinerProp) {
|
|
57
|
+
setDiviner(divinerProp);
|
|
58
|
+
}
|
|
59
|
+
}, [divinerProp]);
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
PayloadDivinerContext.Provider,
|
|
62
|
+
{
|
|
63
|
+
value: {
|
|
64
|
+
diviner: diviner === divinerProp ? diviner : void 0,
|
|
65
|
+
provided: true,
|
|
66
|
+
setDiviner
|
|
67
|
+
},
|
|
68
|
+
children: diviner ? children : required ? null : children
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/contexts/PayloadDiviner/use.ts
|
|
74
|
+
var import_lodash = require("@xylabs/lodash");
|
|
75
|
+
var import_react_async_effect = require("@xylabs/react-async-effect");
|
|
76
|
+
var import_diviner = require("@xyo-network/diviner");
|
|
77
|
+
var import_react_shared3 = require("@xyo-network/react-shared");
|
|
78
|
+
var import_react2 = require("react");
|
|
79
|
+
var usePayloadDiviner = (required = false) => {
|
|
80
|
+
return (0, import_react_shared3.useContextEx)(PayloadDivinerContext, "PayloadDiviner", required);
|
|
81
|
+
};
|
|
82
|
+
var useDivinePayload = (huri) => {
|
|
83
|
+
const { diviner } = usePayloadDiviner();
|
|
84
|
+
const [payload, setPayload] = (0, import_react2.useState)();
|
|
85
|
+
const [error, setError] = (0, import_react2.useState)();
|
|
86
|
+
(0, import_react2.useEffect)(() => {
|
|
87
|
+
if (diviner) {
|
|
88
|
+
setPayload(void 0);
|
|
89
|
+
}
|
|
90
|
+
}, [diviner]);
|
|
91
|
+
(0, import_react_async_effect.useAsyncEffect)(
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
+
async (mounted) => {
|
|
94
|
+
if (huri && diviner && payload === void 0) {
|
|
95
|
+
try {
|
|
96
|
+
const huriPayload = { huri: [huri], schema: import_diviner.HuriSchema };
|
|
97
|
+
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
98
|
+
if (mounted()) {
|
|
99
|
+
setPayload(payload2 ? payload2 : null);
|
|
100
|
+
}
|
|
101
|
+
} catch (ex) {
|
|
102
|
+
if (mounted()) {
|
|
103
|
+
setError(ex);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
[diviner, huri, payload]
|
|
109
|
+
);
|
|
110
|
+
return [payload, setPayload, error];
|
|
111
|
+
};
|
|
112
|
+
var useDivinePayloads = (huriList) => {
|
|
113
|
+
const { diviner } = usePayloadDiviner();
|
|
114
|
+
const [payloads, setPayloads] = (0, import_react2.useState)();
|
|
115
|
+
const [errors, setErrors] = (0, import_react2.useState)();
|
|
116
|
+
(0, import_react2.useEffect)(() => {
|
|
117
|
+
if (diviner) {
|
|
118
|
+
setPayloads(void 0);
|
|
119
|
+
}
|
|
120
|
+
}, [diviner]);
|
|
121
|
+
(0, import_react_async_effect.useAsyncEffect)(
|
|
122
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
123
|
+
async (mounted) => {
|
|
124
|
+
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`);
|
|
125
|
+
const payloads2 = await Promise.allSettled(
|
|
126
|
+
huriList.map(async (huri) => {
|
|
127
|
+
const huriPayload = { huri: [huri], schema: import_diviner.HuriSchema };
|
|
128
|
+
const [payload] = await diviner?.divine([huriPayload]) ?? [];
|
|
129
|
+
return payload;
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
if (mounted()) {
|
|
133
|
+
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
134
|
+
setErrors(
|
|
135
|
+
(0, import_lodash.compact)([...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0))
|
|
136
|
+
);
|
|
137
|
+
if (mounted()) {
|
|
138
|
+
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
139
|
+
setErrors(
|
|
140
|
+
(0, import_lodash.compact)(
|
|
141
|
+
[...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0)
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
[diviner, huriList, payloads]
|
|
148
|
+
);
|
|
149
|
+
return [payloads, setPayloads, errors];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/contexts/DivinedPayload/use.ts
|
|
153
|
+
var import_react_shared4 = require("@xyo-network/react-shared");
|
|
154
|
+
var useDivinedPayload = () => (0, import_react_shared4.useContextEx)(DivinedPayloadContext, "DivinedPayload", true);
|
|
155
|
+
|
|
156
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
157
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
158
|
+
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
159
|
+
const { hash: hashParam } = (0, import_react_router_dom.useParams)();
|
|
160
|
+
const huriFromHashParam = (0, import_react_payload_huri.useBuildHuri)(hashParam);
|
|
161
|
+
const [params] = (0, import_react_router_dom.useSearchParams)();
|
|
162
|
+
const huriSearchParameter = params.get("huri");
|
|
163
|
+
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
164
|
+
const huriUri = hash ?? (decodedHuriParam ? decodedHuriParam : huriFromHashParam);
|
|
165
|
+
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
166
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
167
|
+
};
|
|
168
|
+
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
169
|
+
const { payloadError } = useDivinedPayload();
|
|
170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
171
|
+
import_react_error.ErrorRender,
|
|
172
|
+
{
|
|
173
|
+
error: payloadError ? { message: payloadError.message, schema: import_payload_model.ModuleErrorSchema, sources: [] } : void 0,
|
|
174
|
+
errorContext: "Divined Payload Provider",
|
|
175
|
+
children
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DivinedPayloadWithHandleInner, { children }) });
|
|
181
|
+
};
|
|
182
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
+
0 && (module.exports = {
|
|
184
|
+
DivinedPayloadContext,
|
|
185
|
+
DivinedPayloadProvider,
|
|
186
|
+
DivinedPayloadWithHandleInner,
|
|
187
|
+
DivinedPayloadWithHandleProvider,
|
|
188
|
+
PayloadDivinerContext,
|
|
189
|
+
PayloadDivinerProvider,
|
|
190
|
+
useDivinePayload,
|
|
191
|
+
useDivinePayloads,
|
|
192
|
+
useDivinedPayload,
|
|
193
|
+
usePayloadDiviner
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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'\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 { AbstractPayloadDiviner } from '@xyo-network/diviner'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: AbstractPayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<AbstractPayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n return (\n <PayloadDivinerContext.Provider\n value={{\n diviner: diviner === divinerProp ? diviner : undefined,\n provided: true,\n setDiviner,\n }}\n >\n {diviner ? children : required ? null : children}\n </PayloadDivinerContext.Provider>\n )\n}\n","import { compact } from '@xylabs/lodash'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { HuriPayload, HuriSchema } from '@xyo-network/diviner'\nimport { Payload } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\n\nexport const usePayloadDiviner = (required = false) => {\n return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)\n}\n\nexport const useDivinePayload = <T extends Payload = Payload>(\n huri?: string,\n): [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payload, setPayload] = useState<T | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n if (diviner) {\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (huri && diviner && payload === undefined) {\n try {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n if (mounted()) {\n setPayload(payload ? (payload as T) : null)\n }\n } catch (ex) {\n if (mounted()) {\n setError(ex as Error)\n }\n }\n }\n },\n [diviner, huri, payload],\n )\n\n return [payload, setPayload, error]\n}\n\nexport const useDivinePayloads = <T extends Payload = Payload>(\n huriList: string[],\n): [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payloads, setPayloads] = useState<(T | null)[]>()\n const [errors, setErrors] = useState<Error[]>()\n\n useEffect(() => {\n if (diviner) {\n setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)\n const payloads = await Promise.allSettled(\n huriList.map(async (huri) => {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n return payload\n }),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map((value) => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n compact([...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined))),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map((value) => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n compact(\n [...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined)),\n ),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAgC;AAIzB,IAAM,4BAAwB,qCAAqC;;;ACH1E,2BAAkC;AAClC,yBAA4B;AAC5B,gCAA6B;AAC7B,8BAA2C;;;ACJ3C,IAAAA,uBAAgC;AAIhC,IAAM,4BAAwB,sCAAqC;;;ACFnE,mBAAoC;AAmBhC;AAVG,IAAM,yBAAgE,CAAC,EAAE,SAAS,aAAa,WAAW,OAAO,SAAS,MAAM;AACrI,QAAM,CAAC,SAAS,UAAU,QAAI,uBAA6C,WAAW;AAEtF,8BAAU,MAAM;AACd,QAAI,aAAa;AACf,iBAAW,WAAW;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAEhB,SACE;AAAA,IAAC,sBAAsB;AAAA,IAAtB;AAAA,MACC,OAAO;AAAA,QACL,SAAS,YAAY,cAAc,UAAU;AAAA,QAC7C,UAAU;AAAA,QACV;AAAA,MACF;AAAA,MAEC,oBAAU,WAAW,WAAW,OAAO;AAAA;AAAA,EAC1C;AAEJ;;;AC/BA,oBAAwB;AACxB,gCAA+B;AAC/B,qBAAwC;AAExC,IAAAC,uBAA6B;AAC7B,IAAAC,gBAA8C;AAIvC,IAAM,oBAAoB,CAAC,WAAW,UAAU;AACrD,aAAO,mCAAa,uBAAuB,kBAAkB,QAAQ;AACvE;AAEO,IAAM,mBAAmB,CAC9B,SAC8E;AAC9E,QAAM,EAAE,QAAQ,IAAI,kBAAkB;AACtC,QAAM,CAAC,SAAS,UAAU,QAAI,wBAAmB;AACjD,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAg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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,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"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// src/contexts/DivinedPayload/Context.tsx
|
|
2
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
3
|
+
var DivinedPayloadContext = createContextEx();
|
|
4
|
+
|
|
5
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
6
|
+
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
7
|
+
import { ErrorRender } from "@xyo-network/react-error";
|
|
8
|
+
import { useBuildHuri } from "@xyo-network/react-payload-huri";
|
|
9
|
+
import { useParams, useSearchParams } from "react-router-dom";
|
|
10
|
+
|
|
11
|
+
// src/contexts/PayloadDiviner/Context.ts
|
|
12
|
+
import { createContextEx as createContextEx2 } from "@xyo-network/react-shared";
|
|
13
|
+
var PayloadDivinerContext = createContextEx2();
|
|
14
|
+
|
|
15
|
+
// src/contexts/PayloadDiviner/Provider.tsx
|
|
16
|
+
import { useEffect, useState } from "react";
|
|
17
|
+
import { jsx } from "react/jsx-runtime";
|
|
18
|
+
var PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
19
|
+
const [diviner, setDiviner] = useState(divinerProp);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (divinerProp) {
|
|
22
|
+
setDiviner(divinerProp);
|
|
23
|
+
}
|
|
24
|
+
}, [divinerProp]);
|
|
25
|
+
return /* @__PURE__ */ jsx(
|
|
26
|
+
PayloadDivinerContext.Provider,
|
|
27
|
+
{
|
|
28
|
+
value: {
|
|
29
|
+
diviner: diviner === divinerProp ? diviner : void 0,
|
|
30
|
+
provided: true,
|
|
31
|
+
setDiviner
|
|
32
|
+
},
|
|
33
|
+
children: diviner ? children : required ? null : children
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/contexts/PayloadDiviner/use.ts
|
|
39
|
+
import { compact } from "@xylabs/lodash";
|
|
40
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
41
|
+
import { HuriSchema } from "@xyo-network/diviner";
|
|
42
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
43
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
44
|
+
var usePayloadDiviner = (required = false) => {
|
|
45
|
+
return useContextEx(PayloadDivinerContext, "PayloadDiviner", required);
|
|
46
|
+
};
|
|
47
|
+
var useDivinePayload = (huri) => {
|
|
48
|
+
const { diviner } = usePayloadDiviner();
|
|
49
|
+
const [payload, setPayload] = useState2();
|
|
50
|
+
const [error, setError] = useState2();
|
|
51
|
+
useEffect2(() => {
|
|
52
|
+
if (diviner) {
|
|
53
|
+
setPayload(void 0);
|
|
54
|
+
}
|
|
55
|
+
}, [diviner]);
|
|
56
|
+
useAsyncEffect(
|
|
57
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
+
async (mounted) => {
|
|
59
|
+
if (huri && diviner && payload === void 0) {
|
|
60
|
+
try {
|
|
61
|
+
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
62
|
+
const [payload2] = await diviner?.divine([huriPayload]) ?? [];
|
|
63
|
+
if (mounted()) {
|
|
64
|
+
setPayload(payload2 ? payload2 : null);
|
|
65
|
+
}
|
|
66
|
+
} catch (ex) {
|
|
67
|
+
if (mounted()) {
|
|
68
|
+
setError(ex);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
[diviner, huri, payload]
|
|
74
|
+
);
|
|
75
|
+
return [payload, setPayload, error];
|
|
76
|
+
};
|
|
77
|
+
var useDivinePayloads = (huriList) => {
|
|
78
|
+
const { diviner } = usePayloadDiviner();
|
|
79
|
+
const [payloads, setPayloads] = useState2();
|
|
80
|
+
const [errors, setErrors] = useState2();
|
|
81
|
+
useEffect2(() => {
|
|
82
|
+
if (diviner) {
|
|
83
|
+
setPayloads(void 0);
|
|
84
|
+
}
|
|
85
|
+
}, [diviner]);
|
|
86
|
+
useAsyncEffect(
|
|
87
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
|
+
async (mounted) => {
|
|
89
|
+
console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`);
|
|
90
|
+
const payloads2 = await Promise.allSettled(
|
|
91
|
+
huriList.map(async (huri) => {
|
|
92
|
+
const huriPayload = { huri: [huri], schema: HuriSchema };
|
|
93
|
+
const [payload] = await diviner?.divine([huriPayload]) ?? [];
|
|
94
|
+
return payload;
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
if (mounted()) {
|
|
98
|
+
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
99
|
+
setErrors(
|
|
100
|
+
compact([...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0))
|
|
101
|
+
);
|
|
102
|
+
if (mounted()) {
|
|
103
|
+
setPayloads([...payloads2.values()].map((value) => value.status === "rejected" ? null : value.value));
|
|
104
|
+
setErrors(
|
|
105
|
+
compact(
|
|
106
|
+
[...payloads2.values()].map((value) => value.status === "rejected" ? Error("divine failed", { cause: value.reason }) : void 0)
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[diviner, huriList, payloads]
|
|
113
|
+
);
|
|
114
|
+
return [payloads, setPayloads, errors];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/contexts/DivinedPayload/use.ts
|
|
118
|
+
import { useContextEx as useContextEx2 } from "@xyo-network/react-shared";
|
|
119
|
+
var useDivinedPayload = () => useContextEx2(DivinedPayloadContext, "DivinedPayload", true);
|
|
120
|
+
|
|
121
|
+
// src/contexts/DivinedPayload/Provider.tsx
|
|
122
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
123
|
+
var DivinedPayloadProvider = ({ children, hash }) => {
|
|
124
|
+
const { hash: hashParam } = useParams();
|
|
125
|
+
const huriFromHashParam = useBuildHuri(hashParam);
|
|
126
|
+
const [params] = useSearchParams();
|
|
127
|
+
const huriSearchParameter = params.get("huri");
|
|
128
|
+
const decodedHuriParam = decodeURIComponent(huriSearchParameter ?? "");
|
|
129
|
+
const huriUri = hash ?? (decodedHuriParam ? decodedHuriParam : huriFromHashParam);
|
|
130
|
+
const [payload, setPayload, payloadError] = useDivinePayload(huriUri);
|
|
131
|
+
return /* @__PURE__ */ jsx2(DivinedPayloadContext.Provider, { value: { payload, payloadError, provided: true, setPayload }, children });
|
|
132
|
+
};
|
|
133
|
+
var DivinedPayloadWithHandleInner = ({ children }) => {
|
|
134
|
+
const { payloadError } = useDivinedPayload();
|
|
135
|
+
return /* @__PURE__ */ jsx2(
|
|
136
|
+
ErrorRender,
|
|
137
|
+
{
|
|
138
|
+
error: payloadError ? { message: payloadError.message, schema: ModuleErrorSchema, sources: [] } : void 0,
|
|
139
|
+
errorContext: "Divined Payload Provider",
|
|
140
|
+
children
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
var DivinedPayloadWithHandleProvider = ({ children, ...props }) => {
|
|
145
|
+
return /* @__PURE__ */ jsx2(DivinedPayloadProvider, { ...props, children: /* @__PURE__ */ jsx2(DivinedPayloadWithHandleInner, { children }) });
|
|
146
|
+
};
|
|
147
|
+
export {
|
|
148
|
+
DivinedPayloadContext,
|
|
149
|
+
DivinedPayloadProvider,
|
|
150
|
+
DivinedPayloadWithHandleInner,
|
|
151
|
+
DivinedPayloadWithHandleProvider,
|
|
152
|
+
PayloadDivinerContext,
|
|
153
|
+
PayloadDivinerProvider,
|
|
154
|
+
useDivinePayload,
|
|
155
|
+
useDivinePayloads,
|
|
156
|
+
useDivinedPayload,
|
|
157
|
+
usePayloadDiviner
|
|
158
|
+
};
|
|
159
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/contexts/DivinedPayload/Context.tsx","../src/contexts/DivinedPayload/Provider.tsx","../src/contexts/PayloadDiviner/Context.ts","../src/contexts/PayloadDiviner/Provider.tsx","../src/contexts/PayloadDiviner/use.ts","../src/contexts/DivinedPayload/use.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadState } from './State'\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 { AbstractPayloadDiviner } from '@xyo-network/diviner'\nimport { ContextExProviderProps } from '@xyo-network/react-shared'\nimport { useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\n\nexport type PayloadDivinerProviderProps = ContextExProviderProps<{\n /** Required */\n diviner?: AbstractPayloadDiviner\n}>\n\nexport const PayloadDivinerProvider: React.FC<PayloadDivinerProviderProps> = ({ diviner: divinerProp, required = false, children }) => {\n const [diviner, setDiviner] = useState<AbstractPayloadDiviner | undefined>(divinerProp)\n\n useEffect(() => {\n if (divinerProp) {\n setDiviner(divinerProp)\n }\n }, [divinerProp])\n\n return (\n <PayloadDivinerContext.Provider\n value={{\n diviner: diviner === divinerProp ? diviner : undefined,\n provided: true,\n setDiviner,\n }}\n >\n {diviner ? children : required ? null : children}\n </PayloadDivinerContext.Provider>\n )\n}\n","import { compact } from '@xylabs/lodash'\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { HuriPayload, HuriSchema } from '@xyo-network/diviner'\nimport { Payload } from '@xyo-network/payload-model'\nimport { useContextEx } from '@xyo-network/react-shared'\nimport { Dispatch, useEffect, useState } from 'react'\n\nimport { PayloadDivinerContext } from './Context'\n\nexport const usePayloadDiviner = (required = false) => {\n return useContextEx(PayloadDivinerContext, 'PayloadDiviner', required)\n}\n\nexport const useDivinePayload = <T extends Payload = Payload>(\n huri?: string,\n): [T | undefined | null, Dispatch<T | null | undefined>, Error | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payload, setPayload] = useState<T | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n if (diviner) {\n setPayload(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n if (huri && diviner && payload === undefined) {\n try {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n if (mounted()) {\n setPayload(payload ? (payload as T) : null)\n }\n } catch (ex) {\n if (mounted()) {\n setError(ex as Error)\n }\n }\n }\n },\n [diviner, huri, payload],\n )\n\n return [payload, setPayload, error]\n}\n\nexport const useDivinePayloads = <T extends Payload = Payload>(\n huriList: string[],\n): [(T | null)[] | undefined, Dispatch<(T | null)[] | undefined>, Error[] | undefined] => {\n const { diviner } = usePayloadDiviner()\n const [payloads, setPayloads] = useState<(T | null)[]>()\n const [errors, setErrors] = useState<Error[]>()\n\n useEffect(() => {\n if (diviner) {\n setPayloads(undefined)\n }\n }, [diviner])\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n console.log(`huriList: ${JSON.stringify(huriList, null, 2)}`)\n const payloads = await Promise.allSettled(\n huriList.map(async (huri) => {\n const huriPayload: HuriPayload = { huri: [huri], schema: HuriSchema }\n const [payload] = (await diviner?.divine([huriPayload])) ?? []\n return payload\n }),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map((value) => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n compact([...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined))),\n )\n if (mounted()) {\n setPayloads([...payloads.values()].map((value) => (value.status === 'rejected' ? null : value.value)) as (T | null)[])\n setErrors(\n compact(\n [...payloads.values()].map((value) => (value.status === 'rejected' ? Error('divine failed', { cause: value.reason }) : undefined)),\n ),\n )\n }\n }\n },\n [diviner, huriList, payloads],\n )\n\n return [payloads, setPayloads, errors]\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { DivinedPayloadContext } from './Context'\n\nexport const useDivinedPayload = () => useContextEx(DivinedPayloadContext, 'DivinedPayload', true)\n"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,wBAAwB,gBAAqC;;;ACH1E,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,WAAW,uBAAuB;;;ACJ3C,SAAS,mBAAAA,wBAAuB;AAIhC,IAAM,wBAAwBA,iBAAqC;;;ACFnE,SAAS,WAAW,gBAAgB;AAmBhC;AAVG,IAAM,yBAAgE,CAAC,EAAE,SAAS,aAAa,WAAW,OAAO,SAAS,MAAM;AACrI,QAAM,CAAC,SAAS,UAAU,IAAI,SAA6C,WAAW;AAEtF,YAAU,MAAM;AACd,QAAI,aAAa;AACf,iBAAW,WAAW;AAAA,IACxB;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAEhB,SACE;AAAA,IAAC,sBAAsB;AAAA,IAAtB;AAAA,MACC,OAAO;AAAA,QACL,SAAS,YAAY,cAAc,UAAU;AAAA,QAC7C,UAAU;AAAA,QACV;AAAA,MACF;AAAA,MAEC,oBAAU,WAAW,WAAW,OAAO;AAAA;AAAA,EAC1C;AAEJ;;;AC/BA,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAC/B,SAAsB,kBAAkB;AAExC,SAAS,oBAAoB;AAC7B,SAAmB,aAAAC,YAAW,YAAAC,iBAAgB;AA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AAoB,aAAa,SAAS;AAEhD,QAAM,CAAC,MAAM,IAAI,gBAAgB;AACjC,QAAM,sBAAsB,OAAO,IAAI,MAAM;AAC7C,QAAM,mBAAmB,mBAAmB,uBAAuB,EAAE;AACrE,QAAM,UAAU,SAAS,mBAAmB,mBAAmB;AAE/D,QAAM,CAAC,SAAS,YAAY,YAAY,IAAI,iBAAiB,OAAO;AAEpE,SAAO,gBAAAA,KAAC,sBAAsB,UAAtB,EAA+B,OAAO,EAAE,SAAS,cAAc,UAAU,MAAM,WAAW,GAAI,UAAS;AACjH;AAEO,IAAM,gCAAwD,CAAC,EAAE,SAAS,MAAM;AACrF,QAAM,EAAE,aAAa,IAAI,kBAAkB;AAE3C,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,OAAO,eAAe,EAAE,SAAS,aAAa,SAAS,QAAQ,mBAAmB,SAAS,CAAC,EAAE,IAAI;AAAA,MAClG,cAAa;AAAA,MAEZ;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,mCAA0E,CAAC,EAAE,UAAU,GAAG,MAAM,MAAM;AACjH,SACE,gBAAAA,KAAC,0BAAwB,GAAG,OAC1B,0BAAAA,KAAC,iCAA+B,UAAS,GAC3C;AAEJ;","names":["createContextEx","useEffect","useState","useState","useEffect","payload","payloads","useContextEx","useContextEx","jsx"]}
|
package/package.json
CHANGED
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-react-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/lodash": "^2.
|
|
14
|
-
"@xylabs/react-async-effect": "~2.
|
|
15
|
-
"@xylabs/react-shared": "~2.
|
|
16
|
-
"@xyo-network/diviner": "^2.
|
|
17
|
-
"@xyo-network/payload-model": "^2.
|
|
18
|
-
"@xyo-network/react-error": "~2.
|
|
19
|
-
"@xyo-network/react-payload-huri": "~2.
|
|
20
|
-
"@xyo-network/react-shared": "~2.
|
|
13
|
+
"@xylabs/lodash": "^2.11.7",
|
|
14
|
+
"@xylabs/react-async-effect": "~2.18.4",
|
|
15
|
+
"@xylabs/react-shared": "~2.18.4",
|
|
16
|
+
"@xyo-network/diviner": "^2.74.1",
|
|
17
|
+
"@xyo-network/payload-model": "^2.74.1",
|
|
18
|
+
"@xyo-network/react-error": "~2.62.3",
|
|
19
|
+
"@xyo-network/react-payload-huri": "~2.62.3",
|
|
20
|
+
"@xyo-network/react-shared": "~2.62.3"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@xylabs/ts-scripts-yarn3": "^
|
|
23
|
+
"@xylabs/ts-scripts-yarn3": "^3.0.28",
|
|
24
24
|
"typescript": "^5.2.2"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
@@ -33,27 +33,35 @@
|
|
|
33
33
|
"react-router-dom": "^6"
|
|
34
34
|
},
|
|
35
35
|
"description": "Common React library for all XYO projects that use React",
|
|
36
|
-
"browser": "dist/esm/index.js",
|
|
37
36
|
"docs": "dist/docs.json",
|
|
38
37
|
"exports": {
|
|
39
38
|
".": {
|
|
40
39
|
"node": {
|
|
41
|
-
"import":
|
|
42
|
-
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/index.d.mts",
|
|
42
|
+
"default": "./dist/index.mjs"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"default": "./dist/index.js"
|
|
47
|
+
}
|
|
43
48
|
},
|
|
44
49
|
"browser": {
|
|
45
|
-
"import":
|
|
46
|
-
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./dist/index.d.mts",
|
|
52
|
+
"default": "./dist/index.mjs"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./dist/index.d.ts",
|
|
56
|
+
"default": "./dist/index.js"
|
|
57
|
+
}
|
|
47
58
|
},
|
|
48
|
-
"default": "./dist/
|
|
49
|
-
},
|
|
50
|
-
"./dist/docs.json": {
|
|
51
|
-
"default": "./dist/docs.json"
|
|
59
|
+
"default": "./dist/index.mjs"
|
|
52
60
|
},
|
|
53
61
|
"./package.json": "./package.json"
|
|
54
62
|
},
|
|
55
|
-
"main": "dist/
|
|
56
|
-
"module": "dist/
|
|
63
|
+
"main": "dist/index.js",
|
|
64
|
+
"module": "dist/index.mjs",
|
|
57
65
|
"homepage": "https://xyo.network",
|
|
58
66
|
"keywords": [
|
|
59
67
|
"xyo",
|
|
@@ -74,6 +82,6 @@
|
|
|
74
82
|
"license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
|
|
75
83
|
},
|
|
76
84
|
"sideEffects": false,
|
|
77
|
-
"types": "dist/
|
|
78
|
-
"version": "2.
|
|
85
|
+
"types": "dist/index.d.ts",
|
|
86
|
+
"version": "2.62.3"
|
|
79
87
|
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DivinedPayloadContext = void 0;
|
|
4
|
-
const react_shared_1 = require("@xyo-network/react-shared");
|
|
5
|
-
exports.DivinedPayloadContext = (0, react_shared_1.createContextEx)();
|
|
6
|
-
//# sourceMappingURL=Context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Context.tsx"],"names":[],"mappings":";;;AAAA,4DAA2D;AAI9C,QAAA,qBAAqB,GAAG,IAAA,8BAAe,GAAuB,CAAA"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DivinedPayloadWithHandleProvider = exports.DivinedPayloadWithHandleInner = exports.DivinedPayloadProvider = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
const payload_model_1 = require("@xyo-network/payload-model");
|
|
7
|
-
const react_error_1 = require("@xyo-network/react-error");
|
|
8
|
-
const react_payload_huri_1 = require("@xyo-network/react-payload-huri");
|
|
9
|
-
const react_router_dom_1 = require("react-router-dom");
|
|
10
|
-
const PayloadDiviner_1 = require("../PayloadDiviner");
|
|
11
|
-
const Context_1 = require("./Context");
|
|
12
|
-
const use_1 = require("./use");
|
|
13
|
-
const DivinedPayloadProvider = ({ children, hash }) => {
|
|
14
|
-
const { hash: hashParam } = (0, react_router_dom_1.useParams)();
|
|
15
|
-
const huriFromHashParam = (0, react_payload_huri_1.useBuildHuri)(hashParam);
|
|
16
|
-
const [params] = (0, react_router_dom_1.useSearchParams)();
|
|
17
|
-
const huriSearchParameter = params.get('huri');
|
|
18
|
-
const decodedHuriParam = decodeURIComponent(huriSearchParameter !== null && huriSearchParameter !== void 0 ? huriSearchParameter : '');
|
|
19
|
-
const huriUri = hash !== null && hash !== void 0 ? hash : (decodedHuriParam ? decodedHuriParam : huriFromHashParam);
|
|
20
|
-
const [payload, setPayload, payloadError] = (0, PayloadDiviner_1.useDivinePayload)(huriUri);
|
|
21
|
-
return (0, jsx_runtime_1.jsx)(Context_1.DivinedPayloadContext.Provider, Object.assign({ value: { payload, payloadError, provided: true, setPayload } }, { children: children }));
|
|
22
|
-
};
|
|
23
|
-
exports.DivinedPayloadProvider = DivinedPayloadProvider;
|
|
24
|
-
const DivinedPayloadWithHandleInner = ({ children }) => {
|
|
25
|
-
const { payloadError } = (0, use_1.useDivinedPayload)();
|
|
26
|
-
return ((0, jsx_runtime_1.jsx)(react_error_1.ErrorRender, Object.assign({ error: payloadError ? { message: payloadError.message, schema: payload_model_1.ModuleErrorSchema, sources: [] } : undefined, errorContext: "Divined Payload Provider" }, { children: children })));
|
|
27
|
-
};
|
|
28
|
-
exports.DivinedPayloadWithHandleInner = DivinedPayloadWithHandleInner;
|
|
29
|
-
const DivinedPayloadWithHandleProvider = (_a) => {
|
|
30
|
-
var { children } = _a, props = tslib_1.__rest(_a, ["children"]);
|
|
31
|
-
return ((0, jsx_runtime_1.jsx)(exports.DivinedPayloadProvider, Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(exports.DivinedPayloadWithHandleInner, { children: children }) })));
|
|
32
|
-
};
|
|
33
|
-
exports.DivinedPayloadWithHandleProvider = DivinedPayloadWithHandleProvider;
|
|
34
|
-
//# sourceMappingURL=Provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/Provider.tsx"],"names":[],"mappings":";;;;;AACA,8DAA8D;AAC9D,0DAAsD;AACtD,wEAA8D;AAC9D,uDAA6D;AAE7D,sDAAoD;AACpD,uCAAiD;AACjD,+BAAyC;AAMlC,MAAM,sBAAsB,GAA0C,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE;IAClG,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,IAAA,4BAAS,GAAE,CAAA;IAEvC,MAAM,iBAAiB,GAAG,IAAA,iCAAY,EAAC,SAAS,CAAC,CAAA;IAEjD,MAAM,CAAC,MAAM,CAAC,GAAG,IAAA,kCAAe,GAAE,CAAA;IAClC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC9C,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,mBAAmB,aAAnB,mBAAmB,cAAnB,mBAAmB,GAAI,EAAE,CAAC,CAAA;IACtE,MAAM,OAAO,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAA;IAEjF,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,GAAG,IAAA,iCAAgB,EAAC,OAAO,CAAC,CAAA;IAErE,OAAO,uBAAC,+BAAqB,CAAC,QAAQ,kBAAC,KAAK,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAG,QAAQ,IAAkC,CAAA;AAClJ,CAAC,CAAA;AAbY,QAAA,sBAAsB,0BAalC;AAEM,MAAM,6BAA6B,GAA2B,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACpF,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,uBAAiB,GAAE,CAAA;IAE5C,OAAO,CACL,uBAAC,yBAAW,kBACV,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,iCAAiB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAC3G,YAAY,EAAC,0BAA0B,gBAEtC,QAAQ,IACG,CACf,CAAA;AACH,CAAC,CAAA;AAXY,QAAA,6BAA6B,iCAWzC;AAEM,MAAM,gCAAgC,GAA0C,CAAC,EAAsB,EAAE,EAAE;QAA1B,EAAE,QAAQ,OAAY,EAAP,KAAK,sBAApB,YAAsB,CAAF;IAC1G,OAAO,CACL,uBAAC,8BAAsB,oBAAK,KAAK,cAC/B,uBAAC,qCAA6B,cAAE,QAAQ,GAAiC,IAClD,CAC1B,CAAA;AACH,CAAC,CAAA;AANY,QAAA,gCAAgC,oCAM5C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/State.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./Context"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./Provider"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./State"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./use"), exports);
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,qDAA0B;AAC1B,kDAAuB;AACvB,gDAAqB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useDivinedPayload = void 0;
|
|
4
|
-
const react_shared_1 = require("@xyo-network/react-shared");
|
|
5
|
-
const Context_1 = require("./Context");
|
|
6
|
-
const useDivinedPayload = () => (0, react_shared_1.useContextEx)(Context_1.DivinedPayloadContext, 'DivinedPayload', true);
|
|
7
|
-
exports.useDivinedPayload = useDivinedPayload;
|
|
8
|
-
//# sourceMappingURL=use.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../src/contexts/DivinedPayload/use.ts"],"names":[],"mappings":";;;AAAA,4DAAwD;AAExD,uCAAiD;AAE1C,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,IAAA,2BAAY,EAAC,+BAAqB,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAA;AAArF,QAAA,iBAAiB,qBAAoE"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PayloadDivinerContext = void 0;
|
|
4
|
-
const react_shared_1 = require("@xyo-network/react-shared");
|
|
5
|
-
const PayloadDivinerContext = (0, react_shared_1.createContextEx)();
|
|
6
|
-
exports.PayloadDivinerContext = PayloadDivinerContext;
|
|
7
|
-
//# sourceMappingURL=Context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Context.ts"],"names":[],"mappings":";;;AAAA,4DAA2D;AAI3D,MAAM,qBAAqB,GAAG,IAAA,8BAAe,GAAuB,CAAA;AAE3D,sDAAqB"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PayloadDivinerProvider = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
const Context_1 = require("./Context");
|
|
7
|
-
const PayloadDivinerProvider = ({ diviner: divinerProp, required = false, children }) => {
|
|
8
|
-
const [diviner, setDiviner] = (0, react_1.useState)(divinerProp);
|
|
9
|
-
(0, react_1.useEffect)(() => {
|
|
10
|
-
if (divinerProp) {
|
|
11
|
-
setDiviner(divinerProp);
|
|
12
|
-
}
|
|
13
|
-
}, [divinerProp]);
|
|
14
|
-
return ((0, jsx_runtime_1.jsx)(Context_1.PayloadDivinerContext.Provider, Object.assign({ value: {
|
|
15
|
-
diviner: diviner === divinerProp ? diviner : undefined,
|
|
16
|
-
provided: true,
|
|
17
|
-
setDiviner,
|
|
18
|
-
} }, { children: diviner ? children : required ? null : children })));
|
|
19
|
-
};
|
|
20
|
-
exports.PayloadDivinerProvider = PayloadDivinerProvider;
|
|
21
|
-
//# sourceMappingURL=Provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/Provider.tsx"],"names":[],"mappings":";;;;AAEA,iCAA2C;AAE3C,uCAAiD;AAO1C,MAAM,sBAAsB,GAA0C,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;IACpI,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAqC,WAAW,CAAC,CAAA;IAEvF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,WAAW,EAAE;YACf,UAAU,CAAC,WAAW,CAAC,CAAA;SACxB;IACH,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IAEjB,OAAO,CACL,uBAAC,+BAAqB,CAAC,QAAQ,kBAC7B,KAAK,EAAE;YACL,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;YACtD,QAAQ,EAAE,IAAI;YACd,UAAU;SACX,gBAEA,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,IACjB,CAClC,CAAA;AACH,CAAC,CAAA;AApBY,QAAA,sBAAsB,0BAoBlC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","sourceRoot":"","sources":["../../../../src/contexts/PayloadDiviner/State.ts"],"names":[],"mappings":""}
|