@dudousxd/nestjs-durable-store-mikro-orm 0.35.1 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +99 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +99 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -129,6 +129,8 @@ var WorkflowRunEntity = class {
|
|
|
129
129
|
priority;
|
|
130
130
|
namespace;
|
|
131
131
|
origin;
|
|
132
|
+
tenantId;
|
|
133
|
+
tenantKind;
|
|
132
134
|
createdAt;
|
|
133
135
|
updatedAt;
|
|
134
136
|
};
|
|
@@ -219,6 +221,8 @@ var ScheduleEntity = class {
|
|
|
219
221
|
tags;
|
|
220
222
|
spec;
|
|
221
223
|
state;
|
|
224
|
+
tenantId;
|
|
225
|
+
tenantKind;
|
|
222
226
|
createdAt;
|
|
223
227
|
updatedAt;
|
|
224
228
|
};
|
|
@@ -280,6 +284,14 @@ function durableEntities(options = {}) {
|
|
|
280
284
|
"status",
|
|
281
285
|
"createdAt"
|
|
282
286
|
]
|
|
287
|
+
},
|
|
288
|
+
// App-facing reads with tenancy on: `tenant_id = ? ORDER BY created_at DESC`.
|
|
289
|
+
{
|
|
290
|
+
name: "durable_workflow_runs_tenant_idx",
|
|
291
|
+
properties: [
|
|
292
|
+
"tenantId",
|
|
293
|
+
"createdAt"
|
|
294
|
+
]
|
|
283
295
|
}
|
|
284
296
|
],
|
|
285
297
|
properties: {
|
|
@@ -389,6 +401,19 @@ function durableEntities(options = {}) {
|
|
|
389
401
|
nullable: true,
|
|
390
402
|
fieldName: col("origin")
|
|
391
403
|
},
|
|
404
|
+
// The CUSTOMER (tenancy) the run belongs to — not the worker-pool `namespace`. Nullable, no
|
|
405
|
+
// default: NULL = no tenant, which is every run while tenancy is off. Added in place by the
|
|
406
|
+
// boot-time schema heal.
|
|
407
|
+
tenantId: {
|
|
408
|
+
type: "string",
|
|
409
|
+
nullable: true,
|
|
410
|
+
fieldName: col("tenantId")
|
|
411
|
+
},
|
|
412
|
+
tenantKind: {
|
|
413
|
+
type: "string",
|
|
414
|
+
nullable: true,
|
|
415
|
+
fieldName: col("tenantKind")
|
|
416
|
+
},
|
|
392
417
|
createdAt: {
|
|
393
418
|
type: "Date",
|
|
394
419
|
length: DATETIME_PRECISION,
|
|
@@ -694,6 +719,12 @@ function durableEntities(options = {}) {
|
|
|
694
719
|
"paused",
|
|
695
720
|
"nextFireAt"
|
|
696
721
|
]
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
name: "durable_schedules_tenant_idx",
|
|
725
|
+
properties: [
|
|
726
|
+
"tenantId"
|
|
727
|
+
]
|
|
697
728
|
}
|
|
698
729
|
],
|
|
699
730
|
properties: {
|
|
@@ -734,6 +765,17 @@ function durableEntities(options = {}) {
|
|
|
734
765
|
type: "json",
|
|
735
766
|
fieldName: col("state")
|
|
736
767
|
},
|
|
768
|
+
// The customer the schedule (and every run it starts) belongs to. NULL = none.
|
|
769
|
+
tenantId: {
|
|
770
|
+
type: "string",
|
|
771
|
+
nullable: true,
|
|
772
|
+
fieldName: col("tenantId")
|
|
773
|
+
},
|
|
774
|
+
tenantKind: {
|
|
775
|
+
type: "string",
|
|
776
|
+
nullable: true,
|
|
777
|
+
fieldName: col("tenantKind")
|
|
778
|
+
},
|
|
737
779
|
createdAt: {
|
|
738
780
|
type: "Date",
|
|
739
781
|
length: DATETIME_PRECISION,
|
|
@@ -1781,6 +1823,7 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
1781
1823
|
}
|
|
1782
1824
|
});
|
|
1783
1825
|
}
|
|
1826
|
+
and.push(...tenantWhere(query));
|
|
1784
1827
|
if (query.status && query.statuses) {
|
|
1785
1828
|
and.push({
|
|
1786
1829
|
status: query.status
|
|
@@ -2066,6 +2109,8 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
2066
2109
|
if ("tags" in patch) data.tags = patch.tags ?? null;
|
|
2067
2110
|
if (patch.spec !== void 0) data.spec = patch.spec;
|
|
2068
2111
|
if (patch.state !== void 0) data.state = patch.state;
|
|
2112
|
+
if ("tenantId" in patch) data.tenantId = patch.tenantId ?? null;
|
|
2113
|
+
if ("tenantKind" in patch) data.tenantKind = patch.tenantKind ?? null;
|
|
2069
2114
|
if (patch.updatedAt !== void 0) data.updatedAt = patch.updatedAt;
|
|
2070
2115
|
if (!Object.keys(data).length) return await this.getSchedule(id) !== null;
|
|
2071
2116
|
const where = {
|
|
@@ -2086,18 +2131,17 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
2086
2131
|
if (query.namespace !== void 0) where.namespace = query.namespace;
|
|
2087
2132
|
if (query.workflow !== void 0) where.workflow = query.workflow;
|
|
2088
2133
|
if (query.paused !== void 0) where.paused = query.paused;
|
|
2134
|
+
const scheduleAnd = tenantWhere(query);
|
|
2089
2135
|
if (query.dueBy !== void 0) {
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
nextFireAt: {
|
|
2096
|
-
$lte: query.dueBy
|
|
2097
|
-
}
|
|
2136
|
+
scheduleAnd.push({
|
|
2137
|
+
paused: false
|
|
2138
|
+
}, {
|
|
2139
|
+
nextFireAt: {
|
|
2140
|
+
$lte: query.dueBy
|
|
2098
2141
|
}
|
|
2099
|
-
|
|
2142
|
+
});
|
|
2100
2143
|
}
|
|
2144
|
+
if (scheduleAnd.length) where.$and = scheduleAnd;
|
|
2101
2145
|
const quote = this.idQuote(em);
|
|
2102
2146
|
const meta = em.getMetadata().get(ScheduleEntity);
|
|
2103
2147
|
const tagsCol = meta.properties.tags?.fieldNames?.[0] ?? "tags";
|
|
@@ -2604,6 +2648,8 @@ function runUpdateData(patch) {
|
|
|
2604
2648
|
if ("priority" in patch) data.priority = patch.priority ?? null;
|
|
2605
2649
|
if ("namespace" in patch) data.namespace = patch.namespace || "default";
|
|
2606
2650
|
if ("origin" in patch) data.origin = patch.origin ?? null;
|
|
2651
|
+
if ("tenantId" in patch) data.tenantId = patch.tenantId ?? null;
|
|
2652
|
+
if ("tenantKind" in patch) data.tenantKind = patch.tenantKind ?? null;
|
|
2607
2653
|
if (patch.createdAt != null) data.createdAt = patch.createdAt;
|
|
2608
2654
|
if (patch.updatedAt != null) data.updatedAt = patch.updatedAt;
|
|
2609
2655
|
return data;
|
|
@@ -2628,6 +2674,8 @@ function toRunEntity(run) {
|
|
|
2628
2674
|
e.priority = run.priority ?? null;
|
|
2629
2675
|
e.namespace = run.namespace || "default";
|
|
2630
2676
|
e.origin = run.origin ?? null;
|
|
2677
|
+
e.tenantId = run.tenantId ?? null;
|
|
2678
|
+
e.tenantKind = run.tenantKind ?? null;
|
|
2631
2679
|
e.createdAt = run.createdAt;
|
|
2632
2680
|
e.updatedAt = run.updatedAt;
|
|
2633
2681
|
return e;
|
|
@@ -2653,6 +2701,13 @@ function fromRunEntity(e) {
|
|
|
2653
2701
|
namespace: e.namespace,
|
|
2654
2702
|
// NULL (a row written before the column existed) surfaces as `undefined` = unknown origin.
|
|
2655
2703
|
origin: e.origin ?? void 0,
|
|
2704
|
+
// NULL = no tenant; left off entirely so a tenancy-off run reads back unchanged.
|
|
2705
|
+
...e.tenantId != null ? {
|
|
2706
|
+
tenantId: e.tenantId
|
|
2707
|
+
} : {},
|
|
2708
|
+
...e.tenantKind != null ? {
|
|
2709
|
+
tenantKind: e.tenantKind
|
|
2710
|
+
} : {},
|
|
2656
2711
|
createdAt: e.createdAt,
|
|
2657
2712
|
updatedAt: e.updatedAt
|
|
2658
2713
|
};
|
|
@@ -2801,6 +2856,33 @@ function fromCheckpointEntity(e) {
|
|
|
2801
2856
|
};
|
|
2802
2857
|
}
|
|
2803
2858
|
__name(fromCheckpointEntity, "fromCheckpointEntity");
|
|
2859
|
+
function tenantWhere(query) {
|
|
2860
|
+
const out = [];
|
|
2861
|
+
if (query.tenantId !== void 0) out.push({
|
|
2862
|
+
tenantId: query.tenantId
|
|
2863
|
+
});
|
|
2864
|
+
if (query.tenantIds) {
|
|
2865
|
+
const named = query.tenantIds.filter((t) => t !== null);
|
|
2866
|
+
const branches = [];
|
|
2867
|
+
if (named.length) branches.push({
|
|
2868
|
+
tenantId: {
|
|
2869
|
+
$in: named
|
|
2870
|
+
}
|
|
2871
|
+
});
|
|
2872
|
+
if (query.tenantIds.some((t) => t === null)) branches.push({
|
|
2873
|
+
tenantId: null
|
|
2874
|
+
});
|
|
2875
|
+
out.push(branches.length ? {
|
|
2876
|
+
$or: branches
|
|
2877
|
+
} : {
|
|
2878
|
+
tenantId: {
|
|
2879
|
+
$in: []
|
|
2880
|
+
}
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
return out;
|
|
2884
|
+
}
|
|
2885
|
+
__name(tenantWhere, "tenantWhere");
|
|
2804
2886
|
function toScheduleEntity(r) {
|
|
2805
2887
|
const e = new ScheduleEntity();
|
|
2806
2888
|
e.id = r.id;
|
|
@@ -2811,6 +2893,8 @@ function toScheduleEntity(r) {
|
|
|
2811
2893
|
e.tags = r.tags ?? null;
|
|
2812
2894
|
e.spec = r.spec;
|
|
2813
2895
|
e.state = r.state;
|
|
2896
|
+
e.tenantId = r.tenantId ?? null;
|
|
2897
|
+
e.tenantKind = r.tenantKind ?? null;
|
|
2814
2898
|
e.createdAt = r.createdAt;
|
|
2815
2899
|
e.updatedAt = r.updatedAt;
|
|
2816
2900
|
return e;
|
|
@@ -2828,6 +2912,12 @@ function fromScheduleEntity(e) {
|
|
|
2828
2912
|
} : {},
|
|
2829
2913
|
spec: e.spec ?? {},
|
|
2830
2914
|
state: e.state ?? {},
|
|
2915
|
+
...e.tenantId != null ? {
|
|
2916
|
+
tenantId: e.tenantId
|
|
2917
|
+
} : {},
|
|
2918
|
+
...e.tenantKind != null ? {
|
|
2919
|
+
tenantKind: e.tenantKind
|
|
2920
|
+
} : {},
|
|
2831
2921
|
createdAt: e.createdAt,
|
|
2832
2922
|
updatedAt: e.updatedAt
|
|
2833
2923
|
};
|