@dxos/react-edge-client 0.7.5-labs.5f04cf6
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/LICENSE +8 -0
- package/README.md +1 -0
- package/dist/lib/browser/index.mjs +102 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node/index.cjs +122 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +102 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/types/src/hooks/index.d.ts +3 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useEdgeClient.d.ts +6 -0
- package/dist/types/src/hooks/useEdgeClient.d.ts.map +1 -0
- package/dist/types/src/hooks/useQueue.d.ts +16 -0
- package/dist/types/src/hooks/useQueue.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +43 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useEdgeClient.ts +19 -0
- package/src/hooks/useQueue.ts +96 -0
- package/src/index.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright (c) 2022 DXOS
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @dxos/react-edge-client
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
|
|
3
|
+
// packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { EdgeHttpClient } from "@dxos/edge-client";
|
|
6
|
+
import { invariant } from "@dxos/invariant";
|
|
7
|
+
import { useConfig } from "@dxos/react-client";
|
|
8
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts";
|
|
9
|
+
var useEdgeClient = () => {
|
|
10
|
+
const config = useConfig();
|
|
11
|
+
const edgeUrl = config.values.runtime?.services?.edge?.url;
|
|
12
|
+
invariant(edgeUrl, "EDGE services not configured.", {
|
|
13
|
+
F: __dxlog_file,
|
|
14
|
+
L: 17,
|
|
15
|
+
S: void 0,
|
|
16
|
+
A: [
|
|
17
|
+
"edgeUrl",
|
|
18
|
+
"'EDGE services not configured.'"
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
return useMemo(() => new EdgeHttpClient(edgeUrl), [
|
|
22
|
+
edgeUrl
|
|
23
|
+
]);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// packages/sdk/react-edge-client/src/hooks/useQueue.ts
|
|
27
|
+
import { useEffect, useRef, useState } from "react";
|
|
28
|
+
var useQueue = (client, queueDxn, options = {}) => {
|
|
29
|
+
const [items, setItems] = useState([]);
|
|
30
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
31
|
+
const [error, setError] = useState(null);
|
|
32
|
+
const refreshId = useRef(0);
|
|
33
|
+
const { subspaceTag, spaceId, queueId } = queueDxn?.asQueueDXN() ?? {};
|
|
34
|
+
const append = async (items2) => {
|
|
35
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
setItems((prevItems) => [
|
|
40
|
+
...prevItems,
|
|
41
|
+
...items2
|
|
42
|
+
]);
|
|
43
|
+
void client.insertIntoQueue(subspaceTag, spaceId, queueId, items2);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
setError(err);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const refresh = async () => {
|
|
49
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const thisRefreshId = ++refreshId.current;
|
|
53
|
+
try {
|
|
54
|
+
const { objects } = await client.queryQueue(subspaceTag, spaceId, {
|
|
55
|
+
queueId
|
|
56
|
+
});
|
|
57
|
+
if (thisRefreshId !== refreshId.current) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setItems(objects);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
setError(err);
|
|
63
|
+
} finally {
|
|
64
|
+
setIsLoading(false);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
void refresh();
|
|
69
|
+
}, [
|
|
70
|
+
queueDxn?.toString()
|
|
71
|
+
]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
void refresh();
|
|
74
|
+
}, [
|
|
75
|
+
queueDxn?.toString()
|
|
76
|
+
]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
let interval;
|
|
79
|
+
if (options.pollInterval) {
|
|
80
|
+
const poll = () => {
|
|
81
|
+
void refresh().finally(() => {
|
|
82
|
+
interval = setTimeout(poll, options.pollInterval);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
poll();
|
|
86
|
+
}
|
|
87
|
+
return () => clearInterval(interval);
|
|
88
|
+
}, [
|
|
89
|
+
options.pollInterval
|
|
90
|
+
]);
|
|
91
|
+
return {
|
|
92
|
+
items,
|
|
93
|
+
append,
|
|
94
|
+
isLoading,
|
|
95
|
+
error
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
useEdgeClient,
|
|
100
|
+
useQueue
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useEdgeClient.ts", "../../../src/hooks/useQueue.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { EdgeHttpClient } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport { useConfig } from '@dxos/react-client';\n\n/**\n * Client for edge services.\n */\nexport const useEdgeClient = () => {\n const config = useConfig();\n const edgeUrl = config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'EDGE services not configured.');\n return useMemo(() => new EdgeHttpClient(edgeUrl), [edgeUrl]);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { type EdgeHttpClient } from '@dxos/edge-client';\nimport { type DXN } from '@dxos/keys';\n\nexport type UseQueueOptions = {\n pollInterval?: number;\n};\n\n// TODO(burdon): Convert to class.\nexport type Queue<T> = {\n items: T[];\n isLoading: boolean;\n error: Error | null;\n append: (items: T[]) => void;\n};\n\n/**\n * Polls the given Edge queue.\n */\n// TODO(burdon): Replace polling with socket?\nexport const useQueue = <T>(client: EdgeHttpClient, queueDxn?: DXN, options: UseQueueOptions = {}): Queue<T> => {\n const [items, setItems] = useState<T[]>([]);\n const [isLoading, setIsLoading] = useState(true); // Only for initial load.\n const [error, setError] = useState<Error | null>(null);\n const refreshId = useRef<number>(0);\n\n const { subspaceTag, spaceId, queueId } = queueDxn?.asQueueDXN() ?? {};\n\n const append = async (items: T[]) => {\n if (!subspaceTag || !spaceId || !queueId) {\n return;\n }\n\n try {\n setItems((prevItems) => [...prevItems, ...items]);\n void client.insertIntoQueue(subspaceTag, spaceId, queueId, items);\n } catch (err) {\n setError(err as Error);\n }\n };\n\n const refresh = async () => {\n if (!subspaceTag || !spaceId || !queueId) {\n return;\n }\n\n const thisRefreshId = ++refreshId.current;\n try {\n const { objects } = await client.queryQueue(subspaceTag, spaceId, { queueId });\n if (thisRefreshId !== refreshId.current) {\n return;\n }\n\n setItems(objects as T[]);\n } catch (err) {\n setError(err as Error);\n } finally {\n setIsLoading(false);\n }\n };\n\n useEffect(() => {\n void refresh();\n }, [queueDxn?.toString()]);\n\n useEffect(() => {\n void refresh();\n }, [queueDxn?.toString()]);\n\n useEffect(() => {\n let interval: NodeJS.Timeout;\n if (options.pollInterval) {\n const poll = () => {\n void refresh().finally(() => {\n interval = setTimeout(poll, options.pollInterval);\n });\n };\n\n poll();\n }\n\n return () => clearInterval(interval);\n }, [options.pollInterval]);\n\n return {\n items,\n append,\n isLoading,\n error,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,eAAe;AAExB,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;;AAKnB,IAAMC,gBAAgB,MAAA;AAC3B,QAAMC,SAASF,UAAAA;AACf,QAAMG,UAAUD,OAAOE,OAAOC,SAASC,UAAUC,MAAMC;AACvDT,YAAUI,SAAS,iCAAA;;;;;;;;;AACnB,SAAON,QAAQ,MAAM,IAAIC,eAAeK,OAAAA,GAAU;IAACA;GAAQ;AAC7D;;;ACdA,SAASM,WAAWC,QAAQC,gBAAgB;AAqBrC,IAAMC,WAAW,CAAIC,QAAwBC,UAAgBC,UAA2B,CAAC,MAAC;AAC/F,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAc,CAAA,CAAE;AAC1C,QAAM,CAACC,WAAWC,YAAAA,IAAgBF,SAAS,IAAA;AAC3C,QAAM,CAACG,OAAOC,QAAAA,IAAYJ,SAAuB,IAAA;AACjD,QAAMK,YAAYC,OAAe,CAAA;AAEjC,QAAM,EAAEC,aAAaC,SAASC,QAAO,IAAKb,UAAUc,WAAAA,KAAgB,CAAC;AAErE,QAAMC,SAAS,OAAOb,WAAAA;AACpB,QAAI,CAACS,eAAe,CAACC,WAAW,CAACC,SAAS;AACxC;IACF;AAEA,QAAI;AACFV,eAAS,CAACa,cAAc;WAAIA;WAAcd;OAAM;AAChD,WAAKH,OAAOkB,gBAAgBN,aAAaC,SAASC,SAASX,MAAAA;IAC7D,SAASgB,KAAK;AACZV,eAASU,GAAAA;IACX;EACF;AAEA,QAAMC,UAAU,YAAA;AACd,QAAI,CAACR,eAAe,CAACC,WAAW,CAACC,SAAS;AACxC;IACF;AAEA,UAAMO,gBAAgB,EAAEX,UAAUY;AAClC,QAAI;AACF,YAAM,EAAEC,QAAO,IAAK,MAAMvB,OAAOwB,WAAWZ,aAAaC,SAAS;QAAEC;MAAQ,CAAA;AAC5E,UAAIO,kBAAkBX,UAAUY,SAAS;AACvC;MACF;AAEAlB,eAASmB,OAAAA;IACX,SAASJ,KAAK;AACZV,eAASU,GAAAA;IACX,UAAA;AACEZ,mBAAa,KAAA;IACf;EACF;AAEAkB,YAAU,MAAA;AACR,SAAKL,QAAAA;EACP,GAAG;IAACnB,UAAUyB,SAAAA;GAAW;AAEzBD,YAAU,MAAA;AACR,SAAKL,QAAAA;EACP,GAAG;IAACnB,UAAUyB,SAAAA;GAAW;AAEzBD,YAAU,MAAA;AACR,QAAIE;AACJ,QAAIzB,QAAQ0B,cAAc;AACxB,YAAMC,OAAO,MAAA;AACX,aAAKT,QAAAA,EAAUU,QAAQ,MAAA;AACrBH,qBAAWI,WAAWF,MAAM3B,QAAQ0B,YAAY;QAClD,CAAA;MACF;AAEAC,WAAAA;IACF;AAEA,WAAO,MAAMG,cAAcL,QAAAA;EAC7B,GAAG;IAACzB,QAAQ0B;GAAa;AAEzB,SAAO;IACLzB;IACAa;IACAV;IACAE;EACF;AACF;",
|
|
6
|
+
"names": ["useMemo", "EdgeHttpClient", "invariant", "useConfig", "useEdgeClient", "config", "edgeUrl", "values", "runtime", "services", "edge", "url", "useEffect", "useRef", "useState", "useQueue", "client", "queueDxn", "options", "items", "setItems", "useState", "isLoading", "setIsLoading", "error", "setError", "refreshId", "useRef", "subspaceTag", "spaceId", "queueId", "asQueueDXN", "append", "prevItems", "insertIntoQueue", "err", "refresh", "thisRefreshId", "current", "objects", "queryQueue", "useEffect", "toString", "interval", "pollInterval", "poll", "finally", "setTimeout", "clearInterval"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts":{"bytes":2338,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-client","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/react-edge-client/src/hooks/useQueue.ts":{"bytes":7824,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/react-edge-client/src/hooks/index.ts":{"bytes":613,"imports":[{"path":"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts","kind":"import-statement","original":"./useEdgeClient"},{"path":"packages/sdk/react-edge-client/src/hooks/useQueue.ts","kind":"import-statement","original":"./useQueue"}],"format":"esm"},"packages/sdk/react-edge-client/src/index.ts":{"bytes":495,"imports":[{"path":"packages/sdk/react-edge-client/src/hooks/index.ts","kind":"import-statement","original":"./hooks"}],"format":"esm"}},"outputs":{"packages/sdk/react-edge-client/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5141},"packages/sdk/react-edge-client/dist/lib/browser/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-client","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["useEdgeClient","useQueue"],"entryPoint":"packages/sdk/react-edge-client/src/index.ts","inputs":{"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts":{"bytesInOutput":662},"packages/sdk/react-edge-client/src/hooks/index.ts":{"bytesInOutput":0},"packages/sdk/react-edge-client/src/hooks/useQueue.ts":{"bytesInOutput":1663},"packages/sdk/react-edge-client/src/index.ts":{"bytesInOutput":0}},"bytes":2552}}}
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
var node_exports = {};
|
|
20
|
+
__export(node_exports, {
|
|
21
|
+
useEdgeClient: () => useEdgeClient,
|
|
22
|
+
useQueue: () => useQueue
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(node_exports);
|
|
25
|
+
var import_react = require("react");
|
|
26
|
+
var import_edge_client = require("@dxos/edge-client");
|
|
27
|
+
var import_invariant = require("@dxos/invariant");
|
|
28
|
+
var import_react_client = require("@dxos/react-client");
|
|
29
|
+
var import_react2 = require("react");
|
|
30
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts";
|
|
31
|
+
var useEdgeClient = () => {
|
|
32
|
+
const config = (0, import_react_client.useConfig)();
|
|
33
|
+
const edgeUrl = config.values.runtime?.services?.edge?.url;
|
|
34
|
+
(0, import_invariant.invariant)(edgeUrl, "EDGE services not configured.", {
|
|
35
|
+
F: __dxlog_file,
|
|
36
|
+
L: 17,
|
|
37
|
+
S: void 0,
|
|
38
|
+
A: [
|
|
39
|
+
"edgeUrl",
|
|
40
|
+
"'EDGE services not configured.'"
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
return (0, import_react.useMemo)(() => new import_edge_client.EdgeHttpClient(edgeUrl), [
|
|
44
|
+
edgeUrl
|
|
45
|
+
]);
|
|
46
|
+
};
|
|
47
|
+
var useQueue = (client, queueDxn, options = {}) => {
|
|
48
|
+
const [items, setItems] = (0, import_react2.useState)([]);
|
|
49
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(true);
|
|
50
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
51
|
+
const refreshId = (0, import_react2.useRef)(0);
|
|
52
|
+
const { subspaceTag, spaceId, queueId } = queueDxn?.asQueueDXN() ?? {};
|
|
53
|
+
const append = async (items2) => {
|
|
54
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
setItems((prevItems) => [
|
|
59
|
+
...prevItems,
|
|
60
|
+
...items2
|
|
61
|
+
]);
|
|
62
|
+
void client.insertIntoQueue(subspaceTag, spaceId, queueId, items2);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
setError(err);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const refresh = async () => {
|
|
68
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const thisRefreshId = ++refreshId.current;
|
|
72
|
+
try {
|
|
73
|
+
const { objects } = await client.queryQueue(subspaceTag, spaceId, {
|
|
74
|
+
queueId
|
|
75
|
+
});
|
|
76
|
+
if (thisRefreshId !== refreshId.current) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
setItems(objects);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
setError(err);
|
|
82
|
+
} finally {
|
|
83
|
+
setIsLoading(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
(0, import_react2.useEffect)(() => {
|
|
87
|
+
void refresh();
|
|
88
|
+
}, [
|
|
89
|
+
queueDxn?.toString()
|
|
90
|
+
]);
|
|
91
|
+
(0, import_react2.useEffect)(() => {
|
|
92
|
+
void refresh();
|
|
93
|
+
}, [
|
|
94
|
+
queueDxn?.toString()
|
|
95
|
+
]);
|
|
96
|
+
(0, import_react2.useEffect)(() => {
|
|
97
|
+
let interval;
|
|
98
|
+
if (options.pollInterval) {
|
|
99
|
+
const poll = () => {
|
|
100
|
+
void refresh().finally(() => {
|
|
101
|
+
interval = setTimeout(poll, options.pollInterval);
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
poll();
|
|
105
|
+
}
|
|
106
|
+
return () => clearInterval(interval);
|
|
107
|
+
}, [
|
|
108
|
+
options.pollInterval
|
|
109
|
+
]);
|
|
110
|
+
return {
|
|
111
|
+
items,
|
|
112
|
+
append,
|
|
113
|
+
isLoading,
|
|
114
|
+
error
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
useEdgeClient,
|
|
120
|
+
useQueue
|
|
121
|
+
});
|
|
122
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useEdgeClient.ts", "../../../src/hooks/useQueue.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { EdgeHttpClient } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport { useConfig } from '@dxos/react-client';\n\n/**\n * Client for edge services.\n */\nexport const useEdgeClient = () => {\n const config = useConfig();\n const edgeUrl = config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'EDGE services not configured.');\n return useMemo(() => new EdgeHttpClient(edgeUrl), [edgeUrl]);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { type EdgeHttpClient } from '@dxos/edge-client';\nimport { type DXN } from '@dxos/keys';\n\nexport type UseQueueOptions = {\n pollInterval?: number;\n};\n\n// TODO(burdon): Convert to class.\nexport type Queue<T> = {\n items: T[];\n isLoading: boolean;\n error: Error | null;\n append: (items: T[]) => void;\n};\n\n/**\n * Polls the given Edge queue.\n */\n// TODO(burdon): Replace polling with socket?\nexport const useQueue = <T>(client: EdgeHttpClient, queueDxn?: DXN, options: UseQueueOptions = {}): Queue<T> => {\n const [items, setItems] = useState<T[]>([]);\n const [isLoading, setIsLoading] = useState(true); // Only for initial load.\n const [error, setError] = useState<Error | null>(null);\n const refreshId = useRef<number>(0);\n\n const { subspaceTag, spaceId, queueId } = queueDxn?.asQueueDXN() ?? {};\n\n const append = async (items: T[]) => {\n if (!subspaceTag || !spaceId || !queueId) {\n return;\n }\n\n try {\n setItems((prevItems) => [...prevItems, ...items]);\n void client.insertIntoQueue(subspaceTag, spaceId, queueId, items);\n } catch (err) {\n setError(err as Error);\n }\n };\n\n const refresh = async () => {\n if (!subspaceTag || !spaceId || !queueId) {\n return;\n }\n\n const thisRefreshId = ++refreshId.current;\n try {\n const { objects } = await client.queryQueue(subspaceTag, spaceId, { queueId });\n if (thisRefreshId !== refreshId.current) {\n return;\n }\n\n setItems(objects as T[]);\n } catch (err) {\n setError(err as Error);\n } finally {\n setIsLoading(false);\n }\n };\n\n useEffect(() => {\n void refresh();\n }, [queueDxn?.toString()]);\n\n useEffect(() => {\n void refresh();\n }, [queueDxn?.toString()]);\n\n useEffect(() => {\n let interval: NodeJS.Timeout;\n if (options.pollInterval) {\n const poll = () => {\n void refresh().finally(() => {\n interval = setTimeout(poll, options.pollInterval);\n });\n };\n\n poll();\n }\n\n return () => clearInterval(interval);\n }, [options.pollInterval]);\n\n return {\n items,\n append,\n isLoading,\n error,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAAwB;AAExB,yBAA+B;AAC/B,uBAA0B;AAC1B,0BAA0B;ACJ1B,IAAAA,gBAA4C;;ADSrC,IAAMC,gBAAgB,MAAA;AAC3B,QAAMC,aAASC,+BAAAA;AACf,QAAMC,UAAUF,OAAOG,OAAOC,SAASC,UAAUC,MAAMC;AACvDC,kCAAUN,SAAS,iCAAA;;;;;;;;;AACnB,aAAOO,sBAAQ,MAAM,IAAIC,kCAAeR,OAAAA,GAAU;IAACA;GAAQ;AAC7D;ACOO,IAAMS,WAAW,CAAIC,QAAwBC,UAAgBC,UAA2B,CAAC,MAAC;AAC/F,QAAM,CAACC,OAAOC,QAAAA,QAAYC,wBAAc,CAAA,CAAE;AAC1C,QAAM,CAACC,WAAWC,YAAAA,QAAgBF,wBAAS,IAAA;AAC3C,QAAM,CAACG,OAAOC,QAAAA,QAAYJ,wBAAuB,IAAA;AACjD,QAAMK,gBAAYC,sBAAe,CAAA;AAEjC,QAAM,EAAEC,aAAaC,SAASC,QAAO,IAAKb,UAAUc,WAAAA,KAAgB,CAAC;AAErE,QAAMC,SAAS,OAAOb,WAAAA;AACpB,QAAI,CAACS,eAAe,CAACC,WAAW,CAACC,SAAS;AACxC;IACF;AAEA,QAAI;AACFV,eAAS,CAACa,cAAc;WAAIA;WAAcd;OAAM;AAChD,WAAKH,OAAOkB,gBAAgBN,aAAaC,SAASC,SAASX,MAAAA;IAC7D,SAASgB,KAAK;AACZV,eAASU,GAAAA;IACX;EACF;AAEA,QAAMC,UAAU,YAAA;AACd,QAAI,CAACR,eAAe,CAACC,WAAW,CAACC,SAAS;AACxC;IACF;AAEA,UAAMO,gBAAgB,EAAEX,UAAUY;AAClC,QAAI;AACF,YAAM,EAAEC,QAAO,IAAK,MAAMvB,OAAOwB,WAAWZ,aAAaC,SAAS;QAAEC;MAAQ,CAAA;AAC5E,UAAIO,kBAAkBX,UAAUY,SAAS;AACvC;MACF;AAEAlB,eAASmB,OAAAA;IACX,SAASJ,KAAK;AACZV,eAASU,GAAAA;IACX,UAAA;AACEZ,mBAAa,KAAA;IACf;EACF;AAEAkB,+BAAU,MAAA;AACR,SAAKL,QAAAA;EACP,GAAG;IAACnB,UAAUyB,SAAAA;GAAW;AAEzBD,+BAAU,MAAA;AACR,SAAKL,QAAAA;EACP,GAAG;IAACnB,UAAUyB,SAAAA;GAAW;AAEzBD,+BAAU,MAAA;AACR,QAAIE;AACJ,QAAIzB,QAAQ0B,cAAc;AACxB,YAAMC,OAAO,MAAA;AACX,aAAKT,QAAAA,EAAUU,QAAQ,MAAA;AACrBH,qBAAWI,WAAWF,MAAM3B,QAAQ0B,YAAY;QAClD,CAAA;MACF;AAEAC,WAAAA;IACF;AAEA,WAAO,MAAMG,cAAcL,QAAAA;EAC7B,GAAG;IAACzB,QAAQ0B;GAAa;AAEzB,SAAO;IACLzB;IACAa;IACAV;IACAE;EACF;AACF;",
|
|
6
|
+
"names": ["import_react", "useEdgeClient", "config", "useConfig", "edgeUrl", "values", "runtime", "services", "edge", "url", "invariant", "useMemo", "EdgeHttpClient", "useQueue", "client", "queueDxn", "options", "items", "setItems", "useState", "isLoading", "setIsLoading", "error", "setError", "refreshId", "useRef", "subspaceTag", "spaceId", "queueId", "asQueueDXN", "append", "prevItems", "insertIntoQueue", "err", "refresh", "thisRefreshId", "current", "objects", "queryQueue", "useEffect", "toString", "interval", "pollInterval", "poll", "finally", "setTimeout", "clearInterval"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts":{"bytes":2338,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-client","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/react-edge-client/src/hooks/useQueue.ts":{"bytes":7824,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/react-edge-client/src/hooks/index.ts":{"bytes":613,"imports":[{"path":"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts","kind":"import-statement","original":"./useEdgeClient"},{"path":"packages/sdk/react-edge-client/src/hooks/useQueue.ts","kind":"import-statement","original":"./useQueue"}],"format":"esm"},"packages/sdk/react-edge-client/src/index.ts":{"bytes":495,"imports":[{"path":"packages/sdk/react-edge-client/src/hooks/index.ts","kind":"import-statement","original":"./hooks"}],"format":"esm"}},"outputs":{"packages/sdk/react-edge-client/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5139},"packages/sdk/react-edge-client/dist/lib/node/index.cjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-client","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["useEdgeClient","useQueue"],"entryPoint":"packages/sdk/react-edge-client/src/index.ts","inputs":{"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts":{"bytesInOutput":662},"packages/sdk/react-edge-client/src/hooks/index.ts":{"bytesInOutput":0},"packages/sdk/react-edge-client/src/hooks/useQueue.ts":{"bytesInOutput":1663},"packages/sdk/react-edge-client/src/index.ts":{"bytesInOutput":0}},"bytes":2518}}}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { EdgeHttpClient } from "@dxos/edge-client";
|
|
6
|
+
import { invariant } from "@dxos/invariant";
|
|
7
|
+
import { useConfig } from "@dxos/react-client";
|
|
8
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts";
|
|
9
|
+
var useEdgeClient = () => {
|
|
10
|
+
const config = useConfig();
|
|
11
|
+
const edgeUrl = config.values.runtime?.services?.edge?.url;
|
|
12
|
+
invariant(edgeUrl, "EDGE services not configured.", {
|
|
13
|
+
F: __dxlog_file,
|
|
14
|
+
L: 17,
|
|
15
|
+
S: void 0,
|
|
16
|
+
A: [
|
|
17
|
+
"edgeUrl",
|
|
18
|
+
"'EDGE services not configured.'"
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
return useMemo(() => new EdgeHttpClient(edgeUrl), [
|
|
22
|
+
edgeUrl
|
|
23
|
+
]);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// packages/sdk/react-edge-client/src/hooks/useQueue.ts
|
|
27
|
+
import { useEffect, useRef, useState } from "react";
|
|
28
|
+
var useQueue = (client, queueDxn, options = {}) => {
|
|
29
|
+
const [items, setItems] = useState([]);
|
|
30
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
31
|
+
const [error, setError] = useState(null);
|
|
32
|
+
const refreshId = useRef(0);
|
|
33
|
+
const { subspaceTag, spaceId, queueId } = queueDxn?.asQueueDXN() ?? {};
|
|
34
|
+
const append = async (items2) => {
|
|
35
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
setItems((prevItems) => [
|
|
40
|
+
...prevItems,
|
|
41
|
+
...items2
|
|
42
|
+
]);
|
|
43
|
+
void client.insertIntoQueue(subspaceTag, spaceId, queueId, items2);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
setError(err);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const refresh = async () => {
|
|
49
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const thisRefreshId = ++refreshId.current;
|
|
53
|
+
try {
|
|
54
|
+
const { objects } = await client.queryQueue(subspaceTag, spaceId, {
|
|
55
|
+
queueId
|
|
56
|
+
});
|
|
57
|
+
if (thisRefreshId !== refreshId.current) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setItems(objects);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
setError(err);
|
|
63
|
+
} finally {
|
|
64
|
+
setIsLoading(false);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
void refresh();
|
|
69
|
+
}, [
|
|
70
|
+
queueDxn?.toString()
|
|
71
|
+
]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
void refresh();
|
|
74
|
+
}, [
|
|
75
|
+
queueDxn?.toString()
|
|
76
|
+
]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
let interval;
|
|
79
|
+
if (options.pollInterval) {
|
|
80
|
+
const poll = () => {
|
|
81
|
+
void refresh().finally(() => {
|
|
82
|
+
interval = setTimeout(poll, options.pollInterval);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
poll();
|
|
86
|
+
}
|
|
87
|
+
return () => clearInterval(interval);
|
|
88
|
+
}, [
|
|
89
|
+
options.pollInterval
|
|
90
|
+
]);
|
|
91
|
+
return {
|
|
92
|
+
items,
|
|
93
|
+
append,
|
|
94
|
+
isLoading,
|
|
95
|
+
error
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
useEdgeClient,
|
|
100
|
+
useQueue
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useEdgeClient.ts", "../../../src/hooks/useQueue.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { EdgeHttpClient } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport { useConfig } from '@dxos/react-client';\n\n/**\n * Client for edge services.\n */\nexport const useEdgeClient = () => {\n const config = useConfig();\n const edgeUrl = config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'EDGE services not configured.');\n return useMemo(() => new EdgeHttpClient(edgeUrl), [edgeUrl]);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect, useRef, useState } from 'react';\n\nimport { type EdgeHttpClient } from '@dxos/edge-client';\nimport { type DXN } from '@dxos/keys';\n\nexport type UseQueueOptions = {\n pollInterval?: number;\n};\n\n// TODO(burdon): Convert to class.\nexport type Queue<T> = {\n items: T[];\n isLoading: boolean;\n error: Error | null;\n append: (items: T[]) => void;\n};\n\n/**\n * Polls the given Edge queue.\n */\n// TODO(burdon): Replace polling with socket?\nexport const useQueue = <T>(client: EdgeHttpClient, queueDxn?: DXN, options: UseQueueOptions = {}): Queue<T> => {\n const [items, setItems] = useState<T[]>([]);\n const [isLoading, setIsLoading] = useState(true); // Only for initial load.\n const [error, setError] = useState<Error | null>(null);\n const refreshId = useRef<number>(0);\n\n const { subspaceTag, spaceId, queueId } = queueDxn?.asQueueDXN() ?? {};\n\n const append = async (items: T[]) => {\n if (!subspaceTag || !spaceId || !queueId) {\n return;\n }\n\n try {\n setItems((prevItems) => [...prevItems, ...items]);\n void client.insertIntoQueue(subspaceTag, spaceId, queueId, items);\n } catch (err) {\n setError(err as Error);\n }\n };\n\n const refresh = async () => {\n if (!subspaceTag || !spaceId || !queueId) {\n return;\n }\n\n const thisRefreshId = ++refreshId.current;\n try {\n const { objects } = await client.queryQueue(subspaceTag, spaceId, { queueId });\n if (thisRefreshId !== refreshId.current) {\n return;\n }\n\n setItems(objects as T[]);\n } catch (err) {\n setError(err as Error);\n } finally {\n setIsLoading(false);\n }\n };\n\n useEffect(() => {\n void refresh();\n }, [queueDxn?.toString()]);\n\n useEffect(() => {\n void refresh();\n }, [queueDxn?.toString()]);\n\n useEffect(() => {\n let interval: NodeJS.Timeout;\n if (options.pollInterval) {\n const poll = () => {\n void refresh().finally(() => {\n interval = setTimeout(poll, options.pollInterval);\n });\n };\n\n poll();\n }\n\n return () => clearInterval(interval);\n }, [options.pollInterval]);\n\n return {\n items,\n append,\n isLoading,\n error,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,eAAe;AAExB,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;;AAKnB,IAAMC,gBAAgB,MAAA;AAC3B,QAAMC,SAASF,UAAAA;AACf,QAAMG,UAAUD,OAAOE,OAAOC,SAASC,UAAUC,MAAMC;AACvDT,YAAUI,SAAS,iCAAA;;;;;;;;;AACnB,SAAON,QAAQ,MAAM,IAAIC,eAAeK,OAAAA,GAAU;IAACA;GAAQ;AAC7D;;;ACdA,SAASM,WAAWC,QAAQC,gBAAgB;AAqBrC,IAAMC,WAAW,CAAIC,QAAwBC,UAAgBC,UAA2B,CAAC,MAAC;AAC/F,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAc,CAAA,CAAE;AAC1C,QAAM,CAACC,WAAWC,YAAAA,IAAgBF,SAAS,IAAA;AAC3C,QAAM,CAACG,OAAOC,QAAAA,IAAYJ,SAAuB,IAAA;AACjD,QAAMK,YAAYC,OAAe,CAAA;AAEjC,QAAM,EAAEC,aAAaC,SAASC,QAAO,IAAKb,UAAUc,WAAAA,KAAgB,CAAC;AAErE,QAAMC,SAAS,OAAOb,WAAAA;AACpB,QAAI,CAACS,eAAe,CAACC,WAAW,CAACC,SAAS;AACxC;IACF;AAEA,QAAI;AACFV,eAAS,CAACa,cAAc;WAAIA;WAAcd;OAAM;AAChD,WAAKH,OAAOkB,gBAAgBN,aAAaC,SAASC,SAASX,MAAAA;IAC7D,SAASgB,KAAK;AACZV,eAASU,GAAAA;IACX;EACF;AAEA,QAAMC,UAAU,YAAA;AACd,QAAI,CAACR,eAAe,CAACC,WAAW,CAACC,SAAS;AACxC;IACF;AAEA,UAAMO,gBAAgB,EAAEX,UAAUY;AAClC,QAAI;AACF,YAAM,EAAEC,QAAO,IAAK,MAAMvB,OAAOwB,WAAWZ,aAAaC,SAAS;QAAEC;MAAQ,CAAA;AAC5E,UAAIO,kBAAkBX,UAAUY,SAAS;AACvC;MACF;AAEAlB,eAASmB,OAAAA;IACX,SAASJ,KAAK;AACZV,eAASU,GAAAA;IACX,UAAA;AACEZ,mBAAa,KAAA;IACf;EACF;AAEAkB,YAAU,MAAA;AACR,SAAKL,QAAAA;EACP,GAAG;IAACnB,UAAUyB,SAAAA;GAAW;AAEzBD,YAAU,MAAA;AACR,SAAKL,QAAAA;EACP,GAAG;IAACnB,UAAUyB,SAAAA;GAAW;AAEzBD,YAAU,MAAA;AACR,QAAIE;AACJ,QAAIzB,QAAQ0B,cAAc;AACxB,YAAMC,OAAO,MAAA;AACX,aAAKT,QAAAA,EAAUU,QAAQ,MAAA;AACrBH,qBAAWI,WAAWF,MAAM3B,QAAQ0B,YAAY;QAClD,CAAA;MACF;AAEAC,WAAAA;IACF;AAEA,WAAO,MAAMG,cAAcL,QAAAA;EAC7B,GAAG;IAACzB,QAAQ0B;GAAa;AAEzB,SAAO;IACLzB;IACAa;IACAV;IACAE;EACF;AACF;",
|
|
6
|
+
"names": ["useMemo", "EdgeHttpClient", "invariant", "useConfig", "useEdgeClient", "config", "edgeUrl", "values", "runtime", "services", "edge", "url", "useEffect", "useRef", "useState", "useQueue", "client", "queueDxn", "options", "items", "setItems", "useState", "isLoading", "setIsLoading", "error", "setError", "refreshId", "useRef", "subspaceTag", "spaceId", "queueId", "asQueueDXN", "append", "prevItems", "insertIntoQueue", "err", "refresh", "thisRefreshId", "current", "objects", "queryQueue", "useEffect", "toString", "interval", "pollInterval", "poll", "finally", "setTimeout", "clearInterval"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts":{"bytes":2338,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-client","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/react-edge-client/src/hooks/useQueue.ts":{"bytes":7824,"imports":[{"path":"react","kind":"import-statement","external":true}],"format":"esm"},"packages/sdk/react-edge-client/src/hooks/index.ts":{"bytes":613,"imports":[{"path":"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts","kind":"import-statement","original":"./useEdgeClient"},{"path":"packages/sdk/react-edge-client/src/hooks/useQueue.ts","kind":"import-statement","original":"./useQueue"}],"format":"esm"},"packages/sdk/react-edge-client/src/index.ts":{"bytes":495,"imports":[{"path":"packages/sdk/react-edge-client/src/hooks/index.ts","kind":"import-statement","original":"./hooks"}],"format":"esm"}},"outputs":{"packages/sdk/react-edge-client/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5141},"packages/sdk/react-edge-client/dist/lib/node-esm/index.mjs":{"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/edge-client","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/react-client","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true}],"exports":["useEdgeClient","useQueue"],"entryPoint":"packages/sdk/react-edge-client/src/index.ts","inputs":{"packages/sdk/react-edge-client/src/hooks/useEdgeClient.ts":{"bytesInOutput":662},"packages/sdk/react-edge-client/src/hooks/index.ts":{"bytesInOutput":0},"packages/sdk/react-edge-client/src/hooks/useQueue.ts":{"bytesInOutput":1663},"packages/sdk/react-edge-client/src/index.ts":{"bytesInOutput":0}},"bytes":2611}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEdgeClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useEdgeClient.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;GAEG;AACH,eAAO,MAAM,aAAa,sBAKzB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type EdgeHttpClient } from '@dxos/edge-client';
|
|
2
|
+
import { type DXN } from '@dxos/keys';
|
|
3
|
+
export type UseQueueOptions = {
|
|
4
|
+
pollInterval?: number;
|
|
5
|
+
};
|
|
6
|
+
export type Queue<T> = {
|
|
7
|
+
items: T[];
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
error: Error | null;
|
|
10
|
+
append: (items: T[]) => void;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Polls the given Edge queue.
|
|
14
|
+
*/
|
|
15
|
+
export declare const useQueue: <T>(client: EdgeHttpClient, queueDxn?: DXN, options?: UseQueueOptions) => Queue<T>;
|
|
16
|
+
//# sourceMappingURL=useQueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueue.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useQueue.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAGF,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IACrB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;CAC9B,CAAC;AAEF;;GAEG;AAEH,eAAO,MAAM,QAAQ,GAAI,CAAC,UAAU,cAAc,aAAa,GAAG,YAAW,eAAe,KAAQ,KAAK,CAAC,CAAC,CAsE1G,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.2"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dxos/react-edge-client",
|
|
3
|
+
"version": "0.7.5-labs.5f04cf6",
|
|
4
|
+
"description": "React hooks for the Edge Client.",
|
|
5
|
+
"homepage": "https://dxos.org",
|
|
6
|
+
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "DXOS.org",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/src/index.d.ts",
|
|
12
|
+
"browser": "./dist/lib/browser/index.mjs",
|
|
13
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"types": "dist/types/src/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@dxos/edge-client": "0.7.5-labs.5f04cf6",
|
|
23
|
+
"@dxos/invariant": "0.7.5-labs.5f04cf6",
|
|
24
|
+
"@dxos/log": "0.7.5-labs.5f04cf6",
|
|
25
|
+
"@dxos/node-std": "0.7.5-labs.5f04cf6",
|
|
26
|
+
"@dxos/util": "0.7.5-labs.5f04cf6",
|
|
27
|
+
"@dxos/react-client": "0.7.5-labs.5f04cf6"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"react": "~18.2.0",
|
|
31
|
+
"react-dom": "~18.2.0",
|
|
32
|
+
"vite": "5.4.7"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@effect/schema": "^0.75.5",
|
|
36
|
+
"effect": "^3.12.3",
|
|
37
|
+
"react": "~18.2.0",
|
|
38
|
+
"react-dom": "~18.2.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { EdgeHttpClient } from '@dxos/edge-client';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { useConfig } from '@dxos/react-client';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Client for edge services.
|
|
13
|
+
*/
|
|
14
|
+
export const useEdgeClient = () => {
|
|
15
|
+
const config = useConfig();
|
|
16
|
+
const edgeUrl = config.values.runtime?.services?.edge?.url;
|
|
17
|
+
invariant(edgeUrl, 'EDGE services not configured.');
|
|
18
|
+
return useMemo(() => new EdgeHttpClient(edgeUrl), [edgeUrl]);
|
|
19
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useRef, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type EdgeHttpClient } from '@dxos/edge-client';
|
|
8
|
+
import { type DXN } from '@dxos/keys';
|
|
9
|
+
|
|
10
|
+
export type UseQueueOptions = {
|
|
11
|
+
pollInterval?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// TODO(burdon): Convert to class.
|
|
15
|
+
export type Queue<T> = {
|
|
16
|
+
items: T[];
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
append: (items: T[]) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Polls the given Edge queue.
|
|
24
|
+
*/
|
|
25
|
+
// TODO(burdon): Replace polling with socket?
|
|
26
|
+
export const useQueue = <T>(client: EdgeHttpClient, queueDxn?: DXN, options: UseQueueOptions = {}): Queue<T> => {
|
|
27
|
+
const [items, setItems] = useState<T[]>([]);
|
|
28
|
+
const [isLoading, setIsLoading] = useState(true); // Only for initial load.
|
|
29
|
+
const [error, setError] = useState<Error | null>(null);
|
|
30
|
+
const refreshId = useRef<number>(0);
|
|
31
|
+
|
|
32
|
+
const { subspaceTag, spaceId, queueId } = queueDxn?.asQueueDXN() ?? {};
|
|
33
|
+
|
|
34
|
+
const append = async (items: T[]) => {
|
|
35
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
setItems((prevItems) => [...prevItems, ...items]);
|
|
41
|
+
void client.insertIntoQueue(subspaceTag, spaceId, queueId, items);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
setError(err as Error);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const refresh = async () => {
|
|
48
|
+
if (!subspaceTag || !spaceId || !queueId) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const thisRefreshId = ++refreshId.current;
|
|
53
|
+
try {
|
|
54
|
+
const { objects } = await client.queryQueue(subspaceTag, spaceId, { queueId });
|
|
55
|
+
if (thisRefreshId !== refreshId.current) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setItems(objects as T[]);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
setError(err as Error);
|
|
62
|
+
} finally {
|
|
63
|
+
setIsLoading(false);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
void refresh();
|
|
69
|
+
}, [queueDxn?.toString()]);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
void refresh();
|
|
73
|
+
}, [queueDxn?.toString()]);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
let interval: NodeJS.Timeout;
|
|
77
|
+
if (options.pollInterval) {
|
|
78
|
+
const poll = () => {
|
|
79
|
+
void refresh().finally(() => {
|
|
80
|
+
interval = setTimeout(poll, options.pollInterval);
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
poll();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return () => clearInterval(interval);
|
|
88
|
+
}, [options.pollInterval]);
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
items,
|
|
92
|
+
append,
|
|
93
|
+
isLoading,
|
|
94
|
+
error,
|
|
95
|
+
};
|
|
96
|
+
};
|