@xyo-network/react-sentinel 2.78.0 → 2.78.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.cjs +267 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +244 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +267 -1
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +244 -1
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +283 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +246 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +21 -21
package/dist/browser/index.cjs
CHANGED
|
@@ -1,2 +1,268 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
SentinelCard: () => SentinelCard,
|
|
24
|
+
SentinelCardContent: () => SentinelCardContent,
|
|
25
|
+
SentinelCardHeader: () => SentinelCardHeader,
|
|
26
|
+
SentinelContext: () => SentinelContext,
|
|
27
|
+
SentinelProvider: () => SentinelProvider,
|
|
28
|
+
SentinelReportStatus: () => SentinelReportStatus,
|
|
29
|
+
useSentinelContext: () => useSentinelContext,
|
|
30
|
+
useSentinelFromNode: () => useSentinelFromNode,
|
|
31
|
+
useSentinelsFromNode: () => useSentinelsFromNode,
|
|
32
|
+
useWeakSentinelFromNode: () => useWeakSentinelFromNode,
|
|
33
|
+
useWeakSentinelsFromNode: () => useWeakSentinelsFromNode
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
|
|
37
|
+
// src/components/Card/Card.tsx
|
|
38
|
+
var import_material = require("@mui/material");
|
|
39
|
+
var import_react_promise = require("@xylabs/react-promise");
|
|
40
|
+
var import_react = require("react");
|
|
41
|
+
|
|
42
|
+
// src/components/Card/CardActions.tsx
|
|
43
|
+
var import_react_button = require("@xylabs/react-button");
|
|
44
|
+
var import_react_module = require("@xyo-network/react-module");
|
|
45
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
+
var SentinelCardActions = ({ onReport, mod, ...props }) => {
|
|
47
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_module.ModuleCardActions, { mod, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_button.ButtonEx, { onClick: () => onReport?.(mod), size: "small", variant: "outlined", children: "Report" }) });
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/components/Card/CardContent.tsx
|
|
51
|
+
var import_react_flexbox = require("@xylabs/react-flexbox");
|
|
52
|
+
var import_react_module2 = require("@xyo-network/react-module");
|
|
53
|
+
var import_react_payload_raw_info = require("@xyo-network/react-payload-raw-info");
|
|
54
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
55
|
+
var SentinelCardContent = ({ children, report, mod, ...props }) => {
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_module2.ModuleCardContent, { mod, ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_flexbox.FlexGrowRow, { flexWrap: "wrap", justifyContent: "start", gap: 2, children: [
|
|
57
|
+
report ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_payload_raw_info.JsonViewerEx, { value: report }) : null,
|
|
58
|
+
children
|
|
59
|
+
] }) });
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/components/Card/CardHeader.tsx
|
|
63
|
+
var import_react_module3 = require("@xyo-network/react-module");
|
|
64
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
65
|
+
var SentinelCardHeader = ({ title, mod, ...props }) => {
|
|
66
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_module3.ModuleCardHeader, { mod, title: title ?? mod?.config.name ?? "Sentinel", ...props });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/components/Card/Card.tsx
|
|
70
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
71
|
+
var SentinelCard = ({ children, inPayloads, mod, ...props }) => {
|
|
72
|
+
const [retry, setRetry] = (0, import_react.useState)(-1);
|
|
73
|
+
const [report] = (0, import_react_promise.usePromise)(async () => {
|
|
74
|
+
if (retry >= 0) {
|
|
75
|
+
return await mod?.report(inPayloads);
|
|
76
|
+
}
|
|
77
|
+
}, [mod, retry, inPayloads]);
|
|
78
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_material.Card, { ...props, children: [
|
|
79
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SentinelCardHeader, { mod }),
|
|
80
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SentinelCardContent, { mod, report }),
|
|
81
|
+
children,
|
|
82
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SentinelCardActions, { mod, onReport: () => setRetry(retry + 1) })
|
|
83
|
+
] });
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/contexts/Context.ts
|
|
87
|
+
var import_react_shared = require("@xyo-network/react-shared");
|
|
88
|
+
var SentinelContext = (0, import_react_shared.createContextEx)();
|
|
89
|
+
|
|
90
|
+
// src/contexts/Provider.tsx
|
|
91
|
+
var import_react_async_effect = require("@xylabs/react-async-effect");
|
|
92
|
+
var import_react_witness = require("@xyo-network/react-witness");
|
|
93
|
+
var import_sentinel_memory = require("@xyo-network/sentinel-memory");
|
|
94
|
+
var import_sentinel_model = require("@xyo-network/sentinel-model");
|
|
95
|
+
var import_witness_model = require("@xyo-network/witness-model");
|
|
96
|
+
var import_react2 = require("react");
|
|
97
|
+
|
|
98
|
+
// src/contexts/State.ts
|
|
99
|
+
var SentinelReportStatus = /* @__PURE__ */ ((SentinelReportStatus2) => {
|
|
100
|
+
SentinelReportStatus2["Idle"] = "idle";
|
|
101
|
+
SentinelReportStatus2["Queued"] = "queued";
|
|
102
|
+
SentinelReportStatus2["Started"] = "started";
|
|
103
|
+
SentinelReportStatus2["Succeeded"] = "succeeded";
|
|
104
|
+
SentinelReportStatus2["Failed"] = "failed";
|
|
105
|
+
return SentinelReportStatus2;
|
|
106
|
+
})(SentinelReportStatus || {});
|
|
107
|
+
|
|
108
|
+
// src/contexts/Provider.tsx
|
|
109
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
110
|
+
var SentinelProvider = ({ account, archivist, children, filter, name, required = false }) => {
|
|
111
|
+
const [sentinel, setSentinel] = (0, import_react2.useState)();
|
|
112
|
+
const [history, setHistory] = (0, import_react2.useState)();
|
|
113
|
+
const [progress, setProgress] = (0, import_react2.useState)({});
|
|
114
|
+
const [status, setStatus] = (0, import_react2.useState)("idle" /* Idle */);
|
|
115
|
+
const [reportingErrors, setReportingErrors] = (0, import_react2.useState)();
|
|
116
|
+
const [witnesses] = (0, import_react_witness.useWitnessesFromNode)(filter);
|
|
117
|
+
(0, import_react_async_effect.useAsyncEffect)(
|
|
118
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
119
|
+
async (mounted) => {
|
|
120
|
+
const sentinel2 = await import_sentinel_memory.MemorySentinel.create({
|
|
121
|
+
account,
|
|
122
|
+
config: {
|
|
123
|
+
archivists: archivist ? [archivist] : void 0,
|
|
124
|
+
name,
|
|
125
|
+
schema: import_sentinel_model.SentinelConfigSchema,
|
|
126
|
+
synchronous: true,
|
|
127
|
+
// eslint-disable-next-line id-denylist
|
|
128
|
+
tasks: witnesses?.map((mod) => ({ module: mod.address }))
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
const offCallbacks = [];
|
|
132
|
+
offCallbacks.push(
|
|
133
|
+
sentinel2.on("reportEnd", ({ module: mod, outPayloads }) => {
|
|
134
|
+
if (mounted()) {
|
|
135
|
+
setProgress({
|
|
136
|
+
archivists: progress.archivists,
|
|
137
|
+
witnesses: progress.witnesses
|
|
138
|
+
});
|
|
139
|
+
setStatus(outPayloads?.length ? "succeeded" /* Succeeded */ : "failed" /* Failed */);
|
|
140
|
+
setReportingErrors([new Error(`Witness failed [${mod?.config?.name ?? mod.address}]`)]);
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
offCallbacks.push(
|
|
145
|
+
sentinel2.on("reportStart", () => {
|
|
146
|
+
if (mounted()) {
|
|
147
|
+
setProgress({ archivists: {}, witnesses: {} });
|
|
148
|
+
setStatus("started" /* Started */);
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
if (witnesses)
|
|
153
|
+
for (const witness of witnesses) {
|
|
154
|
+
offCallbacks.push(
|
|
155
|
+
witness.on("observeEnd", ({ module: mod, outPayloads }) => {
|
|
156
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
157
|
+
witnesses2[witness.address] = {
|
|
158
|
+
status: outPayloads?.length ? "succeeded" /* Succeeded */ : "failed" /* Failed */,
|
|
159
|
+
witness: (0, import_witness_model.asWitnessInstance)(mod, () => `Module is not a witness [${mod.id}]`)
|
|
160
|
+
};
|
|
161
|
+
if (mounted()) {
|
|
162
|
+
setProgress({
|
|
163
|
+
archivists: progress.archivists,
|
|
164
|
+
witnesses: witnesses2
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
offCallbacks.push(
|
|
170
|
+
witness.on("observeStart", ({ module: mod }) => {
|
|
171
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
172
|
+
witnesses2[witness.address] = {
|
|
173
|
+
status: "started" /* Started */,
|
|
174
|
+
witness: (0, import_witness_model.asWitnessInstance)(mod, () => `Module is not a witness [${mod.id}]`)
|
|
175
|
+
};
|
|
176
|
+
if (mounted()) {
|
|
177
|
+
setProgress({
|
|
178
|
+
archivists: progress.archivists,
|
|
179
|
+
witnesses: witnesses2
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
setSentinel(sentinel2);
|
|
186
|
+
return () => {
|
|
187
|
+
for (const callback of offCallbacks) {
|
|
188
|
+
callback();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
193
|
+
[account, archivist, witnesses]
|
|
194
|
+
);
|
|
195
|
+
(0, import_react2.useEffect)(() => {
|
|
196
|
+
setHistory(sentinel?.history);
|
|
197
|
+
}, [sentinel]);
|
|
198
|
+
return !required || sentinel ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SentinelContext.Provider, { value: { history, progress, provided: true, reportingErrors, sentinel, status }, children }) : null;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/contexts/use.ts
|
|
202
|
+
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
203
|
+
var useSentinelContext = () => {
|
|
204
|
+
const { sentinel, history, progress, reportingErrors, status } = (0, import_react_shared2.useContextEx)(SentinelContext, "Sentinel");
|
|
205
|
+
return { history, progress, reportingErrors, sentinel, status };
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// src/hooks/node/useSentinelFromNode.tsx
|
|
209
|
+
var import_react_node = require("@xyo-network/react-node");
|
|
210
|
+
var import_sentinel_model2 = require("@xyo-network/sentinel-model");
|
|
211
|
+
var useSentinelFromNode = (nameOrAddressOrInstance, config) => {
|
|
212
|
+
const [mod, error] = (0, import_react_node.useModuleFromNode)(nameOrAddressOrInstance, config);
|
|
213
|
+
const instance = (0, import_sentinel_model2.asSentinelInstance)(mod);
|
|
214
|
+
if (mod && !instance) {
|
|
215
|
+
const error2 = new Error(`Resolved module is not a SentinelInstance [${mod.config?.schema}:${mod.config?.name}:${mod.address}]`);
|
|
216
|
+
console.error(error2.message);
|
|
217
|
+
return [void 0, error2];
|
|
218
|
+
}
|
|
219
|
+
return [instance, error];
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// src/hooks/node/useSentinelsFromNode.tsx
|
|
223
|
+
var import_react_node2 = require("@xyo-network/react-node");
|
|
224
|
+
var import_sentinel_model3 = require("@xyo-network/sentinel-model");
|
|
225
|
+
var useSentinelsFromNode = (filter, config) => {
|
|
226
|
+
const [modules, error] = (0, import_react_node2.useModulesFromNode)(filter, config);
|
|
227
|
+
if (error) {
|
|
228
|
+
return [null, error];
|
|
229
|
+
}
|
|
230
|
+
return modules ? [
|
|
231
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
232
|
+
modules.reduce((prev, mod) => {
|
|
233
|
+
if ((0, import_sentinel_model3.isSentinelInstance)(mod)) {
|
|
234
|
+
prev.push(mod);
|
|
235
|
+
}
|
|
236
|
+
return prev;
|
|
237
|
+
}, []),
|
|
238
|
+
void 0
|
|
239
|
+
] : [modules, error];
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// src/hooks/node/useWeakSentinelFromNode.tsx
|
|
243
|
+
var import_react_node3 = require("@xyo-network/react-node");
|
|
244
|
+
var import_sentinel_model4 = require("@xyo-network/sentinel-model");
|
|
245
|
+
var useWeakSentinelFromNode = (nameOrAddressOrInstance, config) => {
|
|
246
|
+
return (0, import_react_node3.useWeakModuleFromNode)(nameOrAddressOrInstance, { identity: import_sentinel_model4.isSentinelInstance, ...config });
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/hooks/node/useWeakSentinelsFromNode.tsx
|
|
250
|
+
var import_exists = require("@xylabs/exists");
|
|
251
|
+
var import_react_node4 = require("@xyo-network/react-node");
|
|
252
|
+
var import_sentinel_model5 = require("@xyo-network/sentinel-model");
|
|
253
|
+
var useWeakSentinelsFromNode = (filter, config) => {
|
|
254
|
+
const [modules, error] = (0, import_react_node4.useWeakModulesFromNode)(filter, config);
|
|
255
|
+
if (error) {
|
|
256
|
+
return [null, error];
|
|
257
|
+
}
|
|
258
|
+
return [
|
|
259
|
+
modules?.map((mod) => {
|
|
260
|
+
const instance = (0, import_sentinel_model5.asSentinelInstance)(mod?.deref());
|
|
261
|
+
if (instance) {
|
|
262
|
+
return new WeakRef(instance);
|
|
263
|
+
}
|
|
264
|
+
}).filter(import_exists.exists) ?? [],
|
|
265
|
+
void 0
|
|
266
|
+
];
|
|
267
|
+
};
|
|
2
268
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/components/Card/Card.tsx","../../src/components/Card/CardActions.tsx","../../src/components/Card/CardContent.tsx","../../src/components/Card/CardHeader.tsx","../../src/contexts/Context.ts","../../src/contexts/Provider.tsx","../../src/contexts/State.ts","../../src/contexts/use.ts","../../src/hooks/node/useSentinelFromNode.tsx","../../src/hooks/node/useSentinelsFromNode.tsx","../../src/hooks/node/useWeakSentinelFromNode.tsx","../../src/hooks/node/useWeakSentinelsFromNode.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\nexport * from './hooks'\n","import { Card, CardProps } from '@mui/material'\nimport { usePromise } from '@xylabs/react-promise'\nimport { Payload } from '@xyo-network/payload-model'\nimport { ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\nimport { useState } from 'react'\n\nimport { SentinelCardActions } from './CardActions'\nimport { SentinelCardContent } from './CardContent'\nimport { SentinelCardHeader } from './CardHeader'\n\nexport type SentinelCardProps = CardProps &\n ModuleRenderProps<SentinelInstance> & {\n inPayloads?: Payload[]\n }\n\nexport const SentinelCard: React.FC<SentinelCardProps> = ({ children, inPayloads, mod, ...props }) => {\n const [retry, setRetry] = useState(-1)\n const [report] = usePromise(async () => {\n if (retry >= 0) {\n return await mod?.report(inPayloads)\n }\n }, [mod, retry, inPayloads])\n return (\n <Card {...props}>\n <SentinelCardHeader mod={mod} />\n <SentinelCardContent mod={mod} report={report} />\n {children}\n <SentinelCardActions mod={mod} onReport={() => setRetry(retry + 1)} />\n </Card>\n )\n}\n","import { CardActionsProps } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleCardActions, ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport type SentinelCardActionsProps = ModuleRenderProps<SentinelInstance> &\n CardActionsProps & {\n onReport?: (mod?: SentinelInstance) => void\n }\n\nexport const SentinelCardActions: React.FC<SentinelCardActionsProps> = ({ onReport, mod, ...props }) => {\n return (\n <ModuleCardActions mod={mod} {...props}>\n <ButtonEx onClick={() => onReport?.(mod)} size={'small'} variant={'outlined'}>\n Report\n </ButtonEx>\n </ModuleCardActions>\n )\n}\n","import { CardContentProps } from '@mui/material'\nimport { FlexGrowRow } from '@xylabs/react-flexbox'\nimport { Payload } from '@xyo-network/payload-model'\nimport { ModuleCardContent, ModuleRenderProps } from '@xyo-network/react-module'\nimport { JsonViewerEx } from '@xyo-network/react-payload-raw-info'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\nimport React from 'react'\n\nexport type SentinelCardContentProps = ModuleRenderProps<SentinelInstance> &\n CardContentProps & {\n report?: Payload[]\n }\n\nexport const SentinelCardContent: React.FC<SentinelCardContentProps> = ({ children, report, mod, ...props }) => {\n return (\n <ModuleCardContent mod={mod} {...props}>\n <FlexGrowRow flexWrap=\"wrap\" justifyContent=\"start\" gap={2}>\n {report ?\n <JsonViewerEx value={report} />\n : null}\n {children}\n </FlexGrowRow>\n </ModuleCardContent>\n )\n}\n","import { CardHeaderProps } from '@mui/material'\nimport { ModuleCardHeader, ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const SentinelCardHeader: React.FC<ModuleRenderProps<SentinelInstance> & CardHeaderProps> = ({ title, mod, ...props }) => {\n return <ModuleCardHeader mod={mod} title={title ?? mod?.config.name ?? 'Sentinel'} {...props} />\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n","/* eslint-disable unicorn/no-array-push-push */\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { AccountInstance } from '@xyo-network/account-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { ModuleFilter } from '@xyo-network/module-model'\nimport { useWitnessesFromNode } from '@xyo-network/react-witness'\nimport { MemorySentinel } from '@xyo-network/sentinel-memory'\nimport { SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel-model'\nimport { asWitnessInstance, WitnessInstance } from '@xyo-network/witness-model'\nimport { useEffect, useState } from 'react'\n\nimport { SentinelContext } from './Context'\nimport { SentinelReportProgress, SentinelReportStatus } from './State'\n\nexport interface SentinelProviderProps {\n /** Account used by the sentinel for signing */\n account: AccountInstance\n /** @deprecated - sentinel no longer uses archive but relies on an archivist */\n archive?: string\n archivist?: string\n filter?: ModuleFilter\n name?: string\n required?: boolean\n witnesses?: WitnessInstance[]\n}\n\nexport const SentinelProvider: React.FC<WithChildren<SentinelProviderProps>> = ({ account, archivist, children, filter, name, required = false }) => {\n const [sentinel, setSentinel] = useState<MemorySentinel>()\n const [history, setHistory] = useState<BoundWitness[]>()\n const [progress, setProgress] = useState<SentinelReportProgress>({})\n const [status, setStatus] = useState(SentinelReportStatus.Idle)\n const [reportingErrors, setReportingErrors] = useState<Error[]>()\n const [witnesses] = useWitnessesFromNode(filter)\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n const sentinel = await MemorySentinel.create({\n account,\n config: {\n archivists: archivist ? [archivist] : undefined,\n name,\n\n schema: SentinelConfigSchema,\n synchronous: true,\n // eslint-disable-next-line id-denylist\n tasks: witnesses?.map((mod) => ({ module: mod.address })),\n } as SentinelConfig,\n })\n const offCallbacks: (() => void)[] = []\n offCallbacks.push(\n sentinel.on('reportEnd', ({ module: mod, outPayloads }) => {\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses: progress.witnesses,\n })\n setStatus(outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed)\n setReportingErrors([new Error(`Witness failed [${mod?.config?.name ?? mod.address}]`)])\n }\n }),\n )\n offCallbacks.push(\n sentinel.on('reportStart', () => {\n if (mounted()) {\n setProgress({ archivists: {}, witnesses: {} })\n setStatus(SentinelReportStatus.Started)\n }\n }),\n )\n if (witnesses)\n for (const witness of witnesses) {\n offCallbacks.push(\n witness.on('observeEnd', ({ module: mod, outPayloads }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed,\n witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`),\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n offCallbacks.push(\n witness.on('observeStart', ({ module: mod }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: SentinelReportStatus.Started,\n witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`),\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n }\n setSentinel(sentinel as MemorySentinel)\n return () => {\n //unsubscribe from events\n for (const callback of offCallbacks) {\n callback()\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [account, archivist, witnesses],\n )\n\n useEffect(() => {\n setHistory(sentinel?.history as BoundWitness[])\n }, [sentinel])\n\n return !required || sentinel ?\n <SentinelContext.Provider value={{ history, progress, provided: true, reportingErrors, sentinel, status }}>{children}</SentinelContext.Provider>\n : null\n}\n","import { ArchivistModule } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { SentinelModule } from '@xyo-network/sentinel-model'\nimport { WitnessModule } from '@xyo-network/witness-model'\n\nexport enum SentinelReportStatus {\n Idle = 'idle',\n Queued = 'queued',\n Started = 'started',\n Succeeded = 'succeeded',\n Failed = 'failed',\n}\n\nexport interface SentinelWitnessReportProgress {\n status: SentinelReportStatus\n witness: WitnessModule\n}\n\nexport interface SentinelArchivistApiReportProgress {\n archivist: ArchivistModule\n status: SentinelReportStatus\n}\n\nexport interface SentinelReportProgress {\n archivists?: Record<string, SentinelArchivistApiReportProgress>\n witnesses?: Record<string, SentinelWitnessReportProgress>\n}\n\nexport interface SentinelContextState {\n history?: BoundWitness[]\n progress?: SentinelReportProgress\n reportingErrors?: Error[]\n sentinel?: SentinelModule\n status?: SentinelReportStatus\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContext } from './Context'\n\nexport const useSentinelContext = () => {\n const { sentinel, history, progress, reportingErrors, status } = useContextEx(SentinelContext, 'Sentinel')\n return { history, progress, reportingErrors, sentinel, status }\n}\n","// eslint-disable-next-line import/no-deprecated\nimport { ModuleFromNodeConfig, useModuleFromNode } from '@xyo-network/react-node'\nimport { asSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useSentinelFromNode = (\n nameOrAddressOrInstance?: string | SentinelInstance,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance | undefined, Error | undefined] => {\n // eslint-disable-next-line deprecation/deprecation, import/no-deprecated\n const [mod, error] = useModuleFromNode(nameOrAddressOrInstance, config)\n const instance = asSentinelInstance(mod)\n if (mod && !instance) {\n const error = new Error(`Resolved module is not a SentinelInstance [${mod.config?.schema}:${mod.config?.name}:${mod.address}]`)\n console.error(error.message)\n return [undefined, error]\n }\n return [instance, error]\n}\n","import { ModuleFilter } from '@xyo-network/module-model'\n// eslint-disable-next-line import/no-deprecated\nimport { ModuleFromNodeConfig, useModulesFromNode } from '@xyo-network/react-node'\nimport { isSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useSentinelsFromNode = (\n filter?: ModuleFilter,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance[] | null | undefined, Error | undefined] => {\n // eslint-disable-next-line deprecation/deprecation, import/no-deprecated\n const [modules, error] = useModulesFromNode(filter, config)\n if (error) {\n return [null, error]\n }\n return modules ?\n [\n // eslint-disable-next-line unicorn/no-array-reduce\n modules.reduce<SentinelInstance[]>((prev, mod) => {\n if (isSentinelInstance(mod)) {\n prev.push(mod)\n }\n return prev\n }, []),\n undefined,\n ]\n : [modules, error]\n}\n","import { useWeakModuleFromNode, WeakModuleFromNodeConfig } from '@xyo-network/react-node'\nimport { isSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useWeakSentinelFromNode = (\n nameOrAddressOrInstance?: string | SentinelInstance,\n config?: WeakModuleFromNodeConfig,\n): [WeakRef<SentinelInstance> | undefined, Error | undefined] => {\n return useWeakModuleFromNode<SentinelInstance>(nameOrAddressOrInstance, { identity: isSentinelInstance, ...config })\n}\n","import { exists } from '@xylabs/exists'\nimport { ModuleFilter } from '@xyo-network/module-model'\nimport { ModuleFromNodeConfig, useWeakModulesFromNode } from '@xyo-network/react-node'\nimport { asSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useWeakSentinelsFromNode = (\n filter?: ModuleFilter,\n config?: ModuleFromNodeConfig,\n): [WeakRef<SentinelInstance>[] | null | undefined, Error | undefined] => {\n const [modules, error] = useWeakModulesFromNode(filter, config)\n if (error) {\n return [null, error]\n }\n return [\n modules\n ?.map((mod) => {\n const instance = asSentinelInstance(mod?.deref())\n if (instance) {\n return new WeakRef(instance)\n }\n })\n .filter(exists) ?? [],\n undefined,\n ]\n}\n"],"mappings":"mbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,kBAAAE,GAAA,wBAAAC,EAAA,uBAAAC,EAAA,oBAAAC,EAAA,qBAAAC,GAAA,yBAAAC,EAAA,uBAAAC,GAAA,wBAAAC,GAAA,yBAAAC,GAAA,4BAAAC,GAAA,6BAAAC,KAAA,eAAAC,GAAAb,ICAA,IAAAc,EAAgC,yBAChCC,EAA2B,iCAI3BC,EAAyB,iBCJzB,IAAAC,EAAyB,gCACzBC,EAAqD,qCAW/CC,EAAA,6BAHOC,EAA0D,CAAC,CAAE,SAAAC,EAAU,IAAAC,EAAK,GAAGC,CAAM,OAE9F,OAAC,qBAAkB,IAAKD,EAAM,GAAGC,EAC/B,mBAAC,YAAS,QAAS,IAAMF,IAAWC,CAAG,EAAG,KAAM,QAAS,QAAS,WAAY,kBAE9E,EACF,ECfJ,IAAAE,EAA4B,iCAE5BC,EAAqD,qCACrDC,EAA6B,+CAYvBC,EAAA,6BAHOC,EAA0D,CAAC,CAAE,SAAAC,EAAU,OAAAC,EAAQ,IAAAC,EAAK,GAAGC,CAAM,OAEtG,OAAC,qBAAkB,IAAKD,EAAM,GAAGC,EAC/B,oBAAC,eAAY,SAAS,OAAO,eAAe,QAAQ,IAAK,EACtD,UAAAF,KACC,OAAC,gBAAa,MAAOA,EAAQ,EAC7B,KACDD,GACH,EACF,ECrBJ,IAAAI,EAAoD,qCAI3CC,EAAA,6BADIC,EAAsF,CAAC,CAAE,MAAAC,EAAO,IAAAC,EAAK,GAAGC,CAAM,OAClH,OAAC,oBAAiB,IAAKD,EAAK,MAAOD,GAASC,GAAK,OAA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ClCC,EACAC,IAC+D,CAE/D,GAAM,CAACC,EAASC,CAAK,KAAI,sBAAmBH,EAAQC,CAAM,EAC1D,OAAIE,EACK,CAAC,KAAMA,CAAK,EAEdD,EACH,CAEEA,EAAQ,OAA2B,CAACE,EAAMC,QACpC,sBAAmBA,CAAG,GACxBD,EAAK,KAAKC,CAAG,EAERD,GACN,CAAC,CAAC,EACL,MACF,EACA,CAACF,EAASC,CAAK,CACrB,EC1BA,IAAAG,EAAgE,mCAChEC,EAAqD,uCAExCC,GAA0B,CACrCC,EACAC,OAEO,yBAAwCD,EAAyB,CAAE,SAAU,qBAAoB,GAAGC,CAAO,CAAC,ECPrH,IAAAC,EAAuB,0BAEvBC,EAA6D,mCAC7DC,GAAqD,uCAExCC,GAA2B,CACtCC,EACAC,IACwE,CACxE,GAAM,CAACC,EAASC,CAAK,KAAI,0BAAuBH,EAAQC,CAAM,EAC9D,OAAIE,EACK,CAAC,KAAMA,CAAK,EAEd,CACLD,GACI,IAAKE,GAAQ,CACb,IAAMC,KAAW,uBAAmBD,GAAK,MAAM,CAAC,EAChD,GAAIC,EACF,OAAO,IAAI,QAAQA,CAAQ,CAE/B,CAAC,EACA,OAAO,QAAM,GAAK,CAAC,EACtB,MACF,CACF","names":["src_exports","__export","SentinelCard","SentinelCardContent","SentinelCardHeader","SentinelContext","SentinelProvider","SentinelReportStatus","useSentinelContext","useSentinelFromNode","useSentinelsFromNode","useWeakSentinelFromNode","useWeakSentinelsFromNode","__toCommonJS","import_material","import_react_promise","import_react","import_react_button","import_react_module","import_jsx_runtime","SentinelCardActions","onReport","mod","props","import_react_flexbox","import_react_module","import_react_payload_raw_info","import_jsx_runtime","SentinelCardContent","children","report","mod","props","import_react_module","import_jsx_runtime","SentinelCardHeader","title","mod","props","import_jsx_runtime","SentinelCard","children","inPayloads","mod","props","retry","setRetry","report","SentinelCardHeader","SentinelCardContent","SentinelCardActions","import_react_shared","SentinelContext","import_react_async_effect","import_react_witness","import_sentinel_memory","import_sentinel_model","import_witness_model","import_react","SentinelReportStatus","import_jsx_runtime","SentinelProvider","account","archivist","children","filter","name","required","sentinel","setSentinel","history","setHistory","progress","setProgress","status","setStatus","reportingErrors","setReportingErrors","witnesses","mounted","mod","offCallbacks","outPayloads","witness","callback","SentinelContext","import_react_shared","useSentinelContext","sentinel","history","progress","reportingErrors","status","SentinelContext","import_react_node","import_sentinel_model","useSentinelFromNode","nameOrAddressOrInstance","config","mod","error","instance","import_react_node","import_sentinel_model","useSentinelsFromNode","filter","config","modules","error","prev","mod","import_react_node","import_sentinel_model","useWeakSentinelFromNode","nameOrAddressOrInstance","config","import_exists","import_react_node","import_sentinel_model","useWeakSentinelsFromNode","filter","config","modules","error","mod","instance"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/components/Card/Card.tsx","../../src/components/Card/CardActions.tsx","../../src/components/Card/CardContent.tsx","../../src/components/Card/CardHeader.tsx","../../src/contexts/Context.ts","../../src/contexts/Provider.tsx","../../src/contexts/State.ts","../../src/contexts/use.ts","../../src/hooks/node/useSentinelFromNode.tsx","../../src/hooks/node/useSentinelsFromNode.tsx","../../src/hooks/node/useWeakSentinelFromNode.tsx","../../src/hooks/node/useWeakSentinelsFromNode.tsx"],"sourcesContent":["export * from './components'\nexport * from './contexts'\nexport * from './hooks'\n","import { Card, CardProps } from '@mui/material'\nimport { usePromise } from '@xylabs/react-promise'\nimport { Payload } from '@xyo-network/payload-model'\nimport { ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\nimport { useState } from 'react'\n\nimport { SentinelCardActions } from './CardActions'\nimport { SentinelCardContent } from './CardContent'\nimport { SentinelCardHeader } from './CardHeader'\n\nexport type SentinelCardProps = CardProps &\n ModuleRenderProps<SentinelInstance> & {\n inPayloads?: Payload[]\n }\n\nexport const SentinelCard: React.FC<SentinelCardProps> = ({ children, inPayloads, mod, ...props }) => {\n const [retry, setRetry] = useState(-1)\n const [report] = usePromise(async () => {\n if (retry >= 0) {\n return await mod?.report(inPayloads)\n }\n }, [mod, retry, inPayloads])\n return (\n <Card {...props}>\n <SentinelCardHeader mod={mod} />\n <SentinelCardContent mod={mod} report={report} />\n {children}\n <SentinelCardActions mod={mod} onReport={() => setRetry(retry + 1)} />\n </Card>\n )\n}\n","import { CardActionsProps } from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport { ModuleCardActions, ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport type SentinelCardActionsProps = ModuleRenderProps<SentinelInstance> &\n CardActionsProps & {\n onReport?: (mod?: SentinelInstance) => void\n }\n\nexport const SentinelCardActions: React.FC<SentinelCardActionsProps> = ({ onReport, mod, ...props }) => {\n return (\n <ModuleCardActions mod={mod} {...props}>\n <ButtonEx onClick={() => onReport?.(mod)} size={'small'} variant={'outlined'}>\n Report\n </ButtonEx>\n </ModuleCardActions>\n )\n}\n","import { CardContentProps } from '@mui/material'\nimport { FlexGrowRow } from '@xylabs/react-flexbox'\nimport { Payload } from '@xyo-network/payload-model'\nimport { ModuleCardContent, ModuleRenderProps } from '@xyo-network/react-module'\nimport { JsonViewerEx } from '@xyo-network/react-payload-raw-info'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\nimport React from 'react'\n\nexport type SentinelCardContentProps = ModuleRenderProps<SentinelInstance> &\n CardContentProps & {\n report?: Payload[]\n }\n\nexport const SentinelCardContent: React.FC<SentinelCardContentProps> = ({ children, report, mod, ...props }) => {\n return (\n <ModuleCardContent mod={mod} {...props}>\n <FlexGrowRow flexWrap=\"wrap\" justifyContent=\"start\" gap={2}>\n {report ?\n <JsonViewerEx value={report} />\n : null}\n {children}\n </FlexGrowRow>\n </ModuleCardContent>\n )\n}\n","import { CardHeaderProps } from '@mui/material'\nimport { ModuleCardHeader, ModuleRenderProps } from '@xyo-network/react-module'\nimport { SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const SentinelCardHeader: React.FC<ModuleRenderProps<SentinelInstance> & CardHeaderProps> = ({ title, mod, ...props }) => {\n return <ModuleCardHeader mod={mod} title={title ?? mod?.config.name ?? 'Sentinel'} {...props} />\n}\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n","/* eslint-disable unicorn/no-array-push-push */\nimport { useAsyncEffect } from '@xylabs/react-async-effect'\nimport { WithChildren } from '@xylabs/react-shared'\nimport { AccountInstance } from '@xyo-network/account-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { ModuleFilter } from '@xyo-network/module-model'\nimport { useWitnessesFromNode } from '@xyo-network/react-witness'\nimport { MemorySentinel } from '@xyo-network/sentinel-memory'\nimport { SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel-model'\nimport { asWitnessInstance, WitnessInstance } from '@xyo-network/witness-model'\nimport { useEffect, useState } from 'react'\n\nimport { SentinelContext } from './Context'\nimport { SentinelReportProgress, SentinelReportStatus } from './State'\n\nexport interface SentinelProviderProps {\n /** Account used by the sentinel for signing */\n account: AccountInstance\n /** @deprecated - sentinel no longer uses archive but relies on an archivist */\n archive?: string\n archivist?: string\n filter?: ModuleFilter\n name?: string\n required?: boolean\n witnesses?: WitnessInstance[]\n}\n\nexport const SentinelProvider: React.FC<WithChildren<SentinelProviderProps>> = ({ account, archivist, children, filter, name, required = false }) => {\n const [sentinel, setSentinel] = useState<MemorySentinel>()\n const [history, setHistory] = useState<BoundWitness[]>()\n const [progress, setProgress] = useState<SentinelReportProgress>({})\n const [status, setStatus] = useState(SentinelReportStatus.Idle)\n const [reportingErrors, setReportingErrors] = useState<Error[]>()\n const [witnesses] = useWitnessesFromNode(filter)\n\n useAsyncEffect(\n // eslint-disable-next-line react-hooks/exhaustive-deps\n async (mounted) => {\n const sentinel = await MemorySentinel.create({\n account,\n config: {\n archivists: archivist ? [archivist] : undefined,\n name,\n\n schema: SentinelConfigSchema,\n synchronous: true,\n // eslint-disable-next-line id-denylist\n tasks: witnesses?.map((mod) => ({ module: mod.address })),\n } as SentinelConfig,\n })\n const offCallbacks: (() => void)[] = []\n offCallbacks.push(\n sentinel.on('reportEnd', ({ module: mod, outPayloads }) => {\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses: progress.witnesses,\n })\n setStatus(outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed)\n setReportingErrors([new Error(`Witness failed [${mod?.config?.name ?? mod.address}]`)])\n }\n }),\n )\n offCallbacks.push(\n sentinel.on('reportStart', () => {\n if (mounted()) {\n setProgress({ archivists: {}, witnesses: {} })\n setStatus(SentinelReportStatus.Started)\n }\n }),\n )\n if (witnesses)\n for (const witness of witnesses) {\n offCallbacks.push(\n witness.on('observeEnd', ({ module: mod, outPayloads }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed,\n witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`),\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n offCallbacks.push(\n witness.on('observeStart', ({ module: mod }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: SentinelReportStatus.Started,\n witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`),\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n }\n setSentinel(sentinel as MemorySentinel)\n return () => {\n //unsubscribe from events\n for (const callback of offCallbacks) {\n callback()\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [account, archivist, witnesses],\n )\n\n useEffect(() => {\n setHistory(sentinel?.history as BoundWitness[])\n }, [sentinel])\n\n return !required || sentinel ?\n <SentinelContext.Provider value={{ history, progress, provided: true, reportingErrors, sentinel, status }}>{children}</SentinelContext.Provider>\n : null\n}\n","import { ArchivistModule } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { SentinelModule } from '@xyo-network/sentinel-model'\nimport { WitnessModule } from '@xyo-network/witness-model'\n\nexport enum SentinelReportStatus {\n Idle = 'idle',\n Queued = 'queued',\n Started = 'started',\n Succeeded = 'succeeded',\n Failed = 'failed',\n}\n\nexport interface SentinelWitnessReportProgress {\n status: SentinelReportStatus\n witness: WitnessModule\n}\n\nexport interface SentinelArchivistApiReportProgress {\n archivist: ArchivistModule\n status: SentinelReportStatus\n}\n\nexport interface SentinelReportProgress {\n archivists?: Record<string, SentinelArchivistApiReportProgress>\n witnesses?: Record<string, SentinelWitnessReportProgress>\n}\n\nexport interface SentinelContextState {\n history?: BoundWitness[]\n progress?: SentinelReportProgress\n reportingErrors?: Error[]\n sentinel?: SentinelModule\n status?: SentinelReportStatus\n}\n","import { useContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContext } from './Context'\n\nexport const useSentinelContext = () => {\n const { sentinel, history, progress, reportingErrors, status } = useContextEx(SentinelContext, 'Sentinel')\n return { history, progress, reportingErrors, sentinel, status }\n}\n","// eslint-disable-next-line import/no-deprecated\nimport { ModuleFromNodeConfig, useModuleFromNode } from '@xyo-network/react-node'\nimport { asSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useSentinelFromNode = (\n nameOrAddressOrInstance?: string | SentinelInstance,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance | undefined, Error | undefined] => {\n // eslint-disable-next-line deprecation/deprecation, import/no-deprecated\n const [mod, error] = useModuleFromNode(nameOrAddressOrInstance, config)\n const instance = asSentinelInstance(mod)\n if (mod && !instance) {\n const error = new Error(`Resolved module is not a SentinelInstance [${mod.config?.schema}:${mod.config?.name}:${mod.address}]`)\n console.error(error.message)\n return [undefined, error]\n }\n return [instance, error]\n}\n","import { ModuleFilter } from '@xyo-network/module-model'\n// eslint-disable-next-line import/no-deprecated\nimport { ModuleFromNodeConfig, useModulesFromNode } from '@xyo-network/react-node'\nimport { isSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useSentinelsFromNode = (\n filter?: ModuleFilter,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance[] | null | undefined, Error | undefined] => {\n // eslint-disable-next-line deprecation/deprecation, import/no-deprecated\n const [modules, error] = useModulesFromNode(filter, config)\n if (error) {\n return [null, error]\n }\n return modules ?\n [\n // eslint-disable-next-line unicorn/no-array-reduce\n modules.reduce<SentinelInstance[]>((prev, mod) => {\n if (isSentinelInstance(mod)) {\n prev.push(mod)\n }\n return prev\n }, []),\n undefined,\n ]\n : [modules, error]\n}\n","import { useWeakModuleFromNode, WeakModuleFromNodeConfig } from '@xyo-network/react-node'\nimport { isSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useWeakSentinelFromNode = (\n nameOrAddressOrInstance?: string | SentinelInstance,\n config?: WeakModuleFromNodeConfig,\n): [WeakRef<SentinelInstance> | undefined, Error | undefined] => {\n return useWeakModuleFromNode<SentinelInstance>(nameOrAddressOrInstance, { identity: isSentinelInstance, ...config })\n}\n","import { exists } from '@xylabs/exists'\nimport { ModuleFilter } from '@xyo-network/module-model'\nimport { ModuleFromNodeConfig, useWeakModulesFromNode } from '@xyo-network/react-node'\nimport { asSentinelInstance, SentinelInstance } from '@xyo-network/sentinel-model'\n\nexport const useWeakSentinelsFromNode = (\n filter?: ModuleFilter,\n config?: ModuleFromNodeConfig,\n): [WeakRef<SentinelInstance>[] | null | undefined, Error | undefined] => {\n const [modules, error] = useWeakModulesFromNode(filter, config)\n if (error) {\n return [null, error]\n }\n return [\n modules\n ?.map((mod) => {\n const instance = asSentinelInstance(mod?.deref())\n if (instance) {\n return new WeakRef(instance)\n }\n })\n .filter(exists) ?? [],\n undefined,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAAg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,EACrB;AACA,SAAO,UACH;AAAA;AAAA,IAEE,QAAQ,OAA2B,CAAC,MAAM,QAAQ;AAChD,cAAI,2CAAmB,GAAG,GAAG;AAC3B,aAAK,KAAK,GAAG;AAAA,MACf;AACA,aAAO;AAAA,IACT,GAAG,CAAC,CAAC;AAAA,IACL;AAAA,EACF,IACA,CAAC,SAAS,KAAK;AACrB;;;AC1BA,IAAAC,qBAAgE;AAChE,IAAAC,yBAAqD;AAE9C,IAAM,0BAA0B,CACrC,yBACA,WAC+D;AAC/D,aAAO,0CAAwC,yBAAyB,EAAE,UAAU,2CAAoB,GAAG,OAAO,CAAC;AACrH;;;ACRA,oBAAuB;AAEvB,IAAAC,qBAA6D;AAC7D,IAAAC,yBAAqD;AAE9C,IAAM,2BAA2B,CACtC,QACA,WACwE;AACxE,QAAM,CAAC,SAAS,KAAK,QAAI,2CAAuB,QAAQ,MAAM;AAC9D,MAAI,OAAO;AACT,WAAO,CAAC,MAAM,KAAK;AAAA,EACrB;AACA,SAAO;AAAA,IACL,SACI,IAAI,CAAC,QAAQ;AACb,YAAM,eAAW,2CAAmB,KAAK,MAAM,CAAC;AAChD,UAAI,UAAU;AACZ,eAAO,IAAI,QAAQ,QAAQ;AAAA,MAC7B;AAAA,IACF,CAAC,EACA,OAAO,oBAAM,KAAK,CAAC;AAAA,IACtB;AAAA,EACF;AACF;","names":["import_react_module","import_jsx_runtime","import_react_module","import_jsx_runtime","import_jsx_runtime","import_react","SentinelReportStatus","import_jsx_runtime","sentinel","witnesses","import_react_shared","import_sentinel_model","error","import_react_node","import_sentinel_model","import_react_node","import_sentinel_model","import_react_node","import_sentinel_model"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,245 @@
|
|
|
1
|
-
|
|
1
|
+
// src/components/Card/Card.tsx
|
|
2
|
+
import { Card } from "@mui/material";
|
|
3
|
+
import { usePromise } from "@xylabs/react-promise";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
|
|
6
|
+
// src/components/Card/CardActions.tsx
|
|
7
|
+
import { ButtonEx } from "@xylabs/react-button";
|
|
8
|
+
import { ModuleCardActions } from "@xyo-network/react-module";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
var SentinelCardActions = ({ onReport, mod, ...props }) => {
|
|
11
|
+
return /* @__PURE__ */ jsx(ModuleCardActions, { mod, ...props, children: /* @__PURE__ */ jsx(ButtonEx, { onClick: () => onReport?.(mod), size: "small", variant: "outlined", children: "Report" }) });
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/components/Card/CardContent.tsx
|
|
15
|
+
import { FlexGrowRow } from "@xylabs/react-flexbox";
|
|
16
|
+
import { ModuleCardContent } from "@xyo-network/react-module";
|
|
17
|
+
import { JsonViewerEx } from "@xyo-network/react-payload-raw-info";
|
|
18
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
19
|
+
var SentinelCardContent = ({ children, report, mod, ...props }) => {
|
|
20
|
+
return /* @__PURE__ */ jsx2(ModuleCardContent, { mod, ...props, children: /* @__PURE__ */ jsxs(FlexGrowRow, { flexWrap: "wrap", justifyContent: "start", gap: 2, children: [
|
|
21
|
+
report ? /* @__PURE__ */ jsx2(JsonViewerEx, { value: report }) : null,
|
|
22
|
+
children
|
|
23
|
+
] }) });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/components/Card/CardHeader.tsx
|
|
27
|
+
import { ModuleCardHeader } from "@xyo-network/react-module";
|
|
28
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
29
|
+
var SentinelCardHeader = ({ title, mod, ...props }) => {
|
|
30
|
+
return /* @__PURE__ */ jsx3(ModuleCardHeader, { mod, title: title ?? mod?.config.name ?? "Sentinel", ...props });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/components/Card/Card.tsx
|
|
34
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
35
|
+
var SentinelCard = ({ children, inPayloads, mod, ...props }) => {
|
|
36
|
+
const [retry, setRetry] = useState(-1);
|
|
37
|
+
const [report] = usePromise(async () => {
|
|
38
|
+
if (retry >= 0) {
|
|
39
|
+
return await mod?.report(inPayloads);
|
|
40
|
+
}
|
|
41
|
+
}, [mod, retry, inPayloads]);
|
|
42
|
+
return /* @__PURE__ */ jsxs2(Card, { ...props, children: [
|
|
43
|
+
/* @__PURE__ */ jsx4(SentinelCardHeader, { mod }),
|
|
44
|
+
/* @__PURE__ */ jsx4(SentinelCardContent, { mod, report }),
|
|
45
|
+
children,
|
|
46
|
+
/* @__PURE__ */ jsx4(SentinelCardActions, { mod, onReport: () => setRetry(retry + 1) })
|
|
47
|
+
] });
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/contexts/Context.ts
|
|
51
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
52
|
+
var SentinelContext = createContextEx();
|
|
53
|
+
|
|
54
|
+
// src/contexts/Provider.tsx
|
|
55
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
56
|
+
import { useWitnessesFromNode } from "@xyo-network/react-witness";
|
|
57
|
+
import { MemorySentinel } from "@xyo-network/sentinel-memory";
|
|
58
|
+
import { SentinelConfigSchema } from "@xyo-network/sentinel-model";
|
|
59
|
+
import { asWitnessInstance } from "@xyo-network/witness-model";
|
|
60
|
+
import { useEffect, useState as useState2 } from "react";
|
|
61
|
+
|
|
62
|
+
// src/contexts/State.ts
|
|
63
|
+
var SentinelReportStatus = /* @__PURE__ */ ((SentinelReportStatus2) => {
|
|
64
|
+
SentinelReportStatus2["Idle"] = "idle";
|
|
65
|
+
SentinelReportStatus2["Queued"] = "queued";
|
|
66
|
+
SentinelReportStatus2["Started"] = "started";
|
|
67
|
+
SentinelReportStatus2["Succeeded"] = "succeeded";
|
|
68
|
+
SentinelReportStatus2["Failed"] = "failed";
|
|
69
|
+
return SentinelReportStatus2;
|
|
70
|
+
})(SentinelReportStatus || {});
|
|
71
|
+
|
|
72
|
+
// src/contexts/Provider.tsx
|
|
73
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
74
|
+
var SentinelProvider = ({ account, archivist, children, filter, name, required = false }) => {
|
|
75
|
+
const [sentinel, setSentinel] = useState2();
|
|
76
|
+
const [history, setHistory] = useState2();
|
|
77
|
+
const [progress, setProgress] = useState2({});
|
|
78
|
+
const [status, setStatus] = useState2("idle" /* Idle */);
|
|
79
|
+
const [reportingErrors, setReportingErrors] = useState2();
|
|
80
|
+
const [witnesses] = useWitnessesFromNode(filter);
|
|
81
|
+
useAsyncEffect(
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
async (mounted) => {
|
|
84
|
+
const sentinel2 = await MemorySentinel.create({
|
|
85
|
+
account,
|
|
86
|
+
config: {
|
|
87
|
+
archivists: archivist ? [archivist] : void 0,
|
|
88
|
+
name,
|
|
89
|
+
schema: SentinelConfigSchema,
|
|
90
|
+
synchronous: true,
|
|
91
|
+
// eslint-disable-next-line id-denylist
|
|
92
|
+
tasks: witnesses?.map((mod) => ({ module: mod.address }))
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const offCallbacks = [];
|
|
96
|
+
offCallbacks.push(
|
|
97
|
+
sentinel2.on("reportEnd", ({ module: mod, outPayloads }) => {
|
|
98
|
+
if (mounted()) {
|
|
99
|
+
setProgress({
|
|
100
|
+
archivists: progress.archivists,
|
|
101
|
+
witnesses: progress.witnesses
|
|
102
|
+
});
|
|
103
|
+
setStatus(outPayloads?.length ? "succeeded" /* Succeeded */ : "failed" /* Failed */);
|
|
104
|
+
setReportingErrors([new Error(`Witness failed [${mod?.config?.name ?? mod.address}]`)]);
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
offCallbacks.push(
|
|
109
|
+
sentinel2.on("reportStart", () => {
|
|
110
|
+
if (mounted()) {
|
|
111
|
+
setProgress({ archivists: {}, witnesses: {} });
|
|
112
|
+
setStatus("started" /* Started */);
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
if (witnesses)
|
|
117
|
+
for (const witness of witnesses) {
|
|
118
|
+
offCallbacks.push(
|
|
119
|
+
witness.on("observeEnd", ({ module: mod, outPayloads }) => {
|
|
120
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
121
|
+
witnesses2[witness.address] = {
|
|
122
|
+
status: outPayloads?.length ? "succeeded" /* Succeeded */ : "failed" /* Failed */,
|
|
123
|
+
witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`)
|
|
124
|
+
};
|
|
125
|
+
if (mounted()) {
|
|
126
|
+
setProgress({
|
|
127
|
+
archivists: progress.archivists,
|
|
128
|
+
witnesses: witnesses2
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
offCallbacks.push(
|
|
134
|
+
witness.on("observeStart", ({ module: mod }) => {
|
|
135
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
136
|
+
witnesses2[witness.address] = {
|
|
137
|
+
status: "started" /* Started */,
|
|
138
|
+
witness: asWitnessInstance(mod, () => `Module is not a witness [${mod.id}]`)
|
|
139
|
+
};
|
|
140
|
+
if (mounted()) {
|
|
141
|
+
setProgress({
|
|
142
|
+
archivists: progress.archivists,
|
|
143
|
+
witnesses: witnesses2
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
setSentinel(sentinel2);
|
|
150
|
+
return () => {
|
|
151
|
+
for (const callback of offCallbacks) {
|
|
152
|
+
callback();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
157
|
+
[account, archivist, witnesses]
|
|
158
|
+
);
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
setHistory(sentinel?.history);
|
|
161
|
+
}, [sentinel]);
|
|
162
|
+
return !required || sentinel ? /* @__PURE__ */ jsx5(SentinelContext.Provider, { value: { history, progress, provided: true, reportingErrors, sentinel, status }, children }) : null;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/contexts/use.ts
|
|
166
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
167
|
+
var useSentinelContext = () => {
|
|
168
|
+
const { sentinel, history, progress, reportingErrors, status } = useContextEx(SentinelContext, "Sentinel");
|
|
169
|
+
return { history, progress, reportingErrors, sentinel, status };
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/hooks/node/useSentinelFromNode.tsx
|
|
173
|
+
import { useModuleFromNode } from "@xyo-network/react-node";
|
|
174
|
+
import { asSentinelInstance } from "@xyo-network/sentinel-model";
|
|
175
|
+
var useSentinelFromNode = (nameOrAddressOrInstance, config) => {
|
|
176
|
+
const [mod, error] = useModuleFromNode(nameOrAddressOrInstance, config);
|
|
177
|
+
const instance = asSentinelInstance(mod);
|
|
178
|
+
if (mod && !instance) {
|
|
179
|
+
const error2 = new Error(`Resolved module is not a SentinelInstance [${mod.config?.schema}:${mod.config?.name}:${mod.address}]`);
|
|
180
|
+
console.error(error2.message);
|
|
181
|
+
return [void 0, error2];
|
|
182
|
+
}
|
|
183
|
+
return [instance, error];
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/hooks/node/useSentinelsFromNode.tsx
|
|
187
|
+
import { useModulesFromNode } from "@xyo-network/react-node";
|
|
188
|
+
import { isSentinelInstance } from "@xyo-network/sentinel-model";
|
|
189
|
+
var useSentinelsFromNode = (filter, config) => {
|
|
190
|
+
const [modules, error] = useModulesFromNode(filter, config);
|
|
191
|
+
if (error) {
|
|
192
|
+
return [null, error];
|
|
193
|
+
}
|
|
194
|
+
return modules ? [
|
|
195
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
196
|
+
modules.reduce((prev, mod) => {
|
|
197
|
+
if (isSentinelInstance(mod)) {
|
|
198
|
+
prev.push(mod);
|
|
199
|
+
}
|
|
200
|
+
return prev;
|
|
201
|
+
}, []),
|
|
202
|
+
void 0
|
|
203
|
+
] : [modules, error];
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/hooks/node/useWeakSentinelFromNode.tsx
|
|
207
|
+
import { useWeakModuleFromNode } from "@xyo-network/react-node";
|
|
208
|
+
import { isSentinelInstance as isSentinelInstance2 } from "@xyo-network/sentinel-model";
|
|
209
|
+
var useWeakSentinelFromNode = (nameOrAddressOrInstance, config) => {
|
|
210
|
+
return useWeakModuleFromNode(nameOrAddressOrInstance, { identity: isSentinelInstance2, ...config });
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/hooks/node/useWeakSentinelsFromNode.tsx
|
|
214
|
+
import { exists } from "@xylabs/exists";
|
|
215
|
+
import { useWeakModulesFromNode } from "@xyo-network/react-node";
|
|
216
|
+
import { asSentinelInstance as asSentinelInstance2 } from "@xyo-network/sentinel-model";
|
|
217
|
+
var useWeakSentinelsFromNode = (filter, config) => {
|
|
218
|
+
const [modules, error] = useWeakModulesFromNode(filter, config);
|
|
219
|
+
if (error) {
|
|
220
|
+
return [null, error];
|
|
221
|
+
}
|
|
222
|
+
return [
|
|
223
|
+
modules?.map((mod) => {
|
|
224
|
+
const instance = asSentinelInstance2(mod?.deref());
|
|
225
|
+
if (instance) {
|
|
226
|
+
return new WeakRef(instance);
|
|
227
|
+
}
|
|
228
|
+
}).filter(exists) ?? [],
|
|
229
|
+
void 0
|
|
230
|
+
];
|
|
231
|
+
};
|
|
232
|
+
export {
|
|
233
|
+
SentinelCard,
|
|
234
|
+
SentinelCardContent,
|
|
235
|
+
SentinelCardHeader,
|
|
236
|
+
SentinelContext,
|
|
237
|
+
SentinelProvider,
|
|
238
|
+
SentinelReportStatus,
|
|
239
|
+
useSentinelContext,
|
|
240
|
+
useSentinelFromNode,
|
|
241
|
+
useSentinelsFromNode,
|
|
242
|
+
useWeakSentinelFromNode,
|
|
243
|
+
useWeakSentinelsFromNode
|
|
244
|
+
};
|
|
2
245
|
//# sourceMappingURL=index.js.map
|