@asymmetric-effort/specifyjs 0.2.109 → 0.2.113
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/esm/chunks/chunk-2Y3QZBBL.js +221 -0
- package/dist/esm/chunks/{chunk-3SXNLMCH.js.map → chunk-2Y3QZBBL.js.map} +2 -2
- package/dist/esm/chunks/chunk-5OX5JKEY.js +174 -0
- package/dist/esm/chunks/{chunk-VAF4KNDP.js.map → chunk-5OX5JKEY.js.map} +2 -2
- package/dist/esm/chunks/chunk-AVA7QEGU.js +625 -0
- package/dist/esm/chunks/{chunk-A7AAS5ZR.js.map → chunk-AVA7QEGU.js.map} +2 -2
- package/dist/esm/chunks/chunk-BLIAKWAU.js +42 -0
- package/dist/esm/chunks/{chunk-TVDAY42P.js.map → chunk-BLIAKWAU.js.map} +2 -2
- package/dist/esm/chunks/chunk-CWCWXKVV.js +202 -0
- package/dist/esm/chunks/{chunk-MCXU6QF3.js.map → chunk-CWCWXKVV.js.map} +2 -2
- package/dist/esm/chunks/chunk-HINJXYXY.js +29 -0
- package/dist/esm/chunks/{chunk-3J4RXW7E.js.map → chunk-HINJXYXY.js.map} +2 -2
- package/dist/esm/chunks/chunk-MKUA6QTB.js +9 -0
- package/dist/esm/chunks/chunk-NF4555DU.js +58 -0
- package/dist/esm/chunks/{chunk-ODCBJ22O.js.map → chunk-NF4555DU.js.map} +2 -2
- package/dist/esm/chunks/chunk-RSL3RU56.js +14 -0
- package/dist/esm/chunks/{chunk-E43OK6IZ.js.map → chunk-RSL3RU56.js.map} +2 -2
- package/dist/esm/chunks/chunk-T7EHIXSF.js +17 -0
- package/dist/esm/chunks/{chunk-LWOMFZ4C.js.map → chunk-T7EHIXSF.js.map} +2 -2
- package/dist/esm/chunks/metrics-6LW2N3GU.js +16 -0
- package/dist/esm/client/index.js +670 -1
- package/dist/esm/components-barrel.js +25688 -3
- package/dist/esm/dom/index.js +1902 -1
- package/dist/esm/index.js +117 -1
- package/dist/esm/jsx-dev-runtime.js +12 -1
- package/dist/esm/jsx-runtime.js +13 -1
- package/dist/esm/server/index.js +381 -1
- package/dist/esm/telemetry/index.js +188 -1
- package/dist/specifyjs-client.esm.js +670 -1
- package/dist/specifyjs-client.esm.js.map +2 -2
- package/dist/specifyjs-components.cjs.js.map +1 -1
- package/dist/specifyjs-components.esm.js +25688 -3
- package/dist/specifyjs-components.esm.js.map +3 -3
- package/dist/specifyjs-dom.esm.js +1902 -1
- package/dist/specifyjs-dom.esm.js.map +2 -2
- package/dist/specifyjs-jsx-dev-runtime.esm.js +12 -1
- package/dist/specifyjs-jsx-runtime.esm.js +13 -1
- package/dist/specifyjs-server.esm.js +381 -1
- package/dist/specifyjs-server.esm.js.map +2 -2
- package/dist/specifyjs-telemetry.esm.js +188 -1
- package/dist/specifyjs-telemetry.esm.js.map +2 -2
- package/dist/specifyjs.esm.js +117 -1
- package/dist/types/components/ad/adsense/src/AdSense.d.ts +1 -1
- package/dist/types/components/data/analog-clock/src/AnalogClock.d.ts +1 -1
- package/dist/types/components/data/avatar/src/Avatar.d.ts +1 -1
- package/dist/types/components/data/badge/src/Badge.d.ts +1 -1
- package/dist/types/components/data/data-grid/src/DataGrid.d.ts +1 -1
- package/dist/types/components/data/digital-clock/src/DigitalClock.d.ts +1 -1
- package/dist/types/components/data/list-view/src/ListView.d.ts +1 -1
- package/dist/types/components/data/tag/src/Tag.d.ts +1 -1
- package/dist/types/components/data/virtual-scroll/src/VirtualScroll.d.ts +1 -1
- package/dist/types/components/feedback/alert/src/Alert.d.ts +1 -1
- package/dist/types/components/feedback/empty-state/src/EmptyState.d.ts +1 -1
- package/dist/types/components/feedback/progress-bar/src/ProgressBar.d.ts +1 -1
- package/dist/types/components/feedback/skeleton/src/Skeleton.d.ts +1 -1
- package/dist/types/components/feedback/spinner/src/Spinner.d.ts +1 -1
- package/dist/types/components/form/button/src/Button.d.ts +1 -1
- package/dist/types/components/form/checkbox/src/Checkbox.d.ts +1 -1
- package/dist/types/components/form/color-picker/src/ColorPicker.d.ts +1 -1
- package/dist/types/components/form/color-wheel/src/ColorWheel.d.ts +1 -1
- package/dist/types/components/form/datepicker/src/DatePicker.d.ts +1 -1
- package/dist/types/components/form/file-upload/src/FileUpload.d.ts +1 -1
- package/dist/types/components/form/multiline/src/MultilineField.d.ts +1 -1
- package/dist/types/components/form/number-spinner/src/NumberSpinner.d.ts +1 -1
- package/dist/types/components/form/radio/src/RadioGroup.d.ts +1 -1
- package/dist/types/components/form/select/src/Select.d.ts +1 -1
- package/dist/types/components/form/slider/src/Slider.d.ts +1 -1
- package/dist/types/components/form/texteditor/src/TextEditor.d.ts +1 -1
- package/dist/types/components/form/textfield/src/TextField.d.ts +1 -1
- package/dist/types/components/form/timepicker/src/TimePicker.d.ts +1 -1
- package/dist/types/components/form/toggle/src/Toggle.d.ts +1 -1
- package/dist/types/components/form/wrapper/src/FormFieldWrapper.d.ts +1 -1
- package/dist/types/components/layout/card/src/Card.d.ts +1 -1
- package/dist/types/components/layout/desktop-background/src/DesktopBackground.d.ts +1 -1
- package/dist/types/components/layout/flex-container/src/FlexContainer.d.ts +2 -2
- package/dist/types/components/layout/footer/src/Footer.d.ts +1 -1
- package/dist/types/components/layout/grid/src/Grid.d.ts +2 -2
- package/dist/types/components/layout/panel/src/Panel.d.ts +1 -1
- package/dist/types/components/layout/scroll-container/src/ScrollContainer.d.ts +1 -1
- package/dist/types/components/layout/splitter/src/Splitter.d.ts +1 -1
- package/dist/types/components/layout/tabs/src/Tabs.d.ts +1 -1
- package/dist/types/components/layout/window-manager/src/WindowManager.d.ts +1 -1
- package/dist/types/components/media/carousel/src/Carousel.d.ts +1 -1
- package/dist/types/components/media/image/src/Image.d.ts +1 -1
- package/dist/types/components/media/video-player/src/VideoPlayer.d.ts +1 -1
- package/dist/types/components/nav/accordion/src/Accordion.d.ts +1 -1
- package/dist/types/components/nav/breadcrumb/src/Breadcrumb.d.ts +1 -1
- package/dist/types/components/nav/dock/src/Dock.d.ts +1 -1
- package/dist/types/components/nav/dropdown/src/Dropdown.d.ts +1 -1
- package/dist/types/components/nav/menubar/src/Menubar.d.ts +1 -1
- package/dist/types/components/nav/pagination/src/Pagination.d.ts +1 -1
- package/dist/types/components/nav/sidebar/src/Sidebar.d.ts +1 -1
- package/dist/types/components/nav/stepper/src/Stepper.d.ts +1 -1
- package/dist/types/components/nav/system-tray/src/SystemTray.d.ts +1 -1
- package/dist/types/components/nav/toolbar/src/Toolbar.d.ts +1 -1
- package/dist/types/components/nav/treenav/src/TreeNav.d.ts +1 -1
- package/dist/types/components/nav/wrapper/src/NavWrapper.d.ts +1 -1
- package/dist/types/components/overlay/context-menu/src/ContextMenu.d.ts +1 -1
- package/dist/types/components/overlay/drawer/src/Drawer.d.ts +1 -1
- package/dist/types/components/overlay/modal/src/Modal.d.ts +1 -1
- package/dist/types/components/overlay/popover/src/Popover.d.ts +1 -1
- package/dist/types/components/overlay/toast/src/Toast.d.ts +2 -2
- package/dist/types/components/overlay/tooltip/src/Tooltip.d.ts +1 -1
- package/dist/types/components/page/ide/src/IDE.d.ts +1 -1
- package/dist/types/components/page/trading-dashboard/src/TradingDashboard.d.ts +1 -1
- package/dist/types/components/page/unity-desktop/src/UnityApp.d.ts +1 -1
- package/dist/types/components/page/unity-desktop/src/UnityDesktop.d.ts +1 -1
- package/dist/types/components/page/word-processor/src/WordProcessor.d.ts +1 -1
- package/dist/types/components/viz/2D-bar-graph/src/BarGraph.d.ts +1 -1
- package/dist/types/components/viz/2D-discrete-cartesian/src/DiscreteCartesian2D.d.ts +1 -1
- package/dist/types/components/viz/2D-line-graph/src/LineGraph.d.ts +1 -1
- package/dist/types/components/viz/2D-pie-graph/src/PieGraph.d.ts +1 -1
- package/dist/types/components/viz/3d-force-graph/src/ForceGraph3D.d.ts +27 -119
- package/dist/types/components/viz/3d-force-graph/src/force-sim.d.ts +49 -0
- package/dist/types/components/viz/3d-force-graph/src/index.d.ts +5 -1
- package/dist/types/components/viz/3d-force-graph/src/types.d.ts +88 -0
- package/dist/types/components/viz/3d-layers/src/ThreeDLayers.d.ts +1 -1
- package/dist/types/components/viz/3dSpace/src/Space3D.d.ts +1 -1
- package/dist/types/components/viz/3dSpace/src/geom-polyhedron.d.ts +49 -0
- package/dist/types/components/viz/3dSpace/src/geom-sphere.d.ts +27 -0
- package/dist/types/components/viz/3dSpace/src/index.d.ts +5 -0
- package/dist/types/components/viz/3dSpace/src/mesh.d.ts +22 -0
- package/dist/types/components/viz/3dSpace/src/scene-object.d.ts +4 -0
- package/dist/types/components/viz/big-number/src/BigNumber.d.ts +1 -1
- package/dist/types/components/viz/bloch-sphere/src/BlochSphere.d.ts +1 -1
- package/dist/types/components/viz/box-plot/src/BoxPlot.d.ts +1 -1
- package/dist/types/components/viz/bubble-chart/src/BubbleChart.d.ts +1 -1
- package/dist/types/components/viz/calendar-heat-map/src/CalendarHeatMap.d.ts +1 -1
- package/dist/types/components/viz/chord/src/ChordDiagram.d.ts +1 -1
- package/dist/types/components/viz/decomposition-tree/src/DecompositionTree.d.ts +1 -1
- package/dist/types/components/viz/funnel/src/FunnelChart.d.ts +1 -1
- package/dist/types/components/viz/gantt-chart/src/GanttChart.d.ts +1 -1
- package/dist/types/components/viz/gauge/src/Gauge.d.ts +1 -1
- package/dist/types/components/viz/graph/src/HypercubeGraph.d.ts +1 -1
- package/dist/types/components/viz/heat-map/src/HeatMap.d.ts +1 -1
- package/dist/types/components/viz/histogram/src/Histogram.d.ts +1 -1
- package/dist/types/components/viz/matrix/src/Matrix.d.ts +1 -1
- package/dist/types/components/viz/partition/src/Partition.d.ts +1 -1
- package/dist/types/components/viz/pivot-table/src/PivotTable.d.ts +1 -1
- package/dist/types/components/viz/radar-chart/src/RadarChart.d.ts +1 -1
- package/dist/types/components/viz/sankey/src/SankeyDiagram.d.ts +1 -1
- package/dist/types/components/viz/sunburst/src/Sunburst.d.ts +1 -1
- package/dist/types/components/viz/tree-map/src/TreeMap.d.ts +1 -1
- package/dist/types/components/viz/vector-field/src/VectorField.d.ts +1 -1
- package/dist/types/components/viz/waterfall/src/WaterfallChart.d.ts +1 -1
- package/dist/types/components/viz/word-cloud/src/WordCloud.d.ts +1 -1
- package/dist/types/components/viz/wrapper/src/VizWrapper.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/chunks/chunk-3J4RXW7E.js +0 -3
- package/dist/esm/chunks/chunk-3SXNLMCH.js +0 -3
- package/dist/esm/chunks/chunk-A7AAS5ZR.js +0 -3
- package/dist/esm/chunks/chunk-E43OK6IZ.js +0 -3
- package/dist/esm/chunks/chunk-LWOMFZ4C.js +0 -3
- package/dist/esm/chunks/chunk-MCXU6QF3.js +0 -3
- package/dist/esm/chunks/chunk-ODCBJ22O.js +0 -3
- package/dist/esm/chunks/chunk-TVDAY42P.js +0 -3
- package/dist/esm/chunks/chunk-VAF4KNDP.js +0 -3
- package/dist/esm/chunks/chunk-ZDPD2MPQ.js +0 -3
- package/dist/esm/chunks/metrics-56RIK7JQ.js +0 -3
- /package/dist/esm/chunks/{chunk-ZDPD2MPQ.js.map → chunk-MKUA6QTB.js.map} +0 -0
- /package/dist/esm/chunks/{metrics-56RIK7JQ.js.map → metrics-6LW2N3GU.js.map} +0 -0
|
@@ -1,3 +1,672 @@
|
|
|
1
1
|
/* (c) 2025-2026 Asymmetric Effort, LLC. MIT LICENSE */
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
assertSecureUrl
|
|
4
|
+
} from "./esm/chunks/chunk-BLIAKWAU.js";
|
|
5
|
+
import {
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState
|
|
10
|
+
} from "./esm/chunks/chunk-CWCWXKVV.js";
|
|
11
|
+
import "./esm/chunks/chunk-MKUA6QTB.js";
|
|
12
|
+
|
|
13
|
+
// src/client/rest.ts
|
|
14
|
+
var RestError = class extends Error {
|
|
15
|
+
constructor(message, status, statusText, data, config) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "RestError";
|
|
18
|
+
this.status = status;
|
|
19
|
+
this.statusText = statusText;
|
|
20
|
+
this.data = data;
|
|
21
|
+
this.config = config;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function parseResponseHeaders(headers) {
|
|
25
|
+
const result = {};
|
|
26
|
+
headers.forEach((value, key) => {
|
|
27
|
+
result[key] = value;
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function buildURL(baseURL, path) {
|
|
32
|
+
const base = baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL;
|
|
33
|
+
const rel = path.startsWith("/") ? path : "/" + path;
|
|
34
|
+
return base + rel;
|
|
35
|
+
}
|
|
36
|
+
function createRestClient(config) {
|
|
37
|
+
const {
|
|
38
|
+
baseURL,
|
|
39
|
+
headers: defaultHeaders = {},
|
|
40
|
+
timeout: defaultTimeout,
|
|
41
|
+
interceptors = {}
|
|
42
|
+
} = config;
|
|
43
|
+
const requestInterceptors = interceptors.request ?? [];
|
|
44
|
+
const responseInterceptors = interceptors.response ?? [];
|
|
45
|
+
const errorInterceptors = interceptors.error ?? [];
|
|
46
|
+
async function request(method, path, body, opts) {
|
|
47
|
+
let reqConfig = {
|
|
48
|
+
url: buildURL(baseURL, path),
|
|
49
|
+
method,
|
|
50
|
+
headers: {
|
|
51
|
+
...defaultHeaders,
|
|
52
|
+
...opts?.headers ?? {}
|
|
53
|
+
},
|
|
54
|
+
body,
|
|
55
|
+
signal: opts?.signal,
|
|
56
|
+
timeout: opts?.timeout ?? defaultTimeout
|
|
57
|
+
};
|
|
58
|
+
if (body !== void 0 && body !== null && !reqConfig.headers["Content-Type"]) {
|
|
59
|
+
reqConfig.headers["Content-Type"] = "application/json";
|
|
60
|
+
}
|
|
61
|
+
for (const interceptor of requestInterceptors) {
|
|
62
|
+
reqConfig = await interceptor(reqConfig);
|
|
63
|
+
}
|
|
64
|
+
let timeoutId;
|
|
65
|
+
let controller;
|
|
66
|
+
if (reqConfig.timeout && reqConfig.timeout > 0) {
|
|
67
|
+
controller = new AbortController();
|
|
68
|
+
timeoutId = setTimeout(() => {
|
|
69
|
+
controller.abort();
|
|
70
|
+
}, reqConfig.timeout);
|
|
71
|
+
if (reqConfig.signal) {
|
|
72
|
+
const externalSignal = reqConfig.signal;
|
|
73
|
+
if (externalSignal.aborted) {
|
|
74
|
+
controller.abort();
|
|
75
|
+
} else {
|
|
76
|
+
externalSignal.addEventListener("abort", () => {
|
|
77
|
+
controller.abort();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const fetchSignal = controller ? controller.signal : reqConfig.signal;
|
|
83
|
+
const fetchInit = {
|
|
84
|
+
method: reqConfig.method,
|
|
85
|
+
headers: reqConfig.headers,
|
|
86
|
+
signal: fetchSignal
|
|
87
|
+
};
|
|
88
|
+
if (body !== void 0 && body !== null) {
|
|
89
|
+
fetchInit.body = JSON.stringify(body);
|
|
90
|
+
}
|
|
91
|
+
let response;
|
|
92
|
+
try {
|
|
93
|
+
assertSecureUrl(reqConfig.url);
|
|
94
|
+
response = await fetch(reqConfig.url, fetchInit);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
if (timeoutId !== void 0) {
|
|
97
|
+
clearTimeout(timeoutId);
|
|
98
|
+
}
|
|
99
|
+
const isAbort = err instanceof DOMException && err.name === "AbortError";
|
|
100
|
+
const message = isAbort ? `Request timeout after ${reqConfig.timeout}ms` : err instanceof Error ? err.message : "Network error";
|
|
101
|
+
let restError = new RestError(message, 0, "", null, reqConfig);
|
|
102
|
+
for (const interceptor of errorInterceptors) {
|
|
103
|
+
restError = await interceptor(restError);
|
|
104
|
+
}
|
|
105
|
+
throw restError;
|
|
106
|
+
}
|
|
107
|
+
if (timeoutId !== void 0) {
|
|
108
|
+
clearTimeout(timeoutId);
|
|
109
|
+
}
|
|
110
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
111
|
+
let data;
|
|
112
|
+
if (contentType.includes("application/json")) {
|
|
113
|
+
data = await response.json();
|
|
114
|
+
} else {
|
|
115
|
+
const text = await response.text();
|
|
116
|
+
try {
|
|
117
|
+
data = JSON.parse(text);
|
|
118
|
+
} catch {
|
|
119
|
+
data = text;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const parsedHeaders = parseResponseHeaders(response.headers);
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
let restError = new RestError(
|
|
125
|
+
`Request failed with status ${response.status}`,
|
|
126
|
+
response.status,
|
|
127
|
+
response.statusText,
|
|
128
|
+
data,
|
|
129
|
+
reqConfig
|
|
130
|
+
);
|
|
131
|
+
for (const interceptor of errorInterceptors) {
|
|
132
|
+
restError = await interceptor(restError);
|
|
133
|
+
}
|
|
134
|
+
throw restError;
|
|
135
|
+
}
|
|
136
|
+
let restResponse = {
|
|
137
|
+
data,
|
|
138
|
+
status: response.status,
|
|
139
|
+
headers: parsedHeaders,
|
|
140
|
+
ok: response.ok
|
|
141
|
+
};
|
|
142
|
+
for (const interceptor of responseInterceptors) {
|
|
143
|
+
restResponse = interceptor(restResponse);
|
|
144
|
+
}
|
|
145
|
+
return restResponse;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
get(path, opts) {
|
|
149
|
+
return request("GET", path, void 0, opts);
|
|
150
|
+
},
|
|
151
|
+
post(path, body, opts) {
|
|
152
|
+
return request("POST", path, body, opts);
|
|
153
|
+
},
|
|
154
|
+
put(path, body, opts) {
|
|
155
|
+
return request("PUT", path, body, opts);
|
|
156
|
+
},
|
|
157
|
+
patch(path, body, opts) {
|
|
158
|
+
return request("PATCH", path, body, opts);
|
|
159
|
+
},
|
|
160
|
+
delete(path, opts) {
|
|
161
|
+
return request("DELETE", path, void 0, opts);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function useRest(client, path, opts) {
|
|
166
|
+
const method = opts?.method ?? "GET";
|
|
167
|
+
const body = opts?.body;
|
|
168
|
+
const deps = opts?.deps ?? [];
|
|
169
|
+
const enabled = opts?.enabled ?? true;
|
|
170
|
+
const [data, setData] = useState(null);
|
|
171
|
+
const [loading, setLoading] = useState(enabled);
|
|
172
|
+
const [error, setError] = useState(null);
|
|
173
|
+
const controllerRef = useRef(null);
|
|
174
|
+
const mountedRef = useRef(true);
|
|
175
|
+
const fetchData = useCallback(() => {
|
|
176
|
+
if (!enabled) {
|
|
177
|
+
setLoading(false);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (controllerRef.current) {
|
|
181
|
+
controllerRef.current.abort();
|
|
182
|
+
}
|
|
183
|
+
const controller = new AbortController();
|
|
184
|
+
controllerRef.current = controller;
|
|
185
|
+
setLoading(true);
|
|
186
|
+
setError(null);
|
|
187
|
+
const requestOpts = { signal: controller.signal };
|
|
188
|
+
let promise;
|
|
189
|
+
const upperMethod = method.toUpperCase();
|
|
190
|
+
if (upperMethod === "POST") {
|
|
191
|
+
promise = client.post(path, body, requestOpts);
|
|
192
|
+
} else if (upperMethod === "PUT") {
|
|
193
|
+
promise = client.put(path, body, requestOpts);
|
|
194
|
+
} else if (upperMethod === "PATCH") {
|
|
195
|
+
promise = client.patch(path, body, requestOpts);
|
|
196
|
+
} else if (upperMethod === "DELETE") {
|
|
197
|
+
promise = client.delete(path, requestOpts);
|
|
198
|
+
} else {
|
|
199
|
+
promise = client.get(path, requestOpts);
|
|
200
|
+
}
|
|
201
|
+
promise.then((response) => {
|
|
202
|
+
if (mountedRef.current && !controller.signal.aborted) {
|
|
203
|
+
setData(response.data);
|
|
204
|
+
setLoading(false);
|
|
205
|
+
}
|
|
206
|
+
}).catch((err) => {
|
|
207
|
+
if (mountedRef.current && !controller.signal.aborted) {
|
|
208
|
+
setError(
|
|
209
|
+
err instanceof RestError ? err : new RestError(err instanceof Error ? err.message : "Unknown error", 0, "", null, {
|
|
210
|
+
url: path,
|
|
211
|
+
method: upperMethod,
|
|
212
|
+
headers: {}
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
setLoading(false);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}, [client, path, method, body, enabled, ...deps]);
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
mountedRef.current = true;
|
|
221
|
+
fetchData();
|
|
222
|
+
return () => {
|
|
223
|
+
mountedRef.current = false;
|
|
224
|
+
if (controllerRef.current) {
|
|
225
|
+
controllerRef.current.abort();
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}, [fetchData]);
|
|
229
|
+
const refetch = useCallback(() => {
|
|
230
|
+
fetchData();
|
|
231
|
+
}, [fetchData]);
|
|
232
|
+
return { data, loading, error, refetch };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/client/protobuf.ts
|
|
236
|
+
function encodeVarint(value) {
|
|
237
|
+
const bytes = [];
|
|
238
|
+
let v = value >>> 0;
|
|
239
|
+
while (v > 127) {
|
|
240
|
+
bytes.push(v & 127 | 128);
|
|
241
|
+
v >>>= 7;
|
|
242
|
+
}
|
|
243
|
+
bytes.push(v & 127);
|
|
244
|
+
return bytes;
|
|
245
|
+
}
|
|
246
|
+
function decodeVarint(bytes, offset) {
|
|
247
|
+
let result = 0;
|
|
248
|
+
let shift = 0;
|
|
249
|
+
let pos = offset;
|
|
250
|
+
while (pos < bytes.length) {
|
|
251
|
+
const b = bytes[pos];
|
|
252
|
+
result |= (b & 127) << shift;
|
|
253
|
+
pos++;
|
|
254
|
+
if ((b & 128) === 0) {
|
|
255
|
+
return [result >>> 0, pos];
|
|
256
|
+
}
|
|
257
|
+
shift += 7;
|
|
258
|
+
if (shift >= 35) {
|
|
259
|
+
throw new Error("Varint too long");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
throw new Error("Unexpected end of data while decoding varint");
|
|
263
|
+
}
|
|
264
|
+
var WIRE_VARINT = 0;
|
|
265
|
+
var WIRE_64BIT = 1;
|
|
266
|
+
var WIRE_LENGTH_DELIMITED = 2;
|
|
267
|
+
function wireTypeFor(type) {
|
|
268
|
+
switch (type) {
|
|
269
|
+
case "int32":
|
|
270
|
+
case "uint32":
|
|
271
|
+
case "bool":
|
|
272
|
+
case "enum":
|
|
273
|
+
return WIRE_VARINT;
|
|
274
|
+
case "float64":
|
|
275
|
+
return WIRE_64BIT;
|
|
276
|
+
case "string":
|
|
277
|
+
case "bytes":
|
|
278
|
+
return WIRE_LENGTH_DELIMITED;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function encodeFieldKey(tag, wireType) {
|
|
282
|
+
return encodeVarint(tag << 3 | wireType);
|
|
283
|
+
}
|
|
284
|
+
function encodeFieldValue(type, value) {
|
|
285
|
+
switch (type) {
|
|
286
|
+
case "int32": {
|
|
287
|
+
const n = value;
|
|
288
|
+
return encodeVarint(n | 0);
|
|
289
|
+
}
|
|
290
|
+
case "uint32":
|
|
291
|
+
return encodeVarint(value >>> 0);
|
|
292
|
+
case "bool":
|
|
293
|
+
return encodeVarint(value ? 1 : 0);
|
|
294
|
+
case "enum":
|
|
295
|
+
return encodeVarint(value >>> 0);
|
|
296
|
+
case "float64": {
|
|
297
|
+
const buf = new ArrayBuffer(8);
|
|
298
|
+
new DataView(buf).setFloat64(0, value, true);
|
|
299
|
+
return Array.from(new Uint8Array(buf));
|
|
300
|
+
}
|
|
301
|
+
case "string": {
|
|
302
|
+
const encoded = new TextEncoder().encode(value);
|
|
303
|
+
return [...encodeVarint(encoded.length), ...encoded];
|
|
304
|
+
}
|
|
305
|
+
case "bytes": {
|
|
306
|
+
const data = value;
|
|
307
|
+
return [...encodeVarint(data.length), ...data];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function decodeFieldValue(type, wireType, bytes, offset) {
|
|
312
|
+
switch (wireType) {
|
|
313
|
+
case WIRE_VARINT: {
|
|
314
|
+
const [val, newOffset] = decodeVarint(bytes, offset);
|
|
315
|
+
switch (type) {
|
|
316
|
+
case "bool":
|
|
317
|
+
return [val !== 0, newOffset];
|
|
318
|
+
case "int32":
|
|
319
|
+
return [val | 0, newOffset];
|
|
320
|
+
// sign-extend
|
|
321
|
+
case "uint32":
|
|
322
|
+
case "enum":
|
|
323
|
+
return [val >>> 0, newOffset];
|
|
324
|
+
default:
|
|
325
|
+
return [val, newOffset];
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
case WIRE_64BIT: {
|
|
329
|
+
if (offset + 8 > bytes.length) {
|
|
330
|
+
throw new Error("Unexpected end of data while decoding 64-bit value");
|
|
331
|
+
}
|
|
332
|
+
const buf = new ArrayBuffer(8);
|
|
333
|
+
const view = new Uint8Array(buf);
|
|
334
|
+
for (let i = 0; i < 8; i++) {
|
|
335
|
+
view[i] = bytes[offset + i] ?? 0;
|
|
336
|
+
}
|
|
337
|
+
const dv = new DataView(buf);
|
|
338
|
+
return [dv.getFloat64(0, true), offset + 8];
|
|
339
|
+
}
|
|
340
|
+
case WIRE_LENGTH_DELIMITED: {
|
|
341
|
+
const [len, dataStart] = decodeVarint(bytes, offset);
|
|
342
|
+
if (dataStart + len > bytes.length) {
|
|
343
|
+
throw new Error("Unexpected end of data while decoding length-delimited value");
|
|
344
|
+
}
|
|
345
|
+
const slice = bytes.slice(dataStart, dataStart + len);
|
|
346
|
+
if (type === "string") {
|
|
347
|
+
return [new TextDecoder().decode(slice), dataStart + len];
|
|
348
|
+
}
|
|
349
|
+
return [slice, dataStart + len];
|
|
350
|
+
}
|
|
351
|
+
default:
|
|
352
|
+
throw new Error(`Unknown wire type: ${wireType}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function defineMessage(name, fields) {
|
|
356
|
+
const tagToField = /* @__PURE__ */ new Map();
|
|
357
|
+
for (const [fieldName, descriptor] of Object.entries(fields)) {
|
|
358
|
+
tagToField.set(descriptor.tag, { fieldName, descriptor });
|
|
359
|
+
}
|
|
360
|
+
function encode(obj) {
|
|
361
|
+
const out = [];
|
|
362
|
+
const record = obj;
|
|
363
|
+
for (const [fieldName, descriptor] of Object.entries(fields)) {
|
|
364
|
+
const value = record[fieldName];
|
|
365
|
+
if (value === void 0 || value === null) continue;
|
|
366
|
+
const wt = wireTypeFor(descriptor.type);
|
|
367
|
+
if (descriptor.repeated) {
|
|
368
|
+
const arr = value;
|
|
369
|
+
for (const item of arr) {
|
|
370
|
+
out.push(...encodeFieldKey(descriptor.tag, wt));
|
|
371
|
+
out.push(...encodeFieldValue(descriptor.type, item));
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
out.push(...encodeFieldKey(descriptor.tag, wt));
|
|
375
|
+
out.push(...encodeFieldValue(descriptor.type, value));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return new Uint8Array(out);
|
|
379
|
+
}
|
|
380
|
+
function decode(bytes) {
|
|
381
|
+
const result = {};
|
|
382
|
+
for (const [fieldName, descriptor] of Object.entries(fields)) {
|
|
383
|
+
if (descriptor.repeated) {
|
|
384
|
+
result[fieldName] = [];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
let offset = 0;
|
|
388
|
+
while (offset < bytes.length) {
|
|
389
|
+
const [keyVarint, newOffset] = decodeVarint(bytes, offset);
|
|
390
|
+
const tag = keyVarint >>> 3;
|
|
391
|
+
const wireType = keyVarint & 7;
|
|
392
|
+
offset = newOffset;
|
|
393
|
+
const entry = tagToField.get(tag);
|
|
394
|
+
if (!entry) {
|
|
395
|
+
offset = skipField(wireType, bytes, offset);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const [value, nextOffset] = decodeFieldValue(entry.descriptor.type, wireType, bytes, offset);
|
|
399
|
+
offset = nextOffset;
|
|
400
|
+
if (entry.descriptor.repeated) {
|
|
401
|
+
result[entry.fieldName].push(value);
|
|
402
|
+
} else {
|
|
403
|
+
result[entry.fieldName] = value;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return result;
|
|
407
|
+
}
|
|
408
|
+
return { name, fields, encode, decode };
|
|
409
|
+
}
|
|
410
|
+
function skipField(wireType, bytes, offset) {
|
|
411
|
+
switch (wireType) {
|
|
412
|
+
case WIRE_VARINT: {
|
|
413
|
+
const [, next] = decodeVarint(bytes, offset);
|
|
414
|
+
return next;
|
|
415
|
+
}
|
|
416
|
+
case WIRE_64BIT:
|
|
417
|
+
return offset + 8;
|
|
418
|
+
case WIRE_LENGTH_DELIMITED: {
|
|
419
|
+
const [len, dataStart] = decodeVarint(bytes, offset);
|
|
420
|
+
return dataStart + len;
|
|
421
|
+
}
|
|
422
|
+
default:
|
|
423
|
+
throw new Error(`Cannot skip unknown wire type: ${wireType}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function encodeGrpcWebFrame(data, flags = 0) {
|
|
427
|
+
const frame = new Uint8Array(5 + data.length);
|
|
428
|
+
frame[0] = flags;
|
|
429
|
+
const dv = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);
|
|
430
|
+
dv.setUint32(1, data.length, false);
|
|
431
|
+
frame.set(data, 5);
|
|
432
|
+
return frame;
|
|
433
|
+
}
|
|
434
|
+
function decodeGrpcWebFrame(bytes) {
|
|
435
|
+
if (bytes.length < 5) {
|
|
436
|
+
throw new Error("gRPC-Web frame too short");
|
|
437
|
+
}
|
|
438
|
+
const flags = bytes[0] ?? 0;
|
|
439
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
440
|
+
const length = dv.getUint32(1, false);
|
|
441
|
+
if (bytes.length < 5 + length) {
|
|
442
|
+
throw new Error("gRPC-Web frame data incomplete");
|
|
443
|
+
}
|
|
444
|
+
const data = bytes.slice(5, 5 + length);
|
|
445
|
+
return [flags, data, 5 + length];
|
|
446
|
+
}
|
|
447
|
+
function createGrpcWebClient(config) {
|
|
448
|
+
const { baseURL, headers: extraHeaders } = config;
|
|
449
|
+
async function unary(service, method, reqType, resType, request) {
|
|
450
|
+
const reqBytes = reqType.encode(request);
|
|
451
|
+
const frame = encodeGrpcWebFrame(reqBytes);
|
|
452
|
+
const url = `${baseURL.replace(/\/+$/, "")}/${service}/${method}`;
|
|
453
|
+
const hdrs = {
|
|
454
|
+
"Content-Type": "application/grpc-web+proto",
|
|
455
|
+
Accept: "application/grpc-web+proto",
|
|
456
|
+
"X-Grpc-Web": "1",
|
|
457
|
+
...extraHeaders
|
|
458
|
+
};
|
|
459
|
+
assertSecureUrl(url);
|
|
460
|
+
const response = await fetch(url, {
|
|
461
|
+
method: "POST",
|
|
462
|
+
headers: hdrs,
|
|
463
|
+
body: frame.buffer
|
|
464
|
+
});
|
|
465
|
+
if (!response.ok) {
|
|
466
|
+
throw new Error(`gRPC-Web request failed: ${response.status} ${response.statusText}`);
|
|
467
|
+
}
|
|
468
|
+
const responseBytes = new Uint8Array(await response.arrayBuffer());
|
|
469
|
+
let offset = 0;
|
|
470
|
+
while (offset < responseBytes.length) {
|
|
471
|
+
const [flags, data, consumed] = decodeGrpcWebFrame(responseBytes.subarray(offset));
|
|
472
|
+
offset += consumed;
|
|
473
|
+
if ((flags & 128) === 0) {
|
|
474
|
+
return resType.decode(data);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
throw new Error("No data frame found in gRPC-Web response");
|
|
478
|
+
}
|
|
479
|
+
return { unary };
|
|
480
|
+
}
|
|
481
|
+
function useProto(client, service, method, reqType, resType, request, opts) {
|
|
482
|
+
const [data, setData] = useState(null);
|
|
483
|
+
const [loading, setLoading] = useState(false);
|
|
484
|
+
const [error, setError] = useState(null);
|
|
485
|
+
const mountedRef = useRef(true);
|
|
486
|
+
const requestRef = useRef(request);
|
|
487
|
+
requestRef.current = request;
|
|
488
|
+
const enabled = opts?.enabled !== false;
|
|
489
|
+
const refetch = useCallback(() => {
|
|
490
|
+
if (!enabled) return;
|
|
491
|
+
setLoading(true);
|
|
492
|
+
setError(null);
|
|
493
|
+
client.unary(service, method, reqType, resType, requestRef.current).then((res) => {
|
|
494
|
+
if (mountedRef.current) {
|
|
495
|
+
setData(res);
|
|
496
|
+
setLoading(false);
|
|
497
|
+
}
|
|
498
|
+
}).catch((err) => {
|
|
499
|
+
if (mountedRef.current) {
|
|
500
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
501
|
+
setLoading(false);
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}, [client, service, method, reqType, resType, enabled]);
|
|
505
|
+
useEffect(() => {
|
|
506
|
+
mountedRef.current = true;
|
|
507
|
+
refetch();
|
|
508
|
+
return () => {
|
|
509
|
+
mountedRef.current = false;
|
|
510
|
+
};
|
|
511
|
+
}, [refetch]);
|
|
512
|
+
return { data, loading, error, refetch };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/client/graphql.ts
|
|
516
|
+
function gql(strings, ...values) {
|
|
517
|
+
let result = "";
|
|
518
|
+
for (let i = 0; i < strings.length; i++) {
|
|
519
|
+
result += strings[i];
|
|
520
|
+
if (i < values.length) {
|
|
521
|
+
const val = String(values[i]);
|
|
522
|
+
if (/[{}():]/.test(val)) {
|
|
523
|
+
if (typeof console !== "undefined") {
|
|
524
|
+
console.warn(
|
|
525
|
+
"[SpecifyJS] gql: Interpolated value contains GraphQL metacharacters. Use variables parameter instead of string interpolation to prevent injection."
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
result += val;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return result.replace(/\s+/g, " ").trim();
|
|
533
|
+
}
|
|
534
|
+
function createGraphQLClient(config) {
|
|
535
|
+
const { url, headers: configHeaders, credentials, cache: cacheEnabled = false } = config;
|
|
536
|
+
const MAX_CACHE_SIZE = 100;
|
|
537
|
+
const responseCache = /* @__PURE__ */ new Map();
|
|
538
|
+
function buildCacheKey(query, variables) {
|
|
539
|
+
return JSON.stringify({ query, variables });
|
|
540
|
+
}
|
|
541
|
+
async function execute(query, variables) {
|
|
542
|
+
const reqHeaders = {
|
|
543
|
+
"Content-Type": "application/json",
|
|
544
|
+
...configHeaders
|
|
545
|
+
};
|
|
546
|
+
const body = JSON.stringify({ query, variables });
|
|
547
|
+
assertSecureUrl(url);
|
|
548
|
+
const response = await fetch(url, {
|
|
549
|
+
method: "POST",
|
|
550
|
+
headers: reqHeaders,
|
|
551
|
+
credentials,
|
|
552
|
+
body
|
|
553
|
+
});
|
|
554
|
+
if (!response.ok) {
|
|
555
|
+
throw new Error(`GraphQL request failed with status ${response.status}`);
|
|
556
|
+
}
|
|
557
|
+
const json = await response.json();
|
|
558
|
+
return {
|
|
559
|
+
data: json.data ?? null,
|
|
560
|
+
errors: json.errors ?? null,
|
|
561
|
+
...json.extensions !== void 0 ? { extensions: json.extensions } : {}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
const client = {
|
|
565
|
+
async query(query, variables) {
|
|
566
|
+
if (cacheEnabled) {
|
|
567
|
+
const key = buildCacheKey(query, variables);
|
|
568
|
+
const cached = responseCache.get(key);
|
|
569
|
+
if (cached) {
|
|
570
|
+
return cached;
|
|
571
|
+
}
|
|
572
|
+
const result = await execute(query, variables);
|
|
573
|
+
if (responseCache.size >= MAX_CACHE_SIZE) {
|
|
574
|
+
const oldest = responseCache.keys().next().value;
|
|
575
|
+
if (oldest !== void 0) responseCache.delete(oldest);
|
|
576
|
+
}
|
|
577
|
+
responseCache.set(key, result);
|
|
578
|
+
return result;
|
|
579
|
+
}
|
|
580
|
+
return execute(query, variables);
|
|
581
|
+
},
|
|
582
|
+
async mutate(mutation, variables) {
|
|
583
|
+
return execute(mutation, variables);
|
|
584
|
+
},
|
|
585
|
+
clearCache() {
|
|
586
|
+
responseCache.clear();
|
|
587
|
+
},
|
|
588
|
+
invalidate(query) {
|
|
589
|
+
for (const key of responseCache.keys()) {
|
|
590
|
+
try {
|
|
591
|
+
const parsed = JSON.parse(key);
|
|
592
|
+
if (parsed.query === query) {
|
|
593
|
+
responseCache.delete(key);
|
|
594
|
+
}
|
|
595
|
+
} catch {
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
return client;
|
|
601
|
+
}
|
|
602
|
+
function useQuery(client, query, opts) {
|
|
603
|
+
const variables = opts?.variables;
|
|
604
|
+
const deps = opts?.deps;
|
|
605
|
+
const enabled = opts?.enabled ?? true;
|
|
606
|
+
const [data, setData] = useState(null);
|
|
607
|
+
const [loading, setLoading] = useState(enabled);
|
|
608
|
+
const [error, setError] = useState(null);
|
|
609
|
+
const fetchIdRef = useRef(0);
|
|
610
|
+
const fetchData = useCallback(() => {
|
|
611
|
+
if (!enabled) return;
|
|
612
|
+
const id = ++fetchIdRef.current;
|
|
613
|
+
setLoading(true);
|
|
614
|
+
setError(null);
|
|
615
|
+
client.query(query, variables).then((result) => {
|
|
616
|
+
if (fetchIdRef.current !== id) return;
|
|
617
|
+
setData(result.data);
|
|
618
|
+
setError(result.errors);
|
|
619
|
+
setLoading(false);
|
|
620
|
+
}).catch((err) => {
|
|
621
|
+
if (fetchIdRef.current !== id) return;
|
|
622
|
+
setError([{ message: err instanceof Error ? err.message : String(err) }]);
|
|
623
|
+
setLoading(false);
|
|
624
|
+
});
|
|
625
|
+
}, [client, query, variables, enabled]);
|
|
626
|
+
const effectDeps = deps ? [fetchData, ...deps] : [fetchData];
|
|
627
|
+
useEffect(() => {
|
|
628
|
+
fetchData();
|
|
629
|
+
}, effectDeps);
|
|
630
|
+
return { data, loading, error, refetch: fetchData };
|
|
631
|
+
}
|
|
632
|
+
function useMutation(client, mutation) {
|
|
633
|
+
const [data, setData] = useState(null);
|
|
634
|
+
const [loading, setLoading] = useState(false);
|
|
635
|
+
const [error, setError] = useState(null);
|
|
636
|
+
const mutateFn = async (variables) => {
|
|
637
|
+
setLoading(true);
|
|
638
|
+
setError(null);
|
|
639
|
+
try {
|
|
640
|
+
const result = await client.mutate(mutation, variables);
|
|
641
|
+
setData(result.data);
|
|
642
|
+
setError(result.errors);
|
|
643
|
+
setLoading(false);
|
|
644
|
+
return result;
|
|
645
|
+
} catch (err) {
|
|
646
|
+
const errors = [
|
|
647
|
+
{ message: err instanceof Error ? err.message : String(err) }
|
|
648
|
+
];
|
|
649
|
+
setError(errors);
|
|
650
|
+
setLoading(false);
|
|
651
|
+
return { data: null, errors, extensions: void 0 };
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
const mutate = useCallback(
|
|
655
|
+
((...args) => mutateFn(args[0])),
|
|
656
|
+
[client, mutation]
|
|
657
|
+
);
|
|
658
|
+
return [mutate, { data, loading, error }];
|
|
659
|
+
}
|
|
660
|
+
export {
|
|
661
|
+
RestError,
|
|
662
|
+
createGraphQLClient,
|
|
663
|
+
createGrpcWebClient,
|
|
664
|
+
createRestClient,
|
|
665
|
+
defineMessage,
|
|
666
|
+
gql,
|
|
667
|
+
useMutation,
|
|
668
|
+
useProto,
|
|
669
|
+
useQuery,
|
|
670
|
+
useRest
|
|
671
|
+
};
|
|
3
672
|
//# sourceMappingURL=index.js.map
|