@nice-code/action 0.2.5 → 0.2.7
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/build/index.js +42 -40
- package/build/react-query/index.js +20 -3107
- package/build/types/ActionDefinition/Domain/ActionDomain.d.ts +2 -0
- package/build/types/ActionDefinition/Domain/ActionRootDomain.d.ts +2 -1
- package/build/types/ActionRuntime/ActionRuntime.d.ts +8 -0
- package/build/types/ActionRuntime/ActionRuntimeManager.d.ts +1 -0
- package/build/types/ActionRuntime/RuntimeCoordinate.d.ts +2 -1
- package/build/types/react-query/hooks/useActionQuery.d.ts +5 -3
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
function __accessProp(key) {
|
|
7
|
-
return this[key];
|
|
8
|
-
}
|
|
9
|
-
var __toESMCache_node;
|
|
10
|
-
var __toESMCache_esm;
|
|
11
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
12
|
-
var canCache = mod != null && typeof mod === "object";
|
|
13
|
-
if (canCache) {
|
|
14
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
15
|
-
var cached = cache.get(mod);
|
|
16
|
-
if (cached)
|
|
17
|
-
return cached;
|
|
18
|
-
}
|
|
19
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
20
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
21
|
-
for (let key of __getOwnPropNames(mod))
|
|
22
|
-
if (!__hasOwnProp.call(to, key))
|
|
23
|
-
__defProp(to, key, {
|
|
24
|
-
get: __accessProp.bind(mod, key),
|
|
25
|
-
enumerable: true
|
|
26
|
-
});
|
|
27
|
-
if (canCache)
|
|
28
|
-
cache.set(mod, to);
|
|
29
|
-
return to;
|
|
30
|
-
};
|
|
31
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
32
|
-
|
|
33
1
|
// ../../node_modules/.bun/nanoid@5.1.9/node_modules/nanoid/url-alphabet/index.js
|
|
34
2
|
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
35
3
|
|
|
@@ -3310,7 +3278,7 @@ var err_nice_action = err_nice.createChildDomain({
|
|
|
3310
3278
|
message: ({ context, clientStringId }) => `No runtime registered${context?.domain ? ` on domain "${context.domain}"` : ""} for client [${clientStringId}].`
|
|
3311
3279
|
}),
|
|
3312
3280
|
["no_client_runtimes_registered" /* no_client_runtimes_registered */]: err({
|
|
3313
|
-
message: ({ context }) => `No runtimes registered${context?.domain ? ` on domain "${context.domain}"` : ""}.
|
|
3281
|
+
message: ({ context }) => `No runtimes registered${context?.domain ? ` on domain "${context.domain}"` : ""}. Add handlers to a runtime via runtime.addHandlers([handler]) before executing actions.`
|
|
3314
3282
|
}),
|
|
3315
3283
|
["action_input_validation_failed" /* action_input_validation_failed */]: err({
|
|
3316
3284
|
message: ({ domain, actionId, validationMessage }) => `Input validation failed for action "${actionId}" in domain "${domain}":
|
|
@@ -3618,6 +3586,7 @@ class ActionRuntime {
|
|
|
3618
3586
|
actionRouter;
|
|
3619
3587
|
_pendingRunningActions = new Map;
|
|
3620
3588
|
_registeredExternalHandlers = [];
|
|
3589
|
+
_applied = false;
|
|
3621
3590
|
static getDefault() {
|
|
3622
3591
|
return getDefaultActionRuntime();
|
|
3623
3592
|
}
|
|
@@ -3639,6 +3608,7 @@ class ActionRuntime {
|
|
|
3639
3608
|
throw new Error(`Can't update Runtime Coordinate with different "envId" properties (static environment id). "${this.coordinate.envId}" (current) !== ${newCoordinate.envId}`);
|
|
3640
3609
|
}
|
|
3641
3610
|
this._coordinate = newCoordinate;
|
|
3611
|
+
this.apply();
|
|
3642
3612
|
}
|
|
3643
3613
|
registerRunningAction(ra) {
|
|
3644
3614
|
this._pendingRunningActions.set(ra.cuid, ra);
|
|
@@ -3741,6 +3711,9 @@ class ActionRuntime {
|
|
|
3741
3711
|
}
|
|
3742
3712
|
const handlerRouter = handler.getActionRouter();
|
|
3743
3713
|
this.actionRouter.addDomainsFromOther(handlerRouter);
|
|
3714
|
+
if (this._applied) {
|
|
3715
|
+
this.apply();
|
|
3716
|
+
}
|
|
3744
3717
|
for (const key of handlerRouter.getRegisteredKeys()) {
|
|
3745
3718
|
const alreadyRegistered = this.actionRouter.getForKey(key).some((h2) => h2.cuid === handler.cuid);
|
|
3746
3719
|
if (!alreadyRegistered) {
|
|
@@ -3750,6 +3723,19 @@ class ActionRuntime {
|
|
|
3750
3723
|
}
|
|
3751
3724
|
return this;
|
|
3752
3725
|
}
|
|
3726
|
+
applyRuntimeForDomain(domain) {
|
|
3727
|
+
const rootDomain = domain.rootDomain;
|
|
3728
|
+
if (!rootDomain._hasRuntime(this)) {
|
|
3729
|
+
rootDomain._registerRuntime(this);
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
apply() {
|
|
3733
|
+
this._applied = true;
|
|
3734
|
+
for (const domain of this.actionRouter.getDomains()) {
|
|
3735
|
+
this.applyRuntimeForDomain(domain);
|
|
3736
|
+
}
|
|
3737
|
+
return this;
|
|
3738
|
+
}
|
|
3753
3739
|
getReturnHandlerForOrigin(originClient) {
|
|
3754
3740
|
if (originClient.envId === UNSET_RUNTIME_ENV_ID)
|
|
3755
3741
|
return;
|
|
@@ -3949,6 +3935,9 @@ class ActionDomain extends ActionDomainBase {
|
|
|
3949
3935
|
get rootDomain() {
|
|
3950
3936
|
return this._rootDomain;
|
|
3951
3937
|
}
|
|
3938
|
+
_registerRuntime(runtime2) {
|
|
3939
|
+
this._rootDomain._registerRuntime(runtime2);
|
|
3940
|
+
}
|
|
3952
3941
|
createChildDomain(subDomainDef) {
|
|
3953
3942
|
if (this.allDomains.includes(subDomainDef.domain)) {
|
|
3954
3943
|
throw err_nice_action.fromId("domain_already_exists_in_hierarchy" /* domain_already_exists_in_hierarchy */, {
|
|
@@ -4166,6 +4155,9 @@ class ActionRuntimeManager {
|
|
|
4166
4155
|
getBestRuntime(clientSpecifier) {
|
|
4167
4156
|
return clientSpecifier != null ? this.getBestRuntimeForSpecifier(clientSpecifier) : this.getPreferredRuntime();
|
|
4168
4157
|
}
|
|
4158
|
+
hasRuntime(runtime2) {
|
|
4159
|
+
return this._runtimes.has(runtime2.coordinate.stringId);
|
|
4160
|
+
}
|
|
4169
4161
|
getBestRuntimeOrThrow(specifier) {
|
|
4170
4162
|
const runtime2 = this.getBestRuntime(specifier);
|
|
4171
4163
|
if (!runtime2) {
|
|
@@ -4211,9 +4203,11 @@ class ActionRootDomain extends ActionDomainBase {
|
|
|
4211
4203
|
actionSchema: subDomainDef.actions
|
|
4212
4204
|
}, { rootDomain: this });
|
|
4213
4205
|
}
|
|
4214
|
-
|
|
4206
|
+
_registerRuntime(runtime2) {
|
|
4215
4207
|
this._actionRuntimeManager.registerRuntime(runtime2);
|
|
4216
|
-
|
|
4208
|
+
}
|
|
4209
|
+
_hasRuntime(runtime2) {
|
|
4210
|
+
return this._actionRuntimeManager.hasRuntime(runtime2);
|
|
4217
4211
|
}
|
|
4218
4212
|
getRuntime(clientSpecifier) {
|
|
4219
4213
|
return this._actionRuntimeManager.getBestRuntimeForSpecifier(clientSpecifier);
|
|
@@ -6924,7 +6918,11 @@ class ConnectionTransportManager {
|
|
|
6924
6918
|
if (cacheKey != null) {
|
|
6925
6919
|
const cached = this._cache.get(cacheKey);
|
|
6926
6920
|
if (cached != null) {
|
|
6927
|
-
|
|
6921
|
+
if (cached instanceof Promise) {
|
|
6922
|
+
initializingWaiters.push(cached);
|
|
6923
|
+
continue;
|
|
6924
|
+
}
|
|
6925
|
+
return { ...cached, transport };
|
|
6928
6926
|
}
|
|
6929
6927
|
}
|
|
6930
6928
|
const statusInfo = transport.getTransport(routeActionParams);
|
|
@@ -7241,8 +7239,10 @@ class TransportWebSocket extends Transport {
|
|
|
7241
7239
|
const ws = transportStatusInfo.readyData.ws;
|
|
7242
7240
|
if (ws.readyState !== WebSocket.OPEN) {
|
|
7243
7241
|
const initialization = async () => {
|
|
7244
|
-
await new Promise((resolve) => {
|
|
7245
|
-
ws.addEventListener("open", resolve, { once: true });
|
|
7242
|
+
await new Promise((resolve, reject) => {
|
|
7243
|
+
ws.addEventListener("open", () => resolve(), { once: true });
|
|
7244
|
+
ws.addEventListener("error", (event) => reject(event), { once: true });
|
|
7245
|
+
ws.addEventListener("close", (event) => reject(new Error(`WebSocket closed before open: code=${event.code}`)), { once: true });
|
|
7246
7246
|
});
|
|
7247
7247
|
return {
|
|
7248
7248
|
status: "ready" /* ready */,
|
|
@@ -7260,8 +7260,10 @@ class TransportWebSocket extends Transport {
|
|
|
7260
7260
|
const promiseForReadyData = transportStatusInfo.initializationPromise.then(async (result) => {
|
|
7261
7261
|
if (result.status === "ready" /* ready */) {
|
|
7262
7262
|
const ws = result.readyData.ws;
|
|
7263
|
-
await new Promise((resolve) => {
|
|
7264
|
-
ws.addEventListener("open", resolve, { once: true });
|
|
7263
|
+
await new Promise((resolve, reject) => {
|
|
7264
|
+
ws.addEventListener("open", () => resolve(), { once: true });
|
|
7265
|
+
ws.addEventListener("error", (event) => reject(event), { once: true });
|
|
7266
|
+
ws.addEventListener("close", (event) => reject(new Error(`WebSocket closed before open: code=${event.code}`)), { once: true });
|
|
7265
7267
|
});
|
|
7266
7268
|
return {
|
|
7267
7269
|
status: "ready" /* ready */,
|