@dudousxd/nestjs-durable-store-mikro-orm 0.27.0 → 0.27.1
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 +38 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +39 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -185,8 +185,9 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
185
185
|
*/
|
|
186
186
|
private fork;
|
|
187
187
|
ensureSchema(): Promise<void>;
|
|
188
|
+
tryAdmitSingleton(runId: string, tag: string, workflow: string, limit: number, retryWakeAt?: number): Promise<boolean>;
|
|
188
189
|
createRun(run: WorkflowRun): Promise<void>;
|
|
189
|
-
updateRun(runId: string,
|
|
190
|
+
updateRun(runId: string, inputPatch: Partial<WorkflowRun>): Promise<void>;
|
|
190
191
|
/** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors
|
|
191
192
|
* the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */
|
|
192
193
|
private reindexAttributes;
|
package/dist/index.d.ts
CHANGED
|
@@ -185,8 +185,9 @@ declare class MikroOrmStateStore implements StateStore {
|
|
|
185
185
|
*/
|
|
186
186
|
private fork;
|
|
187
187
|
ensureSchema(): Promise<void>;
|
|
188
|
+
tryAdmitSingleton(runId: string, tag: string, workflow: string, limit: number, retryWakeAt?: number): Promise<boolean>;
|
|
188
189
|
createRun(run: WorkflowRun): Promise<void>;
|
|
189
|
-
updateRun(runId: string,
|
|
190
|
+
updateRun(runId: string, inputPatch: Partial<WorkflowRun>): Promise<void>;
|
|
190
191
|
/** Rewrite a run's normalized attribute rows: delete the old set, insert the current one. Mirrors
|
|
191
192
|
* the in-memory store's reindex so the side-table always reflects the run's live searchAttributes. */
|
|
192
193
|
private reindexAttributes;
|
package/dist/index.js
CHANGED
|
@@ -633,7 +633,7 @@ __name(durableEntities, "durableEntities");
|
|
|
633
633
|
var ENTITIES = durableEntities();
|
|
634
634
|
|
|
635
635
|
// src/mikro-orm-state-store.ts
|
|
636
|
-
import { ENGINE_MINTED_TAG_PREFIXES, RUN_VALUE_FACET_LIMIT, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, facetOrigin, mergeRunFacetRows, normalizeAttributeRows, parseDuration } from "@dudousxd/nestjs-durable-core";
|
|
636
|
+
import { ENGINE_MINTED_TAG_PREFIXES, RUN_VALUE_FACET_LIMIT, SINGLETON_ACTIVE_STATUSES, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, clearTerminalSingletonAdmission, facetOrigin, mergeRunFacetRows, normalizeAttributeRows, parseDuration, singletonAdmissionDenialPatch, singletonAdmissionTags } from "@dudousxd/nestjs-durable-core";
|
|
637
637
|
import { raw } from "@mikro-orm/core";
|
|
638
638
|
|
|
639
639
|
// src/schema.ts
|
|
@@ -892,13 +892,50 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
|
|
|
892
892
|
async ensureSchema() {
|
|
893
893
|
await ensureMikroOrmDurableSchema(this.orm);
|
|
894
894
|
}
|
|
895
|
+
async tryAdmitSingleton(runId, tag, workflow, limit, retryWakeAt) {
|
|
896
|
+
return this.fork().transactional(async (em) => {
|
|
897
|
+
const where = {
|
|
898
|
+
workflow,
|
|
899
|
+
status: {
|
|
900
|
+
$in: SINGLETON_ACTIVE_STATUSES
|
|
901
|
+
},
|
|
902
|
+
...this.scopeNamespace !== void 0 ? {
|
|
903
|
+
namespace: this.scopeNamespace
|
|
904
|
+
} : {}
|
|
905
|
+
};
|
|
906
|
+
await em.nativeUpdate(WorkflowRunEntity, where, {
|
|
907
|
+
workflow
|
|
908
|
+
});
|
|
909
|
+
const rows = await em.find(WorkflowRunEntity, where);
|
|
910
|
+
const runs = rows.map(fromRunEntity);
|
|
911
|
+
const tags = singletonAdmissionTags(runs, runId, tag, workflow, limit);
|
|
912
|
+
if (!tags) {
|
|
913
|
+
const patch = singletonAdmissionDenialPatch(runs, runId, tag, workflow, retryWakeAt);
|
|
914
|
+
if (patch) await em.nativeUpdate(WorkflowRunEntity, {
|
|
915
|
+
id: runId
|
|
916
|
+
}, {
|
|
917
|
+
status: "suspended",
|
|
918
|
+
wakeAt: new Date(patch.wakeAt),
|
|
919
|
+
updatedAt: patch.updatedAt
|
|
920
|
+
});
|
|
921
|
+
return false;
|
|
922
|
+
}
|
|
923
|
+
await em.nativeUpdate(WorkflowRunEntity, {
|
|
924
|
+
id: runId
|
|
925
|
+
}, {
|
|
926
|
+
tags
|
|
927
|
+
});
|
|
928
|
+
return true;
|
|
929
|
+
});
|
|
930
|
+
}
|
|
895
931
|
async createRun(run) {
|
|
896
932
|
const em = this.fork();
|
|
897
933
|
em.create(WorkflowRunEntity, toRunEntity(run));
|
|
898
934
|
await em.flush();
|
|
899
935
|
await this.reindexAttributes(run.id, run.searchAttributes);
|
|
900
936
|
}
|
|
901
|
-
async updateRun(runId,
|
|
937
|
+
async updateRun(runId, inputPatch) {
|
|
938
|
+
const patch = inputPatch.status && TERMINAL_RUN_STATUSES.includes(inputPatch.status) ? await clearTerminalSingletonAdmission(runId, inputPatch, (id) => this.withScope({}).getRun(id)) : inputPatch;
|
|
902
939
|
const em = this.fork();
|
|
903
940
|
const entity = await em.findOneOrFail(WorkflowRunEntity, {
|
|
904
941
|
id: runId
|