@rotorsoft/act 1.31.14 → 1.31.16
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/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +2 -0
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/builders/event-builder.d.ts +11 -4
- package/dist/@types/builders/event-builder.d.ts.map +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
- package/dist/@types/internal/date-reviver.d.ts +50 -0
- package/dist/@types/internal/date-reviver.d.ts.map +1 -0
- package/dist/@types/internal/index.d.ts +1 -0
- package/dist/@types/internal/index.d.ts.map +1 -1
- package/dist/@types/internal/sensitive.d.ts +22 -4
- package/dist/@types/internal/sensitive.d.ts.map +1 -1
- package/dist/@types/ports.d.ts +19 -0
- package/dist/@types/ports.d.ts.map +1 -1
- package/dist/@types/scoped.d.ts +17 -5
- package/dist/@types/scoped.d.ts.map +1 -1
- package/dist/{chunk-D5MBFIKL.js → chunk-7IBF4FTQ.js} +16 -11
- package/dist/{chunk-D5MBFIKL.js.map → chunk-7IBF4FTQ.js.map} +1 -1
- package/dist/{chunk-IO2OOCOR.js → chunk-T2AT4N6B.js} +13 -3
- package/dist/{chunk-IO2OOCOR.js.map → chunk-T2AT4N6B.js.map} +1 -1
- package/dist/index.cjs +144 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +121 -75
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.js +2 -2
- package/dist/types/index.cjs +14 -9
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -68,6 +68,7 @@ __export(index_exports, {
|
|
|
68
68
|
cache: () => cache2,
|
|
69
69
|
config: () => config,
|
|
70
70
|
dateReviver: () => dateReviver,
|
|
71
|
+
default_scope: () => default_scope,
|
|
71
72
|
dispose: () => dispose,
|
|
72
73
|
disposeAndExit: () => disposeAndExit,
|
|
73
74
|
extend: () => extend,
|
|
@@ -407,23 +408,28 @@ function is_pii(schema) {
|
|
|
407
408
|
cur = inner;
|
|
408
409
|
}
|
|
409
410
|
}
|
|
410
|
-
function
|
|
411
|
+
function pii_schemas(schema) {
|
|
411
412
|
const shape = schema.shape;
|
|
412
413
|
if (shape && typeof shape === "object") {
|
|
413
|
-
const fields =
|
|
414
|
-
for (const key of Object.keys(shape))
|
|
415
|
-
if (is_pii(shape[key])) fields
|
|
416
|
-
}
|
|
414
|
+
const fields = {};
|
|
415
|
+
for (const key of Object.keys(shape))
|
|
416
|
+
if (is_pii(shape[key])) fields[key] = shape[key];
|
|
417
417
|
return fields;
|
|
418
418
|
}
|
|
419
419
|
const options = schema.options;
|
|
420
420
|
if (Array.isArray(options)) {
|
|
421
|
-
const fields =
|
|
421
|
+
const fields = {};
|
|
422
422
|
for (const option of options)
|
|
423
|
-
for (const key of
|
|
424
|
-
|
|
423
|
+
for (const [key, field] of Object.entries(
|
|
424
|
+
pii_schemas(option)
|
|
425
|
+
))
|
|
426
|
+
fields[key] ??= field;
|
|
427
|
+
return fields;
|
|
425
428
|
}
|
|
426
|
-
return
|
|
429
|
+
return {};
|
|
430
|
+
}
|
|
431
|
+
function pii_fields(schema) {
|
|
432
|
+
return Object.keys(pii_schemas(schema));
|
|
427
433
|
}
|
|
428
434
|
function pii_split(emitted, fields) {
|
|
429
435
|
const data = { ...emitted.data };
|
|
@@ -1607,7 +1613,7 @@ var import_node_async_hooks = require("async_hooks");
|
|
|
1607
1613
|
var scoped = new import_node_async_hooks.AsyncLocalStorage();
|
|
1608
1614
|
var reacting = new import_node_async_hooks.AsyncLocalStorage();
|
|
1609
1615
|
function make_run_scoped(bag) {
|
|
1610
|
-
return
|
|
1616
|
+
return (fn) => scoped.run(bag, fn);
|
|
1611
1617
|
}
|
|
1612
1618
|
function current_ports() {
|
|
1613
1619
|
return scoped.getStore();
|
|
@@ -1661,6 +1667,15 @@ var _cache = port(function cache(adapter) {
|
|
|
1661
1667
|
var cache2 = ((adapter) => {
|
|
1662
1668
|
return current_ports()?.cache ?? _cache(adapter);
|
|
1663
1669
|
});
|
|
1670
|
+
var default_scope = () => DEFAULT_SCOPE;
|
|
1671
|
+
var DEFAULT_SCOPE = {
|
|
1672
|
+
get store() {
|
|
1673
|
+
return _store();
|
|
1674
|
+
},
|
|
1675
|
+
get cache() {
|
|
1676
|
+
return _cache();
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1664
1679
|
async function disposeAndExit(code = "EXIT") {
|
|
1665
1680
|
if (code === "ERROR" && config().env === "production") {
|
|
1666
1681
|
log().warn(
|
|
@@ -3360,14 +3375,17 @@ var CorrelateCycle = class {
|
|
|
3360
3375
|
upgraded,
|
|
3361
3376
|
correlated_at: void 0
|
|
3362
3377
|
};
|
|
3363
|
-
const
|
|
3364
|
-
|
|
3378
|
+
const seen_in_scan = correlated.has(resolved.target);
|
|
3379
|
+
const held_lane = (seen_in_scan ? entry.lane : recorded?.lane) ?? DEFAULT_LANE;
|
|
3380
|
+
const held_priority = seen_in_scan ? entry.priority : recorded?.priority;
|
|
3381
|
+
const resolved_lane = lane ?? DEFAULT_LANE;
|
|
3382
|
+
if (held_priority === priority && held_lane !== resolved_lane)
|
|
3365
3383
|
report_lane_conflict(
|
|
3366
3384
|
this._reported,
|
|
3367
3385
|
reaction.handler.name,
|
|
3368
3386
|
resolved.target,
|
|
3369
|
-
|
|
3370
|
-
|
|
3387
|
+
held_lane,
|
|
3388
|
+
resolved_lane
|
|
3371
3389
|
);
|
|
3372
3390
|
if (carried.priority > entry.priority) {
|
|
3373
3391
|
entry.priority = carried.priority;
|
|
@@ -3509,18 +3527,83 @@ function close_correlation(correlator, actor) {
|
|
|
3509
3527
|
});
|
|
3510
3528
|
}
|
|
3511
3529
|
|
|
3512
|
-
// src/internal/
|
|
3530
|
+
// src/internal/date-reviver.ts
|
|
3513
3531
|
var import_zod7 = require("zod");
|
|
3514
|
-
var
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3532
|
+
var def_of = (schema) => schema._zod?.def ?? schema.def;
|
|
3533
|
+
function variant_schema(schema) {
|
|
3534
|
+
const shape = def_of(schema)?.shape;
|
|
3535
|
+
if (!shape) {
|
|
3536
|
+
const dates = date_reviver_schema(schema);
|
|
3537
|
+
return { schema: dates ?? schema, dated: !!dates };
|
|
3538
|
+
}
|
|
3539
|
+
const next = {};
|
|
3540
|
+
let dated = false;
|
|
3541
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
3542
|
+
const dates = date_reviver_schema(field);
|
|
3543
|
+
if (dates) dated = true;
|
|
3544
|
+
next[key] = (dates ?? field).optional();
|
|
3545
|
+
}
|
|
3546
|
+
return { schema: import_zod7.z.looseObject(next), dated };
|
|
3547
|
+
}
|
|
3548
|
+
function date_reviver_schema(schema) {
|
|
3549
|
+
const def = def_of(schema);
|
|
3550
|
+
if (!def) return void 0;
|
|
3551
|
+
const inner = () => date_reviver_schema(def.innerType);
|
|
3552
|
+
switch (def.type) {
|
|
3553
|
+
case "date":
|
|
3554
|
+
return import_zod7.z.coerce.date();
|
|
3555
|
+
case "object": {
|
|
3556
|
+
const shape = def.shape;
|
|
3557
|
+
if (!shape) return void 0;
|
|
3558
|
+
const dated = {};
|
|
3559
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
3560
|
+
const dates = date_reviver_schema(field);
|
|
3561
|
+
if (dates) dated[key] = dates.optional();
|
|
3562
|
+
}
|
|
3563
|
+
return Object.keys(dated).length ? import_zod7.z.looseObject(dated) : void 0;
|
|
3564
|
+
}
|
|
3565
|
+
case "array": {
|
|
3566
|
+
const element = date_reviver_schema(def.element);
|
|
3567
|
+
return element && import_zod7.z.array(element);
|
|
3568
|
+
}
|
|
3569
|
+
case "tuple": {
|
|
3570
|
+
const items = def.items.map((i) => date_reviver_schema(i));
|
|
3571
|
+
return items.some(Boolean) ? import_zod7.z.tuple(items.map((i) => i ?? import_zod7.z.unknown())) : void 0;
|
|
3572
|
+
}
|
|
3573
|
+
case "record": {
|
|
3574
|
+
const value = date_reviver_schema(def.valueType);
|
|
3575
|
+
return value && import_zod7.z.record(import_zod7.z.string(), value);
|
|
3576
|
+
}
|
|
3577
|
+
case "union": {
|
|
3578
|
+
const variants = def.options.map(variant_schema);
|
|
3579
|
+
return variants.some((v) => v.dated) ? import_zod7.z.union(variants.map((v) => v.schema)) : void 0;
|
|
3580
|
+
}
|
|
3581
|
+
case "nullable":
|
|
3582
|
+
return inner()?.nullable();
|
|
3583
|
+
case "optional":
|
|
3584
|
+
case "nonoptional":
|
|
3585
|
+
case "readonly":
|
|
3586
|
+
case "default":
|
|
3587
|
+
case "prefault":
|
|
3588
|
+
case "catch":
|
|
3589
|
+
return inner();
|
|
3590
|
+
default:
|
|
3591
|
+
return void 0;
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
|
|
3595
|
+
// src/internal/defer-config.ts
|
|
3596
|
+
var import_zod8 = require("zod");
|
|
3597
|
+
var DeferDurationSchema = import_zod8.z.object({
|
|
3598
|
+
days: import_zod8.z.number().positive().optional(),
|
|
3599
|
+
hours: import_zod8.z.number().positive().optional(),
|
|
3600
|
+
minutes: import_zod8.z.number().positive().optional()
|
|
3518
3601
|
}).strict().refine((d) => d.days != null || d.hours != null || d.minutes != null, {
|
|
3519
3602
|
message: "defer: a duration needs at least one of days, hours, or minutes"
|
|
3520
3603
|
});
|
|
3521
|
-
var DeferWhenSchema =
|
|
3604
|
+
var DeferWhenSchema = import_zod8.z.object({
|
|
3522
3605
|
after: DeferDurationSchema.optional(),
|
|
3523
|
-
at:
|
|
3606
|
+
at: import_zod8.z.date().optional()
|
|
3524
3607
|
}).strict().refine((w) => w.after === void 0 !== (w.at === void 0), {
|
|
3525
3608
|
message: "defer: specify exactly one of `after` or `at`"
|
|
3526
3609
|
});
|
|
@@ -5002,6 +5085,8 @@ var Act = class {
|
|
|
5002
5085
|
* per-Act ports (ACT-501). No-op when the Act is unscoped — so the singleton
|
|
5003
5086
|
* path keeps reading fresh `store()`/`cache()` per call, which matters for
|
|
5004
5087
|
* tests that dispose and re-seed mid-suite. */
|
|
5088
|
+
/** This Act's ports: its own bag, or the singleton adapters. */
|
|
5089
|
+
_ports;
|
|
5005
5090
|
_scoped;
|
|
5006
5091
|
/**
|
|
5007
5092
|
* Correlation-id generator for originating actions. Bound at
|
|
@@ -5080,7 +5165,8 @@ var Act = class {
|
|
|
5080
5165
|
this._batch_handlers = batch_handlers;
|
|
5081
5166
|
this._lanes = lanes;
|
|
5082
5167
|
validate_only_lanes(options, lanes);
|
|
5083
|
-
this.
|
|
5168
|
+
this._ports = options.scoped ?? default_scope();
|
|
5169
|
+
this._scoped = make_run_scoped(this._ports);
|
|
5084
5170
|
this._correlator = options.correlator ?? default_correlator;
|
|
5085
5171
|
this._es = build_es(this._logger, this._correlator, patch_fn);
|
|
5086
5172
|
this._cd = build_drain(this._logger);
|
|
@@ -5109,7 +5195,7 @@ var Act = class {
|
|
|
5109
5195
|
this._audit_deps = this._build_audit_deps();
|
|
5110
5196
|
this._correlate = this._build_correlate(options, classification);
|
|
5111
5197
|
this._settle = this._build_settle(options);
|
|
5112
|
-
this._notify_disposer = this._wire_notify(
|
|
5198
|
+
this._notify_disposer = this._wire_notify(this._ports.store);
|
|
5113
5199
|
register_weak_disposer(new WeakRef(this), (self) => self.shutdown());
|
|
5114
5200
|
}
|
|
5115
5201
|
/**
|
|
@@ -5358,13 +5444,13 @@ var Act = class {
|
|
|
5358
5444
|
this._shutdown_promise = (async () => {
|
|
5359
5445
|
this.stop_correlations();
|
|
5360
5446
|
await this._scoped(() => this._correlate.release_correlation());
|
|
5447
|
+
const disposer = await this._notify_disposer;
|
|
5448
|
+
if (disposer) await disposer();
|
|
5361
5449
|
this.stop_settling();
|
|
5362
5450
|
this._breaker.stop();
|
|
5363
5451
|
for (const c of this._drain_controllers.values()) c.stop();
|
|
5364
5452
|
await this._await_inflight(options?.graceMs);
|
|
5365
5453
|
this._emitter.removeAllListeners();
|
|
5366
|
-
const disposer = await this._notify_disposer;
|
|
5367
|
-
if (disposer) await disposer();
|
|
5368
5454
|
})();
|
|
5369
5455
|
}
|
|
5370
5456
|
return this._shutdown_promise;
|
|
@@ -6362,7 +6448,7 @@ var Act = class {
|
|
|
6362
6448
|
};
|
|
6363
6449
|
|
|
6364
6450
|
// src/builders/merge.ts
|
|
6365
|
-
var
|
|
6451
|
+
var import_zod9 = require("zod");
|
|
6366
6452
|
function base_type_name(zodType) {
|
|
6367
6453
|
let t = zodType;
|
|
6368
6454
|
while (typeof t.unwrap === "function") {
|
|
@@ -6371,7 +6457,7 @@ function base_type_name(zodType) {
|
|
|
6371
6457
|
return t.constructor.name;
|
|
6372
6458
|
}
|
|
6373
6459
|
function merge_schemas(existing, incoming, state_name) {
|
|
6374
|
-
if (existing instanceof
|
|
6460
|
+
if (existing instanceof import_zod9.ZodObject && incoming instanceof import_zod9.ZodObject) {
|
|
6375
6461
|
const existing_shape = existing.shape;
|
|
6376
6462
|
const incoming_shape = incoming.shape;
|
|
6377
6463
|
for (const key of Object.keys(incoming_shape)) {
|
|
@@ -6558,70 +6644,43 @@ function reaction_on(event, events, builder) {
|
|
|
6558
6644
|
}
|
|
6559
6645
|
|
|
6560
6646
|
// src/builders/event-builder.ts
|
|
6561
|
-
var
|
|
6562
|
-
var def_of = (schema) => schema._zod?.def ?? schema.def;
|
|
6563
|
-
function to_read_schema(schema, found) {
|
|
6564
|
-
const def = def_of(schema);
|
|
6565
|
-
if (!def) return schema;
|
|
6566
|
-
switch (def.type) {
|
|
6567
|
-
case "date":
|
|
6568
|
-
found.date = true;
|
|
6569
|
-
return import_zod9.z.coerce.date();
|
|
6570
|
-
case "object": {
|
|
6571
|
-
const shape = def.shape;
|
|
6572
|
-
if (!shape) return schema;
|
|
6573
|
-
const next = {};
|
|
6574
|
-
for (const [key, inner] of Object.entries(shape))
|
|
6575
|
-
next[key] = to_read_schema(inner, found);
|
|
6576
|
-
return import_zod9.z.looseObject(next);
|
|
6577
|
-
}
|
|
6578
|
-
case "array":
|
|
6579
|
-
return import_zod9.z.array(to_read_schema(def.element, found));
|
|
6580
|
-
case "record":
|
|
6581
|
-
return import_zod9.z.record(
|
|
6582
|
-
import_zod9.z.string(),
|
|
6583
|
-
to_read_schema(def.valueType, found)
|
|
6584
|
-
);
|
|
6585
|
-
case "union":
|
|
6586
|
-
return import_zod9.z.union(
|
|
6587
|
-
def.options.map(
|
|
6588
|
-
(o) => to_read_schema(o, found)
|
|
6589
|
-
)
|
|
6590
|
-
);
|
|
6591
|
-
case "optional":
|
|
6592
|
-
return to_read_schema(def.innerType, found).optional();
|
|
6593
|
-
case "nullable":
|
|
6594
|
-
return to_read_schema(def.innerType, found).nullable();
|
|
6595
|
-
default:
|
|
6596
|
-
return schema;
|
|
6597
|
-
}
|
|
6598
|
-
}
|
|
6647
|
+
var import_zod10 = require("zod");
|
|
6599
6648
|
function event_tags(schema) {
|
|
6600
|
-
const
|
|
6601
|
-
const
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
const
|
|
6609
|
-
|
|
6649
|
+
const pii = pii_schemas(schema);
|
|
6650
|
+
const pii_dates = {};
|
|
6651
|
+
for (const [key, field] of Object.entries(pii)) {
|
|
6652
|
+
const dates = date_reviver_schema(field);
|
|
6653
|
+
if (dates) pii_dates[key] = dates.optional();
|
|
6654
|
+
}
|
|
6655
|
+
const data_reviver_schema = date_reviver_schema(schema);
|
|
6656
|
+
const revive = (schema2) => (data) => {
|
|
6657
|
+
const revived = schema2.safeParse(data);
|
|
6658
|
+
return revived.success ? revived.data : data;
|
|
6610
6659
|
};
|
|
6611
|
-
|
|
6612
|
-
const found = { date: false };
|
|
6613
|
-
const read_schema = to_read_schema(schema, found);
|
|
6660
|
+
const dated_pii = Object.keys(pii_dates).length > 0;
|
|
6614
6661
|
return {
|
|
6615
|
-
sensitive:
|
|
6616
|
-
|
|
6662
|
+
sensitive: Object.keys(pii),
|
|
6663
|
+
date_reviver: data_reviver_schema && revive(data_reviver_schema),
|
|
6664
|
+
pii_date_reviver: dated_pii ? revive(import_zod10.z.looseObject(pii_dates)) : void 0
|
|
6617
6665
|
};
|
|
6618
6666
|
}
|
|
6619
6667
|
function make_event_reader(tags, disclosure, predicate = null) {
|
|
6620
|
-
const { sensitive: sensitive2,
|
|
6621
|
-
if (!
|
|
6668
|
+
const { sensitive: sensitive2, date_reviver, pii_date_reviver } = tags;
|
|
6669
|
+
if (!date_reviver && sensitive2.length === 0) return void 0;
|
|
6622
6670
|
const gate = sensitive2.length === 0 ? IDENTITY_GATE : disclosure === "strip" ? ((event) => pii_strip(event, sensitive2)) : make_gate(sensitive2, predicate);
|
|
6623
|
-
if (!
|
|
6624
|
-
|
|
6671
|
+
if (!date_reviver) return gate;
|
|
6672
|
+
const revive_pii = disclosure === "redact" && predicate ? pii_date_reviver : void 0;
|
|
6673
|
+
return ((event, actor) => {
|
|
6674
|
+
const pii = event.pii;
|
|
6675
|
+
return gate(
|
|
6676
|
+
{
|
|
6677
|
+
...event,
|
|
6678
|
+
data: date_reviver(event.data),
|
|
6679
|
+
...revive_pii && actor && pii != null ? { pii: revive_pii(pii) } : {}
|
|
6680
|
+
},
|
|
6681
|
+
actor
|
|
6682
|
+
);
|
|
6683
|
+
});
|
|
6625
6684
|
}
|
|
6626
6685
|
function build_events(registry, states, lanes, owners) {
|
|
6627
6686
|
const declared = /* @__PURE__ */ new Set([DEFAULT_LANE, ...lanes.map((l) => l.name)]);
|
|
@@ -7408,6 +7467,7 @@ function write_line(writer, line) {
|
|
|
7408
7467
|
cache,
|
|
7409
7468
|
config,
|
|
7410
7469
|
dateReviver,
|
|
7470
|
+
default_scope,
|
|
7411
7471
|
dispose,
|
|
7412
7472
|
disposeAndExit,
|
|
7413
7473
|
extend,
|