@dudousxd/nestjs-durable-store-mikro-orm 0.26.0 → 0.27.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.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _mikro_orm_core from '@mikro-orm/core';
2
2
  import { EntityRepository, EntityRepositoryType, EntitySchema, MikroORM } from '@mikro-orm/core';
3
- import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, SignalWaiter } from '@dudousxd/nestjs-durable-core';
3
+ import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, SignalWaiter } from '@dudousxd/nestjs-durable-core';
4
4
 
5
5
  /**
6
6
  * Custom repositories for the durable entities, so a host app can `@InjectRepository`/inject a
@@ -29,6 +29,8 @@ declare class BufferedSignalRepository extends EntityRepository<BufferedSignalEn
29
29
  }
30
30
  declare class BufferedEventRepository extends EntityRepository<BufferedEventEntity> {
31
31
  }
32
+ declare class ScheduleRepository extends EntityRepository<ScheduleEntity> {
33
+ }
32
34
 
33
35
  /**
34
36
  * How property names map to physical column names. The durable tables are adapter-agnostic: a run
@@ -121,6 +123,22 @@ declare class BufferedEventEntity {
121
123
  payload?: unknown;
122
124
  publishedAt: Date;
123
125
  }
126
+ /** A persisted schedule (`engine.schedules`). `spec`/`state` are engine-owned JSON documents. */
127
+ declare class ScheduleEntity {
128
+ [EntityRepositoryType]?: ScheduleRepository;
129
+ id: string;
130
+ namespace: string;
131
+ workflow: string;
132
+ paused: boolean;
133
+ /** Epoch ms as a `bigint` column — exact, so `updateSchedule`'s compare-and-set can't be defeated
134
+ * by a DATETIME's truncated milliseconds. Drivers may hand it back as a string. */
135
+ nextFireAt?: number | string | bigint | null;
136
+ tags?: string[] | null;
137
+ spec: Record<string, unknown>;
138
+ state: Record<string, unknown>;
139
+ createdAt: Date;
140
+ updatedAt: Date;
141
+ }
124
142
  declare function durableEntities(options?: {
125
143
  naming?: DurableColumnNaming;
126
144
  }): EntitySchema[];
@@ -174,6 +192,7 @@ declare class MikroOrmStateStore implements StateStore {
174
192
  private reindexAttributes;
175
193
  getRun(runId: string): Promise<WorkflowRun | null>;
176
194
  deleteRun(runId: string): Promise<void>;
195
+ deleteRuns(runIds: string[]): Promise<void>;
177
196
  pruneTerminalRuns(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
178
197
  getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
179
198
  saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
@@ -199,6 +218,7 @@ declare class MikroOrmStateStore implements StateStore {
199
218
  /** `tags LIKE '%"etl"%'` — the quoted token, so `etl` doesn't match `etl-foo`. See the note in
200
219
  * {@link listRuns} for why this is raw SQL rather than a MikroORM condition. */
201
220
  private tagLikeSql;
221
+ countRuns(query: Omit<RunQuery, 'limit' | 'offset'>): Promise<number>;
202
222
  /** `GROUP BY status, origin` over the same predicates {@link listRuns} pages — one aggregate, so a
203
223
  * console can show whole-set counts next to a bounded page instead of downloading every run to
204
224
  * count them in the browser. */
@@ -257,6 +277,13 @@ declare class MikroOrmStateStore implements StateStore {
257
277
  private jsonAsText;
258
278
  /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */
259
279
  private idQuote;
280
+ saveSchedule(record: ScheduleRecord): Promise<void>;
281
+ getSchedule(id: string): Promise<ScheduleRecord | null>;
282
+ /** One conditional `nativeUpdate`: the compare-and-set on `next_fire_at` (an exact bigint) is a
283
+ * single statement. */
284
+ updateSchedule(id: string, patch: Partial<Omit<ScheduleRecord, 'id' | 'createdAt'>>, expectedNextFireAt?: number | null): Promise<boolean>;
285
+ deleteSchedule(id: string): Promise<boolean>;
286
+ listSchedules(query: ScheduleQuery): Promise<ScheduleRecord[]>;
260
287
  listCheckpoints(runId: string): Promise<StepCheckpoint[]>;
261
288
  getLatestCheckpointByName(runId: string, name: string): Promise<StepCheckpoint | undefined>;
262
289
  listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
@@ -327,4 +354,4 @@ declare function durableManagedTables(): string[];
327
354
  */
328
355
  declare function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void>;
329
356
 
330
- export { BufferedEventEntity, BufferedEventRepository, BufferedSignalEntity, BufferedSignalRepository, type DurableColumnNaming, ENTITIES, MikroOrmStateStore, type MikroOrmStateStoreOptions, RunAttributeEntity, RunAttributeRepository, SignalWaiterEntity, SignalWaiterRepository, StepCheckpointEntity, StepCheckpointRepository, WorkflowRunEntity, WorkflowRunRepository, durableEntities, durableManagedTables, ensureMikroOrmDurableSchema };
357
+ export { BufferedEventEntity, BufferedEventRepository, BufferedSignalEntity, BufferedSignalRepository, type DurableColumnNaming, ENTITIES, MikroOrmStateStore, type MikroOrmStateStoreOptions, RunAttributeEntity, RunAttributeRepository, ScheduleEntity, ScheduleRepository, SignalWaiterEntity, SignalWaiterRepository, StepCheckpointEntity, StepCheckpointRepository, WorkflowRunEntity, WorkflowRunRepository, durableEntities, durableManagedTables, ensureMikroOrmDurableSchema };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _mikro_orm_core from '@mikro-orm/core';
2
2
  import { EntityRepository, EntityRepositoryType, EntitySchema, MikroORM } from '@mikro-orm/core';
3
- import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, SignalWaiter } from '@dudousxd/nestjs-durable-core';
3
+ import { StepKind, RunStatus, StateStore, WorkflowRun, RetentionPolicy, StepCheckpoint, RunQuery, RunFacetQuery, RunFacetRow, RunValueAxis, RunValueFacetOptions, RunValueFacetRow, ScheduleRecord, ScheduleQuery, SignalWaiter } from '@dudousxd/nestjs-durable-core';
4
4
 
5
5
  /**
6
6
  * Custom repositories for the durable entities, so a host app can `@InjectRepository`/inject a
@@ -29,6 +29,8 @@ declare class BufferedSignalRepository extends EntityRepository<BufferedSignalEn
29
29
  }
30
30
  declare class BufferedEventRepository extends EntityRepository<BufferedEventEntity> {
31
31
  }
32
+ declare class ScheduleRepository extends EntityRepository<ScheduleEntity> {
33
+ }
32
34
 
33
35
  /**
34
36
  * How property names map to physical column names. The durable tables are adapter-agnostic: a run
@@ -121,6 +123,22 @@ declare class BufferedEventEntity {
121
123
  payload?: unknown;
122
124
  publishedAt: Date;
123
125
  }
126
+ /** A persisted schedule (`engine.schedules`). `spec`/`state` are engine-owned JSON documents. */
127
+ declare class ScheduleEntity {
128
+ [EntityRepositoryType]?: ScheduleRepository;
129
+ id: string;
130
+ namespace: string;
131
+ workflow: string;
132
+ paused: boolean;
133
+ /** Epoch ms as a `bigint` column — exact, so `updateSchedule`'s compare-and-set can't be defeated
134
+ * by a DATETIME's truncated milliseconds. Drivers may hand it back as a string. */
135
+ nextFireAt?: number | string | bigint | null;
136
+ tags?: string[] | null;
137
+ spec: Record<string, unknown>;
138
+ state: Record<string, unknown>;
139
+ createdAt: Date;
140
+ updatedAt: Date;
141
+ }
124
142
  declare function durableEntities(options?: {
125
143
  naming?: DurableColumnNaming;
126
144
  }): EntitySchema[];
@@ -174,6 +192,7 @@ declare class MikroOrmStateStore implements StateStore {
174
192
  private reindexAttributes;
175
193
  getRun(runId: string): Promise<WorkflowRun | null>;
176
194
  deleteRun(runId: string): Promise<void>;
195
+ deleteRuns(runIds: string[]): Promise<void>;
177
196
  pruneTerminalRuns(policy: RetentionPolicy, nowMs: number, limit: number): Promise<number>;
178
197
  getCheckpoint(runId: string, seq: number): Promise<StepCheckpoint | null>;
179
198
  saveCheckpoint(checkpoint: StepCheckpoint): Promise<void>;
@@ -199,6 +218,7 @@ declare class MikroOrmStateStore implements StateStore {
199
218
  /** `tags LIKE '%"etl"%'` — the quoted token, so `etl` doesn't match `etl-foo`. See the note in
200
219
  * {@link listRuns} for why this is raw SQL rather than a MikroORM condition. */
201
220
  private tagLikeSql;
221
+ countRuns(query: Omit<RunQuery, 'limit' | 'offset'>): Promise<number>;
202
222
  /** `GROUP BY status, origin` over the same predicates {@link listRuns} pages — one aggregate, so a
203
223
  * console can show whole-set counts next to a bounded page instead of downloading every run to
204
224
  * count them in the browser. */
@@ -257,6 +277,13 @@ declare class MikroOrmStateStore implements StateStore {
257
277
  private jsonAsText;
258
278
  /** Quote an identifier per the active SQL driver (MySQL/MariaDB backtick, others double-quote). */
259
279
  private idQuote;
280
+ saveSchedule(record: ScheduleRecord): Promise<void>;
281
+ getSchedule(id: string): Promise<ScheduleRecord | null>;
282
+ /** One conditional `nativeUpdate`: the compare-and-set on `next_fire_at` (an exact bigint) is a
283
+ * single statement. */
284
+ updateSchedule(id: string, patch: Partial<Omit<ScheduleRecord, 'id' | 'createdAt'>>, expectedNextFireAt?: number | null): Promise<boolean>;
285
+ deleteSchedule(id: string): Promise<boolean>;
286
+ listSchedules(query: ScheduleQuery): Promise<ScheduleRecord[]>;
260
287
  listCheckpoints(runId: string): Promise<StepCheckpoint[]>;
261
288
  getLatestCheckpointByName(runId: string, name: string): Promise<StepCheckpoint | undefined>;
262
289
  listCheckpointsByNamePrefix(runId: string, prefixes: string[]): Promise<StepCheckpoint[]>;
@@ -327,4 +354,4 @@ declare function durableManagedTables(): string[];
327
354
  */
328
355
  declare function ensureMikroOrmDurableSchema(orm: MikroORM): Promise<void>;
329
356
 
330
- export { BufferedEventEntity, BufferedEventRepository, BufferedSignalEntity, BufferedSignalRepository, type DurableColumnNaming, ENTITIES, MikroOrmStateStore, type MikroOrmStateStoreOptions, RunAttributeEntity, RunAttributeRepository, SignalWaiterEntity, SignalWaiterRepository, StepCheckpointEntity, StepCheckpointRepository, WorkflowRunEntity, WorkflowRunRepository, durableEntities, durableManagedTables, ensureMikroOrmDurableSchema };
357
+ export { BufferedEventEntity, BufferedEventRepository, BufferedSignalEntity, BufferedSignalRepository, type DurableColumnNaming, ENTITIES, MikroOrmStateStore, type MikroOrmStateStoreOptions, RunAttributeEntity, RunAttributeRepository, ScheduleEntity, ScheduleRepository, SignalWaiterEntity, SignalWaiterRepository, StepCheckpointEntity, StepCheckpointRepository, WorkflowRunEntity, WorkflowRunRepository, durableEntities, durableManagedTables, ensureMikroOrmDurableSchema };
package/dist/index.js CHANGED
@@ -36,6 +36,11 @@ var BufferedEventRepository = class extends EntityRepository {
36
36
  __name(this, "BufferedEventRepository");
37
37
  }
38
38
  };
39
+ var ScheduleRepository = class extends EntityRepository {
40
+ static {
41
+ __name(this, "ScheduleRepository");
42
+ }
43
+ };
39
44
 
40
45
  // src/entities.ts
41
46
  function snakeCase(property) {
@@ -135,6 +140,24 @@ var BufferedEventEntity = class {
135
140
  payload;
136
141
  publishedAt;
137
142
  };
143
+ var ScheduleEntity = class {
144
+ static {
145
+ __name(this, "ScheduleEntity");
146
+ }
147
+ [EntityRepositoryType];
148
+ id;
149
+ namespace;
150
+ workflow;
151
+ paused;
152
+ /** Epoch ms as a `bigint` column — exact, so `updateSchedule`'s compare-and-set can't be defeated
153
+ * by a DATETIME's truncated milliseconds. Drivers may hand it back as a string. */
154
+ nextFireAt;
155
+ tags;
156
+ spec;
157
+ state;
158
+ createdAt;
159
+ updatedAt;
160
+ };
138
161
  function namespaceFilterCond(args) {
139
162
  if (args?.namespace === void 0) return {};
140
163
  return {
@@ -534,20 +557,83 @@ function durableEntities(options = {}) {
534
557
  }
535
558
  }
536
559
  });
560
+ const schedules = new EntitySchema({
561
+ class: ScheduleEntity,
562
+ tableName: "durable_schedules",
563
+ repository: /* @__PURE__ */ __name(() => ScheduleRepository, "repository"),
564
+ // The poll's "due by T" scan: `paused = false AND next_fire_at <= T ORDER BY next_fire_at`.
565
+ indexes: [
566
+ {
567
+ name: "durable_schedules_due_idx",
568
+ properties: [
569
+ "paused",
570
+ "nextFireAt"
571
+ ]
572
+ }
573
+ ],
574
+ properties: {
575
+ id: {
576
+ type: "string",
577
+ primary: true,
578
+ fieldName: col("id")
579
+ },
580
+ namespace: {
581
+ type: "string",
582
+ default: "default",
583
+ fieldName: col("namespace")
584
+ },
585
+ workflow: {
586
+ type: "string",
587
+ fieldName: col("workflow")
588
+ },
589
+ paused: {
590
+ type: "boolean",
591
+ default: false,
592
+ fieldName: col("paused")
593
+ },
594
+ nextFireAt: {
595
+ type: "bigint",
596
+ nullable: true,
597
+ fieldName: col("nextFireAt")
598
+ },
599
+ tags: {
600
+ type: "json",
601
+ nullable: true,
602
+ fieldName: col("tags")
603
+ },
604
+ spec: {
605
+ type: "json",
606
+ fieldName: col("spec")
607
+ },
608
+ state: {
609
+ type: "json",
610
+ fieldName: col("state")
611
+ },
612
+ createdAt: {
613
+ type: "Date",
614
+ fieldName: col("createdAt")
615
+ },
616
+ updatedAt: {
617
+ type: "Date",
618
+ fieldName: col("updatedAt")
619
+ }
620
+ }
621
+ });
537
622
  return [
538
623
  workflowRuns,
539
624
  stepCheckpoints,
540
625
  runAttributes,
541
626
  signalWaiters,
542
627
  bufferedSignals,
543
- bufferedEvents
628
+ bufferedEvents,
629
+ schedules
544
630
  ];
545
631
  }
546
632
  __name(durableEntities, "durableEntities");
547
633
  var ENTITIES = durableEntities();
548
634
 
549
635
  // src/mikro-orm-state-store.ts
550
- import { ENGINE_MINTED_TAG_PREFIXES, RUN_VALUE_FACET_LIMIT, attributePredicateOperands, axisIsRunColumn, facetOrigin, mergeRunFacetRows, normalizeAttributeRows, parseDuration } from "@dudousxd/nestjs-durable-core";
636
+ import { ENGINE_MINTED_TAG_PREFIXES, RUN_VALUE_FACET_LIMIT, TERMINAL_RUN_STATUSES, attributePredicateOperands, axisIsRunColumn, facetOrigin, mergeRunFacetRows, normalizeAttributeRows, parseDuration } from "@dudousxd/nestjs-durable-core";
551
637
  import { raw } from "@mikro-orm/core";
552
638
 
553
639
  // src/schema.ts
@@ -558,7 +644,8 @@ var DURABLE_TABLE_NAMES = /* @__PURE__ */ new Set([
558
644
  "durable_run_attributes",
559
645
  "durable_signal_waiters",
560
646
  "durable_buffered_signals",
561
- "durable_buffered_events"
647
+ "durable_buffered_events",
648
+ "durable_schedules"
562
649
  ]);
563
650
  function durableManagedTables() {
564
651
  return [
@@ -855,71 +942,69 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
855
942
  id: runId
856
943
  });
857
944
  }
945
+ async deleteRuns(runIds) {
946
+ if (runIds.length === 0) return;
947
+ const runId = {
948
+ $in: runIds
949
+ };
950
+ await this.fork().transactional(async (tem) => {
951
+ await tem.nativeDelete(StepCheckpointEntity, {
952
+ runId
953
+ });
954
+ await tem.nativeDelete(SignalWaiterEntity, {
955
+ runId
956
+ });
957
+ await tem.nativeDelete(RunAttributeEntity, {
958
+ runId
959
+ });
960
+ await tem.nativeDelete(WorkflowRunEntity, {
961
+ id: runId
962
+ });
963
+ });
964
+ }
858
965
  async pruneTerminalRuns(policy, nowMs, limit) {
859
- if (policy.statuses.length === 0 || limit <= 0) return 0;
966
+ const statuses = policy.statuses.filter((s) => TERMINAL_RUN_STATUSES.includes(s));
967
+ if (statuses.length === 0 || limit <= 0) return 0;
968
+ if (policy.maxAge == null && policy.maxCount == null) return 0;
860
969
  const em = this.fork();
861
- const status = {
862
- $in: policy.statuses
970
+ const meta = em.getMetadata().get(WorkflowRunEntity);
971
+ const idCol = meta.properties.id?.fieldNames?.[0] ?? "id";
972
+ const query = {
973
+ ...policy.scope ?? {},
974
+ statuses
863
975
  };
976
+ const scoped = /* @__PURE__ */ __name((extra) => this.runQueryBuilder(em, query, {
977
+ ...this.runWhere(query),
978
+ ...extra ?? {}
979
+ }).select([
980
+ `r.${idCol}`
981
+ ]), "scoped");
864
982
  const ids = /* @__PURE__ */ new Set();
865
983
  if (policy.maxAge != null) {
866
984
  const cutoff = new Date(nowMs - parseDuration(policy.maxAge));
867
- const rows = await em.find(WorkflowRunEntity, {
868
- status,
985
+ const rows = await scoped({
869
986
  updatedAt: {
870
987
  $lt: cutoff
871
988
  }
872
- }, {
873
- fields: [
874
- "id"
875
- ],
876
- orderBy: {
877
- updatedAt: "asc"
878
- },
879
- limit
880
- });
881
- for (const r of rows) ids.add(r.id);
989
+ }).orderBy({
990
+ "r.updatedAt": "asc"
991
+ }).limit(limit).execute();
992
+ for (const r of rows) ids.add(String(r[idCol] ?? r.id));
882
993
  }
883
994
  if (policy.maxCount != null && ids.size < limit) {
884
- const rows = await em.find(WorkflowRunEntity, {
885
- status
886
- }, {
887
- fields: [
888
- "id"
889
- ],
890
- orderBy: {
891
- updatedAt: "desc",
892
- id: "desc"
893
- },
894
- limit,
895
- offset: policy.maxCount
896
- });
995
+ const rows = await scoped().orderBy({
996
+ "r.updatedAt": "desc",
997
+ "r.id": "desc"
998
+ }).limit(limit).offset(policy.maxCount).execute();
897
999
  for (const r of rows) {
898
- ids.add(r.id);
899
1000
  if (ids.size >= limit) break;
1001
+ ids.add(String(r[idCol] ?? r.id));
900
1002
  }
901
1003
  }
902
- if (ids.size === 0) return 0;
903
1004
  const idList = [
904
1005
  ...ids
905
1006
  ].slice(0, limit);
906
- const runId = {
907
- $in: idList
908
- };
909
- await em.transactional(async (tem) => {
910
- await tem.nativeDelete(StepCheckpointEntity, {
911
- runId
912
- });
913
- await tem.nativeDelete(SignalWaiterEntity, {
914
- runId
915
- });
916
- await tem.nativeDelete(RunAttributeEntity, {
917
- runId
918
- });
919
- await tem.nativeDelete(WorkflowRunEntity, {
920
- id: runId
921
- });
922
- });
1007
+ await this.deleteRuns(idList);
923
1008
  return idList.length;
924
1009
  }
925
1010
  async getCheckpoint(runId, seq) {
@@ -1131,6 +1216,11 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1131
1216
  const colExpr = this.jsonAsText(em, `${quote("r")}.${quote(this.tagsColumn(em))}`);
1132
1217
  return `${colExpr} LIKE '${pattern}'`;
1133
1218
  }
1219
+ async countRuns(query) {
1220
+ const em = this.fork();
1221
+ const rows = await this.runQueryBuilder(em, query, this.runWhere(query)).select([]).addSelect(raw("count(*) as count")).execute();
1222
+ return Number(rows[0]?.count ?? 0);
1223
+ }
1134
1224
  /** `GROUP BY status, origin` over the same predicates {@link listRuns} pages — one aggregate, so a
1135
1225
  * console can show whole-set counts next to a bounded page instead of downloading every run to
1136
1226
  * count them in the browser. */
@@ -1322,6 +1412,76 @@ var MikroOrmStateStore = class _MikroOrmStateStore {
1322
1412
  const ch = isMysql ? "`" : '"';
1323
1413
  return (id) => `${ch}${id}${ch}`;
1324
1414
  }
1415
+ // ---- persisted schedules ----------------------------------------------------------------------
1416
+ async saveSchedule(record) {
1417
+ const em = this.fork();
1418
+ await em.upsert(ScheduleEntity, toScheduleEntity(record));
1419
+ }
1420
+ async getSchedule(id) {
1421
+ const entity = await this.fork().findOne(ScheduleEntity, {
1422
+ id
1423
+ });
1424
+ return entity ? fromScheduleEntity(entity) : null;
1425
+ }
1426
+ /** One conditional `nativeUpdate`: the compare-and-set on `next_fire_at` (an exact bigint) is a
1427
+ * single statement. */
1428
+ async updateSchedule(id, patch, expectedNextFireAt) {
1429
+ const data = {};
1430
+ if (patch.namespace !== void 0) data.namespace = patch.namespace;
1431
+ if (patch.workflow !== void 0) data.workflow = patch.workflow;
1432
+ if (patch.paused !== void 0) data.paused = patch.paused;
1433
+ if ("nextFireAt" in patch) data.nextFireAt = patch.nextFireAt ?? null;
1434
+ if ("tags" in patch) data.tags = patch.tags ?? null;
1435
+ if (patch.spec !== void 0) data.spec = patch.spec;
1436
+ if (patch.state !== void 0) data.state = patch.state;
1437
+ if (patch.updatedAt !== void 0) data.updatedAt = patch.updatedAt;
1438
+ if (!Object.keys(data).length) return await this.getSchedule(id) !== null;
1439
+ const where = {
1440
+ id
1441
+ };
1442
+ if (expectedNextFireAt !== void 0) where.nextFireAt = expectedNextFireAt;
1443
+ const affected = await this.fork().nativeUpdate(ScheduleEntity, where, data);
1444
+ return affected > 0;
1445
+ }
1446
+ async deleteSchedule(id) {
1447
+ return await this.fork().nativeDelete(ScheduleEntity, {
1448
+ id
1449
+ }) > 0;
1450
+ }
1451
+ async listSchedules(query) {
1452
+ const em = this.fork();
1453
+ const where = {};
1454
+ if (query.namespace !== void 0) where.namespace = query.namespace;
1455
+ if (query.workflow !== void 0) where.workflow = query.workflow;
1456
+ if (query.paused !== void 0) where.paused = query.paused;
1457
+ if (query.dueBy !== void 0) {
1458
+ where.$and = [
1459
+ {
1460
+ paused: false
1461
+ },
1462
+ {
1463
+ nextFireAt: {
1464
+ $lte: query.dueBy
1465
+ }
1466
+ }
1467
+ ];
1468
+ }
1469
+ const quote = this.idQuote(em);
1470
+ const meta = em.getMetadata().get(ScheduleEntity);
1471
+ const tagsCol = meta.properties.tags?.fieldNames?.[0] ?? "tags";
1472
+ const qb = em.createQueryBuilder(ScheduleEntity, "r").where(where);
1473
+ if (query.tag !== void 0) {
1474
+ const pattern = `%"${query.tag.replace(/'/g, "''")}"%`;
1475
+ qb.andWhere(`${this.jsonAsText(em, `${quote("r")}.${quote(tagsCol)}`)} LIKE '${pattern}'`);
1476
+ }
1477
+ qb.orderBy({
1478
+ "r.nextFireAt": "asc nulls last",
1479
+ "r.id": "asc"
1480
+ });
1481
+ if (query.limit != null) qb.limit(query.limit);
1482
+ if (query.offset != null) qb.offset(query.offset);
1483
+ return (await qb.getResultList()).map(fromScheduleEntity);
1484
+ }
1325
1485
  async listCheckpoints(runId) {
1326
1486
  const em = this.fork();
1327
1487
  const rows = await em.find(StepCheckpointEntity, {
@@ -1560,6 +1720,38 @@ function fromCheckpointEntity(e) {
1560
1720
  };
1561
1721
  }
1562
1722
  __name(fromCheckpointEntity, "fromCheckpointEntity");
1723
+ function toScheduleEntity(r) {
1724
+ const e = new ScheduleEntity();
1725
+ e.id = r.id;
1726
+ e.namespace = r.namespace;
1727
+ e.workflow = r.workflow;
1728
+ e.paused = r.paused;
1729
+ e.nextFireAt = r.nextFireAt;
1730
+ e.tags = r.tags ?? null;
1731
+ e.spec = r.spec;
1732
+ e.state = r.state;
1733
+ e.createdAt = r.createdAt;
1734
+ e.updatedAt = r.updatedAt;
1735
+ return e;
1736
+ }
1737
+ __name(toScheduleEntity, "toScheduleEntity");
1738
+ function fromScheduleEntity(e) {
1739
+ return {
1740
+ id: e.id,
1741
+ namespace: e.namespace,
1742
+ workflow: e.workflow,
1743
+ paused: Boolean(e.paused),
1744
+ nextFireAt: e.nextFireAt == null ? null : Number(e.nextFireAt),
1745
+ ...e.tags?.length ? {
1746
+ tags: e.tags
1747
+ } : {},
1748
+ spec: e.spec ?? {},
1749
+ state: e.state ?? {},
1750
+ createdAt: e.createdAt,
1751
+ updatedAt: e.updatedAt
1752
+ };
1753
+ }
1754
+ __name(fromScheduleEntity, "fromScheduleEntity");
1563
1755
  export {
1564
1756
  BufferedEventEntity,
1565
1757
  BufferedEventRepository,
@@ -1569,6 +1761,8 @@ export {
1569
1761
  MikroOrmStateStore,
1570
1762
  RunAttributeEntity,
1571
1763
  RunAttributeRepository,
1764
+ ScheduleEntity,
1765
+ ScheduleRepository,
1572
1766
  SignalWaiterEntity,
1573
1767
  SignalWaiterRepository,
1574
1768
  StepCheckpointEntity,