@xyo-network/react-sentinel 2.64.0-rc.6 → 2.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/contexts/Context.cjs +28 -0
- package/dist/{node/contexts/Context.mjs.map → browser/contexts/Context.cjs.map} +1 -1
- package/dist/browser/contexts/Context.d.cts +4 -0
- package/dist/browser/contexts/Context.d.cts.map +1 -0
- package/dist/browser/contexts/Provider.cjs +124 -0
- package/dist/browser/contexts/Provider.cjs.map +1 -0
- package/dist/browser/contexts/Provider.d.cts +18 -0
- package/dist/browser/contexts/Provider.d.cts.map +1 -0
- package/dist/browser/contexts/State.cjs +34 -0
- package/dist/{node/contexts/State.mjs.map → browser/contexts/State.cjs.map} +1 -1
- package/dist/browser/contexts/State.d.cts +31 -0
- package/dist/browser/contexts/State.d.cts.map +1 -0
- package/dist/browser/contexts/index.cjs +146 -0
- package/dist/browser/contexts/index.cjs.map +1 -0
- package/dist/browser/contexts/index.d.cts +5 -0
- package/dist/browser/contexts/index.d.cts.map +1 -0
- package/dist/browser/contexts/use.cjs +37 -0
- package/dist/browser/contexts/use.cjs.map +1 -0
- package/dist/browser/contexts/use.d.cts +78 -0
- package/dist/browser/contexts/use.d.cts.map +1 -0
- package/dist/browser/hooks/index.cjs +64 -0
- package/dist/browser/hooks/index.cjs.map +1 -0
- package/dist/browser/hooks/index.d.cts +2 -0
- package/dist/browser/hooks/index.d.cts.map +1 -0
- package/dist/browser/hooks/node/index.cjs +64 -0
- package/dist/browser/hooks/node/index.cjs.map +1 -0
- package/dist/browser/hooks/node/index.d.cts +3 -0
- package/dist/browser/hooks/node/index.d.cts.map +1 -0
- package/dist/browser/hooks/node/useSentinelFromNode.cjs +38 -0
- package/dist/{node/hooks/node/useSentinelFromNode.mjs.map → browser/hooks/node/useSentinelFromNode.cjs.map} +1 -1
- package/dist/browser/hooks/node/useSentinelFromNode.d.cts +4 -0
- package/dist/browser/hooks/node/useSentinelFromNode.d.cts.map +1 -0
- package/dist/browser/hooks/node/useSentinelsFromNode.cjs +47 -0
- package/dist/{node/hooks/node/useSentinelsFromNode.mjs.map → browser/hooks/node/useSentinelsFromNode.cjs.map} +1 -1
- package/dist/browser/hooks/node/useSentinelsFromNode.d.cts +5 -0
- package/dist/browser/hooks/node/useSentinelsFromNode.d.cts.map +1 -0
- package/dist/browser/index.cjs +185 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +3 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/docs.json +2133 -0
- package/dist/node/contexts/Context.cjs +32 -0
- package/dist/node/contexts/Context.cjs.map +1 -0
- package/dist/node/contexts/Context.d.cts +4 -0
- package/dist/node/contexts/Context.d.cts.map +1 -0
- package/dist/node/contexts/Context.js +5 -28
- package/dist/node/contexts/Context.js.map +1 -1
- package/dist/node/contexts/Provider.cjs +129 -0
- package/dist/node/contexts/Provider.cjs.map +1 -0
- package/dist/node/contexts/Provider.d.cts +18 -0
- package/dist/node/contexts/Provider.d.cts.map +1 -0
- package/dist/node/contexts/Provider.js +40 -58
- package/dist/node/contexts/Provider.js.map +1 -1
- package/dist/node/contexts/State.cjs +38 -0
- package/dist/node/contexts/State.cjs.map +1 -0
- package/dist/node/contexts/State.d.cts +31 -0
- package/dist/node/contexts/State.d.cts.map +1 -0
- package/dist/node/contexts/State.js +3 -26
- package/dist/node/contexts/State.js.map +1 -1
- package/dist/node/contexts/index.cjs +154 -0
- package/dist/node/contexts/index.cjs.map +1 -0
- package/dist/node/contexts/index.d.cts +5 -0
- package/dist/node/contexts/index.d.cts.map +1 -0
- package/dist/node/contexts/index.js +122 -27
- package/dist/node/contexts/index.js.map +1 -1
- package/dist/node/contexts/use.cjs +41 -0
- package/dist/node/contexts/use.cjs.map +1 -0
- package/dist/node/contexts/use.d.cts +78 -0
- package/dist/node/contexts/use.d.cts.map +1 -0
- package/dist/node/contexts/use.js +12 -30
- package/dist/node/contexts/use.js.map +1 -1
- package/dist/node/hooks/index.cjs +70 -0
- package/dist/node/hooks/index.cjs.map +1 -0
- package/dist/node/hooks/index.d.cts +2 -0
- package/dist/node/hooks/index.d.cts.map +1 -0
- package/dist/node/hooks/index.js +39 -20
- package/dist/node/hooks/index.js.map +1 -1
- package/dist/node/hooks/node/index.cjs +70 -0
- package/dist/node/hooks/node/index.cjs.map +1 -0
- package/dist/node/hooks/node/index.d.cts +3 -0
- package/dist/node/hooks/node/index.d.cts.map +1 -0
- package/dist/node/hooks/node/index.js +39 -22
- package/dist/node/hooks/node/index.js.map +1 -1
- package/dist/node/hooks/node/useSentinelFromNode.cjs +43 -0
- package/dist/node/hooks/node/useSentinelFromNode.cjs.map +1 -0
- package/dist/node/hooks/node/useSentinelFromNode.d.cts +4 -0
- package/dist/node/hooks/node/useSentinelFromNode.d.cts.map +1 -0
- package/dist/node/hooks/node/useSentinelFromNode.js +11 -33
- package/dist/node/hooks/node/useSentinelFromNode.js.map +1 -1
- package/dist/node/hooks/node/useSentinelsFromNode.cjs +51 -0
- package/dist/node/hooks/node/useSentinelsFromNode.cjs.map +1 -0
- package/dist/node/hooks/node/useSentinelsFromNode.d.cts +5 -0
- package/dist/node/hooks/node/useSentinelsFromNode.d.cts.map +1 -0
- package/dist/node/hooks/node/useSentinelsFromNode.js +10 -33
- package/dist/node/hooks/node/useSentinelsFromNode.js.map +1 -1
- package/dist/node/index.cjs +196 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +3 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +161 -22
- package/dist/node/index.js.map +1 -1
- package/package.json +24 -24
- package/dist/node/contexts/Context.mjs +0 -6
- package/dist/node/contexts/Provider.mjs +0 -98
- package/dist/node/contexts/Provider.mjs.map +0 -1
- package/dist/node/contexts/State.mjs +0 -12
- package/dist/node/contexts/index.mjs +0 -5
- package/dist/node/contexts/index.mjs.map +0 -1
- package/dist/node/contexts/use.mjs +0 -10
- package/dist/node/contexts/use.mjs.map +0 -1
- package/dist/node/hooks/index.mjs +0 -2
- package/dist/node/hooks/index.mjs.map +0 -1
- package/dist/node/hooks/node/index.mjs +0 -3
- package/dist/node/hooks/node/index.mjs.map +0 -1
- package/dist/node/hooks/node/useSentinelFromNode.mjs +0 -16
- package/dist/node/hooks/node/useSentinelsFromNode.mjs +0 -25
- package/dist/node/index.mjs +0 -3
- package/dist/node/index.mjs.map +0 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/contexts/index.ts
|
|
21
|
+
var contexts_exports = {};
|
|
22
|
+
__export(contexts_exports, {
|
|
23
|
+
SentinelContext: () => SentinelContext,
|
|
24
|
+
SentinelProvider: () => SentinelProvider,
|
|
25
|
+
SentinelReportStatus: () => SentinelReportStatus,
|
|
26
|
+
useSentinelContext: () => useSentinelContext
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(contexts_exports);
|
|
29
|
+
|
|
30
|
+
// src/contexts/Context.ts
|
|
31
|
+
var import_react_shared = require("@xyo-network/react-shared");
|
|
32
|
+
var SentinelContext = (0, import_react_shared.createContextEx)();
|
|
33
|
+
|
|
34
|
+
// src/contexts/Provider.tsx
|
|
35
|
+
var import_react_async_effect = require("@xylabs/react-async-effect");
|
|
36
|
+
var import_react_witness = require("@xyo-network/react-witness");
|
|
37
|
+
var import_sentinel = require("@xyo-network/sentinel");
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
|
|
40
|
+
// src/contexts/State.ts
|
|
41
|
+
var SentinelReportStatus = /* @__PURE__ */ ((SentinelReportStatus2) => {
|
|
42
|
+
SentinelReportStatus2["Idle"] = "idle";
|
|
43
|
+
SentinelReportStatus2["Queued"] = "queued";
|
|
44
|
+
SentinelReportStatus2["Started"] = "started";
|
|
45
|
+
SentinelReportStatus2["Succeeded"] = "succeeded";
|
|
46
|
+
SentinelReportStatus2["Failed"] = "failed";
|
|
47
|
+
return SentinelReportStatus2;
|
|
48
|
+
})(SentinelReportStatus || {});
|
|
49
|
+
|
|
50
|
+
// src/contexts/Provider.tsx
|
|
51
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
52
|
+
var SentinelProvider = ({ account, archivist, children, filter, name, required = false }) => {
|
|
53
|
+
const [sentinel, setSentinel] = (0, import_react.useState)();
|
|
54
|
+
const [history, setHistory] = (0, import_react.useState)();
|
|
55
|
+
const [progress, setProgress] = (0, import_react.useState)({});
|
|
56
|
+
const [status, setStatus] = (0, import_react.useState)("idle" /* Idle */);
|
|
57
|
+
const [reportingErrors, setReportingErrors] = (0, import_react.useState)();
|
|
58
|
+
const [witnesses] = (0, import_react_witness.useWitnessesFromNode)(filter);
|
|
59
|
+
(0, import_react_async_effect.useAsyncEffect)(
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
async (mounted) => {
|
|
62
|
+
const sentinel2 = await import_sentinel.MemorySentinel.create({
|
|
63
|
+
account,
|
|
64
|
+
config: {
|
|
65
|
+
archivists: archivist ? [archivist] : void 0,
|
|
66
|
+
name,
|
|
67
|
+
schema: import_sentinel.SentinelConfigSchema,
|
|
68
|
+
witnesses: witnesses == null ? void 0 : witnesses.map((module2) => module2.address)
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const offCallbacks = [];
|
|
72
|
+
offCallbacks.push(
|
|
73
|
+
sentinel2.on("reportEnd", ({ module: module2, outPayloads }) => {
|
|
74
|
+
var _a;
|
|
75
|
+
if (mounted()) {
|
|
76
|
+
setProgress({
|
|
77
|
+
archivists: progress.archivists,
|
|
78
|
+
witnesses: progress.witnesses
|
|
79
|
+
});
|
|
80
|
+
setStatus((outPayloads == null ? void 0 : outPayloads.length) ? "succeeded" /* Succeeded */ : "failed" /* Failed */);
|
|
81
|
+
setReportingErrors([Error(`Witness failed [${((_a = module2 == null ? void 0 : module2.config) == null ? void 0 : _a.name) ?? module2.address}]`)]);
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
offCallbacks.push(
|
|
86
|
+
sentinel2.on("reportStart", () => {
|
|
87
|
+
if (mounted()) {
|
|
88
|
+
setProgress({ archivists: {}, witnesses: {} });
|
|
89
|
+
setStatus("started" /* Started */);
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
witnesses == null ? void 0 : witnesses.forEach((witness) => {
|
|
94
|
+
offCallbacks.push(
|
|
95
|
+
witness.on("observeEnd", ({ module: module2, outPayloads }) => {
|
|
96
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
97
|
+
witnesses2[witness.address] = {
|
|
98
|
+
status: (outPayloads == null ? void 0 : outPayloads.length) ? "succeeded" /* Succeeded */ : "failed" /* Failed */,
|
|
99
|
+
witness: module2
|
|
100
|
+
};
|
|
101
|
+
if (mounted()) {
|
|
102
|
+
setProgress({
|
|
103
|
+
archivists: progress.archivists,
|
|
104
|
+
witnesses: witnesses2
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
offCallbacks.push(
|
|
110
|
+
witness.on("observeStart", ({ module: module2 }) => {
|
|
111
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
112
|
+
witnesses2[witness.address] = {
|
|
113
|
+
status: "started" /* Started */,
|
|
114
|
+
witness: module2
|
|
115
|
+
};
|
|
116
|
+
if (mounted()) {
|
|
117
|
+
setProgress({
|
|
118
|
+
archivists: progress.archivists,
|
|
119
|
+
witnesses: witnesses2
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
setSentinel(sentinel2);
|
|
126
|
+
return () => {
|
|
127
|
+
offCallbacks.forEach((callback) => {
|
|
128
|
+
callback();
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
133
|
+
[account, archivist, witnesses]
|
|
134
|
+
);
|
|
135
|
+
(0, import_react.useEffect)(() => {
|
|
136
|
+
setHistory(sentinel == null ? void 0 : sentinel.history);
|
|
137
|
+
}, [sentinel]);
|
|
138
|
+
return !required || sentinel ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SentinelContext.Provider, { value: { history, progress, provided: true, reportingErrors, sentinel, status }, children }) : null;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// src/contexts/use.ts
|
|
142
|
+
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
143
|
+
var useSentinelContext = () => {
|
|
144
|
+
const { sentinel, history, progress, reportingErrors, status } = (0, import_react_shared2.useContextEx)(SentinelContext, "Sentinel");
|
|
145
|
+
return { history, progress, reportingErrors, sentinel, status };
|
|
146
|
+
};
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
SentinelContext,
|
|
150
|
+
SentinelProvider,
|
|
151
|
+
SentinelReportStatus,
|
|
152
|
+
useSentinelContext
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/contexts/index.ts","../../../src/contexts/Context.ts","../../../src/contexts/Provider.tsx","../../../src/contexts/State.ts","../../../src/contexts/use.ts"],"sourcesContent":["export * from './Context'\nexport * from './Provider'\nexport * from './State'\nexport * from './use'\n","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n","import { 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'\nimport { useWitnessesFromNode } from '@xyo-network/react-witness'\nimport { MemorySentinel, SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel'\nimport { WitnessInstance } from '@xyo-network/witness'\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 witnesses: witnesses?.map((module) => module.address),\n } as SentinelConfig,\n })\n const offCallbacks: (() => void)[] = []\n offCallbacks.push(\n sentinel.on('reportEnd', ({ module, 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([Error(`Witness failed [${module?.config?.name ?? module.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 witnesses?.forEach((witness) => {\n offCallbacks.push(\n witness.on('observeEnd', ({ module, outPayloads }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed,\n witness: module,\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n offCallbacks.push(\n witness.on('observeStart', ({ module }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: SentinelReportStatus.Started,\n witness: module,\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 offCallbacks.forEach((callback) => {\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'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { SentinelModule } from '@xyo-network/sentinel'\nimport { WitnessModule } from '@xyo-network/witness'\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,0BAAgC;AAIzB,IAAM,sBAAkB,qCAAsC;;;ACJrE,gCAA+B;AAK/B,2BAAqC;AACrC,sBAAqE;AAErE,mBAAoC;;;ACH7B,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,YAAS;AACT,EAAAA,sBAAA,aAAU;AACV,EAAAA,sBAAA,eAAY;AACZ,EAAAA,sBAAA,YAAS;AALC,SAAAA;AAAA,GAAA;;;AD+GR;AA3FG,IAAM,mBAAkE,CAAC,EAAE,SAAS,WAAW,UAAU,QAAQ,MAAM,WAAW,MAAM,MAAM;AACnJ,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAyB;AACzD,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAyB;AACvD,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAiC,CAAC,CAAC;AACnE,QAAM,CAAC,QAAQ,SAAS,QAAI,wC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BAAY;AAAA,gBACV,YAAY,SAAS;AAAA,gBACrB,WAAAC;AAAA,cACF,CAAC;AAAA,YACH;AAAA,UACF,CAAC;AAAA,QACH;AACA,qBAAa;AAAA,UACX,QAAQ,GAAG,gBAAgB,CAAC,EAAE,QAAAD,QAAO,MAAM;AACzC,kBAAMC,aAAY,SAAS,aAAa,CAAC;AACzC,YAAAA,WAAU,QAAQ,OAAO,IAAI;AAAA,cAC3B;AAAA,cACA,SAASD;AAAA,YACX;AACA,gBAAI,QAAQ,GAAG;AACb,0BAAY;AAAA,gBACV,YAAY,SAAS;AAAA,gBACrB,WAAAC;AAAA,cACF,CAAC;AAAA,YACH;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AACA,kBAAYF,SAA0B;AACtC,aAAO,MAAM;AAEX,qBAAa,QAAQ,CAAC,aAAa;AACjC,mBAAS;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA;AAAA,IAEA,CAAC,SAAS,WAAW,SAAS;AAAA,EAChC;AAEA,8BAAU,MAAM;AACd,eAAW,qCAAU,OAAyB;AAAA,EAChD,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO,CAAC,YAAY,WAClB,4CAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,SAAS,UAAU,UAAU,MAAM,iBAAiB,UAAU,OAAO,GAAI,UAAS,IACnH;AACN;;;AEtHA,IAAAG,uBAA6B;AAItB,IAAM,qBAAqB,MAAM;AACtC,QAAM,EAAE,UAAU,SAAS,UAAU,iBAAiB,OAAO,QAAI,mCAAa,iBAAiB,UAAU;AACzG,SAAO,EAAE,SAAS,UAAU,iBAAiB,UAAU,OAAO;AAChE;","names":["SentinelReportStatus","sentinel","module","witnesses","import_react_shared"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contexts/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA"}
|
|
@@ -1,29 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
// src/contexts/Context.ts
|
|
2
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
3
|
+
var SentinelContext = createContextEx();
|
|
4
|
+
|
|
5
|
+
// src/contexts/Provider.tsx
|
|
6
|
+
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
7
|
+
import { useWitnessesFromNode } from "@xyo-network/react-witness";
|
|
8
|
+
import { MemorySentinel, SentinelConfigSchema } from "@xyo-network/sentinel";
|
|
9
|
+
import { useEffect, useState } from "react";
|
|
10
|
+
|
|
11
|
+
// src/contexts/State.ts
|
|
12
|
+
var SentinelReportStatus = /* @__PURE__ */ ((SentinelReportStatus2) => {
|
|
13
|
+
SentinelReportStatus2["Idle"] = "idle";
|
|
14
|
+
SentinelReportStatus2["Queued"] = "queued";
|
|
15
|
+
SentinelReportStatus2["Started"] = "started";
|
|
16
|
+
SentinelReportStatus2["Succeeded"] = "succeeded";
|
|
17
|
+
SentinelReportStatus2["Failed"] = "failed";
|
|
18
|
+
return SentinelReportStatus2;
|
|
19
|
+
})(SentinelReportStatus || {});
|
|
20
|
+
|
|
21
|
+
// src/contexts/Provider.tsx
|
|
22
|
+
import { jsx } from "react/jsx-runtime";
|
|
23
|
+
var SentinelProvider = ({ account, archivist, children, filter, name, required = false }) => {
|
|
24
|
+
const [sentinel, setSentinel] = useState();
|
|
25
|
+
const [history, setHistory] = useState();
|
|
26
|
+
const [progress, setProgress] = useState({});
|
|
27
|
+
const [status, setStatus] = useState("idle" /* Idle */);
|
|
28
|
+
const [reportingErrors, setReportingErrors] = useState();
|
|
29
|
+
const [witnesses] = useWitnessesFromNode(filter);
|
|
30
|
+
useAsyncEffect(
|
|
31
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
+
async (mounted) => {
|
|
33
|
+
const sentinel2 = await MemorySentinel.create({
|
|
34
|
+
account,
|
|
35
|
+
config: {
|
|
36
|
+
archivists: archivist ? [archivist] : void 0,
|
|
37
|
+
name,
|
|
38
|
+
schema: SentinelConfigSchema,
|
|
39
|
+
witnesses: witnesses == null ? void 0 : witnesses.map((module) => module.address)
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const offCallbacks = [];
|
|
43
|
+
offCallbacks.push(
|
|
44
|
+
sentinel2.on("reportEnd", ({ module, outPayloads }) => {
|
|
45
|
+
var _a;
|
|
46
|
+
if (mounted()) {
|
|
47
|
+
setProgress({
|
|
48
|
+
archivists: progress.archivists,
|
|
49
|
+
witnesses: progress.witnesses
|
|
50
|
+
});
|
|
51
|
+
setStatus((outPayloads == null ? void 0 : outPayloads.length) ? "succeeded" /* Succeeded */ : "failed" /* Failed */);
|
|
52
|
+
setReportingErrors([Error(`Witness failed [${((_a = module == null ? void 0 : module.config) == null ? void 0 : _a.name) ?? module.address}]`)]);
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
offCallbacks.push(
|
|
57
|
+
sentinel2.on("reportStart", () => {
|
|
58
|
+
if (mounted()) {
|
|
59
|
+
setProgress({ archivists: {}, witnesses: {} });
|
|
60
|
+
setStatus("started" /* Started */);
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
witnesses == null ? void 0 : witnesses.forEach((witness) => {
|
|
65
|
+
offCallbacks.push(
|
|
66
|
+
witness.on("observeEnd", ({ module, outPayloads }) => {
|
|
67
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
68
|
+
witnesses2[witness.address] = {
|
|
69
|
+
status: (outPayloads == null ? void 0 : outPayloads.length) ? "succeeded" /* Succeeded */ : "failed" /* Failed */,
|
|
70
|
+
witness: module
|
|
71
|
+
};
|
|
72
|
+
if (mounted()) {
|
|
73
|
+
setProgress({
|
|
74
|
+
archivists: progress.archivists,
|
|
75
|
+
witnesses: witnesses2
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
offCallbacks.push(
|
|
81
|
+
witness.on("observeStart", ({ module }) => {
|
|
82
|
+
const witnesses2 = progress.witnesses ?? {};
|
|
83
|
+
witnesses2[witness.address] = {
|
|
84
|
+
status: "started" /* Started */,
|
|
85
|
+
witness: module
|
|
86
|
+
};
|
|
87
|
+
if (mounted()) {
|
|
88
|
+
setProgress({
|
|
89
|
+
archivists: progress.archivists,
|
|
90
|
+
witnesses: witnesses2
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
setSentinel(sentinel2);
|
|
97
|
+
return () => {
|
|
98
|
+
offCallbacks.forEach((callback) => {
|
|
99
|
+
callback();
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
104
|
+
[account, archivist, witnesses]
|
|
105
|
+
);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
setHistory(sentinel == null ? void 0 : sentinel.history);
|
|
108
|
+
}, [sentinel]);
|
|
109
|
+
return !required || sentinel ? /* @__PURE__ */ jsx(SentinelContext.Provider, { value: { history, progress, provided: true, reportingErrors, sentinel, status }, children }) : null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/contexts/use.ts
|
|
113
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
114
|
+
var useSentinelContext = () => {
|
|
115
|
+
const { sentinel, history, progress, reportingErrors, status } = useContextEx(SentinelContext, "Sentinel");
|
|
116
|
+
return { history, progress, reportingErrors, sentinel, status };
|
|
117
|
+
};
|
|
118
|
+
export {
|
|
119
|
+
SentinelContext,
|
|
120
|
+
SentinelProvider,
|
|
121
|
+
SentinelReportStatus,
|
|
122
|
+
useSentinelContext
|
|
13
123
|
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var contexts_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(contexts_exports);
|
|
18
|
-
__reExport(contexts_exports, require("./Context"), module.exports);
|
|
19
|
-
__reExport(contexts_exports, require("./Provider"), module.exports);
|
|
20
|
-
__reExport(contexts_exports, require("./State"), module.exports);
|
|
21
|
-
__reExport(contexts_exports, require("./use"), module.exports);
|
|
22
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
23
|
-
0 && (module.exports = {
|
|
24
|
-
...require("./Context"),
|
|
25
|
-
...require("./Provider"),
|
|
26
|
-
...require("./State"),
|
|
27
|
-
...require("./use")
|
|
28
|
-
});
|
|
29
124
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/contexts/
|
|
1
|
+
{"version":3,"sources":["../../../src/contexts/Context.ts","../../../src/contexts/Provider.tsx","../../../src/contexts/State.ts","../../../src/contexts/use.ts"],"sourcesContent":["import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n","import { 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'\nimport { useWitnessesFromNode } from '@xyo-network/react-witness'\nimport { MemorySentinel, SentinelConfig, SentinelConfigSchema } from '@xyo-network/sentinel'\nimport { WitnessInstance } from '@xyo-network/witness'\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 witnesses: witnesses?.map((module) => module.address),\n } as SentinelConfig,\n })\n const offCallbacks: (() => void)[] = []\n offCallbacks.push(\n sentinel.on('reportEnd', ({ module, 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([Error(`Witness failed [${module?.config?.name ?? module.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 witnesses?.forEach((witness) => {\n offCallbacks.push(\n witness.on('observeEnd', ({ module, outPayloads }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: outPayloads?.length ? SentinelReportStatus.Succeeded : SentinelReportStatus.Failed,\n witness: module,\n }\n if (mounted()) {\n setProgress({\n archivists: progress.archivists,\n witnesses,\n })\n }\n }),\n )\n offCallbacks.push(\n witness.on('observeStart', ({ module }) => {\n const witnesses = progress.witnesses ?? {}\n witnesses[witness.address] = {\n status: SentinelReportStatus.Started,\n witness: module,\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 offCallbacks.forEach((callback) => {\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'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { SentinelModule } from '@xyo-network/sentinel'\nimport { WitnessModule } from '@xyo-network/witness'\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"],"mappings":";AAAA,SAAS,uBAAuB;AAIzB,IAAM,kBAAkB,gBAAsC;;;ACJrE,SAAS,sBAAsB;A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BAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,SAAS,UAAU,UAAU,MAAM,iBAAiB,UAAU,OAAO,GAAI,UAAS,IACnH;AACN;;;AEtHA,SAAS,oBAAoB;AAItB,IAAM,qBAAqB,MAAM;AACtC,QAAM,EAAE,UAAU,SAAS,UAAU,iBAAiB,OAAO,IAAI,aAAa,iBAAiB,UAAU;AACzG,SAAO,EAAE,SAAS,UAAU,iBAAiB,UAAU,OAAO;AAChE;","names":["SentinelReportStatus","sentinel","witnesses"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/contexts/use.ts
|
|
21
|
+
var use_exports = {};
|
|
22
|
+
__export(use_exports, {
|
|
23
|
+
useSentinelContext: () => useSentinelContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(use_exports);
|
|
26
|
+
var import_react_shared2 = require("@xyo-network/react-shared");
|
|
27
|
+
|
|
28
|
+
// src/contexts/Context.ts
|
|
29
|
+
var import_react_shared = require("@xyo-network/react-shared");
|
|
30
|
+
var SentinelContext = (0, import_react_shared.createContextEx)();
|
|
31
|
+
|
|
32
|
+
// src/contexts/use.ts
|
|
33
|
+
var useSentinelContext = () => {
|
|
34
|
+
const { sentinel, history, progress, reportingErrors, status } = (0, import_react_shared2.useContextEx)(SentinelContext, "Sentinel");
|
|
35
|
+
return { history, progress, reportingErrors, sentinel, status };
|
|
36
|
+
};
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
useSentinelContext
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=use.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/contexts/use.ts","../../../src/contexts/Context.ts"],"sourcesContent":["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","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,uBAA6B;;;ACA7B,0BAAgC;AAIzB,IAAM,sBAAkB,qCAAsC;;;ADA9D,IAAM,qBAAqB,MAAM;AACtC,QAAM,EAAE,UAAU,SAAS,UAAU,iBAAiB,OAAO,QAAI,mCAAa,iBAAiB,UAAU;AACzG,SAAO,EAAE,SAAS,UAAU,iBAAiB,UAAU,OAAO;AAChE;","names":["import_react_shared"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare const useSentinelContext: () => {
|
|
2
|
+
history: (import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & import("@xyo-network/boundwitness-model").BoundWitnessFields & {
|
|
3
|
+
schema: "network.xyo.boundwitness";
|
|
4
|
+
})[] | undefined;
|
|
5
|
+
progress: import("./State").SentinelReportProgress | undefined;
|
|
6
|
+
reportingErrors: Error[] | undefined;
|
|
7
|
+
sentinel: import("@xyo-network/sentinel-model").SentinelModule<import("@xyo-network/core").BaseParamsFields & {
|
|
8
|
+
account?: import("@xyo-network/account-model").AccountInstance | "random" | undefined;
|
|
9
|
+
config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<{
|
|
10
|
+
accountDerivationPath?: string | undefined;
|
|
11
|
+
readonly archivist?: import("@xyo-network/module-model").ArchivistModuleConfig | undefined;
|
|
12
|
+
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
13
|
+
readonly name?: string | undefined;
|
|
14
|
+
readonly paging?: Record<string, {
|
|
15
|
+
size?: number | undefined;
|
|
16
|
+
}> | undefined;
|
|
17
|
+
readonly security?: {
|
|
18
|
+
readonly allowAnonymous?: boolean | undefined;
|
|
19
|
+
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
20
|
+
readonly disallowed?: Record<string, string[]> | undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
readonly sign?: boolean | undefined;
|
|
23
|
+
readonly storeQueries?: boolean | undefined;
|
|
24
|
+
readonly timestamp?: boolean | undefined;
|
|
25
|
+
} & Omit<import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<{
|
|
26
|
+
accountDerivationPath?: string | undefined;
|
|
27
|
+
readonly archivist?: import("@xyo-network/module-model").ArchivistModuleConfig | undefined;
|
|
28
|
+
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
29
|
+
readonly name?: string | undefined;
|
|
30
|
+
readonly paging?: Record<string, {
|
|
31
|
+
size?: number | undefined;
|
|
32
|
+
}> | undefined;
|
|
33
|
+
readonly security?: {
|
|
34
|
+
readonly allowAnonymous?: boolean | undefined;
|
|
35
|
+
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
36
|
+
readonly disallowed?: Record<string, string[]> | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
readonly sign?: boolean | undefined;
|
|
39
|
+
readonly storeQueries?: boolean | undefined;
|
|
40
|
+
readonly timestamp?: boolean | undefined;
|
|
41
|
+
} & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<{
|
|
42
|
+
accountDerivationPath?: string | undefined;
|
|
43
|
+
readonly archivist?: import("@xyo-network/module-model").ArchivistModuleConfig | undefined;
|
|
44
|
+
readonly labels?: import("@xyo-network/module-model").Labels | undefined;
|
|
45
|
+
readonly name?: string | undefined;
|
|
46
|
+
readonly paging?: Record<string, {
|
|
47
|
+
size?: number | undefined;
|
|
48
|
+
}> | undefined;
|
|
49
|
+
readonly security?: {
|
|
50
|
+
readonly allowAnonymous?: boolean | undefined;
|
|
51
|
+
readonly allowed?: Record<string, (string | import("@xyo-network/module-model").CosigningAddressSet)[]> | undefined;
|
|
52
|
+
readonly disallowed?: Record<string, string[]> | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
readonly sign?: boolean | undefined;
|
|
55
|
+
readonly storeQueries?: boolean | undefined;
|
|
56
|
+
readonly timestamp?: boolean | undefined;
|
|
57
|
+
} & {
|
|
58
|
+
archivists?: string[] | undefined;
|
|
59
|
+
schema: string;
|
|
60
|
+
} & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
|
|
61
|
+
schema: "network.xyo.module.config";
|
|
62
|
+
}, "schema"> & {
|
|
63
|
+
schema: "network.xyo.module.config";
|
|
64
|
+
} & {
|
|
65
|
+
witnesses?: string[] | undefined;
|
|
66
|
+
}, "schema"> & {
|
|
67
|
+
schema: "network.xyo.sentinel.config";
|
|
68
|
+
}, "schema"> & {
|
|
69
|
+
schema: string;
|
|
70
|
+
}, "schema"> & {
|
|
71
|
+
schema: string;
|
|
72
|
+
};
|
|
73
|
+
ephemeralQueryAccountEnabled?: boolean | undefined;
|
|
74
|
+
wallet?: import("@xyo-network/wallet-model").WalletInstance | undefined;
|
|
75
|
+
}> | undefined;
|
|
76
|
+
status: import("./State").SentinelReportStatus | undefined;
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=use.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use.d.ts","sourceRoot":"","sources":["../../../src/contexts/use.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAG9B,CAAA"}
|
|
@@ -1,34 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
var use_exports = {};
|
|
20
|
-
__export(use_exports, {
|
|
21
|
-
useSentinelContext: () => useSentinelContext
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(use_exports);
|
|
24
|
-
var import_react_shared = require("@xyo-network/react-shared");
|
|
25
|
-
var import_Context = require("./Context");
|
|
26
|
-
const useSentinelContext = () => {
|
|
27
|
-
const { sentinel, history, progress, reportingErrors, status } = (0, import_react_shared.useContextEx)(import_Context.SentinelContext, "Sentinel");
|
|
1
|
+
// src/contexts/use.ts
|
|
2
|
+
import { useContextEx } from "@xyo-network/react-shared";
|
|
3
|
+
|
|
4
|
+
// src/contexts/Context.ts
|
|
5
|
+
import { createContextEx } from "@xyo-network/react-shared";
|
|
6
|
+
var SentinelContext = createContextEx();
|
|
7
|
+
|
|
8
|
+
// src/contexts/use.ts
|
|
9
|
+
var useSentinelContext = () => {
|
|
10
|
+
const { sentinel, history, progress, reportingErrors, status } = useContextEx(SentinelContext, "Sentinel");
|
|
28
11
|
return { history, progress, reportingErrors, sentinel, status };
|
|
29
12
|
};
|
|
30
|
-
|
|
31
|
-
0 && (module.exports = {
|
|
13
|
+
export {
|
|
32
14
|
useSentinelContext
|
|
33
|
-
}
|
|
15
|
+
};
|
|
34
16
|
//# sourceMappingURL=use.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/contexts/use.ts"],"sourcesContent":["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"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/contexts/use.ts","../../../src/contexts/Context.ts"],"sourcesContent":["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","import { createContextEx } from '@xyo-network/react-shared'\n\nimport { SentinelContextState } from './State'\n\nexport const SentinelContext = createContextEx<SentinelContextState>()\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,uBAAuB;AAIzB,IAAM,kBAAkB,gBAAsC;;;ADA9D,IAAM,qBAAqB,MAAM;AACtC,QAAM,EAAE,UAAU,SAAS,UAAU,iBAAiB,OAAO,IAAI,aAAa,iBAAiB,UAAU;AACzG,SAAO,EAAE,SAAS,UAAU,iBAAiB,UAAU,OAAO;AAChE;","names":[]}
|
|
@@ -0,0 +1,70 @@
|
|
|
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/hooks/index.ts
|
|
21
|
+
var hooks_exports = {};
|
|
22
|
+
__export(hooks_exports, {
|
|
23
|
+
useSentinelFromNode: () => useSentinelFromNode,
|
|
24
|
+
useSentinelsFromNode: () => useSentinelsFromNode
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
27
|
+
|
|
28
|
+
// src/hooks/node/useSentinelFromNode.tsx
|
|
29
|
+
var import_react_node = require("@xyo-network/react-node");
|
|
30
|
+
var import_sentinel = require("@xyo-network/sentinel");
|
|
31
|
+
var useSentinelFromNode = (nameOrAddressOrInstance, config) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const [module2, error] = (0, import_react_node.useModuleFromNode)(nameOrAddressOrInstance, config);
|
|
34
|
+
const instance = (0, import_sentinel.asSentinelInstance)(module2);
|
|
35
|
+
if (module2 && !instance) {
|
|
36
|
+
const error2 = Error(`Resolved module is not a SentinelInstance [${(_a = module2.config) == null ? void 0 : _a.schema}:${(_b = module2.config) == null ? void 0 : _b.name}:${module2.address}]`);
|
|
37
|
+
console.error(error2.message);
|
|
38
|
+
return [void 0, error2];
|
|
39
|
+
}
|
|
40
|
+
return [instance, error];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/hooks/node/useSentinelsFromNode.tsx
|
|
44
|
+
var import_react_node2 = require("@xyo-network/react-node");
|
|
45
|
+
var import_sentinel2 = require("@xyo-network/sentinel");
|
|
46
|
+
var useSentinelsFromNode = (filter, config) => {
|
|
47
|
+
const [modules, error] = (0, import_react_node2.useModulesFromNode)(filter, config);
|
|
48
|
+
if (error) {
|
|
49
|
+
return [null, error];
|
|
50
|
+
}
|
|
51
|
+
if (modules) {
|
|
52
|
+
return [
|
|
53
|
+
modules.reduce((prev, module2) => {
|
|
54
|
+
if ((0, import_sentinel2.isSentinelInstance)(module2)) {
|
|
55
|
+
prev.push(module2);
|
|
56
|
+
}
|
|
57
|
+
return prev;
|
|
58
|
+
}, []),
|
|
59
|
+
void 0
|
|
60
|
+
];
|
|
61
|
+
} else {
|
|
62
|
+
return [modules, error];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
useSentinelFromNode,
|
|
68
|
+
useSentinelsFromNode
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/index.ts","../../../src/hooks/node/useSentinelFromNode.tsx","../../../src/hooks/node/useSentinelsFromNode.tsx"],"sourcesContent":["export * from './node'\n","import { ModuleFromNodeConfig, useModuleFromNode } from '@xyo-network/react-node'\nimport { asSentinelInstance, SentinelInstance } from '@xyo-network/sentinel'\n\nexport const useSentinelFromNode = (\n nameOrAddressOrInstance?: string | SentinelInstance,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance | undefined, Error | undefined] => {\n const [module, error] = useModuleFromNode(nameOrAddressOrInstance, config)\n const instance = asSentinelInstance(module)\n if (module && !instance) {\n const error = Error(`Resolved module is not a SentinelInstance [${module.config?.schema}:${module.config?.name}:${module.address}]`)\n console.error(error.message)\n return [undefined, error]\n }\n return [instance, error]\n}\n","import { ModuleFilter } from '@xyo-network/module-model'\nimport { ModuleFromNodeConfig, useModulesFromNode } from '@xyo-network/react-node'\nimport { isSentinelInstance, SentinelInstance } from '@xyo-network/sentinel'\n\nexport const useSentinelsFromNode = (\n filter?: ModuleFilter,\n config?: ModuleFromNodeConfig,\n): [SentinelInstance[] | null | undefined, Error | undefined] => {\n const [modules, error] = useModulesFromNode(filter, config)\n if (error) {\n return [null, error]\n }\n if (modules) {\n return [\n modules.reduce<SentinelInstance[]>((prev, module) => {\n if (isSentinelInstance(module)) {\n prev.push(module)\n }\n return prev\n }, []),\n undefined,\n ]\n } else {\n return [modules, error]\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,wBAAwD;AACxD,sBAAqD;AAE9C,IAAM,sBAAsB,CACjC,yBACA,WACsD;AANxD;AAOE,QAAM,CAACA,SAAQ,KAAK,QAAI,qCAAkB,yBAAyB,MAAM;AACzE,QAAM,eAAW,oCAAmBA,OAAM;AAC1C,MAAIA,WAAU,CAAC,UAAU;AACvB,UAAMC,SAAQ,MAAM,+CAA8C,KAAAD,QAAO,WAAP,mBAAe,MAAM,KAAI,KAAAA,QAAO,WAAP,mBAAe,IAAI,IAAIA,QAAO,OAAO,GAAG;AACnI,YAAQ,MAAMC,OAAM,OAAO;AAC3B,WAAO,CAAC,QAAWA,MAAK;AAAA,EAC1B;AACA,SAAO,CAAC,UAAU,KAAK;AACzB;;;ACdA,IAAAC,qBAAyD;AACzD,IAAAC,mBAAqD;AAE9C,IAAM,uBAAuB,CAClC,QACA,WAC+D;AAC/D,QAAM,CAAC,SAAS,KAAK,QAAI,uCAAmB,QAAQ,MAAM;AAC1D,MAAI,OAAO;AACT,WAAO,CAAC,MAAM,KAAK;AAAA,EACrB;AACA,MAAI,SAAS;AACX,WAAO;AAAA,MACL,QAAQ,OAA2B,CAAC,MAAMC,YAAW;AACnD,gBAAI,qCAAmBA,OAAM,GAAG;AAC9B,eAAK,KAAKA,OAAM;AAAA,QAClB;AACA,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AAAA,MACL;AAAA,IACF;AAAA,EACF,OAAO;AACL,WAAO,CAAC,SAAS,KAAK;AAAA,EACxB;AACF;","names":["module","error","import_react_node","import_sentinel","module"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|