@dudousxd/nestjs-durable 0.69.0 → 0.70.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +144 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +142 -77
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1045,21 +1045,116 @@ var import_nestjs_durable_core9 = require("@dudousxd/nestjs-durable-core");
|
|
|
1045
1045
|
var import_common3 = require("@nestjs/common");
|
|
1046
1046
|
var import_core = require("@nestjs/core");
|
|
1047
1047
|
|
|
1048
|
-
// src/
|
|
1048
|
+
// src/tokens.ts
|
|
1049
1049
|
var import_nestjs_durable_core4 = require("@dudousxd/nestjs-durable-core");
|
|
1050
|
+
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
1051
|
+
var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
|
|
1052
|
+
var RUN_GATEWAY = import_nestjs_durable_core4.RunGateway;
|
|
1053
|
+
|
|
1054
|
+
// src/context-runtime.ts
|
|
1055
|
+
function resolveAccessor(moduleRef) {
|
|
1056
|
+
try {
|
|
1057
|
+
return moduleRef.get(CONTEXT_ACCESSOR, {
|
|
1058
|
+
strict: false
|
|
1059
|
+
});
|
|
1060
|
+
} catch {
|
|
1061
|
+
return void 0;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
__name(resolveAccessor, "resolveAccessor");
|
|
1065
|
+
function contextSlotPresent() {
|
|
1066
|
+
const slot = globalThis[Symbol.for("@dudousxd/nestjs-diagnostics:accessor")];
|
|
1067
|
+
return !!slot?.current;
|
|
1068
|
+
}
|
|
1069
|
+
__name(contextSlotPresent, "contextSlotPresent");
|
|
1070
|
+
function isContextRuntime(x) {
|
|
1071
|
+
return !!x && typeof x.deserialize === "function";
|
|
1072
|
+
}
|
|
1073
|
+
__name(isContextRuntime, "isContextRuntime");
|
|
1074
|
+
async function resolveContextRuntime() {
|
|
1075
|
+
try {
|
|
1076
|
+
const specifier = "@dudousxd/nestjs-context";
|
|
1077
|
+
const mod = await import(specifier);
|
|
1078
|
+
return isContextRuntime(mod.Context) ? mod.Context : void 0;
|
|
1079
|
+
} catch {
|
|
1080
|
+
return void 0;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
__name(resolveContextRuntime, "resolveContextRuntime");
|
|
1084
|
+
async function resolveContextSerializer(accessor) {
|
|
1085
|
+
try {
|
|
1086
|
+
const specifier = "@dudousxd/nestjs-context";
|
|
1087
|
+
const mod = await import(specifier);
|
|
1088
|
+
const serialize = mod.Context?.serialize;
|
|
1089
|
+
if (typeof serialize !== "function" || mod.contextAccessor !== accessor) return void 0;
|
|
1090
|
+
return () => serialize.call(mod.Context);
|
|
1091
|
+
} catch {
|
|
1092
|
+
return void 0;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
__name(resolveContextSerializer, "resolveContextSerializer");
|
|
1096
|
+
var CONTEXT_MODULE_OPTIONS = Symbol.for("@dudousxd/nestjs-context:options");
|
|
1097
|
+
function contextHasCustomSerialize(moduleRef) {
|
|
1098
|
+
try {
|
|
1099
|
+
const options = moduleRef.get(CONTEXT_MODULE_OPTIONS, {
|
|
1100
|
+
strict: false
|
|
1101
|
+
});
|
|
1102
|
+
return typeof options?.serialize === "function";
|
|
1103
|
+
} catch {
|
|
1104
|
+
return false;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
__name(contextHasCustomSerialize, "contextHasCustomSerialize");
|
|
1108
|
+
function rehydrateBridge(runtime) {
|
|
1109
|
+
return (carrier, fn) => carrier && Object.keys(carrier).length > 0 ? runtime.deserialize(carrier, fn) : fn();
|
|
1110
|
+
}
|
|
1111
|
+
__name(rehydrateBridge, "rehydrateBridge");
|
|
1112
|
+
async function resolveContextRehydrate(moduleRef) {
|
|
1113
|
+
if (resolveAccessor(moduleRef) === void 0) return void 0;
|
|
1114
|
+
const runtime = await resolveContextRuntime();
|
|
1115
|
+
return runtime ? rehydrateBridge(runtime) : void 0;
|
|
1116
|
+
}
|
|
1117
|
+
__name(resolveContextRehydrate, "resolveContextRehydrate");
|
|
1118
|
+
function carrierFromContext(accessor, serialize, customSerialize) {
|
|
1119
|
+
if (serialize) {
|
|
1120
|
+
const carrier2 = {
|
|
1121
|
+
...serialize() ?? {}
|
|
1122
|
+
};
|
|
1123
|
+
for (const key of Object.keys(carrier2)) if (carrier2[key] === void 0) delete carrier2[key];
|
|
1124
|
+
const tenant2 = customSerialize ? void 0 : accessor.tenant?.();
|
|
1125
|
+
if (carrier2.tenantId !== void 0 && tenant2 !== void 0 && tenant2.source !== "legacy") {
|
|
1126
|
+
carrier2.tenant = tenant2;
|
|
1127
|
+
}
|
|
1128
|
+
return carrier2;
|
|
1129
|
+
}
|
|
1130
|
+
const carrier = {};
|
|
1131
|
+
const traceId = accessor.traceId();
|
|
1132
|
+
if (traceId !== void 0) carrier.traceId = traceId;
|
|
1133
|
+
const tenantId = accessor.tenantId();
|
|
1134
|
+
if (tenantId !== void 0) carrier.tenantId = tenantId;
|
|
1135
|
+
const tenant = accessor.tenant?.();
|
|
1136
|
+
if (tenant !== void 0 && tenant.source !== "legacy") carrier.tenant = tenant;
|
|
1137
|
+
const userRef = accessor.userRef();
|
|
1138
|
+
if (userRef !== void 0) carrier.userRef = userRef;
|
|
1139
|
+
return carrier;
|
|
1140
|
+
}
|
|
1141
|
+
__name(carrierFromContext, "carrierFromContext");
|
|
1142
|
+
|
|
1143
|
+
// src/schema-parse.ts
|
|
1144
|
+
var import_nestjs_durable_core5 = require("@dudousxd/nestjs-durable-core");
|
|
1050
1145
|
function schemaParser(schema, kind, label) {
|
|
1051
1146
|
const code = kind === "input" ? "invalid_input" : "invalid_output";
|
|
1052
1147
|
if (isStandardSchema(schema)) {
|
|
1053
1148
|
return async (value) => {
|
|
1054
1149
|
const result = await schema["~standard"].validate(value);
|
|
1055
|
-
if (result.issues) throw new
|
|
1150
|
+
if (result.issues) throw new import_nestjs_durable_core5.SchemaValidationError(label, result.issues, code);
|
|
1056
1151
|
return result.value;
|
|
1057
1152
|
};
|
|
1058
1153
|
}
|
|
1059
1154
|
if (isZodLike(schema)) {
|
|
1060
1155
|
return async (value) => {
|
|
1061
1156
|
const result = schema.safeParse(value);
|
|
1062
|
-
if (!result.success) throw new
|
|
1157
|
+
if (!result.success) throw new import_nestjs_durable_core5.SchemaValidationError(label, result.error.issues, code);
|
|
1063
1158
|
return result.data;
|
|
1064
1159
|
};
|
|
1065
1160
|
}
|
|
@@ -1079,7 +1174,7 @@ function classValidatorParser(cls, code, label) {
|
|
|
1079
1174
|
}
|
|
1080
1175
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
1081
1176
|
const got = value === null ? "null" : Array.isArray(value) ? "an array" : typeof value;
|
|
1082
|
-
throw new
|
|
1177
|
+
throw new import_nestjs_durable_core5.SchemaValidationError(label, [
|
|
1083
1178
|
{
|
|
1084
1179
|
message: `expected an object, got ${got}`
|
|
1085
1180
|
}
|
|
@@ -1099,7 +1194,7 @@ function classValidatorParser(cls, code, label) {
|
|
|
1099
1194
|
]
|
|
1100
1195
|
}));
|
|
1101
1196
|
const summary = issues.map((i) => i.message).join("; ");
|
|
1102
|
-
throw new
|
|
1197
|
+
throw new import_nestjs_durable_core5.SchemaValidationError(label, issues, code, summary);
|
|
1103
1198
|
}
|
|
1104
1199
|
return instance;
|
|
1105
1200
|
};
|
|
@@ -1154,7 +1249,7 @@ function scanSteps(discovery, scanner, register) {
|
|
|
1154
1249
|
__name(scanSteps, "scanSteps");
|
|
1155
1250
|
|
|
1156
1251
|
// src/entity.ts
|
|
1157
|
-
var
|
|
1252
|
+
var import_nestjs_durable_core6 = require("@dudousxd/nestjs-durable-core");
|
|
1158
1253
|
var import_common2 = require("@nestjs/common");
|
|
1159
1254
|
var import_reflect_metadata2 = require("reflect-metadata");
|
|
1160
1255
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
@@ -1237,15 +1332,15 @@ EntityService = _ts_decorate2([
|
|
|
1237
1332
|
(0, import_common2.Injectable)(),
|
|
1238
1333
|
_ts_metadata2("design:type", Function),
|
|
1239
1334
|
_ts_metadata2("design:paramtypes", [
|
|
1240
|
-
typeof
|
|
1335
|
+
typeof import_nestjs_durable_core6.WorkflowEngine === "undefined" ? Object : import_nestjs_durable_core6.WorkflowEngine
|
|
1241
1336
|
])
|
|
1242
1337
|
], EntityService);
|
|
1243
1338
|
|
|
1244
1339
|
// src/runtime-registration.ts
|
|
1245
|
-
var
|
|
1340
|
+
var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
|
|
1246
1341
|
|
|
1247
1342
|
// src/on-error-handlers.ts
|
|
1248
|
-
var
|
|
1343
|
+
var import_nestjs_durable_core7 = require("@dudousxd/nestjs-durable-core");
|
|
1249
1344
|
function onErrorHandlersOf(meta, instance, scanner) {
|
|
1250
1345
|
const handlers = [];
|
|
1251
1346
|
const routes = [];
|
|
@@ -1266,7 +1361,7 @@ function onErrorHandlersOf(meta, instance, scanner) {
|
|
|
1266
1361
|
for (const r of meta.onError ?? []) {
|
|
1267
1362
|
routes.push({
|
|
1268
1363
|
code: r.code === void 0 || typeof r.code === "string" ? r.code : r.code.code,
|
|
1269
|
-
workflow: (0,
|
|
1364
|
+
workflow: (0, import_nestjs_durable_core7.workflowName)(r.workflow)
|
|
1270
1365
|
});
|
|
1271
1366
|
}
|
|
1272
1367
|
return {
|
|
@@ -1336,7 +1431,7 @@ function announcedOptions(meta) {
|
|
|
1336
1431
|
...meta.tags
|
|
1337
1432
|
];
|
|
1338
1433
|
if (meta.executionTimeout !== void 0) {
|
|
1339
|
-
options.executionTimeoutMs = (0,
|
|
1434
|
+
options.executionTimeoutMs = (0, import_nestjs_durable_core8.parseDuration)(meta.executionTimeout);
|
|
1340
1435
|
}
|
|
1341
1436
|
if (meta.singleton !== void 0) {
|
|
1342
1437
|
options.singleton = {
|
|
@@ -1368,12 +1463,6 @@ function isStepInterceptor(target) {
|
|
|
1368
1463
|
}
|
|
1369
1464
|
__name(isStepInterceptor, "isStepInterceptor");
|
|
1370
1465
|
|
|
1371
|
-
// src/tokens.ts
|
|
1372
|
-
var import_nestjs_durable_core8 = require("@dudousxd/nestjs-durable-core");
|
|
1373
|
-
var CONTEXT_ACCESSOR = Symbol.for("@dudousxd/nestjs-context:accessor");
|
|
1374
|
-
var TENANT_AUTH = Symbol("nestjs-durable:tenant-auth");
|
|
1375
|
-
var RUN_GATEWAY = import_nestjs_durable_core8.RunGateway;
|
|
1376
|
-
|
|
1377
1466
|
// src/durable-worker.module.ts
|
|
1378
1467
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
1379
1468
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -1701,16 +1790,24 @@ function thinWorkerProviders() {
|
|
|
1701
1790
|
// The role gate lives HERE, not just in the consumers: constructing the runtime resolves the
|
|
1702
1791
|
// optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
|
|
1703
1792
|
// reach this branch at all.
|
|
1704
|
-
useFactory: /* @__PURE__ */ __name((options) =>
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1793
|
+
useFactory: /* @__PURE__ */ __name(async (options, moduleRef) => {
|
|
1794
|
+
if (!isPureThinWorker(options)) return null;
|
|
1795
|
+
const rehydrate = await resolveContextRehydrate(moduleRef);
|
|
1796
|
+
return createWorkerRuntime({
|
|
1797
|
+
workflowGroup: options.partition ?? "",
|
|
1798
|
+
// The worker unwinds a failed turn's `localStep` undos itself, so it takes the
|
|
1799
|
+
// module's `compensationRetries` as the engine does.
|
|
1800
|
+
...options.compensationRetries !== void 0 ? {
|
|
1801
|
+
compensationRetries: options.compensationRetries
|
|
1802
|
+
} : {},
|
|
1803
|
+
...rehydrate !== void 0 ? {
|
|
1804
|
+
rehydrate
|
|
1805
|
+
} : {}
|
|
1806
|
+
});
|
|
1807
|
+
}, "useFactory"),
|
|
1712
1808
|
inject: [
|
|
1713
|
-
import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL
|
|
1809
|
+
import_nestjs_durable_core9.DURABLE_OPTIONS_CANONICAL,
|
|
1810
|
+
import_core.ModuleRef
|
|
1714
1811
|
]
|
|
1715
1812
|
},
|
|
1716
1813
|
{
|
|
@@ -2019,16 +2116,24 @@ function inAppWorkerProviders() {
|
|
|
2019
2116
|
// The role gate lives HERE, not just in the consumer: constructing the runtime resolves the
|
|
2020
2117
|
// optional `@dudousxd/durable-worker` peer, so an operator that never runs a worker must not
|
|
2021
2118
|
// reach this branch at all.
|
|
2022
|
-
useFactory: /* @__PURE__ */ __name((options) =>
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2119
|
+
useFactory: /* @__PURE__ */ __name(async (options, moduleRef) => {
|
|
2120
|
+
if (!isCoLocatedWorker(options)) return null;
|
|
2121
|
+
const rehydrate = await resolveContextRehydrate(moduleRef);
|
|
2122
|
+
return createWorkerRuntime({
|
|
2123
|
+
workflowGroup: options.partition ?? "",
|
|
2124
|
+
// The worker unwinds a failed turn's `localStep` undos itself, so it takes the
|
|
2125
|
+
// module's `compensationRetries` as the engine does.
|
|
2126
|
+
...options.compensationRetries !== void 0 ? {
|
|
2127
|
+
compensationRetries: options.compensationRetries
|
|
2128
|
+
} : {},
|
|
2129
|
+
...rehydrate !== void 0 ? {
|
|
2130
|
+
rehydrate
|
|
2131
|
+
} : {}
|
|
2132
|
+
});
|
|
2133
|
+
}, "useFactory"),
|
|
2030
2134
|
inject: [
|
|
2031
|
-
import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL
|
|
2135
|
+
import_nestjs_durable_core11.DURABLE_OPTIONS_CANONICAL,
|
|
2136
|
+
import_core3.ModuleRef
|
|
2032
2137
|
]
|
|
2033
2138
|
},
|
|
2034
2139
|
{
|
|
@@ -4465,48 +4570,6 @@ function _ts_param9(paramIndex, decorator) {
|
|
|
4465
4570
|
};
|
|
4466
4571
|
}
|
|
4467
4572
|
__name(_ts_param9, "_ts_param");
|
|
4468
|
-
function resolveAccessor(moduleRef) {
|
|
4469
|
-
try {
|
|
4470
|
-
return moduleRef.get(CONTEXT_ACCESSOR, {
|
|
4471
|
-
strict: false
|
|
4472
|
-
});
|
|
4473
|
-
} catch {
|
|
4474
|
-
return void 0;
|
|
4475
|
-
}
|
|
4476
|
-
}
|
|
4477
|
-
__name(resolveAccessor, "resolveAccessor");
|
|
4478
|
-
function carrierFromAccessor(accessor) {
|
|
4479
|
-
const carrier = {};
|
|
4480
|
-
const traceId = accessor.traceId();
|
|
4481
|
-
if (traceId !== void 0) carrier.traceId = traceId;
|
|
4482
|
-
const tenantId = accessor.tenantId();
|
|
4483
|
-
if (tenantId !== void 0) carrier.tenantId = tenantId;
|
|
4484
|
-
const tenant = accessor.tenant?.();
|
|
4485
|
-
if (tenant !== void 0 && tenant.source !== "legacy") carrier.tenant = tenant;
|
|
4486
|
-
const userRef = accessor.userRef();
|
|
4487
|
-
if (userRef !== void 0) carrier.userRef = userRef;
|
|
4488
|
-
return carrier;
|
|
4489
|
-
}
|
|
4490
|
-
__name(carrierFromAccessor, "carrierFromAccessor");
|
|
4491
|
-
function contextSlotPresent() {
|
|
4492
|
-
const slot = globalThis[Symbol.for("@dudousxd/nestjs-diagnostics:accessor")];
|
|
4493
|
-
return !!slot?.current;
|
|
4494
|
-
}
|
|
4495
|
-
__name(contextSlotPresent, "contextSlotPresent");
|
|
4496
|
-
function isContextRuntime(x) {
|
|
4497
|
-
return !!x && typeof x.deserialize === "function";
|
|
4498
|
-
}
|
|
4499
|
-
__name(isContextRuntime, "isContextRuntime");
|
|
4500
|
-
async function resolveContextRuntime() {
|
|
4501
|
-
try {
|
|
4502
|
-
const specifier = "@dudousxd/nestjs-context";
|
|
4503
|
-
const mod = await import(specifier);
|
|
4504
|
-
return isContextRuntime(mod.Context) ? mod.Context : void 0;
|
|
4505
|
-
} catch {
|
|
4506
|
-
return void 0;
|
|
4507
|
-
}
|
|
4508
|
-
}
|
|
4509
|
-
__name(resolveContextRuntime, "resolveContextRuntime");
|
|
4510
4573
|
function isControlPlane(x) {
|
|
4511
4574
|
return !!x && typeof x.publishControl === "function" && typeof x.onControl === "function";
|
|
4512
4575
|
}
|
|
@@ -4824,10 +4887,12 @@ var DurableModule = class _DurableModule {
|
|
|
4824
4887
|
}
|
|
4825
4888
|
const primary = transport ?? options.transports?.[0]?.transport;
|
|
4826
4889
|
const accessor = resolveAccessor(moduleRef);
|
|
4827
|
-
const context = options.context ?? (accessor ? () => carrierFromAccessor(accessor) : void 0);
|
|
4828
4890
|
const runtimeNeeded = accessor !== void 0 || contextSlotPresent();
|
|
4829
4891
|
const runtime = runtimeNeeded ? await resolveContextRuntime() : void 0;
|
|
4830
|
-
const rehydrate = runtime && (
|
|
4892
|
+
const rehydrate = runtime && rehydrateBridge(runtime);
|
|
4893
|
+
const serialize = options.context === void 0 && accessor ? await resolveContextSerializer(accessor) : void 0;
|
|
4894
|
+
const customSerialize = contextHasCustomSerialize(moduleRef);
|
|
4895
|
+
const context = options.context ?? (accessor ? () => carrierFromContext(accessor, serialize, customSerialize) : void 0);
|
|
4831
4896
|
if (options.consumers === false) {
|
|
4832
4897
|
for (const t of [
|
|
4833
4898
|
transport,
|