oxidejs 0.3.2 → 0.3.3
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/README.md +42 -41
- package/client.d.ts +15 -9
- package/dist/client-DOfB6wxk.mjs +207 -0
- package/dist/context-CmChiQ2W.d.mts +98 -0
- package/dist/{context-DQDDwFYi.mjs → context-DUN_VWJF.mjs} +44 -36
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +72 -51
- package/dist/plugin-BIb3YnN7.mjs +674 -0
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.mjs +1 -1
- package/dist/rpc/client.d.mts +16 -7
- package/dist/rpc/client.mjs +1 -1
- package/dist/{rpc-tYqxQToi.mjs → rpc-gCOSJXql.mjs} +337 -300
- package/dist/rpc.d.mts +37 -31
- package/dist/rpc.mjs +2 -2
- package/dist/rsbuild.d.mts +1 -1
- package/dist/rsbuild.mjs +1 -1
- package/dist/{types-BM4NAnzy.d.mts → types-BaZeMYcP.d.mts} +22 -8
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/worker-dom.d.mts +1 -1
- package/dist/worker-dom.mjs +15 -8
- package/package.json +2 -2
- package/virtual.d.ts +16 -3
- package/dist/client-BgBfkZDx.mjs +0 -166
- package/dist/context-Ct8u5XUC.d.mts +0 -73
- package/dist/plugin-CurpVnGn.mjs +0 -602
package/dist/index.mjs
CHANGED
|
@@ -1,36 +1,55 @@
|
|
|
1
|
-
import { a as useEnv, i as useCtx, l as withRequestStore, o as useFetchCtx, s as useRequest, t as getRequestStore } from "./context-
|
|
1
|
+
import { a as useEnv, i as useCtx, l as withRequestStore, o as useFetchCtx, s as useRequest, t as getRequestStore } from "./context-DUN_VWJF.mjs";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Atom from "effect/unstable/reactivity/Atom";
|
|
4
4
|
import * as Registry from "effect/unstable/reactivity/AtomRegistry";
|
|
5
5
|
//#region src/action.ts
|
|
6
6
|
const ACTION_CALL = Symbol.for("ilha.actionCall");
|
|
7
7
|
const ACTION_KEY = Symbol.for("oxidejs.actionKey");
|
|
8
|
-
const AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {
|
|
8
|
+
const AsyncGeneratorFunction = Object.getPrototypeOf(async function* asyncGeneratorProbe() {
|
|
9
|
+
yield;
|
|
10
|
+
}).constructor;
|
|
9
11
|
let defaultRegistry;
|
|
10
|
-
function registry() {
|
|
12
|
+
const registry = function registry() {
|
|
11
13
|
return defaultRegistry ??= Registry.make();
|
|
12
|
-
}
|
|
13
|
-
function isAsyncGeneratorFunction(fn) {
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
};
|
|
15
|
+
const isAsyncGeneratorFunction = function isAsyncGeneratorFunction(fn) {
|
|
16
|
+
return fn instanceof AsyncGeneratorFunction;
|
|
17
|
+
};
|
|
18
|
+
const emptyArgs = function emptyArgs() {
|
|
19
|
+
return [];
|
|
20
|
+
};
|
|
21
|
+
const asArgs = function asArgs(value) {
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
const readActionKey = function readActionKey(target) {
|
|
25
|
+
return target[ACTION_KEY];
|
|
26
|
+
};
|
|
27
|
+
const writeActionKey = function writeActionKey(target, key) {
|
|
28
|
+
target[ACTION_KEY] = key;
|
|
29
|
+
};
|
|
30
|
+
const denyStreamBind = function denyStreamBind() {
|
|
31
|
+
throw new Error("oxidejs: stream actions cannot be bound to DOM events");
|
|
32
|
+
};
|
|
33
|
+
const splitCallOptions = function splitCallOptions(args) {
|
|
34
|
+
if (args.length === 0) return { args: emptyArgs() };
|
|
35
|
+
const last = args.at(-1);
|
|
36
|
+
if (last instanceof Object && !Array.isArray(last) && "signal" in last && last.signal instanceof AbortSignal && Object.keys(last).length === 1) return {
|
|
37
|
+
args: asArgs(args.slice(0, -1)),
|
|
38
|
+
options: { signal: last.signal }
|
|
22
39
|
};
|
|
23
40
|
return { args };
|
|
24
|
-
}
|
|
25
|
-
function bindHandler(key, invoke, args) {
|
|
26
|
-
const handler = ((..._ev) =>
|
|
41
|
+
};
|
|
42
|
+
const bindHandler = function bindHandler(key, invoke, args) {
|
|
43
|
+
const handler = ((..._ev) => {
|
|
44
|
+
invoke(...args);
|
|
45
|
+
});
|
|
27
46
|
if (key) handler[ACTION_CALL] = {
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
a: args,
|
|
48
|
+
k: key
|
|
30
49
|
};
|
|
31
50
|
return handler;
|
|
32
|
-
}
|
|
33
|
-
function defineServerAction(atom, invoke, opts) {
|
|
51
|
+
};
|
|
52
|
+
const defineServerAction = function defineServerAction(atom, invoke, opts) {
|
|
34
53
|
const captureKey = opts?.captureKey;
|
|
35
54
|
const stripCallOptions = opts?.stripCallOptions ?? true;
|
|
36
55
|
const run = ((...allArgs) => {
|
|
@@ -43,66 +62,68 @@ function defineServerAction(atom, invoke, opts) {
|
|
|
43
62
|
return Promise.resolve(invoke(...args));
|
|
44
63
|
};
|
|
45
64
|
const bind = (...args) => {
|
|
46
|
-
|
|
65
|
+
const key = captureKey ?? readActionKey(run);
|
|
66
|
+
return bindHandler(key, (...a) => {
|
|
67
|
+
set(...a);
|
|
68
|
+
}, args);
|
|
47
69
|
};
|
|
48
70
|
Object.assign(run, {
|
|
49
|
-
|
|
50
|
-
bind,
|
|
51
|
-
with: bind,
|
|
71
|
+
$$atom: 1,
|
|
52
72
|
atom,
|
|
53
|
-
|
|
73
|
+
bind,
|
|
74
|
+
set,
|
|
75
|
+
with: bind
|
|
54
76
|
});
|
|
55
77
|
Object.defineProperty(run, "result", {
|
|
56
78
|
enumerable: true,
|
|
57
79
|
get: () => registry().get(atom)
|
|
58
80
|
});
|
|
59
|
-
if (captureKey) run
|
|
81
|
+
if (captureKey) writeActionKey(run, captureKey);
|
|
60
82
|
return run;
|
|
61
|
-
}
|
|
62
|
-
function defineStreamAction(fn) {
|
|
83
|
+
};
|
|
84
|
+
const defineStreamAction = function defineStreamAction(fn) {
|
|
63
85
|
const call = ((...allArgs) => {
|
|
64
86
|
const { args } = splitCallOptions(allArgs);
|
|
65
87
|
return fn(...args);
|
|
66
88
|
});
|
|
67
|
-
const deny = () => {
|
|
68
|
-
throw new Error("oxidejs: stream actions cannot be bound to DOM events");
|
|
69
|
-
};
|
|
70
89
|
Object.assign(call, {
|
|
71
|
-
|
|
72
|
-
bind: deny,
|
|
73
|
-
with: deny,
|
|
90
|
+
$$atom: 1,
|
|
74
91
|
atom: void 0,
|
|
75
|
-
|
|
92
|
+
bind: denyStreamBind,
|
|
93
|
+
set: call,
|
|
94
|
+
with: denyStreamBind
|
|
76
95
|
});
|
|
77
96
|
return call;
|
|
78
|
-
}
|
|
97
|
+
};
|
|
79
98
|
/** Attach an ilha server-island capture key to an action handle. */
|
|
80
|
-
function brandServerAction(key, handle) {
|
|
81
|
-
handle
|
|
99
|
+
const brandServerAction = function brandServerAction(key, handle) {
|
|
100
|
+
writeActionKey(handle, key);
|
|
82
101
|
return handle;
|
|
83
|
-
}
|
|
102
|
+
};
|
|
84
103
|
/** Wrap an RPC caller as an `Atom.fn`-shaped client action handle. */
|
|
85
|
-
function wrapClientRpc(rpc) {
|
|
104
|
+
const wrapClientRpc = function wrapClientRpc(rpc) {
|
|
86
105
|
const invoke = (...args) => Promise.resolve(rpc(...args));
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})))
|
|
91
|
-
}
|
|
106
|
+
const atom = Atom.make(Atom.fn((packed) => Effect.tryPromise({
|
|
107
|
+
catch: (error) => error instanceof Error ? error : new Error(String(error)),
|
|
108
|
+
try: () => invoke(...packed)
|
|
109
|
+
})));
|
|
110
|
+
return defineServerAction(atom, (...args) => invoke(...args), { stripCallOptions: false });
|
|
111
|
+
};
|
|
92
112
|
/**
|
|
93
113
|
* Wrap a streaming RPC caller so the client handle returns an async generator
|
|
94
114
|
* (awaiting the underlying client lazily), not `Promise<AsyncGenerator>`.
|
|
95
115
|
*/
|
|
96
|
-
function wrapClientStreamRpc(rpc) {
|
|
116
|
+
const wrapClientStreamRpc = function wrapClientStreamRpc(rpc) {
|
|
97
117
|
return defineStreamAction((...args) => rpc(...args));
|
|
98
|
-
}
|
|
118
|
+
};
|
|
99
119
|
function action(fn) {
|
|
100
120
|
if (isAsyncGeneratorFunction(fn)) return defineStreamAction(fn);
|
|
101
121
|
const invoke = (...args) => Promise.resolve(fn(...args));
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
})))
|
|
122
|
+
const atom = Atom.make(Atom.fn((packed) => Effect.tryPromise({
|
|
123
|
+
catch: (error) => error instanceof Error ? error : new Error(String(error)),
|
|
124
|
+
try: () => invoke(...packed)
|
|
125
|
+
})));
|
|
126
|
+
return defineServerAction(atom, invoke);
|
|
106
127
|
}
|
|
107
128
|
//#endregion
|
|
108
129
|
export { ACTION_CALL, action, brandServerAction, getRequestStore, useCtx, useEnv, useFetchCtx, useRequest, withRequestStore, wrapClientRpc, wrapClientStreamRpc };
|