@nice-code/action 0.2.1 → 0.2.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/build/index.js +1128 -1112
- package/build/react-query/index.js +10 -9
- package/build/types/ActionDefinition/Action/Action.combined.types.d.ts +8 -8
- package/build/types/ActionDefinition/Action/ActionBase.d.ts +2 -2
- package/build/types/ActionDefinition/Action/ActionBase.types.d.ts +4 -4
- package/build/types/ActionDefinition/Action/Context/ActionContext.d.ts +5 -5
- package/build/types/ActionDefinition/Action/Context/ActionContext.types.d.ts +2 -2
- package/build/types/ActionDefinition/Action/Core/ActionCore.d.ts +6 -6
- package/build/types/ActionDefinition/Action/Core/ActionCore.types.d.ts +2 -2
- package/build/types/ActionDefinition/Action/Payload/ActionPayload.d.ts +1 -1
- package/build/types/ActionDefinition/Action/Payload/ActionPayload.types.d.ts +14 -13
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Progress.d.ts +1 -1
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Request.d.ts +6 -6
- package/build/types/ActionDefinition/Action/Payload/ActionPayload_Result.d.ts +3 -3
- package/build/types/ActionDefinition/Action/RunningAction.d.ts +1 -1
- package/build/types/ActionDefinition/Action/RunningAction.types.d.ts +16 -16
- package/build/types/ActionDefinition/Domain/ActionDomain.d.ts +17 -7
- package/build/types/ActionDefinition/Domain/ActionDomain.types.d.ts +9 -6
- package/build/types/ActionDefinition/Domain/ActionDomainBase.d.ts +3 -3
- package/build/types/ActionDefinition/Domain/ActionRootDomain.d.ts +1 -1
- package/build/types/ActionRuntime/ActionDomainManager.d.ts +1 -1
- package/build/types/ActionRuntime/ActionRuntime.d.ts +2 -7
- package/build/types/ActionRuntime/Handler/ActionHandler.d.ts +1 -1
- package/build/types/ActionRuntime/Handler/ActionHandler.types.d.ts +3 -6
- package/build/types/ActionRuntime/Handler/ExternalClient/ActionExternalClientHandler.d.ts +3 -3
- package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.d.ts +4 -4
- package/build/types/ActionRuntime/Handler/Local/ActionLocalHandler.types.d.ts +1 -1
- package/build/types/ActionRuntime/Routing/ActionRouter.d.ts +7 -7
- package/build/types/errors/err_nice_action.d.ts +2 -2
- package/build/types/react-query/hooks/useActionMutation.d.ts +6 -0
- package/build/types/react-query/hooks/useActionQuery.d.ts +15 -0
- package/build/types/react-query/index.d.ts +2 -72
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -143,7 +143,7 @@ class ActionBase {
|
|
|
143
143
|
this.id = id;
|
|
144
144
|
this.domain = _domain.domain;
|
|
145
145
|
this.allDomains = _domain.allDomains;
|
|
146
|
-
this.schema = _domain.
|
|
146
|
+
this.schema = _domain.actionSchema[id];
|
|
147
147
|
}
|
|
148
148
|
toJsonObject() {
|
|
149
149
|
return {
|
|
@@ -251,8 +251,9 @@ var EActionPayloadType;
|
|
|
251
251
|
((EActionPayloadType2) => {
|
|
252
252
|
EActionPayloadType2["request"] = "request";
|
|
253
253
|
EActionPayloadType2["progress"] = "progress";
|
|
254
|
-
EActionPayloadType2["stream"] = "stream";
|
|
255
254
|
EActionPayloadType2["result"] = "result";
|
|
255
|
+
EActionPayloadType2["stream"] = "stream";
|
|
256
|
+
EActionPayloadType2["push"] = "push";
|
|
256
257
|
})(EActionPayloadType ||= {});
|
|
257
258
|
var EActionProgressType;
|
|
258
259
|
((EActionProgressType2) => {
|
|
@@ -572,7 +573,7 @@ class RunningAction {
|
|
|
572
573
|
return this._completeWithResult(result);
|
|
573
574
|
}
|
|
574
575
|
}
|
|
575
|
-
//
|
|
576
|
+
// ../../node_modules/.bun/@nice-code+error@0.1.3+7524df1edfed9f02/node_modules/@nice-code/error/build/index.js
|
|
576
577
|
var ACCEPTED = 202;
|
|
577
578
|
var BAD_GATEWAY = 502;
|
|
578
579
|
var BAD_REQUEST = 400;
|
|
@@ -3257,7 +3258,7 @@ var EErrId_NiceAction;
|
|
|
3257
3258
|
EErrId_NiceAction2["hydration_action_state_mismatch"] = "hydration_action_state_mismatch";
|
|
3258
3259
|
EErrId_NiceAction2["hydration_action_id_not_found"] = "hydration_action_id_not_found";
|
|
3259
3260
|
EErrId_NiceAction2["no_action_execution_handler"] = "no_action_execution_handler";
|
|
3260
|
-
EErrId_NiceAction2["
|
|
3261
|
+
EErrId_NiceAction2["wire_action_not_payload"] = "wire_action_not_payload";
|
|
3261
3262
|
EErrId_NiceAction2["wire_not_action_data"] = "wire_not_action_data";
|
|
3262
3263
|
EErrId_NiceAction2["client_runtime_already_registered"] = "client_runtime_already_registered";
|
|
3263
3264
|
EErrId_NiceAction2["client_runtime_not_registered"] = "client_runtime_not_registered";
|
|
@@ -3295,11 +3296,11 @@ var err_nice_action = err_nice.createChildDomain({
|
|
|
3295
3296
|
["no_action_execution_handler" /* no_action_execution_handler */]: err({
|
|
3296
3297
|
message: ({ domain, actionId, specifiedClient }) => `${specifiedClient ? ` The targeted client runtime [${specifiedClient.stringId}] has no` : "No"} action handler registered for "${actionId}" in domain "${domain}".`
|
|
3297
3298
|
}),
|
|
3298
|
-
["
|
|
3299
|
-
message: ({ domain, actionId, actionState }) => `Cannot handle wire for action "${actionId}" in domain "${domain}": expected action type of "
|
|
3299
|
+
["wire_action_not_payload" /* wire_action_not_payload */]: err({
|
|
3300
|
+
message: ({ domain, actionId, actionState }) => `Cannot handle wire for action "${actionId}" in domain "${domain}": expected action form of "${"data" /* data */}" and type of "${"request" /* request */}", "${"progress" /* progress */}" or "${"result" /* result */}", got "${actionState}".`
|
|
3300
3301
|
}),
|
|
3301
3302
|
["wire_not_action_data" /* wire_not_action_data */]: err({
|
|
3302
|
-
message: () => `Cannot handle wire for action: expected an object with a "domain" property of type string and a "type" property of "
|
|
3303
|
+
message: () => `Cannot handle wire for action: expected an object with a "domain" property of type string, a "form" property of "${"data" /* data */}" and a "type" property of "${"request" /* request */}", "${"progress" /* progress */}" or "${"result" /* result */}".`
|
|
3303
3304
|
}),
|
|
3304
3305
|
["client_runtime_already_registered" /* client_runtime_already_registered */]: err({
|
|
3305
3306
|
message: ({ context, client }) => `Environment is already registered${context?.domain ? ` on domain "${context.domain}"` : ""} for client [${client.stringId}]. Each client specifier (exact match on all properties) may only be registered once.`
|
|
@@ -3336,34 +3337,90 @@ var isAction_Base_JsonObject = (obj) => {
|
|
|
3336
3337
|
return typeof obj === "object" && obj !== null && typeof obj.domain === "string" && typeof obj.id === "string" && typeof obj.form === "string";
|
|
3337
3338
|
};
|
|
3338
3339
|
|
|
3339
|
-
// src/utils/
|
|
3340
|
-
var
|
|
3341
|
-
return isAction_Base_JsonObject(obj) && obj.form === "
|
|
3340
|
+
// src/utils/isActionPayload_Result_JsonObject.ts
|
|
3341
|
+
var isActionPayload_Result_JsonObject = (obj) => {
|
|
3342
|
+
return isAction_Base_JsonObject(obj) && obj.result != null && obj.form === "data" /* data */ && obj.type === "result" /* result */;
|
|
3342
3343
|
};
|
|
3343
3344
|
|
|
3344
|
-
//
|
|
3345
|
-
var
|
|
3346
|
-
|
|
3345
|
+
// ../../node_modules/.bun/std-env@4.1.0/node_modules/std-env/dist/index.mjs
|
|
3346
|
+
var e = globalThis.process?.env || Object.create(null);
|
|
3347
|
+
var t = globalThis.process || { env: e };
|
|
3348
|
+
var n = t !== undefined && t.env && t.env.NODE_ENV || undefined;
|
|
3349
|
+
var r = [[`claude`, [`CLAUDECODE`, `CLAUDE_CODE`]], [`replit`, [`REPL_ID`]], [`gemini`, [`GEMINI_CLI`]], [`codex`, [`CODEX_SANDBOX`, `CODEX_THREAD_ID`]], [`opencode`, [`OPENCODE`]], [`pi`, [i(`PATH`, /\.pi[\\/]agent/)]], [`auggie`, [`AUGMENT_AGENT`]], [`goose`, [`GOOSE_PROVIDER`]], [`devin`, [i(`EDITOR`, /devin/)]], [`cursor`, [`CURSOR_AGENT`]], [`kiro`, [i(`TERM_PROGRAM`, /kiro/)]]];
|
|
3350
|
+
function i(t2, n2) {
|
|
3351
|
+
return () => {
|
|
3352
|
+
let r2 = e[t2];
|
|
3353
|
+
return r2 ? n2.test(r2) : false;
|
|
3354
|
+
};
|
|
3355
|
+
}
|
|
3356
|
+
function a() {
|
|
3357
|
+
let t2 = e.AI_AGENT;
|
|
3358
|
+
if (t2)
|
|
3359
|
+
return { name: t2.toLowerCase() };
|
|
3360
|
+
for (let [t3, n2] of r)
|
|
3361
|
+
for (let r2 of n2)
|
|
3362
|
+
if (typeof r2 == `string` ? e[r2] : r2())
|
|
3363
|
+
return { name: t3 };
|
|
3364
|
+
return {};
|
|
3365
|
+
}
|
|
3366
|
+
var o = a();
|
|
3367
|
+
var s = o.name;
|
|
3368
|
+
var c = !!o.name;
|
|
3369
|
+
var l = [[`APPVEYOR`], [`AWS_AMPLIFY`, `AWS_APP_ID`, { ci: true }], [`AZURE_PIPELINES`, `SYSTEM_TEAMFOUNDATIONCOLLECTIONURI`], [`AZURE_STATIC`, `INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN`], [`APPCIRCLE`, `AC_APPCIRCLE`], [`BAMBOO`, `bamboo_planKey`], [`BITBUCKET`, `BITBUCKET_COMMIT`], [`BITRISE`, `BITRISE_IO`], [`BUDDY`, `BUDDY_WORKSPACE_ID`], [`BUILDKITE`], [`CIRCLE`, `CIRCLECI`], [`CIRRUS`, `CIRRUS_CI`], [`CLOUDFLARE_PAGES`, `CF_PAGES`, { ci: true }], [`CLOUDFLARE_WORKERS`, `WORKERS_CI`, { ci: true }], [`GOOGLE_CLOUDRUN`, `K_SERVICE`], [`GOOGLE_CLOUDRUN_JOB`, `CLOUD_RUN_JOB`], [`CODEBUILD`, `CODEBUILD_BUILD_ARN`], [`CODEFRESH`, `CF_BUILD_ID`], [`DRONE`], [`DRONE`, `DRONE_BUILD_EVENT`], [`DSARI`], [`GITHUB_ACTIONS`], [`GITLAB`, `GITLAB_CI`], [`GITLAB`, `CI_MERGE_REQUEST_ID`], [`GOCD`, `GO_PIPELINE_LABEL`], [`LAYERCI`], [`JENKINS`, `JENKINS_URL`], [`HUDSON`, `HUDSON_URL`], [`MAGNUM`], [`NETLIFY`], [`NETLIFY`, `NETLIFY_LOCAL`, { ci: false }], [`NEVERCODE`], [`RENDER`], [`SAIL`, `SAILCI`], [`SEMAPHORE`], [`SCREWDRIVER`], [`SHIPPABLE`], [`SOLANO`, `TDDIUM`], [`STRIDER`], [`TEAMCITY`, `TEAMCITY_VERSION`], [`TRAVIS`], [`VERCEL`, `NOW_BUILDER`], [`VERCEL`, `VERCEL`, { ci: false }], [`VERCEL`, `VERCEL_ENV`, { ci: false }], [`APPCENTER`, `APPCENTER_BUILD_ID`], [`CODESANDBOX`, `CODESANDBOX_SSE`, { ci: false }], [`CODESANDBOX`, `CODESANDBOX_HOST`, { ci: false }], [`STACKBLITZ`], [`STORMKIT`], [`CLEAVR`], [`ZEABUR`], [`CODESPHERE`, `CODESPHERE_APP_ID`, { ci: true }], [`RAILWAY`, `RAILWAY_PROJECT_ID`], [`RAILWAY`, `RAILWAY_SERVICE_ID`], [`DENO-DEPLOY`, `DENO_DEPLOY`], [`DENO-DEPLOY`, `DENO_DEPLOYMENT_ID`], [`FIREBASE_APP_HOSTING`, `FIREBASE_APP_HOSTING`, { ci: true }], [`EDGEONE_PAGES`, `EO_PAGES_CI`, { ci: true }]];
|
|
3370
|
+
function u() {
|
|
3371
|
+
for (let t2 of l)
|
|
3372
|
+
if (e[t2[1] || t2[0]])
|
|
3373
|
+
return { name: t2[0].toLowerCase(), ...t2[2] };
|
|
3374
|
+
return e.SHELL === `/bin/jsh` && t.versions?.webcontainer ? { name: `stackblitz`, ci: false } : { name: ``, ci: false };
|
|
3375
|
+
}
|
|
3376
|
+
var d = u();
|
|
3377
|
+
var f = d.name;
|
|
3378
|
+
var p = t.platform || ``;
|
|
3379
|
+
var m = !!e.CI || d.ci !== false;
|
|
3380
|
+
var h = !!t.stdout?.isTTY;
|
|
3381
|
+
var _ = !!e.DEBUG;
|
|
3382
|
+
var v = n === `test` || !!e.TEST;
|
|
3383
|
+
var y = n === `production` || e.MODE === `production`;
|
|
3384
|
+
var b = n === `dev` || n === `development` || e.MODE === `development`;
|
|
3385
|
+
var x = !!e.MINIMAL || m || v || !h;
|
|
3386
|
+
var S = /^win/i.test(p);
|
|
3387
|
+
var C = /^linux/i.test(p);
|
|
3388
|
+
var w = /^darwin/i.test(p);
|
|
3389
|
+
var T = !e.NO_COLOR && (!!e.FORCE_COLOR || (h || S) && e.TERM !== `dumb` || m);
|
|
3390
|
+
var E = (t.versions?.node || ``).replace(/^v/, ``) || null;
|
|
3391
|
+
var D = Number(E?.split(`.`)[0]) || null;
|
|
3392
|
+
var O = !!t?.versions?.node;
|
|
3393
|
+
var k = `Bun` in globalThis;
|
|
3394
|
+
var A = `Deno` in globalThis;
|
|
3395
|
+
var j = `fastly` in globalThis;
|
|
3396
|
+
var M = `Netlify` in globalThis;
|
|
3397
|
+
var N = `EdgeRuntime` in globalThis;
|
|
3398
|
+
var P = globalThis.navigator?.userAgent === `Cloudflare-Workers`;
|
|
3399
|
+
var F = [[M, `netlify`], [N, `edge-light`], [P, `workerd`], [j, `fastly`], [A, `deno`], [k, `bun`], [O, `node`]];
|
|
3400
|
+
function I() {
|
|
3401
|
+
let e2 = F.find((e3) => e3[0]);
|
|
3402
|
+
if (e2)
|
|
3403
|
+
return { name: e2[1] };
|
|
3404
|
+
}
|
|
3405
|
+
var L = I();
|
|
3406
|
+
var R = L?.name || ``;
|
|
3407
|
+
|
|
3408
|
+
// src/utils/getAssumedRuntimeEnvironment.ts
|
|
3409
|
+
var getAssumedRuntimeInfo = () => {
|
|
3410
|
+
return {
|
|
3411
|
+
assumed: true,
|
|
3412
|
+
runtimeName: R
|
|
3413
|
+
};
|
|
3347
3414
|
};
|
|
3348
3415
|
|
|
3349
3416
|
// src/utils/isActionPayload_Progress_JsonObject.ts
|
|
3350
3417
|
var isActionPayload_Progress_JsonObject = (obj) => {
|
|
3351
|
-
return isAction_Base_JsonObject(obj) && "
|
|
3418
|
+
return isAction_Base_JsonObject(obj) && "progress" in obj && obj.form === "data" /* data */ && obj.type === "progress" /* progress */;
|
|
3352
3419
|
};
|
|
3353
3420
|
|
|
3354
3421
|
// src/utils/isActionPayload_Request_JsonObject.ts
|
|
3355
3422
|
var isActionPayload_Request_JsonObject = (obj) => {
|
|
3356
|
-
return isAction_Base_JsonObject(obj) && "input" in obj && obj.type === "request" /* request */;
|
|
3357
|
-
};
|
|
3358
|
-
|
|
3359
|
-
// src/utils/isActionPayload_Result_JsonObject.ts
|
|
3360
|
-
var isActionPayload_Result_JsonObject = (obj) => {
|
|
3361
|
-
if (!isAction_Base_JsonObject(obj))
|
|
3362
|
-
return false;
|
|
3363
|
-
if (obj.type !== "result" /* result */)
|
|
3364
|
-
return false;
|
|
3365
|
-
const result = obj.result;
|
|
3366
|
-
return result != null && typeof result === "object" && typeof result.ok === "boolean" && (("output" in result) || ("error" in result));
|
|
3423
|
+
return isAction_Base_JsonObject(obj) && "input" in obj && obj.form === "data" /* data */ && obj.type === "request" /* request */;
|
|
3367
3424
|
};
|
|
3368
3425
|
|
|
3369
3426
|
// src/utils/isActionPayload_Any_JsonObject.ts
|
|
@@ -3371,321 +3428,802 @@ function isActionPayload_Any_JsonObject(obj) {
|
|
|
3371
3428
|
return isActionPayload_Request_JsonObject(obj) || isActionPayload_Result_JsonObject(obj) || isActionPayload_Progress_JsonObject(obj);
|
|
3372
3429
|
}
|
|
3373
3430
|
|
|
3374
|
-
// src/
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
// src/utils/assertIsActionJson.ts
|
|
3380
|
-
function assertIsActionJson(obj) {
|
|
3381
|
-
if (!isAction_Any_JsonObject(obj)) {
|
|
3382
|
-
throw err_nice_action.fromId("wire_not_action_data" /* wire_not_action_data */);
|
|
3383
|
-
}
|
|
3384
|
-
}
|
|
3385
|
-
|
|
3386
|
-
// src/utils/isAction_Any_Instance.ts
|
|
3387
|
-
function isAction_Any_Instance(value) {
|
|
3388
|
-
return value instanceof ActionCore || value instanceof ActionPayload || value instanceof ActionContext;
|
|
3389
|
-
}
|
|
3390
|
-
|
|
3391
|
-
// src/ActionDefinition/Domain/ActionDomainBase.ts
|
|
3392
|
-
class ActionDomainBase {
|
|
3393
|
-
domain;
|
|
3394
|
-
allDomains;
|
|
3395
|
-
actions;
|
|
3396
|
-
_listeners = [];
|
|
3397
|
-
constructor(definition) {
|
|
3398
|
-
this.domain = definition.domain;
|
|
3399
|
-
this.allDomains = definition.allDomains;
|
|
3400
|
-
this.actions = definition.actions;
|
|
3401
|
-
}
|
|
3402
|
-
addActionListener(listener) {
|
|
3403
|
-
this._listeners.push(listener);
|
|
3404
|
-
return () => {
|
|
3405
|
-
this._listeners = this._listeners.filter((l) => l !== listener);
|
|
3406
|
-
};
|
|
3431
|
+
// src/ActionRuntime/ActionDomainManager.ts
|
|
3432
|
+
class ActionDomainManager {
|
|
3433
|
+
_domains = new Map;
|
|
3434
|
+
addDomain(domain) {
|
|
3435
|
+
this._domains.set(domain.domain, domain);
|
|
3407
3436
|
}
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
// src/ActionDefinition/Domain/ActionDomain.ts
|
|
3411
|
-
class ActionDomain extends ActionDomainBase {
|
|
3412
|
-
_rootDomain;
|
|
3413
|
-
constructor(definition, {
|
|
3414
|
-
rootDomain
|
|
3415
|
-
}) {
|
|
3416
|
-
super(definition);
|
|
3417
|
-
this._rootDomain = rootDomain;
|
|
3437
|
+
getDomains() {
|
|
3438
|
+
return [...this._domains.values()];
|
|
3418
3439
|
}
|
|
3419
|
-
|
|
3420
|
-
|
|
3440
|
+
verifyIsActionJson(action) {
|
|
3441
|
+
if (typeof action.domain !== "string" || typeof action.id !== "string") {
|
|
3442
|
+
throw err_nice_action.fromId("wire_not_action_data" /* wire_not_action_data */);
|
|
3443
|
+
}
|
|
3421
3444
|
}
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
parentDomain: this.domain
|
|
3428
|
-
});
|
|
3445
|
+
getActionDomain(action) {
|
|
3446
|
+
this.verifyIsActionJson(action);
|
|
3447
|
+
const domain = this._domains.get(action.domain);
|
|
3448
|
+
if (!domain) {
|
|
3449
|
+
return;
|
|
3429
3450
|
}
|
|
3430
|
-
return
|
|
3431
|
-
allDomains: [subDomainDef.domain, ...this.allDomains],
|
|
3432
|
-
domain: subDomainDef.domain,
|
|
3433
|
-
actions: subDomainDef.actions
|
|
3434
|
-
}, { rootDomain: this._rootDomain });
|
|
3451
|
+
return domain;
|
|
3435
3452
|
}
|
|
3436
|
-
action
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3453
|
+
getActionDomainOrThrow(action) {
|
|
3454
|
+
this.verifyIsActionJson(action);
|
|
3455
|
+
const domain = this._domains.get(action.domain);
|
|
3456
|
+
if (!domain) {
|
|
3457
|
+
throw err_nice_action.fromId("domain_no_handler" /* domain_no_handler */, {
|
|
3458
|
+
domain: action.domain
|
|
3442
3459
|
});
|
|
3443
3460
|
}
|
|
3444
|
-
return
|
|
3461
|
+
return domain;
|
|
3445
3462
|
}
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
cuid: contextData.cuid,
|
|
3450
|
-
routing: contextData.routing.map((item) => {
|
|
3451
|
-
return {
|
|
3452
|
-
runtime: new ActionClientSpecifier(item.runtime),
|
|
3453
|
-
handler: item.handler,
|
|
3454
|
-
time: item.time
|
|
3455
|
-
};
|
|
3456
|
-
}),
|
|
3457
|
-
originClient: contextData.originClient ? new ActionClientSpecifier(contextData.originClient) : ActionClientSpecifier.unknown
|
|
3458
|
-
});
|
|
3463
|
+
hydrateActionPayload(actionJson) {
|
|
3464
|
+
const domain = this.getActionDomainOrThrow(actionJson);
|
|
3465
|
+
return domain.hydrateAnyAction(actionJson);
|
|
3459
3466
|
}
|
|
3460
|
-
|
|
3461
|
-
|
|
3467
|
+
}
|
|
3468
|
+
|
|
3469
|
+
// src/ActionRuntime/Routing/ActionRouter.ts
|
|
3470
|
+
class ActionRouter {
|
|
3471
|
+
domainManager = new ActionDomainManager;
|
|
3472
|
+
actionRouteData = new Map;
|
|
3473
|
+
_context;
|
|
3474
|
+
constructor(context) {
|
|
3475
|
+
this._context = context;
|
|
3462
3476
|
}
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
expected: "request" /* request */,
|
|
3467
|
-
received: serialized.type
|
|
3468
|
-
});
|
|
3477
|
+
mergeRouter(actionRouter) {
|
|
3478
|
+
for (const domain of actionRouter.getDomains()) {
|
|
3479
|
+
this.domainManager.addDomain(domain);
|
|
3469
3480
|
}
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
expected: this.domain,
|
|
3473
|
-
received: serialized.domain
|
|
3474
|
-
});
|
|
3481
|
+
for (const [matchKey, routeDataEntries] of actionRouter.actionRouteData.entries()) {
|
|
3482
|
+
this.actionRouteData.set(matchKey, [...routeDataEntries]);
|
|
3475
3483
|
}
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
actionId: serialized.id
|
|
3481
|
-
});
|
|
3484
|
+
}
|
|
3485
|
+
addDomainsFromOther(actionRouter) {
|
|
3486
|
+
for (const domain of actionRouter.getDomains()) {
|
|
3487
|
+
this.domainManager.addDomain(domain);
|
|
3482
3488
|
}
|
|
3483
|
-
const contextAction = this.hydrateContext(id, serialized.context);
|
|
3484
|
-
return new ActionPayload_Request({ context: contextAction }, contextAction.deserializeInput(serialized.input), {
|
|
3485
|
-
time: serialized.time
|
|
3486
|
-
});
|
|
3487
3489
|
}
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3490
|
+
getRouteDataEntriesForAction(action) {
|
|
3491
|
+
const idKey = `dom[${action.domain}]id[${action.id}]`;
|
|
3492
|
+
const domKey = `dom[${action.domain}]id[_]`;
|
|
3493
|
+
return [
|
|
3494
|
+
...this.actionRouteData.get(idKey) ?? [],
|
|
3495
|
+
...this.actionRouteData.get(domKey) ?? []
|
|
3496
|
+
];
|
|
3497
|
+
}
|
|
3498
|
+
getRouteDataForAction(action) {
|
|
3499
|
+
return this.getRouteDataEntriesForAction(action)[0];
|
|
3500
|
+
}
|
|
3501
|
+
throwNoHandlerForAction(action, context) {
|
|
3502
|
+
if (this._context.contextType === "handler_route" /* handler_route */) {
|
|
3503
|
+
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
3504
|
+
domain: action.domain,
|
|
3505
|
+
actionId: action.id,
|
|
3506
|
+
specifiedClient: context.targetLocalRuntime?.clientSpecifier
|
|
3493
3507
|
});
|
|
3494
3508
|
}
|
|
3495
|
-
if (
|
|
3496
|
-
throw err_nice_action.fromId("
|
|
3497
|
-
|
|
3498
|
-
|
|
3509
|
+
if (this._context.contextType === "runtime_to_handler" /* runtime_to_handler */) {
|
|
3510
|
+
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
3511
|
+
domain: action.domain,
|
|
3512
|
+
actionId: action.id,
|
|
3513
|
+
specifiedClient: this._context.runtime.clientSpecifier
|
|
3499
3514
|
});
|
|
3500
3515
|
}
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3516
|
+
throw new Error(`No route function found for action with domain "${action.domain}" and id "${action.id}".`);
|
|
3517
|
+
}
|
|
3518
|
+
getRouteDataEntriesForActionOrThrow(action, context) {
|
|
3519
|
+
const entries = this.getRouteDataEntriesForAction(action);
|
|
3520
|
+
if (entries.length === 0) {
|
|
3521
|
+
this.throwNoHandlerForAction(action, context);
|
|
3507
3522
|
}
|
|
3508
|
-
|
|
3509
|
-
return new ActionPayload_Result({ context: contextAction }, serialized.result, {
|
|
3510
|
-
time: serialized.time
|
|
3511
|
-
});
|
|
3523
|
+
return entries;
|
|
3512
3524
|
}
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
if (
|
|
3516
|
-
|
|
3517
|
-
return this.hydrateRequest(actionJson);
|
|
3518
|
-
}
|
|
3519
|
-
if (actionJson.type === "result" /* result */) {
|
|
3520
|
-
return this.hydrateResultPayload(actionJson);
|
|
3521
|
-
}
|
|
3525
|
+
getRouteDataForActionOrThrow(action, context) {
|
|
3526
|
+
const routeData = this.getRouteDataForAction(action);
|
|
3527
|
+
if (!routeData) {
|
|
3528
|
+
this.throwNoHandlerForAction(action, context);
|
|
3522
3529
|
}
|
|
3523
|
-
return
|
|
3530
|
+
return routeData;
|
|
3524
3531
|
}
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
...options?.listeners ?? [],
|
|
3528
|
-
...this._listeners
|
|
3529
|
-
];
|
|
3530
|
-
return this._rootDomain._runAction(request, {
|
|
3531
|
-
...options,
|
|
3532
|
-
listeners: allListeners
|
|
3533
|
-
});
|
|
3532
|
+
getForKey(key) {
|
|
3533
|
+
return this.actionRouteData.get(key) ?? [];
|
|
3534
3534
|
}
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
class ActionRuntimeManager {
|
|
3538
|
-
_runtimes = new Map;
|
|
3539
|
-
_preferredRuntimeClientId = null;
|
|
3540
|
-
_context;
|
|
3541
|
-
constructor(context) {
|
|
3542
|
-
this._context = context ?? {};
|
|
3535
|
+
getRegisteredKeys() {
|
|
3536
|
+
return [...this.actionRouteData.keys()];
|
|
3543
3537
|
}
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
if (this._runtimes.has(runtimeId)) {
|
|
3547
|
-
throw err_nice_action.fromId("client_runtime_already_registered" /* client_runtime_already_registered */, {
|
|
3548
|
-
context: this._context,
|
|
3549
|
-
client: runtime2.clientSpecifier
|
|
3550
|
-
});
|
|
3551
|
-
}
|
|
3552
|
-
for (const id of runtime2.clientSpecifier.toStringIds()) {
|
|
3553
|
-
if (this._runtimes.has(id)) {
|
|
3554
|
-
continue;
|
|
3555
|
-
}
|
|
3556
|
-
this._runtimes.set(id, runtime2);
|
|
3557
|
-
}
|
|
3538
|
+
getDomains() {
|
|
3539
|
+
return this.domainManager.getDomains();
|
|
3558
3540
|
}
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
}
|
|
3541
|
+
forDomain(domain, routeData) {
|
|
3542
|
+
this.domainManager.addDomain(domain);
|
|
3543
|
+
this.actionRouteData.set(`dom[${domain.domain}]id[_]`, [routeData]);
|
|
3544
|
+
return this;
|
|
3545
|
+
}
|
|
3546
|
+
forAction(action, routeData) {
|
|
3547
|
+
return this.forActionId(action._domain, action.id, routeData);
|
|
3548
|
+
}
|
|
3549
|
+
forActionId(domain, id, routeData) {
|
|
3550
|
+
this.domainManager.addDomain(domain);
|
|
3551
|
+
this.actionRouteData.set(`dom[${domain.domain}]id[${id}]`, [routeData]);
|
|
3552
|
+
return this;
|
|
3553
|
+
}
|
|
3554
|
+
forActionIds(domain, ids, routeData) {
|
|
3555
|
+
this.domainManager.addDomain(domain);
|
|
3556
|
+
for (const id of ids) {
|
|
3557
|
+
this.forActionId(domain, id, routeData);
|
|
3577
3558
|
}
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3559
|
+
return this;
|
|
3560
|
+
}
|
|
3561
|
+
forDomainActionCases(domain, cases) {
|
|
3562
|
+
this.domainManager.addDomain(domain);
|
|
3563
|
+
for (const id of Object.keys(cases)) {
|
|
3564
|
+
const routeData = cases[id];
|
|
3565
|
+
if (routeData != null) {
|
|
3566
|
+
this.actionRouteData.set(`dom[${domain.domain}]id[${id}]`, [routeData]);
|
|
3582
3567
|
}
|
|
3583
3568
|
}
|
|
3584
|
-
|
|
3585
|
-
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
3586
|
-
domain: action.domain,
|
|
3587
|
-
actionId: action.id,
|
|
3588
|
-
specifiedClient: options?.targetLocalRuntime?.clientSpecifier
|
|
3589
|
-
});
|
|
3590
|
-
}
|
|
3569
|
+
return this;
|
|
3591
3570
|
}
|
|
3592
|
-
|
|
3593
|
-
|
|
3571
|
+
addForDomain(domain, routeData) {
|
|
3572
|
+
this.domainManager.addDomain(domain);
|
|
3573
|
+
this._push(`dom[${domain.domain}]id[_]`, routeData);
|
|
3574
|
+
return this;
|
|
3594
3575
|
}
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
this.
|
|
3576
|
+
addForAction(domain, id, routeData) {
|
|
3577
|
+
this.domainManager.addDomain(domain);
|
|
3578
|
+
this._push(`dom[${domain.domain}]id[${id}]`, routeData);
|
|
3579
|
+
return this;
|
|
3598
3580
|
}
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
return runtime2;
|
|
3604
|
-
}
|
|
3581
|
+
addForActionIds(domain, ids, routeData) {
|
|
3582
|
+
this.domainManager.addDomain(domain);
|
|
3583
|
+
for (const id of ids) {
|
|
3584
|
+
this.addForAction(domain, id, routeData);
|
|
3605
3585
|
}
|
|
3606
|
-
return this
|
|
3586
|
+
return this;
|
|
3607
3587
|
}
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
const
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
return runtime2;
|
|
3588
|
+
addForDomainActionCases(domain, cases) {
|
|
3589
|
+
this.domainManager.addDomain(domain);
|
|
3590
|
+
for (const id of Object.keys(cases)) {
|
|
3591
|
+
const routeData = cases[id];
|
|
3592
|
+
if (routeData != null) {
|
|
3593
|
+
this._push(`dom[${domain.domain}]id[${id}]`, routeData);
|
|
3615
3594
|
}
|
|
3616
3595
|
}
|
|
3596
|
+
return this;
|
|
3617
3597
|
}
|
|
3618
|
-
|
|
3619
|
-
|
|
3598
|
+
addForKey(key, routeData) {
|
|
3599
|
+
this._push(key, routeData);
|
|
3600
|
+
return this;
|
|
3620
3601
|
}
|
|
3621
|
-
|
|
3622
|
-
const
|
|
3623
|
-
if (
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
});
|
|
3628
|
-
}
|
|
3629
|
-
throw err_nice_action.fromId("client_runtime_not_registered" /* client_runtime_not_registered */, {
|
|
3630
|
-
context: this._context,
|
|
3631
|
-
clientStringId: clientSpecifierToStringIds(specifier)[0]
|
|
3632
|
-
});
|
|
3602
|
+
_push(key, routeData) {
|
|
3603
|
+
const existing = this.actionRouteData.get(key);
|
|
3604
|
+
if (existing != null) {
|
|
3605
|
+
existing.push(routeData);
|
|
3606
|
+
} else {
|
|
3607
|
+
this.actionRouteData.set(key, [routeData]);
|
|
3633
3608
|
}
|
|
3634
|
-
return runtime2;
|
|
3635
3609
|
}
|
|
3636
3610
|
}
|
|
3637
3611
|
|
|
3638
|
-
// src/
|
|
3639
|
-
class
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3612
|
+
// src/ActionRuntime/ActionRuntime.ts
|
|
3613
|
+
class ActionRuntime {
|
|
3614
|
+
clientSpecifier;
|
|
3615
|
+
timeCreated;
|
|
3616
|
+
runtimeInfo = getAssumedRuntimeInfo();
|
|
3617
|
+
actionRouter;
|
|
3618
|
+
_pendingRunningActions = new Map;
|
|
3619
|
+
_registeredExternalHandlers = [];
|
|
3620
|
+
static getDefault() {
|
|
3621
|
+
return getDefaultActionRuntime();
|
|
3622
|
+
}
|
|
3623
|
+
constructor(client) {
|
|
3624
|
+
this.clientSpecifier = client.specifyIfUnset({
|
|
3625
|
+
insId: nanoid(14)
|
|
3626
|
+
});
|
|
3627
|
+
this.timeCreated = Date.now();
|
|
3628
|
+
this.actionRouter = new ActionRouter({
|
|
3629
|
+
contextType: "runtime_to_handler" /* runtime_to_handler */,
|
|
3630
|
+
runtime: this
|
|
3648
3631
|
});
|
|
3649
|
-
this.domainDefinition = domainDefinition;
|
|
3650
|
-
this._actionRuntimeManager = new ActionRuntimeManager({ domain: domainId });
|
|
3651
3632
|
}
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3633
|
+
registerRunningAction(ra) {
|
|
3634
|
+
this._pendingRunningActions.set(ra.cuid, ra);
|
|
3635
|
+
ra.addUpdateListeners([
|
|
3636
|
+
(update) => {
|
|
3637
|
+
if (update.type === "finished" /* finished */) {
|
|
3638
|
+
this._pendingRunningActions.delete(ra.cuid);
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
]);
|
|
3642
|
+
}
|
|
3643
|
+
resolveIncomingActionPayload(json) {
|
|
3644
|
+
if (json.type === "request" /* request */) {
|
|
3645
|
+
this.handleActionPayloadWire(json).catch((err2) => {
|
|
3646
|
+
console.error(`[ActionRuntime] Incoming action [${json.domain}:${json.id}:${json.form}:${json.type}] unhandled:`, err2);
|
|
3658
3647
|
});
|
|
3648
|
+
return;
|
|
3659
3649
|
}
|
|
3660
|
-
|
|
3661
|
-
allDomains: [subDomainDef.domain, ...this.allDomains],
|
|
3662
|
-
domain: subDomainDef.domain,
|
|
3663
|
-
actions: subDomainDef.actions
|
|
3664
|
-
}, { rootDomain: this });
|
|
3665
|
-
}
|
|
3666
|
-
addActionRuntime(runtime2) {
|
|
3667
|
-
this._actionRuntimeManager.registerRuntime(runtime2);
|
|
3668
|
-
return this;
|
|
3669
|
-
}
|
|
3670
|
-
getRuntime(clientSpecifier) {
|
|
3671
|
-
return this._actionRuntimeManager.getBestRuntimeForSpecifier(clientSpecifier);
|
|
3650
|
+
this._pendingRunningActions.get(json.context.cuid)?._resolveFromJson(json);
|
|
3672
3651
|
}
|
|
3673
|
-
async
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3652
|
+
async handleActionPayloadWire(wire) {
|
|
3653
|
+
let action;
|
|
3654
|
+
if (isActionPayload_Any_JsonObject(wire)) {
|
|
3655
|
+
const domain = this.actionRouter.domainManager.getActionDomainOrThrow(wire);
|
|
3656
|
+
action = domain.hydrateAnyAction(wire);
|
|
3657
|
+
}
|
|
3658
|
+
if (action == null) {
|
|
3659
|
+
throw err_nice_action.fromId("wire_not_action_data" /* wire_not_action_data */);
|
|
3660
|
+
}
|
|
3661
|
+
return this.handleActionPayload(action);
|
|
3682
3662
|
}
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3663
|
+
async handleActionPayload(action, options) {
|
|
3664
|
+
const handlerForAction = this.getHandlerForActionOrThrow(action, options);
|
|
3665
|
+
if (action.type === "request" /* request */) {
|
|
3666
|
+
const runningAction = await handlerForAction.handleActionRequest(action, {
|
|
3667
|
+
...options,
|
|
3668
|
+
targetLocalRuntime: this
|
|
3669
|
+
});
|
|
3670
|
+
this._trySetupReturnDispatch(runningAction);
|
|
3671
|
+
return runningAction;
|
|
3672
|
+
}
|
|
3673
|
+
throw err_nice_action.fromId("not_implemented" /* not_implemented */, {
|
|
3674
|
+
label: `Handling incoming action payloads of type "${action.type}"`
|
|
3675
|
+
});
|
|
3676
|
+
}
|
|
3677
|
+
_getHandlerForAction(action, options) {
|
|
3678
|
+
const handlers = this.actionRouter.getRouteDataEntriesForAction(action);
|
|
3679
|
+
const targetExternalClient = options?.targetExternalClient;
|
|
3680
|
+
const possibleHandlers = handlers.filter((handler2) => {
|
|
3681
|
+
if (handler2.handlerType === "external" /* external */) {
|
|
3682
|
+
if (targetExternalClient && !targetExternalClient.isSameFor(handler2.externalClient).id) {
|
|
3683
|
+
return false;
|
|
3684
|
+
}
|
|
3685
|
+
return true;
|
|
3686
|
+
}
|
|
3687
|
+
if (targetExternalClient != null) {
|
|
3688
|
+
return false;
|
|
3689
|
+
}
|
|
3690
|
+
if (action.type === "request" /* request */) {
|
|
3691
|
+
return true;
|
|
3692
|
+
}
|
|
3693
|
+
return false;
|
|
3694
|
+
});
|
|
3695
|
+
if (possibleHandlers.length === 0) {
|
|
3696
|
+
return;
|
|
3697
|
+
}
|
|
3698
|
+
const scoringExternalClient = targetExternalClient ?? ActionClientSpecifier.unknown;
|
|
3699
|
+
let handlerScore = -1;
|
|
3700
|
+
let handler;
|
|
3701
|
+
for (const possibleHandler of possibleHandlers) {
|
|
3702
|
+
if (possibleHandler.handlerType === "local" /* local */ && handler == null) {
|
|
3703
|
+
return possibleHandler;
|
|
3704
|
+
}
|
|
3705
|
+
if (possibleHandler.handlerType === "external" /* external */) {
|
|
3706
|
+
const score = scoringExternalClient.similarityLevel(possibleHandler.externalClient);
|
|
3707
|
+
if (score > handlerScore) {
|
|
3708
|
+
handlerScore = score;
|
|
3709
|
+
handler = possibleHandler;
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
return handler;
|
|
3714
|
+
}
|
|
3715
|
+
getHandlerForActionOrThrow(action, options) {
|
|
3716
|
+
const handler = this._getHandlerForAction(action, options);
|
|
3717
|
+
if (handler == null) {
|
|
3718
|
+
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
3719
|
+
actionId: action.id,
|
|
3720
|
+
domain: action.domain,
|
|
3721
|
+
specifiedClient: options?.targetExternalClient
|
|
3722
|
+
});
|
|
3723
|
+
}
|
|
3724
|
+
return handler;
|
|
3725
|
+
}
|
|
3726
|
+
addHandlers(handlers) {
|
|
3727
|
+
for (const handler of handlers) {
|
|
3728
|
+
if (handler.handlerType === "external" /* external */) {
|
|
3729
|
+
handler._setIncomingActionDataListener((json) => this.resolveIncomingActionPayload(json));
|
|
3730
|
+
this._registeredExternalHandlers.push(handler);
|
|
3731
|
+
}
|
|
3732
|
+
const handlerRouter = handler.getActionRouter();
|
|
3733
|
+
this.actionRouter.addDomainsFromOther(handlerRouter);
|
|
3734
|
+
for (const key of handlerRouter.getRegisteredKeys()) {
|
|
3735
|
+
const alreadyRegistered = this.actionRouter.getForKey(key).some((h2) => h2.cuid === handler.cuid);
|
|
3736
|
+
if (!alreadyRegistered) {
|
|
3737
|
+
this.actionRouter.addForKey(key, handler);
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
return this;
|
|
3742
|
+
}
|
|
3743
|
+
getReturnHandlerForOrigin(originClient) {
|
|
3744
|
+
if (originClient.id === UNSET_CLIENT_ID)
|
|
3745
|
+
return;
|
|
3746
|
+
let bestScore = -1;
|
|
3747
|
+
let bestHandler;
|
|
3748
|
+
for (const handler of this._registeredExternalHandlers) {
|
|
3749
|
+
const score = originClient.similarityLevel(handler.externalClient);
|
|
3750
|
+
if (score > bestScore) {
|
|
3751
|
+
bestScore = score;
|
|
3752
|
+
bestHandler = handler;
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
return bestScore > 0 ? bestHandler : undefined;
|
|
3756
|
+
}
|
|
3757
|
+
_trySetupReturnDispatch(runningAction) {
|
|
3758
|
+
const originClient = runningAction.context.originClient;
|
|
3759
|
+
if (originClient.id === UNSET_CLIENT_ID || originClient.isSameFor(this.clientSpecifier).id) {
|
|
3760
|
+
return;
|
|
3761
|
+
}
|
|
3762
|
+
runningAction.addUpdateListeners([
|
|
3763
|
+
(update) => {
|
|
3764
|
+
if (update.type === "finished" /* finished */ && update.finishType === "success" /* success */) {
|
|
3765
|
+
const returnHandler = this.getReturnHandlerForOrigin(originClient);
|
|
3766
|
+
returnHandler?.sendReturnPayload(update.response, { targetLocalRuntime: this }).catch(() => {});
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
]);
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
var runtimeState = {
|
|
3773
|
+
defaultLocalRuntime: undefined,
|
|
3774
|
+
assumedRuntimeInfo: undefined
|
|
3775
|
+
};
|
|
3776
|
+
function getDefaultActionRuntime() {
|
|
3777
|
+
if (runtimeState.assumedRuntimeInfo == null) {
|
|
3778
|
+
runtimeState.assumedRuntimeInfo = getAssumedRuntimeInfo();
|
|
3779
|
+
}
|
|
3780
|
+
if (runtimeState.defaultLocalRuntime == null) {
|
|
3781
|
+
runtimeState.defaultLocalRuntime = new ActionRuntime(ActionClientSpecifier.unknown.specify({
|
|
3782
|
+
perId: `${runtimeState.assumedRuntimeInfo?.runtimeName ?? "unknown"}-runtime`
|
|
3783
|
+
}));
|
|
3784
|
+
}
|
|
3785
|
+
return runtimeState.defaultLocalRuntime;
|
|
3786
|
+
}
|
|
3787
|
+
|
|
3788
|
+
// src/ActionRuntime/Handler/ActionHandler.ts
|
|
3789
|
+
class ActionHandler {
|
|
3790
|
+
cuid;
|
|
3791
|
+
constructor() {
|
|
3792
|
+
this.cuid = nanoid();
|
|
3793
|
+
}
|
|
3794
|
+
getActionRouter() {
|
|
3795
|
+
return this.actionRouter;
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
|
|
3799
|
+
// src/ActionRuntime/Handler/Local/ActionLocalHandler.ts
|
|
3800
|
+
class ActionLocalHandler extends ActionHandler {
|
|
3801
|
+
handlerType = "local" /* local */;
|
|
3802
|
+
actionRouter = new ActionRouter({
|
|
3803
|
+
contextType: "handler_route" /* handler_route */,
|
|
3804
|
+
handler: this
|
|
3805
|
+
});
|
|
3806
|
+
constructor() {
|
|
3807
|
+
super();
|
|
3808
|
+
}
|
|
3809
|
+
forDomain(domain, handler) {
|
|
3810
|
+
this.actionRouter.forDomain(domain, handler);
|
|
3811
|
+
return this;
|
|
3812
|
+
}
|
|
3813
|
+
forAction(action, handler) {
|
|
3814
|
+
this.actionRouter.forAction(action, handler);
|
|
3815
|
+
return this;
|
|
3816
|
+
}
|
|
3817
|
+
forActionIds(domain, ids, handler) {
|
|
3818
|
+
this.actionRouter.forActionIds(domain, ids, handler);
|
|
3819
|
+
return this;
|
|
3820
|
+
}
|
|
3821
|
+
forDomainActionCases(domain, cases) {
|
|
3822
|
+
this.actionRouter.forDomainActionCases(domain, cases);
|
|
3823
|
+
return this;
|
|
3824
|
+
}
|
|
3825
|
+
async handleActionRequest(action, config) {
|
|
3826
|
+
const targetLocalRuntime = config?.targetLocalRuntime ?? ActionRuntime.getDefault();
|
|
3827
|
+
const handler = this.actionRouter.getRouteDataForActionOrThrow(action, {
|
|
3828
|
+
targetLocalRuntime
|
|
3829
|
+
});
|
|
3830
|
+
action.context.addRouteItem({
|
|
3831
|
+
runtime: targetLocalRuntime.clientSpecifier,
|
|
3832
|
+
handler: this.toHandlerRouteItem(),
|
|
3833
|
+
time: Date.now()
|
|
3834
|
+
});
|
|
3835
|
+
const runningAction = new RunningAction({ context: action.context, request: action });
|
|
3836
|
+
this._handleRunningAction(handler, runningAction).catch((err2) => runningAction._abort(err2));
|
|
3837
|
+
return runningAction;
|
|
3838
|
+
}
|
|
3839
|
+
async _handleRunningAction(handler, runningAction) {
|
|
3840
|
+
const state = runningAction.state;
|
|
3841
|
+
if (state.result != null) {
|
|
3842
|
+
return;
|
|
3843
|
+
}
|
|
3844
|
+
const rawResult = await handler(state.request);
|
|
3845
|
+
let result;
|
|
3846
|
+
if (rawResult instanceof ActionPayload_Result) {
|
|
3847
|
+
result = rawResult;
|
|
3848
|
+
} else if (rawResult != null && isActionPayload_Result_JsonObject(rawResult)) {
|
|
3849
|
+
const domain = this.actionRouter.domainManager.getActionDomainOrThrow(state.request);
|
|
3850
|
+
result = domain.hydrateResultPayload(rawResult);
|
|
3851
|
+
} else {
|
|
3852
|
+
result = state.request.successResult(rawResult);
|
|
3853
|
+
}
|
|
3854
|
+
runningAction._completeWithResult(result);
|
|
3855
|
+
}
|
|
3856
|
+
async handlePayloadWireOrThrow(wire, config) {
|
|
3857
|
+
const hydratedAction = this.actionRouter.domainManager.hydrateActionPayload(wire);
|
|
3858
|
+
if (!(hydratedAction instanceof ActionPayload_Request)) {
|
|
3859
|
+
throw err_nice_action.fromId("wire_action_not_payload" /* wire_action_not_payload */, {
|
|
3860
|
+
domain: hydratedAction.domain,
|
|
3861
|
+
actionId: hydratedAction.id,
|
|
3862
|
+
actionState: hydratedAction.type ?? hydratedAction.form
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3865
|
+
return await this.handleActionRequest(hydratedAction, config);
|
|
3866
|
+
}
|
|
3867
|
+
toJsonObject() {
|
|
3868
|
+
return {
|
|
3869
|
+
type: this.handlerType
|
|
3870
|
+
};
|
|
3871
|
+
}
|
|
3872
|
+
toHandlerRouteItem() {
|
|
3873
|
+
return {
|
|
3874
|
+
type: this.handlerType
|
|
3875
|
+
};
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3878
|
+
var createLocalHandler = () => {
|
|
3879
|
+
return new ActionLocalHandler;
|
|
3880
|
+
};
|
|
3881
|
+
|
|
3882
|
+
// src/utils/isAction_Context_JsonObject.ts
|
|
3883
|
+
var isAction_Context_JsonObject = (obj) => {
|
|
3884
|
+
return isAction_Base_JsonObject(obj) && obj.form === "context" /* context */;
|
|
3885
|
+
};
|
|
3886
|
+
|
|
3887
|
+
// src/utils/isAction_Core_JsonObject.ts
|
|
3888
|
+
var isAction_Core_JsonObject = (obj) => {
|
|
3889
|
+
return isAction_Base_JsonObject(obj) && obj.form === "core" /* core */;
|
|
3890
|
+
};
|
|
3891
|
+
|
|
3892
|
+
// src/utils/isAction_Any_JsonObject.ts
|
|
3893
|
+
function isAction_Any_JsonObject(obj) {
|
|
3894
|
+
return isActionPayload_Any_JsonObject(obj) || isAction_Context_JsonObject(obj) || isAction_Core_JsonObject(obj);
|
|
3895
|
+
}
|
|
3896
|
+
|
|
3897
|
+
// src/utils/assertIsActionJson.ts
|
|
3898
|
+
function assertIsActionJson(obj) {
|
|
3899
|
+
if (!isAction_Any_JsonObject(obj)) {
|
|
3900
|
+
throw err_nice_action.fromId("wire_not_action_data" /* wire_not_action_data */);
|
|
3901
|
+
}
|
|
3902
|
+
}
|
|
3903
|
+
|
|
3904
|
+
// src/utils/isAction_Any_Instance.ts
|
|
3905
|
+
function isAction_Any_Instance(value) {
|
|
3906
|
+
return value instanceof ActionCore || value instanceof ActionPayload || value instanceof ActionContext;
|
|
3907
|
+
}
|
|
3908
|
+
|
|
3909
|
+
// src/ActionDefinition/Domain/ActionDomainBase.ts
|
|
3910
|
+
class ActionDomainBase {
|
|
3911
|
+
domain;
|
|
3912
|
+
allDomains;
|
|
3913
|
+
actionSchema;
|
|
3914
|
+
_listeners = [];
|
|
3915
|
+
constructor(definition) {
|
|
3916
|
+
this.domain = definition.domain;
|
|
3917
|
+
this.allDomains = definition.allDomains;
|
|
3918
|
+
this.actionSchema = definition.actionSchema;
|
|
3919
|
+
}
|
|
3920
|
+
addActionListener(listener) {
|
|
3921
|
+
this._listeners.push(listener);
|
|
3922
|
+
return () => {
|
|
3923
|
+
this._listeners = this._listeners.filter((l2) => l2 !== listener);
|
|
3924
|
+
};
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3928
|
+
// src/ActionDefinition/Domain/ActionDomain.ts
|
|
3929
|
+
class ActionDomain extends ActionDomainBase {
|
|
3930
|
+
_rootDomain;
|
|
3931
|
+
_actionMap;
|
|
3932
|
+
constructor(definition, {
|
|
3933
|
+
rootDomain
|
|
3934
|
+
}) {
|
|
3935
|
+
super(definition);
|
|
3936
|
+
this._rootDomain = rootDomain;
|
|
3937
|
+
this._actionMap = this.createActionMap();
|
|
3938
|
+
}
|
|
3939
|
+
get rootDomain() {
|
|
3940
|
+
return this._rootDomain;
|
|
3941
|
+
}
|
|
3942
|
+
createChildDomain(subDomainDef) {
|
|
3943
|
+
if (this.allDomains.includes(subDomainDef.domain)) {
|
|
3944
|
+
throw err_nice_action.fromId("domain_already_exists_in_hierarchy" /* domain_already_exists_in_hierarchy */, {
|
|
3945
|
+
domain: subDomainDef.domain,
|
|
3946
|
+
allParentDomains: this.allDomains,
|
|
3947
|
+
parentDomain: this.domain
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3950
|
+
return new ActionDomain({
|
|
3951
|
+
allDomains: [...this.allDomains, subDomainDef.domain],
|
|
3952
|
+
domain: subDomainDef.domain,
|
|
3953
|
+
actionSchema: subDomainDef.actions
|
|
3954
|
+
}, { rootDomain: this._rootDomain });
|
|
3955
|
+
}
|
|
3956
|
+
get action() {
|
|
3957
|
+
return this._actionMap;
|
|
3958
|
+
}
|
|
3959
|
+
actionsMap() {
|
|
3960
|
+
return this._actionMap;
|
|
3961
|
+
}
|
|
3962
|
+
actionForId(id) {
|
|
3963
|
+
const actionSchema = this.actionSchema[id];
|
|
3964
|
+
if (!actionSchema) {
|
|
3965
|
+
throw err_nice_action.fromId("action_id_not_in_domain" /* action_id_not_in_domain */, {
|
|
3966
|
+
domain: this.domain,
|
|
3967
|
+
actionId: id
|
|
3968
|
+
});
|
|
3969
|
+
}
|
|
3970
|
+
return new ActionCore(this, id);
|
|
3971
|
+
}
|
|
3972
|
+
wrapAsLocalHandler(wrappedActionExecutor) {
|
|
3973
|
+
const _handler = new ActionLocalHandler;
|
|
3974
|
+
const executor = wrappedActionExecutor;
|
|
3975
|
+
return _handler.forDomain(this, (request) => executor[request.id](request.input));
|
|
3976
|
+
}
|
|
3977
|
+
hydrateContext(id, contextData) {
|
|
3978
|
+
return new ActionContext(this, id, {
|
|
3979
|
+
timeCreated: contextData.timeCreated,
|
|
3980
|
+
cuid: contextData.cuid,
|
|
3981
|
+
routing: contextData.routing.map((item) => {
|
|
3982
|
+
return {
|
|
3983
|
+
runtime: new ActionClientSpecifier(item.runtime),
|
|
3984
|
+
handler: item.handler,
|
|
3985
|
+
time: item.time
|
|
3986
|
+
};
|
|
3987
|
+
}),
|
|
3988
|
+
originClient: contextData.originClient ? new ActionClientSpecifier(contextData.originClient) : ActionClientSpecifier.unknown
|
|
3989
|
+
});
|
|
3990
|
+
}
|
|
3991
|
+
isDomainAction(action) {
|
|
3992
|
+
return isAction_Any_Instance(action) && action.domain === this.domain;
|
|
3993
|
+
}
|
|
3994
|
+
hydrateRequestPayload(serialized) {
|
|
3995
|
+
if (serialized.type !== "request" /* request */) {
|
|
3996
|
+
throw err_nice_action.fromId("hydration_action_state_mismatch" /* hydration_action_state_mismatch */, {
|
|
3997
|
+
expected: "request" /* request */,
|
|
3998
|
+
received: serialized.type
|
|
3999
|
+
});
|
|
4000
|
+
}
|
|
4001
|
+
if (serialized.domain !== this.domain) {
|
|
4002
|
+
throw err_nice_action.fromId("hydration_domain_mismatch" /* hydration_domain_mismatch */, {
|
|
4003
|
+
expected: this.domain,
|
|
4004
|
+
received: serialized.domain
|
|
4005
|
+
});
|
|
4006
|
+
}
|
|
4007
|
+
const id = serialized.id;
|
|
4008
|
+
if (!this.actionSchema[id]) {
|
|
4009
|
+
throw err_nice_action.fromId("hydration_action_id_not_found" /* hydration_action_id_not_found */, {
|
|
4010
|
+
domain: this.domain,
|
|
4011
|
+
actionId: serialized.id
|
|
4012
|
+
});
|
|
4013
|
+
}
|
|
4014
|
+
const contextAction = this.hydrateContext(id, serialized.context);
|
|
4015
|
+
return new ActionPayload_Request({ context: contextAction }, contextAction.deserializeInput(serialized.input), {
|
|
4016
|
+
time: serialized.time
|
|
4017
|
+
});
|
|
4018
|
+
}
|
|
4019
|
+
hydrateResultPayload(serialized) {
|
|
4020
|
+
if (serialized.type !== "result" /* result */) {
|
|
4021
|
+
throw err_nice_action.fromId("hydration_action_state_mismatch" /* hydration_action_state_mismatch */, {
|
|
4022
|
+
expected: "result" /* result */,
|
|
4023
|
+
received: serialized.type
|
|
4024
|
+
});
|
|
4025
|
+
}
|
|
4026
|
+
if (serialized.domain !== this.domain) {
|
|
4027
|
+
throw err_nice_action.fromId("hydration_domain_mismatch" /* hydration_domain_mismatch */, {
|
|
4028
|
+
expected: this.domain,
|
|
4029
|
+
received: serialized.domain
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
const id = serialized.id;
|
|
4033
|
+
if (!this.actionSchema[id]) {
|
|
4034
|
+
throw err_nice_action.fromId("hydration_action_id_not_found" /* hydration_action_id_not_found */, {
|
|
4035
|
+
domain: this.domain,
|
|
4036
|
+
actionId: serialized.id
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4039
|
+
const contextAction = this.hydrateContext(id, serialized.context);
|
|
4040
|
+
return new ActionPayload_Result({ context: contextAction }, serialized.result, {
|
|
4041
|
+
time: serialized.time
|
|
4042
|
+
});
|
|
4043
|
+
}
|
|
4044
|
+
hydrateAnyAction(actionJson) {
|
|
4045
|
+
assertIsActionJson(actionJson);
|
|
4046
|
+
if (actionJson.form === "data" /* data */) {
|
|
4047
|
+
if (actionJson.type === "request" /* request */) {
|
|
4048
|
+
return this.hydrateRequestPayload(actionJson);
|
|
4049
|
+
}
|
|
4050
|
+
if (actionJson.type === "result" /* result */) {
|
|
4051
|
+
return this.hydrateResultPayload(actionJson);
|
|
4052
|
+
}
|
|
4053
|
+
}
|
|
4054
|
+
return this.actionForId(actionJson.id);
|
|
4055
|
+
}
|
|
4056
|
+
async runAction(request, options) {
|
|
4057
|
+
const allListeners = [
|
|
4058
|
+
...options?.listeners ?? [],
|
|
4059
|
+
...this._listeners
|
|
4060
|
+
];
|
|
4061
|
+
return this._rootDomain._runAction(request, {
|
|
4062
|
+
...options,
|
|
4063
|
+
listeners: allListeners
|
|
4064
|
+
});
|
|
4065
|
+
}
|
|
4066
|
+
createActionMap() {
|
|
4067
|
+
const map = {};
|
|
4068
|
+
for (const id in this.actionSchema) {
|
|
4069
|
+
map[id] = new ActionCore(this, id);
|
|
4070
|
+
}
|
|
4071
|
+
return map;
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
// src/ActionRuntime/ActionRuntimeManager.ts
|
|
4075
|
+
class ActionRuntimeManager {
|
|
4076
|
+
_runtimes = new Map;
|
|
4077
|
+
_preferredRuntimeClientId = null;
|
|
4078
|
+
_context;
|
|
4079
|
+
constructor(context) {
|
|
4080
|
+
this._context = context ?? {};
|
|
4081
|
+
}
|
|
4082
|
+
registerRuntime(runtime2) {
|
|
4083
|
+
const runtimeId = runtime2.clientSpecifier.stringId;
|
|
4084
|
+
if (this._runtimes.has(runtimeId)) {
|
|
4085
|
+
throw err_nice_action.fromId("client_runtime_already_registered" /* client_runtime_already_registered */, {
|
|
4086
|
+
context: this._context,
|
|
4087
|
+
client: runtime2.clientSpecifier
|
|
4088
|
+
});
|
|
4089
|
+
}
|
|
4090
|
+
for (const id of runtime2.clientSpecifier.toStringIds()) {
|
|
4091
|
+
if (this._runtimes.has(id)) {
|
|
4092
|
+
continue;
|
|
4093
|
+
}
|
|
4094
|
+
this._runtimes.set(id, runtime2);
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
getRuntimeAndHandlerForAction(action, options, throwOnIssue) {
|
|
4098
|
+
const localRuntime = options?.targetLocalRuntime;
|
|
4099
|
+
if (localRuntime != null) {
|
|
4100
|
+
const runtime2 = throwOnIssue ? this.getBestRuntimeOrThrow(options?.targetLocalRuntime?.clientSpecifier) : this.getBestRuntime(options?.targetLocalRuntime?.clientSpecifier);
|
|
4101
|
+
if (runtime2 == null) {
|
|
4102
|
+
return;
|
|
4103
|
+
}
|
|
4104
|
+
const handler = runtime2._getHandlerForAction(action, options);
|
|
4105
|
+
if (handler != null) {
|
|
4106
|
+
return { handler, runtime: runtime2 };
|
|
4107
|
+
}
|
|
4108
|
+
if (throwOnIssue) {
|
|
4109
|
+
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
4110
|
+
domain: action.domain,
|
|
4111
|
+
actionId: action.id,
|
|
4112
|
+
specifiedClient: localRuntime.clientSpecifier
|
|
4113
|
+
});
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4116
|
+
for (const runtime2 of this._runtimes.values()) {
|
|
4117
|
+
const handler = runtime2._getHandlerForAction(action);
|
|
4118
|
+
if (handler) {
|
|
4119
|
+
return { handler, runtime: runtime2 };
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
if (throwOnIssue) {
|
|
4123
|
+
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
4124
|
+
domain: action.domain,
|
|
4125
|
+
actionId: action.id,
|
|
4126
|
+
specifiedClient: options?.targetLocalRuntime?.clientSpecifier
|
|
4127
|
+
});
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
getRuntimeAndHandlerForActionOrThrow(action, options) {
|
|
4131
|
+
return this.getRuntimeAndHandlerForAction(action, options, true);
|
|
4132
|
+
}
|
|
4133
|
+
setPreferredRuntime(runtime2) {
|
|
4134
|
+
const runtimeId = runtime2.clientSpecifier.stringId;
|
|
4135
|
+
this._preferredRuntimeClientId = runtimeId;
|
|
4136
|
+
}
|
|
4137
|
+
getPreferredRuntime() {
|
|
4138
|
+
if (this._preferredRuntimeClientId) {
|
|
4139
|
+
const runtime2 = this._runtimes.get(this._preferredRuntimeClientId);
|
|
4140
|
+
if (runtime2) {
|
|
4141
|
+
return runtime2;
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
4144
|
+
return this._runtimes.values().next().value;
|
|
4145
|
+
}
|
|
4146
|
+
getBestRuntimeForSpecifier(clientSpecifier) {
|
|
4147
|
+
const actionClient = new ActionClientSpecifier(clientSpecifier);
|
|
4148
|
+
const ids = actionClient.toStringIds();
|
|
4149
|
+
for (const id of ids) {
|
|
4150
|
+
const runtime2 = this._runtimes.get(id);
|
|
4151
|
+
if (runtime2) {
|
|
4152
|
+
return runtime2;
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
getBestRuntime(clientSpecifier) {
|
|
4157
|
+
return clientSpecifier != null ? this.getBestRuntimeForSpecifier(clientSpecifier) : this.getPreferredRuntime();
|
|
4158
|
+
}
|
|
4159
|
+
getBestRuntimeOrThrow(specifier) {
|
|
4160
|
+
const runtime2 = this.getBestRuntime(specifier);
|
|
4161
|
+
if (!runtime2) {
|
|
4162
|
+
if (specifier == null) {
|
|
4163
|
+
throw err_nice_action.fromId("no_client_runtimes_registered" /* no_client_runtimes_registered */, {
|
|
4164
|
+
context: this._context
|
|
4165
|
+
});
|
|
4166
|
+
}
|
|
4167
|
+
throw err_nice_action.fromId("client_runtime_not_registered" /* client_runtime_not_registered */, {
|
|
4168
|
+
context: this._context,
|
|
4169
|
+
clientStringId: clientSpecifierToStringIds(specifier)[0]
|
|
4170
|
+
});
|
|
4171
|
+
}
|
|
4172
|
+
return runtime2;
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
// src/ActionDefinition/Domain/ActionRootDomain.ts
|
|
4177
|
+
class ActionRootDomain extends ActionDomainBase {
|
|
4178
|
+
domainDefinition;
|
|
4179
|
+
_actionRuntimeManager;
|
|
4180
|
+
constructor(domainDefinition) {
|
|
4181
|
+
const domainId = domainDefinition.domain;
|
|
4182
|
+
super({
|
|
4183
|
+
domain: domainId,
|
|
4184
|
+
allDomains: [domainId],
|
|
4185
|
+
actionSchema: {}
|
|
4186
|
+
});
|
|
4187
|
+
this.domainDefinition = domainDefinition;
|
|
4188
|
+
this._actionRuntimeManager = new ActionRuntimeManager({ domain: domainId });
|
|
4189
|
+
}
|
|
4190
|
+
createChildDomain(subDomainDef) {
|
|
4191
|
+
if (this.allDomains.includes(subDomainDef.domain)) {
|
|
4192
|
+
throw err_nice_action.fromId("domain_already_exists_in_hierarchy" /* domain_already_exists_in_hierarchy */, {
|
|
4193
|
+
domain: subDomainDef.domain,
|
|
4194
|
+
allParentDomains: this.allDomains,
|
|
4195
|
+
parentDomain: this.domain
|
|
4196
|
+
});
|
|
4197
|
+
}
|
|
4198
|
+
return new ActionDomain({
|
|
4199
|
+
allDomains: [...this.allDomains, subDomainDef.domain],
|
|
4200
|
+
domain: subDomainDef.domain,
|
|
4201
|
+
actionSchema: subDomainDef.actions
|
|
4202
|
+
}, { rootDomain: this });
|
|
4203
|
+
}
|
|
4204
|
+
addActionRuntime(runtime2) {
|
|
4205
|
+
this._actionRuntimeManager.registerRuntime(runtime2);
|
|
4206
|
+
return this;
|
|
4207
|
+
}
|
|
4208
|
+
getRuntime(clientSpecifier) {
|
|
4209
|
+
return this._actionRuntimeManager.getBestRuntimeForSpecifier(clientSpecifier);
|
|
4210
|
+
}
|
|
4211
|
+
async _runAction(actionPayload, options) {
|
|
4212
|
+
const { handler, runtime: runtime2 } = this._actionRuntimeManager.getRuntimeAndHandlerForActionOrThrow(actionPayload, options);
|
|
4213
|
+
actionPayload.context._setOriginClient(runtime2.clientSpecifier);
|
|
4214
|
+
const allListeners = [...this._listeners, ...options?.listeners ?? []];
|
|
4215
|
+
const runningAction = await handler.handleActionRequest(actionPayload, {
|
|
4216
|
+
targetLocalRuntime: runtime2
|
|
4217
|
+
});
|
|
4218
|
+
runningAction.addUpdateListeners(allListeners);
|
|
4219
|
+
return runningAction;
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
// src/ActionDefinition/Domain/helpers/createRootActionDomain.ts
|
|
4223
|
+
var createActionRootDomain = (definition) => {
|
|
4224
|
+
return new ActionRootDomain(definition);
|
|
4225
|
+
};
|
|
4226
|
+
// ../../node_modules/.bun/@nice-code+common-errors@0.1.3+51eba3db27e14993/node_modules/@nice-code/common-errors/build/index.js
|
|
3689
4227
|
var ACCEPTED2 = 202;
|
|
3690
4228
|
var BAD_GATEWAY2 = 502;
|
|
3691
4229
|
var BAD_REQUEST2 = 400;
|
|
@@ -3991,14 +4529,14 @@ var StatusCodes2;
|
|
|
3991
4529
|
StatusCodes22[StatusCodes22["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
3992
4530
|
})(StatusCodes2 || (StatusCodes2 = {}));
|
|
3993
4531
|
var __assign2 = function() {
|
|
3994
|
-
__assign2 = Object.assign || function(
|
|
3995
|
-
for (var
|
|
3996
|
-
|
|
3997
|
-
for (var
|
|
3998
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
3999
|
-
|
|
4000
|
-
}
|
|
4001
|
-
return
|
|
4532
|
+
__assign2 = Object.assign || function(t2) {
|
|
4533
|
+
for (var s2, i2 = 1, n2 = arguments.length;i2 < n2; i2++) {
|
|
4534
|
+
s2 = arguments[i2];
|
|
4535
|
+
for (var p2 in s2)
|
|
4536
|
+
if (Object.prototype.hasOwnProperty.call(s2, p2))
|
|
4537
|
+
t2[p2] = s2[p2];
|
|
4538
|
+
}
|
|
4539
|
+
return t2;
|
|
4002
4540
|
};
|
|
4003
4541
|
return __assign2.apply(this, arguments);
|
|
4004
4542
|
};
|
|
@@ -4107,7 +4645,7 @@ class NiceError2 extends Error {
|
|
|
4107
4645
|
const otherIds = other.getIds().map(String).sort();
|
|
4108
4646
|
if (myIds.length !== otherIds.length)
|
|
4109
4647
|
return false;
|
|
4110
|
-
return myIds.every((id,
|
|
4648
|
+
return myIds.every((id, i2) => id === otherIds[i2]);
|
|
4111
4649
|
}
|
|
4112
4650
|
toJsonObject() {
|
|
4113
4651
|
const originError = this.originError ? {
|
|
@@ -4632,8 +5170,8 @@ function formatTemplate2(settings, template, values, hideUnsetPlaceholder = fals
|
|
|
4632
5170
|
}
|
|
4633
5171
|
};
|
|
4634
5172
|
const defaultStyle = null;
|
|
4635
|
-
return templateString.replace(/{{(.+?)}}/g, (
|
|
4636
|
-
const value = values[placeholder] != null ? String(values[placeholder]) : hideUnsetPlaceholder ? "" :
|
|
5173
|
+
return templateString.replace(/{{(.+?)}}/g, (_2, placeholder) => {
|
|
5174
|
+
const value = values[placeholder] != null ? String(values[placeholder]) : hideUnsetPlaceholder ? "" : _2;
|
|
4637
5175
|
return settings.stylePrettyLogs ? styleWrap(value, settings?.prettyLogStyles?.[placeholder] ?? defaultStyle) + ansiColorWrap("", prettyLogStyles2.reset) : value;
|
|
4638
5176
|
});
|
|
4639
5177
|
}
|
|
@@ -4870,14 +5408,14 @@ function isRegExp2(re) {
|
|
|
4870
5408
|
function isObject2(arg) {
|
|
4871
5409
|
return typeof arg === "object" && arg !== null;
|
|
4872
5410
|
}
|
|
4873
|
-
function isError2(
|
|
4874
|
-
return isObject2(
|
|
5411
|
+
function isError2(e2) {
|
|
5412
|
+
return isObject2(e2) && (objectToString2(e2) === "[object Error]" || e2 instanceof Error);
|
|
4875
5413
|
}
|
|
4876
|
-
function isDate2(
|
|
4877
|
-
return isObject2(
|
|
5414
|
+
function isDate2(d2) {
|
|
5415
|
+
return isObject2(d2) && objectToString2(d2) === "[object Date]";
|
|
4878
5416
|
}
|
|
4879
|
-
function objectToString2(
|
|
4880
|
-
return Object.prototype.toString.call(
|
|
5417
|
+
function objectToString2(o2) {
|
|
5418
|
+
return Object.prototype.toString.call(o2);
|
|
4881
5419
|
}
|
|
4882
5420
|
function arrayToHash2(array) {
|
|
4883
5421
|
const hash = {};
|
|
@@ -4888,9 +5426,9 @@ function arrayToHash2(array) {
|
|
|
4888
5426
|
}
|
|
4889
5427
|
function formatArray2(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
4890
5428
|
const output = [];
|
|
4891
|
-
for (let
|
|
4892
|
-
if (hasOwn2(value, String(
|
|
4893
|
-
output.push(formatProperty2(ctx, value, recurseTimes, visibleKeys, String(
|
|
5429
|
+
for (let i2 = 0, l2 = value.length;i2 < l2; ++i2) {
|
|
5430
|
+
if (hasOwn2(value, String(i2))) {
|
|
5431
|
+
output.push(formatProperty2(ctx, value, recurseTimes, visibleKeys, String(i2), true));
|
|
4894
5432
|
} else {
|
|
4895
5433
|
output.push("");
|
|
4896
5434
|
}
|
|
@@ -4961,8 +5499,8 @@ function formatValue2(ctx, value, recurseTimes = 0) {
|
|
|
4961
5499
|
]`];
|
|
4962
5500
|
}
|
|
4963
5501
|
if (isFunction2(value)) {
|
|
4964
|
-
const
|
|
4965
|
-
base = " [Function" +
|
|
5502
|
+
const n2 = value.name ? ": " + value.name : "";
|
|
5503
|
+
base = " [Function" + n2 + "]";
|
|
4966
5504
|
}
|
|
4967
5505
|
if (isRegExp2(value)) {
|
|
4968
5506
|
base = " " + RegExp.prototype.toString.call(value);
|
|
@@ -5088,9 +5626,9 @@ function _extend2(origin, add) {
|
|
|
5088
5626
|
return origin;
|
|
5089
5627
|
const clonedAdd = { ...add };
|
|
5090
5628
|
const keys = Object.keys(add);
|
|
5091
|
-
let
|
|
5092
|
-
while (
|
|
5093
|
-
typedOrigin[keys[
|
|
5629
|
+
let i2 = keys.length;
|
|
5630
|
+
while (i2--) {
|
|
5631
|
+
typedOrigin[keys[i2]] = clonedAdd[keys[i2]];
|
|
5094
5632
|
}
|
|
5095
5633
|
return typedOrigin;
|
|
5096
5634
|
}
|
|
@@ -5103,7 +5641,7 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5103
5641
|
_extend2(ctx, inspectOptions);
|
|
5104
5642
|
}
|
|
5105
5643
|
const first = args[0];
|
|
5106
|
-
let
|
|
5644
|
+
let a2 = 0;
|
|
5107
5645
|
let str = "";
|
|
5108
5646
|
let join = "";
|
|
5109
5647
|
if (typeof first === "string") {
|
|
@@ -5112,13 +5650,13 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5112
5650
|
}
|
|
5113
5651
|
let tempStr;
|
|
5114
5652
|
let lastPos = 0;
|
|
5115
|
-
for (let
|
|
5116
|
-
if (first.charCodeAt(
|
|
5117
|
-
const nextChar = first.charCodeAt(++
|
|
5118
|
-
if (
|
|
5653
|
+
for (let i2 = 0;i2 < first.length - 1; i2++) {
|
|
5654
|
+
if (first.charCodeAt(i2) === 37) {
|
|
5655
|
+
const nextChar = first.charCodeAt(++i2);
|
|
5656
|
+
if (a2 + 1 !== args.length) {
|
|
5119
5657
|
switch (nextChar) {
|
|
5120
5658
|
case 115: {
|
|
5121
|
-
const tempArg = args[++
|
|
5659
|
+
const tempArg = args[++a2];
|
|
5122
5660
|
if (typeof tempArg === "number") {
|
|
5123
5661
|
tempStr = formatPrimitive2(ctx, tempArg);
|
|
5124
5662
|
} else if (typeof tempArg === "bigint") {
|
|
@@ -5136,10 +5674,10 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5136
5674
|
break;
|
|
5137
5675
|
}
|
|
5138
5676
|
case 106:
|
|
5139
|
-
tempStr = jsonStringifyRecursive2(args[++
|
|
5677
|
+
tempStr = jsonStringifyRecursive2(args[++a2]);
|
|
5140
5678
|
break;
|
|
5141
5679
|
case 100: {
|
|
5142
|
-
const tempNum = args[++
|
|
5680
|
+
const tempNum = args[++a2];
|
|
5143
5681
|
if (typeof tempNum === "bigint") {
|
|
5144
5682
|
tempStr = formatPrimitive2(ctx, tempNum);
|
|
5145
5683
|
} else if (typeof tempNum === "symbol") {
|
|
@@ -5150,10 +5688,10 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5150
5688
|
break;
|
|
5151
5689
|
}
|
|
5152
5690
|
case 79:
|
|
5153
|
-
tempStr = inspect2(args[++
|
|
5691
|
+
tempStr = inspect2(args[++a2], inspectOptions);
|
|
5154
5692
|
break;
|
|
5155
5693
|
case 111:
|
|
5156
|
-
tempStr = inspect2(args[++
|
|
5694
|
+
tempStr = inspect2(args[++a2], {
|
|
5157
5695
|
...inspectOptions,
|
|
5158
5696
|
showHidden: true,
|
|
5159
5697
|
showProxy: true,
|
|
@@ -5161,7 +5699,7 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5161
5699
|
});
|
|
5162
5700
|
break;
|
|
5163
5701
|
case 105: {
|
|
5164
|
-
const tempInteger = args[++
|
|
5702
|
+
const tempInteger = args[++a2];
|
|
5165
5703
|
if (typeof tempInteger === "bigint") {
|
|
5166
5704
|
tempStr = formatPrimitive2(ctx, tempInteger);
|
|
5167
5705
|
} else if (typeof tempInteger === "symbol") {
|
|
@@ -5172,7 +5710,7 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5172
5710
|
break;
|
|
5173
5711
|
}
|
|
5174
5712
|
case 102: {
|
|
5175
|
-
const tempFloat = args[++
|
|
5713
|
+
const tempFloat = args[++a2];
|
|
5176
5714
|
if (typeof tempFloat === "symbol") {
|
|
5177
5715
|
tempStr = "NaN";
|
|
5178
5716
|
} else {
|
|
@@ -5181,41 +5719,41 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5181
5719
|
break;
|
|
5182
5720
|
}
|
|
5183
5721
|
case 99:
|
|
5184
|
-
|
|
5722
|
+
a2 += 1;
|
|
5185
5723
|
tempStr = "";
|
|
5186
5724
|
break;
|
|
5187
5725
|
case 37:
|
|
5188
|
-
str += first.slice(lastPos,
|
|
5189
|
-
lastPos =
|
|
5726
|
+
str += first.slice(lastPos, i2);
|
|
5727
|
+
lastPos = i2 + 1;
|
|
5190
5728
|
continue;
|
|
5191
5729
|
default:
|
|
5192
5730
|
continue;
|
|
5193
5731
|
}
|
|
5194
|
-
if (lastPos !==
|
|
5195
|
-
str += first.slice(lastPos,
|
|
5732
|
+
if (lastPos !== i2 - 1) {
|
|
5733
|
+
str += first.slice(lastPos, i2 - 1);
|
|
5196
5734
|
}
|
|
5197
5735
|
str += tempStr;
|
|
5198
|
-
lastPos =
|
|
5736
|
+
lastPos = i2 + 1;
|
|
5199
5737
|
} else if (nextChar === 37) {
|
|
5200
|
-
str += first.slice(lastPos,
|
|
5201
|
-
lastPos =
|
|
5738
|
+
str += first.slice(lastPos, i2);
|
|
5739
|
+
lastPos = i2 + 1;
|
|
5202
5740
|
}
|
|
5203
5741
|
}
|
|
5204
5742
|
}
|
|
5205
5743
|
if (lastPos !== 0) {
|
|
5206
|
-
|
|
5744
|
+
a2++;
|
|
5207
5745
|
join = " ";
|
|
5208
5746
|
if (lastPos < first.length) {
|
|
5209
5747
|
str += first.slice(lastPos);
|
|
5210
5748
|
}
|
|
5211
5749
|
}
|
|
5212
5750
|
}
|
|
5213
|
-
while (
|
|
5214
|
-
const value = args[
|
|
5751
|
+
while (a2 < args.length) {
|
|
5752
|
+
const value = args[a2];
|
|
5215
5753
|
str += join;
|
|
5216
5754
|
str += typeof value !== "string" ? inspect2(value, inspectOptions) : value;
|
|
5217
5755
|
join = " ";
|
|
5218
|
-
|
|
5756
|
+
a2++;
|
|
5219
5757
|
}
|
|
5220
5758
|
return str;
|
|
5221
5759
|
}
|
|
@@ -5979,767 +6517,327 @@ error stack:
|
|
|
5979
6517
|
return urlToObject2(source);
|
|
5980
6518
|
} else if (source !== null && typeof source === "object") {
|
|
5981
6519
|
const baseObject = runtime2.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
|
|
5982
|
-
return Object.getOwnPropertyNames(source).reduce((
|
|
6520
|
+
return Object.getOwnPropertyNames(source).reduce((o2, prop) => {
|
|
5983
6521
|
const lookupKey = this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : typeof prop === "string" ? prop.toLowerCase() : String(prop).toLowerCase();
|
|
5984
|
-
|
|
6522
|
+
o2[prop] = keys.includes(lookupKey) ? this.settings.maskPlaceholder : (() => {
|
|
5985
6523
|
try {
|
|
5986
6524
|
return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
|
|
5987
6525
|
} catch {
|
|
5988
6526
|
return null;
|
|
5989
6527
|
}
|
|
5990
6528
|
})();
|
|
5991
|
-
return
|
|
6529
|
+
return o2;
|
|
5992
6530
|
}, baseObject);
|
|
5993
6531
|
} else {
|
|
5994
|
-
if (typeof source === "string") {
|
|
5995
|
-
let modifiedSource = source;
|
|
5996
|
-
for (const regEx of this.settings?.maskValuesRegEx || []) {
|
|
5997
|
-
modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
|
|
5998
|
-
}
|
|
5999
|
-
return modifiedSource;
|
|
6000
|
-
}
|
|
6001
|
-
return source;
|
|
6002
|
-
}
|
|
6003
|
-
}
|
|
6004
|
-
_recursiveCloneAndExecuteFunctions(source, seen = []) {
|
|
6005
|
-
if (this.isObjectOrArray(source) && seen.includes(source)) {
|
|
6006
|
-
return this.shallowCopy(source);
|
|
6007
|
-
}
|
|
6008
|
-
if (this.isObjectOrArray(source)) {
|
|
6009
|
-
seen.push(source);
|
|
6010
|
-
}
|
|
6011
|
-
if (Array.isArray(source)) {
|
|
6012
|
-
return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
|
|
6013
|
-
} else if (source instanceof Date) {
|
|
6014
|
-
return new Date(source.getTime());
|
|
6015
|
-
} else if (this.isObject(source)) {
|
|
6016
|
-
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
6017
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, prop);
|
|
6018
|
-
if (descriptor) {
|
|
6019
|
-
Object.defineProperty(o, prop, descriptor);
|
|
6020
|
-
const value = source[prop];
|
|
6021
|
-
o[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
|
|
6022
|
-
}
|
|
6023
|
-
return o;
|
|
6024
|
-
}, Object.create(Object.getPrototypeOf(source)));
|
|
6025
|
-
} else {
|
|
6026
|
-
return source;
|
|
6027
|
-
}
|
|
6028
|
-
}
|
|
6029
|
-
isObjectOrArray(value) {
|
|
6030
|
-
return typeof value === "object" && value !== null;
|
|
6031
|
-
}
|
|
6032
|
-
isObject(value) {
|
|
6033
|
-
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
|
6034
|
-
}
|
|
6035
|
-
shallowCopy(source) {
|
|
6036
|
-
if (Array.isArray(source)) {
|
|
6037
|
-
return [...source];
|
|
6038
|
-
} else {
|
|
6039
|
-
return { ...source };
|
|
6040
|
-
}
|
|
6041
|
-
}
|
|
6042
|
-
_toLogObj(args, clonedLogObj = {}) {
|
|
6043
|
-
args = args?.map((arg) => runtime2.isError(arg) ? this._toErrorObject(arg) : arg);
|
|
6044
|
-
if (this.settings.argumentsArrayName == null) {
|
|
6045
|
-
if (args.length === 1 && !Array.isArray(args[0]) && runtime2.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
|
|
6046
|
-
clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
|
|
6047
|
-
} else {
|
|
6048
|
-
clonedLogObj = { ...clonedLogObj, ...args };
|
|
6049
|
-
}
|
|
6050
|
-
} else {
|
|
6051
|
-
clonedLogObj = {
|
|
6052
|
-
...clonedLogObj,
|
|
6053
|
-
[this.settings.argumentsArrayName]: args
|
|
6054
|
-
};
|
|
6055
|
-
}
|
|
6056
|
-
return clonedLogObj;
|
|
6057
|
-
}
|
|
6058
|
-
_cloneError(error) {
|
|
6059
|
-
const cloned = new error.constructor;
|
|
6060
|
-
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
6061
|
-
cloned[key] = error[key];
|
|
6062
|
-
});
|
|
6063
|
-
return cloned;
|
|
6064
|
-
}
|
|
6065
|
-
_toErrorObject(error, depth = 0, seen = new Set) {
|
|
6066
|
-
if (!seen.has(error)) {
|
|
6067
|
-
seen.add(error);
|
|
6068
|
-
}
|
|
6069
|
-
const errorObject = {
|
|
6070
|
-
nativeError: error,
|
|
6071
|
-
name: error.name ?? "Error",
|
|
6072
|
-
message: error.message,
|
|
6073
|
-
stack: runtime2.getErrorTrace(error)
|
|
6074
|
-
};
|
|
6075
|
-
if (depth >= this.maxErrorCauseDepth) {
|
|
6076
|
-
return errorObject;
|
|
6077
|
-
}
|
|
6078
|
-
const causeValue = error.cause;
|
|
6079
|
-
if (causeValue != null) {
|
|
6080
|
-
const normalizedCause = toError2(causeValue);
|
|
6081
|
-
if (!seen.has(normalizedCause)) {
|
|
6082
|
-
errorObject.cause = this._toErrorObject(normalizedCause, depth + 1, seen);
|
|
6083
|
-
}
|
|
6084
|
-
}
|
|
6085
|
-
return errorObject;
|
|
6086
|
-
}
|
|
6087
|
-
_addMetaToLogObj(logObj, logLevelId, logLevelName) {
|
|
6088
|
-
return {
|
|
6089
|
-
...logObj,
|
|
6090
|
-
[this.settings.metaProperty]: runtime2.getMeta(logLevelId, logLevelName, this.stackDepthLevel, !this.captureStackForMeta, this.settings.name, this.settings.parentNames)
|
|
6091
|
-
};
|
|
6092
|
-
}
|
|
6093
|
-
_shouldCaptureStack() {
|
|
6094
|
-
if (this.settings.hideLogPositionForProduction) {
|
|
6095
|
-
return false;
|
|
6096
|
-
}
|
|
6097
|
-
if (this.settings.type === "json") {
|
|
6098
|
-
return true;
|
|
6099
|
-
}
|
|
6100
|
-
const template = this.settings.prettyLogTemplate ?? "";
|
|
6101
|
-
const stackPlaceholders = /{{\s*(file(Name|Path|Line|PathWithLine|NameWithLine)|fullFilePath)\s*}}/;
|
|
6102
|
-
if (stackPlaceholders.test(template)) {
|
|
6103
|
-
return true;
|
|
6104
|
-
}
|
|
6105
|
-
return false;
|
|
6106
|
-
}
|
|
6107
|
-
_prettyFormatLogObjMeta(logObjMeta) {
|
|
6108
|
-
return buildPrettyMeta2(this.settings, logObjMeta).text;
|
|
6109
|
-
}
|
|
6110
|
-
}
|
|
6111
|
-
|
|
6112
|
-
class Logger2 extends BaseLogger2 {
|
|
6113
|
-
constructor(settings, logObj) {
|
|
6114
|
-
const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
6115
|
-
const normalizedSettings = { ...settings ?? {} };
|
|
6116
|
-
if (isBrowser) {
|
|
6117
|
-
normalizedSettings.stylePrettyLogs = settings?.stylePrettyLogs ?? true;
|
|
6118
|
-
}
|
|
6119
|
-
super(normalizedSettings, logObj, Number.NaN);
|
|
6120
|
-
}
|
|
6121
|
-
log(logLevelId, logLevelName, ...args) {
|
|
6122
|
-
return super.log(logLevelId, logLevelName, ...args);
|
|
6123
|
-
}
|
|
6124
|
-
silly(...args) {
|
|
6125
|
-
return super.log(0, "SILLY", ...args);
|
|
6126
|
-
}
|
|
6127
|
-
trace(...args) {
|
|
6128
|
-
return super.log(1, "TRACE", ...args);
|
|
6129
|
-
}
|
|
6130
|
-
debug(...args) {
|
|
6131
|
-
return super.log(2, "DEBUG", ...args);
|
|
6132
|
-
}
|
|
6133
|
-
info(...args) {
|
|
6134
|
-
return super.log(3, "INFO", ...args);
|
|
6135
|
-
}
|
|
6136
|
-
warn(...args) {
|
|
6137
|
-
return super.log(4, "WARN", ...args);
|
|
6138
|
-
}
|
|
6139
|
-
error(...args) {
|
|
6140
|
-
return super.log(5, "ERROR", ...args);
|
|
6141
|
-
}
|
|
6142
|
-
fatal(...args) {
|
|
6143
|
-
return super.log(6, "FATAL", ...args);
|
|
6144
|
-
}
|
|
6145
|
-
getSubLogger(settings, logObj) {
|
|
6146
|
-
return super.getSubLogger(settings, logObj);
|
|
6147
|
-
}
|
|
6148
|
-
}
|
|
6149
|
-
var logger_NiceError2 = new Logger2({
|
|
6150
|
-
name: "NiceErrorLogger"
|
|
6151
|
-
});
|
|
6152
|
-
var logger_NiceError_testing2 = logger_NiceError2.getSubLogger({
|
|
6153
|
-
name: "NiceErrorTestingLogger"
|
|
6154
|
-
});
|
|
6155
|
-
function extractPathFromIssue(issue) {
|
|
6156
|
-
let pathString = "";
|
|
6157
|
-
for (const segment of issue) {
|
|
6158
|
-
if (typeof segment === "object") {
|
|
6159
|
-
if (segment.key != null) {
|
|
6160
|
-
if (typeof segment.key === "number") {
|
|
6161
|
-
pathString += `[${String(segment.key)}]`;
|
|
6162
|
-
} else if (typeof segment.key === "symbol") {
|
|
6163
|
-
pathString += `[SYMBOL:${String(segment.key)}]`;
|
|
6164
|
-
} else {
|
|
6165
|
-
pathString += `.${String(segment.key)}`;
|
|
6166
|
-
}
|
|
6167
|
-
}
|
|
6168
|
-
} else {
|
|
6169
|
-
pathString += `.${String(segment)}`;
|
|
6170
|
-
}
|
|
6171
|
-
}
|
|
6172
|
-
return pathString.slice(1);
|
|
6173
|
-
}
|
|
6174
|
-
var extractMessageFromStandardSchema = (failureResult) => {
|
|
6175
|
-
let message = `Data validation failed:
|
|
6176
|
-
`;
|
|
6177
|
-
let issueCount = 0;
|
|
6178
|
-
for (const issue of failureResult.issues) {
|
|
6179
|
-
issueCount++;
|
|
6180
|
-
if (issue.path == null || issue.path.length === 0) {
|
|
6181
|
-
message += ` (issue ${issueCount}) ${issue.message}
|
|
6182
|
-
`;
|
|
6183
|
-
} else {
|
|
6184
|
-
message += ` (issue ${issueCount}) [${extractPathFromIssue(issue.path)}]: ${issue.message}
|
|
6185
|
-
`;
|
|
6186
|
-
}
|
|
6187
|
-
}
|
|
6188
|
-
return message;
|
|
6189
|
-
};
|
|
6190
|
-
var EValidator;
|
|
6191
|
-
((EValidator2) => {
|
|
6192
|
-
EValidator2["standard_schema"] = "standard_schema";
|
|
6193
|
-
})(EValidator ||= {});
|
|
6194
|
-
var err_validation = err_nice2.createChildDomain({
|
|
6195
|
-
domain: "err_validation",
|
|
6196
|
-
defaultHttpStatusCode: StatusCodes2.BAD_REQUEST,
|
|
6197
|
-
schema: {
|
|
6198
|
-
["standard_schema"]: err2({
|
|
6199
|
-
message: ({ issues }) => extractMessageFromStandardSchema({ issues })
|
|
6200
|
-
})
|
|
6201
|
-
}
|
|
6202
|
-
});
|
|
6203
|
-
|
|
6204
|
-
// src/ActionDefinition/Schema/ActionSchema.ts
|
|
6205
|
-
class ActionSchema {
|
|
6206
|
-
_errorDeclarations = [];
|
|
6207
|
-
inputOptions;
|
|
6208
|
-
outputOptions;
|
|
6209
|
-
get inputSchema() {
|
|
6210
|
-
return this.inputOptions?.schema;
|
|
6211
|
-
}
|
|
6212
|
-
get outputSchema() {
|
|
6213
|
-
return this.outputOptions?.schema;
|
|
6214
|
-
}
|
|
6215
|
-
input(options, serialize, deserialize) {
|
|
6216
|
-
if (serialize != null && deserialize != null) {
|
|
6217
|
-
this.inputOptions = { ...options, serialization: { serialize, deserialize } };
|
|
6218
|
-
} else {
|
|
6219
|
-
this.inputOptions = options;
|
|
6532
|
+
if (typeof source === "string") {
|
|
6533
|
+
let modifiedSource = source;
|
|
6534
|
+
for (const regEx of this.settings?.maskValuesRegEx || []) {
|
|
6535
|
+
modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
|
|
6536
|
+
}
|
|
6537
|
+
return modifiedSource;
|
|
6538
|
+
}
|
|
6539
|
+
return source;
|
|
6220
6540
|
}
|
|
6221
|
-
return this;
|
|
6222
6541
|
}
|
|
6223
|
-
|
|
6224
|
-
if (
|
|
6225
|
-
this.
|
|
6226
|
-
} else {
|
|
6227
|
-
this.outputOptions = options;
|
|
6542
|
+
_recursiveCloneAndExecuteFunctions(source, seen = []) {
|
|
6543
|
+
if (this.isObjectOrArray(source) && seen.includes(source)) {
|
|
6544
|
+
return this.shallowCopy(source);
|
|
6228
6545
|
}
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
throws(domain, ids) {
|
|
6232
|
-
this._errorDeclarations.push({ _domain: domain, _ids: ids });
|
|
6233
|
-
return this;
|
|
6234
|
-
}
|
|
6235
|
-
serializeInput(rawInput) {
|
|
6236
|
-
if (this.inputOptions?.serialization) {
|
|
6237
|
-
return this.inputOptions.serialization.serialize(rawInput);
|
|
6546
|
+
if (this.isObjectOrArray(source)) {
|
|
6547
|
+
seen.push(source);
|
|
6238
6548
|
}
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6549
|
+
if (Array.isArray(source)) {
|
|
6550
|
+
return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
|
|
6551
|
+
} else if (source instanceof Date) {
|
|
6552
|
+
return new Date(source.getTime());
|
|
6553
|
+
} else if (this.isObject(source)) {
|
|
6554
|
+
return Object.getOwnPropertyNames(source).reduce((o2, prop) => {
|
|
6555
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, prop);
|
|
6556
|
+
if (descriptor) {
|
|
6557
|
+
Object.defineProperty(o2, prop, descriptor);
|
|
6558
|
+
const value = source[prop];
|
|
6559
|
+
o2[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
|
|
6560
|
+
}
|
|
6561
|
+
return o2;
|
|
6562
|
+
}, Object.create(Object.getPrototypeOf(source)));
|
|
6563
|
+
} else {
|
|
6564
|
+
return source;
|
|
6244
6565
|
}
|
|
6245
|
-
return serialized;
|
|
6246
6566
|
}
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
return value;
|
|
6250
|
-
}
|
|
6251
|
-
const result = this.inputOptions.schema["~standard"].validate(value);
|
|
6252
|
-
if (result instanceof Promise) {
|
|
6253
|
-
throw err_nice_action.fromId("action_input_validation_promise" /* action_input_validation_promise */, {
|
|
6254
|
-
domain: meta.domain,
|
|
6255
|
-
actionId: meta.actionId
|
|
6256
|
-
});
|
|
6257
|
-
}
|
|
6258
|
-
if (result.issues != null) {
|
|
6259
|
-
throw err_nice_action.fromId("action_input_validation_failed" /* action_input_validation_failed */, {
|
|
6260
|
-
domain: meta.domain,
|
|
6261
|
-
actionId: meta.actionId,
|
|
6262
|
-
validationMessage: extractMessageFromStandardSchema(result)
|
|
6263
|
-
});
|
|
6264
|
-
}
|
|
6265
|
-
return result.value;
|
|
6567
|
+
isObjectOrArray(value) {
|
|
6568
|
+
return typeof value === "object" && value !== null;
|
|
6266
6569
|
}
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
return value;
|
|
6270
|
-
}
|
|
6271
|
-
const result = this.outputOptions.schema["~standard"].validate(value);
|
|
6272
|
-
if (result instanceof Promise) {
|
|
6273
|
-
throw err_nice_action.fromId("action_output_validation_promise" /* action_output_validation_promise */, {
|
|
6274
|
-
domain: meta.domain,
|
|
6275
|
-
actionId: meta.actionId
|
|
6276
|
-
});
|
|
6277
|
-
}
|
|
6278
|
-
if (result.issues != null) {
|
|
6279
|
-
throw err_nice_action.fromId("action_output_validation_failed" /* action_output_validation_failed */, {
|
|
6280
|
-
domain: meta.domain,
|
|
6281
|
-
actionId: meta.actionId,
|
|
6282
|
-
validationMessage: extractMessageFromStandardSchema(result)
|
|
6283
|
-
});
|
|
6284
|
-
}
|
|
6285
|
-
return result.value;
|
|
6570
|
+
isObject(value) {
|
|
6571
|
+
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
|
6286
6572
|
}
|
|
6287
|
-
|
|
6288
|
-
if (
|
|
6289
|
-
return
|
|
6573
|
+
shallowCopy(source) {
|
|
6574
|
+
if (Array.isArray(source)) {
|
|
6575
|
+
return [...source];
|
|
6576
|
+
} else {
|
|
6577
|
+
return { ...source };
|
|
6290
6578
|
}
|
|
6291
|
-
return rawOutput;
|
|
6292
6579
|
}
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6580
|
+
_toLogObj(args, clonedLogObj = {}) {
|
|
6581
|
+
args = args?.map((arg) => runtime2.isError(arg) ? this._toErrorObject(arg) : arg);
|
|
6582
|
+
if (this.settings.argumentsArrayName == null) {
|
|
6583
|
+
if (args.length === 1 && !Array.isArray(args[0]) && runtime2.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
|
|
6584
|
+
clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
|
|
6585
|
+
} else {
|
|
6586
|
+
clonedLogObj = { ...clonedLogObj, ...args };
|
|
6587
|
+
}
|
|
6588
|
+
} else {
|
|
6589
|
+
clonedLogObj = {
|
|
6590
|
+
...clonedLogObj,
|
|
6591
|
+
[this.settings.argumentsArrayName]: args
|
|
6592
|
+
};
|
|
6296
6593
|
}
|
|
6297
|
-
return
|
|
6298
|
-
}
|
|
6299
|
-
}
|
|
6300
|
-
var actionSchema = () => {
|
|
6301
|
-
return new ActionSchema;
|
|
6302
|
-
};
|
|
6303
|
-
// ../../node_modules/.bun/std-env@4.1.0/node_modules/std-env/dist/index.mjs
|
|
6304
|
-
var e = globalThis.process?.env || Object.create(null);
|
|
6305
|
-
var t = globalThis.process || { env: e };
|
|
6306
|
-
var n = t !== undefined && t.env && t.env.NODE_ENV || undefined;
|
|
6307
|
-
var r = [[`claude`, [`CLAUDECODE`, `CLAUDE_CODE`]], [`replit`, [`REPL_ID`]], [`gemini`, [`GEMINI_CLI`]], [`codex`, [`CODEX_SANDBOX`, `CODEX_THREAD_ID`]], [`opencode`, [`OPENCODE`]], [`pi`, [i(`PATH`, /\.pi[\\/]agent/)]], [`auggie`, [`AUGMENT_AGENT`]], [`goose`, [`GOOSE_PROVIDER`]], [`devin`, [i(`EDITOR`, /devin/)]], [`cursor`, [`CURSOR_AGENT`]], [`kiro`, [i(`TERM_PROGRAM`, /kiro/)]]];
|
|
6308
|
-
function i(t2, n2) {
|
|
6309
|
-
return () => {
|
|
6310
|
-
let r2 = e[t2];
|
|
6311
|
-
return r2 ? n2.test(r2) : false;
|
|
6312
|
-
};
|
|
6313
|
-
}
|
|
6314
|
-
function a() {
|
|
6315
|
-
let t2 = e.AI_AGENT;
|
|
6316
|
-
if (t2)
|
|
6317
|
-
return { name: t2.toLowerCase() };
|
|
6318
|
-
for (let [t3, n2] of r)
|
|
6319
|
-
for (let r2 of n2)
|
|
6320
|
-
if (typeof r2 == `string` ? e[r2] : r2())
|
|
6321
|
-
return { name: t3 };
|
|
6322
|
-
return {};
|
|
6323
|
-
}
|
|
6324
|
-
var o = a();
|
|
6325
|
-
var s = o.name;
|
|
6326
|
-
var c = !!o.name;
|
|
6327
|
-
var l = [[`APPVEYOR`], [`AWS_AMPLIFY`, `AWS_APP_ID`, { ci: true }], [`AZURE_PIPELINES`, `SYSTEM_TEAMFOUNDATIONCOLLECTIONURI`], [`AZURE_STATIC`, `INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN`], [`APPCIRCLE`, `AC_APPCIRCLE`], [`BAMBOO`, `bamboo_planKey`], [`BITBUCKET`, `BITBUCKET_COMMIT`], [`BITRISE`, `BITRISE_IO`], [`BUDDY`, `BUDDY_WORKSPACE_ID`], [`BUILDKITE`], [`CIRCLE`, `CIRCLECI`], [`CIRRUS`, `CIRRUS_CI`], [`CLOUDFLARE_PAGES`, `CF_PAGES`, { ci: true }], [`CLOUDFLARE_WORKERS`, `WORKERS_CI`, { ci: true }], [`GOOGLE_CLOUDRUN`, `K_SERVICE`], [`GOOGLE_CLOUDRUN_JOB`, `CLOUD_RUN_JOB`], [`CODEBUILD`, `CODEBUILD_BUILD_ARN`], [`CODEFRESH`, `CF_BUILD_ID`], [`DRONE`], [`DRONE`, `DRONE_BUILD_EVENT`], [`DSARI`], [`GITHUB_ACTIONS`], [`GITLAB`, `GITLAB_CI`], [`GITLAB`, `CI_MERGE_REQUEST_ID`], [`GOCD`, `GO_PIPELINE_LABEL`], [`LAYERCI`], [`JENKINS`, `JENKINS_URL`], [`HUDSON`, `HUDSON_URL`], [`MAGNUM`], [`NETLIFY`], [`NETLIFY`, `NETLIFY_LOCAL`, { ci: false }], [`NEVERCODE`], [`RENDER`], [`SAIL`, `SAILCI`], [`SEMAPHORE`], [`SCREWDRIVER`], [`SHIPPABLE`], [`SOLANO`, `TDDIUM`], [`STRIDER`], [`TEAMCITY`, `TEAMCITY_VERSION`], [`TRAVIS`], [`VERCEL`, `NOW_BUILDER`], [`VERCEL`, `VERCEL`, { ci: false }], [`VERCEL`, `VERCEL_ENV`, { ci: false }], [`APPCENTER`, `APPCENTER_BUILD_ID`], [`CODESANDBOX`, `CODESANDBOX_SSE`, { ci: false }], [`CODESANDBOX`, `CODESANDBOX_HOST`, { ci: false }], [`STACKBLITZ`], [`STORMKIT`], [`CLEAVR`], [`ZEABUR`], [`CODESPHERE`, `CODESPHERE_APP_ID`, { ci: true }], [`RAILWAY`, `RAILWAY_PROJECT_ID`], [`RAILWAY`, `RAILWAY_SERVICE_ID`], [`DENO-DEPLOY`, `DENO_DEPLOY`], [`DENO-DEPLOY`, `DENO_DEPLOYMENT_ID`], [`FIREBASE_APP_HOSTING`, `FIREBASE_APP_HOSTING`, { ci: true }], [`EDGEONE_PAGES`, `EO_PAGES_CI`, { ci: true }]];
|
|
6328
|
-
function u() {
|
|
6329
|
-
for (let t2 of l)
|
|
6330
|
-
if (e[t2[1] || t2[0]])
|
|
6331
|
-
return { name: t2[0].toLowerCase(), ...t2[2] };
|
|
6332
|
-
return e.SHELL === `/bin/jsh` && t.versions?.webcontainer ? { name: `stackblitz`, ci: false } : { name: ``, ci: false };
|
|
6333
|
-
}
|
|
6334
|
-
var d = u();
|
|
6335
|
-
var f = d.name;
|
|
6336
|
-
var p = t.platform || ``;
|
|
6337
|
-
var m = !!e.CI || d.ci !== false;
|
|
6338
|
-
var h = !!t.stdout?.isTTY;
|
|
6339
|
-
var _ = !!e.DEBUG;
|
|
6340
|
-
var v = n === `test` || !!e.TEST;
|
|
6341
|
-
var y = n === `production` || e.MODE === `production`;
|
|
6342
|
-
var b = n === `dev` || n === `development` || e.MODE === `development`;
|
|
6343
|
-
var x = !!e.MINIMAL || m || v || !h;
|
|
6344
|
-
var S = /^win/i.test(p);
|
|
6345
|
-
var C = /^linux/i.test(p);
|
|
6346
|
-
var w = /^darwin/i.test(p);
|
|
6347
|
-
var T = !e.NO_COLOR && (!!e.FORCE_COLOR || (h || S) && e.TERM !== `dumb` || m);
|
|
6348
|
-
var E = (t.versions?.node || ``).replace(/^v/, ``) || null;
|
|
6349
|
-
var D = Number(E?.split(`.`)[0]) || null;
|
|
6350
|
-
var O = !!t?.versions?.node;
|
|
6351
|
-
var k = `Bun` in globalThis;
|
|
6352
|
-
var A = `Deno` in globalThis;
|
|
6353
|
-
var j = `fastly` in globalThis;
|
|
6354
|
-
var M = `Netlify` in globalThis;
|
|
6355
|
-
var N = `EdgeRuntime` in globalThis;
|
|
6356
|
-
var P = globalThis.navigator?.userAgent === `Cloudflare-Workers`;
|
|
6357
|
-
var F = [[M, `netlify`], [N, `edge-light`], [P, `workerd`], [j, `fastly`], [A, `deno`], [k, `bun`], [O, `node`]];
|
|
6358
|
-
function I() {
|
|
6359
|
-
let e2 = F.find((e3) => e3[0]);
|
|
6360
|
-
if (e2)
|
|
6361
|
-
return { name: e2[1] };
|
|
6362
|
-
}
|
|
6363
|
-
var L = I();
|
|
6364
|
-
var R = L?.name || ``;
|
|
6365
|
-
|
|
6366
|
-
// src/utils/getAssumedRuntimeEnvironment.ts
|
|
6367
|
-
var getAssumedRuntimeInfo = () => {
|
|
6368
|
-
return {
|
|
6369
|
-
assumed: true,
|
|
6370
|
-
runtimeName: R
|
|
6371
|
-
};
|
|
6372
|
-
};
|
|
6373
|
-
|
|
6374
|
-
// src/ActionRuntime/ActionDomainManager.ts
|
|
6375
|
-
class ActionDomainManager {
|
|
6376
|
-
_domains = new Map;
|
|
6377
|
-
addDomain(domain) {
|
|
6378
|
-
this._domains.set(domain.domain, domain);
|
|
6594
|
+
return clonedLogObj;
|
|
6379
6595
|
}
|
|
6380
|
-
|
|
6381
|
-
|
|
6596
|
+
_cloneError(error) {
|
|
6597
|
+
const cloned = new error.constructor;
|
|
6598
|
+
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
6599
|
+
cloned[key] = error[key];
|
|
6600
|
+
});
|
|
6601
|
+
return cloned;
|
|
6382
6602
|
}
|
|
6383
|
-
|
|
6384
|
-
if (
|
|
6385
|
-
|
|
6603
|
+
_toErrorObject(error, depth = 0, seen = new Set) {
|
|
6604
|
+
if (!seen.has(error)) {
|
|
6605
|
+
seen.add(error);
|
|
6386
6606
|
}
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6607
|
+
const errorObject = {
|
|
6608
|
+
nativeError: error,
|
|
6609
|
+
name: error.name ?? "Error",
|
|
6610
|
+
message: error.message,
|
|
6611
|
+
stack: runtime2.getErrorTrace(error)
|
|
6612
|
+
};
|
|
6613
|
+
if (depth >= this.maxErrorCauseDepth) {
|
|
6614
|
+
return errorObject;
|
|
6393
6615
|
}
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
throw err_nice_action.fromId("domain_no_handler" /* domain_no_handler */, {
|
|
6401
|
-
domain: action.domain
|
|
6402
|
-
});
|
|
6616
|
+
const causeValue = error.cause;
|
|
6617
|
+
if (causeValue != null) {
|
|
6618
|
+
const normalizedCause = toError2(causeValue);
|
|
6619
|
+
if (!seen.has(normalizedCause)) {
|
|
6620
|
+
errorObject.cause = this._toErrorObject(normalizedCause, depth + 1, seen);
|
|
6621
|
+
}
|
|
6403
6622
|
}
|
|
6404
|
-
return
|
|
6405
|
-
}
|
|
6406
|
-
hydrateActionPayload(actionJson) {
|
|
6407
|
-
const domain = this.getActionDomainOrThrow(actionJson);
|
|
6408
|
-
return domain.hydrateAnyAction(actionJson);
|
|
6623
|
+
return errorObject;
|
|
6409
6624
|
}
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
actionRouteData = new Map;
|
|
6416
|
-
_context;
|
|
6417
|
-
constructor(context) {
|
|
6418
|
-
this._context = context;
|
|
6625
|
+
_addMetaToLogObj(logObj, logLevelId, logLevelName) {
|
|
6626
|
+
return {
|
|
6627
|
+
...logObj,
|
|
6628
|
+
[this.settings.metaProperty]: runtime2.getMeta(logLevelId, logLevelName, this.stackDepthLevel, !this.captureStackForMeta, this.settings.name, this.settings.parentNames)
|
|
6629
|
+
};
|
|
6419
6630
|
}
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6631
|
+
_shouldCaptureStack() {
|
|
6632
|
+
if (this.settings.hideLogPositionForProduction) {
|
|
6633
|
+
return false;
|
|
6423
6634
|
}
|
|
6424
|
-
|
|
6425
|
-
|
|
6635
|
+
if (this.settings.type === "json") {
|
|
6636
|
+
return true;
|
|
6426
6637
|
}
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6638
|
+
const template = this.settings.prettyLogTemplate ?? "";
|
|
6639
|
+
const stackPlaceholders = /{{\s*(file(Name|Path|Line|PathWithLine|NameWithLine)|fullFilePath)\s*}}/;
|
|
6640
|
+
if (stackPlaceholders.test(template)) {
|
|
6641
|
+
return true;
|
|
6431
6642
|
}
|
|
6643
|
+
return false;
|
|
6432
6644
|
}
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
const domKey = `dom[${action.domain}]id[_]`;
|
|
6436
|
-
return [
|
|
6437
|
-
...this.actionRouteData.get(idKey) ?? [],
|
|
6438
|
-
...this.actionRouteData.get(domKey) ?? []
|
|
6439
|
-
];
|
|
6440
|
-
}
|
|
6441
|
-
getRouteDataForAction(action) {
|
|
6442
|
-
return this.getRouteDataEntriesForAction(action)[0];
|
|
6645
|
+
_prettyFormatLogObjMeta(logObjMeta) {
|
|
6646
|
+
return buildPrettyMeta2(this.settings, logObjMeta).text;
|
|
6443
6647
|
}
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6451
|
-
|
|
6452
|
-
if (this._context.contextType === "runtime_to_handler" /* runtime_to_handler */) {
|
|
6453
|
-
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
6454
|
-
domain: action.domain,
|
|
6455
|
-
actionId: action.id,
|
|
6456
|
-
specifiedClient: this._context.runtime.clientSpecifier
|
|
6457
|
-
});
|
|
6648
|
+
}
|
|
6649
|
+
|
|
6650
|
+
class Logger2 extends BaseLogger2 {
|
|
6651
|
+
constructor(settings, logObj) {
|
|
6652
|
+
const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
6653
|
+
const normalizedSettings = { ...settings ?? {} };
|
|
6654
|
+
if (isBrowser) {
|
|
6655
|
+
normalizedSettings.stylePrettyLogs = settings?.stylePrettyLogs ?? true;
|
|
6458
6656
|
}
|
|
6459
|
-
|
|
6657
|
+
super(normalizedSettings, logObj, Number.NaN);
|
|
6460
6658
|
}
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
if (entries.length === 0) {
|
|
6464
|
-
this.throwNoHandlerForAction(action, context);
|
|
6465
|
-
}
|
|
6466
|
-
return entries;
|
|
6659
|
+
log(logLevelId, logLevelName, ...args) {
|
|
6660
|
+
return super.log(logLevelId, logLevelName, ...args);
|
|
6467
6661
|
}
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
if (!routeData) {
|
|
6471
|
-
this.throwNoHandlerForAction(action, context);
|
|
6472
|
-
}
|
|
6473
|
-
return routeData;
|
|
6662
|
+
silly(...args) {
|
|
6663
|
+
return super.log(0, "SILLY", ...args);
|
|
6474
6664
|
}
|
|
6475
|
-
|
|
6476
|
-
return
|
|
6665
|
+
trace(...args) {
|
|
6666
|
+
return super.log(1, "TRACE", ...args);
|
|
6477
6667
|
}
|
|
6478
|
-
|
|
6479
|
-
return
|
|
6668
|
+
debug(...args) {
|
|
6669
|
+
return super.log(2, "DEBUG", ...args);
|
|
6480
6670
|
}
|
|
6481
|
-
|
|
6482
|
-
return
|
|
6671
|
+
info(...args) {
|
|
6672
|
+
return super.log(3, "INFO", ...args);
|
|
6483
6673
|
}
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
this.actionRouteData.set(`dom[${domain.domain}]id[_]`, [routeData]);
|
|
6487
|
-
return this;
|
|
6674
|
+
warn(...args) {
|
|
6675
|
+
return super.log(4, "WARN", ...args);
|
|
6488
6676
|
}
|
|
6489
|
-
|
|
6490
|
-
return
|
|
6677
|
+
error(...args) {
|
|
6678
|
+
return super.log(5, "ERROR", ...args);
|
|
6491
6679
|
}
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
this.actionRouteData.set(`dom[${domain.domain}]id[${id}]`, [routeData]);
|
|
6495
|
-
return this;
|
|
6680
|
+
fatal(...args) {
|
|
6681
|
+
return super.log(6, "FATAL", ...args);
|
|
6496
6682
|
}
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
for (const id of ids) {
|
|
6500
|
-
this.forActionId(domain, id, routeData);
|
|
6501
|
-
}
|
|
6502
|
-
return this;
|
|
6683
|
+
getSubLogger(settings, logObj) {
|
|
6684
|
+
return super.getSubLogger(settings, logObj);
|
|
6503
6685
|
}
|
|
6504
|
-
|
|
6505
|
-
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6686
|
+
}
|
|
6687
|
+
var logger_NiceError2 = new Logger2({
|
|
6688
|
+
name: "NiceErrorLogger"
|
|
6689
|
+
});
|
|
6690
|
+
var logger_NiceError_testing2 = logger_NiceError2.getSubLogger({
|
|
6691
|
+
name: "NiceErrorTestingLogger"
|
|
6692
|
+
});
|
|
6693
|
+
function extractPathFromIssue(issue) {
|
|
6694
|
+
let pathString = "";
|
|
6695
|
+
for (const segment of issue) {
|
|
6696
|
+
if (typeof segment === "object") {
|
|
6697
|
+
if (segment.key != null) {
|
|
6698
|
+
if (typeof segment.key === "number") {
|
|
6699
|
+
pathString += `[${String(segment.key)}]`;
|
|
6700
|
+
} else if (typeof segment.key === "symbol") {
|
|
6701
|
+
pathString += `[SYMBOL:${String(segment.key)}]`;
|
|
6702
|
+
} else {
|
|
6703
|
+
pathString += `.${String(segment.key)}`;
|
|
6704
|
+
}
|
|
6510
6705
|
}
|
|
6706
|
+
} else {
|
|
6707
|
+
pathString += `.${String(segment)}`;
|
|
6511
6708
|
}
|
|
6512
|
-
return this;
|
|
6513
6709
|
}
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6710
|
+
return pathString.slice(1);
|
|
6711
|
+
}
|
|
6712
|
+
var extractMessageFromStandardSchema = (failureResult) => {
|
|
6713
|
+
let message = `Data validation failed:
|
|
6714
|
+
`;
|
|
6715
|
+
let issueCount = 0;
|
|
6716
|
+
for (const issue of failureResult.issues) {
|
|
6717
|
+
issueCount++;
|
|
6718
|
+
if (issue.path == null || issue.path.length === 0) {
|
|
6719
|
+
message += ` (issue ${issueCount}) ${issue.message}
|
|
6720
|
+
`;
|
|
6721
|
+
} else {
|
|
6722
|
+
message += ` (issue ${issueCount}) [${extractPathFromIssue(issue.path)}]: ${issue.message}
|
|
6723
|
+
`;
|
|
6724
|
+
}
|
|
6518
6725
|
}
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6726
|
+
return message;
|
|
6727
|
+
};
|
|
6728
|
+
var EValidator;
|
|
6729
|
+
((EValidator2) => {
|
|
6730
|
+
EValidator2["standard_schema"] = "standard_schema";
|
|
6731
|
+
})(EValidator ||= {});
|
|
6732
|
+
var err_validation = err_nice2.createChildDomain({
|
|
6733
|
+
domain: "err_validation",
|
|
6734
|
+
defaultHttpStatusCode: StatusCodes2.BAD_REQUEST,
|
|
6735
|
+
schema: {
|
|
6736
|
+
["standard_schema"]: err2({
|
|
6737
|
+
message: ({ issues }) => extractMessageFromStandardSchema({ issues })
|
|
6738
|
+
})
|
|
6523
6739
|
}
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6740
|
+
});
|
|
6741
|
+
|
|
6742
|
+
// src/ActionDefinition/Schema/ActionSchema.ts
|
|
6743
|
+
class ActionSchema {
|
|
6744
|
+
_errorDeclarations = [];
|
|
6745
|
+
inputOptions;
|
|
6746
|
+
outputOptions;
|
|
6747
|
+
get inputSchema() {
|
|
6748
|
+
return this.inputOptions?.schema;
|
|
6749
|
+
}
|
|
6750
|
+
get outputSchema() {
|
|
6751
|
+
return this.outputOptions?.schema;
|
|
6752
|
+
}
|
|
6753
|
+
input(options, serialize, deserialize) {
|
|
6754
|
+
if (serialize != null && deserialize != null) {
|
|
6755
|
+
this.inputOptions = { ...options, serialization: { serialize, deserialize } };
|
|
6756
|
+
} else {
|
|
6757
|
+
this.inputOptions = options;
|
|
6528
6758
|
}
|
|
6529
6759
|
return this;
|
|
6530
6760
|
}
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
this._push(`dom[${domain.domain}]id[${id}]`, routeData);
|
|
6537
|
-
}
|
|
6761
|
+
output(options, serialize, deserialize) {
|
|
6762
|
+
if (serialize != null && deserialize != null) {
|
|
6763
|
+
this.outputOptions = { ...options, serialization: { serialize, deserialize } };
|
|
6764
|
+
} else {
|
|
6765
|
+
this.outputOptions = options;
|
|
6538
6766
|
}
|
|
6539
6767
|
return this;
|
|
6540
6768
|
}
|
|
6541
|
-
|
|
6542
|
-
this.
|
|
6769
|
+
throws(domain, ids) {
|
|
6770
|
+
this._errorDeclarations.push({ _domain: domain, _ids: ids });
|
|
6543
6771
|
return this;
|
|
6544
6772
|
}
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
existing.push(routeData);
|
|
6549
|
-
} else {
|
|
6550
|
-
this.actionRouteData.set(key, [routeData]);
|
|
6773
|
+
serializeInput(rawInput) {
|
|
6774
|
+
if (this.inputOptions?.serialization) {
|
|
6775
|
+
return this.inputOptions.serialization.serialize(rawInput);
|
|
6551
6776
|
}
|
|
6777
|
+
return rawInput;
|
|
6552
6778
|
}
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
class ActionRuntime {
|
|
6557
|
-
clientSpecifier;
|
|
6558
|
-
timeCreated;
|
|
6559
|
-
runtimeInfo = getAssumedRuntimeInfo();
|
|
6560
|
-
actionRouter;
|
|
6561
|
-
_pendingRunningActions = new Map;
|
|
6562
|
-
_registeredExternalHandlers = [];
|
|
6563
|
-
static getDefault() {
|
|
6564
|
-
return getDefaultActionRuntime();
|
|
6565
|
-
}
|
|
6566
|
-
constructor(client) {
|
|
6567
|
-
this.clientSpecifier = client.specifyIfUnset({
|
|
6568
|
-
insId: nanoid(14)
|
|
6569
|
-
});
|
|
6570
|
-
this.timeCreated = Date.now();
|
|
6571
|
-
this.actionRouter = new ActionRouter({
|
|
6572
|
-
contextType: "runtime_to_handler" /* runtime_to_handler */,
|
|
6573
|
-
runtime: this
|
|
6574
|
-
});
|
|
6575
|
-
}
|
|
6576
|
-
registerRunningAction(ra) {
|
|
6577
|
-
this._pendingRunningActions.set(ra.cuid, ra);
|
|
6578
|
-
ra.addUpdateListeners([
|
|
6579
|
-
(update) => {
|
|
6580
|
-
if (update.type === "finished" /* finished */) {
|
|
6581
|
-
this._pendingRunningActions.delete(ra.cuid);
|
|
6582
|
-
}
|
|
6583
|
-
}
|
|
6584
|
-
]);
|
|
6585
|
-
}
|
|
6586
|
-
resolveIncomingActionPayload(json) {
|
|
6587
|
-
if (json.type === "request" /* request */) {
|
|
6588
|
-
this.handleActionPayloadWire(json).catch((err3) => {
|
|
6589
|
-
console.error(`[ActionRuntime] Incoming primed action [${json.domain}:${json.id}] unhandled:`, err3);
|
|
6590
|
-
});
|
|
6591
|
-
return;
|
|
6779
|
+
deserializeInput(serialized) {
|
|
6780
|
+
if (this.inputOptions?.serialization) {
|
|
6781
|
+
return this.inputOptions.serialization.deserialize(serialized);
|
|
6592
6782
|
}
|
|
6593
|
-
|
|
6783
|
+
return serialized;
|
|
6594
6784
|
}
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
const domain = this.actionRouter.domainManager.getActionDomain(wire);
|
|
6599
|
-
if (domain) {
|
|
6600
|
-
action = domain.hydrateAnyAction(wire);
|
|
6601
|
-
}
|
|
6785
|
+
validateInput(value, meta) {
|
|
6786
|
+
if (this.inputOptions?.schema == null) {
|
|
6787
|
+
return value;
|
|
6602
6788
|
}
|
|
6603
|
-
|
|
6604
|
-
|
|
6789
|
+
const result = this.inputOptions.schema["~standard"].validate(value);
|
|
6790
|
+
if (result instanceof Promise) {
|
|
6791
|
+
throw err_nice_action.fromId("action_input_validation_promise" /* action_input_validation_promise */, {
|
|
6792
|
+
domain: meta.domain,
|
|
6793
|
+
actionId: meta.actionId
|
|
6794
|
+
});
|
|
6605
6795
|
}
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
const runningAction = await handlerForAction.handleActionRequest(action, {
|
|
6612
|
-
...options,
|
|
6613
|
-
targetLocalRuntime: this
|
|
6796
|
+
if (result.issues != null) {
|
|
6797
|
+
throw err_nice_action.fromId("action_input_validation_failed" /* action_input_validation_failed */, {
|
|
6798
|
+
domain: meta.domain,
|
|
6799
|
+
actionId: meta.actionId,
|
|
6800
|
+
validationMessage: extractMessageFromStandardSchema(result)
|
|
6614
6801
|
});
|
|
6615
|
-
this._trySetupReturnDispatch(runningAction);
|
|
6616
|
-
return runningAction;
|
|
6617
6802
|
}
|
|
6618
|
-
|
|
6619
|
-
label: `Handling incoming action payloads of type "${action.type}"`
|
|
6620
|
-
});
|
|
6803
|
+
return result.value;
|
|
6621
6804
|
}
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
const possibleHandlers = handlers.filter((handler2) => {
|
|
6626
|
-
if (handler2.handlerType === "external" /* external */) {
|
|
6627
|
-
if (targetExternalClient && !targetExternalClient.isSameFor(handler2.externalClient).id) {
|
|
6628
|
-
return false;
|
|
6629
|
-
}
|
|
6630
|
-
return true;
|
|
6631
|
-
}
|
|
6632
|
-
if (targetExternalClient != null) {
|
|
6633
|
-
return false;
|
|
6634
|
-
}
|
|
6635
|
-
if (action.type === "request" /* request */) {
|
|
6636
|
-
return true;
|
|
6637
|
-
}
|
|
6638
|
-
return false;
|
|
6639
|
-
});
|
|
6640
|
-
if (possibleHandlers.length === 0) {
|
|
6641
|
-
return;
|
|
6642
|
-
}
|
|
6643
|
-
const scoringExternalClient = targetExternalClient ?? ActionClientSpecifier.unknown;
|
|
6644
|
-
let handlerScore = -1;
|
|
6645
|
-
let handler;
|
|
6646
|
-
for (const possibleHandler of possibleHandlers) {
|
|
6647
|
-
if (possibleHandler.handlerType === "local" /* local */ && handler == null) {
|
|
6648
|
-
return possibleHandler;
|
|
6649
|
-
}
|
|
6650
|
-
if (possibleHandler.handlerType === "external" /* external */) {
|
|
6651
|
-
const score = scoringExternalClient.similarityLevel(possibleHandler.externalClient);
|
|
6652
|
-
if (score > handlerScore) {
|
|
6653
|
-
handlerScore = score;
|
|
6654
|
-
handler = possibleHandler;
|
|
6655
|
-
}
|
|
6656
|
-
}
|
|
6805
|
+
validateOutput(value, meta) {
|
|
6806
|
+
if (this.outputOptions?.schema == null) {
|
|
6807
|
+
return value;
|
|
6657
6808
|
}
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
6664
|
-
actionId: action.id,
|
|
6665
|
-
domain: action.domain,
|
|
6666
|
-
specifiedClient: options?.targetExternalClient
|
|
6809
|
+
const result = this.outputOptions.schema["~standard"].validate(value);
|
|
6810
|
+
if (result instanceof Promise) {
|
|
6811
|
+
throw err_nice_action.fromId("action_output_validation_promise" /* action_output_validation_promise */, {
|
|
6812
|
+
domain: meta.domain,
|
|
6813
|
+
actionId: meta.actionId
|
|
6667
6814
|
});
|
|
6668
6815
|
}
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
this._registeredExternalHandlers.push(handler);
|
|
6676
|
-
}
|
|
6677
|
-
const handlerRouter = handler.getActionRouter();
|
|
6678
|
-
this.actionRouter.addDomainsFromOther(handlerRouter);
|
|
6679
|
-
for (const key of handlerRouter.getRegisteredKeys()) {
|
|
6680
|
-
const alreadyRegistered = this.actionRouter.getForKey(key).some((h2) => h2.cuid === handler.cuid);
|
|
6681
|
-
if (!alreadyRegistered) {
|
|
6682
|
-
this.actionRouter.addForKey(key, handler);
|
|
6683
|
-
}
|
|
6684
|
-
}
|
|
6816
|
+
if (result.issues != null) {
|
|
6817
|
+
throw err_nice_action.fromId("action_output_validation_failed" /* action_output_validation_failed */, {
|
|
6818
|
+
domain: meta.domain,
|
|
6819
|
+
actionId: meta.actionId,
|
|
6820
|
+
validationMessage: extractMessageFromStandardSchema(result)
|
|
6821
|
+
});
|
|
6685
6822
|
}
|
|
6686
|
-
return
|
|
6823
|
+
return result.value;
|
|
6687
6824
|
}
|
|
6688
|
-
|
|
6689
|
-
if (
|
|
6690
|
-
return;
|
|
6691
|
-
let bestScore = -1;
|
|
6692
|
-
let bestHandler;
|
|
6693
|
-
for (const handler of this._registeredExternalHandlers) {
|
|
6694
|
-
const score = originClient.similarityLevel(handler.externalClient);
|
|
6695
|
-
if (score > bestScore) {
|
|
6696
|
-
bestScore = score;
|
|
6697
|
-
bestHandler = handler;
|
|
6698
|
-
}
|
|
6825
|
+
serializeOutput(rawOutput) {
|
|
6826
|
+
if (this.outputOptions?.serialization) {
|
|
6827
|
+
return this.outputOptions.serialization.serialize(rawOutput);
|
|
6699
6828
|
}
|
|
6700
|
-
return
|
|
6829
|
+
return rawOutput;
|
|
6701
6830
|
}
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
return;
|
|
6831
|
+
deserializeOutput(serialized) {
|
|
6832
|
+
if (this.outputOptions?.serialization) {
|
|
6833
|
+
return this.outputOptions.serialization.deserialize(serialized);
|
|
6706
6834
|
}
|
|
6707
|
-
|
|
6708
|
-
(update) => {
|
|
6709
|
-
if (update.type === "finished" /* finished */ && update.finishType === "success" /* success */) {
|
|
6710
|
-
const returnHandler = this.getReturnHandlerForOrigin(originClient);
|
|
6711
|
-
returnHandler?.sendReturnPayload(update.response, { targetLocalRuntime: this }).catch(() => {});
|
|
6712
|
-
}
|
|
6713
|
-
}
|
|
6714
|
-
]);
|
|
6835
|
+
return serialized;
|
|
6715
6836
|
}
|
|
6716
6837
|
}
|
|
6717
|
-
var
|
|
6718
|
-
|
|
6719
|
-
assumedRuntimeInfo: undefined
|
|
6838
|
+
var actionSchema = () => {
|
|
6839
|
+
return new ActionSchema;
|
|
6720
6840
|
};
|
|
6721
|
-
function getDefaultActionRuntime() {
|
|
6722
|
-
if (runtimeState.assumedRuntimeInfo == null) {
|
|
6723
|
-
runtimeState.assumedRuntimeInfo = getAssumedRuntimeInfo();
|
|
6724
|
-
}
|
|
6725
|
-
if (runtimeState.defaultLocalRuntime == null) {
|
|
6726
|
-
runtimeState.defaultLocalRuntime = new ActionRuntime(ActionClientSpecifier.unknown.specify({
|
|
6727
|
-
perId: `${runtimeState.assumedRuntimeInfo?.runtimeName ?? "unknown"}-runtime`
|
|
6728
|
-
}));
|
|
6729
|
-
}
|
|
6730
|
-
return runtimeState.defaultLocalRuntime;
|
|
6731
|
-
}
|
|
6732
|
-
// src/ActionRuntime/Handler/ActionHandler.ts
|
|
6733
|
-
class ActionHandler {
|
|
6734
|
-
cuid;
|
|
6735
|
-
constructor() {
|
|
6736
|
-
this.cuid = nanoid();
|
|
6737
|
-
}
|
|
6738
|
-
getActionRouter() {
|
|
6739
|
-
return this.actionRouter;
|
|
6740
|
-
}
|
|
6741
|
-
}
|
|
6742
|
-
|
|
6743
6841
|
// src/ActionRuntime/Handler/ExternalClient/err_nice_external_client.ts
|
|
6744
6842
|
var err_nice_external_client = err_nice_action.createChildDomain({
|
|
6745
6843
|
domain: "err_nice_external_client",
|
|
@@ -7196,9 +7294,9 @@ class TransportWebSocket extends Transport {
|
|
|
7196
7294
|
};
|
|
7197
7295
|
ws.addEventListener("message", (event) => {
|
|
7198
7296
|
if (typeof event.data === "string") {
|
|
7199
|
-
const
|
|
7200
|
-
if (
|
|
7201
|
-
this.resolvers.onIncomingActionDataJson(
|
|
7297
|
+
const rawJson = wsData.formatMessage?.incoming?.(event.data) ?? this._parseActionMessage(event.data);
|
|
7298
|
+
if (rawJson != null && isActionPayload_Any_JsonObject(rawJson)) {
|
|
7299
|
+
this.resolvers.onIncomingActionDataJson(rawJson);
|
|
7202
7300
|
}
|
|
7203
7301
|
}
|
|
7204
7302
|
});
|
|
@@ -7366,88 +7464,6 @@ class ActionExternalClientHandler extends ActionHandler {
|
|
|
7366
7464
|
var createExternalClientHandler = (config) => {
|
|
7367
7465
|
return new ActionExternalClientHandler(config);
|
|
7368
7466
|
};
|
|
7369
|
-
// src/ActionRuntime/Handler/Local/ActionLocalHandler.ts
|
|
7370
|
-
class ActionLocalHandler extends ActionHandler {
|
|
7371
|
-
handlerType = "local" /* local */;
|
|
7372
|
-
actionRouter = new ActionRouter({
|
|
7373
|
-
contextType: "handler_route" /* handler_route */,
|
|
7374
|
-
handler: this
|
|
7375
|
-
});
|
|
7376
|
-
constructor() {
|
|
7377
|
-
super();
|
|
7378
|
-
}
|
|
7379
|
-
forDomain(domain, handler) {
|
|
7380
|
-
this.actionRouter.forDomain(domain, handler);
|
|
7381
|
-
return this;
|
|
7382
|
-
}
|
|
7383
|
-
forAction(action, handler) {
|
|
7384
|
-
this.actionRouter.forAction(action, handler);
|
|
7385
|
-
return this;
|
|
7386
|
-
}
|
|
7387
|
-
forActionIds(domain, ids, handler) {
|
|
7388
|
-
this.actionRouter.forActionIds(domain, ids, handler);
|
|
7389
|
-
return this;
|
|
7390
|
-
}
|
|
7391
|
-
forDomainActionCases(domain, cases) {
|
|
7392
|
-
this.actionRouter.forDomainActionCases(domain, cases);
|
|
7393
|
-
return this;
|
|
7394
|
-
}
|
|
7395
|
-
async handleActionRequest(action, config) {
|
|
7396
|
-
const targetLocalRuntime = config?.targetLocalRuntime ?? ActionRuntime.getDefault();
|
|
7397
|
-
const handler = this.actionRouter.getRouteDataForActionOrThrow(action, {
|
|
7398
|
-
targetLocalRuntime
|
|
7399
|
-
});
|
|
7400
|
-
action.context.addRouteItem({
|
|
7401
|
-
runtime: targetLocalRuntime.clientSpecifier,
|
|
7402
|
-
handler: this.toHandlerRouteItem(),
|
|
7403
|
-
time: Date.now()
|
|
7404
|
-
});
|
|
7405
|
-
const runningAction = new RunningAction({ context: action.context, request: action });
|
|
7406
|
-
this._handleRunningAction(handler, runningAction).catch((err3) => runningAction._abort(err3));
|
|
7407
|
-
return runningAction;
|
|
7408
|
-
}
|
|
7409
|
-
async _handleRunningAction(handler, runningAction) {
|
|
7410
|
-
const state = runningAction.state;
|
|
7411
|
-
if (state.result != null) {
|
|
7412
|
-
return;
|
|
7413
|
-
}
|
|
7414
|
-
const rawResult = await handler(state.request);
|
|
7415
|
-
let result;
|
|
7416
|
-
if (rawResult instanceof ActionPayload_Result) {
|
|
7417
|
-
result = rawResult;
|
|
7418
|
-
} else if (rawResult != null && isActionPayload_Result_JsonObject(rawResult)) {
|
|
7419
|
-
const domain = this.actionRouter.domainManager.getActionDomainOrThrow(state.request);
|
|
7420
|
-
result = domain.hydrateResultPayload(rawResult);
|
|
7421
|
-
} else {
|
|
7422
|
-
result = state.request.successResult(rawResult);
|
|
7423
|
-
}
|
|
7424
|
-
runningAction._completeWithResult(result);
|
|
7425
|
-
}
|
|
7426
|
-
async handlePayloadWireOrThrow(wire, config) {
|
|
7427
|
-
const hydratedAction = this.actionRouter.domainManager.hydrateActionPayload(wire);
|
|
7428
|
-
if (!(hydratedAction instanceof ActionPayload_Request)) {
|
|
7429
|
-
throw err_nice_action.fromId("wire_action_not_primed_or_response" /* wire_action_not_primed_or_response */, {
|
|
7430
|
-
domain: hydratedAction.domain,
|
|
7431
|
-
actionId: hydratedAction.id,
|
|
7432
|
-
actionState: hydratedAction.type ?? hydratedAction.form
|
|
7433
|
-
});
|
|
7434
|
-
}
|
|
7435
|
-
return await this.handleActionRequest(hydratedAction, config);
|
|
7436
|
-
}
|
|
7437
|
-
toJsonObject() {
|
|
7438
|
-
return {
|
|
7439
|
-
type: this.handlerType
|
|
7440
|
-
};
|
|
7441
|
-
}
|
|
7442
|
-
toHandlerRouteItem() {
|
|
7443
|
-
return {
|
|
7444
|
-
type: this.handlerType
|
|
7445
|
-
};
|
|
7446
|
-
}
|
|
7447
|
-
}
|
|
7448
|
-
var createLocalHandler = () => {
|
|
7449
|
-
return new ActionLocalHandler;
|
|
7450
|
-
};
|
|
7451
7467
|
export {
|
|
7452
7468
|
isActionPayload_Result_JsonObject,
|
|
7453
7469
|
isActionPayload_Request_JsonObject,
|