@rotorsoft/act 2.1.13 → 2.1.15
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.map +1 -1
- package/dist/@types/builders/act-builder.d.ts.map +1 -1
- package/dist/@types/builders/event-builder.d.ts +7 -3
- package/dist/@types/builders/event-builder.d.ts.map +1 -1
- package/dist/@types/builders/merge.d.ts.map +1 -1
- package/dist/@types/deprecated.d.ts +10 -0
- package/dist/@types/deprecated.d.ts.map +1 -1
- package/dist/@types/index.d.ts +2 -3
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/@types/internal/audit.d.ts +2 -0
- package/dist/@types/internal/audit.d.ts.map +1 -1
- package/dist/@types/internal/config.d.ts +9 -0
- package/dist/@types/internal/config.d.ts.map +1 -1
- package/dist/@types/internal/pii.d.ts +1 -1
- package/dist/@types/{sensitive.d.ts → internal/sensitive.d.ts} +0 -24
- package/dist/@types/internal/sensitive.d.ts.map +1 -0
- package/dist/@types/types/act.d.ts +4 -3
- package/dist/@types/types/act.d.ts.map +1 -1
- package/dist/@types/types/action-rules.d.ts +177 -0
- package/dist/@types/types/action-rules.d.ts.map +1 -0
- package/dist/@types/types/builders.d.ts +15 -311
- package/dist/@types/types/builders.d.ts.map +1 -1
- package/dist/@types/types/projection.d.ts +135 -0
- package/dist/@types/types/projection.d.ts.map +1 -0
- package/dist/@types/types/registry.d.ts +7 -4
- package/dist/@types/types/registry.d.ts.map +1 -1
- package/dist/@types/types/schemas.d.ts +0 -1
- package/dist/@types/types/schemas.d.ts.map +1 -1
- package/dist/adapter.cjs +3 -3
- package/dist/adapter.js +2 -2
- package/dist/{chunk-OW67FBYO.cjs → chunk-3WHD4VPP.cjs} +62 -54
- package/dist/chunk-3WHD4VPP.cjs.map +1 -0
- package/dist/{chunk-R5PT4AYJ.js → chunk-CWWTVYIN.js} +11 -3
- package/dist/chunk-CWWTVYIN.js.map +1 -0
- package/dist/{chunk-MWLATJDX.js → chunk-GHMCESJA.js} +2 -2
- package/dist/{chunk-FYI7O7W6.js → chunk-KAUON2M3.js} +5 -93
- package/dist/chunk-KAUON2M3.js.map +1 -0
- package/dist/{chunk-QSXWCJ2U.cjs → chunk-LA2BPKNS.cjs} +40 -128
- package/dist/chunk-LA2BPKNS.cjs.map +1 -0
- package/dist/{chunk-PDMLWC77.cjs → chunk-QITJ63HG.cjs} +11 -11
- package/dist/{chunk-PDMLWC77.cjs.map → chunk-QITJ63HG.cjs.map} +1 -1
- package/dist/index.cjs +599 -507
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +111 -19
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +9 -9
- package/dist/test/index.js +3 -3
- package/dist/types/index.cjs +2 -6
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +3 -7
- package/package.json +2 -2
- package/dist/@types/sensitive.d.ts.map +0 -1
- package/dist/chunk-FYI7O7W6.js.map +0 -1
- package/dist/chunk-OW67FBYO.cjs.map +0 -1
- package/dist/chunk-QSXWCJ2U.cjs.map +0 -1
- package/dist/chunk-R5PT4AYJ.js.map +0 -1
- /package/dist/{chunk-MWLATJDX.js.map → chunk-GHMCESJA.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
store,
|
|
28
28
|
unscoped_ports,
|
|
29
29
|
validate
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-CWWTVYIN.js";
|
|
31
31
|
import {
|
|
32
32
|
checkAppends,
|
|
33
33
|
checkVersion,
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
isStreamName,
|
|
37
37
|
parseNotification,
|
|
38
38
|
seedEvent
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-GHMCESJA.js";
|
|
40
40
|
import {
|
|
41
41
|
ActorSchema,
|
|
42
42
|
CausationEventSchema,
|
|
@@ -65,14 +65,8 @@ import {
|
|
|
65
65
|
ValidationError,
|
|
66
66
|
ZodEmpty,
|
|
67
67
|
__name,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
output_of,
|
|
71
|
-
pii_fields,
|
|
72
|
-
pii_schemas,
|
|
73
|
-
sensitive,
|
|
74
|
-
sensitiveFields
|
|
75
|
-
} from "./chunk-FYI7O7W6.js";
|
|
68
|
+
sensitive
|
|
69
|
+
} from "./chunk-KAUON2M3.js";
|
|
76
70
|
|
|
77
71
|
// src/signals.ts
|
|
78
72
|
process.once("SIGINT", async (arg) => {
|
|
@@ -287,7 +281,7 @@ var make_schema_pass = /* @__PURE__ */ __name((deps) => {
|
|
|
287
281
|
return;
|
|
288
282
|
}
|
|
289
283
|
const schema = state2.events[name];
|
|
290
|
-
const sensitive2 =
|
|
284
|
+
const sensitive2 = deps.sensitive_fields(name);
|
|
291
285
|
let parse_schema = schema;
|
|
292
286
|
if (sensitive2.length > 0) {
|
|
293
287
|
const omitter = schema.omit;
|
|
@@ -1136,6 +1130,55 @@ import { prettifyError, ZodError } from "zod";
|
|
|
1136
1130
|
|
|
1137
1131
|
// src/internal/date-reviver.ts
|
|
1138
1132
|
import { z } from "zod";
|
|
1133
|
+
|
|
1134
|
+
// src/internal/zod.ts
|
|
1135
|
+
var def_of = /* @__PURE__ */ __name((schema) => schema?._zod?.def, "def_of");
|
|
1136
|
+
var SINGLE_INNER = [
|
|
1137
|
+
"optional",
|
|
1138
|
+
"nullable",
|
|
1139
|
+
"default",
|
|
1140
|
+
"prefault",
|
|
1141
|
+
"nonoptional",
|
|
1142
|
+
"readonly",
|
|
1143
|
+
"catch"
|
|
1144
|
+
];
|
|
1145
|
+
var inner_of = /* @__PURE__ */ __name((def) => SINGLE_INNER.includes(def.type) ? def.innerType : void 0, "inner_of");
|
|
1146
|
+
function wrapped(schema) {
|
|
1147
|
+
const def = def_of(schema);
|
|
1148
|
+
if (!def) return [];
|
|
1149
|
+
if (def.type === "pipe") return [def.in, def.out];
|
|
1150
|
+
if (def.type === "lazy") return [def.getter()];
|
|
1151
|
+
const inner = inner_of(def);
|
|
1152
|
+
return inner ? [inner] : [];
|
|
1153
|
+
}
|
|
1154
|
+
__name(wrapped, "wrapped");
|
|
1155
|
+
function some_layer(schema, test) {
|
|
1156
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1157
|
+
const visit = /* @__PURE__ */ __name((s) => {
|
|
1158
|
+
if (seen.has(s)) return false;
|
|
1159
|
+
seen.add(s);
|
|
1160
|
+
const def = def_of(s);
|
|
1161
|
+
return !!def && (test(def) || wrapped(s).some(visit));
|
|
1162
|
+
}, "visit");
|
|
1163
|
+
return visit(schema);
|
|
1164
|
+
}
|
|
1165
|
+
__name(some_layer, "some_layer");
|
|
1166
|
+
function output_of(schema) {
|
|
1167
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1168
|
+
let cur = schema;
|
|
1169
|
+
while (!seen.has(cur)) {
|
|
1170
|
+
seen.add(cur);
|
|
1171
|
+
const def = def_of(cur);
|
|
1172
|
+
if (!def) return cur;
|
|
1173
|
+
const next = def.type === "pipe" ? def.out : wrapped(cur)[0];
|
|
1174
|
+
if (!next) return cur;
|
|
1175
|
+
cur = next;
|
|
1176
|
+
}
|
|
1177
|
+
return cur;
|
|
1178
|
+
}
|
|
1179
|
+
__name(output_of, "output_of");
|
|
1180
|
+
|
|
1181
|
+
// src/internal/date-reviver.ts
|
|
1139
1182
|
function variant_schema(schema, walk) {
|
|
1140
1183
|
const shape = def_of(schema)?.shape;
|
|
1141
1184
|
if (!shape) {
|
|
@@ -3552,6 +3595,7 @@ var Act = class {
|
|
|
3552
3595
|
throw new Error(
|
|
3553
3596
|
`ActOptions.onlyLanes references undeclared lane(s): ${undeclared.map((l) => `"${l}"`).join(", ")}`
|
|
3554
3597
|
);
|
|
3598
|
+
check("act", options);
|
|
3555
3599
|
if (options.scoped) check("store", options.scoped.store);
|
|
3556
3600
|
this._ports = options.scoped ?? unscoped_ports();
|
|
3557
3601
|
const ports = this._ports;
|
|
@@ -3677,6 +3721,7 @@ var Act = class {
|
|
|
3677
3721
|
return {
|
|
3678
3722
|
store,
|
|
3679
3723
|
event_to_state: this._event_to_state,
|
|
3724
|
+
sensitive_fields: this.registry.sensitive_fields,
|
|
3680
3725
|
// Declared lanes, not this process's controllers: a lane another
|
|
3681
3726
|
// worker drains is not `unknown-lane`.
|
|
3682
3727
|
declared_lanes: new Set(this._declared_lanes),
|
|
@@ -3916,6 +3961,7 @@ var Act = class {
|
|
|
3916
3961
|
* @see {@link query_array} for loading events into memory
|
|
3917
3962
|
*/
|
|
3918
3963
|
async query(query, callback) {
|
|
3964
|
+
check("page", query);
|
|
3919
3965
|
return this._scoped(async () => {
|
|
3920
3966
|
let first;
|
|
3921
3967
|
let last;
|
|
@@ -4083,6 +4129,7 @@ var Act = class {
|
|
|
4083
4129
|
* @see {@link start_correlations} for automatic periodic correlation
|
|
4084
4130
|
*/
|
|
4085
4131
|
async correlate(query = {}) {
|
|
4132
|
+
check("page", query);
|
|
4086
4133
|
const pass = await this._correlate_pass(query.limit ?? 10);
|
|
4087
4134
|
return {
|
|
4088
4135
|
subscribed: pass.kind === "scanned" ? pass.subscribed : 0,
|
|
@@ -4128,6 +4175,8 @@ var Act = class {
|
|
|
4128
4175
|
* @see {@link stop_correlations} to stop the poll
|
|
4129
4176
|
*/
|
|
4130
4177
|
start_correlations(query = {}, frequency = 1e4) {
|
|
4178
|
+
check("page", query);
|
|
4179
|
+
check("poll", { frequency });
|
|
4131
4180
|
if (this._poll) return false;
|
|
4132
4181
|
this._poll_limit = query.limit || void 0;
|
|
4133
4182
|
this._poll = setInterval(() => {
|
|
@@ -4329,6 +4378,7 @@ var Act = class {
|
|
|
4329
4378
|
* ```
|
|
4330
4379
|
*/
|
|
4331
4380
|
async blocked_streams(options) {
|
|
4381
|
+
check("page", options ?? {});
|
|
4332
4382
|
return this._scoped(async () => {
|
|
4333
4383
|
const positions = [];
|
|
4334
4384
|
await store().query_streams(
|
|
@@ -4520,14 +4570,19 @@ function register_state(state2, states, actions, events) {
|
|
|
4520
4570
|
}
|
|
4521
4571
|
}
|
|
4522
4572
|
__name(register_state, "register_state");
|
|
4573
|
+
var shared_name = /* @__PURE__ */ __name((name) => new Error(
|
|
4574
|
+
`Action and event share the name "${name}" \u2014 action and event names must be unique across the application. Rename one of them.`
|
|
4575
|
+
), "shared_name");
|
|
4523
4576
|
function register_new_state(state2, states, actions, events) {
|
|
4524
4577
|
states.set(state2.name, state2);
|
|
4525
4578
|
for (const name of Object.keys(state2.actions)) {
|
|
4526
4579
|
if (actions[name]) throw new Error(`Duplicate action "${name}"`);
|
|
4580
|
+
if (events[name]) throw shared_name(name);
|
|
4527
4581
|
actions[name] = state2;
|
|
4528
4582
|
}
|
|
4529
4583
|
for (const name of Object.keys(state2.events)) {
|
|
4530
4584
|
if (events[name]) throw new Error(`Duplicate event "${name}"`);
|
|
4585
|
+
if (actions[name]) throw shared_name(name);
|
|
4531
4586
|
events[name] = { schema: state2.events[name], reactions: /* @__PURE__ */ new Map() };
|
|
4532
4587
|
}
|
|
4533
4588
|
}
|
|
@@ -4558,6 +4613,7 @@ function merge_into_existing(state2, existing, states, actions, events) {
|
|
|
4558
4613
|
for (const name of Object.keys(state2.actions)) {
|
|
4559
4614
|
if (existing.on[name] === state2.on[name]) continue;
|
|
4560
4615
|
if (actions[name]) throw new Error(`Duplicate action "${name}"`);
|
|
4616
|
+
if (events[name] || state2.events[name]) throw shared_name(name);
|
|
4561
4617
|
}
|
|
4562
4618
|
for (const name of Object.keys(state2.events)) {
|
|
4563
4619
|
if (existing.events[name] === state2.events[name]) continue;
|
|
@@ -4567,6 +4623,7 @@ function merge_into_existing(state2, existing, states, actions, events) {
|
|
|
4567
4623
|
);
|
|
4568
4624
|
}
|
|
4569
4625
|
if (events[name]) throw new Error(`Duplicate event "${name}"`);
|
|
4626
|
+
if (actions[name]) throw shared_name(name);
|
|
4570
4627
|
}
|
|
4571
4628
|
const merged_patch = merge_patches(existing.patch, state2.patch, state2.name);
|
|
4572
4629
|
const merged = {
|
|
@@ -4742,6 +4799,33 @@ __name(reaction_on, "reaction_on");
|
|
|
4742
4799
|
|
|
4743
4800
|
// src/builders/event-builder.ts
|
|
4744
4801
|
import { z as z2 } from "zod";
|
|
4802
|
+
|
|
4803
|
+
// src/internal/sensitive.ts
|
|
4804
|
+
var SENSITIVE = /* @__PURE__ */ Symbol.for("act.sensitive");
|
|
4805
|
+
var is_pii = /* @__PURE__ */ __name((schema) => some_layer(schema, (def) => def[SENSITIVE] === true), "is_pii");
|
|
4806
|
+
function pii_schemas(schema) {
|
|
4807
|
+
const shape = schema.shape;
|
|
4808
|
+
if (shape && typeof shape === "object") {
|
|
4809
|
+
const fields = {};
|
|
4810
|
+
for (const key of Object.keys(shape))
|
|
4811
|
+
if (is_pii(shape[key])) fields[key] = shape[key];
|
|
4812
|
+
return fields;
|
|
4813
|
+
}
|
|
4814
|
+
const options = schema.options;
|
|
4815
|
+
if (Array.isArray(options)) {
|
|
4816
|
+
const fields = {};
|
|
4817
|
+
for (const option of options)
|
|
4818
|
+
for (const [key, field] of Object.entries(
|
|
4819
|
+
pii_schemas(option)
|
|
4820
|
+
))
|
|
4821
|
+
fields[key] ??= field;
|
|
4822
|
+
return fields;
|
|
4823
|
+
}
|
|
4824
|
+
return {};
|
|
4825
|
+
}
|
|
4826
|
+
__name(pii_schemas, "pii_schemas");
|
|
4827
|
+
|
|
4828
|
+
// src/builders/event-builder.ts
|
|
4745
4829
|
function event_tags(schema) {
|
|
4746
4830
|
const pii = pii_schemas(schema);
|
|
4747
4831
|
const pii_dates = {};
|
|
@@ -4816,9 +4900,9 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4816
4900
|
handler_readers.set(event_name, handler_reader);
|
|
4817
4901
|
for (const [name, reaction] of def.reactions) {
|
|
4818
4902
|
const inner = reaction.handler;
|
|
4819
|
-
const
|
|
4820
|
-
Object.defineProperty(
|
|
4821
|
-
reaction.handler =
|
|
4903
|
+
const wrapped2 = /* @__PURE__ */ __name((evt, stream, app) => inner(handler_reader(evt), stream, app), "wrapped");
|
|
4904
|
+
Object.defineProperty(wrapped2, "name", { value: inner.name });
|
|
4905
|
+
reaction.handler = wrapped2;
|
|
4822
4906
|
def.reactions.set(name, reaction);
|
|
4823
4907
|
}
|
|
4824
4908
|
}
|
|
@@ -4862,6 +4946,10 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4862
4946
|
if (readers.size === 0) continue;
|
|
4863
4947
|
state2.view = (event, actor) => (readers.get(event.name) ?? IDENTITY_GATE)(event, actor);
|
|
4864
4948
|
}
|
|
4949
|
+
for (const [action_name, state2] of Object.entries(registry.actions)) {
|
|
4950
|
+
const fields = Object.keys(pii_schemas(state2.actions[action_name]));
|
|
4951
|
+
if (fields.length > 0) sensitive2.set(action_name, fields);
|
|
4952
|
+
}
|
|
4865
4953
|
const advisory = advised.size > 0 ? `Act has ${advised.size} sensitive field(s) whose type isn't a string: ${[...advised].join(", ")}. A caller who may not see one reads "[REDACTED]" or "[SHREDDED]" there instead, which its type doesn't allow. Declare sensitive fields as strings. See docs/docs/guides/sensitive-data.md.` : void 0;
|
|
4866
4954
|
return { sensitive: sensitive2, advisory, query_readers, handler_readers };
|
|
4867
4955
|
}
|
|
@@ -4897,7 +4985,7 @@ function act() {
|
|
|
4897
4985
|
const registry = {
|
|
4898
4986
|
actions: {},
|
|
4899
4987
|
events: {},
|
|
4900
|
-
sensitive_fields: /* @__PURE__ */ __name((
|
|
4988
|
+
sensitive_fields: /* @__PURE__ */ __name((name) => _sf.get(name) ?? [], "sensitive_fields"),
|
|
4901
4989
|
query_gate: /* @__PURE__ */ __name((event_name) => _qg.get(event_name) ?? IDENTITY_GATE, "query_gate"),
|
|
4902
4990
|
disclosure_predicate: /* @__PURE__ */ __name((state_name) => _dp.get(state_name) ?? null, "disclosure_predicate"),
|
|
4903
4991
|
deprecated_events: /* @__PURE__ */ __name((state_name) => _de.get(state_name) ?? EMPTY_DEPRECATED, "deprecated_events"),
|
|
@@ -4926,13 +5014,13 @@ function act() {
|
|
|
4926
5014
|
const lanes = [];
|
|
4927
5015
|
let _built = false;
|
|
4928
5016
|
const read_wrap = /* @__PURE__ */ __name((original) => {
|
|
4929
|
-
const
|
|
5017
|
+
const wrapped2 = /* @__PURE__ */ __name(async (events, stream) => {
|
|
4930
5018
|
const read = events.map((e) => _hr.get(e.name)?.(e) ?? e);
|
|
4931
5019
|
return original(read, stream);
|
|
4932
5020
|
}, "wrapped");
|
|
4933
5021
|
const reset = original[FOLD_RESET];
|
|
4934
|
-
if (reset) Object.defineProperty(
|
|
4935
|
-
return
|
|
5022
|
+
if (reset) Object.defineProperty(wrapped2, FOLD_RESET, { value: reset });
|
|
5023
|
+
return wrapped2;
|
|
4936
5024
|
}, "read_wrap");
|
|
4937
5025
|
const make_batch_handlers = /* @__PURE__ */ __name(() => {
|
|
4938
5026
|
const handlers = new Map(batch_handlers);
|
|
@@ -5023,7 +5111,6 @@ function act() {
|
|
|
5023
5111
|
return reaction_on(event, registry.events, builder);
|
|
5024
5112
|
}, "on"),
|
|
5025
5113
|
build: /* @__PURE__ */ __name((options) => {
|
|
5026
|
-
check("act", options ?? {});
|
|
5027
5114
|
if (!_built) {
|
|
5028
5115
|
for (const proj of pending_projections) add_projection(proj);
|
|
5029
5116
|
for (const proj of fold_projections) {
|
|
@@ -5632,6 +5719,11 @@ var default_scope = unscoped_ports;
|
|
|
5632
5719
|
var extend = /* @__PURE__ */ __name((source, schema, target) => ({ ...target, ...validate("config", source, schema) }), "extend");
|
|
5633
5720
|
var ISO_8601 = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(\.\d+)?(Z|[+-][0-2][0-9]:[0-5][0-9])?$/;
|
|
5634
5721
|
var dateReviver = /* @__PURE__ */ __name((_key, value) => typeof value === "string" && ISO_8601.test(value) ? new Date(value) : value, "dateReviver");
|
|
5722
|
+
function sensitiveFields(schema) {
|
|
5723
|
+
return Object.keys(pii_schemas(schema));
|
|
5724
|
+
}
|
|
5725
|
+
__name(sensitiveFields, "sensitiveFields");
|
|
5726
|
+
var pii_fields = sensitiveFields;
|
|
5635
5727
|
export {
|
|
5636
5728
|
Act,
|
|
5637
5729
|
ActorSchema2 as ActorSchema,
|