@epoch32/visage 1.1.3 → 1.1.4
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/api/index.js +55 -4085
- package/dist/charts/index.js +48 -2806
- package/dist/devtools/index.js +18 -4771
- package/dist/dom/index.js +32 -1639
- package/dist/form/index.js +13 -1498
- package/dist/index-061jf06a.js +848 -0
- package/dist/index-0madxn60.js +442 -0
- package/dist/index-1xtrtz1t.js +256 -0
- package/dist/index-2zz0g2n2.js +212 -0
- package/dist/index-5s255b3w.js +303 -0
- package/dist/index-6kfe1nr4.js +1179 -0
- package/dist/index-8czhpea8.js +338 -0
- package/dist/index-8x8xz80v.js +727 -0
- package/dist/index-921pn75b.js +0 -0
- package/dist/index-965ryh36.js +537 -0
- package/dist/index-9fvarkrx.js +98 -0
- package/dist/index-a4xns6cc.js +219 -0
- package/dist/index-b5wc752a.js +1696 -0
- package/dist/index-df5e614s.js +334 -0
- package/dist/index-dyvgtp43.js +1094 -0
- package/dist/index-grhdtcb5.js +234 -0
- package/dist/index-h6tjqk6e.js +158 -0
- package/dist/index-js199er4.js +101 -0
- package/dist/index-x2rs3vab.js +124 -0
- package/dist/index-y9bq7h9g.js +1162 -0
- package/dist/index-zr6cvset.js +2092 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +458 -11920
- package/dist/jsx-runtime/index.js +13 -1719
- package/dist/query/index.js +47 -2505
- package/dist/router/index.js +25 -1945
- package/dist/rpc/index.js +39 -3567
- package/dist/server/index.js +11 -1256
- package/dist/signals/index.js +52 -1160
- package/dist/style/index.js +77 -2429
- package/dist/template/index.js +7 -1232
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +150 -4249
- package/dist/ui/tabs.d.ts +23 -1
- package/dist/virtual/index.js +12 -2044
- package/dist/vite/index.js +5 -744
- package/package.json +2 -2
- package/src/dom/render.ts +20 -7
- package/src/index.ts +2 -0
- package/src/signals/computed.ts +19 -12
- package/src/signals/effect.ts +7 -7
- package/src/signals/signal.ts +16 -12
- package/src/signals/system.ts +50 -21
- package/src/ui/index.ts +2 -0
- package/src/ui/tabs.tsx +211 -10
- package/src/ui/utils.ts +1 -3
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RPCError2,
|
|
3
|
+
createProcedure2,
|
|
4
|
+
matchesRulePattern
|
|
5
|
+
} from "./index-965ryh36.js";
|
|
6
|
+
import {
|
|
7
|
+
createMutation2,
|
|
8
|
+
createQuery2
|
|
9
|
+
} from "./index-y9bq7h9g.js";
|
|
10
|
+
// src/rpc/client.ts
|
|
11
|
+
async function resolveHeaders(headers, fullPath = "") {
|
|
12
|
+
if (!headers)
|
|
13
|
+
return {};
|
|
14
|
+
if (typeof headers === "function") {
|
|
15
|
+
return await headers();
|
|
16
|
+
}
|
|
17
|
+
const result = {};
|
|
18
|
+
for (const [key, val] of Object.entries(headers)) {
|
|
19
|
+
if (typeof val === "object" || typeof val === "function") {
|
|
20
|
+
if (matchesRulePattern(key, fullPath, fullPath)) {
|
|
21
|
+
const resolved = typeof val === "function" ? await val() : val;
|
|
22
|
+
if (resolved && typeof resolved === "object") {
|
|
23
|
+
Object.assign(result, resolved);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} else if (typeof val === "string") {
|
|
27
|
+
result[key] = val;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
function createProxyPath(options, path = []) {
|
|
33
|
+
return new Proxy({}, {
|
|
34
|
+
get(_target, prop) {
|
|
35
|
+
if (prop === "then")
|
|
36
|
+
return;
|
|
37
|
+
if (prop === "query") {
|
|
38
|
+
return async (input, callOpts) => {
|
|
39
|
+
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
40
|
+
const baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
41
|
+
const fullPath = path.join(".");
|
|
42
|
+
let url = `${baseUrl}/${fullPath}`;
|
|
43
|
+
if (input !== undefined) {
|
|
44
|
+
const serialized = JSON.stringify(input);
|
|
45
|
+
url += `${url.includes("?") ? "&" : "?"}input=${encodeURIComponent(serialized)}`;
|
|
46
|
+
}
|
|
47
|
+
const dynamicHeaders = await resolveHeaders(options.headers, fullPath);
|
|
48
|
+
const headers = {
|
|
49
|
+
Accept: "application/json",
|
|
50
|
+
...dynamicHeaders,
|
|
51
|
+
...callOpts?.headers
|
|
52
|
+
};
|
|
53
|
+
const devtools = typeof window !== "undefined" ? window.__VISAGE_DEVTOOLS__ : null;
|
|
54
|
+
const logId = devtools?.logRpcCall({
|
|
55
|
+
id: `rpc_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
56
|
+
path: fullPath,
|
|
57
|
+
type: "query",
|
|
58
|
+
input
|
|
59
|
+
});
|
|
60
|
+
try {
|
|
61
|
+
const res = await fetchFn(url, {
|
|
62
|
+
method: "GET",
|
|
63
|
+
headers,
|
|
64
|
+
signal: callOpts?.signal
|
|
65
|
+
});
|
|
66
|
+
const body = await res.json();
|
|
67
|
+
if ("error" in body) {
|
|
68
|
+
devtools?.updateRpcCall(logId, { status: "error", error: body.error });
|
|
69
|
+
throw new RPCError2({
|
|
70
|
+
code: body.error.code,
|
|
71
|
+
message: body.error.message,
|
|
72
|
+
issues: body.error.issues
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
devtools?.updateRpcCall(logId, { status: "success", response: body.result.data });
|
|
76
|
+
return body.result.data;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
devtools?.updateRpcCall(logId, { status: "error", error: err });
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (prop === "mutate") {
|
|
84
|
+
return async (input, callOpts) => {
|
|
85
|
+
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
86
|
+
const baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
87
|
+
const fullPath = path.join(".");
|
|
88
|
+
const url = `${baseUrl}/${fullPath}`;
|
|
89
|
+
const dynamicHeaders = await resolveHeaders(options.headers, fullPath);
|
|
90
|
+
const headers = {
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
Accept: "application/json",
|
|
93
|
+
...dynamicHeaders,
|
|
94
|
+
...callOpts?.headers
|
|
95
|
+
};
|
|
96
|
+
const devtools = typeof window !== "undefined" ? window.__VISAGE_DEVTOOLS__ : null;
|
|
97
|
+
const logId = devtools?.logRpcCall({
|
|
98
|
+
id: `rpc_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
99
|
+
path: fullPath,
|
|
100
|
+
type: "mutation",
|
|
101
|
+
input
|
|
102
|
+
});
|
|
103
|
+
try {
|
|
104
|
+
const res = await fetchFn(url, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers,
|
|
107
|
+
body: JSON.stringify({ input }),
|
|
108
|
+
signal: callOpts?.signal
|
|
109
|
+
});
|
|
110
|
+
const body = await res.json();
|
|
111
|
+
if ("error" in body) {
|
|
112
|
+
devtools?.updateRpcCall(logId, { status: "error", error: body.error });
|
|
113
|
+
throw new RPCError2({
|
|
114
|
+
code: body.error.code,
|
|
115
|
+
message: body.error.message,
|
|
116
|
+
issues: body.error.issues
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
devtools?.updateRpcCall(logId, { status: "success", response: body.result.data });
|
|
120
|
+
return body.result.data;
|
|
121
|
+
} catch (err) {
|
|
122
|
+
devtools?.updateRpcCall(logId, { status: "error", error: err });
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (prop === "subscribe") {
|
|
128
|
+
return (input, callbacks) => {
|
|
129
|
+
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
130
|
+
const baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
131
|
+
const fullPath = path.join(".");
|
|
132
|
+
let url = `${baseUrl}/${fullPath}`;
|
|
133
|
+
if (input !== undefined) {
|
|
134
|
+
const serialized = JSON.stringify(input);
|
|
135
|
+
url += `${url.includes("?") ? "&" : "?"}input=${encodeURIComponent(serialized)}`;
|
|
136
|
+
}
|
|
137
|
+
const controller = new AbortController;
|
|
138
|
+
const devtools = typeof window !== "undefined" ? window.__VISAGE_DEVTOOLS__ : null;
|
|
139
|
+
const logId = devtools?.logRpcCall({
|
|
140
|
+
id: `rpc_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
|
|
141
|
+
path: fullPath,
|
|
142
|
+
type: "subscription",
|
|
143
|
+
input
|
|
144
|
+
});
|
|
145
|
+
(async () => {
|
|
146
|
+
try {
|
|
147
|
+
const dynamicHeaders = await resolveHeaders(options.headers, fullPath);
|
|
148
|
+
const headers = {
|
|
149
|
+
Accept: "text/event-stream",
|
|
150
|
+
...dynamicHeaders
|
|
151
|
+
};
|
|
152
|
+
const res = await fetchFn(url, {
|
|
153
|
+
method: "GET",
|
|
154
|
+
headers,
|
|
155
|
+
signal: controller.signal
|
|
156
|
+
});
|
|
157
|
+
if (!res.ok || !res.body) {
|
|
158
|
+
throw new Error(`Subscription connection failed with status ${res.status}`);
|
|
159
|
+
}
|
|
160
|
+
const reader = res.body.getReader();
|
|
161
|
+
const decoder = new TextDecoder;
|
|
162
|
+
let buffer = "";
|
|
163
|
+
while (true) {
|
|
164
|
+
const { done, value } = await reader.read();
|
|
165
|
+
if (done)
|
|
166
|
+
break;
|
|
167
|
+
buffer += decoder.decode(value, { stream: true });
|
|
168
|
+
const lines = buffer.split(`
|
|
169
|
+
|
|
170
|
+
`);
|
|
171
|
+
buffer = lines.pop() ?? "";
|
|
172
|
+
for (const line of lines) {
|
|
173
|
+
const trimmed = line.trim();
|
|
174
|
+
if (trimmed.startsWith("data:")) {
|
|
175
|
+
const jsonStr = trimmed.slice(5).trim();
|
|
176
|
+
try {
|
|
177
|
+
const parsed = JSON.parse(jsonStr);
|
|
178
|
+
devtools?.logRpcEvent(logId, parsed);
|
|
179
|
+
callbacks.onData(parsed);
|
|
180
|
+
} catch (parseErr) {
|
|
181
|
+
devtools?.updateRpcCall(logId, { status: "error", error: parseErr });
|
|
182
|
+
callbacks.onError?.(parseErr);
|
|
183
|
+
}
|
|
184
|
+
} else if (trimmed.startsWith("event: error")) {
|
|
185
|
+
devtools?.updateRpcCall(logId, { status: "error" });
|
|
186
|
+
callbacks.onError?.(new Error("Server event stream error"));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
callbacks.onComplete?.();
|
|
191
|
+
} catch (err) {
|
|
192
|
+
if (!controller.signal.aborted) {
|
|
193
|
+
callbacks.onError?.(err);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
})();
|
|
197
|
+
return {
|
|
198
|
+
unsubscribe: () => {
|
|
199
|
+
controller.abort();
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (prop === "queryKey") {
|
|
205
|
+
return (input) => {
|
|
206
|
+
const resolvedInput = typeof input === "function" ? input() : input;
|
|
207
|
+
const key = [...path];
|
|
208
|
+
if (resolvedInput !== undefined) {
|
|
209
|
+
key.push(resolvedInput);
|
|
210
|
+
}
|
|
211
|
+
return key;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (prop === "queryOptions") {
|
|
215
|
+
return (input, extra) => {
|
|
216
|
+
const resolvedInput = typeof input === "function" ? input() : input;
|
|
217
|
+
const key = [...path];
|
|
218
|
+
if (resolvedInput !== undefined) {
|
|
219
|
+
key.push(resolvedInput);
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
queryKey: key,
|
|
223
|
+
queryFn: ({ signal }) => {
|
|
224
|
+
const queryFn = createProxyPath(options, path).query;
|
|
225
|
+
return queryFn(resolvedInput, { signal });
|
|
226
|
+
},
|
|
227
|
+
...extra
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
if (prop === "createQuery" || prop === "useQuery") {
|
|
232
|
+
return (input, extra) => {
|
|
233
|
+
const proxy = createProxyPath(options, path);
|
|
234
|
+
return createQuery2(() => proxy.queryOptions(input, extra));
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (prop === "mutationKey") {
|
|
238
|
+
return () => [...path];
|
|
239
|
+
}
|
|
240
|
+
if (prop === "mutationOptions") {
|
|
241
|
+
return (extra) => {
|
|
242
|
+
return {
|
|
243
|
+
mutationKey: [...path],
|
|
244
|
+
mutationFn: (input) => {
|
|
245
|
+
const mutateFn = createProxyPath(options, path).mutate;
|
|
246
|
+
return mutateFn(input);
|
|
247
|
+
},
|
|
248
|
+
...extra
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (prop === "createMutation" || prop === "useMutation") {
|
|
253
|
+
return (extra) => {
|
|
254
|
+
const proxy = createProxyPath(options, path);
|
|
255
|
+
return createMutation2(proxy.mutationOptions(extra));
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return createProxyPath(options, [...path, prop]);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function createClient2(options) {
|
|
263
|
+
return createProxyPath(options, []);
|
|
264
|
+
}
|
|
265
|
+
// src/rpc/router.ts
|
|
266
|
+
class RouterImpl2 {
|
|
267
|
+
_def;
|
|
268
|
+
constructor(record = {}, middlewares = []) {
|
|
269
|
+
this._def = {
|
|
270
|
+
record: { ...record },
|
|
271
|
+
middlewares: [...middlewares]
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
query(name, options) {
|
|
275
|
+
const proc = createProcedure2("query", options, this._def.middlewares);
|
|
276
|
+
const newRecord = {
|
|
277
|
+
...this._def.record,
|
|
278
|
+
[name]: proc
|
|
279
|
+
};
|
|
280
|
+
return new RouterImpl2(newRecord, this._def.middlewares);
|
|
281
|
+
}
|
|
282
|
+
mutation(name, options) {
|
|
283
|
+
const proc = createProcedure2("mutation", options, this._def.middlewares);
|
|
284
|
+
const newRecord = {
|
|
285
|
+
...this._def.record,
|
|
286
|
+
[name]: proc
|
|
287
|
+
};
|
|
288
|
+
return new RouterImpl2(newRecord, this._def.middlewares);
|
|
289
|
+
}
|
|
290
|
+
subscription(name, options) {
|
|
291
|
+
const proc = createProcedure2("subscription", options, this._def.middlewares);
|
|
292
|
+
const newRecord = {
|
|
293
|
+
...this._def.record,
|
|
294
|
+
[name]: proc
|
|
295
|
+
};
|
|
296
|
+
return new RouterImpl2(newRecord, this._def.middlewares);
|
|
297
|
+
}
|
|
298
|
+
use(middleware) {
|
|
299
|
+
const updatedMiddlewares = [...this._def.middlewares, middleware];
|
|
300
|
+
const updatedRecord = {};
|
|
301
|
+
for (const key in this._def.record) {
|
|
302
|
+
const item = this._def.record[key];
|
|
303
|
+
if ("type" in item) {
|
|
304
|
+
updatedRecord[key] = {
|
|
305
|
+
...item,
|
|
306
|
+
middlewares: [...updatedMiddlewares]
|
|
307
|
+
};
|
|
308
|
+
} else {
|
|
309
|
+
updatedRecord[key] = item;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return new RouterImpl2(updatedRecord, updatedMiddlewares);
|
|
313
|
+
}
|
|
314
|
+
merge(prefix, router) {
|
|
315
|
+
const newRecord = {
|
|
316
|
+
...this._def.record,
|
|
317
|
+
[prefix]: router
|
|
318
|
+
};
|
|
319
|
+
return new RouterImpl2(newRecord, this._def.middlewares);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function createRouter2(record) {
|
|
323
|
+
return new RouterImpl2(record ?? {});
|
|
324
|
+
}
|
|
325
|
+
function query3(options) {
|
|
326
|
+
return createProcedure2("query", options);
|
|
327
|
+
}
|
|
328
|
+
function mutation3(options) {
|
|
329
|
+
return createProcedure2("mutation", options);
|
|
330
|
+
}
|
|
331
|
+
function subscription3(options) {
|
|
332
|
+
return createProcedure2("subscription", options);
|
|
333
|
+
}
|
|
334
|
+
export { createClient2, RouterImpl2, createRouter2, query3, mutation3, subscription3 };
|