@dudousxd/nestjs-durable-testing 0.25.0 → 0.26.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.d.ts +4 -0
- package/dist/index.js +211 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -76,6 +76,8 @@ declare const DURABLE_CANONICAL_COLUMNS: {
|
|
|
76
76
|
readonly priority: "priority";
|
|
77
77
|
readonly origin: "origin";
|
|
78
78
|
readonly namespace: "namespace";
|
|
79
|
+
readonly tenantId: "tenant_id";
|
|
80
|
+
readonly tenantKind: "tenant_kind";
|
|
79
81
|
readonly createdAt: "created_at";
|
|
80
82
|
readonly updatedAt: "updated_at";
|
|
81
83
|
};
|
|
@@ -135,6 +137,8 @@ declare const DURABLE_CANONICAL_COLUMNS: {
|
|
|
135
137
|
readonly tags: "tags";
|
|
136
138
|
readonly spec: "spec";
|
|
137
139
|
readonly state: "state";
|
|
140
|
+
readonly tenantId: "tenant_id";
|
|
141
|
+
readonly tenantKind: "tenant_kind";
|
|
138
142
|
readonly createdAt: "created_at";
|
|
139
143
|
readonly updatedAt: "updated_at";
|
|
140
144
|
};
|
package/dist/index.js
CHANGED
|
@@ -238,6 +238,10 @@ var DURABLE_CANONICAL_COLUMNS = {
|
|
|
238
238
|
// now that all four adapters carry the column — see the note above, which used to
|
|
239
239
|
// name this as the standing example of a capability gap the map cannot express.
|
|
240
240
|
namespace: "namespace",
|
|
241
|
+
// The CUSTOMER (tenancy) a run belongs to — distinct from `namespace`. Two words each, so a
|
|
242
|
+
// `preserve` adapter and a `snake_case` one disagree, and each must say which it is.
|
|
243
|
+
tenantId: "tenant_id",
|
|
244
|
+
tenantKind: "tenant_kind",
|
|
241
245
|
createdAt: "created_at",
|
|
242
246
|
updatedAt: "updated_at"
|
|
243
247
|
},
|
|
@@ -305,6 +309,8 @@ var DURABLE_CANONICAL_COLUMNS = {
|
|
|
305
309
|
tags: "tags",
|
|
306
310
|
spec: "spec",
|
|
307
311
|
state: "state",
|
|
312
|
+
tenantId: "tenant_id",
|
|
313
|
+
tenantKind: "tenant_kind",
|
|
308
314
|
createdAt: "created_at",
|
|
309
315
|
updatedAt: "updated_at"
|
|
310
316
|
}
|
|
@@ -2929,6 +2935,47 @@ function runStateStoreContract(name, makeStore) {
|
|
|
2929
2935
|
message: "boom"
|
|
2930
2936
|
});
|
|
2931
2937
|
expect3(failed?.startedAt.getTime()).toBe(at.getTime());
|
|
2938
|
+
await store.saveCheckpoint(pending("r1", 4));
|
|
2939
|
+
const events = [
|
|
2940
|
+
{
|
|
2941
|
+
at: 2,
|
|
2942
|
+
level: "info",
|
|
2943
|
+
message: "started"
|
|
2944
|
+
},
|
|
2945
|
+
{
|
|
2946
|
+
at: 3,
|
|
2947
|
+
level: "info",
|
|
2948
|
+
message: "done"
|
|
2949
|
+
}
|
|
2950
|
+
];
|
|
2951
|
+
const [arrays] = await store.settleResultsIfPending([
|
|
2952
|
+
{
|
|
2953
|
+
runId: "r1",
|
|
2954
|
+
seq: 4,
|
|
2955
|
+
status: "completed",
|
|
2956
|
+
output: [
|
|
2957
|
+
{
|
|
2958
|
+
row: 1
|
|
2959
|
+
},
|
|
2960
|
+
{
|
|
2961
|
+
row: 2
|
|
2962
|
+
}
|
|
2963
|
+
],
|
|
2964
|
+
events,
|
|
2965
|
+
finishedAt: later
|
|
2966
|
+
}
|
|
2967
|
+
]);
|
|
2968
|
+
expect3(arrays?.status).toBe("completed");
|
|
2969
|
+
expect3(arrays?.output).toEqual([
|
|
2970
|
+
{
|
|
2971
|
+
row: 1
|
|
2972
|
+
},
|
|
2973
|
+
{
|
|
2974
|
+
row: 2
|
|
2975
|
+
}
|
|
2976
|
+
]);
|
|
2977
|
+
expect3(arrays?.events).toEqual(events);
|
|
2978
|
+
expect3((await store.getCheckpoint("r1", 4))?.events).toEqual(events);
|
|
2932
2979
|
const stored = await store.getCheckpoint("r1", 0);
|
|
2933
2980
|
expect3(stored?.output).toEqual({
|
|
2934
2981
|
n: 0
|
|
@@ -3862,6 +3909,116 @@ function runStateStoreContract(name, makeStore) {
|
|
|
3862
3909
|
"d"
|
|
3863
3910
|
]);
|
|
3864
3911
|
});
|
|
3912
|
+
t("round-trips a run tenant and filters by tenantId / tenantIds (null = no tenant)", async () => {
|
|
3913
|
+
await store.createRun(run({
|
|
3914
|
+
id: "a",
|
|
3915
|
+
tenantId: "acme",
|
|
3916
|
+
tenantKind: "organization"
|
|
3917
|
+
}));
|
|
3918
|
+
await store.createRun(run({
|
|
3919
|
+
id: "b",
|
|
3920
|
+
tenantId: "globex"
|
|
3921
|
+
}));
|
|
3922
|
+
await store.createRun(run({
|
|
3923
|
+
id: "c"
|
|
3924
|
+
}));
|
|
3925
|
+
const a = await store.getRun("a");
|
|
3926
|
+
expect3(a?.tenantId).toBe("acme");
|
|
3927
|
+
expect3(a?.tenantKind).toBe("organization");
|
|
3928
|
+
expect3((await store.getRun("b"))?.tenantKind ?? void 0).toBeUndefined();
|
|
3929
|
+
const c = await store.getRun("c");
|
|
3930
|
+
expect3(c?.tenantId ?? void 0).toBeUndefined();
|
|
3931
|
+
expect3(c?.tenantKind ?? void 0).toBeUndefined();
|
|
3932
|
+
const ids2 = /* @__PURE__ */ __name(async (q) => (await store.listRuns(q)).map((r) => r.id).sort(), "ids");
|
|
3933
|
+
expect3(await ids2({
|
|
3934
|
+
tenantId: "acme"
|
|
3935
|
+
})).toEqual([
|
|
3936
|
+
"a"
|
|
3937
|
+
]);
|
|
3938
|
+
expect3(await ids2({
|
|
3939
|
+
tenantId: null
|
|
3940
|
+
})).toEqual([
|
|
3941
|
+
"c"
|
|
3942
|
+
]);
|
|
3943
|
+
expect3(await ids2({
|
|
3944
|
+
tenantIds: [
|
|
3945
|
+
"acme"
|
|
3946
|
+
]
|
|
3947
|
+
})).toEqual([
|
|
3948
|
+
"a"
|
|
3949
|
+
]);
|
|
3950
|
+
expect3(await ids2({
|
|
3951
|
+
tenantIds: [
|
|
3952
|
+
"acme",
|
|
3953
|
+
null
|
|
3954
|
+
]
|
|
3955
|
+
})).toEqual([
|
|
3956
|
+
"a",
|
|
3957
|
+
"c"
|
|
3958
|
+
]);
|
|
3959
|
+
expect3(await ids2({
|
|
3960
|
+
tenantIds: [
|
|
3961
|
+
null
|
|
3962
|
+
]
|
|
3963
|
+
})).toEqual([
|
|
3964
|
+
"c"
|
|
3965
|
+
]);
|
|
3966
|
+
expect3(await ids2({
|
|
3967
|
+
tenantIds: []
|
|
3968
|
+
})).toEqual([]);
|
|
3969
|
+
expect3(await ids2({})).toEqual([
|
|
3970
|
+
"a",
|
|
3971
|
+
"b",
|
|
3972
|
+
"c"
|
|
3973
|
+
]);
|
|
3974
|
+
expect3(await ids2({
|
|
3975
|
+
tenantIds: [
|
|
3976
|
+
"acme",
|
|
3977
|
+
null
|
|
3978
|
+
],
|
|
3979
|
+
tenantId: "acme"
|
|
3980
|
+
})).toEqual([
|
|
3981
|
+
"a"
|
|
3982
|
+
]);
|
|
3983
|
+
expect3(await ids2({
|
|
3984
|
+
tenantIds: [
|
|
3985
|
+
"acme",
|
|
3986
|
+
"globex"
|
|
3987
|
+
],
|
|
3988
|
+
workflow: "nope"
|
|
3989
|
+
})).toEqual([]);
|
|
3990
|
+
await store.updateRun("c", {
|
|
3991
|
+
tenantId: "acme",
|
|
3992
|
+
tenantKind: "organization"
|
|
3993
|
+
});
|
|
3994
|
+
expect3(await ids2({
|
|
3995
|
+
tenantId: "acme"
|
|
3996
|
+
})).toEqual([
|
|
3997
|
+
"a",
|
|
3998
|
+
"c"
|
|
3999
|
+
]);
|
|
4000
|
+
await store.updateRun("c", {
|
|
4001
|
+
tenantId: null,
|
|
4002
|
+
tenantKind: null
|
|
4003
|
+
});
|
|
4004
|
+
expect3(await ids2({
|
|
4005
|
+
tenantId: null
|
|
4006
|
+
})).toEqual([
|
|
4007
|
+
"c"
|
|
4008
|
+
]);
|
|
4009
|
+
await store.updateRun("a", {
|
|
4010
|
+
status: "completed"
|
|
4011
|
+
});
|
|
4012
|
+
expect3((await store.getRun("a"))?.tenantId).toBe("acme");
|
|
4013
|
+
if (store.runFacets) {
|
|
4014
|
+
const facets = await store.runFacets({
|
|
4015
|
+
tenantIds: [
|
|
4016
|
+
"acme"
|
|
4017
|
+
]
|
|
4018
|
+
});
|
|
4019
|
+
expect3(facets.reduce((n, f) => n + f.count, 0)).toBe(1);
|
|
4020
|
+
}
|
|
4021
|
+
});
|
|
3865
4022
|
t("counts runs by (status, origin) without returning them", async () => {
|
|
3866
4023
|
if (!store.runFacets) return;
|
|
3867
4024
|
await store.createRun(run({
|
|
@@ -4809,6 +4966,60 @@ function runStateStoreContract(name, makeStore) {
|
|
|
4809
4966
|
expect3(await store.deleteSchedule?.("s1")).toBe(false);
|
|
4810
4967
|
expect3(await store.getSchedule?.("s1")).toBeNull();
|
|
4811
4968
|
});
|
|
4969
|
+
t("round-trips a schedule tenant and filters listSchedules by it", async () => {
|
|
4970
|
+
if (!store.saveSchedule || !store.listSchedules) return;
|
|
4971
|
+
await store.saveSchedule(schedule({
|
|
4972
|
+
id: "s1",
|
|
4973
|
+
tenantId: "acme",
|
|
4974
|
+
tenantKind: "organization"
|
|
4975
|
+
}));
|
|
4976
|
+
await store.saveSchedule(schedule({
|
|
4977
|
+
id: "s2"
|
|
4978
|
+
}));
|
|
4979
|
+
const s1 = await store.getSchedule?.("s1");
|
|
4980
|
+
expect3(s1?.tenantId).toBe("acme");
|
|
4981
|
+
expect3(s1?.tenantKind).toBe("organization");
|
|
4982
|
+
expect3((await store.getSchedule?.("s2"))?.tenantId ?? void 0).toBeUndefined();
|
|
4983
|
+
const ids2 = /* @__PURE__ */ __name(async (q) => (await store.listSchedules?.(q) ?? []).map((r) => r.id).sort(), "ids");
|
|
4984
|
+
expect3(await ids2({
|
|
4985
|
+
tenantId: "acme"
|
|
4986
|
+
})).toEqual([
|
|
4987
|
+
"s1"
|
|
4988
|
+
]);
|
|
4989
|
+
expect3(await ids2({
|
|
4990
|
+
tenantIds: [
|
|
4991
|
+
null
|
|
4992
|
+
]
|
|
4993
|
+
})).toEqual([
|
|
4994
|
+
"s2"
|
|
4995
|
+
]);
|
|
4996
|
+
expect3(await ids2({
|
|
4997
|
+
tenantIds: [
|
|
4998
|
+
"acme",
|
|
4999
|
+
null
|
|
5000
|
+
]
|
|
5001
|
+
})).toEqual([
|
|
5002
|
+
"s1",
|
|
5003
|
+
"s2"
|
|
5004
|
+
]);
|
|
5005
|
+
expect3(await ids2({
|
|
5006
|
+
tenantIds: []
|
|
5007
|
+
})).toEqual([]);
|
|
5008
|
+
expect3(await ids2({
|
|
5009
|
+
tenantId: "acme",
|
|
5010
|
+
dueBy: NOW + 12e4
|
|
5011
|
+
})).toEqual([
|
|
5012
|
+
"s1"
|
|
5013
|
+
]);
|
|
5014
|
+
expect3(await store.updateSchedule?.("s2", {
|
|
5015
|
+
tenantId: "globex"
|
|
5016
|
+
})).toBe(true);
|
|
5017
|
+
expect3(await ids2({
|
|
5018
|
+
tenantId: "globex"
|
|
5019
|
+
})).toEqual([
|
|
5020
|
+
"s2"
|
|
5021
|
+
]);
|
|
5022
|
+
});
|
|
4812
5023
|
t("updateSchedule patches, and compare-and-sets on nextFireAt", async () => {
|
|
4813
5024
|
await store.saveSchedule?.(schedule());
|
|
4814
5025
|
expect3(await store.updateSchedule?.("s1", {
|