@mdxui/do 4.0.0 → 4.0.8
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/app/index.d.ts +32 -186
- package/dist/app/index.js +19 -11
- package/dist/auth/index.d.ts +48 -0
- package/dist/auth/index.js +4 -0
- package/dist/{breadcrumbs-C9Qn3S7d.d.ts → breadcrumbs-DltlCiHt.d.ts} +3 -3
- package/dist/chunk-2FWXT4HH.js +576 -0
- package/dist/chunk-2FWXT4HH.js.map +1 -0
- package/dist/chunk-5PC6U46L.js +604 -0
- package/dist/chunk-5PC6U46L.js.map +1 -0
- package/dist/chunk-63VCRTDQ.js +2505 -0
- package/dist/chunk-63VCRTDQ.js.map +1 -0
- package/dist/chunk-7J3RSIG4.js +178 -0
- package/dist/chunk-7J3RSIG4.js.map +1 -0
- package/dist/chunk-7QCTRNEJ.js +173 -0
- package/dist/chunk-7QCTRNEJ.js.map +1 -0
- package/dist/chunk-7TFHUKS7.js +66 -0
- package/dist/chunk-7TFHUKS7.js.map +1 -0
- package/dist/{chunk-LJIWB7KE.js → chunk-BU5HMHGQ.js} +3 -3
- package/dist/chunk-BU5HMHGQ.js.map +1 -0
- package/dist/{chunk-GGO5GW72.js → chunk-BZURBNFD.js} +305 -51
- package/dist/chunk-BZURBNFD.js.map +1 -0
- package/dist/{chunk-NA652ART.js → chunk-FM2RTAHV.js} +5 -65
- package/dist/chunk-FM2RTAHV.js.map +1 -0
- package/dist/{chunk-WMNT4OIE.js → chunk-HC4PBXV4.js} +131 -58
- package/dist/chunk-HC4PBXV4.js.map +1 -0
- package/dist/{chunk-Y52IEYVM.js → chunk-JPZ6RZJE.js} +78 -45
- package/dist/chunk-JPZ6RZJE.js.map +1 -0
- package/dist/{chunk-OVLO7UOH.js → chunk-KLN5OTQH.js} +168 -361
- package/dist/chunk-KLN5OTQH.js.map +1 -0
- package/dist/chunk-LCYBQR35.js +79 -0
- package/dist/chunk-LCYBQR35.js.map +1 -0
- package/dist/chunk-PJYGRD7N.js +216 -0
- package/dist/chunk-PJYGRD7N.js.map +1 -0
- package/dist/chunk-QEXY4FZV.js +292 -0
- package/dist/chunk-QEXY4FZV.js.map +1 -0
- package/dist/chunk-SX4IIE2R.js +53 -0
- package/dist/chunk-SX4IIE2R.js.map +1 -0
- package/dist/chunk-UCWMSKCW.js +901 -0
- package/dist/chunk-UCWMSKCW.js.map +1 -0
- package/dist/{chunk-5SHZZC7L.js → chunk-WC6SFBAF.js} +59 -6
- package/dist/chunk-WC6SFBAF.js.map +1 -0
- package/dist/chunk-WIKU77ZY.js +18 -0
- package/dist/chunk-WIKU77ZY.js.map +1 -0
- package/dist/chunk-X3AWNFBF.js +47 -0
- package/dist/chunk-X3AWNFBF.js.map +1 -0
- package/dist/chunk-ZZTQGMLX.js +23 -0
- package/dist/chunk-ZZTQGMLX.js.map +1 -0
- package/dist/{lib → client}/index.d.ts +97 -345
- package/dist/client/index.js +3 -0
- package/dist/common-DW_JM2dW.d.ts +454 -0
- package/dist/components/index.d.ts +11 -2
- package/dist/components/index.js +8 -3
- package/dist/{config-CxvpD8Y6.d.ts → config-DB14_LhF.d.ts} +1 -1
- package/dist/{do-D27i5bU0.d.ts → do-D37hbmL9.d.ts} +6 -14
- package/dist/dotdo-client-2DkwXHM2.d.ts +344 -0
- package/dist/errors-BOY11CJs.d.ts +373 -0
- package/dist/features/data-browser/index.d.ts +51 -0
- package/dist/features/data-browser/index.js +12 -0
- package/dist/features/data-browser/index.js.map +1 -0
- package/dist/features/data-grid/index.d.ts +22 -0
- package/dist/features/data-grid/index.js +12 -0
- package/dist/features/data-grid/index.js.map +1 -0
- package/dist/features/document-editor/index.d.ts +26 -0
- package/dist/features/document-editor/index.js +12 -0
- package/dist/features/document-editor/index.js.map +1 -0
- package/dist/features/function-editor/index.d.ts +215 -0
- package/dist/features/function-editor/index.js +7 -0
- package/dist/features/function-editor/index.js.map +1 -0
- package/dist/hooks/index.d.ts +64 -7
- package/dist/hooks/index.js +8 -7
- package/dist/hooks/things/index.d.ts +5 -297
- package/dist/hooks/things/index.js +6 -6
- package/dist/index-C0m9UI6W.d.ts +444 -0
- package/dist/index.d.ts +42 -32
- package/dist/index.js +21 -13
- package/dist/providers/index.d.ts +16 -28
- package/dist/providers/index.js +3 -3
- package/dist/schemas/index.d.ts +4551 -109
- package/dist/schemas/index.js +2 -260
- package/dist/schemas/index.js.map +1 -1
- package/dist/shell/index.d.ts +92 -0
- package/dist/shell/index.js +6 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/{thing-BF25aUtJ.d.ts → thing-Dc3AE2XI.d.ts} +22 -22
- package/dist/thing-adapters-aMjF0h9u.d.ts +1214 -0
- package/dist/types/index.d.ts +954 -7521
- package/dist/types/index.js +2 -2
- package/dist/ui-filters-BvrjMP_U.d.ts +108 -0
- package/dist/{errors-DratdVIz.d.ts → utils/index.d.ts} +38 -77
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist-app/assets/index-DWX3479M.js +7 -0
- package/dist-app/assets/index-DWX3479M.js.map +1 -0
- package/dist-app/assets/main-BptePr_C.js +318 -0
- package/dist-app/assets/main-BptePr_C.js.map +1 -0
- package/dist-app/assets/main-CS9jgKzj.css +1 -0
- package/dist-app/index.html +38 -0
- package/package.json +32 -19
- package/dist/agents-2_r9e9i7.d.ts +0 -1043
- package/dist/capnweb-client-Bq78FtEA.d.ts +0 -229
- package/dist/chunk-3XKYQRXY.js +0 -192
- package/dist/chunk-3XKYQRXY.js.map +0 -1
- package/dist/chunk-4KXVN3EQ.js +0 -56
- package/dist/chunk-4KXVN3EQ.js.map +0 -1
- package/dist/chunk-5SHZZC7L.js.map +0 -1
- package/dist/chunk-7UFINK3Q.js +0 -1994
- package/dist/chunk-7UFINK3Q.js.map +0 -1
- package/dist/chunk-GGO5GW72.js.map +0 -1
- package/dist/chunk-JJLAES6W.js +0 -76
- package/dist/chunk-JJLAES6W.js.map +0 -1
- package/dist/chunk-KT52UU3U.js +0 -985
- package/dist/chunk-KT52UU3U.js.map +0 -1
- package/dist/chunk-LJIWB7KE.js.map +0 -1
- package/dist/chunk-NA652ART.js.map +0 -1
- package/dist/chunk-OVLO7UOH.js.map +0 -1
- package/dist/chunk-VRLUXCLD.js +0 -31
- package/dist/chunk-VRLUXCLD.js.map +0 -1
- package/dist/chunk-WMNT4OIE.js.map +0 -1
- package/dist/chunk-Y52IEYVM.js.map +0 -1
- package/dist/lib/index.js +0 -6
- package/dist/query-keys-CZNFikIi.d.ts +0 -153
- package/dist/views/index.d.ts +0 -131
- package/dist/views/index.js +0 -11
- /package/dist/{lib → auth}/index.js.map +0 -0
- /package/dist/{views → client}/index.js.map +0 -0
|
@@ -1,20 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { newWebSocketRpcSession } from 'capnweb';
|
|
3
|
-
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
1
|
+
import { createDOApiClient } from '@dotdo/do/sdk';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
3
|
+
// src/client/dotdo-client.ts
|
|
4
|
+
function normalizeApiItem(item, defaultNs) {
|
|
5
|
+
if (!item || typeof item !== "object") {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const {
|
|
9
|
+
id,
|
|
10
|
+
$id,
|
|
11
|
+
// Canonical format
|
|
12
|
+
$type,
|
|
13
|
+
name,
|
|
14
|
+
createdAt,
|
|
15
|
+
updatedAt,
|
|
16
|
+
data,
|
|
17
|
+
// Canonical format has nested data
|
|
18
|
+
...restData
|
|
19
|
+
} = item;
|
|
20
|
+
const entityId = $id ?? id ?? crypto.randomUUID();
|
|
21
|
+
const type = $type ?? item.type ?? "Unknown";
|
|
22
|
+
const entityData = data && typeof data === "object" ? data : restData;
|
|
23
|
+
const derivedName = name ?? entityData.title ?? entityData.label ?? entityData.displayName ?? entityData.email ?? entityData.username ?? `${type} ${entityId.slice(0, 8)}`;
|
|
24
|
+
return {
|
|
25
|
+
id: entityId,
|
|
26
|
+
ns: defaultNs,
|
|
27
|
+
type,
|
|
28
|
+
name: derivedName,
|
|
29
|
+
createdAt: createdAt ? new Date(createdAt) : /* @__PURE__ */ new Date(),
|
|
30
|
+
updatedAt: updatedAt ? new Date(updatedAt) : /* @__PURE__ */ new Date(),
|
|
31
|
+
data: entityData
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createDOClient(baseUrl, options = {}) {
|
|
35
|
+
const rpc = createDOApiClient({
|
|
36
|
+
baseURL: baseUrl,
|
|
37
|
+
token: options.authToken,
|
|
38
|
+
transport: options.transport ?? "http"
|
|
39
|
+
});
|
|
11
40
|
return {
|
|
12
41
|
/**
|
|
13
42
|
* Namespace operations
|
|
14
43
|
*/
|
|
15
44
|
Namespace: {
|
|
16
45
|
async list(_params) {
|
|
17
|
-
|
|
46
|
+
try {
|
|
47
|
+
const result = await rpc.namespaces?.list?.();
|
|
48
|
+
if (Array.isArray(result)) {
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
if (result?.items) {
|
|
52
|
+
return result.items;
|
|
53
|
+
}
|
|
54
|
+
return [{ id: "default", name: "default" }];
|
|
55
|
+
} catch {
|
|
56
|
+
return [{ id: "default", name: "default" }];
|
|
57
|
+
}
|
|
18
58
|
}
|
|
19
59
|
},
|
|
20
60
|
/**
|
|
@@ -23,20 +63,23 @@ function createCapnwebClient(baseUrl, options = {}) {
|
|
|
23
63
|
Schema: {
|
|
24
64
|
async discover(_params) {
|
|
25
65
|
try {
|
|
26
|
-
const
|
|
66
|
+
const result = await rpc.schemas?.list?.();
|
|
67
|
+
const types = Array.isArray(result) ? result : result?.items ?? result?.data ?? [];
|
|
27
68
|
return {
|
|
28
69
|
namespaces: ["default"],
|
|
29
|
-
types:
|
|
30
|
-
|
|
70
|
+
types: types.map(
|
|
71
|
+
(t) => typeof t === "string" ? t : t?.name ?? t
|
|
72
|
+
),
|
|
73
|
+
schemas: types
|
|
31
74
|
};
|
|
32
75
|
} catch (error) {
|
|
33
|
-
console.error("[@mdxui/do] Failed to
|
|
76
|
+
console.error("[@mdxui/do] Failed to discover schemas:", error);
|
|
34
77
|
return { namespaces: ["default"], types: [], schemas: [] };
|
|
35
78
|
}
|
|
36
79
|
},
|
|
37
80
|
async get(params) {
|
|
38
81
|
try {
|
|
39
|
-
const result = await rpc.
|
|
82
|
+
const result = await rpc.schemas?.get?.(params.type);
|
|
40
83
|
return result;
|
|
41
84
|
} catch {
|
|
42
85
|
return null;
|
|
@@ -48,11 +91,35 @@ function createCapnwebClient(baseUrl, options = {}) {
|
|
|
48
91
|
*/
|
|
49
92
|
Thing: {
|
|
50
93
|
async types(params) {
|
|
94
|
+
const ns = params.ns ?? "default";
|
|
51
95
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
96
|
+
const result = await rpc.types?.list?.();
|
|
97
|
+
const types = Array.isArray(result) ? result : result?.items ?? result?.data ?? [];
|
|
98
|
+
if (types.length > 0) {
|
|
99
|
+
return types.map((t) => {
|
|
100
|
+
if (typeof t === "string") {
|
|
101
|
+
return { name: t, ns };
|
|
102
|
+
}
|
|
103
|
+
return { name: t?.name ?? t, ns };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const thingsResult = await rpc.things?.list?.({ limit: 1e3 });
|
|
107
|
+
let rawItems = [];
|
|
108
|
+
if (Array.isArray(thingsResult)) {
|
|
109
|
+
rawItems = thingsResult;
|
|
110
|
+
} else if (thingsResult) {
|
|
111
|
+
rawItems = thingsResult.data || thingsResult.items || thingsResult.result || [];
|
|
112
|
+
}
|
|
113
|
+
const uniqueTypes = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const item of rawItems) {
|
|
115
|
+
const type = item.$type ?? item.type;
|
|
116
|
+
if (type) {
|
|
117
|
+
uniqueTypes.add(type);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return Array.from(uniqueTypes).map((typeName) => ({
|
|
121
|
+
name: typeName,
|
|
122
|
+
ns
|
|
56
123
|
}));
|
|
57
124
|
} catch (error) {
|
|
58
125
|
console.error("[@mdxui/do] Failed to get types:", error);
|
|
@@ -61,19 +128,26 @@ function createCapnwebClient(baseUrl, options = {}) {
|
|
|
61
128
|
},
|
|
62
129
|
async list(params) {
|
|
63
130
|
try {
|
|
131
|
+
const ns = params.ns ?? "default";
|
|
64
132
|
const options2 = {};
|
|
65
133
|
if (params.type) options2.type = params.type;
|
|
134
|
+
if (params.type) options2.$type = params.type;
|
|
66
135
|
if (params.limit !== void 0) options2.limit = params.limit;
|
|
67
136
|
if (params.offset !== void 0) options2.offset = params.offset;
|
|
68
|
-
const result = await rpc.list(options2);
|
|
137
|
+
const result = await rpc.things?.list?.(options2);
|
|
138
|
+
let rawItems = [];
|
|
139
|
+
let total = 0;
|
|
69
140
|
if (Array.isArray(result)) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (result) {
|
|
73
|
-
|
|
74
|
-
|
|
141
|
+
rawItems = result;
|
|
142
|
+
total = result.length;
|
|
143
|
+
} else if (result) {
|
|
144
|
+
rawItems = result.data || result.items || result.result || [];
|
|
145
|
+
total = result.total ?? result.count ?? rawItems.length;
|
|
75
146
|
}
|
|
76
|
-
|
|
147
|
+
const normalizedItems = rawItems.map(
|
|
148
|
+
(item) => normalizeApiItem(item, ns)
|
|
149
|
+
);
|
|
150
|
+
return { data: normalizedItems, total };
|
|
77
151
|
} catch (error) {
|
|
78
152
|
console.error("[@mdxui/do] Failed to list things:", error);
|
|
79
153
|
return { data: [], total: 0 };
|
|
@@ -81,22 +155,42 @@ function createCapnwebClient(baseUrl, options = {}) {
|
|
|
81
155
|
},
|
|
82
156
|
async get(params) {
|
|
83
157
|
try {
|
|
84
|
-
const
|
|
85
|
-
|
|
158
|
+
const ns = params.ns ?? "default";
|
|
159
|
+
let result = await rpc.things?.get?.(params.id);
|
|
160
|
+
if (!result && params.type) {
|
|
161
|
+
result = await rpc.things?.get?.({
|
|
162
|
+
id: params.id,
|
|
163
|
+
type: params.type,
|
|
164
|
+
$type: params.type
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (result) {
|
|
168
|
+
return normalizeApiItem(result, ns);
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
86
171
|
} catch {
|
|
87
172
|
return null;
|
|
88
173
|
}
|
|
89
174
|
},
|
|
90
175
|
async create(params) {
|
|
91
|
-
const
|
|
176
|
+
const payload = {
|
|
177
|
+
$type: params.type,
|
|
178
|
+
...params.data
|
|
179
|
+
};
|
|
180
|
+
const result = await rpc.things?.create?.(payload);
|
|
92
181
|
return result;
|
|
93
182
|
},
|
|
94
183
|
async update(params) {
|
|
95
|
-
const
|
|
184
|
+
const payload = {
|
|
185
|
+
$type: params.type,
|
|
186
|
+
id: params.id,
|
|
187
|
+
...params.data
|
|
188
|
+
};
|
|
189
|
+
const result = await rpc.things?.update?.(params.id, payload);
|
|
96
190
|
return result;
|
|
97
191
|
},
|
|
98
192
|
async delete(params) {
|
|
99
|
-
await rpc.delete(
|
|
193
|
+
await rpc.things?.delete?.(params.id);
|
|
100
194
|
return { success: true };
|
|
101
195
|
},
|
|
102
196
|
async versions(_params) {
|
|
@@ -106,7 +200,7 @@ function createCapnwebClient(baseUrl, options = {}) {
|
|
|
106
200
|
try {
|
|
107
201
|
const options2 = {};
|
|
108
202
|
if (_params.type) options2.type = _params.type;
|
|
109
|
-
const result = await rpc.
|
|
203
|
+
const result = await rpc.things?.stats?.(options2);
|
|
110
204
|
return {
|
|
111
205
|
total: result?.total ?? 0,
|
|
112
206
|
byType: result?.byType ?? {}
|
|
@@ -115,209 +209,19 @@ function createCapnwebClient(baseUrl, options = {}) {
|
|
|
115
209
|
console.error("[@mdxui/do] Failed to get stats:", error);
|
|
116
210
|
return { total: 0, byType: {} };
|
|
117
211
|
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
/**
|
|
121
|
-
* SQL operations (not supported by capnweb servers)
|
|
122
|
-
*/
|
|
123
|
-
SQL: {
|
|
124
|
-
async execute(_params) {
|
|
125
|
-
throw new Error("SQL execution is not supported by this server");
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
// Required for interface compatibility
|
|
129
|
-
dup: () => createCapnwebClient(baseUrl, options),
|
|
130
|
-
onRpcBroken: (callback) => {
|
|
131
|
-
if ("onRpcBroken" in session && typeof session.onRpcBroken === "function") {
|
|
132
|
-
session.onRpcBroken(callback);
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
[Symbol.dispose]: () => {
|
|
136
|
-
if (Symbol.dispose in session) {
|
|
137
|
-
session[Symbol.dispose]();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function $CapnwebContext(url, options) {
|
|
143
|
-
return createCapnwebClient(url, options);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// src/lib/json-rpc-client.ts
|
|
147
|
-
var endpointCache = /* @__PURE__ */ new Map();
|
|
148
|
-
function createJsonRpcClient(baseUrl, options = {}) {
|
|
149
|
-
const rpcUrl = baseUrl.replace(/\/$/, "").replace(/\/rpc$/, "");
|
|
150
|
-
function getAuthHeaders() {
|
|
151
|
-
if (options.authToken) {
|
|
152
|
-
return { Authorization: `Bearer ${options.authToken}` };
|
|
153
|
-
}
|
|
154
|
-
return {};
|
|
155
|
-
}
|
|
156
|
-
async function rpcCall(method, args = []) {
|
|
157
|
-
const response = await fetch(`${rpcUrl}/rpc`, {
|
|
158
|
-
method: "POST",
|
|
159
|
-
headers: {
|
|
160
|
-
"Content-Type": "application/json",
|
|
161
|
-
...getAuthHeaders()
|
|
162
212
|
},
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
return data.result;
|
|
173
|
-
}
|
|
174
|
-
async function restCall(path, init) {
|
|
175
|
-
const response = await fetch(`${rpcUrl}${path}`, {
|
|
176
|
-
...init,
|
|
177
|
-
headers: {
|
|
178
|
-
"Content-Type": "application/json",
|
|
179
|
-
...getAuthHeaders(),
|
|
180
|
-
...init?.headers
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
if (!response.ok) {
|
|
184
|
-
const method = init?.method?.toUpperCase() ?? "GET";
|
|
185
|
-
if (response.status === 404 && method === "GET") {
|
|
186
|
-
return { data: [], count: 0 };
|
|
187
|
-
}
|
|
188
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
189
|
-
}
|
|
190
|
-
return response.json();
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
/**
|
|
194
|
-
* Namespace operations
|
|
195
|
-
*/
|
|
196
|
-
Namespace: {
|
|
197
|
-
async list(_params) {
|
|
198
|
-
return [{ id: "default", name: "default" }];
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
/**
|
|
202
|
-
* Schema operations
|
|
203
|
-
*/
|
|
204
|
-
Schema: {
|
|
205
|
-
async discover(_params) {
|
|
206
|
-
const schemas = await rpcCall("schemas.list", []);
|
|
213
|
+
/**
|
|
214
|
+
* Subscribe to real-time Thing updates
|
|
215
|
+
* @returns Subscription object with unsubscribe method
|
|
216
|
+
*/
|
|
217
|
+
subscribe(_params, _callbacks) {
|
|
218
|
+
console.warn(
|
|
219
|
+
'[@mdxui/do] Thing.subscribe() requires WebSocket transport. Use transport: "ws" for real-time updates.'
|
|
220
|
+
);
|
|
207
221
|
return {
|
|
208
|
-
|
|
209
|
-
types: schemas,
|
|
210
|
-
schemas
|
|
211
|
-
};
|
|
212
|
-
},
|
|
213
|
-
async get(params) {
|
|
214
|
-
const result = await rpcCall("schemas.get", [params.type]);
|
|
215
|
-
return result;
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
/**
|
|
219
|
-
* Thing operations (maps to REST endpoints)
|
|
220
|
-
*/
|
|
221
|
-
Thing: {
|
|
222
|
-
async types(params) {
|
|
223
|
-
try {
|
|
224
|
-
const schemas = await rpcCall("schemas.list", []);
|
|
225
|
-
let validEndpoints = endpointCache.get(rpcUrl);
|
|
226
|
-
if (!validEndpoints) {
|
|
227
|
-
validEndpoints = /* @__PURE__ */ new Set();
|
|
228
|
-
const probeResults = await Promise.all(
|
|
229
|
-
schemas.map(async (type) => {
|
|
230
|
-
const endpoint = getEndpointForType(type);
|
|
231
|
-
try {
|
|
232
|
-
const response = await fetch(`${rpcUrl}${endpoint}`, { method: "HEAD" });
|
|
233
|
-
return { type, exists: response.ok };
|
|
234
|
-
} catch {
|
|
235
|
-
try {
|
|
236
|
-
const response = await fetch(`${rpcUrl}${endpoint}?limit=0`);
|
|
237
|
-
return { type, exists: response.ok };
|
|
238
|
-
} catch {
|
|
239
|
-
return { type, exists: false };
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
|
-
);
|
|
244
|
-
for (const { type, exists } of probeResults) {
|
|
245
|
-
if (exists) {
|
|
246
|
-
validEndpoints.add(type);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
endpointCache.set(rpcUrl, validEndpoints);
|
|
222
|
+
unsubscribe: () => {
|
|
250
223
|
}
|
|
251
|
-
return Array.from(validEndpoints).map((name) => ({
|
|
252
|
-
name,
|
|
253
|
-
ns: params.ns || "default"
|
|
254
|
-
}));
|
|
255
|
-
} catch {
|
|
256
|
-
return ["Noun", "Verb", "Action", "Function"].map((name) => ({
|
|
257
|
-
name,
|
|
258
|
-
ns: params.ns || "default"
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
async list(params) {
|
|
263
|
-
const endpoint = getEndpointForType(params.type || "Thing");
|
|
264
|
-
const response = await restCall(endpoint);
|
|
265
|
-
const items = response.data || response.items || response.result || [];
|
|
266
|
-
return {
|
|
267
|
-
data: items,
|
|
268
|
-
total: response.count ?? items.length
|
|
269
224
|
};
|
|
270
|
-
},
|
|
271
|
-
async get(params) {
|
|
272
|
-
const endpoint = getEndpointForType(params.type);
|
|
273
|
-
const response = await restCall(`${endpoint}/${params.id}`);
|
|
274
|
-
return response.data;
|
|
275
|
-
},
|
|
276
|
-
async create(params) {
|
|
277
|
-
const endpoint = getEndpointForType(params.type);
|
|
278
|
-
const response = await restCall(endpoint, {
|
|
279
|
-
method: "POST",
|
|
280
|
-
body: JSON.stringify(params.data)
|
|
281
|
-
});
|
|
282
|
-
return response.data;
|
|
283
|
-
},
|
|
284
|
-
async update(params) {
|
|
285
|
-
const endpoint = getEndpointForType(params.type);
|
|
286
|
-
const response = await restCall(`${endpoint}/${params.id}`, {
|
|
287
|
-
method: "PUT",
|
|
288
|
-
body: JSON.stringify(params.data)
|
|
289
|
-
});
|
|
290
|
-
return response.data;
|
|
291
|
-
},
|
|
292
|
-
async delete(params) {
|
|
293
|
-
const endpoint = getEndpointForType(params.type);
|
|
294
|
-
await restCall(`${endpoint}/${params.id}`, { method: "DELETE" });
|
|
295
|
-
return { success: true };
|
|
296
|
-
},
|
|
297
|
-
async versions(_params) {
|
|
298
|
-
return [];
|
|
299
|
-
},
|
|
300
|
-
async stats(_params) {
|
|
301
|
-
let validEndpoints = endpointCache.get(rpcUrl);
|
|
302
|
-
if (!validEndpoints) {
|
|
303
|
-
await this.types({ ns: _params.ns });
|
|
304
|
-
validEndpoints = endpointCache.get(rpcUrl) || /* @__PURE__ */ new Set();
|
|
305
|
-
}
|
|
306
|
-
const types = Array.from(validEndpoints);
|
|
307
|
-
const results = await Promise.all(
|
|
308
|
-
types.map(async (type) => {
|
|
309
|
-
const endpoint = getEndpointForType(type);
|
|
310
|
-
const response = await restCall(endpoint).catch(() => ({ count: 0 }));
|
|
311
|
-
return { type, count: response.count || 0 };
|
|
312
|
-
})
|
|
313
|
-
);
|
|
314
|
-
const byType = {};
|
|
315
|
-
let total = 0;
|
|
316
|
-
for (const { type, count } of results) {
|
|
317
|
-
byType[type] = count;
|
|
318
|
-
total += count;
|
|
319
|
-
}
|
|
320
|
-
return { total, byType };
|
|
321
225
|
}
|
|
322
226
|
},
|
|
323
227
|
/**
|
|
@@ -325,66 +229,47 @@ function createJsonRpcClient(baseUrl, options = {}) {
|
|
|
325
229
|
*/
|
|
326
230
|
SQL: {
|
|
327
231
|
async execute(params) {
|
|
328
|
-
const startTime = Date.now();
|
|
329
232
|
try {
|
|
330
|
-
const result = await
|
|
233
|
+
const result = await rpc.sql?.execute?.(params.query, params.params);
|
|
331
234
|
return {
|
|
332
|
-
rows: result
|
|
333
|
-
columns: result
|
|
334
|
-
rowsAffected: result
|
|
335
|
-
executionTimeMs: result
|
|
235
|
+
rows: result?.rows ?? [],
|
|
236
|
+
columns: result?.columns ?? [],
|
|
237
|
+
rowsAffected: result?.rowsAffected,
|
|
238
|
+
executionTimeMs: result?.executionTimeMs
|
|
336
239
|
};
|
|
337
|
-
} catch
|
|
338
|
-
|
|
339
|
-
const isNotSupported = errorMessage.includes("not found") || errorMessage.includes("not supported") || errorMessage.includes("unknown method");
|
|
340
|
-
try {
|
|
341
|
-
const response = await restCall("/sql", {
|
|
342
|
-
method: "POST",
|
|
343
|
-
body: JSON.stringify({ query: params.query, params: params.params })
|
|
344
|
-
});
|
|
345
|
-
return {
|
|
346
|
-
rows: response.rows ?? [],
|
|
347
|
-
columns: response.columns ?? [],
|
|
348
|
-
rowsAffected: response.rowsAffected,
|
|
349
|
-
executionTimeMs: Date.now() - startTime
|
|
350
|
-
};
|
|
351
|
-
} catch (restError) {
|
|
352
|
-
if (isNotSupported) {
|
|
353
|
-
throw new Error(
|
|
354
|
-
"SQL execution is not supported by this server. The server does not expose sql.execute RPC method or /sql REST endpoint."
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
throw restError;
|
|
358
|
-
}
|
|
240
|
+
} catch {
|
|
241
|
+
throw new Error("SQL execution is not supported by this server");
|
|
359
242
|
}
|
|
360
243
|
}
|
|
361
244
|
},
|
|
362
|
-
|
|
363
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Create a duplicate client instance
|
|
247
|
+
*/
|
|
248
|
+
dup: () => createDOClient(baseUrl, options),
|
|
249
|
+
/**
|
|
250
|
+
* Register callback for RPC connection errors
|
|
251
|
+
*/
|
|
364
252
|
onRpcBroken: (_callback) => {
|
|
365
253
|
},
|
|
254
|
+
/**
|
|
255
|
+
* Cleanup/dispose the client
|
|
256
|
+
*/
|
|
366
257
|
[Symbol.dispose]: () => {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
Function: "/functions",
|
|
376
|
-
Event: "/events",
|
|
377
|
-
Relationship: "/relationships",
|
|
378
|
-
Thing: "/things",
|
|
379
|
-
Workflow: "/workflows"
|
|
258
|
+
if (rpc.close && typeof rpc.close === "function") {
|
|
259
|
+
rpc.close();
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
/**
|
|
263
|
+
* Raw SDK access for advanced usage
|
|
264
|
+
*/
|
|
265
|
+
$rpc: rpc
|
|
380
266
|
};
|
|
381
|
-
return typeMap[type] || `/${type}`;
|
|
382
267
|
}
|
|
383
|
-
function $
|
|
384
|
-
return
|
|
268
|
+
function $DOContext(url, options) {
|
|
269
|
+
return createDOClient(url, options);
|
|
385
270
|
}
|
|
386
271
|
|
|
387
|
-
// src/
|
|
272
|
+
// src/client/mock-data.ts
|
|
388
273
|
var idCounter = 0;
|
|
389
274
|
function generateId(prefix = "mock") {
|
|
390
275
|
return `${prefix}_${Date.now().toString(36)}_${(++idCounter).toString(36)}`;
|
|
@@ -682,7 +567,7 @@ function generateInitialMockData() {
|
|
|
682
567
|
];
|
|
683
568
|
}
|
|
684
569
|
|
|
685
|
-
// src/
|
|
570
|
+
// src/client/mock-client.ts
|
|
686
571
|
function thingKey(ns, type, id) {
|
|
687
572
|
return `${ns}:${type}:${id}`;
|
|
688
573
|
}
|
|
@@ -956,15 +841,7 @@ function $MockContext(options) {
|
|
|
956
841
|
return createMockClient(options);
|
|
957
842
|
}
|
|
958
843
|
|
|
959
|
-
// src/
|
|
960
|
-
function deriveRpcUrl(url) {
|
|
961
|
-
let rpcUrl = url.replace(/^wss:/, "https:").replace(/^ws:/, "http:");
|
|
962
|
-
rpcUrl = rpcUrl.replace(/\/(sync|rpc)$/, "");
|
|
963
|
-
rpcUrl = rpcUrl.replace(/\/$/, "");
|
|
964
|
-
return `${rpcUrl}/rpc`;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
// src/lib/fetch-with-timeout.ts
|
|
844
|
+
// src/client/fetch.ts
|
|
968
845
|
var DEFAULT_REQUEST_TIMEOUT = 3e4;
|
|
969
846
|
async function fetchWithTimeout(url, options = {}) {
|
|
970
847
|
const { timeout = DEFAULT_REQUEST_TIMEOUT, signal: existingSignal, ...fetchOptions } = options;
|
|
@@ -995,77 +872,7 @@ async function fetchWithTimeout(url, options = {}) {
|
|
|
995
872
|
function createFetchWithTimeout(defaultTimeout) {
|
|
996
873
|
return (url, options = {}) => fetchWithTimeout(url, { timeout: defaultTimeout, ...options });
|
|
997
874
|
}
|
|
998
|
-
function useHealthCheck(config) {
|
|
999
|
-
const [isConnected, setIsConnected] = useState(false);
|
|
1000
|
-
const [connectionError, setConnectionError] = useState();
|
|
1001
|
-
const [isChecking, setIsChecking] = useState(true);
|
|
1002
|
-
const { apiEndpoint, authToken, requestTimeout, healthCheckRetries = 3 } = config;
|
|
1003
|
-
const abortControllerRef = useRef(null);
|
|
1004
|
-
const performHealthCheck = useCallback(async () => {
|
|
1005
|
-
const response = await fetchWithTimeout(apiEndpoint, {
|
|
1006
|
-
method: "GET",
|
|
1007
|
-
headers: {
|
|
1008
|
-
"Content-Type": "application/json",
|
|
1009
|
-
...authToken ? { Authorization: `Bearer ${authToken}` } : {}
|
|
1010
|
-
},
|
|
1011
|
-
timeout: requestTimeout ?? DEFAULT_REQUEST_TIMEOUT
|
|
1012
|
-
});
|
|
1013
|
-
if (!response.ok) {
|
|
1014
|
-
throw new Error(`Health check failed: ${response.status}`);
|
|
1015
|
-
}
|
|
1016
|
-
}, [apiEndpoint, authToken, requestTimeout]);
|
|
1017
|
-
const checkConnection = useCallback(async () => {
|
|
1018
|
-
setIsChecking(true);
|
|
1019
|
-
try {
|
|
1020
|
-
await retryWithBackoff(performHealthCheck, {
|
|
1021
|
-
maxRetries: healthCheckRetries,
|
|
1022
|
-
backoffMultiplier: 1e3
|
|
1023
|
-
});
|
|
1024
|
-
setIsConnected(true);
|
|
1025
|
-
setConnectionError(void 0);
|
|
1026
|
-
} catch (error) {
|
|
1027
|
-
setIsConnected(false);
|
|
1028
|
-
setConnectionError(error instanceof Error ? error : new Error("Connection failed"));
|
|
1029
|
-
} finally {
|
|
1030
|
-
setIsChecking(false);
|
|
1031
|
-
}
|
|
1032
|
-
}, [performHealthCheck, healthCheckRetries]);
|
|
1033
|
-
useEffect(() => {
|
|
1034
|
-
abortControllerRef.current = new AbortController();
|
|
1035
|
-
const { signal } = abortControllerRef.current;
|
|
1036
|
-
async function runCheck() {
|
|
1037
|
-
try {
|
|
1038
|
-
await retryWithBackoff(performHealthCheck, {
|
|
1039
|
-
maxRetries: healthCheckRetries,
|
|
1040
|
-
backoffMultiplier: 1e3,
|
|
1041
|
-
signal
|
|
1042
|
-
});
|
|
1043
|
-
if (!signal.aborted) {
|
|
1044
|
-
setIsConnected(true);
|
|
1045
|
-
setConnectionError(void 0);
|
|
1046
|
-
setIsChecking(false);
|
|
1047
|
-
}
|
|
1048
|
-
} catch (error) {
|
|
1049
|
-
if (!signal.aborted) {
|
|
1050
|
-
setIsConnected(false);
|
|
1051
|
-
setConnectionError(error instanceof Error ? error : new Error("Connection failed"));
|
|
1052
|
-
setIsChecking(false);
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
runCheck();
|
|
1057
|
-
return () => {
|
|
1058
|
-
abortControllerRef.current?.abort();
|
|
1059
|
-
};
|
|
1060
|
-
}, [performHealthCheck, healthCheckRetries]);
|
|
1061
|
-
return {
|
|
1062
|
-
isConnected,
|
|
1063
|
-
connectionError,
|
|
1064
|
-
checkConnection,
|
|
1065
|
-
isChecking
|
|
1066
|
-
};
|
|
1067
|
-
}
|
|
1068
875
|
|
|
1069
|
-
export { $
|
|
1070
|
-
//# sourceMappingURL=chunk-
|
|
1071
|
-
//# sourceMappingURL=chunk-
|
|
876
|
+
export { $DOContext, $MockContext, DEFAULT_REQUEST_TIMEOUT, MOCK_TYPES, createDOClient, createFetchWithTimeout, createMockClient, fetchWithTimeout, generateInitialMockData, generateMockSchema, generateMockThing, generateMockThings };
|
|
877
|
+
//# sourceMappingURL=chunk-KLN5OTQH.js.map
|
|
878
|
+
//# sourceMappingURL=chunk-KLN5OTQH.js.map
|