@alineo-labs/sqlite 0.1.2 → 0.2.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/README.md CHANGED
@@ -13,10 +13,10 @@ For production workloads that need durability across multiple processes or machi
13
13
  ## Usage
14
14
 
15
15
  ```ts
16
- import { Alineo } from "alineo";
16
+ import { Sandbox } from "@alineo-labs/sandbox";
17
17
  import { SQLiteAdapter } from "@alineo-labs/sqlite";
18
18
 
19
- const client = new Alineo({
19
+ const client = new Sandbox({
20
20
  baseUrl: "http://localhost:8080",
21
21
  adapter: new SQLiteAdapter("./ledger.db"),
22
22
  });
package/dist/index.mjs CHANGED
@@ -37,7 +37,10 @@ const AGG_SQL = (whereClause) => `
37
37
  MAX(CASE WHEN event = 'sandbox_closed' THEN ts END) AS completed_at,
38
38
  MAX(CASE WHEN event = 'sandbox_closed' THEN 1 ELSE 0 END) AS is_closed,
39
39
  CAST(COUNT(CASE WHEN event = 'exec_complete' THEN 1 END) AS INTEGER) AS exec_count,
40
- MAX(CASE WHEN event = 'sandbox_created' THEN json_extract(payload, '$.runId') END) AS run_id
40
+ MAX(CASE WHEN event = 'sandbox_created' THEN json_extract(payload, '$.runId') END) AS run_id,
41
+ MAX(CASE WHEN event = 'sandbox_created' THEN json_extract(payload, '$.resourceId') END) AS resource_id,
42
+ MAX(CASE WHEN event = 'sandbox_created' THEN json_extract(payload, '$.teamId') END) AS team_id,
43
+ MAX(CASE WHEN event = 'sandbox_created' THEN json_extract(payload, '$.parentSandboxId') END) AS parent_sandbox_id
41
44
  FROM alineo_events
42
45
  ${whereClause}
43
46
  GROUP BY name, sandbox_id
@@ -45,6 +48,7 @@ const AGG_SQL = (whereClause) => `
45
48
  SELECT * FROM agg WHERE started_at IS NOT NULL ORDER BY started_at DESC
46
49
  `;
47
50
  function aggRowToDetails(row) {
51
+ if (row.started_at == null) throw new Error(`corrupt ledger: aggregated row for ${row.name}/${row.sandbox_id} has no started_at`);
48
52
  return {
49
53
  name: row.name,
50
54
  sandboxId: row.sandbox_id,
@@ -52,14 +56,22 @@ function aggRowToDetails(row) {
52
56
  startedAt: row.started_at,
53
57
  completedAt: row.completed_at ?? void 0,
54
58
  execCount: row.exec_count,
55
- runId: row.run_id ?? row.sandbox_id
59
+ runId: row.run_id ?? row.sandbox_id,
60
+ resourceId: row.resource_id ?? void 0,
61
+ teamId: row.team_id ?? void 0,
62
+ parentSandboxId: row.parent_sandbox_id ?? void 0
56
63
  };
57
64
  }
58
65
  function applyOpts(details, opts) {
59
66
  let result = details;
60
- if (opts?.before != null) result = result.filter((d) => d.startedAt < opts.before);
67
+ if (opts?.before != null) {
68
+ const before = opts.before;
69
+ result = result.filter((d) => d.startedAt < before);
70
+ }
61
71
  if (opts?.status != null) result = result.filter((d) => d.status === opts.status);
62
72
  if (opts?.runId != null) result = result.filter((d) => d.runId === opts.runId);
73
+ if (opts?.resourceId != null) result = result.filter((d) => d.resourceId === opts.resourceId);
74
+ if (opts?.teamId != null) result = result.filter((d) => d.teamId === opts.teamId);
63
75
  if (opts?.limit != null) result = result.slice(0, opts.limit);
64
76
  return result;
65
77
  }
@@ -86,8 +98,8 @@ var SQLiteAdapter = class {
86
98
  this.db = new Database(path, { create: true });
87
99
  }
88
100
  async connect() {
89
- this.db.exec(MIGRATION_SQL);
90
- this.db.exec("PRAGMA journal_mode = WAL;");
101
+ this.db.run(MIGRATION_SQL);
102
+ this.db.run("PRAGMA journal_mode = WAL;");
91
103
  }
92
104
  async close() {
93
105
  this.db.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alineo-labs/sqlite",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "test": "bun test"
29
29
  },
30
30
  "dependencies": {
31
- "@alineo-labs/core": "0.1.0"
31
+ "@alineo-labs/core": "0.3.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "bun-types": "1.3.14",