@sentry/junior-scheduler 0.108.0 → 0.109.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 CHANGED
@@ -1,4 +1,4 @@
1
1
  export { createSchedulerPlugin, schedulerPlugin } from "./plugin";
2
2
  export { createSlackScheduleCreateTaskTool, createSlackScheduleDeleteTaskTool, createSlackScheduleListTasksTool, createSlackScheduleRunTaskNowTool, createSlackScheduleUpdateTaskTool, type SchedulerToolContext, } from "./schedule-tools";
3
- export { createSchedulerOperationalSqlStore, createSchedulerSqlStore, migrateSchedulerStateToSql, type SchedulerDb, } from "./store";
3
+ export { createSchedulerOperationalSqlStore, createSchedulerSqlStore, type SchedulerDb, } from "./store";
4
4
  export type { ScheduledCalendarFrequency, ScheduledLocalTime, ScheduledRun, ScheduledRunStatus, ScheduledTask, ScheduledTaskConversationAccess, ScheduledTaskExecutionActor, ScheduledTaskPrincipal, ScheduledTaskRecurrence, ScheduledTaskSchedule, ScheduledTaskSpec, ScheduledTaskStatus, } from "./types";
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ import {
6
6
 
7
7
  // src/store.ts
8
8
  import {
9
- pluginCredentialSubjectSchema,
10
9
  destinationSchema,
11
10
  isSlackDestination,
12
11
  slackActorSchema
@@ -429,10 +428,6 @@ var taskRecordSchema = z2.object({
429
428
  ...taskRecordFields,
430
429
  credentialMode: scheduledTaskCredentialModeSchema
431
430
  }).strict();
432
- var legacyTaskRecordSchema = z2.object({
433
- ...taskRecordFields,
434
- credentialSubject: pluginCredentialSubjectSchema.optional()
435
- }).strict();
436
431
  var runRecordSchema = z2.object({
437
432
  id: z2.string(),
438
433
  attempt: z2.number(),
@@ -464,31 +459,13 @@ function taskLockKey(taskId) {
464
459
  function runKey(runId) {
465
460
  return `${SCHEDULER_KEY_PREFIX}:run:${runId}`;
466
461
  }
467
- function activeRunKey(taskId) {
468
- return `${SCHEDULER_KEY_PREFIX}:active:${taskId}`;
469
- }
470
- function globalTaskIndexKey() {
471
- return `${SCHEDULER_KEY_PREFIX}:tasks`;
472
- }
473
462
  function indexLockKey(indexKey) {
474
463
  return `${indexKey}:lock`;
475
464
  }
476
465
  function buildRunId(taskId, scheduledForMs) {
477
466
  return `${taskId}:${scheduledForMs}`;
478
467
  }
479
- function unique(values) {
480
- return [...new Set(values.filter(Boolean))];
481
- }
482
468
  var schedulerTaskIndexSchema = z2.array(z2.string().min(1));
483
- function parseStringIndex(value) {
484
- return value === void 0 ? [] : schedulerTaskIndexSchema.parse(value);
485
- }
486
- async function getIndex(state, key) {
487
- return unique(parseStringIndex(await state.get(key)));
488
- }
489
- function isFinishedRun(run) {
490
- return run.status === "completed" || run.status === "failed" || run.status === "blocked" || run.status === "skipped";
491
- }
492
469
  function isStalePendingRun(run, nowMs) {
493
470
  return run?.status === "pending" && run.claimedAtMs + PENDING_CLAIM_STALE_MS <= nowMs;
494
471
  }
@@ -564,25 +541,6 @@ function parseStoredTask(value) {
564
541
  const parsed = taskRecordSchema.safeParse(parseJsonRecord(value));
565
542
  return parsed.success ? stripLegacyTaskFields(parsed.data) : void 0;
566
543
  }
567
- function parseLegacyStoredTaskForMigration(value) {
568
- const parsed = legacyTaskRecordSchema.safeParse(parseJsonRecord(value));
569
- if (!parsed.success) {
570
- return void 0;
571
- }
572
- const {
573
- credentialSubject: _credentialSubject,
574
- version: _version,
575
- ...task
576
- } = parsed.data;
577
- return {
578
- ...task,
579
- credentialMode: "system"
580
- };
581
- }
582
- function parseStoredRun(value) {
583
- const parsed = runRecordSchema.safeParse(parseJsonRecord(value));
584
- return parsed.success ? stripLegacyRunFields(parsed.data) : void 0;
585
- }
586
544
  function stripLegacyTaskFields(task) {
587
545
  const { version: _version, ...current } = task;
588
546
  return current;
@@ -618,23 +576,6 @@ function requireStoredTask(task) {
618
576
  }
619
577
  return parsed;
620
578
  }
621
- async function getRunFromState(state, runId) {
622
- return parseStoredRun(await state.get(runKey(runId)));
623
- }
624
- async function listIncompleteRunsForTasksFromState(state, tasks) {
625
- const runs = [];
626
- for (const task of tasks) {
627
- const active = await state.get(activeRunKey(task.id));
628
- if (typeof active?.runId !== "string") {
629
- continue;
630
- }
631
- const run = await getRunFromState(state, active.runId);
632
- if (run && !isFinishedRun(run)) {
633
- runs.push(run);
634
- }
635
- }
636
- return runs;
637
- }
638
579
  function parseSqlTaskRecord(value) {
639
580
  const parsed = taskRecordSchema.safeParse(parseJsonRecord(value));
640
581
  return parsed.success ? stripLegacyTaskFields(parsed.data) : void 0;
@@ -1046,47 +987,6 @@ function createSchedulerSqlStore(db) {
1046
987
  function createSchedulerOperationalSqlStore(db) {
1047
988
  return new SqlSchedulerStore(db);
1048
989
  }
1049
- async function migrateSchedulerStateToSql(args) {
1050
- const store = createSchedulerSqlStore(args.db);
1051
- const ids = await getIndex(args.state, globalTaskIndexKey());
1052
- let existing = 0;
1053
- let migrated = 0;
1054
- let missing = 0;
1055
- const migratedTasks = [];
1056
- for (const id of ids) {
1057
- const rawTask = await args.state.get(taskKey(id));
1058
- const task = parseStoredTask(rawTask) ?? parseLegacyStoredTaskForMigration(rawTask);
1059
- if (!task) {
1060
- missing += 1;
1061
- continue;
1062
- }
1063
- migratedTasks.push(task);
1064
- if (await store.getTask(task.id)) {
1065
- existing += 1;
1066
- continue;
1067
- }
1068
- await store.saveTask(task);
1069
- migrated += 1;
1070
- }
1071
- const runs = await listIncompleteRunsForTasksFromState(
1072
- args.state,
1073
- migratedTasks
1074
- );
1075
- for (const run of runs) {
1076
- if (await store.getRun(run.id)) {
1077
- existing += 1;
1078
- continue;
1079
- }
1080
- await upsertSqlRun(args.db, run);
1081
- migrated += 1;
1082
- }
1083
- return {
1084
- existing,
1085
- migrated,
1086
- missing,
1087
- scanned: ids.length + runs.length
1088
- };
1089
- }
1090
990
 
1091
991
  // src/identity.ts
1092
992
  var SLACK_USER_ID_PATTERN = /^[UW][A-Z0-9]{5,}$/;
@@ -2292,12 +2192,6 @@ function createSchedulerPlugin() {
2292
2192
  nowMs: ctx.nowMs,
2293
2193
  store: schedulerOperationalStore(ctx)
2294
2194
  });
2295
- },
2296
- async migrateStorage(ctx) {
2297
- return await migrateSchedulerStateToSql({
2298
- db: ctx.db,
2299
- state: ctx.state
2300
- });
2301
2195
  }
2302
2196
  }
2303
2197
  });
@@ -2312,6 +2206,5 @@ export {
2312
2206
  createSlackScheduleListTasksTool,
2313
2207
  createSlackScheduleRunTaskNowTool,
2314
2208
  createSlackScheduleUpdateTaskTool,
2315
- migrateSchedulerStateToSql,
2316
2209
  schedulerPlugin
2317
2210
  };
package/dist/store.d.ts CHANGED
@@ -63,13 +63,3 @@ export declare function createSchedulerOperationalStore(state: PluginReadState):
63
63
  export declare function createSchedulerSqlStore(db: SchedulerDb): SchedulerStore;
64
64
  /** Create a read-only scheduler operational store backed by SQL. */
65
65
  export declare function createSchedulerOperationalSqlStore(db: SchedulerDb): SchedulerOperationalStore;
66
- /** Copy retained scheduler plugin-state records into the scheduler SQL tables. */
67
- export declare function migrateSchedulerStateToSql(args: {
68
- db: SchedulerDb;
69
- state: PluginState;
70
- }): Promise<{
71
- existing: number;
72
- migrated: number;
73
- missing: number;
74
- scanned: number;
75
- }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior-scheduler",
3
- "version": "0.108.0",
3
+ "version": "0.109.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "drizzle-orm": "^0.45.2",
27
27
  "zod": "^4.4.3",
28
- "@sentry/junior-plugin-api": "0.108.0"
28
+ "@sentry/junior-plugin-api": "0.109.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^25.9.1",
package/src/index.ts CHANGED
@@ -10,7 +10,6 @@ export {
10
10
  export {
11
11
  createSchedulerOperationalSqlStore,
12
12
  createSchedulerSqlStore,
13
- migrateSchedulerStateToSql,
14
13
  type SchedulerDb,
15
14
  } from "./store";
16
15
  export type {
package/src/plugin.ts CHANGED
@@ -13,7 +13,6 @@ import {
13
13
  import {
14
14
  createSchedulerOperationalSqlStore,
15
15
  createSchedulerSqlStore,
16
- migrateSchedulerStateToSql,
17
16
  type SchedulerDb,
18
17
  type SchedulerOperationalStore,
19
18
  type SchedulerStore,
@@ -582,12 +581,6 @@ export function createSchedulerPlugin() {
582
581
  store: schedulerOperationalStore(ctx),
583
582
  });
584
583
  },
585
- async migrateStorage(ctx) {
586
- return await migrateSchedulerStateToSql({
587
- db: ctx.db as SchedulerDb,
588
- state: ctx.state,
589
- });
590
- },
591
584
  },
592
585
  });
593
586
  }
package/src/store.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import {
2
- pluginCredentialSubjectSchema,
3
2
  destinationSchema,
4
3
  isSlackDestination,
5
4
  slackActorSchema,
@@ -114,13 +113,6 @@ const taskRecordSchema = z
114
113
  credentialMode: scheduledTaskCredentialModeSchema,
115
114
  })
116
115
  .strict();
117
- // TODO(v0.101.0): Remove parsing for scheduler task records without credentialMode.
118
- const legacyTaskRecordSchema = z
119
- .object({
120
- ...taskRecordFields,
121
- credentialSubject: pluginCredentialSubjectSchema.optional(),
122
- })
123
- .strict();
124
116
  const runRecordSchema = z
125
117
  .object({
126
118
  id: z.string(),
@@ -492,25 +484,6 @@ function parseStoredTask(value: unknown): ScheduledTask | undefined {
492
484
  return parsed.success ? stripLegacyTaskFields(parsed.data) : undefined;
493
485
  }
494
486
 
495
- /** Decode pre-credential-mode tasks only for the state-to-SQL migration. */
496
- function parseLegacyStoredTaskForMigration(
497
- value: unknown,
498
- ): ScheduledTask | undefined {
499
- const parsed = legacyTaskRecordSchema.safeParse(parseJsonRecord(value));
500
- if (!parsed.success) {
501
- return undefined;
502
- }
503
- const {
504
- credentialSubject: _credentialSubject,
505
- version: _version,
506
- ...task
507
- } = parsed.data;
508
- return {
509
- ...task,
510
- credentialMode: "system",
511
- };
512
- }
513
-
514
487
  /** Decode retained scheduler run state, skipping invalid legacy records. */
515
488
  function parseStoredRun(value: unknown): ScheduledRun | undefined {
516
489
  const parsed = runRecordSchema.safeParse(parseJsonRecord(value));
@@ -1715,58 +1688,3 @@ export function createSchedulerOperationalSqlStore(
1715
1688
  ): SchedulerOperationalStore {
1716
1689
  return new SqlSchedulerStore(db);
1717
1690
  }
1718
-
1719
- /** Copy retained scheduler plugin-state records into the scheduler SQL tables. */
1720
- export async function migrateSchedulerStateToSql(args: {
1721
- db: SchedulerDb;
1722
- state: PluginState;
1723
- }): Promise<{
1724
- existing: number;
1725
- migrated: number;
1726
- missing: number;
1727
- scanned: number;
1728
- }> {
1729
- const store = createSchedulerSqlStore(args.db);
1730
- const ids = await getIndex(args.state, globalTaskIndexKey());
1731
- let existing = 0;
1732
- let migrated = 0;
1733
- let missing = 0;
1734
- const migratedTasks: ScheduledTask[] = [];
1735
-
1736
- for (const id of ids) {
1737
- const rawTask = await args.state.get(taskKey(id));
1738
- const task =
1739
- parseStoredTask(rawTask) ?? parseLegacyStoredTaskForMigration(rawTask);
1740
- if (!task) {
1741
- missing += 1;
1742
- continue;
1743
- }
1744
- migratedTasks.push(task);
1745
- if (await store.getTask(task.id)) {
1746
- existing += 1;
1747
- continue;
1748
- }
1749
- await store.saveTask(task);
1750
- migrated += 1;
1751
- }
1752
-
1753
- const runs = await listIncompleteRunsForTasksFromState(
1754
- args.state,
1755
- migratedTasks,
1756
- );
1757
- for (const run of runs) {
1758
- if (await store.getRun(run.id)) {
1759
- existing += 1;
1760
- continue;
1761
- }
1762
- await upsertSqlRun(args.db, run);
1763
- migrated += 1;
1764
- }
1765
-
1766
- return {
1767
- existing,
1768
- migrated,
1769
- missing,
1770
- scanned: ids.length + runs.length,
1771
- };
1772
- }