@apisurf/ngn-persistence 0.3.1 → 0.5.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.
Files changed (2) hide show
  1. package/dist/client.js +39 -0
  2. package/package.json +2 -2
package/dist/client.js CHANGED
@@ -107,6 +107,45 @@ var migrations = [
107
107
  id: "0004-task-run-retry-and-skip-reason",
108
108
  up: `ALTER TABLE task_runs ADD COLUMN retry_of INTEGER REFERENCES task_runs(id) ON DELETE CASCADE;
109
109
  ALTER TABLE task_runs ADD COLUMN skip_reason TEXT`
110
+ },
111
+ // Each scheduled task's schedule, a small state machine, and the log of every
112
+ // change to it: a transition updates the row and appends its event in one
113
+ // write, and each event carries the row as it left it, so the row is always
114
+ // the fold of its log. A tick's final run records the next run decided after it.
115
+ {
116
+ id: "0005-schedules",
117
+ up: `CREATE TABLE IF NOT EXISTS schedules (
118
+ file_task_id INTEGER PRIMARY KEY NOT NULL REFERENCES file_tasks(id) ON DELETE CASCADE,
119
+ state TEXT NOT NULL,
120
+ next_at INTEGER,
121
+ reason TEXT,
122
+ source TEXT,
123
+ holder TEXT,
124
+ anchor INTEGER,
125
+ request TEXT,
126
+ updated_at INTEGER NOT NULL
127
+ );
128
+ CREATE TABLE IF NOT EXISTS schedule_events (
129
+ id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
130
+ file_task_id INTEGER NOT NULL REFERENCES file_tasks(id) ON DELETE CASCADE,
131
+ at INTEGER NOT NULL,
132
+ event TEXT NOT NULL,
133
+ from_state TEXT,
134
+ to_state TEXT NOT NULL,
135
+ next_at INTEGER,
136
+ reason TEXT,
137
+ source TEXT,
138
+ holder TEXT,
139
+ anchor INTEGER,
140
+ request TEXT,
141
+ origin TEXT,
142
+ first_run_id INTEGER,
143
+ run_id INTEGER,
144
+ previous_next_at INTEGER
145
+ );
146
+ CREATE INDEX schedule_events_task_idx ON schedule_events(file_task_id, id);
147
+ ALTER TABLE task_runs ADD COLUMN next_at INTEGER;
148
+ ALTER TABLE task_runs ADD COLUMN next_reason TEXT`
110
149
  }
111
150
  ];
112
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apisurf/ngn-persistence",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "ngn SQLite persistence: connection pragmas, migrations and the client.",
5
5
  "type": "module",
6
6
  "author": "Luka Vidakovic",
@@ -37,7 +37,7 @@
37
37
  "@libsql/client": "^0.14.0",
38
38
  "tiny-invariant": "^1.3.3",
39
39
  "zod": "^3.24.2",
40
- "@apisurf/ngn-os": "0.3.1"
40
+ "@apisurf/ngn-os": "0.5.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^22.8.1",