@voltro/runtime 0.11.1 → 0.11.2
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/CHANGELOG.md +40 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +300 -296
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -4043,29 +4043,30 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4043
4043
|
for (let n of e) {
|
|
4044
4044
|
let e = /* @__PURE__ */ new Set();
|
|
4045
4045
|
for (let t of n.appliedMixins ?? []) t.id !== void 0 && e.add(t.id);
|
|
4046
|
-
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o;
|
|
4047
|
-
for (let [e, t] of Object.entries(n.fields)) t.unique && r.add(e), t.type === "id" && (r.add(e), t.idScheme !== void 0 && (
|
|
4048
|
-
let
|
|
4049
|
-
for (let e of
|
|
4046
|
+
let r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s;
|
|
4047
|
+
for (let [e, t] of Object.entries(n.fields)) t.unique && r.add(e), t.type === "id" && (r.add(e), t.idScheme !== void 0 && (s = t.idScheme)), t.defaultFactory !== void 0 && i.set(e, t.defaultFactory), t.computed !== void 0 && a.set(e, t.computed), t.generatedAs !== void 0 && o.add(e);
|
|
4048
|
+
let c = n.appliedIndexes ?? [];
|
|
4049
|
+
for (let e of c) {
|
|
4050
4050
|
let t = e.fields[0];
|
|
4051
4051
|
t !== void 0 && r.add(t);
|
|
4052
4052
|
}
|
|
4053
|
-
let
|
|
4053
|
+
let l = {
|
|
4054
4054
|
tableName: n.tableName,
|
|
4055
4055
|
mixinIds: e,
|
|
4056
4056
|
fields: new Set(Object.keys(n.fields)),
|
|
4057
4057
|
indexedFields: r,
|
|
4058
|
-
compositeIndexes:
|
|
4058
|
+
compositeIndexes: c.map((e) => ({
|
|
4059
4059
|
name: e.name,
|
|
4060
4060
|
fields: [...e.fields]
|
|
4061
4061
|
})),
|
|
4062
4062
|
defaultFactories: i,
|
|
4063
4063
|
computedFields: a,
|
|
4064
|
-
|
|
4064
|
+
generatedColumns: o,
|
|
4065
|
+
...s === void 0 ? {} : { idScheme: s },
|
|
4065
4066
|
...n.insertSchema === void 0 ? {} : { insertSchema: n.insertSchema },
|
|
4066
4067
|
...n.validatePatchSchema === void 0 ? {} : { validatePatchSchema: n.validatePatchSchema }
|
|
4067
4068
|
};
|
|
4068
|
-
t.set(n.tableName,
|
|
4069
|
+
t.set(n.tableName, l);
|
|
4069
4070
|
}
|
|
4070
4071
|
return {
|
|
4071
4072
|
tables: t,
|
|
@@ -4083,25 +4084,26 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4083
4084
|
idScheme: (e) => t.get(e)?.idScheme,
|
|
4084
4085
|
defaultFactories: (e) => t.get(e)?.defaultFactories ?? fs,
|
|
4085
4086
|
computedFields: (e) => t.get(e)?.computedFields ?? ps,
|
|
4087
|
+
generatedColumns: (e) => t.get(e)?.generatedColumns ?? ms,
|
|
4086
4088
|
insertSchema: (e) => t.get(e)?.insertSchema,
|
|
4087
4089
|
validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
|
|
4088
4090
|
};
|
|
4089
|
-
}, fs = /* @__PURE__ */ new Map(), ps = /* @__PURE__ */ new Map(), ms = ds([]),
|
|
4091
|
+
}, fs = /* @__PURE__ */ new Map(), ps = /* @__PURE__ */ new Map(), ms = /* @__PURE__ */ new Set(), hs = ds([]), gs = class extends R.TaggedError()("NoRowFound", {
|
|
4090
4092
|
table: R.String,
|
|
4091
4093
|
found: R.Number
|
|
4092
4094
|
}) {
|
|
4093
4095
|
get message() {
|
|
4094
4096
|
return this.found === 0 ? `expected exactly one row in '${this.table}', found none` : `expected exactly one row in '${this.table}', found more than one`;
|
|
4095
4097
|
}
|
|
4096
|
-
},
|
|
4098
|
+
}, _s = class extends R.TaggedError()("OptimisticLockError", {
|
|
4097
4099
|
table: R.String,
|
|
4098
4100
|
expected: R.Number
|
|
4099
4101
|
}) {
|
|
4100
4102
|
get message() {
|
|
4101
4103
|
return `optimistic lock failed on '${this.table}': expected version ${this.expected}`;
|
|
4102
4104
|
}
|
|
4103
|
-
},
|
|
4104
|
-
if (e.length === 1 &&
|
|
4105
|
+
}, vs = (e) => typeof e == "object" && !!e && ("and" in e || "or" in e || "not" in e || "op" in e || "subquery" in e), ys = (e) => {
|
|
4106
|
+
if (e.length === 1 && vs(e[0])) return e[0];
|
|
4105
4107
|
let t = e[0];
|
|
4106
4108
|
if (e.length === 2) return u(t, e[1]);
|
|
4107
4109
|
let n = e[1], r = e[2];
|
|
@@ -4119,11 +4121,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4119
4121
|
case "fts": return o(t, r);
|
|
4120
4122
|
default: return u(t, r);
|
|
4121
4123
|
}
|
|
4122
|
-
},
|
|
4124
|
+
}, bs = (e) => {
|
|
4123
4125
|
let t = m(e);
|
|
4124
4126
|
if (t === void 0) throw Error(`unknown table '${e}' — is it declared with table()?`);
|
|
4125
4127
|
return ae(t);
|
|
4126
|
-
},
|
|
4128
|
+
}, xs = class e {
|
|
4127
4129
|
backend;
|
|
4128
4130
|
scope;
|
|
4129
4131
|
table;
|
|
@@ -4137,7 +4139,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4137
4139
|
return new e(this.backend, this.scope, this.table, t, this.skipTenant, this.skipSoftDelete);
|
|
4138
4140
|
}
|
|
4139
4141
|
where(...e) {
|
|
4140
|
-
return this.clone(this.query.where(
|
|
4142
|
+
return this.clone(this.query.where(ys(e)));
|
|
4141
4143
|
}
|
|
4142
4144
|
orderBy(e, t = "asc") {
|
|
4143
4145
|
return this.clone(this.query.orderBy(e, t));
|
|
@@ -4186,11 +4188,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4186
4188
|
}
|
|
4187
4189
|
async one() {
|
|
4188
4190
|
let e = await this.backend.query(this.scopedQuery().limit(2).descriptor), t = e[0];
|
|
4189
|
-
if (t === void 0) throw new
|
|
4191
|
+
if (t === void 0) throw new gs({
|
|
4190
4192
|
table: this.table,
|
|
4191
4193
|
found: 0
|
|
4192
4194
|
});
|
|
4193
|
-
if (e.length > 1) throw new
|
|
4195
|
+
if (e.length > 1) throw new gs({
|
|
4194
4196
|
table: this.table,
|
|
4195
4197
|
found: e.length
|
|
4196
4198
|
});
|
|
@@ -4206,7 +4208,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4206
4208
|
get descriptor() {
|
|
4207
4209
|
return this.scopedQuery().descriptor;
|
|
4208
4210
|
}
|
|
4209
|
-
},
|
|
4211
|
+
}, Ss = class {
|
|
4210
4212
|
backend;
|
|
4211
4213
|
scope;
|
|
4212
4214
|
table;
|
|
@@ -4217,7 +4219,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4217
4219
|
this.backend = e, this.scope = t, this.table = n;
|
|
4218
4220
|
}
|
|
4219
4221
|
where(...e) {
|
|
4220
|
-
let n =
|
|
4222
|
+
let n = ys(e);
|
|
4221
4223
|
return this.predicate = this.predicate ? t(this.predicate, n) : n, this;
|
|
4222
4224
|
}
|
|
4223
4225
|
unscoped() {
|
|
@@ -4241,7 +4243,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4241
4243
|
}
|
|
4242
4244
|
async set(e) {
|
|
4243
4245
|
let t = await this.backend.updateMany(this.table, e, { where: this.scopedWhere() });
|
|
4244
|
-
if (this.expectedVersion !== void 0 && t === 0) throw new
|
|
4246
|
+
if (this.expectedVersion !== void 0 && t === 0) throw new _s({
|
|
4245
4247
|
table: this.table,
|
|
4246
4248
|
expected: this.expectedVersion
|
|
4247
4249
|
});
|
|
@@ -4250,7 +4252,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4250
4252
|
async restore() {
|
|
4251
4253
|
return this.backend.updateMany(this.table, { deletedAt: null }, { where: this.scopedWhere() });
|
|
4252
4254
|
}
|
|
4253
|
-
},
|
|
4255
|
+
}, Cs = class {
|
|
4254
4256
|
backend;
|
|
4255
4257
|
scope;
|
|
4256
4258
|
table;
|
|
@@ -4260,7 +4262,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4260
4262
|
this.backend = e, this.scope = t, this.table = n;
|
|
4261
4263
|
}
|
|
4262
4264
|
where(...e) {
|
|
4263
|
-
let n =
|
|
4265
|
+
let n = ys(e);
|
|
4264
4266
|
return this.predicate = this.predicate ? t(this.predicate, n) : n, this;
|
|
4265
4267
|
}
|
|
4266
4268
|
unscoped() {
|
|
@@ -4281,36 +4283,38 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4281
4283
|
async hard() {
|
|
4282
4284
|
return this.backend.deleteMany(this.table, { where: this.scopedWhere() });
|
|
4283
4285
|
}
|
|
4284
|
-
},
|
|
4285
|
-
select: (n) => new
|
|
4286
|
-
updateWhere: (n) => new
|
|
4287
|
-
deleteWhere: (n) => new
|
|
4288
|
-
}),
|
|
4286
|
+
}, ws = (e, t) => ({
|
|
4287
|
+
select: (n) => new xs(e, t, n, bs(n)),
|
|
4288
|
+
updateWhere: (n) => new Ss(e, t, n),
|
|
4289
|
+
deleteWhere: (n) => new Cs(e, t, n)
|
|
4290
|
+
}), Ts = "id", Es = (e) => "descriptor" in e ? e.descriptor : e, Ds = (e, t) => {
|
|
4289
4291
|
let n = {};
|
|
4290
4292
|
for (let r of t) e[r] !== void 0 && (n[r] = e[r]);
|
|
4291
4293
|
return n;
|
|
4292
|
-
},
|
|
4294
|
+
}, Os = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", ks = (e) => {
|
|
4293
4295
|
throw new qi({
|
|
4294
4296
|
table: e,
|
|
4295
|
-
reason:
|
|
4297
|
+
reason: Os
|
|
4296
4298
|
});
|
|
4297
|
-
},
|
|
4299
|
+
}, As = (e, n) => {
|
|
4298
4300
|
let r = n.subject.id, i = n.subject.tenantId, a = n.rowFilter ?? In, o = (e, t) => {
|
|
4299
4301
|
let a = { ...t }, o = n.schemaRegistry, s = o.idScheme(e);
|
|
4300
|
-
if (s !== void 0 && a[
|
|
4302
|
+
if (s !== void 0 && a[Ts] == null) if (s.kind === "numeric") delete a[Ts];
|
|
4301
4303
|
else {
|
|
4302
4304
|
let t = f(s, e);
|
|
4303
|
-
t !== null && (a[
|
|
4305
|
+
t !== null && (a[Ts] = t);
|
|
4304
4306
|
}
|
|
4305
4307
|
if (o.hasAudit(e)) {
|
|
4306
4308
|
let e = /* @__PURE__ */ new Date();
|
|
4307
4309
|
"createdAt" in a || (a.createdAt = e), "updatedAt" in a || (a.updatedAt = e), r !== null && ("createdBy" in a || (a.createdBy = r), "updatedBy" in a || (a.updatedBy = r));
|
|
4308
4310
|
}
|
|
4309
|
-
o.hasTenant(e) && ("tenantId" in a || (i === null &&
|
|
4311
|
+
o.hasTenant(e) && ("tenantId" in a || (i === null && ks(e), a.tenantId = i));
|
|
4310
4312
|
let c = o.defaultFactories(e);
|
|
4311
4313
|
if (c.size > 0) for (let [e, t] of c) (!(e in a) || a[e] === void 0) && (a[e] = t());
|
|
4312
4314
|
let l = o.computedFields(e);
|
|
4313
4315
|
if (l.size > 0) for (let [e, t] of l) a[e] = t(a);
|
|
4316
|
+
let u = o.generatedColumns(e);
|
|
4317
|
+
if (u.size > 0) for (let e of u) delete a[e];
|
|
4314
4318
|
return a;
|
|
4315
4319
|
}, d = (e, t) => {
|
|
4316
4320
|
if (!n.schemaRegistry.hasAudit(e)) return t;
|
|
@@ -4433,7 +4437,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4433
4437
|
let n = (await e.query({
|
|
4434
4438
|
table: t,
|
|
4435
4439
|
predicate: {
|
|
4436
|
-
column:
|
|
4440
|
+
column: Ts,
|
|
4437
4441
|
op: "eq",
|
|
4438
4442
|
value: r
|
|
4439
4443
|
},
|
|
@@ -4454,7 +4458,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4454
4458
|
}), D = async (e, t) => de(e, {
|
|
4455
4459
|
...t,
|
|
4456
4460
|
where: fe(e, t.where)
|
|
4457
|
-
}), O =
|
|
4461
|
+
}), O = ws({
|
|
4458
4462
|
query: ae,
|
|
4459
4463
|
updateMany: le,
|
|
4460
4464
|
deleteMany: de,
|
|
@@ -4467,26 +4471,26 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4467
4471
|
return {
|
|
4468
4472
|
query: oe,
|
|
4469
4473
|
one: (async (e) => {
|
|
4470
|
-
let t =
|
|
4474
|
+
let t = Es(e), n = await oe({
|
|
4471
4475
|
...t,
|
|
4472
4476
|
take: 2
|
|
4473
4477
|
}), r = n[0];
|
|
4474
|
-
if (r === void 0) throw new
|
|
4478
|
+
if (r === void 0) throw new gs({
|
|
4475
4479
|
table: t.table,
|
|
4476
4480
|
found: 0
|
|
4477
4481
|
});
|
|
4478
|
-
if (n.length > 1) throw new
|
|
4482
|
+
if (n.length > 1) throw new gs({
|
|
4479
4483
|
table: t.table,
|
|
4480
4484
|
found: n.length
|
|
4481
4485
|
});
|
|
4482
4486
|
return r;
|
|
4483
4487
|
}),
|
|
4484
4488
|
first: (async (e) => (await oe({
|
|
4485
|
-
...
|
|
4489
|
+
...Es(e),
|
|
4486
4490
|
take: 1
|
|
4487
4491
|
}))[0] ?? null),
|
|
4488
4492
|
maybeOne: (async (e) => (await oe({
|
|
4489
|
-
...
|
|
4493
|
+
...Es(e),
|
|
4490
4494
|
take: 1
|
|
4491
4495
|
}))[0] ?? null),
|
|
4492
4496
|
insert: async (t, n) => {
|
|
@@ -4504,7 +4508,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4504
4508
|
select: O.select,
|
|
4505
4509
|
update: ((e, t, n) => t === void 0 ? O.updateWhere(e) : se(e, t, n)),
|
|
4506
4510
|
delete: ((e, t) => t === void 0 ? O.deleteWhere(e) : ce(e, t)),
|
|
4507
|
-
applyDefined:
|
|
4511
|
+
applyDefined: Ds,
|
|
4508
4512
|
hardDelete: async (t, n) => e.delete(t, n),
|
|
4509
4513
|
updateMany: E,
|
|
4510
4514
|
deleteMany: D,
|
|
@@ -4520,32 +4524,32 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4520
4524
|
let a = await p(t, i, () => e.insertIgnore(t, x(t, y(t, i)), r));
|
|
4521
4525
|
return T(t, [a])[0];
|
|
4522
4526
|
},
|
|
4523
|
-
transactional: (t) => e.transactional(async (e) => t(
|
|
4527
|
+
transactional: (t) => e.transactional(async (e) => t(As(e, n))),
|
|
4524
4528
|
...e.raw ? { raw: e.raw.bind(e) } : {},
|
|
4525
4529
|
onChange: (t) => e.onChange(t),
|
|
4526
4530
|
injectExternalChange: (t) => e.injectExternalChange(t),
|
|
4527
4531
|
...e.changeScope === void 0 ? {} : { changeScope: e.changeScope }
|
|
4528
4532
|
};
|
|
4529
|
-
},
|
|
4533
|
+
}, js = class extends R.TaggedError()("CircuitOpen", {
|
|
4530
4534
|
name: R.String,
|
|
4531
4535
|
retryAfterMs: R.Number
|
|
4532
|
-
}) {},
|
|
4536
|
+
}) {}, Ms = {
|
|
4533
4537
|
tag: "closed",
|
|
4534
4538
|
failureCount: 0,
|
|
4535
4539
|
halfOpenSuccesses: 0,
|
|
4536
4540
|
openedAt: 0
|
|
4537
|
-
},
|
|
4538
|
-
let t = e.name ?? "circuit", n = We.toMillis(We.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* L.make(
|
|
4541
|
+
}, Ns = { make: (e) => N.gen(function* () {
|
|
4542
|
+
let t = e.name ?? "circuit", n = We.toMillis(We.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* L.make(Ms), o = N.gen(function* () {
|
|
4539
4543
|
let e = yield* L.get(a);
|
|
4540
4544
|
if (e.tag === "half-open") {
|
|
4541
4545
|
let t = e.halfOpenSuccesses + 1;
|
|
4542
|
-
yield* L.set(a, t >= r ?
|
|
4546
|
+
yield* L.set(a, t >= r ? Ms : {
|
|
4543
4547
|
...e,
|
|
4544
4548
|
halfOpenSuccesses: t
|
|
4545
4549
|
});
|
|
4546
4550
|
return;
|
|
4547
4551
|
}
|
|
4548
|
-
e.failureCount !== 0 && (yield* L.set(a,
|
|
4552
|
+
e.failureCount !== 0 && (yield* L.set(a, Ms));
|
|
4549
4553
|
}), s = N.gen(function* () {
|
|
4550
4554
|
let t = yield* Ve.currentTimeMillis, n = yield* L.get(a);
|
|
4551
4555
|
if (n.tag === "half-open" || n.tag === "open") {
|
|
@@ -4583,7 +4587,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4583
4587
|
if (j.isInterruptedOnly(e)) return N.void;
|
|
4584
4588
|
let t = j.failureOption(e), n = t._tag === "Some" ? t.value : void 0;
|
|
4585
4589
|
return i(n) ? s : N.void;
|
|
4586
|
-
})) : yield* N.fail(new
|
|
4590
|
+
})) : yield* N.fail(new js({
|
|
4587
4591
|
name: t,
|
|
4588
4592
|
retryAfterMs: n
|
|
4589
4593
|
}));
|
|
@@ -4592,25 +4596,25 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4592
4596
|
value: L.get(a).pipe(N.map((e) => e.tag)),
|
|
4593
4597
|
enumerable: !0
|
|
4594
4598
|
}), Object.defineProperty(u, "reset", {
|
|
4595
|
-
value: L.set(a,
|
|
4599
|
+
value: L.set(a, Ms),
|
|
4596
4600
|
enumerable: !0
|
|
4597
4601
|
}), u;
|
|
4598
|
-
}) },
|
|
4599
|
-
|
|
4600
|
-
},
|
|
4601
|
-
|
|
4602
|
-
},
|
|
4603
|
-
let n = t.scopes === void 0 ? ze(t.id ?? "system") : ze(t.id ?? "system", t.scopes), r = t.store ??
|
|
4602
|
+
}) }, Ps, Fs = (e) => {
|
|
4603
|
+
Ps = e;
|
|
4604
|
+
}, Is = () => {
|
|
4605
|
+
Ps = void 0;
|
|
4606
|
+
}, Ls = () => Ps, Rs = async (e, t = {}) => {
|
|
4607
|
+
let n = t.scopes === void 0 ? ze(t.id ?? "system") : ze(t.id ?? "system", t.scopes), r = t.store ?? Ps?.dataStore, i = t.schemaRegistry ?? Ps?.schemaRegistry, a = t.dialect ?? Ps?.dialect;
|
|
4604
4608
|
if (r === void 0 || i === void 0) throw Error("runAsSystem: no data store available — register one at boot via setSystemStoreHandle({ dataStore, schemaRegistry }) or pass { store, schemaRegistry } in the options.");
|
|
4605
4609
|
return e({
|
|
4606
4610
|
subject: n,
|
|
4607
|
-
store:
|
|
4611
|
+
store: As(r, {
|
|
4608
4612
|
subject: n,
|
|
4609
4613
|
schemaRegistry: i,
|
|
4610
4614
|
...a === void 0 ? {} : { dialect: a }
|
|
4611
4615
|
})
|
|
4612
4616
|
});
|
|
4613
|
-
},
|
|
4617
|
+
}, zs = (e) => {
|
|
4614
4618
|
let { currentRegion: t, replicaRegions: n, inner: r } = e, i = (e) => {
|
|
4615
4619
|
if (t === void 0) return {
|
|
4616
4620
|
sameRegion: [],
|
|
@@ -4638,7 +4642,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4638
4642
|
return r.loadSnapshot();
|
|
4639
4643
|
}
|
|
4640
4644
|
};
|
|
4641
|
-
},
|
|
4645
|
+
}, Bs = (e = process.env) => {
|
|
4642
4646
|
for (let t of [
|
|
4643
4647
|
"VOLTRO_REGION",
|
|
4644
4648
|
"AWS_REGION",
|
|
@@ -4650,7 +4654,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4650
4654
|
let n = e[t];
|
|
4651
4655
|
if (typeof n == "string" && n.length > 0) return n;
|
|
4652
4656
|
}
|
|
4653
|
-
},
|
|
4657
|
+
}, Vs = () => {
|
|
4654
4658
|
let e = {
|
|
4655
4659
|
primary: 0,
|
|
4656
4660
|
lagByReplica: /* @__PURE__ */ new Map()
|
|
@@ -4675,7 +4679,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4675
4679
|
e.lagByReplica.set(t, n);
|
|
4676
4680
|
}
|
|
4677
4681
|
};
|
|
4678
|
-
},
|
|
4682
|
+
}, Hs = Symbol.for("@voltro/ScheduleDefinition"), Us = (e) => typeof e == "object" && !!e && Hs in e, Ws = 30 * 6e4, Gs = (e) => {
|
|
4679
4683
|
let t = M.parse(e.cron, e.timezone);
|
|
4680
4684
|
if (Ge.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
|
|
4681
4685
|
if (!e.timezone || e.timezone.trim() === "") throw Error(`defineSchedule("${e.name}"): timezone is required (e.g. "UTC", "Europe/Berlin")`);
|
|
@@ -4684,18 +4688,18 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4684
4688
|
...e,
|
|
4685
4689
|
onOverlap: e.onOverlap ?? "skip",
|
|
4686
4690
|
backfill: e.backfill ?? "skip",
|
|
4687
|
-
maxRuntimeMs: e.maxRuntimeMs ??
|
|
4688
|
-
[
|
|
4691
|
+
maxRuntimeMs: e.maxRuntimeMs ?? Ws,
|
|
4692
|
+
[Hs]: !0
|
|
4689
4693
|
};
|
|
4690
|
-
},
|
|
4694
|
+
}, Ks = (e) => M.unsafeParse(e.cron, e.timezone), qs = (e, t = /* @__PURE__ */ new Date()) => M.next(Ks(e), t), Z = "_voltro_wakeups", Js = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Ys = (e) => ({
|
|
4691
4695
|
tenantId: String(e.tenantId),
|
|
4692
4696
|
kind: String(e.kind),
|
|
4693
4697
|
refId: String(e.refId),
|
|
4694
4698
|
wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
|
|
4695
4699
|
status: e.status === "fired" ? "fired" : "pending"
|
|
4696
|
-
}),
|
|
4700
|
+
}), Xs = async (e, t) => {
|
|
4697
4701
|
await e.upsert(Z, {
|
|
4698
|
-
id:
|
|
4702
|
+
id: Js(t),
|
|
4699
4703
|
tenantId: t.tenantId,
|
|
4700
4704
|
kind: t.kind,
|
|
4701
4705
|
refId: t.refId,
|
|
@@ -4705,7 +4709,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4705
4709
|
conflictColumns: ["id"],
|
|
4706
4710
|
update: ["wakeAt", "status"]
|
|
4707
4711
|
});
|
|
4708
|
-
},
|
|
4712
|
+
}, Zs = async (e, t) => e.delete(Z, Js(t)), Qs = async (e, t) => await e.update(Z, Js(t), { status: "fired" }) !== null, $s = (e, t) => ({ and: [{
|
|
4709
4713
|
column: "id",
|
|
4710
4714
|
op: "eq",
|
|
4711
4715
|
value: e
|
|
@@ -4713,16 +4717,16 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4713
4717
|
column: "status",
|
|
4714
4718
|
op: "eq",
|
|
4715
4719
|
value: t
|
|
4716
|
-
}] }),
|
|
4717
|
-
await e.updateMany(Z, { status: "pending" }, { where:
|
|
4718
|
-
},
|
|
4720
|
+
}] }), ec = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: $s(Js(t), "pending") }) > 0, tc = async (e, t) => {
|
|
4721
|
+
await e.updateMany(Z, { status: "pending" }, { where: $s(Js(t), "fired") });
|
|
4722
|
+
}, nc = {
|
|
4719
4723
|
column: "status",
|
|
4720
4724
|
op: "eq",
|
|
4721
4725
|
value: "pending"
|
|
4722
|
-
},
|
|
4726
|
+
}, rc = async (e, t) => {
|
|
4723
4727
|
let n = {
|
|
4724
4728
|
table: Z,
|
|
4725
|
-
predicate:
|
|
4729
|
+
predicate: nc,
|
|
4726
4730
|
order: [{
|
|
4727
4731
|
column: "wakeAt",
|
|
4728
4732
|
direction: "asc"
|
|
@@ -4731,18 +4735,18 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4731
4735
|
skip: void 0,
|
|
4732
4736
|
projection: void 0
|
|
4733
4737
|
};
|
|
4734
|
-
return (await e.query(n)).map(
|
|
4735
|
-
},
|
|
4736
|
-
let r = await
|
|
4738
|
+
return (await e.query(n)).map(Ys);
|
|
4739
|
+
}, ic = async (e, t, n = 500) => {
|
|
4740
|
+
let r = await rc(e, n), i = t.getTime();
|
|
4737
4741
|
return r.filter((e) => e.wakeAt.getTime() <= i);
|
|
4738
|
-
},
|
|
4742
|
+
}, ac = async (e) => (await rc(e, 1))[0] ?? null, oc = {
|
|
4739
4743
|
column: "status",
|
|
4740
4744
|
op: "eq",
|
|
4741
4745
|
value: "fired"
|
|
4742
|
-
},
|
|
4746
|
+
}, sc = async (e, t = {}) => {
|
|
4743
4747
|
let n = {
|
|
4744
4748
|
table: Z,
|
|
4745
|
-
predicate:
|
|
4749
|
+
predicate: oc,
|
|
4746
4750
|
order: [{
|
|
4747
4751
|
column: "wakeAt",
|
|
4748
4752
|
direction: "asc"
|
|
@@ -4753,12 +4757,12 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4753
4757
|
}, r = await e.query(n), i = t.firedOlderThan?.getTime(), a = 0;
|
|
4754
4758
|
for (let t of r) i !== void 0 && (t.wakeAt instanceof Date ? t.wakeAt : new Date(String(t.wakeAt))).getTime() >= i || await e.delete(Z, String(t.id)) && a++;
|
|
4755
4759
|
return a;
|
|
4756
|
-
},
|
|
4760
|
+
}, cc = Ki, lc = "default", uc = {
|
|
4757
4761
|
kind: "single",
|
|
4758
4762
|
tryClaim: async () => !0
|
|
4759
|
-
},
|
|
4763
|
+
}, dc = "_voltro_schedule_claims", fc = (e, t, n) => {
|
|
4760
4764
|
let r = async (t) => (await e.query({
|
|
4761
|
-
table:
|
|
4765
|
+
table: dc,
|
|
4762
4766
|
order: [],
|
|
4763
4767
|
predicate: void 0,
|
|
4764
4768
|
projection: ["id"],
|
|
@@ -4773,7 +4777,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4773
4777
|
if (await r(s)) return !1;
|
|
4774
4778
|
} catch {}
|
|
4775
4779
|
try {
|
|
4776
|
-
return await e.insert(
|
|
4780
|
+
return await e.insert(dc, {
|
|
4777
4781
|
id: s,
|
|
4778
4782
|
scheduleName: i,
|
|
4779
4783
|
bucket: o,
|
|
@@ -4791,12 +4795,12 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4791
4795
|
}
|
|
4792
4796
|
}
|
|
4793
4797
|
};
|
|
4794
|
-
},
|
|
4798
|
+
}, pc = "_voltro_schedule_runs", mc = async (e, t) => {
|
|
4795
4799
|
let { store: n, coordinator: r, buildContext: i, replicaId: a, log: o, onRunEvent: s, interceptFire: c } = t, l = t.dormancy === "sleep", u = t.dormancyTenantId ?? "default", d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map(), m = !1, h = new Map(e.map((e) => [e.name, e])), g = (e, t) => {
|
|
4796
|
-
s?.(e,
|
|
4800
|
+
s?.(e, gc(t));
|
|
4797
4801
|
}, _ = async (e, t, r, i, s, c) => {
|
|
4798
4802
|
try {
|
|
4799
|
-
let o = `sr_${ve()}`, l = await n.insert(
|
|
4803
|
+
let o = `sr_${ve()}`, l = await n.insert(pc, {
|
|
4800
4804
|
id: o,
|
|
4801
4805
|
name: e.name,
|
|
4802
4806
|
status: i,
|
|
@@ -4821,7 +4825,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4821
4825
|
}
|
|
4822
4826
|
}, v = async (e, t) => {
|
|
4823
4827
|
try {
|
|
4824
|
-
let r = await n.update(
|
|
4828
|
+
let r = await n.update(pc, e, t);
|
|
4825
4829
|
r && g("update", r);
|
|
4826
4830
|
} catch (t) {
|
|
4827
4831
|
o.warn("schedule: failed to record run finish", {
|
|
@@ -4832,7 +4836,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4832
4836
|
}, y = async (e) => {
|
|
4833
4837
|
try {
|
|
4834
4838
|
let t = await n.query({
|
|
4835
|
-
table:
|
|
4839
|
+
table: pc,
|
|
4836
4840
|
predicate: {
|
|
4837
4841
|
_tag: "leaf",
|
|
4838
4842
|
column: "status",
|
|
@@ -4867,7 +4871,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4867
4871
|
scheduleName: e.name,
|
|
4868
4872
|
trigger: n,
|
|
4869
4873
|
runId: s,
|
|
4870
|
-
subject:
|
|
4874
|
+
subject: cc
|
|
4871
4875
|
})
|
|
4872
4876
|
};
|
|
4873
4877
|
try {
|
|
@@ -4898,7 +4902,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4898
4902
|
let n = Q(t).includes("exceeded maxRuntimeMs");
|
|
4899
4903
|
s && await v(s, {
|
|
4900
4904
|
status: "failed",
|
|
4901
|
-
errorTag: n ? "timeout" :
|
|
4905
|
+
errorTag: n ? "timeout" : hc(t),
|
|
4902
4906
|
errorMessage: Q(t),
|
|
4903
4907
|
completedAt: /* @__PURE__ */ new Date(),
|
|
4904
4908
|
durationMs: Date.now() - l
|
|
@@ -4955,8 +4959,8 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4955
4959
|
}
|
|
4956
4960
|
}, C = async (e) => {
|
|
4957
4961
|
try {
|
|
4958
|
-
let t = M.next(
|
|
4959
|
-
await
|
|
4962
|
+
let t = M.next(Ks(e), /* @__PURE__ */ new Date());
|
|
4963
|
+
await Xs(n, {
|
|
4960
4964
|
tenantId: u,
|
|
4961
4965
|
kind: "schedule",
|
|
4962
4966
|
refId: e.name,
|
|
@@ -4970,7 +4974,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4970
4974
|
}
|
|
4971
4975
|
}, ee = 2147483647, te = (e) => {
|
|
4972
4976
|
if (m) return;
|
|
4973
|
-
let n =
|
|
4977
|
+
let n = Ks(e), r = M.next(n, /* @__PURE__ */ new Date()), i = () => {
|
|
4974
4978
|
if (m) return;
|
|
4975
4979
|
let n = r.getTime() - Date.now();
|
|
4976
4980
|
if (n > ee) {
|
|
@@ -4992,7 +4996,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
4992
4996
|
let r;
|
|
4993
4997
|
try {
|
|
4994
4998
|
let t = (await n.query({
|
|
4995
|
-
table:
|
|
4999
|
+
table: pc,
|
|
4996
5000
|
order: [{
|
|
4997
5001
|
column: "scheduledAt",
|
|
4998
5002
|
direction: "desc"
|
|
@@ -5011,7 +5015,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5011
5015
|
return;
|
|
5012
5016
|
}
|
|
5013
5017
|
if (!r) return;
|
|
5014
|
-
let i =
|
|
5018
|
+
let i = Ks(e), a = [], s = M.next(i, r), c = Date.now();
|
|
5015
5019
|
for (; s.getTime() < c && a.length < 1e3;) a.push(s), s = M.next(i, s);
|
|
5016
5020
|
if (a.length !== 0) if (o.info("schedule: backfill", {
|
|
5017
5021
|
name: e.name,
|
|
@@ -5056,11 +5060,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5056
5060
|
d.clear(), o.info("scheduler: stopped");
|
|
5057
5061
|
}
|
|
5058
5062
|
};
|
|
5059
|
-
}, Q = (e) => e?.message ?? String(e),
|
|
5063
|
+
}, Q = (e) => e?.message ?? String(e), hc = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, gc = (e) => {
|
|
5060
5064
|
let t = {};
|
|
5061
5065
|
for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
|
|
5062
5066
|
return t;
|
|
5063
|
-
},
|
|
5067
|
+
}, _c = (e, t, n, r) => {
|
|
5064
5068
|
let i = !1, a, o = async () => {
|
|
5065
5069
|
if (i) return;
|
|
5066
5070
|
let a = new Date(Math.floor(Date.now() / t) * t), o = !1;
|
|
@@ -5090,7 +5094,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5090
5094
|
i || (i = !0, a && clearInterval(a), a = void 0);
|
|
5091
5095
|
}
|
|
5092
5096
|
};
|
|
5093
|
-
},
|
|
5097
|
+
}, vc = (e) => (t, n, r) => _c(t, n, r, e), yc = E("_voltro_schedule_runs", {
|
|
5094
5098
|
id: v({ prefix: "schrun" }),
|
|
5095
5099
|
name: D(),
|
|
5096
5100
|
status: D().oneOf([
|
|
@@ -5120,13 +5124,13 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5120
5124
|
]).nullable(),
|
|
5121
5125
|
replicaId: D().nullable(),
|
|
5122
5126
|
result: C().nullable()
|
|
5123
|
-
}).index(["name", "scheduledAt"]).index(["status"]),
|
|
5127
|
+
}).index(["name", "scheduledAt"]).index(["status"]), bc = E("_voltro_schedule_claims", {
|
|
5124
5128
|
id: v({ prefix: "schclaim" }),
|
|
5125
5129
|
scheduleName: D(),
|
|
5126
5130
|
bucket: D(),
|
|
5127
5131
|
claimedBy: D(),
|
|
5128
5132
|
claimedAt: O()
|
|
5129
|
-
}).index(["scheduleName", "bucket"]).index(["claimedAt"]),
|
|
5133
|
+
}).index(["scheduleName", "bucket"]).index(["claimedAt"]), xc = E("_voltro_traces", {
|
|
5130
5134
|
id: v({ prefix: "span" }),
|
|
5131
5135
|
traceId: D(),
|
|
5132
5136
|
spanId: D(),
|
|
@@ -5150,7 +5154,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5150
5154
|
durationMs: b(),
|
|
5151
5155
|
attributes: C().nullable(),
|
|
5152
5156
|
events: C().nullable()
|
|
5153
|
-
}).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]),
|
|
5157
|
+
}).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Sc = E("_voltro_undo_log", {
|
|
5154
5158
|
id: v({ prefix: "undo" }),
|
|
5155
5159
|
tag: D(),
|
|
5156
5160
|
label: D().nullable(),
|
|
@@ -5161,25 +5165,25 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5161
5165
|
crossesAction: r().default(!1),
|
|
5162
5166
|
undone: r().default(!1),
|
|
5163
5167
|
createdAt: O().default("now")
|
|
5164
|
-
}).index(["subjectId", "createdAt"]).reactive(),
|
|
5168
|
+
}).index(["subjectId", "createdAt"]).reactive(), Cc = (e = process.env) => {
|
|
5165
5169
|
let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
|
|
5166
5170
|
return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
|
|
5167
|
-
},
|
|
5171
|
+
}, wc = (e) => e.startsWith("_voltro"), Tc = async (e, t, n) => (await e.query({
|
|
5168
5172
|
table: t,
|
|
5169
5173
|
predicate: u("id", n),
|
|
5170
5174
|
order: []
|
|
5171
|
-
}))[0] ?? null,
|
|
5175
|
+
}))[0] ?? null, Ec = (e, t) => new Proxy(e, { get(e, n, r) {
|
|
5172
5176
|
if (n === "insert") return async (n, r) => {
|
|
5173
5177
|
let i = await e.insert(n, r);
|
|
5174
|
-
return
|
|
5178
|
+
return wc(n) || t({
|
|
5175
5179
|
table: n,
|
|
5176
5180
|
op: "insert",
|
|
5177
5181
|
next: i
|
|
5178
5182
|
}), i;
|
|
5179
5183
|
};
|
|
5180
5184
|
if (n === "update") return async (n, r, i) => {
|
|
5181
|
-
let a =
|
|
5182
|
-
return
|
|
5185
|
+
let a = wc(n) ? null : await Tc(e, n, r), o = await e.update(n, r, i);
|
|
5186
|
+
return wc(n) || t({
|
|
5183
5187
|
table: n,
|
|
5184
5188
|
op: "update",
|
|
5185
5189
|
id: r,
|
|
@@ -5188,8 +5192,8 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5188
5192
|
}), o;
|
|
5189
5193
|
};
|
|
5190
5194
|
if (n === "delete") return async (n, r) => {
|
|
5191
|
-
let i =
|
|
5192
|
-
return !
|
|
5195
|
+
let i = wc(n) ? null : await Tc(e, n, r), a = await e.delete(n, r);
|
|
5196
|
+
return !wc(n) && a && t({
|
|
5193
5197
|
table: n,
|
|
5194
5198
|
op: "delete",
|
|
5195
5199
|
id: r,
|
|
@@ -5198,10 +5202,10 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5198
5202
|
};
|
|
5199
5203
|
let i = Reflect.get(e, n, r);
|
|
5200
5204
|
return typeof i == "function" ? i.bind(e) : i;
|
|
5201
|
-
} }),
|
|
5205
|
+
} }), Dc = (e) => {
|
|
5202
5206
|
let t = [];
|
|
5203
5207
|
return {
|
|
5204
|
-
tx:
|
|
5208
|
+
tx: Ec(e, (e) => t.push(e)),
|
|
5205
5209
|
persist: async (e, n) => {
|
|
5206
5210
|
if (t.length === 0 || n.tag.startsWith("__voltro")) return;
|
|
5207
5211
|
let r = n.subject;
|
|
@@ -5217,14 +5221,14 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5217
5221
|
});
|
|
5218
5222
|
}
|
|
5219
5223
|
};
|
|
5220
|
-
},
|
|
5224
|
+
}, Oc = (e) => {
|
|
5221
5225
|
if (e.id !== void 0) return e.id;
|
|
5222
5226
|
let t = e.next?.id;
|
|
5223
5227
|
if (typeof t == "string") return t;
|
|
5224
5228
|
let n = e.prev?.id;
|
|
5225
5229
|
return typeof n == "string" ? n : void 0;
|
|
5226
|
-
},
|
|
5227
|
-
let t =
|
|
5230
|
+
}, kc = (e) => {
|
|
5231
|
+
let t = Oc(e);
|
|
5228
5232
|
switch (e.op) {
|
|
5229
5233
|
case "insert": return t === void 0 ? null : {
|
|
5230
5234
|
table: e.table,
|
|
@@ -5248,28 +5252,28 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5248
5252
|
row: e.prev
|
|
5249
5253
|
};
|
|
5250
5254
|
}
|
|
5251
|
-
},
|
|
5252
|
-
if (e.crossesAction) throw new
|
|
5255
|
+
}, Ac = (e) => {
|
|
5256
|
+
if (e.crossesAction) throw new jc(e.invocationId, "action");
|
|
5253
5257
|
let t = [];
|
|
5254
5258
|
for (let n = e.changes.length - 1; n >= 0; --n) {
|
|
5255
|
-
let r =
|
|
5259
|
+
let r = kc(e.changes[n]);
|
|
5256
5260
|
r !== null && t.push(r);
|
|
5257
5261
|
}
|
|
5258
5262
|
return t;
|
|
5259
|
-
},
|
|
5263
|
+
}, jc = class extends Error {
|
|
5260
5264
|
invocationId;
|
|
5261
5265
|
boundary;
|
|
5262
5266
|
_tag = "UndoBoundaryError";
|
|
5263
5267
|
constructor(e, t) {
|
|
5264
5268
|
super(t === "action" ? `cannot undo invocation ${e}: it crossed an action (external side effect)` : `cannot undo invocation ${e}: the row changed since (conflict)`), this.invocationId = e, this.boundary = t, this.name = "UndoBoundaryError";
|
|
5265
5269
|
}
|
|
5266
|
-
},
|
|
5270
|
+
}, Mc = (e, t, n = ["updatedAt", "updatedBy"]) => {
|
|
5267
5271
|
if (t == null) return e == null;
|
|
5268
5272
|
if (e == null) return !1;
|
|
5269
5273
|
let r = new Set(n);
|
|
5270
5274
|
for (let [n, i] of Object.entries(t)) if (!r.has(n) && !Object.is(e[n], i) && JSON.stringify(e[n]) !== JSON.stringify(i)) return !1;
|
|
5271
5275
|
return !0;
|
|
5272
|
-
},
|
|
5276
|
+
}, Nc = class {
|
|
5273
5277
|
capacity;
|
|
5274
5278
|
done = [];
|
|
5275
5279
|
undone = [];
|
|
@@ -5305,7 +5309,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5305
5309
|
redo: [...this.undone]
|
|
5306
5310
|
};
|
|
5307
5311
|
}
|
|
5308
|
-
},
|
|
5312
|
+
}, Pc = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
|
|
5309
5313
|
table: e.table,
|
|
5310
5314
|
op: "insert",
|
|
5311
5315
|
next: e.new ?? null
|
|
@@ -5322,7 +5326,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5322
5326
|
table: e.table,
|
|
5323
5327
|
op: "delete",
|
|
5324
5328
|
prev: e.old ?? null
|
|
5325
|
-
},
|
|
5329
|
+
}, Fc = async (e, t) => {
|
|
5326
5330
|
switch (t.op) {
|
|
5327
5331
|
case "delete":
|
|
5328
5332
|
await e.delete(t.table, t.id);
|
|
@@ -5340,21 +5344,21 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5340
5344
|
await e.insert(t.table, t.row);
|
|
5341
5345
|
return;
|
|
5342
5346
|
}
|
|
5343
|
-
},
|
|
5344
|
-
for (let n of t) await
|
|
5345
|
-
},
|
|
5347
|
+
}, Ic = async (e, t) => {
|
|
5348
|
+
for (let n of t) await Fc(e, n);
|
|
5349
|
+
}, Lc = (e) => e.request?.subject?.id ?? null, Rc = (e) => e === !0 || e === 1, zc = async (e, t, n) => (await e.query({
|
|
5346
5350
|
table: t,
|
|
5347
5351
|
predicate: u("id", n),
|
|
5348
5352
|
order: []
|
|
5349
|
-
}))[0] ?? null,
|
|
5353
|
+
}))[0] ?? null, Bc = (e) => {
|
|
5350
5354
|
try {
|
|
5351
5355
|
let t = JSON.parse(String(e ?? "[]"));
|
|
5352
5356
|
return Array.isArray(t) ? t : [];
|
|
5353
5357
|
} catch {
|
|
5354
5358
|
return [];
|
|
5355
5359
|
}
|
|
5356
|
-
},
|
|
5357
|
-
let n =
|
|
5360
|
+
}, Vc = (e) => e.id ?? e.next?.id ?? e.prev?.id, Hc = async (e, t) => {
|
|
5361
|
+
let n = Lc(t);
|
|
5358
5362
|
return [...await t.store.query({
|
|
5359
5363
|
table: "_voltro_undo_log",
|
|
5360
5364
|
predicate: u("subjectId", n),
|
|
@@ -5363,68 +5367,68 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5363
5367
|
id: String(e.id),
|
|
5364
5368
|
tag: String(e.tag ?? ""),
|
|
5365
5369
|
label: e.label ?? null,
|
|
5366
|
-
undone:
|
|
5367
|
-
crossesAction:
|
|
5370
|
+
undone: Rc(e.undone),
|
|
5371
|
+
crossesAction: Rc(e.crossesAction),
|
|
5368
5372
|
createdAt: String(e.createdAt ?? "")
|
|
5369
5373
|
}));
|
|
5370
|
-
},
|
|
5371
|
-
let n = await
|
|
5374
|
+
}, Uc = async (e, t) => {
|
|
5375
|
+
let n = await zc(t.store, "_voltro_undo_log", e.invocationId);
|
|
5372
5376
|
if (!n) throw new ke({ invocationId: e.invocationId });
|
|
5373
|
-
if ((n.subjectId ?? null) !==
|
|
5377
|
+
if ((n.subjectId ?? null) !== Lc(t)) throw new Oe({ invocationId: e.invocationId });
|
|
5374
5378
|
return n;
|
|
5375
|
-
},
|
|
5376
|
-
let n = await
|
|
5377
|
-
if (
|
|
5378
|
-
if (
|
|
5379
|
+
}, Wc = async (e, t) => {
|
|
5380
|
+
let n = await Uc(e, t);
|
|
5381
|
+
if (Rc(n.undone)) return { ok: !0 };
|
|
5382
|
+
if (Rc(n.crossesAction)) throw new De({
|
|
5379
5383
|
invocationId: e.invocationId,
|
|
5380
5384
|
reason: "action"
|
|
5381
5385
|
});
|
|
5382
|
-
let r =
|
|
5386
|
+
let r = Bc(n.changes);
|
|
5383
5387
|
for (let n of r) {
|
|
5384
|
-
let r =
|
|
5385
|
-
if (r !== void 0 && !
|
|
5388
|
+
let r = Vc(n);
|
|
5389
|
+
if (r !== void 0 && !Mc(await zc(t.store, n.table, r), n.next ?? null)) throw new De({
|
|
5386
5390
|
invocationId: e.invocationId,
|
|
5387
5391
|
reason: "conflict"
|
|
5388
5392
|
});
|
|
5389
5393
|
}
|
|
5390
5394
|
let i = {
|
|
5391
5395
|
invocationId: e.invocationId,
|
|
5392
|
-
subject:
|
|
5396
|
+
subject: Lc(t),
|
|
5393
5397
|
changes: r,
|
|
5394
5398
|
crossesAction: !1
|
|
5395
5399
|
};
|
|
5396
|
-
return await
|
|
5397
|
-
},
|
|
5398
|
-
let n = await
|
|
5399
|
-
if (!
|
|
5400
|
-
for (let e of
|
|
5401
|
-
let n =
|
|
5400
|
+
return await Ic(t.store, Ac(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
|
|
5401
|
+
}, Gc = async (e, t) => {
|
|
5402
|
+
let n = await Uc(e, t);
|
|
5403
|
+
if (!Rc(n.undone)) return { ok: !0 };
|
|
5404
|
+
for (let e of Bc(n.changes)) {
|
|
5405
|
+
let n = Vc(e);
|
|
5402
5406
|
e.op === "insert" && e.next ? await t.store.insert(e.table, e.next) : e.op === "update" && n !== void 0 && e.next ? await t.store.update(e.table, n, e.next) : e.op === "delete" && n !== void 0 && await t.store.delete(e.table, n);
|
|
5403
5407
|
}
|
|
5404
5408
|
return await t.store.update("_voltro_undo_log", e.invocationId, { undone: !1 }), { ok: !0 };
|
|
5405
|
-
},
|
|
5409
|
+
}, Kc = (e = process.env) => {
|
|
5406
5410
|
let t = (e.VOLTRO_TIMELINE ?? "").toLowerCase();
|
|
5407
5411
|
return t === "off" || t === "0" || t === "false" ? "off" : t === "all" ? "all" : t === "interesting" || t === "on" || t === "1" || t === "true" ? "interesting" : e.NODE_ENV === "production" ? "off" : "interesting";
|
|
5408
|
-
},
|
|
5412
|
+
}, qc = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, Jc = "«redacted»", Yc = (e) => {
|
|
5409
5413
|
if (e == null) return null;
|
|
5410
5414
|
let t = {};
|
|
5411
|
-
for (let [n, r] of Object.entries(e)) t[n] =
|
|
5415
|
+
for (let [n, r] of Object.entries(e)) t[n] = qc.test(n) ? Jc : r;
|
|
5412
5416
|
return t;
|
|
5413
|
-
},
|
|
5417
|
+
}, Xc = (e) => {
|
|
5414
5418
|
let t = e?.id;
|
|
5415
5419
|
return typeof t == "string" ? t : void 0;
|
|
5416
|
-
},
|
|
5420
|
+
}, Zc = (e, t) => {
|
|
5417
5421
|
if (t.op === "insert") {
|
|
5418
|
-
let n =
|
|
5422
|
+
let n = Xc(t.new);
|
|
5419
5423
|
return n === void 0 ? e : e.filter((e) => e.id !== n);
|
|
5420
5424
|
}
|
|
5421
5425
|
if (t.op === "update") {
|
|
5422
5426
|
if (t.old == null) return e;
|
|
5423
|
-
let n =
|
|
5427
|
+
let n = Xc(t.new) ?? Xc(t.old);
|
|
5424
5428
|
return e.map((e) => e.id === n ? t.old : e);
|
|
5425
5429
|
}
|
|
5426
5430
|
return t.old == null ? e : [...e, t.old];
|
|
5427
|
-
},
|
|
5431
|
+
}, Qc = class {
|
|
5428
5432
|
mode;
|
|
5429
5433
|
capacity;
|
|
5430
5434
|
now;
|
|
@@ -5444,8 +5448,8 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5444
5448
|
ts: this.now(),
|
|
5445
5449
|
table: e.table,
|
|
5446
5450
|
op: e.op,
|
|
5447
|
-
old:
|
|
5448
|
-
new:
|
|
5451
|
+
old: Yc(e.old),
|
|
5452
|
+
new: Yc(e.new),
|
|
5449
5453
|
tenantId: n
|
|
5450
5454
|
}), this.ring.length > this.capacity && this.ring.shift(), t;
|
|
5451
5455
|
}
|
|
@@ -5458,23 +5462,23 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5458
5462
|
}
|
|
5459
5463
|
replay(e, t, n) {
|
|
5460
5464
|
let r = this.ring.filter((n) => n.table === e && n.seq > t).sort((e, t) => t.seq - e.seq), i = n;
|
|
5461
|
-
for (let e of r) i =
|
|
5465
|
+
for (let e of r) i = Zc(i, e);
|
|
5462
5466
|
return i;
|
|
5463
5467
|
}
|
|
5464
|
-
},
|
|
5465
|
-
|
|
5466
|
-
},
|
|
5467
|
-
let t =
|
|
5468
|
+
}, $c, el = () => ($c === void 0 && ($c = new Qc(Kc())), $c), tl = (e) => {
|
|
5469
|
+
$c = e;
|
|
5470
|
+
}, nl = (e) => {
|
|
5471
|
+
let t = el();
|
|
5468
5472
|
if (t.enabled) try {
|
|
5469
5473
|
t.record(e);
|
|
5470
5474
|
} catch {}
|
|
5471
|
-
},
|
|
5475
|
+
}, rl = /* @__PURE__ */ new Set([
|
|
5472
5476
|
"count",
|
|
5473
5477
|
"sum",
|
|
5474
5478
|
"avg",
|
|
5475
5479
|
"min",
|
|
5476
5480
|
"max"
|
|
5477
|
-
]),
|
|
5481
|
+
]), il = (e) => {
|
|
5478
5482
|
if (e.joins !== void 0 && e.joins.length > 0) return {
|
|
5479
5483
|
maintainable: !1,
|
|
5480
5484
|
reason: "joins are not maintainable in v1"
|
|
@@ -5496,7 +5500,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5496
5500
|
reason: "v1 maintains exactly one aggregation"
|
|
5497
5501
|
};
|
|
5498
5502
|
let t = e.aggregations[0];
|
|
5499
|
-
return
|
|
5503
|
+
return rl.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
|
|
5500
5504
|
maintainable: !1,
|
|
5501
5505
|
reason: `op '${t.op}' requires a column`
|
|
5502
5506
|
} : {
|
|
@@ -5510,7 +5514,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5510
5514
|
maintainable: !1,
|
|
5511
5515
|
reason: `op '${t.op}' is not maintainable`
|
|
5512
5516
|
};
|
|
5513
|
-
},
|
|
5517
|
+
}, al = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(al), ol = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), sl = (e, t) => {
|
|
5514
5518
|
switch (e.op) {
|
|
5515
5519
|
case "count": return t.count;
|
|
5516
5520
|
case "sum": return t.sum ?? 0;
|
|
@@ -5518,10 +5522,10 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5518
5522
|
case "min":
|
|
5519
5523
|
case "max": return t.count > 0 ? t.extreme ?? null : null;
|
|
5520
5524
|
}
|
|
5521
|
-
},
|
|
5525
|
+
}, cl = (e, t) => {
|
|
5522
5526
|
let n = /* @__PURE__ */ new Map();
|
|
5523
5527
|
for (let r of t) {
|
|
5524
|
-
let t = $(r, e.groupBy), i = n.get(t), a =
|
|
5528
|
+
let t = $(r, e.groupBy), i = n.get(t), a = ol(r, e.column);
|
|
5525
5529
|
if (i === void 0) n.set(t, {
|
|
5526
5530
|
count: 1,
|
|
5527
5531
|
...e.op === "sum" || e.op === "avg" ? { sum: a } : {},
|
|
@@ -5537,10 +5541,10 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5537
5541
|
}
|
|
5538
5542
|
}
|
|
5539
5543
|
return n;
|
|
5540
|
-
},
|
|
5544
|
+
}, ll = (e, t) => [...t.entries()].map(([t, n]) => ({
|
|
5541
5545
|
groupKey: t,
|
|
5542
|
-
value:
|
|
5543
|
-
})),
|
|
5546
|
+
value: sl(e, n)
|
|
5547
|
+
})), ul = (e, t, n) => {
|
|
5544
5548
|
let r = new Map(t), i = /* @__PURE__ */ new Set(), a = (t) => {
|
|
5545
5549
|
let n = $(t, e.groupBy), a = r.get(n);
|
|
5546
5550
|
if (a === void 0) return;
|
|
@@ -5549,7 +5553,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5549
5553
|
r.delete(n);
|
|
5550
5554
|
return;
|
|
5551
5555
|
}
|
|
5552
|
-
let s =
|
|
5556
|
+
let s = ol(t, e.column);
|
|
5553
5557
|
e.op === "min" || e.op === "max" ? (a.extreme !== void 0 && s === a.extreme && i.add(n), r.set(n, {
|
|
5554
5558
|
count: o,
|
|
5555
5559
|
...a.extreme === void 0 ? {} : { extreme: a.extreme }
|
|
@@ -5558,7 +5562,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5558
5562
|
...e.op === "sum" || e.op === "avg" ? { sum: (a.sum ?? 0) - s } : {}
|
|
5559
5563
|
});
|
|
5560
5564
|
}, o = (t) => {
|
|
5561
|
-
let n = $(t, e.groupBy), i = r.get(n), a =
|
|
5565
|
+
let n = $(t, e.groupBy), i = r.get(n), a = ol(t, e.column);
|
|
5562
5566
|
if (i === void 0) {
|
|
5563
5567
|
r.set(n, {
|
|
5564
5568
|
count: 1,
|
|
@@ -5578,15 +5582,15 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5578
5582
|
state: r,
|
|
5579
5583
|
rescanGroups: [...i]
|
|
5580
5584
|
};
|
|
5581
|
-
},
|
|
5585
|
+
}, dl = (e, t, n, r) => {
|
|
5582
5586
|
if (n.length === 0) return t;
|
|
5583
|
-
let i = new Set(n), a =
|
|
5587
|
+
let i = new Set(n), a = cl(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
|
|
5584
5588
|
for (let e of i) {
|
|
5585
5589
|
let t = a.get(e);
|
|
5586
5590
|
t === void 0 ? o.delete(e) : o.set(e, t);
|
|
5587
5591
|
}
|
|
5588
5592
|
return o;
|
|
5589
|
-
},
|
|
5593
|
+
}, fl = class {
|
|
5590
5594
|
shape;
|
|
5591
5595
|
state = /* @__PURE__ */ new Map();
|
|
5592
5596
|
groups = /* @__PURE__ */ new Map();
|
|
@@ -5594,7 +5598,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5594
5598
|
this.shape = e;
|
|
5595
5599
|
}
|
|
5596
5600
|
seed(e) {
|
|
5597
|
-
this.state =
|
|
5601
|
+
this.state = cl(this.shape, e), this.groups.clear();
|
|
5598
5602
|
for (let t of e) {
|
|
5599
5603
|
let e = $(t, this.shape.groupBy);
|
|
5600
5604
|
this.groups.has(e) || this.groups.set(e, this.groupValues(t));
|
|
@@ -5606,14 +5610,14 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5606
5610
|
let e = $(t, this.shape.groupBy);
|
|
5607
5611
|
this.groups.has(e) || this.groups.set(e, this.groupValues(t));
|
|
5608
5612
|
}
|
|
5609
|
-
let n =
|
|
5613
|
+
let n = ul(this.shape, this.state, e);
|
|
5610
5614
|
this.state = n.state;
|
|
5611
5615
|
for (let e of this.groups.keys()) this.state.has(e) || this.groups.delete(e);
|
|
5612
5616
|
return n.rescanGroups;
|
|
5613
5617
|
}
|
|
5614
5618
|
resolveRescan(e, t) {
|
|
5615
5619
|
if (e.length === 0) return;
|
|
5616
|
-
this.state =
|
|
5620
|
+
this.state = dl(this.shape, this.state, e, t);
|
|
5617
5621
|
let n = new Set(e);
|
|
5618
5622
|
for (let e of t) {
|
|
5619
5623
|
let t = $(e, this.shape.groupBy);
|
|
@@ -5622,7 +5626,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5622
5626
|
for (let e of n) this.state.has(e) || this.groups.delete(e);
|
|
5623
5627
|
}
|
|
5624
5628
|
materialize() {
|
|
5625
|
-
return
|
|
5629
|
+
return ll(this.shape, this.state).map((e) => ({
|
|
5626
5630
|
groupKey: e.groupKey,
|
|
5627
5631
|
group: this.groups.get(e.groupKey) ?? {},
|
|
5628
5632
|
value: e.value
|
|
@@ -5635,7 +5639,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5635
5639
|
for (let r of t) n[r] = e[r];
|
|
5636
5640
|
return n;
|
|
5637
5641
|
}
|
|
5638
|
-
},
|
|
5642
|
+
}, pl = E("_voltro_rebac_tuples", {
|
|
5639
5643
|
id: v({ prefix: "rbct" }),
|
|
5640
5644
|
subjectId: D(),
|
|
5641
5645
|
relation: D(),
|
|
@@ -5647,7 +5651,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5647
5651
|
"subjectId",
|
|
5648
5652
|
"resourceType",
|
|
5649
5653
|
"resourceId"
|
|
5650
|
-
]).reactive(),
|
|
5654
|
+
]).reactive(), ml = async (e, n, r, i) => n === null ? [] : (await e.query({
|
|
5651
5655
|
table: "_voltro_rebac_tuples",
|
|
5652
5656
|
predicate: t(u("subjectId", n), u("resourceType", r), u("resourceId", i)),
|
|
5653
5657
|
order: [],
|
|
@@ -5659,11 +5663,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5659
5663
|
relation: e.relation,
|
|
5660
5664
|
resourceType: e.resourceType,
|
|
5661
5665
|
resourceId: e.resourceId
|
|
5662
|
-
})),
|
|
5666
|
+
})), hl = (e) => ({
|
|
5663
5667
|
id: e.id,
|
|
5664
5668
|
tenantId: e.tenantId,
|
|
5665
5669
|
...e.scopes === void 0 ? {} : { scopes: e.scopes }
|
|
5666
|
-
}),
|
|
5670
|
+
}), gl = (e, t) => {
|
|
5667
5671
|
let n = t.getPolicy ?? Wo;
|
|
5668
5672
|
return (r, i) => {
|
|
5669
5673
|
let a = e[i.tag];
|
|
@@ -5676,7 +5680,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5676
5680
|
if (o === void 0) return s("");
|
|
5677
5681
|
let c = a.resourceId(i.input);
|
|
5678
5682
|
if (c === null || c === "") return s("");
|
|
5679
|
-
let l =
|
|
5683
|
+
let l = hl(i.subject), u = {
|
|
5680
5684
|
type: a.resourceType,
|
|
5681
5685
|
id: c,
|
|
5682
5686
|
tenantId: i.subject.tenantId
|
|
@@ -5686,7 +5690,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5686
5690
|
tuples: e
|
|
5687
5691
|
}) ? r : s(c));
|
|
5688
5692
|
};
|
|
5689
|
-
},
|
|
5693
|
+
}, _l = async (e, n, r) => n === null ? [] : (await e.query({
|
|
5690
5694
|
table: "_voltro_rebac_tuples",
|
|
5691
5695
|
predicate: t(u("subjectId", n), u("resourceType", r)),
|
|
5692
5696
|
order: [],
|
|
@@ -5698,18 +5702,18 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5698
5702
|
relation: e.relation,
|
|
5699
5703
|
resourceType: e.resourceType,
|
|
5700
5704
|
resourceId: e.resourceId
|
|
5701
|
-
})),
|
|
5705
|
+
})), vl = (e) => {
|
|
5702
5706
|
let t = e.getPolicy ?? Wo;
|
|
5703
5707
|
return async (n, r, i, a) => {
|
|
5704
5708
|
let o = t(r);
|
|
5705
5709
|
if (o === void 0) return [];
|
|
5706
|
-
let s =
|
|
5710
|
+
let s = hl(n);
|
|
5707
5711
|
return Qo(s, i, r, a, {
|
|
5708
5712
|
policy: o,
|
|
5709
5713
|
tuples: await e.loadSubjectTuples(s.id, r)
|
|
5710
5714
|
});
|
|
5711
5715
|
};
|
|
5712
|
-
},
|
|
5716
|
+
}, yl = (e) => {
|
|
5713
5717
|
if (typeof e.name != "string" || e.name.length === 0) throw Error("defineReaction: a non-empty `name` is required");
|
|
5714
5718
|
if (e.watch === void 0 || typeof e.watch.table != "string" || e.watch.table.length === 0) throw Error(`reaction '${e.name}': watch.table is required`);
|
|
5715
5719
|
if (e.act === void 0 || e.act.kind !== "agent" && e.act.kind !== "workflow") throw Error(`reaction '${e.name}': act must be { kind: 'agent' | 'workflow', … }`);
|
|
@@ -5717,14 +5721,14 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5717
5721
|
if (e.guards.rateLimit !== void 0 && (e.guards.rateLimit.limit <= 0 || e.guards.rateLimit.windowMs <= 0)) throw Error(`reaction '${e.name}': guards.rateLimit needs positive limit + windowMs`);
|
|
5718
5722
|
if (e.guards.costBudgetUsd !== void 0 && e.guards.costBudgetUsd < 0) throw Error(`reaction '${e.name}': guards.costBudgetUsd must be >= 0`);
|
|
5719
5723
|
return e;
|
|
5720
|
-
},
|
|
5724
|
+
}, bl = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, xl = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, Sl = class {
|
|
5721
5725
|
hits = /* @__PURE__ */ new Map();
|
|
5722
5726
|
allow(e, t, n, r) {
|
|
5723
5727
|
let i = r - n, a = (this.hits.get(e) ?? []).filter((e) => e > i);
|
|
5724
5728
|
return a.length >= t ? (this.hits.set(e, a), !1) : (a.push(r), this.hits.set(e, a), !0);
|
|
5725
5729
|
}
|
|
5726
|
-
},
|
|
5727
|
-
if (t.table !== e.watch.table || !
|
|
5730
|
+
}, Cl = async (e, t, n) => {
|
|
5731
|
+
if (t.table !== e.watch.table || !bl(e.watch.on, t.op)) return "skipped-op";
|
|
5728
5732
|
if (e.when !== void 0 && !e.when(t)) return "skipped-when";
|
|
5729
5733
|
let r = `${e.name}:${e.guards.dedupeKey(t)}`;
|
|
5730
5734
|
if (await n.dedupe.has(r)) return "skipped-dedupe";
|
|
@@ -5733,26 +5737,26 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5733
5737
|
let t = n.now?.() ?? Date.now();
|
|
5734
5738
|
if (!n.rateLimiter.allow(e.name, i.limit, i.windowMs, t)) return "skipped-ratelimit";
|
|
5735
5739
|
}
|
|
5736
|
-
let a =
|
|
5740
|
+
let a = xl(t);
|
|
5737
5741
|
return e.guards.costBudgetUsd !== void 0 && n.checkBudget !== void 0 && !await n.checkBudget(a, e.guards.costBudgetUsd) ? "skipped-budget" : (await n.runAct(e.act, t, {
|
|
5738
5742
|
id: a,
|
|
5739
5743
|
via: "agent"
|
|
5740
5744
|
}), await n.dedupe.add(r), "acted");
|
|
5741
|
-
},
|
|
5745
|
+
}, wl = E("_voltro_wakeups", {
|
|
5742
5746
|
id: v({ prefix: "wakeup" }),
|
|
5743
5747
|
tenantId: D(),
|
|
5744
5748
|
kind: D(),
|
|
5745
5749
|
refId: D(),
|
|
5746
5750
|
wakeAt: O(),
|
|
5747
5751
|
status: D()
|
|
5748
|
-
}).index(["status", "wakeAt"]).index(["tenantId"]),
|
|
5749
|
-
let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await
|
|
5752
|
+
}).index(["status", "wakeAt"]).index(["tenantId"]), Tl = async (e) => {
|
|
5753
|
+
let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await ic(e.store, t, e.batchLimit ?? 100);
|
|
5750
5754
|
if (n.length === 0) return 0;
|
|
5751
5755
|
let r = 0;
|
|
5752
|
-
for (let t of n) if (await
|
|
5756
|
+
for (let t of n) if (await ec(e.store, t)) try {
|
|
5753
5757
|
await e.adapter.wake(t), r++;
|
|
5754
5758
|
} catch (n) {
|
|
5755
|
-
await
|
|
5759
|
+
await tc(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
|
|
5756
5760
|
tenantId: t.tenantId,
|
|
5757
5761
|
kind: t.kind,
|
|
5758
5762
|
refId: t.refId,
|
|
@@ -5760,11 +5764,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5760
5764
|
});
|
|
5761
5765
|
}
|
|
5762
5766
|
return r > 0 && e.log?.info("wake: woke due deployments", { count: r }), r;
|
|
5763
|
-
},
|
|
5767
|
+
}, El = (e, t = 1e3) => {
|
|
5764
5768
|
let n = !1, r, i = async () => {
|
|
5765
5769
|
if (!n) {
|
|
5766
5770
|
try {
|
|
5767
|
-
await
|
|
5771
|
+
await Tl(e);
|
|
5768
5772
|
} catch (t) {
|
|
5769
5773
|
e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
|
|
5770
5774
|
}
|
|
@@ -5774,10 +5778,10 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5774
5778
|
return i(), { stop: () => {
|
|
5775
5779
|
n = !0, r !== void 0 && clearTimeout(r);
|
|
5776
5780
|
} };
|
|
5777
|
-
},
|
|
5781
|
+
}, Dl = (e) => ({ wake: async () => {
|
|
5778
5782
|
await e.start();
|
|
5779
|
-
} }),
|
|
5780
|
-
let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ??
|
|
5783
|
+
} }), Ol = (e) => new Promise((t) => setTimeout(t, e)), kl = (e) => {
|
|
5784
|
+
let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? Ol, i = e.spawnImpl ?? Et, a = e.startTimeoutMs ?? 3e4, o = e.healthPollMs ?? 200, s = e.stopSignal ?? "SIGTERM", c = e.stopGraceMs ?? 1e4, l, u, d = e.healthCheck ?? ((e) => e.ok), f = async () => {
|
|
5781
5785
|
try {
|
|
5782
5786
|
let n = await t(e.healthUrl);
|
|
5783
5787
|
return d(n);
|
|
@@ -5831,11 +5835,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5831
5835
|
},
|
|
5832
5836
|
stop: m
|
|
5833
5837
|
};
|
|
5834
|
-
},
|
|
5838
|
+
}, Al = async (e) => {
|
|
5835
5839
|
if (e.signals.connectedClients() > 0 || e.signals.inFlightRequests() > 0 || e.signals.activeWorkflowExecutions() > 0) return !1;
|
|
5836
|
-
let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await
|
|
5840
|
+
let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await ac(e.store);
|
|
5837
5841
|
return !(n !== null && n.wakeAt.getTime() <= t);
|
|
5838
|
-
},
|
|
5842
|
+
}, jl = (e, t = Date.now) => {
|
|
5839
5843
|
let n;
|
|
5840
5844
|
return {
|
|
5841
5845
|
update: (r) => {
|
|
@@ -5847,7 +5851,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5847
5851
|
n = void 0;
|
|
5848
5852
|
}
|
|
5849
5853
|
};
|
|
5850
|
-
},
|
|
5854
|
+
}, Ml = () => {
|
|
5851
5855
|
let e = 0, t = 0;
|
|
5852
5856
|
return {
|
|
5853
5857
|
onRequestStart: () => {
|
|
@@ -5865,7 +5869,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5865
5869
|
inFlightRequests: () => e,
|
|
5866
5870
|
openConnections: () => t
|
|
5867
5871
|
};
|
|
5868
|
-
},
|
|
5872
|
+
}, Nl = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), Pl = (e, t, n, r) => new Promise((i, a) => {
|
|
5869
5873
|
let o = Qe.request({
|
|
5870
5874
|
host: n,
|
|
5871
5875
|
port: r,
|
|
@@ -5876,7 +5880,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5876
5880
|
t.writeHead(e.statusCode ?? 502, e.headers), e.pipe(t), e.on("end", i), e.on("error", a);
|
|
5877
5881
|
});
|
|
5878
5882
|
o.on("error", a), e.pipe(o);
|
|
5879
|
-
}),
|
|
5883
|
+
}), Fl = (e, t, n, r, i) => new Promise((a, o) => {
|
|
5880
5884
|
let s = Qe.request({
|
|
5881
5885
|
host: r,
|
|
5882
5886
|
port: i,
|
|
@@ -5891,21 +5895,21 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5891
5895
|
};
|
|
5892
5896
|
t.on("close", s), r.on("close", s), r.on("error", o);
|
|
5893
5897
|
}), s.on("error", o), s.end();
|
|
5894
|
-
}),
|
|
5895
|
-
let t =
|
|
5898
|
+
}), Il = (e) => {
|
|
5899
|
+
let t = Nl({
|
|
5896
5900
|
ensureAwake: () => e.supervisor.start(),
|
|
5897
5901
|
...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
|
|
5898
5902
|
}), n = e.activity, r = Qe.createServer((r, i) => {
|
|
5899
|
-
n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() =>
|
|
5903
|
+
n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => Pl(r, i, e.targetHost, e.targetPort)).catch((t) => {
|
|
5900
5904
|
e.log?.warn("wake-router: proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.headersSent || i.writeHead(502), i.end("wake/proxy failed");
|
|
5901
5905
|
});
|
|
5902
5906
|
});
|
|
5903
5907
|
return r.on("upgrade", (r, i, a) => {
|
|
5904
|
-
n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() =>
|
|
5908
|
+
n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => Fl(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
|
|
5905
5909
|
e.log?.warn("wake-router: upgrade proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.destroy();
|
|
5906
5910
|
});
|
|
5907
5911
|
}), r;
|
|
5908
|
-
},
|
|
5912
|
+
}, Ll = async (e) => {
|
|
5909
5913
|
try {
|
|
5910
5914
|
return (await e.query({
|
|
5911
5915
|
table: "_voltro_workflow_runs",
|
|
@@ -5922,15 +5926,15 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5922
5926
|
} catch {
|
|
5923
5927
|
return 0;
|
|
5924
5928
|
}
|
|
5925
|
-
},
|
|
5926
|
-
let t =
|
|
5929
|
+
}, Rl = async (e) => {
|
|
5930
|
+
let t = Dl(e.supervisor), n = await Tl({
|
|
5927
5931
|
store: e.store,
|
|
5928
5932
|
adapter: t,
|
|
5929
5933
|
...e.now === void 0 ? {} : { now: e.now },
|
|
5930
5934
|
...e.log === void 0 ? {} : { log: e.log }
|
|
5931
5935
|
});
|
|
5932
5936
|
n > 0 && e.idleGate.reset();
|
|
5933
|
-
let r = await
|
|
5937
|
+
let r = await Al({
|
|
5934
5938
|
store: e.store,
|
|
5935
5939
|
signals: e.signals,
|
|
5936
5940
|
...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
|
|
@@ -5940,12 +5944,12 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5940
5944
|
woke: n,
|
|
5941
5945
|
stopped: i
|
|
5942
5946
|
};
|
|
5943
|
-
},
|
|
5944
|
-
let t =
|
|
5947
|
+
}, zl = async (e) => {
|
|
5948
|
+
let t = jl(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = Ml(), i = 0, a = e.signals === void 0, o = e.signals ?? {
|
|
5945
5949
|
connectedClients: () => r.openConnections(),
|
|
5946
5950
|
inFlightRequests: () => r.inFlightRequests(),
|
|
5947
5951
|
activeWorkflowExecutions: () => i
|
|
5948
|
-
}, s =
|
|
5952
|
+
}, s = Il({
|
|
5949
5953
|
supervisor: e.supervisor,
|
|
5950
5954
|
targetHost: e.targetHost,
|
|
5951
5955
|
targetPort: e.targetPort,
|
|
@@ -5964,7 +5968,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5964
5968
|
let l = !1, u, d = e.firedRetentionMs ?? 10 * 6e4, f = 0, p = async () => {
|
|
5965
5969
|
if (!l) {
|
|
5966
5970
|
try {
|
|
5967
|
-
if (a && (i = await
|
|
5971
|
+
if (a && (i = await Ll(e.store)), await Rl({
|
|
5968
5972
|
store: e.store,
|
|
5969
5973
|
supervisor: e.supervisor,
|
|
5970
5974
|
signals: o,
|
|
@@ -5972,7 +5976,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5972
5976
|
...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
|
|
5973
5977
|
...e.log === void 0 ? {} : { log: e.log }
|
|
5974
5978
|
}), f++ % 60 == 0) {
|
|
5975
|
-
let t = await
|
|
5979
|
+
let t = await sc(e.store, { firedOlderThan: new Date(Date.now() - d) });
|
|
5976
5980
|
t > 0 && e.log?.info("orchestrator: pruned fired wakeups", { count: t });
|
|
5977
5981
|
}
|
|
5978
5982
|
} catch (t) {
|
|
@@ -5987,14 +5991,14 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
5987
5991
|
l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
|
|
5988
5992
|
}
|
|
5989
5993
|
};
|
|
5990
|
-
},
|
|
5994
|
+
}, Bl = (e) => e, Vl = class extends R.TaggedError()("AnalyticsError", {
|
|
5991
5995
|
provider: R.String,
|
|
5992
5996
|
operation: R.String,
|
|
5993
5997
|
cause: R.String
|
|
5994
|
-
}) {},
|
|
5998
|
+
}) {}, Hl = class extends R.TaggedError()("AnalyticsCapabilityNotSupported", {
|
|
5995
5999
|
provider: R.String,
|
|
5996
6000
|
capability: R.String
|
|
5997
|
-
}) {},
|
|
6001
|
+
}) {}, Ul = class extends He.Tag("@voltro/AnalyticsSink")() {}, Wl = (e, t) => ({
|
|
5998
6002
|
info: e.info,
|
|
5999
6003
|
track: (n) => e.track(n.tenantId === void 0 ? {
|
|
6000
6004
|
...n,
|
|
@@ -6013,20 +6017,20 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6013
6017
|
tenantId: t
|
|
6014
6018
|
} : n),
|
|
6015
6019
|
...e.mirror === void 0 ? {} : { mirror: e.mirror }
|
|
6016
|
-
}),
|
|
6017
|
-
let e = yield*
|
|
6020
|
+
}), Gl = () => N.gen(function* () {
|
|
6021
|
+
let e = yield* Ul, t = yield* N.serviceOption(Ee), n = I.match(t, {
|
|
6018
6022
|
onNone: () => null,
|
|
6019
6023
|
onSome: (e) => e.tenantId ?? null
|
|
6020
6024
|
});
|
|
6021
|
-
return n === null ? e :
|
|
6022
|
-
}),
|
|
6023
|
-
let e = (e) => N.fail(new
|
|
6024
|
-
provider:
|
|
6025
|
+
return n === null ? e : Wl(e, n);
|
|
6026
|
+
}), Kl = "noop", ql = () => {
|
|
6027
|
+
let e = (e) => N.fail(new Hl({
|
|
6028
|
+
provider: Kl,
|
|
6025
6029
|
capability: e
|
|
6026
6030
|
}));
|
|
6027
6031
|
return {
|
|
6028
6032
|
info: {
|
|
6029
|
-
provider:
|
|
6033
|
+
provider: Kl,
|
|
6030
6034
|
capabilities: {
|
|
6031
6035
|
track: !0,
|
|
6032
6036
|
aggregate: !1,
|
|
@@ -6040,8 +6044,8 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6040
6044
|
timeseries: () => e("timeseries"),
|
|
6041
6045
|
topN: () => e("topN")
|
|
6042
6046
|
};
|
|
6043
|
-
},
|
|
6044
|
-
if (e.length === 0) return
|
|
6047
|
+
}, Jl = (e) => {
|
|
6048
|
+
if (e.length === 0) return ql();
|
|
6045
6049
|
if (e.length === 1) return e[0];
|
|
6046
6050
|
let t = {
|
|
6047
6051
|
provider: "compose",
|
|
@@ -6058,7 +6062,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6058
6062
|
discard: !0
|
|
6059
6063
|
}), r = (t, n) => {
|
|
6060
6064
|
let r = e.find((e) => e.info.capabilities[t]);
|
|
6061
|
-
return r === void 0 ? N.fail(new
|
|
6065
|
+
return r === void 0 ? N.fail(new Hl({
|
|
6062
6066
|
provider: "compose",
|
|
6063
6067
|
capability: t
|
|
6064
6068
|
})) : n(r);
|
|
@@ -6081,11 +6085,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6081
6085
|
topN: (e) => r("topN", (t) => t.topN(e)),
|
|
6082
6086
|
...a === void 0 ? {} : { mirror: a }
|
|
6083
6087
|
};
|
|
6084
|
-
},
|
|
6088
|
+
}, Yl = (e) => {
|
|
6085
6089
|
let t = e.filter((e) => e.dispose !== void 0);
|
|
6086
6090
|
return {
|
|
6087
6091
|
kind: "compose",
|
|
6088
|
-
build: (t) =>
|
|
6092
|
+
build: (t) => Jl(e.map((e) => e.build(t))),
|
|
6089
6093
|
tables: e.flatMap((e) => e.tables ?? []),
|
|
6090
6094
|
initialize: (t) => N.forEach(e, (e) => e.initialize ? e.initialize(t) : N.void, {
|
|
6091
6095
|
concurrency: 1,
|
|
@@ -6096,15 +6100,15 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6096
6100
|
discard: !0
|
|
6097
6101
|
}) } : {}
|
|
6098
6102
|
};
|
|
6099
|
-
}, Yl = {
|
|
6100
|
-
kind: "noop",
|
|
6101
|
-
build: () => Kl()
|
|
6102
6103
|
}, Xl = {
|
|
6104
|
+
kind: "noop",
|
|
6105
|
+
build: () => ql()
|
|
6106
|
+
}, Zl = {
|
|
6103
6107
|
tables: [],
|
|
6104
6108
|
detach: () => {}
|
|
6105
|
-
},
|
|
6109
|
+
}, Ql = (e) => {
|
|
6106
6110
|
let { store: t, sink: n, log: r } = e, i = n.mirror;
|
|
6107
|
-
if (i === void 0 || i.tables.length === 0) return
|
|
6111
|
+
if (i === void 0 || i.tables.length === 0) return Zl;
|
|
6108
6112
|
let a = e.run ?? ((e) => N.runPromise(e)), o = i.primaryKey ?? "id", s = new Set(i.tables), c = (e) => {
|
|
6109
6113
|
if (e.op === "delete") {
|
|
6110
6114
|
let t = e.old;
|
|
@@ -6128,11 +6132,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6128
6132
|
tables: i.tables,
|
|
6129
6133
|
detach: l
|
|
6130
6134
|
};
|
|
6131
|
-
},
|
|
6135
|
+
}, $l = (e) => {
|
|
6132
6136
|
let t = typeof e.refresh == "string" ? { interval: e.refresh } : e.refresh, n = e.strategy ?? "replace";
|
|
6133
6137
|
if (n === "merge" && (e.mergeKey === void 0 || e.mergeKey.length === 0)) throw Error(`defineAggregate("${e.name}"): strategy: 'merge' requires mergeKey — the property on each row to upsert by`);
|
|
6134
6138
|
if (e.incremental !== void 0) {
|
|
6135
|
-
let t =
|
|
6139
|
+
let t = il({
|
|
6136
6140
|
aggregations: [{
|
|
6137
6141
|
op: e.incremental.op,
|
|
6138
6142
|
...e.incremental.column === void 0 ? {} : { column: e.incremental.column }
|
|
@@ -6154,47 +6158,47 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6154
6158
|
build: e.build,
|
|
6155
6159
|
...e.incremental === void 0 ? {} : { incremental: e.incremental }
|
|
6156
6160
|
};
|
|
6157
|
-
},
|
|
6161
|
+
}, eu = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, tu = class extends R.TaggedError()("AggregateStale", {
|
|
6158
6162
|
name: R.String,
|
|
6159
6163
|
ageMs: R.Number,
|
|
6160
6164
|
maxAgeMs: R.Number
|
|
6161
|
-
}) {},
|
|
6165
|
+
}) {}, nu = class extends R.TaggedError()("AggregateNotFound", { name: R.String }) {}, ru = class extends R.TaggedError()("AggregateError", {
|
|
6162
6166
|
name: R.String,
|
|
6163
6167
|
operation: R.String,
|
|
6164
6168
|
cause: R.String
|
|
6165
|
-
}) {},
|
|
6166
|
-
return (yield*
|
|
6167
|
-
}),
|
|
6169
|
+
}) {}, iu = class extends He.Tag("@voltro/AggregateRegistry")() {}, au = (e) => N.gen(function* () {
|
|
6170
|
+
return (yield* iu).getHandle(e);
|
|
6171
|
+
}), ou = (e, n, r) => {
|
|
6168
6172
|
if (e.crossTenant || !n.has(e.table) || r == null) return e;
|
|
6169
6173
|
let i = u("tenantId", r);
|
|
6170
6174
|
return {
|
|
6171
6175
|
...e,
|
|
6172
6176
|
predicate: e.predicate ? t(e.predicate, i) : i
|
|
6173
6177
|
};
|
|
6174
|
-
},
|
|
6178
|
+
}, su = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), cu = (e) => e?.type === "user" && e.tenantId === "", lu = (e, n) => {
|
|
6175
6179
|
if (e.includeDeleted || !n.has(e.table)) return e;
|
|
6176
6180
|
let r = S("deletedAt");
|
|
6177
6181
|
return {
|
|
6178
6182
|
...e,
|
|
6179
6183
|
predicate: e.predicate ? t(e.predicate, r) : r
|
|
6180
6184
|
};
|
|
6181
|
-
},
|
|
6185
|
+
}, uu = (e, t) => t, du = (e) => N.runPromiseExit(e).then((e) => {
|
|
6182
6186
|
if (Ke.isSuccess(e)) return e.value;
|
|
6183
6187
|
let t = j.failureOption(e.cause);
|
|
6184
6188
|
throw I.isSome(t) ? t.value : j.squash(e.cause);
|
|
6185
|
-
}),
|
|
6189
|
+
}), fu = (e, t) => e.pipe(N.provideService(Ee, t)), pu = async (e, t, n) => {
|
|
6186
6190
|
let r = await N.runPromise(je(t, e.guards, n));
|
|
6187
6191
|
if (r) throw r;
|
|
6188
|
-
},
|
|
6192
|
+
}, mu = async (e) => {
|
|
6189
6193
|
if (Fn() === void 0) return e;
|
|
6190
|
-
let t = await
|
|
6194
|
+
let t = await du(Ln(e.subject, (e) => {
|
|
6191
6195
|
console.error("[voltro] row filter failed to load", e);
|
|
6192
6196
|
}));
|
|
6193
6197
|
return {
|
|
6194
6198
|
...e,
|
|
6195
6199
|
rowFilter: t
|
|
6196
6200
|
};
|
|
6197
|
-
},
|
|
6201
|
+
}, hu = async (e) => {
|
|
6198
6202
|
let t = `${e.kind}.${e.name}`, n = Date.now(), r = "ok";
|
|
6199
6203
|
try {
|
|
6200
6204
|
if (e.interceptor) {
|
|
@@ -6223,28 +6227,28 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6223
6227
|
status: r
|
|
6224
6228
|
});
|
|
6225
6229
|
}
|
|
6226
|
-
},
|
|
6230
|
+
}, gu = /* @__PURE__ */ new Set([1213, 1205]), _u = /* @__PURE__ */ new Set([
|
|
6227
6231
|
"ER_LOCK_DEADLOCK",
|
|
6228
6232
|
"ER_LOCK_WAIT_TIMEOUT",
|
|
6229
6233
|
"40001",
|
|
6230
6234
|
"40P01"
|
|
6231
|
-
]),
|
|
6235
|
+
]), vu = (e) => {
|
|
6232
6236
|
let t = e;
|
|
6233
6237
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
6234
6238
|
let e = t;
|
|
6235
|
-
if (typeof e.errno == "number" &&
|
|
6239
|
+
if (typeof e.errno == "number" && gu.has(e.errno) || typeof e.code == "string" && _u.has(e.code) || typeof e.sqlState == "string" && _u.has(e.sqlState)) return !0;
|
|
6236
6240
|
t = e.cause;
|
|
6237
6241
|
}
|
|
6238
6242
|
return !1;
|
|
6239
|
-
},
|
|
6240
|
-
let n = t?.delay ?? ((e) =>
|
|
6243
|
+
}, yu = 3, bu = (e) => new Promise((t) => setTimeout(t, e)), xu = async (e, t) => {
|
|
6244
|
+
let n = t?.delay ?? ((e) => bu(e * 20 + Math.floor(Math.random() * 30)));
|
|
6241
6245
|
for (let t = 1;; t++) try {
|
|
6242
6246
|
return await e();
|
|
6243
6247
|
} catch (e) {
|
|
6244
|
-
if (t >=
|
|
6248
|
+
if (t >= yu || !vu(e)) throw e;
|
|
6245
6249
|
await n(t);
|
|
6246
6250
|
}
|
|
6247
|
-
},
|
|
6251
|
+
}, Su = (e) => (t, n, r) => hu({
|
|
6248
6252
|
name: t.descriptor.name,
|
|
6249
6253
|
kind: "mutation",
|
|
6250
6254
|
input: n,
|
|
@@ -6252,11 +6256,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6252
6256
|
...e.interceptor ? { interceptor: e.interceptor } : {},
|
|
6253
6257
|
...e.recordMetric ? { recordMetric: e.recordMetric } : {},
|
|
6254
6258
|
runExecutor: async () => {
|
|
6255
|
-
await
|
|
6256
|
-
let i = await
|
|
6259
|
+
await pu(t.descriptor, r.subject, n);
|
|
6260
|
+
let i = await mu(r), a = [], o = await xu(async () => (a.length = 0, e.store.transactional(async (o) => {
|
|
6257
6261
|
let s = e.undoCapture?.(o), c = s ? s.tx : o, l = e.buildContext(i, c, { afterCommit: (e) => {
|
|
6258
6262
|
a.push(e);
|
|
6259
|
-
} }), u = t.executor(n, l), d = N.isEffect(u) ? await e.runEffect(
|
|
6263
|
+
} }), u = t.executor(n, l), d = N.isEffect(u) ? await e.runEffect(fu(u, r.subject), l.store) : await u;
|
|
6260
6264
|
return s && await s.persist(l.store, {
|
|
6261
6265
|
tag: t.descriptor.name,
|
|
6262
6266
|
subject: r.subject,
|
|
@@ -6266,30 +6270,30 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6266
6270
|
for (let e of a) await e();
|
|
6267
6271
|
return o;
|
|
6268
6272
|
}
|
|
6269
|
-
}),
|
|
6273
|
+
}), Cu = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, wu = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, Tu = (e) => {
|
|
6270
6274
|
let t = e.descriptor.source;
|
|
6271
6275
|
return t == null ? [] : typeof t == "string" ? [t] : [...t];
|
|
6272
|
-
},
|
|
6276
|
+
}, Eu = (e, t) => (n) => () => {
|
|
6273
6277
|
let r = e.descriptor.guards;
|
|
6274
6278
|
return !r || r.length === 0 ? Promise.resolve(null) : N.runPromise(je(n, r, t));
|
|
6275
|
-
},
|
|
6276
|
-
let i = e.buildContext(r), a =
|
|
6279
|
+
}, Du = (e) => (t, n) => (r) => {
|
|
6280
|
+
let i = e.buildContext(r), a = Eu(t, n)(r.subject), o = async () => {
|
|
6277
6281
|
let i = await a();
|
|
6278
6282
|
if (i) throw i;
|
|
6279
|
-
let o = e.buildContext(await
|
|
6280
|
-
return N.isEffect(s) ? N.runPromise(e.provideEffect(
|
|
6283
|
+
let o = e.buildContext(await mu(r)), s = t.executor(n, o);
|
|
6284
|
+
return N.isEffect(s) ? N.runPromise(e.provideEffect(fu(s, r.subject), o.store)) : Cu(await Promise.resolve(s));
|
|
6281
6285
|
}, s = (n) => {
|
|
6282
|
-
let i =
|
|
6283
|
-
return
|
|
6286
|
+
let i = Cu(n);
|
|
6287
|
+
return wu(i) ? e.finalize(i, r) : {
|
|
6284
6288
|
__voltroComputed: !0,
|
|
6285
6289
|
value: i,
|
|
6286
|
-
dependentTables:
|
|
6290
|
+
dependentTables: Tu(t),
|
|
6287
6291
|
tenantId: r.subject?.tenantId ?? null,
|
|
6288
6292
|
recompute: o
|
|
6289
6293
|
};
|
|
6290
6294
|
}, c = () => {
|
|
6291
6295
|
let a = t.executor(n, i);
|
|
6292
|
-
return N.isEffect(a) ? e.provideEffect(
|
|
6296
|
+
return N.isEffect(a) ? e.provideEffect(fu(a, r.subject), i.store).pipe(N.map(s)) : a instanceof Promise ? N.promise(() => a).pipe(N.map(s)) : s(a);
|
|
6293
6297
|
}, l = () => {
|
|
6294
6298
|
let e = t.descriptor.guards;
|
|
6295
6299
|
return !e || e.length === 0 ? c() : je(r.subject, e, n).pipe(N.flatMap((e) => {
|
|
@@ -6311,7 +6315,7 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6311
6315
|
traceId: r.traceId,
|
|
6312
6316
|
...r.spanId === void 0 ? {} : { spanId: r.spanId }
|
|
6313
6317
|
});
|
|
6314
|
-
},
|
|
6318
|
+
}, Ou = (e) => (t, n, r) => hu({
|
|
6315
6319
|
name: t.descriptor.name,
|
|
6316
6320
|
kind: "action",
|
|
6317
6321
|
input: n,
|
|
@@ -6319,16 +6323,16 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6319
6323
|
...e.interceptor ? { interceptor: e.interceptor } : {},
|
|
6320
6324
|
...e.recordMetric ? { recordMetric: e.recordMetric } : {},
|
|
6321
6325
|
runExecutor: async () => {
|
|
6322
|
-
await
|
|
6323
|
-
let i = e.buildContext(await
|
|
6324
|
-
return N.isEffect(a) ? e.runEffect(
|
|
6326
|
+
await pu(t.descriptor, r.subject, n);
|
|
6327
|
+
let i = e.buildContext(await mu(r)), a = t.executor(n, i);
|
|
6328
|
+
return N.isEffect(a) ? e.runEffect(fu(a, r.subject), i.store) : a;
|
|
6325
6329
|
}
|
|
6326
|
-
}),
|
|
6330
|
+
}), ku = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, Au = (e) => typeof e == "string" && e.length > 0 ? e : null, ju = [
|
|
6327
6331
|
"updatedAt",
|
|
6328
6332
|
"createdAt",
|
|
6329
6333
|
"updatedBy",
|
|
6330
6334
|
"createdBy"
|
|
6331
|
-
],
|
|
6335
|
+
], Mu = (e) => ju.some((t) => t in e), Nu = (e, t, n) => {
|
|
6332
6336
|
let r = {
|
|
6333
6337
|
table: t.table,
|
|
6334
6338
|
id: t.id,
|
|
@@ -6343,14 +6347,14 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6343
6347
|
found: !1
|
|
6344
6348
|
};
|
|
6345
6349
|
let i = t.column === void 0 ? void 0 : e[t.column];
|
|
6346
|
-
if (!
|
|
6350
|
+
if (!Mu(e)) return {
|
|
6347
6351
|
...r,
|
|
6348
6352
|
value: i,
|
|
6349
6353
|
lastWrite: null,
|
|
6350
6354
|
attribution: "none",
|
|
6351
6355
|
found: !0
|
|
6352
6356
|
};
|
|
6353
|
-
let a =
|
|
6357
|
+
let a = Au(e.updatedBy) ?? Au(e.createdBy), o = ku(e.updatedAt) ?? ku(e.createdAt);
|
|
6354
6358
|
return {
|
|
6355
6359
|
...r,
|
|
6356
6360
|
value: i,
|
|
@@ -6362,12 +6366,12 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6362
6366
|
attribution: "audit",
|
|
6363
6367
|
found: !0
|
|
6364
6368
|
};
|
|
6365
|
-
},
|
|
6369
|
+
}, Pu = (e, t) => {
|
|
6366
6370
|
let n = e.map((e) => {
|
|
6367
6371
|
let n = e.newValue ?? e.value, r = t.column !== void 0 && n && typeof n == "object" ? n[t.column] : e.newValue ?? e.value;
|
|
6368
6372
|
return {
|
|
6369
|
-
actor: { id:
|
|
6370
|
-
at:
|
|
6373
|
+
actor: { id: Au(e.actor) ?? Au(e.changedBy) },
|
|
6374
|
+
at: ku(e.at) ?? ku(e.changedAt),
|
|
6371
6375
|
...e.traceId === void 0 ? {} : { traceId: e.traceId },
|
|
6372
6376
|
value: r
|
|
6373
6377
|
};
|
|
@@ -6382,12 +6386,12 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6382
6386
|
history: n,
|
|
6383
6387
|
found: n.length > 0
|
|
6384
6388
|
};
|
|
6385
|
-
},
|
|
6389
|
+
}, Fu = (e) => {
|
|
6386
6390
|
let t = e.new?.id;
|
|
6387
6391
|
if (typeof t == "string") return t;
|
|
6388
6392
|
let n = e.old?.id;
|
|
6389
6393
|
return typeof n == "string" ? n : void 0;
|
|
6390
|
-
},
|
|
6394
|
+
}, Iu = (e) => {
|
|
6391
6395
|
let t = {};
|
|
6392
6396
|
if (e.op === "insert") for (let [n, r] of Object.entries(e.new ?? {})) t[n] = {
|
|
6393
6397
|
from: void 0,
|
|
@@ -6407,11 +6411,11 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6407
6411
|
return {
|
|
6408
6412
|
table: e.table,
|
|
6409
6413
|
op: e.op,
|
|
6410
|
-
id:
|
|
6414
|
+
id: Fu(e),
|
|
6411
6415
|
fields: t
|
|
6412
6416
|
};
|
|
6413
|
-
},
|
|
6414
|
-
let t = e.map(
|
|
6417
|
+
}, Lu = (e) => {
|
|
6418
|
+
let t = e.map(Iu);
|
|
6415
6419
|
return {
|
|
6416
6420
|
rows: t,
|
|
6417
6421
|
summary: {
|
|
@@ -6420,21 +6424,21 @@ var K = /* @__PURE__ */ new Map(), nr = (e, t) => {
|
|
|
6420
6424
|
deletes: t.filter((e) => e.op === "delete").length
|
|
6421
6425
|
}
|
|
6422
6426
|
};
|
|
6423
|
-
},
|
|
6427
|
+
}, Ru = class extends Error {
|
|
6424
6428
|
constructor() {
|
|
6425
6429
|
super("voltro:preview-rollback"), this.name = "PreviewRollback";
|
|
6426
6430
|
}
|
|
6427
|
-
},
|
|
6431
|
+
}, zu = async (e, t) => {
|
|
6428
6432
|
let n, r = !1;
|
|
6429
6433
|
try {
|
|
6430
6434
|
await e.transactional(async (e) => {
|
|
6431
|
-
throw n = await t(e), r = !0, new
|
|
6435
|
+
throw n = await t(e), r = !0, new Ru();
|
|
6432
6436
|
});
|
|
6433
6437
|
} catch (e) {
|
|
6434
|
-
if (!(e instanceof
|
|
6438
|
+
if (!(e instanceof Ru)) throw e;
|
|
6435
6439
|
}
|
|
6436
6440
|
if (!r) throw Error("preview: handler did not complete");
|
|
6437
6441
|
return n;
|
|
6438
|
-
},
|
|
6442
|
+
}, Bu = "framework-runtime";
|
|
6439
6443
|
//#endregion
|
|
6440
|
-
export { Ni as API_KEYS_TABLE, Vo as AccessDenied,
|
|
6444
|
+
export { Ni as API_KEYS_TABLE, Vo as AccessDenied, ru as AggregateError, fl as AggregateMaintainer, nu as AggregateNotFound, iu as AggregateRegistry, tu as AggregateStale, Hl as AnalyticsCapabilityNotSupported, Vl as AnalyticsError, Ul as AnalyticsSink, X as CONNECTIONS_TABLE, za as CONNECTION_GRANTS_TABLE, Ns as CircuitBreaker, js as CircuitOpen, co as ConnectionNotConnected, Hr as DEFAULT_MAX_RPC_BODY_BYTES, oo as DEFAULT_REFRESH_SKEW_MS, Mn as DEFAULT_ROW_FILTER_RETRY, lc as DORMANCY_WAKEUP_TENANT, Cs as DeleteBuilder, Wn as Dispatcher, Xi as EffectStore, xo as GRANT_TTL_MS, qt as InMemoryDataStore, Pt as IndexedMatcher, Dt as LinearScanMatcher, Je as MetricBoundaries, Kl as NOOP_ANALYTICS_PROVIDER, In as NO_ROW_FILTER, gs as NoRowFound, wa as OUTBOX_ATTEMPTS_TABLE, ja as OUTBOX_ATTEMPT_LOG_CAP, Y as OUTBOX_TABLE, _s as OptimisticLockError, Bo as REBAC_ADMIN_SCOPE, so as REFRESH_LEASE_MS, Bu as RUNTIME_NAME, Sl as ReactionRateLimiter, Cr as ReplicatedDataStore, jn as RowFilterUnavailable, cc as SCHEDULE_SUBJECT, Ki as SYSTEM_SUBJECT, xs as SelectBuilder, Ji as StoreOperationFailed, Lt as SubscriptionRegistry, Yi as TableValidationFailed, qi as TenantScopeViolation, Qc as TimelineRecorder, jc as UndoBoundaryError, Nc as UndoStack, Ss as UpdateBuilder, cs as VOLTRO_AUDIT_MIXIN_ID, ls as VOLTRO_SOFT_DELETE_MIXIN_ID, us as VOLTRO_TENANT_MIXIN_ID, ir as _connectionStreamCount, ar as _resetConnectionSubjectsForTest, Va as _voltroConnectionGrantsTable, Ra as _voltroConnectionsTable, pl as _voltroRebacTuplesTable, bc as _voltroScheduleClaimsTable, yc as _voltroScheduleRunsTable, xc as _voltroTracesTable, Sc as _voltroUndoLogTable, wl as _voltroWakeupsTable, ya as _voltroWorkflowEventDeliveriesTable, va as _voltroWorkflowEventsTable, Gi as apiKeyManagementRoutes, Ds as applyDefined, ul as applyDelta, Fc as applyInverse, Ic as applyInverses, Bn as applyRowFilter, Vn as applyRowFilterToDescriptor, lu as applySoftDeleteScope, ou as applyTenantScope, Wc as applyUndoInvocation, Zo as assertCan, Ga as assertConnectionCipherConfigured, Ql as attachAnalyticsMirror, Wr as awaitServerListening, Aa as backoffMs, To as beginOAuthConnect, Zn as bindConnectionSubject, Vr as bindMutation, Nr as bindStream, Mr as bindSubscription, Ar as bindSubscriptionUntyped, cl as buildIvmState, Lu as buildPreview, gl as buildRebacInterceptor, vl as buildRebacReadFilter, _r as buildSubjectKey, Yr as buildTracingLayer, ui as cachedBackend, Xo as can, Zs as cancelWakeup, il as classifyShape, po as clearConnectionRefreshFlights, Ko as clearResourcePolicies, i as clearRetentions, Is as clearSystemStoreHandle, Ks as compileCron, Eo as completeOAuthConnect, Yl as composeAnalytics, Jl as composeAnalyticsSinks, So as connectionCallbackPath, Wa as connectionLabel, or as connectionSubjectsSnapshot, Ll as countRunningWorkflows, Tn as counter, Sr as currentRoutingContext, pr as currentTraceContext, Hi as dataStoreApiKeyStore, Ti as dataStoreIdempotencyStore, Ai as dataStoreKvStore, bi as decryptField, $l as defineAggregate, Ua as defineConnection, pa as defineEventTrigger, uu as defineExecutor, Da as defineOutboxHandler, yl as defineReaction, Uo as defineResourcePolicy, Gs as defineSchedule, Bl as defineSubscriber, Hn as deliveredRowCount, pi as deriveKey, Iu as diffChange, Fa as drainOutbox, ic as dueWakeups, Yo as effectiveRelations, hs as emptySchemaRegistry, q as encryptField, ii as envSecretsBackend, io as exchangeAuthorizationCode, ur as externalSpanFromTraceparent, Yt as extractDbCause, It as fingerprintFor, eo as forgetCredential, cr as formatTraceparent, Pc as forwardChangeFromCdc, Ui as frameworkApiKeyStrategy, En as gauge, Fi as generateApiKeyToken, Ao as getConnectionResolver, Qn as getConnectionSubject, vi as getFieldCipher, Wo as getResourcePolicy, Fn as getRowFilter, Ls as getSystemStoreHandle, el as getTimelineRecorder, rs as getTupleSource, $ as groupKeyOf, Dn as histogramMetric, Pu as historyProvenance, di as httpSecretsBackend, wt as inspectWorkflow, is as installPolicyGuardResolver, rr as interruptConnectionStreams, kc as invertChange, eu as isAggregateDefinition, su as isEmptyTenantScopedRead, Xt as isForeignKeyViolation, Al as isIdleNow, Rr as isInfraError, cu as isOrglessUserSubject, Mc as isSafeToApply, Us as isScheduleDefinition, ma as isWorkflowEventTriggerDefinition, sl as ivmValue, Nu as lastWriteProvenance, to as listConnectionStates, Go as listResourcePolicies, ee as listRetentions, ml as loadResourceTuples, _l as loadSubjectTuples, zs as localityAwareSelector, Ou as makeActionRunner, fc as makeAdvisoryLockCoordinator, mi as makeAesCipher, Ri as makeApiKeyService, Zt as makeAppAccess, ji as makeAsyncKv, ri as makeBufferingSpanProcessor, Ka as makeConnectionRegistry, Mo as makeConnectionResolver, No as makeConnectionsFacade, vc as makeCoordinatedScheduler, os as makeDataLoader, zo as makeDisconnectConnectionExecutor, $i as makeEffectStoreLayer, ba as makeEventsFacade, hi as makeFieldCipher, ws as makeFluentStore, jl as makeIdleGate, la as makeLazyWorkflowFacade, Io as makeListConnectionsExecutor, Su as makeMutationRunner, ka as makeOutboxFacade, sa as makePostCommitWorkflowFacade, Dl as makeProcessAdapter, Du as makeQueryDescriptorProducer, Eu as makeQueryReauthorizer, Ml as makeRouterActivity, ds as makeSchemaRegistry, Lo as makeStartConnectionExecutor, Ro as makeSubmitTokenExecutor, Dc as makeUndoCapture, Nl as makeWakeGate, Il as makeWakeProxyServer, oa as makeWorkflowFacade, ca as makeWorkflowFacadeWithCallerContext, ua as makeWorkflowHandlers, da as makeWorkflowLayers, na as makeWorkflowRunHandle, Qs as markWakeupFired, ll as materializeIvm, zi as memoryApiKeyStore, Vs as memoryReplicationAdapter, gr as memoryRywPositionStore, qs as nextFiring, ac as nextWakeup, kl as nodeProcessSupervisor, ql as noopAnalytics, Xl as noopAnalyticsSpec, Mi as noopKv, er as onBindConnectionSubject, Ea as outboxAttemptsTable, Ca as outboxTable, lr as parseTraceparent, mr as powerOfTwoSelector, zu as previewInRollback, Xa as projectConnectionState, sc as pruneWakeups, qo as rebacPolicyGraph, xn as recordSample, U as recordSubscriptionActive, Cn as recordSubscriptionDelivery, nl as recordTimelineEvent, Yc as redactRow, vr as redisRywPositionStore, Gc as redoUndoInvocation, ao as refreshAccessToken, nr as registerConnectionStream, se as registerRetention, Xs as registerWakeup, tc as releaseWakeup, hr as replicaHealth, si as resetSecretsBackend, go as resolveConnection, jo as resolveConnectionForSubject, Bs as resolveCurrentRegion, Qt as resolveDependentTables, wo as resolveRedirectUri, dl as resolveRescan, Ln as resolveRowFilterScope, Rn as resolveRowFilterScopeFor, ci as resolveSecret, li as resolveSecretSync, fi as resolveSecretsBackend, Kc as resolveTimelineMode, le as retentionTtlMsFromEnv, Zc as reverseEventOverRows, $o as revokedIds, Rs as runAsSystem, Rl as runOrchestratorTick, du as runProvidedEffect, Cl as runReaction, zl as runSingleNodeOrchestrator, El as runWakeLoop, xu as runWithDeadlockRetry, xr as runWithRoutingContext, fr as runWithTraceContext, Co as sanitizeRedirectTo, _c as scheduleCoordinated, ko as setConnectionResolver, _i as setFieldCipher, Pn as setRowFilter, oi as setSecretsBackend, Fs as setSystemStoreHandle, tl as setTimelineRecorderForTest, ns as setTupleSource, Pi as sha256Hex, uc as singleCoordinator, kn as snapshotMetrics, An as snapshotMetricsSync, Ur as startRpcServer, mc as startScheduler, Qa as storeCredential, Do as sweepExpiredGrants, fe as sweepRetention, Ac as synthesizeInverse, ss as tracingHttpClientLayer, fa as triggerWorkflow, ec as tryClaimWakeup, $n as unbindConnectionSubject, Cc as undoCaptureEnabled, Hc as undoLogExecutor, au as useAggregate, Gl as useAnalytics, Qo as visibleRows, Tl as wakeDueOnce, mu as withRowFilter, ea as workflowToRpc, Ec as wrapCaptureStore, As as wrapStoreWithMixinBehaviour };
|