@nice-code/action 0.2.2 → 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
CHANGED
|
@@ -3337,14 +3337,80 @@ var isAction_Base_JsonObject = (obj) => {
|
|
|
3337
3337
|
return typeof obj === "object" && obj !== null && typeof obj.domain === "string" && typeof obj.id === "string" && typeof obj.form === "string";
|
|
3338
3338
|
};
|
|
3339
3339
|
|
|
3340
|
-
// src/utils/
|
|
3341
|
-
var
|
|
3342
|
-
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 */;
|
|
3343
3343
|
};
|
|
3344
3344
|
|
|
3345
|
-
//
|
|
3346
|
-
var
|
|
3347
|
-
|
|
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
|
+
};
|
|
3348
3414
|
};
|
|
3349
3415
|
|
|
3350
3416
|
// src/utils/isActionPayload_Progress_JsonObject.ts
|
|
@@ -3357,321 +3423,782 @@ var isActionPayload_Request_JsonObject = (obj) => {
|
|
|
3357
3423
|
return isAction_Base_JsonObject(obj) && "input" in obj && obj.form === "data" /* data */ && obj.type === "request" /* request */;
|
|
3358
3424
|
};
|
|
3359
3425
|
|
|
3360
|
-
// src/utils/isActionPayload_Result_JsonObject.ts
|
|
3361
|
-
var isActionPayload_Result_JsonObject = (obj) => {
|
|
3362
|
-
return isAction_Base_JsonObject(obj) && obj.result != null && obj.form === "data" /* data */ && obj.type === "result" /* result */;
|
|
3363
|
-
};
|
|
3364
|
-
|
|
3365
3426
|
// src/utils/isActionPayload_Any_JsonObject.ts
|
|
3366
3427
|
function isActionPayload_Any_JsonObject(obj) {
|
|
3367
3428
|
return isActionPayload_Request_JsonObject(obj) || isActionPayload_Result_JsonObject(obj) || isActionPayload_Progress_JsonObject(obj);
|
|
3368
3429
|
}
|
|
3369
3430
|
|
|
3370
|
-
// src/
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
// src/utils/assertIsActionJson.ts
|
|
3376
|
-
function assertIsActionJson(obj) {
|
|
3377
|
-
if (!isAction_Any_JsonObject(obj)) {
|
|
3378
|
-
throw err_nice_action.fromId("wire_not_action_data" /* wire_not_action_data */);
|
|
3379
|
-
}
|
|
3380
|
-
}
|
|
3381
|
-
|
|
3382
|
-
// src/utils/isAction_Any_Instance.ts
|
|
3383
|
-
function isAction_Any_Instance(value) {
|
|
3384
|
-
return value instanceof ActionCore || value instanceof ActionPayload || value instanceof ActionContext;
|
|
3385
|
-
}
|
|
3386
|
-
|
|
3387
|
-
// src/ActionDefinition/Domain/ActionDomainBase.ts
|
|
3388
|
-
class ActionDomainBase {
|
|
3389
|
-
domain;
|
|
3390
|
-
allDomains;
|
|
3391
|
-
actionSchema;
|
|
3392
|
-
_listeners = [];
|
|
3393
|
-
constructor(definition) {
|
|
3394
|
-
this.domain = definition.domain;
|
|
3395
|
-
this.allDomains = definition.allDomains;
|
|
3396
|
-
this.actionSchema = definition.actionSchema;
|
|
3431
|
+
// src/ActionRuntime/ActionDomainManager.ts
|
|
3432
|
+
class ActionDomainManager {
|
|
3433
|
+
_domains = new Map;
|
|
3434
|
+
addDomain(domain) {
|
|
3435
|
+
this._domains.set(domain.domain, domain);
|
|
3397
3436
|
}
|
|
3398
|
-
|
|
3399
|
-
this.
|
|
3400
|
-
return () => {
|
|
3401
|
-
this._listeners = this._listeners.filter((l) => l !== listener);
|
|
3402
|
-
};
|
|
3437
|
+
getDomains() {
|
|
3438
|
+
return [...this._domains.values()];
|
|
3403
3439
|
}
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
_rootDomain;
|
|
3409
|
-
_actionMap;
|
|
3410
|
-
constructor(definition, {
|
|
3411
|
-
rootDomain
|
|
3412
|
-
}) {
|
|
3413
|
-
super(definition);
|
|
3414
|
-
this._rootDomain = rootDomain;
|
|
3415
|
-
this._actionMap = this.createActionMap();
|
|
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
|
+
}
|
|
3416
3444
|
}
|
|
3417
|
-
|
|
3418
|
-
|
|
3445
|
+
getActionDomain(action) {
|
|
3446
|
+
this.verifyIsActionJson(action);
|
|
3447
|
+
const domain = this._domains.get(action.domain);
|
|
3448
|
+
if (!domain) {
|
|
3449
|
+
return;
|
|
3450
|
+
}
|
|
3451
|
+
return domain;
|
|
3419
3452
|
}
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
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
|
|
3426
3459
|
});
|
|
3427
3460
|
}
|
|
3428
|
-
return
|
|
3429
|
-
allDomains: [...this.allDomains, subDomainDef.domain],
|
|
3430
|
-
domain: subDomainDef.domain,
|
|
3431
|
-
actionSchema: subDomainDef.actions
|
|
3432
|
-
}, { rootDomain: this._rootDomain });
|
|
3461
|
+
return domain;
|
|
3433
3462
|
}
|
|
3434
|
-
|
|
3435
|
-
|
|
3463
|
+
hydrateActionPayload(actionJson) {
|
|
3464
|
+
const domain = this.getActionDomainOrThrow(actionJson);
|
|
3465
|
+
return domain.hydrateAnyAction(actionJson);
|
|
3436
3466
|
}
|
|
3437
|
-
|
|
3438
|
-
|
|
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;
|
|
3439
3476
|
}
|
|
3440
|
-
|
|
3441
|
-
const
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
});
|
|
3477
|
+
mergeRouter(actionRouter) {
|
|
3478
|
+
for (const domain of actionRouter.getDomains()) {
|
|
3479
|
+
this.domainManager.addDomain(domain);
|
|
3480
|
+
}
|
|
3481
|
+
for (const [matchKey, routeDataEntries] of actionRouter.actionRouteData.entries()) {
|
|
3482
|
+
this.actionRouteData.set(matchKey, [...routeDataEntries]);
|
|
3447
3483
|
}
|
|
3448
|
-
return new ActionCore(this, id);
|
|
3449
3484
|
}
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
routing: contextData.routing.map((item) => {
|
|
3455
|
-
return {
|
|
3456
|
-
runtime: new ActionClientSpecifier(item.runtime),
|
|
3457
|
-
handler: item.handler,
|
|
3458
|
-
time: item.time
|
|
3459
|
-
};
|
|
3460
|
-
}),
|
|
3461
|
-
originClient: contextData.originClient ? new ActionClientSpecifier(contextData.originClient) : ActionClientSpecifier.unknown
|
|
3462
|
-
});
|
|
3485
|
+
addDomainsFromOther(actionRouter) {
|
|
3486
|
+
for (const domain of actionRouter.getDomains()) {
|
|
3487
|
+
this.domainManager.addDomain(domain);
|
|
3488
|
+
}
|
|
3463
3489
|
}
|
|
3464
|
-
|
|
3465
|
-
|
|
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
|
+
];
|
|
3466
3497
|
}
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
expected: this.domain,
|
|
3477
|
-
received: serialized.domain
|
|
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
|
|
3478
3507
|
});
|
|
3479
3508
|
}
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
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
|
|
3485
3514
|
});
|
|
3486
3515
|
}
|
|
3487
|
-
|
|
3488
|
-
return new ActionPayload_Request({ context: contextAction }, contextAction.deserializeInput(serialized.input), {
|
|
3489
|
-
time: serialized.time
|
|
3490
|
-
});
|
|
3516
|
+
throw new Error(`No route function found for action with domain "${action.domain}" and id "${action.id}".`);
|
|
3491
3517
|
}
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
received: serialized.type
|
|
3497
|
-
});
|
|
3498
|
-
}
|
|
3499
|
-
if (serialized.domain !== this.domain) {
|
|
3500
|
-
throw err_nice_action.fromId("hydration_domain_mismatch" /* hydration_domain_mismatch */, {
|
|
3501
|
-
expected: this.domain,
|
|
3502
|
-
received: serialized.domain
|
|
3503
|
-
});
|
|
3504
|
-
}
|
|
3505
|
-
const id = serialized.id;
|
|
3506
|
-
if (!this.actionSchema[id]) {
|
|
3507
|
-
throw err_nice_action.fromId("hydration_action_id_not_found" /* hydration_action_id_not_found */, {
|
|
3508
|
-
domain: this.domain,
|
|
3509
|
-
actionId: serialized.id
|
|
3510
|
-
});
|
|
3518
|
+
getRouteDataEntriesForActionOrThrow(action, context) {
|
|
3519
|
+
const entries = this.getRouteDataEntriesForAction(action);
|
|
3520
|
+
if (entries.length === 0) {
|
|
3521
|
+
this.throwNoHandlerForAction(action, context);
|
|
3511
3522
|
}
|
|
3512
|
-
|
|
3513
|
-
return new ActionPayload_Result({ context: contextAction }, serialized.result, {
|
|
3514
|
-
time: serialized.time
|
|
3515
|
-
});
|
|
3523
|
+
return entries;
|
|
3516
3524
|
}
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
if (
|
|
3520
|
-
|
|
3521
|
-
return this.hydrateRequestPayload(actionJson);
|
|
3522
|
-
}
|
|
3523
|
-
if (actionJson.type === "result" /* result */) {
|
|
3524
|
-
return this.hydrateResultPayload(actionJson);
|
|
3525
|
-
}
|
|
3525
|
+
getRouteDataForActionOrThrow(action, context) {
|
|
3526
|
+
const routeData = this.getRouteDataForAction(action);
|
|
3527
|
+
if (!routeData) {
|
|
3528
|
+
this.throwNoHandlerForAction(action, context);
|
|
3526
3529
|
}
|
|
3527
|
-
return
|
|
3530
|
+
return routeData;
|
|
3528
3531
|
}
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
...options?.listeners ?? [],
|
|
3532
|
-
...this._listeners
|
|
3533
|
-
];
|
|
3534
|
-
return this._rootDomain._runAction(request, {
|
|
3535
|
-
...options,
|
|
3536
|
-
listeners: allListeners
|
|
3537
|
-
});
|
|
3532
|
+
getForKey(key) {
|
|
3533
|
+
return this.actionRouteData.get(key) ?? [];
|
|
3538
3534
|
}
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
for (const id in this.actionSchema) {
|
|
3542
|
-
map[id] = new ActionCore(this, id);
|
|
3543
|
-
}
|
|
3544
|
-
return map;
|
|
3535
|
+
getRegisteredKeys() {
|
|
3536
|
+
return [...this.actionRouteData.keys()];
|
|
3545
3537
|
}
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
class ActionRuntimeManager {
|
|
3549
|
-
_runtimes = new Map;
|
|
3550
|
-
_preferredRuntimeClientId = null;
|
|
3551
|
-
_context;
|
|
3552
|
-
constructor(context) {
|
|
3553
|
-
this._context = context ?? {};
|
|
3538
|
+
getDomains() {
|
|
3539
|
+
return this.domainManager.getDomains();
|
|
3554
3540
|
}
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
context: this._context,
|
|
3560
|
-
client: runtime2.clientSpecifier
|
|
3561
|
-
});
|
|
3562
|
-
}
|
|
3563
|
-
for (const id of runtime2.clientSpecifier.toStringIds()) {
|
|
3564
|
-
if (this._runtimes.has(id)) {
|
|
3565
|
-
continue;
|
|
3566
|
-
}
|
|
3567
|
-
this._runtimes.set(id, runtime2);
|
|
3568
|
-
}
|
|
3541
|
+
forDomain(domain, routeData) {
|
|
3542
|
+
this.domainManager.addDomain(domain);
|
|
3543
|
+
this.actionRouteData.set(`dom[${domain.domain}]id[_]`, [routeData]);
|
|
3544
|
+
return this;
|
|
3569
3545
|
}
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
3583
|
-
domain: action.domain,
|
|
3584
|
-
actionId: action.id,
|
|
3585
|
-
specifiedClient: localRuntime.clientSpecifier
|
|
3586
|
-
});
|
|
3587
|
-
}
|
|
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);
|
|
3588
3558
|
}
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
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]);
|
|
3593
3567
|
}
|
|
3594
3568
|
}
|
|
3595
|
-
|
|
3596
|
-
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
3597
|
-
domain: action.domain,
|
|
3598
|
-
actionId: action.id,
|
|
3599
|
-
specifiedClient: options?.targetLocalRuntime?.clientSpecifier
|
|
3600
|
-
});
|
|
3601
|
-
}
|
|
3569
|
+
return this;
|
|
3602
3570
|
}
|
|
3603
|
-
|
|
3604
|
-
|
|
3571
|
+
addForDomain(domain, routeData) {
|
|
3572
|
+
this.domainManager.addDomain(domain);
|
|
3573
|
+
this._push(`dom[${domain.domain}]id[_]`, routeData);
|
|
3574
|
+
return this;
|
|
3605
3575
|
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
this.
|
|
3576
|
+
addForAction(domain, id, routeData) {
|
|
3577
|
+
this.domainManager.addDomain(domain);
|
|
3578
|
+
this._push(`dom[${domain.domain}]id[${id}]`, routeData);
|
|
3579
|
+
return this;
|
|
3609
3580
|
}
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
return runtime2;
|
|
3615
|
-
}
|
|
3581
|
+
addForActionIds(domain, ids, routeData) {
|
|
3582
|
+
this.domainManager.addDomain(domain);
|
|
3583
|
+
for (const id of ids) {
|
|
3584
|
+
this.addForAction(domain, id, routeData);
|
|
3616
3585
|
}
|
|
3617
|
-
return this
|
|
3586
|
+
return this;
|
|
3618
3587
|
}
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
const
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
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);
|
|
3626
3594
|
}
|
|
3627
3595
|
}
|
|
3596
|
+
return this;
|
|
3628
3597
|
}
|
|
3629
|
-
|
|
3630
|
-
|
|
3598
|
+
addForKey(key, routeData) {
|
|
3599
|
+
this._push(key, routeData);
|
|
3600
|
+
return this;
|
|
3631
3601
|
}
|
|
3632
|
-
|
|
3633
|
-
const
|
|
3634
|
-
if (
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
});
|
|
3639
|
-
}
|
|
3640
|
-
throw err_nice_action.fromId("client_runtime_not_registered" /* client_runtime_not_registered */, {
|
|
3641
|
-
context: this._context,
|
|
3642
|
-
clientStringId: clientSpecifierToStringIds(specifier)[0]
|
|
3643
|
-
});
|
|
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]);
|
|
3644
3608
|
}
|
|
3645
|
-
return runtime2;
|
|
3646
3609
|
}
|
|
3647
3610
|
}
|
|
3648
3611
|
|
|
3649
|
-
// src/
|
|
3650
|
-
class
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
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
|
|
3659
3631
|
});
|
|
3660
|
-
this.domainDefinition = domainDefinition;
|
|
3661
|
-
this._actionRuntimeManager = new ActionRuntimeManager({ domain: domainId });
|
|
3662
3632
|
}
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
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);
|
|
3669
3647
|
});
|
|
3648
|
+
return;
|
|
3670
3649
|
}
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3650
|
+
this._pendingRunningActions.get(json.context.cuid)?._resolveFromJson(json);
|
|
3651
|
+
}
|
|
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);
|
|
3662
|
+
}
|
|
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
|
|
3675
4202
|
}, { rootDomain: this });
|
|
3676
4203
|
}
|
|
3677
4204
|
addActionRuntime(runtime2) {
|
|
@@ -4002,14 +4529,14 @@ var StatusCodes2;
|
|
|
4002
4529
|
StatusCodes22[StatusCodes22["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
4003
4530
|
})(StatusCodes2 || (StatusCodes2 = {}));
|
|
4004
4531
|
var __assign2 = function() {
|
|
4005
|
-
__assign2 = Object.assign || function(
|
|
4006
|
-
for (var
|
|
4007
|
-
|
|
4008
|
-
for (var
|
|
4009
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
4010
|
-
|
|
4011
|
-
}
|
|
4012
|
-
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;
|
|
4013
4540
|
};
|
|
4014
4541
|
return __assign2.apply(this, arguments);
|
|
4015
4542
|
};
|
|
@@ -4118,7 +4645,7 @@ class NiceError2 extends Error {
|
|
|
4118
4645
|
const otherIds = other.getIds().map(String).sort();
|
|
4119
4646
|
if (myIds.length !== otherIds.length)
|
|
4120
4647
|
return false;
|
|
4121
|
-
return myIds.every((id,
|
|
4648
|
+
return myIds.every((id, i2) => id === otherIds[i2]);
|
|
4122
4649
|
}
|
|
4123
4650
|
toJsonObject() {
|
|
4124
4651
|
const originError = this.originError ? {
|
|
@@ -4643,8 +5170,8 @@ function formatTemplate2(settings, template, values, hideUnsetPlaceholder = fals
|
|
|
4643
5170
|
}
|
|
4644
5171
|
};
|
|
4645
5172
|
const defaultStyle = null;
|
|
4646
|
-
return templateString.replace(/{{(.+?)}}/g, (
|
|
4647
|
-
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;
|
|
4648
5175
|
return settings.stylePrettyLogs ? styleWrap(value, settings?.prettyLogStyles?.[placeholder] ?? defaultStyle) + ansiColorWrap("", prettyLogStyles2.reset) : value;
|
|
4649
5176
|
});
|
|
4650
5177
|
}
|
|
@@ -4881,14 +5408,14 @@ function isRegExp2(re) {
|
|
|
4881
5408
|
function isObject2(arg) {
|
|
4882
5409
|
return typeof arg === "object" && arg !== null;
|
|
4883
5410
|
}
|
|
4884
|
-
function isError2(
|
|
4885
|
-
return isObject2(
|
|
5411
|
+
function isError2(e2) {
|
|
5412
|
+
return isObject2(e2) && (objectToString2(e2) === "[object Error]" || e2 instanceof Error);
|
|
4886
5413
|
}
|
|
4887
|
-
function isDate2(
|
|
4888
|
-
return isObject2(
|
|
5414
|
+
function isDate2(d2) {
|
|
5415
|
+
return isObject2(d2) && objectToString2(d2) === "[object Date]";
|
|
4889
5416
|
}
|
|
4890
|
-
function objectToString2(
|
|
4891
|
-
return Object.prototype.toString.call(
|
|
5417
|
+
function objectToString2(o2) {
|
|
5418
|
+
return Object.prototype.toString.call(o2);
|
|
4892
5419
|
}
|
|
4893
5420
|
function arrayToHash2(array) {
|
|
4894
5421
|
const hash = {};
|
|
@@ -4899,9 +5426,9 @@ function arrayToHash2(array) {
|
|
|
4899
5426
|
}
|
|
4900
5427
|
function formatArray2(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
4901
5428
|
const output = [];
|
|
4902
|
-
for (let
|
|
4903
|
-
if (hasOwn2(value, String(
|
|
4904
|
-
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));
|
|
4905
5432
|
} else {
|
|
4906
5433
|
output.push("");
|
|
4907
5434
|
}
|
|
@@ -4972,8 +5499,8 @@ function formatValue2(ctx, value, recurseTimes = 0) {
|
|
|
4972
5499
|
]`];
|
|
4973
5500
|
}
|
|
4974
5501
|
if (isFunction2(value)) {
|
|
4975
|
-
const
|
|
4976
|
-
base = " [Function" +
|
|
5502
|
+
const n2 = value.name ? ": " + value.name : "";
|
|
5503
|
+
base = " [Function" + n2 + "]";
|
|
4977
5504
|
}
|
|
4978
5505
|
if (isRegExp2(value)) {
|
|
4979
5506
|
base = " " + RegExp.prototype.toString.call(value);
|
|
@@ -5099,9 +5626,9 @@ function _extend2(origin, add) {
|
|
|
5099
5626
|
return origin;
|
|
5100
5627
|
const clonedAdd = { ...add };
|
|
5101
5628
|
const keys = Object.keys(add);
|
|
5102
|
-
let
|
|
5103
|
-
while (
|
|
5104
|
-
typedOrigin[keys[
|
|
5629
|
+
let i2 = keys.length;
|
|
5630
|
+
while (i2--) {
|
|
5631
|
+
typedOrigin[keys[i2]] = clonedAdd[keys[i2]];
|
|
5105
5632
|
}
|
|
5106
5633
|
return typedOrigin;
|
|
5107
5634
|
}
|
|
@@ -5114,7 +5641,7 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5114
5641
|
_extend2(ctx, inspectOptions);
|
|
5115
5642
|
}
|
|
5116
5643
|
const first = args[0];
|
|
5117
|
-
let
|
|
5644
|
+
let a2 = 0;
|
|
5118
5645
|
let str = "";
|
|
5119
5646
|
let join = "";
|
|
5120
5647
|
if (typeof first === "string") {
|
|
@@ -5123,13 +5650,13 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5123
5650
|
}
|
|
5124
5651
|
let tempStr;
|
|
5125
5652
|
let lastPos = 0;
|
|
5126
|
-
for (let
|
|
5127
|
-
if (first.charCodeAt(
|
|
5128
|
-
const nextChar = first.charCodeAt(++
|
|
5129
|
-
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) {
|
|
5130
5657
|
switch (nextChar) {
|
|
5131
5658
|
case 115: {
|
|
5132
|
-
const tempArg = args[++
|
|
5659
|
+
const tempArg = args[++a2];
|
|
5133
5660
|
if (typeof tempArg === "number") {
|
|
5134
5661
|
tempStr = formatPrimitive2(ctx, tempArg);
|
|
5135
5662
|
} else if (typeof tempArg === "bigint") {
|
|
@@ -5147,10 +5674,10 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5147
5674
|
break;
|
|
5148
5675
|
}
|
|
5149
5676
|
case 106:
|
|
5150
|
-
tempStr = jsonStringifyRecursive2(args[++
|
|
5677
|
+
tempStr = jsonStringifyRecursive2(args[++a2]);
|
|
5151
5678
|
break;
|
|
5152
5679
|
case 100: {
|
|
5153
|
-
const tempNum = args[++
|
|
5680
|
+
const tempNum = args[++a2];
|
|
5154
5681
|
if (typeof tempNum === "bigint") {
|
|
5155
5682
|
tempStr = formatPrimitive2(ctx, tempNum);
|
|
5156
5683
|
} else if (typeof tempNum === "symbol") {
|
|
@@ -5161,10 +5688,10 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5161
5688
|
break;
|
|
5162
5689
|
}
|
|
5163
5690
|
case 79:
|
|
5164
|
-
tempStr = inspect2(args[++
|
|
5691
|
+
tempStr = inspect2(args[++a2], inspectOptions);
|
|
5165
5692
|
break;
|
|
5166
5693
|
case 111:
|
|
5167
|
-
tempStr = inspect2(args[++
|
|
5694
|
+
tempStr = inspect2(args[++a2], {
|
|
5168
5695
|
...inspectOptions,
|
|
5169
5696
|
showHidden: true,
|
|
5170
5697
|
showProxy: true,
|
|
@@ -5172,7 +5699,7 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5172
5699
|
});
|
|
5173
5700
|
break;
|
|
5174
5701
|
case 105: {
|
|
5175
|
-
const tempInteger = args[++
|
|
5702
|
+
const tempInteger = args[++a2];
|
|
5176
5703
|
if (typeof tempInteger === "bigint") {
|
|
5177
5704
|
tempStr = formatPrimitive2(ctx, tempInteger);
|
|
5178
5705
|
} else if (typeof tempInteger === "symbol") {
|
|
@@ -5183,7 +5710,7 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5183
5710
|
break;
|
|
5184
5711
|
}
|
|
5185
5712
|
case 102: {
|
|
5186
|
-
const tempFloat = args[++
|
|
5713
|
+
const tempFloat = args[++a2];
|
|
5187
5714
|
if (typeof tempFloat === "symbol") {
|
|
5188
5715
|
tempStr = "NaN";
|
|
5189
5716
|
} else {
|
|
@@ -5192,41 +5719,41 @@ function formatWithOptions2(inspectOptions, ...args) {
|
|
|
5192
5719
|
break;
|
|
5193
5720
|
}
|
|
5194
5721
|
case 99:
|
|
5195
|
-
|
|
5722
|
+
a2 += 1;
|
|
5196
5723
|
tempStr = "";
|
|
5197
5724
|
break;
|
|
5198
5725
|
case 37:
|
|
5199
|
-
str += first.slice(lastPos,
|
|
5200
|
-
lastPos =
|
|
5726
|
+
str += first.slice(lastPos, i2);
|
|
5727
|
+
lastPos = i2 + 1;
|
|
5201
5728
|
continue;
|
|
5202
5729
|
default:
|
|
5203
5730
|
continue;
|
|
5204
5731
|
}
|
|
5205
|
-
if (lastPos !==
|
|
5206
|
-
str += first.slice(lastPos,
|
|
5732
|
+
if (lastPos !== i2 - 1) {
|
|
5733
|
+
str += first.slice(lastPos, i2 - 1);
|
|
5207
5734
|
}
|
|
5208
5735
|
str += tempStr;
|
|
5209
|
-
lastPos =
|
|
5736
|
+
lastPos = i2 + 1;
|
|
5210
5737
|
} else if (nextChar === 37) {
|
|
5211
|
-
str += first.slice(lastPos,
|
|
5212
|
-
lastPos =
|
|
5738
|
+
str += first.slice(lastPos, i2);
|
|
5739
|
+
lastPos = i2 + 1;
|
|
5213
5740
|
}
|
|
5214
5741
|
}
|
|
5215
5742
|
}
|
|
5216
5743
|
if (lastPos !== 0) {
|
|
5217
|
-
|
|
5744
|
+
a2++;
|
|
5218
5745
|
join = " ";
|
|
5219
5746
|
if (lastPos < first.length) {
|
|
5220
5747
|
str += first.slice(lastPos);
|
|
5221
5748
|
}
|
|
5222
5749
|
}
|
|
5223
5750
|
}
|
|
5224
|
-
while (
|
|
5225
|
-
const value = args[
|
|
5751
|
+
while (a2 < args.length) {
|
|
5752
|
+
const value = args[a2];
|
|
5226
5753
|
str += join;
|
|
5227
5754
|
str += typeof value !== "string" ? inspect2(value, inspectOptions) : value;
|
|
5228
5755
|
join = " ";
|
|
5229
|
-
|
|
5756
|
+
a2++;
|
|
5230
5757
|
}
|
|
5231
5758
|
return str;
|
|
5232
5759
|
}
|
|
@@ -5847,908 +6374,470 @@ error stack:
|
|
|
5847
6374
|
},
|
|
5848
6375
|
metaProperty: settings?.metaProperty ?? "_meta",
|
|
5849
6376
|
maskPlaceholder: settings?.maskPlaceholder ?? "[***]",
|
|
5850
|
-
maskValuesOfKeys: settings?.maskValuesOfKeys ?? ["password"],
|
|
5851
|
-
maskValuesOfKeysCaseInsensitive: settings?.maskValuesOfKeysCaseInsensitive ?? false,
|
|
5852
|
-
maskValuesRegEx: settings?.maskValuesRegEx,
|
|
5853
|
-
prefix: [...settings?.prefix ?? []],
|
|
5854
|
-
attachedTransports: [...settings?.attachedTransports ?? []],
|
|
5855
|
-
overwrite: {
|
|
5856
|
-
mask: settings?.overwrite?.mask,
|
|
5857
|
-
toLogObj: settings?.overwrite?.toLogObj,
|
|
5858
|
-
addMeta: settings?.overwrite?.addMeta,
|
|
5859
|
-
addPlaceholders: settings?.overwrite?.addPlaceholders,
|
|
5860
|
-
formatMeta: settings?.overwrite?.formatMeta,
|
|
5861
|
-
formatLogObj: settings?.overwrite?.formatLogObj,
|
|
5862
|
-
transportFormatted: settings?.overwrite?.transportFormatted,
|
|
5863
|
-
transportJSON: settings?.overwrite?.transportJSON
|
|
5864
|
-
}
|
|
5865
|
-
};
|
|
5866
|
-
this.captureStackForMeta = this._shouldCaptureStack();
|
|
5867
|
-
}
|
|
5868
|
-
log(logLevelId, logLevelName, ...args) {
|
|
5869
|
-
if (logLevelId < this.settings.minLevel) {
|
|
5870
|
-
return;
|
|
5871
|
-
}
|
|
5872
|
-
const resolvedArgs = this._resolveLogArguments(args);
|
|
5873
|
-
const logArgs = [...this.settings.prefix, ...resolvedArgs];
|
|
5874
|
-
const maskedArgs = this.settings.overwrite?.mask != null ? this.settings.overwrite?.mask(logArgs) : this.settings.maskValuesOfKeys != null && this.settings.maskValuesOfKeys.length > 0 ? this._mask(logArgs) : logArgs;
|
|
5875
|
-
const thisLogObj = this.logObj != null ? this._recursiveCloneAndExecuteFunctions(this.logObj) : undefined;
|
|
5876
|
-
const logObj = this.settings.overwrite?.toLogObj != null ? this.settings.overwrite?.toLogObj(maskedArgs, thisLogObj) : this._toLogObj(maskedArgs, thisLogObj);
|
|
5877
|
-
const logObjWithMeta = this.settings.overwrite?.addMeta != null ? this.settings.overwrite?.addMeta(logObj, logLevelId, logLevelName) : this._addMetaToLogObj(logObj, logLevelId, logLevelName);
|
|
5878
|
-
const logMeta = logObjWithMeta?.[this.settings.metaProperty];
|
|
5879
|
-
let logMetaMarkup;
|
|
5880
|
-
let logArgsAndErrorsMarkup = undefined;
|
|
5881
|
-
if (this.settings.overwrite?.formatMeta != null) {
|
|
5882
|
-
logMetaMarkup = this.settings.overwrite?.formatMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
5883
|
-
}
|
|
5884
|
-
if (this.settings.overwrite?.formatLogObj != null) {
|
|
5885
|
-
logArgsAndErrorsMarkup = this.settings.overwrite?.formatLogObj(maskedArgs, this.settings);
|
|
5886
|
-
}
|
|
5887
|
-
if (this.settings.type === "pretty") {
|
|
5888
|
-
logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
5889
|
-
logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? runtime2.prettyFormatLogObj(maskedArgs, this.settings);
|
|
5890
|
-
}
|
|
5891
|
-
if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
|
|
5892
|
-
if (this.settings.overwrite?.transportFormatted != null) {
|
|
5893
|
-
const transport = this.settings.overwrite.transportFormatted;
|
|
5894
|
-
const declaredParams = transport.length;
|
|
5895
|
-
if (declaredParams < 4) {
|
|
5896
|
-
transport(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors);
|
|
5897
|
-
} else if (declaredParams === 4) {
|
|
5898
|
-
transport(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, logMeta);
|
|
5899
|
-
} else {
|
|
5900
|
-
transport(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, logMeta, this.settings);
|
|
5901
|
-
}
|
|
5902
|
-
} else {
|
|
5903
|
-
runtime2.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, logMeta, this.settings);
|
|
5904
|
-
}
|
|
5905
|
-
} else {
|
|
5906
|
-
if (this.settings.overwrite?.transportJSON != null) {
|
|
5907
|
-
this.settings.overwrite.transportJSON(logObjWithMeta);
|
|
5908
|
-
} else if (this.settings.type !== "hidden") {
|
|
5909
|
-
runtime2.transportJSON(logObjWithMeta);
|
|
5910
|
-
}
|
|
5911
|
-
}
|
|
5912
|
-
if (this.settings.attachedTransports != null && this.settings.attachedTransports.length > 0) {
|
|
5913
|
-
this.settings.attachedTransports.forEach((transportLogger) => {
|
|
5914
|
-
transportLogger(logObjWithMeta);
|
|
5915
|
-
});
|
|
5916
|
-
}
|
|
5917
|
-
return logObjWithMeta;
|
|
5918
|
-
}
|
|
5919
|
-
attachTransport(transportLogger) {
|
|
5920
|
-
this.settings.attachedTransports.push(transportLogger);
|
|
5921
|
-
}
|
|
5922
|
-
getSubLogger(settings, logObj) {
|
|
5923
|
-
const subLoggerSettings = {
|
|
5924
|
-
...this.settings,
|
|
5925
|
-
...settings,
|
|
5926
|
-
parentNames: this.settings?.parentNames != null && this.settings?.name != null ? [...this.settings.parentNames, this.settings.name] : this.settings?.name != null ? [this.settings.name] : undefined,
|
|
5927
|
-
prefix: [...this.settings.prefix, ...settings?.prefix ?? []]
|
|
5928
|
-
};
|
|
5929
|
-
const subLogger = new this.constructor(subLoggerSettings, logObj ?? this.logObj, this.stackDepthLevel);
|
|
5930
|
-
return subLogger;
|
|
5931
|
-
}
|
|
5932
|
-
_mask(args) {
|
|
5933
|
-
const maskKeys = this._getMaskKeys();
|
|
5934
|
-
return args?.map((arg) => {
|
|
5935
|
-
return this._recursiveCloneAndMaskValuesOfKeys(arg, maskKeys);
|
|
5936
|
-
});
|
|
5937
|
-
}
|
|
5938
|
-
_getMaskKeys() {
|
|
5939
|
-
const maskKeys = this.settings.maskValuesOfKeys ?? [];
|
|
5940
|
-
const signature = maskKeys.map(String).join("|");
|
|
5941
|
-
if (this.settings.maskValuesOfKeysCaseInsensitive === true) {
|
|
5942
|
-
if (this.maskKeysCache?.source === maskKeys && this.maskKeysCache.caseInsensitive === true && this.maskKeysCache.signature === signature) {
|
|
5943
|
-
return this.maskKeysCache.normalized;
|
|
5944
|
-
}
|
|
5945
|
-
const normalized = maskKeys.map((key) => typeof key === "string" ? key.toLowerCase() : String(key).toLowerCase());
|
|
5946
|
-
this.maskKeysCache = {
|
|
5947
|
-
source: maskKeys,
|
|
5948
|
-
caseInsensitive: true,
|
|
5949
|
-
normalized,
|
|
5950
|
-
signature
|
|
5951
|
-
};
|
|
5952
|
-
return normalized;
|
|
5953
|
-
}
|
|
5954
|
-
this.maskKeysCache = {
|
|
5955
|
-
source: maskKeys,
|
|
5956
|
-
caseInsensitive: false,
|
|
5957
|
-
normalized: maskKeys,
|
|
5958
|
-
signature
|
|
5959
|
-
};
|
|
5960
|
-
return maskKeys;
|
|
5961
|
-
}
|
|
5962
|
-
_resolveLogArguments(args) {
|
|
5963
|
-
if (args.length === 1 && typeof args[0] === "function") {
|
|
5964
|
-
const candidate = args[0];
|
|
5965
|
-
if (candidate.length === 0) {
|
|
5966
|
-
const result = candidate();
|
|
5967
|
-
return Array.isArray(result) ? result : [result];
|
|
5968
|
-
}
|
|
5969
|
-
}
|
|
5970
|
-
return args;
|
|
5971
|
-
}
|
|
5972
|
-
_recursiveCloneAndMaskValuesOfKeys(source, keys, seen = []) {
|
|
5973
|
-
if (seen.includes(source)) {
|
|
5974
|
-
return { ...source };
|
|
5975
|
-
}
|
|
5976
|
-
if (typeof source === "object" && source !== null) {
|
|
5977
|
-
seen.push(source);
|
|
5978
|
-
}
|
|
5979
|
-
if (runtime2.isError(source) || runtime2.isBuffer(source)) {
|
|
5980
|
-
return source;
|
|
5981
|
-
} else if (source instanceof Map) {
|
|
5982
|
-
return new Map(source);
|
|
5983
|
-
} else if (source instanceof Set) {
|
|
5984
|
-
return new Set(source);
|
|
5985
|
-
} else if (Array.isArray(source)) {
|
|
5986
|
-
return source.map((item) => this._recursiveCloneAndMaskValuesOfKeys(item, keys, seen));
|
|
5987
|
-
} else if (source instanceof Date) {
|
|
5988
|
-
return new Date(source.getTime());
|
|
5989
|
-
} else if (source instanceof URL) {
|
|
5990
|
-
return urlToObject2(source);
|
|
5991
|
-
} else if (source !== null && typeof source === "object") {
|
|
5992
|
-
const baseObject = runtime2.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
|
|
5993
|
-
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
5994
|
-
const lookupKey = this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : typeof prop === "string" ? prop.toLowerCase() : String(prop).toLowerCase();
|
|
5995
|
-
o[prop] = keys.includes(lookupKey) ? this.settings.maskPlaceholder : (() => {
|
|
5996
|
-
try {
|
|
5997
|
-
return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
|
|
5998
|
-
} catch {
|
|
5999
|
-
return null;
|
|
6000
|
-
}
|
|
6001
|
-
})();
|
|
6002
|
-
return o;
|
|
6003
|
-
}, baseObject);
|
|
6004
|
-
} else {
|
|
6005
|
-
if (typeof source === "string") {
|
|
6006
|
-
let modifiedSource = source;
|
|
6007
|
-
for (const regEx of this.settings?.maskValuesRegEx || []) {
|
|
6008
|
-
modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
|
|
6009
|
-
}
|
|
6010
|
-
return modifiedSource;
|
|
6011
|
-
}
|
|
6012
|
-
return source;
|
|
6013
|
-
}
|
|
6014
|
-
}
|
|
6015
|
-
_recursiveCloneAndExecuteFunctions(source, seen = []) {
|
|
6016
|
-
if (this.isObjectOrArray(source) && seen.includes(source)) {
|
|
6017
|
-
return this.shallowCopy(source);
|
|
6018
|
-
}
|
|
6019
|
-
if (this.isObjectOrArray(source)) {
|
|
6020
|
-
seen.push(source);
|
|
6021
|
-
}
|
|
6022
|
-
if (Array.isArray(source)) {
|
|
6023
|
-
return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
|
|
6024
|
-
} else if (source instanceof Date) {
|
|
6025
|
-
return new Date(source.getTime());
|
|
6026
|
-
} else if (this.isObject(source)) {
|
|
6027
|
-
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
6028
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, prop);
|
|
6029
|
-
if (descriptor) {
|
|
6030
|
-
Object.defineProperty(o, prop, descriptor);
|
|
6031
|
-
const value = source[prop];
|
|
6032
|
-
o[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
|
|
6033
|
-
}
|
|
6034
|
-
return o;
|
|
6035
|
-
}, Object.create(Object.getPrototypeOf(source)));
|
|
6036
|
-
} else {
|
|
6037
|
-
return source;
|
|
6038
|
-
}
|
|
6039
|
-
}
|
|
6040
|
-
isObjectOrArray(value) {
|
|
6041
|
-
return typeof value === "object" && value !== null;
|
|
6042
|
-
}
|
|
6043
|
-
isObject(value) {
|
|
6044
|
-
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
|
6045
|
-
}
|
|
6046
|
-
shallowCopy(source) {
|
|
6047
|
-
if (Array.isArray(source)) {
|
|
6048
|
-
return [...source];
|
|
6049
|
-
} else {
|
|
6050
|
-
return { ...source };
|
|
6051
|
-
}
|
|
6052
|
-
}
|
|
6053
|
-
_toLogObj(args, clonedLogObj = {}) {
|
|
6054
|
-
args = args?.map((arg) => runtime2.isError(arg) ? this._toErrorObject(arg) : arg);
|
|
6055
|
-
if (this.settings.argumentsArrayName == null) {
|
|
6056
|
-
if (args.length === 1 && !Array.isArray(args[0]) && runtime2.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
|
|
6057
|
-
clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
|
|
6058
|
-
} else {
|
|
6059
|
-
clonedLogObj = { ...clonedLogObj, ...args };
|
|
6060
|
-
}
|
|
6061
|
-
} else {
|
|
6062
|
-
clonedLogObj = {
|
|
6063
|
-
...clonedLogObj,
|
|
6064
|
-
[this.settings.argumentsArrayName]: args
|
|
6065
|
-
};
|
|
6066
|
-
}
|
|
6067
|
-
return clonedLogObj;
|
|
6068
|
-
}
|
|
6069
|
-
_cloneError(error) {
|
|
6070
|
-
const cloned = new error.constructor;
|
|
6071
|
-
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
6072
|
-
cloned[key] = error[key];
|
|
6073
|
-
});
|
|
6074
|
-
return cloned;
|
|
6075
|
-
}
|
|
6076
|
-
_toErrorObject(error, depth = 0, seen = new Set) {
|
|
6077
|
-
if (!seen.has(error)) {
|
|
6078
|
-
seen.add(error);
|
|
6079
|
-
}
|
|
6080
|
-
const errorObject = {
|
|
6081
|
-
nativeError: error,
|
|
6082
|
-
name: error.name ?? "Error",
|
|
6083
|
-
message: error.message,
|
|
6084
|
-
stack: runtime2.getErrorTrace(error)
|
|
6085
|
-
};
|
|
6086
|
-
if (depth >= this.maxErrorCauseDepth) {
|
|
6087
|
-
return errorObject;
|
|
6088
|
-
}
|
|
6089
|
-
const causeValue = error.cause;
|
|
6090
|
-
if (causeValue != null) {
|
|
6091
|
-
const normalizedCause = toError2(causeValue);
|
|
6092
|
-
if (!seen.has(normalizedCause)) {
|
|
6093
|
-
errorObject.cause = this._toErrorObject(normalizedCause, depth + 1, seen);
|
|
6377
|
+
maskValuesOfKeys: settings?.maskValuesOfKeys ?? ["password"],
|
|
6378
|
+
maskValuesOfKeysCaseInsensitive: settings?.maskValuesOfKeysCaseInsensitive ?? false,
|
|
6379
|
+
maskValuesRegEx: settings?.maskValuesRegEx,
|
|
6380
|
+
prefix: [...settings?.prefix ?? []],
|
|
6381
|
+
attachedTransports: [...settings?.attachedTransports ?? []],
|
|
6382
|
+
overwrite: {
|
|
6383
|
+
mask: settings?.overwrite?.mask,
|
|
6384
|
+
toLogObj: settings?.overwrite?.toLogObj,
|
|
6385
|
+
addMeta: settings?.overwrite?.addMeta,
|
|
6386
|
+
addPlaceholders: settings?.overwrite?.addPlaceholders,
|
|
6387
|
+
formatMeta: settings?.overwrite?.formatMeta,
|
|
6388
|
+
formatLogObj: settings?.overwrite?.formatLogObj,
|
|
6389
|
+
transportFormatted: settings?.overwrite?.transportFormatted,
|
|
6390
|
+
transportJSON: settings?.overwrite?.transportJSON
|
|
6094
6391
|
}
|
|
6095
|
-
}
|
|
6096
|
-
return errorObject;
|
|
6097
|
-
}
|
|
6098
|
-
_addMetaToLogObj(logObj, logLevelId, logLevelName) {
|
|
6099
|
-
return {
|
|
6100
|
-
...logObj,
|
|
6101
|
-
[this.settings.metaProperty]: runtime2.getMeta(logLevelId, logLevelName, this.stackDepthLevel, !this.captureStackForMeta, this.settings.name, this.settings.parentNames)
|
|
6102
6392
|
};
|
|
6393
|
+
this.captureStackForMeta = this._shouldCaptureStack();
|
|
6103
6394
|
}
|
|
6104
|
-
|
|
6105
|
-
if (this.settings.
|
|
6106
|
-
return
|
|
6395
|
+
log(logLevelId, logLevelName, ...args) {
|
|
6396
|
+
if (logLevelId < this.settings.minLevel) {
|
|
6397
|
+
return;
|
|
6107
6398
|
}
|
|
6108
|
-
|
|
6109
|
-
|
|
6399
|
+
const resolvedArgs = this._resolveLogArguments(args);
|
|
6400
|
+
const logArgs = [...this.settings.prefix, ...resolvedArgs];
|
|
6401
|
+
const maskedArgs = this.settings.overwrite?.mask != null ? this.settings.overwrite?.mask(logArgs) : this.settings.maskValuesOfKeys != null && this.settings.maskValuesOfKeys.length > 0 ? this._mask(logArgs) : logArgs;
|
|
6402
|
+
const thisLogObj = this.logObj != null ? this._recursiveCloneAndExecuteFunctions(this.logObj) : undefined;
|
|
6403
|
+
const logObj = this.settings.overwrite?.toLogObj != null ? this.settings.overwrite?.toLogObj(maskedArgs, thisLogObj) : this._toLogObj(maskedArgs, thisLogObj);
|
|
6404
|
+
const logObjWithMeta = this.settings.overwrite?.addMeta != null ? this.settings.overwrite?.addMeta(logObj, logLevelId, logLevelName) : this._addMetaToLogObj(logObj, logLevelId, logLevelName);
|
|
6405
|
+
const logMeta = logObjWithMeta?.[this.settings.metaProperty];
|
|
6406
|
+
let logMetaMarkup;
|
|
6407
|
+
let logArgsAndErrorsMarkup = undefined;
|
|
6408
|
+
if (this.settings.overwrite?.formatMeta != null) {
|
|
6409
|
+
logMetaMarkup = this.settings.overwrite?.formatMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
6110
6410
|
}
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
if (stackPlaceholders.test(template)) {
|
|
6114
|
-
return true;
|
|
6411
|
+
if (this.settings.overwrite?.formatLogObj != null) {
|
|
6412
|
+
logArgsAndErrorsMarkup = this.settings.overwrite?.formatLogObj(maskedArgs, this.settings);
|
|
6115
6413
|
}
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
return buildPrettyMeta2(this.settings, logObjMeta).text;
|
|
6120
|
-
}
|
|
6121
|
-
}
|
|
6122
|
-
|
|
6123
|
-
class Logger2 extends BaseLogger2 {
|
|
6124
|
-
constructor(settings, logObj) {
|
|
6125
|
-
const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
6126
|
-
const normalizedSettings = { ...settings ?? {} };
|
|
6127
|
-
if (isBrowser) {
|
|
6128
|
-
normalizedSettings.stylePrettyLogs = settings?.stylePrettyLogs ?? true;
|
|
6414
|
+
if (this.settings.type === "pretty") {
|
|
6415
|
+
logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
6416
|
+
logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? runtime2.prettyFormatLogObj(maskedArgs, this.settings);
|
|
6129
6417
|
}
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
trace(...args) {
|
|
6139
|
-
return super.log(1, "TRACE", ...args);
|
|
6140
|
-
}
|
|
6141
|
-
debug(...args) {
|
|
6142
|
-
return super.log(2, "DEBUG", ...args);
|
|
6143
|
-
}
|
|
6144
|
-
info(...args) {
|
|
6145
|
-
return super.log(3, "INFO", ...args);
|
|
6146
|
-
}
|
|
6147
|
-
warn(...args) {
|
|
6148
|
-
return super.log(4, "WARN", ...args);
|
|
6149
|
-
}
|
|
6150
|
-
error(...args) {
|
|
6151
|
-
return super.log(5, "ERROR", ...args);
|
|
6152
|
-
}
|
|
6153
|
-
fatal(...args) {
|
|
6154
|
-
return super.log(6, "FATAL", ...args);
|
|
6155
|
-
}
|
|
6156
|
-
getSubLogger(settings, logObj) {
|
|
6157
|
-
return super.getSubLogger(settings, logObj);
|
|
6158
|
-
}
|
|
6159
|
-
}
|
|
6160
|
-
var logger_NiceError2 = new Logger2({
|
|
6161
|
-
name: "NiceErrorLogger"
|
|
6162
|
-
});
|
|
6163
|
-
var logger_NiceError_testing2 = logger_NiceError2.getSubLogger({
|
|
6164
|
-
name: "NiceErrorTestingLogger"
|
|
6165
|
-
});
|
|
6166
|
-
function extractPathFromIssue(issue) {
|
|
6167
|
-
let pathString = "";
|
|
6168
|
-
for (const segment of issue) {
|
|
6169
|
-
if (typeof segment === "object") {
|
|
6170
|
-
if (segment.key != null) {
|
|
6171
|
-
if (typeof segment.key === "number") {
|
|
6172
|
-
pathString += `[${String(segment.key)}]`;
|
|
6173
|
-
} else if (typeof segment.key === "symbol") {
|
|
6174
|
-
pathString += `[SYMBOL:${String(segment.key)}]`;
|
|
6418
|
+
if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
|
|
6419
|
+
if (this.settings.overwrite?.transportFormatted != null) {
|
|
6420
|
+
const transport = this.settings.overwrite.transportFormatted;
|
|
6421
|
+
const declaredParams = transport.length;
|
|
6422
|
+
if (declaredParams < 4) {
|
|
6423
|
+
transport(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors);
|
|
6424
|
+
} else if (declaredParams === 4) {
|
|
6425
|
+
transport(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, logMeta);
|
|
6175
6426
|
} else {
|
|
6176
|
-
|
|
6427
|
+
transport(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, logMeta, this.settings);
|
|
6177
6428
|
}
|
|
6429
|
+
} else {
|
|
6430
|
+
runtime2.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, logMeta, this.settings);
|
|
6178
6431
|
}
|
|
6179
6432
|
} else {
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
}
|
|
6185
|
-
var extractMessageFromStandardSchema = (failureResult) => {
|
|
6186
|
-
let message = `Data validation failed:
|
|
6187
|
-
`;
|
|
6188
|
-
let issueCount = 0;
|
|
6189
|
-
for (const issue of failureResult.issues) {
|
|
6190
|
-
issueCount++;
|
|
6191
|
-
if (issue.path == null || issue.path.length === 0) {
|
|
6192
|
-
message += ` (issue ${issueCount}) ${issue.message}
|
|
6193
|
-
`;
|
|
6194
|
-
} else {
|
|
6195
|
-
message += ` (issue ${issueCount}) [${extractPathFromIssue(issue.path)}]: ${issue.message}
|
|
6196
|
-
`;
|
|
6197
|
-
}
|
|
6198
|
-
}
|
|
6199
|
-
return message;
|
|
6200
|
-
};
|
|
6201
|
-
var EValidator;
|
|
6202
|
-
((EValidator2) => {
|
|
6203
|
-
EValidator2["standard_schema"] = "standard_schema";
|
|
6204
|
-
})(EValidator ||= {});
|
|
6205
|
-
var err_validation = err_nice2.createChildDomain({
|
|
6206
|
-
domain: "err_validation",
|
|
6207
|
-
defaultHttpStatusCode: StatusCodes2.BAD_REQUEST,
|
|
6208
|
-
schema: {
|
|
6209
|
-
["standard_schema"]: err2({
|
|
6210
|
-
message: ({ issues }) => extractMessageFromStandardSchema({ issues })
|
|
6211
|
-
})
|
|
6212
|
-
}
|
|
6213
|
-
});
|
|
6214
|
-
|
|
6215
|
-
// src/ActionDefinition/Schema/ActionSchema.ts
|
|
6216
|
-
class ActionSchema {
|
|
6217
|
-
_errorDeclarations = [];
|
|
6218
|
-
inputOptions;
|
|
6219
|
-
outputOptions;
|
|
6220
|
-
get inputSchema() {
|
|
6221
|
-
return this.inputOptions?.schema;
|
|
6222
|
-
}
|
|
6223
|
-
get outputSchema() {
|
|
6224
|
-
return this.outputOptions?.schema;
|
|
6225
|
-
}
|
|
6226
|
-
input(options, serialize, deserialize) {
|
|
6227
|
-
if (serialize != null && deserialize != null) {
|
|
6228
|
-
this.inputOptions = { ...options, serialization: { serialize, deserialize } };
|
|
6229
|
-
} else {
|
|
6230
|
-
this.inputOptions = options;
|
|
6433
|
+
if (this.settings.overwrite?.transportJSON != null) {
|
|
6434
|
+
this.settings.overwrite.transportJSON(logObjWithMeta);
|
|
6435
|
+
} else if (this.settings.type !== "hidden") {
|
|
6436
|
+
runtime2.transportJSON(logObjWithMeta);
|
|
6437
|
+
}
|
|
6231
6438
|
}
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
this.outputOptions = { ...options, serialization: { serialize, deserialize } };
|
|
6237
|
-
} else {
|
|
6238
|
-
this.outputOptions = options;
|
|
6439
|
+
if (this.settings.attachedTransports != null && this.settings.attachedTransports.length > 0) {
|
|
6440
|
+
this.settings.attachedTransports.forEach((transportLogger) => {
|
|
6441
|
+
transportLogger(logObjWithMeta);
|
|
6442
|
+
});
|
|
6239
6443
|
}
|
|
6240
|
-
return
|
|
6444
|
+
return logObjWithMeta;
|
|
6241
6445
|
}
|
|
6242
|
-
|
|
6243
|
-
this.
|
|
6244
|
-
return this;
|
|
6446
|
+
attachTransport(transportLogger) {
|
|
6447
|
+
this.settings.attachedTransports.push(transportLogger);
|
|
6245
6448
|
}
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6449
|
+
getSubLogger(settings, logObj) {
|
|
6450
|
+
const subLoggerSettings = {
|
|
6451
|
+
...this.settings,
|
|
6452
|
+
...settings,
|
|
6453
|
+
parentNames: this.settings?.parentNames != null && this.settings?.name != null ? [...this.settings.parentNames, this.settings.name] : this.settings?.name != null ? [this.settings.name] : undefined,
|
|
6454
|
+
prefix: [...this.settings.prefix, ...settings?.prefix ?? []]
|
|
6455
|
+
};
|
|
6456
|
+
const subLogger = new this.constructor(subLoggerSettings, logObj ?? this.logObj, this.stackDepthLevel);
|
|
6457
|
+
return subLogger;
|
|
6251
6458
|
}
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6459
|
+
_mask(args) {
|
|
6460
|
+
const maskKeys = this._getMaskKeys();
|
|
6461
|
+
return args?.map((arg) => {
|
|
6462
|
+
return this._recursiveCloneAndMaskValuesOfKeys(arg, maskKeys);
|
|
6463
|
+
});
|
|
6257
6464
|
}
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6465
|
+
_getMaskKeys() {
|
|
6466
|
+
const maskKeys = this.settings.maskValuesOfKeys ?? [];
|
|
6467
|
+
const signature = maskKeys.map(String).join("|");
|
|
6468
|
+
if (this.settings.maskValuesOfKeysCaseInsensitive === true) {
|
|
6469
|
+
if (this.maskKeysCache?.source === maskKeys && this.maskKeysCache.caseInsensitive === true && this.maskKeysCache.signature === signature) {
|
|
6470
|
+
return this.maskKeysCache.normalized;
|
|
6471
|
+
}
|
|
6472
|
+
const normalized = maskKeys.map((key) => typeof key === "string" ? key.toLowerCase() : String(key).toLowerCase());
|
|
6473
|
+
this.maskKeysCache = {
|
|
6474
|
+
source: maskKeys,
|
|
6475
|
+
caseInsensitive: true,
|
|
6476
|
+
normalized,
|
|
6477
|
+
signature
|
|
6478
|
+
};
|
|
6479
|
+
return normalized;
|
|
6268
6480
|
}
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6481
|
+
this.maskKeysCache = {
|
|
6482
|
+
source: maskKeys,
|
|
6483
|
+
caseInsensitive: false,
|
|
6484
|
+
normalized: maskKeys,
|
|
6485
|
+
signature
|
|
6486
|
+
};
|
|
6487
|
+
return maskKeys;
|
|
6488
|
+
}
|
|
6489
|
+
_resolveLogArguments(args) {
|
|
6490
|
+
if (args.length === 1 && typeof args[0] === "function") {
|
|
6491
|
+
const candidate = args[0];
|
|
6492
|
+
if (candidate.length === 0) {
|
|
6493
|
+
const result = candidate();
|
|
6494
|
+
return Array.isArray(result) ? result : [result];
|
|
6495
|
+
}
|
|
6275
6496
|
}
|
|
6276
|
-
return
|
|
6497
|
+
return args;
|
|
6277
6498
|
}
|
|
6278
|
-
|
|
6279
|
-
if (
|
|
6280
|
-
return
|
|
6499
|
+
_recursiveCloneAndMaskValuesOfKeys(source, keys, seen = []) {
|
|
6500
|
+
if (seen.includes(source)) {
|
|
6501
|
+
return { ...source };
|
|
6281
6502
|
}
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
throw err_nice_action.fromId("action_output_validation_promise" /* action_output_validation_promise */, {
|
|
6285
|
-
domain: meta.domain,
|
|
6286
|
-
actionId: meta.actionId
|
|
6287
|
-
});
|
|
6503
|
+
if (typeof source === "object" && source !== null) {
|
|
6504
|
+
seen.push(source);
|
|
6288
6505
|
}
|
|
6289
|
-
if (
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6506
|
+
if (runtime2.isError(source) || runtime2.isBuffer(source)) {
|
|
6507
|
+
return source;
|
|
6508
|
+
} else if (source instanceof Map) {
|
|
6509
|
+
return new Map(source);
|
|
6510
|
+
} else if (source instanceof Set) {
|
|
6511
|
+
return new Set(source);
|
|
6512
|
+
} else if (Array.isArray(source)) {
|
|
6513
|
+
return source.map((item) => this._recursiveCloneAndMaskValuesOfKeys(item, keys, seen));
|
|
6514
|
+
} else if (source instanceof Date) {
|
|
6515
|
+
return new Date(source.getTime());
|
|
6516
|
+
} else if (source instanceof URL) {
|
|
6517
|
+
return urlToObject2(source);
|
|
6518
|
+
} else if (source !== null && typeof source === "object") {
|
|
6519
|
+
const baseObject = runtime2.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
|
|
6520
|
+
return Object.getOwnPropertyNames(source).reduce((o2, prop) => {
|
|
6521
|
+
const lookupKey = this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : typeof prop === "string" ? prop.toLowerCase() : String(prop).toLowerCase();
|
|
6522
|
+
o2[prop] = keys.includes(lookupKey) ? this.settings.maskPlaceholder : (() => {
|
|
6523
|
+
try {
|
|
6524
|
+
return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
|
|
6525
|
+
} catch {
|
|
6526
|
+
return null;
|
|
6527
|
+
}
|
|
6528
|
+
})();
|
|
6529
|
+
return o2;
|
|
6530
|
+
}, baseObject);
|
|
6531
|
+
} else {
|
|
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;
|
|
6295
6540
|
}
|
|
6296
|
-
return result.value;
|
|
6297
6541
|
}
|
|
6298
|
-
|
|
6299
|
-
if (this.
|
|
6300
|
-
return this.
|
|
6542
|
+
_recursiveCloneAndExecuteFunctions(source, seen = []) {
|
|
6543
|
+
if (this.isObjectOrArray(source) && seen.includes(source)) {
|
|
6544
|
+
return this.shallowCopy(source);
|
|
6301
6545
|
}
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
if (
|
|
6306
|
-
return this.
|
|
6546
|
+
if (this.isObjectOrArray(source)) {
|
|
6547
|
+
seen.push(source);
|
|
6548
|
+
}
|
|
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;
|
|
6307
6565
|
}
|
|
6308
|
-
return serialized;
|
|
6309
6566
|
}
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
return new ActionSchema;
|
|
6313
|
-
};
|
|
6314
|
-
// ../../node_modules/.bun/std-env@4.1.0/node_modules/std-env/dist/index.mjs
|
|
6315
|
-
var e = globalThis.process?.env || Object.create(null);
|
|
6316
|
-
var t = globalThis.process || { env: e };
|
|
6317
|
-
var n = t !== undefined && t.env && t.env.NODE_ENV || undefined;
|
|
6318
|
-
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/)]]];
|
|
6319
|
-
function i(t2, n2) {
|
|
6320
|
-
return () => {
|
|
6321
|
-
let r2 = e[t2];
|
|
6322
|
-
return r2 ? n2.test(r2) : false;
|
|
6323
|
-
};
|
|
6324
|
-
}
|
|
6325
|
-
function a() {
|
|
6326
|
-
let t2 = e.AI_AGENT;
|
|
6327
|
-
if (t2)
|
|
6328
|
-
return { name: t2.toLowerCase() };
|
|
6329
|
-
for (let [t3, n2] of r)
|
|
6330
|
-
for (let r2 of n2)
|
|
6331
|
-
if (typeof r2 == `string` ? e[r2] : r2())
|
|
6332
|
-
return { name: t3 };
|
|
6333
|
-
return {};
|
|
6334
|
-
}
|
|
6335
|
-
var o = a();
|
|
6336
|
-
var s = o.name;
|
|
6337
|
-
var c = !!o.name;
|
|
6338
|
-
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 }]];
|
|
6339
|
-
function u() {
|
|
6340
|
-
for (let t2 of l)
|
|
6341
|
-
if (e[t2[1] || t2[0]])
|
|
6342
|
-
return { name: t2[0].toLowerCase(), ...t2[2] };
|
|
6343
|
-
return e.SHELL === `/bin/jsh` && t.versions?.webcontainer ? { name: `stackblitz`, ci: false } : { name: ``, ci: false };
|
|
6344
|
-
}
|
|
6345
|
-
var d = u();
|
|
6346
|
-
var f = d.name;
|
|
6347
|
-
var p = t.platform || ``;
|
|
6348
|
-
var m = !!e.CI || d.ci !== false;
|
|
6349
|
-
var h = !!t.stdout?.isTTY;
|
|
6350
|
-
var _ = !!e.DEBUG;
|
|
6351
|
-
var v = n === `test` || !!e.TEST;
|
|
6352
|
-
var y = n === `production` || e.MODE === `production`;
|
|
6353
|
-
var b = n === `dev` || n === `development` || e.MODE === `development`;
|
|
6354
|
-
var x = !!e.MINIMAL || m || v || !h;
|
|
6355
|
-
var S = /^win/i.test(p);
|
|
6356
|
-
var C = /^linux/i.test(p);
|
|
6357
|
-
var w = /^darwin/i.test(p);
|
|
6358
|
-
var T = !e.NO_COLOR && (!!e.FORCE_COLOR || (h || S) && e.TERM !== `dumb` || m);
|
|
6359
|
-
var E = (t.versions?.node || ``).replace(/^v/, ``) || null;
|
|
6360
|
-
var D = Number(E?.split(`.`)[0]) || null;
|
|
6361
|
-
var O = !!t?.versions?.node;
|
|
6362
|
-
var k = `Bun` in globalThis;
|
|
6363
|
-
var A = `Deno` in globalThis;
|
|
6364
|
-
var j = `fastly` in globalThis;
|
|
6365
|
-
var M = `Netlify` in globalThis;
|
|
6366
|
-
var N = `EdgeRuntime` in globalThis;
|
|
6367
|
-
var P = globalThis.navigator?.userAgent === `Cloudflare-Workers`;
|
|
6368
|
-
var F = [[M, `netlify`], [N, `edge-light`], [P, `workerd`], [j, `fastly`], [A, `deno`], [k, `bun`], [O, `node`]];
|
|
6369
|
-
function I() {
|
|
6370
|
-
let e2 = F.find((e3) => e3[0]);
|
|
6371
|
-
if (e2)
|
|
6372
|
-
return { name: e2[1] };
|
|
6373
|
-
}
|
|
6374
|
-
var L = I();
|
|
6375
|
-
var R = L?.name || ``;
|
|
6376
|
-
|
|
6377
|
-
// src/utils/getAssumedRuntimeEnvironment.ts
|
|
6378
|
-
var getAssumedRuntimeInfo = () => {
|
|
6379
|
-
return {
|
|
6380
|
-
assumed: true,
|
|
6381
|
-
runtimeName: R
|
|
6382
|
-
};
|
|
6383
|
-
};
|
|
6384
|
-
|
|
6385
|
-
// src/ActionRuntime/ActionDomainManager.ts
|
|
6386
|
-
class ActionDomainManager {
|
|
6387
|
-
_domains = new Map;
|
|
6388
|
-
addDomain(domain) {
|
|
6389
|
-
this._domains.set(domain.domain, domain);
|
|
6567
|
+
isObjectOrArray(value) {
|
|
6568
|
+
return typeof value === "object" && value !== null;
|
|
6390
6569
|
}
|
|
6391
|
-
|
|
6392
|
-
return
|
|
6570
|
+
isObject(value) {
|
|
6571
|
+
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
|
6393
6572
|
}
|
|
6394
|
-
|
|
6395
|
-
if (
|
|
6396
|
-
|
|
6573
|
+
shallowCopy(source) {
|
|
6574
|
+
if (Array.isArray(source)) {
|
|
6575
|
+
return [...source];
|
|
6576
|
+
} else {
|
|
6577
|
+
return { ...source };
|
|
6397
6578
|
}
|
|
6398
6579
|
}
|
|
6399
|
-
|
|
6400
|
-
this.
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
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
|
+
};
|
|
6404
6593
|
}
|
|
6405
|
-
return
|
|
6594
|
+
return clonedLogObj;
|
|
6406
6595
|
}
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
});
|
|
6414
|
-
}
|
|
6415
|
-
return domain;
|
|
6596
|
+
_cloneError(error) {
|
|
6597
|
+
const cloned = new error.constructor;
|
|
6598
|
+
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
6599
|
+
cloned[key] = error[key];
|
|
6600
|
+
});
|
|
6601
|
+
return cloned;
|
|
6416
6602
|
}
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6603
|
+
_toErrorObject(error, depth = 0, seen = new Set) {
|
|
6604
|
+
if (!seen.has(error)) {
|
|
6605
|
+
seen.add(error);
|
|
6606
|
+
}
|
|
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;
|
|
6615
|
+
}
|
|
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
|
+
}
|
|
6622
|
+
}
|
|
6623
|
+
return errorObject;
|
|
6420
6624
|
}
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
actionRouteData = new Map;
|
|
6427
|
-
_context;
|
|
6428
|
-
constructor(context) {
|
|
6429
|
-
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
|
+
};
|
|
6430
6630
|
}
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6631
|
+
_shouldCaptureStack() {
|
|
6632
|
+
if (this.settings.hideLogPositionForProduction) {
|
|
6633
|
+
return false;
|
|
6434
6634
|
}
|
|
6435
|
-
|
|
6436
|
-
|
|
6635
|
+
if (this.settings.type === "json") {
|
|
6636
|
+
return true;
|
|
6437
6637
|
}
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
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;
|
|
6442
6642
|
}
|
|
6643
|
+
return false;
|
|
6443
6644
|
}
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
const domKey = `dom[${action.domain}]id[_]`;
|
|
6447
|
-
return [
|
|
6448
|
-
...this.actionRouteData.get(idKey) ?? [],
|
|
6449
|
-
...this.actionRouteData.get(domKey) ?? []
|
|
6450
|
-
];
|
|
6451
|
-
}
|
|
6452
|
-
getRouteDataForAction(action) {
|
|
6453
|
-
return this.getRouteDataEntriesForAction(action)[0];
|
|
6645
|
+
_prettyFormatLogObjMeta(logObjMeta) {
|
|
6646
|
+
return buildPrettyMeta2(this.settings, logObjMeta).text;
|
|
6454
6647
|
}
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
if (this._context.contextType === "runtime_to_handler" /* runtime_to_handler */) {
|
|
6464
|
-
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
6465
|
-
domain: action.domain,
|
|
6466
|
-
actionId: action.id,
|
|
6467
|
-
specifiedClient: this._context.runtime.clientSpecifier
|
|
6468
|
-
});
|
|
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;
|
|
6469
6656
|
}
|
|
6470
|
-
|
|
6657
|
+
super(normalizedSettings, logObj, Number.NaN);
|
|
6471
6658
|
}
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
if (entries.length === 0) {
|
|
6475
|
-
this.throwNoHandlerForAction(action, context);
|
|
6476
|
-
}
|
|
6477
|
-
return entries;
|
|
6659
|
+
log(logLevelId, logLevelName, ...args) {
|
|
6660
|
+
return super.log(logLevelId, logLevelName, ...args);
|
|
6478
6661
|
}
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
if (!routeData) {
|
|
6482
|
-
this.throwNoHandlerForAction(action, context);
|
|
6483
|
-
}
|
|
6484
|
-
return routeData;
|
|
6662
|
+
silly(...args) {
|
|
6663
|
+
return super.log(0, "SILLY", ...args);
|
|
6485
6664
|
}
|
|
6486
|
-
|
|
6487
|
-
return
|
|
6665
|
+
trace(...args) {
|
|
6666
|
+
return super.log(1, "TRACE", ...args);
|
|
6488
6667
|
}
|
|
6489
|
-
|
|
6490
|
-
return
|
|
6668
|
+
debug(...args) {
|
|
6669
|
+
return super.log(2, "DEBUG", ...args);
|
|
6491
6670
|
}
|
|
6492
|
-
|
|
6493
|
-
return
|
|
6671
|
+
info(...args) {
|
|
6672
|
+
return super.log(3, "INFO", ...args);
|
|
6494
6673
|
}
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
this.actionRouteData.set(`dom[${domain.domain}]id[_]`, [routeData]);
|
|
6498
|
-
return this;
|
|
6674
|
+
warn(...args) {
|
|
6675
|
+
return super.log(4, "WARN", ...args);
|
|
6499
6676
|
}
|
|
6500
|
-
|
|
6501
|
-
return
|
|
6677
|
+
error(...args) {
|
|
6678
|
+
return super.log(5, "ERROR", ...args);
|
|
6502
6679
|
}
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
this.actionRouteData.set(`dom[${domain.domain}]id[${id}]`, [routeData]);
|
|
6506
|
-
return this;
|
|
6680
|
+
fatal(...args) {
|
|
6681
|
+
return super.log(6, "FATAL", ...args);
|
|
6507
6682
|
}
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
for (const id of ids) {
|
|
6511
|
-
this.forActionId(domain, id, routeData);
|
|
6512
|
-
}
|
|
6513
|
-
return this;
|
|
6683
|
+
getSubLogger(settings, logObj) {
|
|
6684
|
+
return super.getSubLogger(settings, logObj);
|
|
6514
6685
|
}
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
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
|
+
}
|
|
6521
6705
|
}
|
|
6706
|
+
} else {
|
|
6707
|
+
pathString += `.${String(segment)}`;
|
|
6522
6708
|
}
|
|
6523
|
-
return this;
|
|
6524
6709
|
}
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
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
|
+
}
|
|
6529
6725
|
}
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
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
|
+
})
|
|
6534
6739
|
}
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
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;
|
|
6539
6758
|
}
|
|
6540
6759
|
return this;
|
|
6541
6760
|
}
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
this._push(`dom[${domain.domain}]id[${id}]`, routeData);
|
|
6548
|
-
}
|
|
6761
|
+
output(options, serialize, deserialize) {
|
|
6762
|
+
if (serialize != null && deserialize != null) {
|
|
6763
|
+
this.outputOptions = { ...options, serialization: { serialize, deserialize } };
|
|
6764
|
+
} else {
|
|
6765
|
+
this.outputOptions = options;
|
|
6549
6766
|
}
|
|
6550
6767
|
return this;
|
|
6551
6768
|
}
|
|
6552
|
-
|
|
6553
|
-
this.
|
|
6769
|
+
throws(domain, ids) {
|
|
6770
|
+
this._errorDeclarations.push({ _domain: domain, _ids: ids });
|
|
6554
6771
|
return this;
|
|
6555
6772
|
}
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
existing.push(routeData);
|
|
6560
|
-
} else {
|
|
6561
|
-
this.actionRouteData.set(key, [routeData]);
|
|
6773
|
+
serializeInput(rawInput) {
|
|
6774
|
+
if (this.inputOptions?.serialization) {
|
|
6775
|
+
return this.inputOptions.serialization.serialize(rawInput);
|
|
6562
6776
|
}
|
|
6777
|
+
return rawInput;
|
|
6563
6778
|
}
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
class ActionRuntime {
|
|
6568
|
-
clientSpecifier;
|
|
6569
|
-
timeCreated;
|
|
6570
|
-
runtimeInfo = getAssumedRuntimeInfo();
|
|
6571
|
-
actionRouter;
|
|
6572
|
-
_pendingRunningActions = new Map;
|
|
6573
|
-
_registeredExternalHandlers = [];
|
|
6574
|
-
static getDefault() {
|
|
6575
|
-
return getDefaultActionRuntime();
|
|
6576
|
-
}
|
|
6577
|
-
constructor(client) {
|
|
6578
|
-
this.clientSpecifier = client.specifyIfUnset({
|
|
6579
|
-
insId: nanoid(14)
|
|
6580
|
-
});
|
|
6581
|
-
this.timeCreated = Date.now();
|
|
6582
|
-
this.actionRouter = new ActionRouter({
|
|
6583
|
-
contextType: "runtime_to_handler" /* runtime_to_handler */,
|
|
6584
|
-
runtime: this
|
|
6585
|
-
});
|
|
6586
|
-
}
|
|
6587
|
-
registerRunningAction(ra) {
|
|
6588
|
-
this._pendingRunningActions.set(ra.cuid, ra);
|
|
6589
|
-
ra.addUpdateListeners([
|
|
6590
|
-
(update) => {
|
|
6591
|
-
if (update.type === "finished" /* finished */) {
|
|
6592
|
-
this._pendingRunningActions.delete(ra.cuid);
|
|
6593
|
-
}
|
|
6594
|
-
}
|
|
6595
|
-
]);
|
|
6596
|
-
}
|
|
6597
|
-
resolveIncomingActionPayload(json) {
|
|
6598
|
-
if (json.type === "request" /* request */) {
|
|
6599
|
-
this.handleActionPayloadWire(json).catch((err3) => {
|
|
6600
|
-
console.error(`[ActionRuntime] Incoming action [${json.domain}:${json.id}:${json.form}:${json.type}] unhandled:`, err3);
|
|
6601
|
-
});
|
|
6602
|
-
return;
|
|
6779
|
+
deserializeInput(serialized) {
|
|
6780
|
+
if (this.inputOptions?.serialization) {
|
|
6781
|
+
return this.inputOptions.serialization.deserialize(serialized);
|
|
6603
6782
|
}
|
|
6604
|
-
|
|
6783
|
+
return serialized;
|
|
6605
6784
|
}
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
const domain = this.actionRouter.domainManager.getActionDomainOrThrow(wire);
|
|
6610
|
-
action = domain.hydrateAnyAction(wire);
|
|
6785
|
+
validateInput(value, meta) {
|
|
6786
|
+
if (this.inputOptions?.schema == null) {
|
|
6787
|
+
return value;
|
|
6611
6788
|
}
|
|
6612
|
-
|
|
6613
|
-
|
|
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
|
+
});
|
|
6614
6795
|
}
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
const runningAction = await handlerForAction.handleActionRequest(action, {
|
|
6621
|
-
...options,
|
|
6622
|
-
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)
|
|
6623
6801
|
});
|
|
6624
|
-
this._trySetupReturnDispatch(runningAction);
|
|
6625
|
-
return runningAction;
|
|
6626
6802
|
}
|
|
6627
|
-
|
|
6628
|
-
label: `Handling incoming action payloads of type "${action.type}"`
|
|
6629
|
-
});
|
|
6803
|
+
return result.value;
|
|
6630
6804
|
}
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
const possibleHandlers = handlers.filter((handler2) => {
|
|
6635
|
-
if (handler2.handlerType === "external" /* external */) {
|
|
6636
|
-
if (targetExternalClient && !targetExternalClient.isSameFor(handler2.externalClient).id) {
|
|
6637
|
-
return false;
|
|
6638
|
-
}
|
|
6639
|
-
return true;
|
|
6640
|
-
}
|
|
6641
|
-
if (targetExternalClient != null) {
|
|
6642
|
-
return false;
|
|
6643
|
-
}
|
|
6644
|
-
if (action.type === "request" /* request */) {
|
|
6645
|
-
return true;
|
|
6646
|
-
}
|
|
6647
|
-
return false;
|
|
6648
|
-
});
|
|
6649
|
-
if (possibleHandlers.length === 0) {
|
|
6650
|
-
return;
|
|
6651
|
-
}
|
|
6652
|
-
const scoringExternalClient = targetExternalClient ?? ActionClientSpecifier.unknown;
|
|
6653
|
-
let handlerScore = -1;
|
|
6654
|
-
let handler;
|
|
6655
|
-
for (const possibleHandler of possibleHandlers) {
|
|
6656
|
-
if (possibleHandler.handlerType === "local" /* local */ && handler == null) {
|
|
6657
|
-
return possibleHandler;
|
|
6658
|
-
}
|
|
6659
|
-
if (possibleHandler.handlerType === "external" /* external */) {
|
|
6660
|
-
const score = scoringExternalClient.similarityLevel(possibleHandler.externalClient);
|
|
6661
|
-
if (score > handlerScore) {
|
|
6662
|
-
handlerScore = score;
|
|
6663
|
-
handler = possibleHandler;
|
|
6664
|
-
}
|
|
6665
|
-
}
|
|
6805
|
+
validateOutput(value, meta) {
|
|
6806
|
+
if (this.outputOptions?.schema == null) {
|
|
6807
|
+
return value;
|
|
6666
6808
|
}
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
throw err_nice_action.fromId("no_action_execution_handler" /* no_action_execution_handler */, {
|
|
6673
|
-
actionId: action.id,
|
|
6674
|
-
domain: action.domain,
|
|
6675
|
-
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
|
|
6676
6814
|
});
|
|
6677
6815
|
}
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
this._registeredExternalHandlers.push(handler);
|
|
6685
|
-
}
|
|
6686
|
-
const handlerRouter = handler.getActionRouter();
|
|
6687
|
-
this.actionRouter.addDomainsFromOther(handlerRouter);
|
|
6688
|
-
for (const key of handlerRouter.getRegisteredKeys()) {
|
|
6689
|
-
const alreadyRegistered = this.actionRouter.getForKey(key).some((h2) => h2.cuid === handler.cuid);
|
|
6690
|
-
if (!alreadyRegistered) {
|
|
6691
|
-
this.actionRouter.addForKey(key, handler);
|
|
6692
|
-
}
|
|
6693
|
-
}
|
|
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
|
+
});
|
|
6694
6822
|
}
|
|
6695
|
-
return
|
|
6823
|
+
return result.value;
|
|
6696
6824
|
}
|
|
6697
|
-
|
|
6698
|
-
if (
|
|
6699
|
-
return;
|
|
6700
|
-
let bestScore = -1;
|
|
6701
|
-
let bestHandler;
|
|
6702
|
-
for (const handler of this._registeredExternalHandlers) {
|
|
6703
|
-
const score = originClient.similarityLevel(handler.externalClient);
|
|
6704
|
-
if (score > bestScore) {
|
|
6705
|
-
bestScore = score;
|
|
6706
|
-
bestHandler = handler;
|
|
6707
|
-
}
|
|
6825
|
+
serializeOutput(rawOutput) {
|
|
6826
|
+
if (this.outputOptions?.serialization) {
|
|
6827
|
+
return this.outputOptions.serialization.serialize(rawOutput);
|
|
6708
6828
|
}
|
|
6709
|
-
return
|
|
6829
|
+
return rawOutput;
|
|
6710
6830
|
}
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
return;
|
|
6831
|
+
deserializeOutput(serialized) {
|
|
6832
|
+
if (this.outputOptions?.serialization) {
|
|
6833
|
+
return this.outputOptions.serialization.deserialize(serialized);
|
|
6715
6834
|
}
|
|
6716
|
-
|
|
6717
|
-
(update) => {
|
|
6718
|
-
if (update.type === "finished" /* finished */ && update.finishType === "success" /* success */) {
|
|
6719
|
-
const returnHandler = this.getReturnHandlerForOrigin(originClient);
|
|
6720
|
-
returnHandler?.sendReturnPayload(update.response, { targetLocalRuntime: this }).catch(() => {});
|
|
6721
|
-
}
|
|
6722
|
-
}
|
|
6723
|
-
]);
|
|
6835
|
+
return serialized;
|
|
6724
6836
|
}
|
|
6725
6837
|
}
|
|
6726
|
-
var
|
|
6727
|
-
|
|
6728
|
-
assumedRuntimeInfo: undefined
|
|
6838
|
+
var actionSchema = () => {
|
|
6839
|
+
return new ActionSchema;
|
|
6729
6840
|
};
|
|
6730
|
-
function getDefaultActionRuntime() {
|
|
6731
|
-
if (runtimeState.assumedRuntimeInfo == null) {
|
|
6732
|
-
runtimeState.assumedRuntimeInfo = getAssumedRuntimeInfo();
|
|
6733
|
-
}
|
|
6734
|
-
if (runtimeState.defaultLocalRuntime == null) {
|
|
6735
|
-
runtimeState.defaultLocalRuntime = new ActionRuntime(ActionClientSpecifier.unknown.specify({
|
|
6736
|
-
perId: `${runtimeState.assumedRuntimeInfo?.runtimeName ?? "unknown"}-runtime`
|
|
6737
|
-
}));
|
|
6738
|
-
}
|
|
6739
|
-
return runtimeState.defaultLocalRuntime;
|
|
6740
|
-
}
|
|
6741
|
-
// src/ActionRuntime/Handler/ActionHandler.ts
|
|
6742
|
-
class ActionHandler {
|
|
6743
|
-
cuid;
|
|
6744
|
-
constructor() {
|
|
6745
|
-
this.cuid = nanoid();
|
|
6746
|
-
}
|
|
6747
|
-
getActionRouter() {
|
|
6748
|
-
return this.actionRouter;
|
|
6749
|
-
}
|
|
6750
|
-
}
|
|
6751
|
-
|
|
6752
6841
|
// src/ActionRuntime/Handler/ExternalClient/err_nice_external_client.ts
|
|
6753
6842
|
var err_nice_external_client = err_nice_action.createChildDomain({
|
|
6754
6843
|
domain: "err_nice_external_client",
|
|
@@ -7375,88 +7464,6 @@ class ActionExternalClientHandler extends ActionHandler {
|
|
|
7375
7464
|
var createExternalClientHandler = (config) => {
|
|
7376
7465
|
return new ActionExternalClientHandler(config);
|
|
7377
7466
|
};
|
|
7378
|
-
// src/ActionRuntime/Handler/Local/ActionLocalHandler.ts
|
|
7379
|
-
class ActionLocalHandler extends ActionHandler {
|
|
7380
|
-
handlerType = "local" /* local */;
|
|
7381
|
-
actionRouter = new ActionRouter({
|
|
7382
|
-
contextType: "handler_route" /* handler_route */,
|
|
7383
|
-
handler: this
|
|
7384
|
-
});
|
|
7385
|
-
constructor() {
|
|
7386
|
-
super();
|
|
7387
|
-
}
|
|
7388
|
-
forDomain(domain, handler) {
|
|
7389
|
-
this.actionRouter.forDomain(domain, handler);
|
|
7390
|
-
return this;
|
|
7391
|
-
}
|
|
7392
|
-
forAction(action, handler) {
|
|
7393
|
-
this.actionRouter.forAction(action, handler);
|
|
7394
|
-
return this;
|
|
7395
|
-
}
|
|
7396
|
-
forActionIds(domain, ids, handler) {
|
|
7397
|
-
this.actionRouter.forActionIds(domain, ids, handler);
|
|
7398
|
-
return this;
|
|
7399
|
-
}
|
|
7400
|
-
forDomainActionCases(domain, cases) {
|
|
7401
|
-
this.actionRouter.forDomainActionCases(domain, cases);
|
|
7402
|
-
return this;
|
|
7403
|
-
}
|
|
7404
|
-
async handleActionRequest(action, config) {
|
|
7405
|
-
const targetLocalRuntime = config?.targetLocalRuntime ?? ActionRuntime.getDefault();
|
|
7406
|
-
const handler = this.actionRouter.getRouteDataForActionOrThrow(action, {
|
|
7407
|
-
targetLocalRuntime
|
|
7408
|
-
});
|
|
7409
|
-
action.context.addRouteItem({
|
|
7410
|
-
runtime: targetLocalRuntime.clientSpecifier,
|
|
7411
|
-
handler: this.toHandlerRouteItem(),
|
|
7412
|
-
time: Date.now()
|
|
7413
|
-
});
|
|
7414
|
-
const runningAction = new RunningAction({ context: action.context, request: action });
|
|
7415
|
-
this._handleRunningAction(handler, runningAction).catch((err3) => runningAction._abort(err3));
|
|
7416
|
-
return runningAction;
|
|
7417
|
-
}
|
|
7418
|
-
async _handleRunningAction(handler, runningAction) {
|
|
7419
|
-
const state = runningAction.state;
|
|
7420
|
-
if (state.result != null) {
|
|
7421
|
-
return;
|
|
7422
|
-
}
|
|
7423
|
-
const rawResult = await handler(state.request);
|
|
7424
|
-
let result;
|
|
7425
|
-
if (rawResult instanceof ActionPayload_Result) {
|
|
7426
|
-
result = rawResult;
|
|
7427
|
-
} else if (rawResult != null && isActionPayload_Result_JsonObject(rawResult)) {
|
|
7428
|
-
const domain = this.actionRouter.domainManager.getActionDomainOrThrow(state.request);
|
|
7429
|
-
result = domain.hydrateResultPayload(rawResult);
|
|
7430
|
-
} else {
|
|
7431
|
-
result = state.request.successResult(rawResult);
|
|
7432
|
-
}
|
|
7433
|
-
runningAction._completeWithResult(result);
|
|
7434
|
-
}
|
|
7435
|
-
async handlePayloadWireOrThrow(wire, config) {
|
|
7436
|
-
const hydratedAction = this.actionRouter.domainManager.hydrateActionPayload(wire);
|
|
7437
|
-
if (!(hydratedAction instanceof ActionPayload_Request)) {
|
|
7438
|
-
throw err_nice_action.fromId("wire_action_not_payload" /* wire_action_not_payload */, {
|
|
7439
|
-
domain: hydratedAction.domain,
|
|
7440
|
-
actionId: hydratedAction.id,
|
|
7441
|
-
actionState: hydratedAction.type ?? hydratedAction.form
|
|
7442
|
-
});
|
|
7443
|
-
}
|
|
7444
|
-
return await this.handleActionRequest(hydratedAction, config);
|
|
7445
|
-
}
|
|
7446
|
-
toJsonObject() {
|
|
7447
|
-
return {
|
|
7448
|
-
type: this.handlerType
|
|
7449
|
-
};
|
|
7450
|
-
}
|
|
7451
|
-
toHandlerRouteItem() {
|
|
7452
|
-
return {
|
|
7453
|
-
type: this.handlerType
|
|
7454
|
-
};
|
|
7455
|
-
}
|
|
7456
|
-
}
|
|
7457
|
-
var createLocalHandler = () => {
|
|
7458
|
-
return new ActionLocalHandler;
|
|
7459
|
-
};
|
|
7460
7467
|
export {
|
|
7461
7468
|
isActionPayload_Result_JsonObject,
|
|
7462
7469
|
isActionPayload_Request_JsonObject,
|