db4ai 0.3.0 → 0.3.2

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 (89) hide show
  1. package/dist/chunk-3DWAMVV5.js +305 -0
  2. package/dist/chunk-3DWAMVV5.js.map +1 -0
  3. package/dist/chunk-COTPYBYM.js +618 -0
  4. package/dist/chunk-COTPYBYM.js.map +1 -0
  5. package/dist/chunk-EERD6CDF.js +735 -0
  6. package/dist/chunk-EERD6CDF.js.map +1 -0
  7. package/dist/chunk-FUF4HJTC.js +758 -0
  8. package/dist/chunk-FUF4HJTC.js.map +1 -0
  9. package/dist/chunk-JLL6FH5L.js +16 -0
  10. package/dist/chunk-JLL6FH5L.js.map +1 -0
  11. package/dist/chunk-JXFW6AIT.js +192 -0
  12. package/dist/chunk-JXFW6AIT.js.map +1 -0
  13. package/dist/chunk-XLSYCQPG.js +854 -0
  14. package/dist/chunk-XLSYCQPG.js.map +1 -0
  15. package/dist/chunk-Y5IXAS7F.js +569 -0
  16. package/dist/chunk-Y5IXAS7F.js.map +1 -0
  17. package/dist/cli/bin.d.ts +13 -12
  18. package/dist/cli/bin.js +277 -307
  19. package/dist/cli/bin.js.map +1 -1
  20. package/dist/cli/dashboard/index.d.ts +295 -14
  21. package/dist/cli/dashboard/index.js +60 -15
  22. package/dist/cli/dashboard/index.js.map +1 -1
  23. package/dist/cli/index.d.ts +10 -16
  24. package/dist/cli/index.js +94 -47
  25. package/dist/cli/index.js.map +1 -1
  26. package/dist/cli/runtime/index.d.ts +52 -23
  27. package/dist/cli/runtime/index.js +10 -704
  28. package/dist/cli/runtime/index.js.map +1 -1
  29. package/dist/cli/scanner/index.d.ts +17 -15
  30. package/dist/cli/scanner/index.js +8 -639
  31. package/dist/cli/scanner/index.js.map +1 -1
  32. package/dist/cli/seed/index.d.ts +16 -12
  33. package/dist/cli/seed/index.js +12 -773
  34. package/dist/cli/seed/index.js.map +1 -1
  35. package/dist/cli/sync/index.d.ts +54 -53
  36. package/dist/cli/sync/index.js +23 -704
  37. package/dist/cli/sync/index.js.map +1 -1
  38. package/dist/cli/terminal.d.ts +9 -8
  39. package/dist/cli/terminal.js +6 -209
  40. package/dist/cli/terminal.js.map +1 -1
  41. package/dist/cli/workflow/index.d.ts +18 -10
  42. package/dist/cli/workflow/index.js +6 -307
  43. package/dist/cli/workflow/index.js.map +1 -1
  44. package/dist/handlers.d.ts +10 -9
  45. package/dist/handlers.js +6 -38
  46. package/dist/handlers.js.map +1 -1
  47. package/dist/index.d.ts +120 -118
  48. package/dist/index.js +1972 -3125
  49. package/dist/index.js.map +1 -1
  50. package/package.json +3 -4
  51. package/dist/cli/bin.d.ts.map +0 -1
  52. package/dist/cli/dashboard/App.d.ts +0 -16
  53. package/dist/cli/dashboard/App.d.ts.map +0 -1
  54. package/dist/cli/dashboard/App.js +0 -116
  55. package/dist/cli/dashboard/App.js.map +0 -1
  56. package/dist/cli/dashboard/components/index.d.ts +0 -70
  57. package/dist/cli/dashboard/components/index.d.ts.map +0 -1
  58. package/dist/cli/dashboard/components/index.js +0 -192
  59. package/dist/cli/dashboard/components/index.js.map +0 -1
  60. package/dist/cli/dashboard/hooks/index.d.ts +0 -76
  61. package/dist/cli/dashboard/hooks/index.d.ts.map +0 -1
  62. package/dist/cli/dashboard/hooks/index.js +0 -201
  63. package/dist/cli/dashboard/hooks/index.js.map +0 -1
  64. package/dist/cli/dashboard/index.d.ts.map +0 -1
  65. package/dist/cli/dashboard/types.d.ts +0 -84
  66. package/dist/cli/dashboard/types.d.ts.map +0 -1
  67. package/dist/cli/dashboard/types.js +0 -5
  68. package/dist/cli/dashboard/types.js.map +0 -1
  69. package/dist/cli/dashboard/views/index.d.ts +0 -51
  70. package/dist/cli/dashboard/views/index.d.ts.map +0 -1
  71. package/dist/cli/dashboard/views/index.js +0 -72
  72. package/dist/cli/dashboard/views/index.js.map +0 -1
  73. package/dist/cli/index.d.ts.map +0 -1
  74. package/dist/cli/runtime/index.d.ts.map +0 -1
  75. package/dist/cli/scanner/index.d.ts.map +0 -1
  76. package/dist/cli/seed/index.d.ts.map +0 -1
  77. package/dist/cli/sync/index.d.ts.map +0 -1
  78. package/dist/cli/terminal.d.ts.map +0 -1
  79. package/dist/cli/workflow/index.d.ts.map +0 -1
  80. package/dist/errors.d.ts +0 -43
  81. package/dist/errors.d.ts.map +0 -1
  82. package/dist/errors.js +0 -47
  83. package/dist/errors.js.map +0 -1
  84. package/dist/handlers.d.ts.map +0 -1
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/types.d.ts +0 -276
  87. package/dist/types.d.ts.map +0 -1
  88. package/dist/types.js +0 -12
  89. package/dist/types.js.map +0 -1
@@ -1,3 +1,5 @@
1
+ import Database from 'better-sqlite3';
2
+
1
3
  /**
2
4
  * Module 14: Local Runtime
3
5
  *
@@ -5,8 +7,8 @@
5
7
  * Provides the same interface as the Cloudflare Durable Object for
6
8
  * seamless local development and testing.
7
9
  */
8
- import Database from 'better-sqlite3';
9
- export interface Thing {
10
+
11
+ interface Thing {
10
12
  rowid: number;
11
13
  type: string;
12
14
  id: string;
@@ -15,28 +17,28 @@ export interface Thing {
15
17
  created_at: number;
16
18
  created_by_action?: number;
17
19
  }
18
- export interface UpsertResult {
20
+ interface UpsertResult {
19
21
  rowid: number;
20
22
  created: boolean;
21
23
  }
22
- export interface UpsertParams {
24
+ interface UpsertParams {
23
25
  type: string;
24
26
  id: string;
25
27
  data: Record<string, unknown>;
26
28
  created_by_action?: number;
27
29
  }
28
- export interface GetParams {
30
+ interface GetParams {
29
31
  type: string;
30
32
  id: string;
31
33
  }
32
- export interface ListParams {
34
+ interface ListParams {
33
35
  type?: string;
34
36
  limit?: number;
35
37
  offset?: number;
36
38
  where?: Record<string, unknown>;
37
39
  order?: 'asc' | 'desc';
38
40
  }
39
- export interface Relationship {
41
+ interface Relationship {
40
42
  rowid: number;
41
43
  from_rowid: number;
42
44
  to_rowid: number;
@@ -46,7 +48,7 @@ export interface Relationship {
46
48
  created_at: number;
47
49
  created_by_action?: number;
48
50
  }
49
- export interface CreateRelationshipParams {
51
+ interface CreateRelationshipParams {
50
52
  from_rowid: number;
51
53
  to_rowid: number;
52
54
  type: string;
@@ -54,24 +56,24 @@ export interface CreateRelationshipParams {
54
56
  label: string;
55
57
  created_by_action?: number;
56
58
  }
57
- export interface TraverseParams {
59
+ interface TraverseParams {
58
60
  from_rowid: number;
59
61
  type?: string;
60
62
  }
61
- export interface IncomingParams {
63
+ interface IncomingParams {
62
64
  to_rowid: number;
63
65
  type?: string;
64
66
  }
65
- export interface TraverseMultiHopParams {
67
+ interface TraverseMultiHopParams {
66
68
  from_rowid: number;
67
69
  depth: number;
68
70
  type?: string;
69
71
  }
70
- export interface TraverseMultiHopResult {
72
+ interface TraverseMultiHopResult {
71
73
  to_rowid: number;
72
74
  depth: number;
73
75
  }
74
- export interface Action {
76
+ interface Action {
75
77
  rowid: number;
76
78
  type: 'mutation' | 'generation' | 'resolution' | 'function' | 'evaluate';
77
79
  input_hash: string;
@@ -84,22 +86,22 @@ export interface Action {
84
86
  cost_tokens?: number;
85
87
  created_at: number;
86
88
  }
87
- export interface CreateActionParams {
89
+ interface CreateActionParams {
88
90
  type: 'mutation' | 'generation' | 'resolution' | 'function' | 'evaluate';
89
91
  input: Record<string, unknown>;
90
92
  model?: string;
91
93
  }
92
- export interface CompleteActionParams {
94
+ interface CompleteActionParams {
93
95
  rowid: number;
94
96
  output: Record<string, unknown>;
95
97
  duration_ms?: number;
96
98
  cost_tokens?: number;
97
99
  }
98
- export interface FailActionParams {
100
+ interface FailActionParams {
99
101
  rowid: number;
100
102
  error: string;
101
103
  }
102
- export interface DBEvent {
104
+ interface DBEvent {
103
105
  rowid: number;
104
106
  type: string;
105
107
  action: 'created' | 'updated' | 'deleted' | 'generated';
@@ -112,7 +114,7 @@ export interface DBEvent {
112
114
  action_id?: number;
113
115
  correlation_id?: string;
114
116
  }
115
- export interface EmitEventParams {
117
+ interface EmitEventParams {
116
118
  type: string;
117
119
  action: 'created' | 'updated' | 'deleted' | 'generated';
118
120
  entity_type: string;
@@ -123,23 +125,50 @@ export interface EmitEventParams {
123
125
  action_id?: number;
124
126
  correlation_id?: string;
125
127
  }
126
- export interface ListEventsParams {
128
+ interface ListEventsParams {
127
129
  type?: string;
128
130
  action?: 'created' | 'updated' | 'deleted' | 'generated';
129
131
  since?: number;
130
132
  correlation_id?: string;
131
133
  limit?: number;
132
134
  }
133
- export declare class LocalDB {
135
+ /**
136
+ * Connection pool for reusing database instances.
137
+ * SQLite with better-sqlite3 uses file-level locking, so we maintain
138
+ * a singleton instance per database path to avoid resource contention.
139
+ */
140
+ declare class ConnectionPool {
141
+ private static instances;
142
+ /**
143
+ * Acquire a database connection. Creates a new one or returns existing.
144
+ */
145
+ static acquire(dbPath: string): Database.Database;
146
+ /**
147
+ * Release a database connection. Closes when ref count reaches 0.
148
+ */
149
+ static release(dbPath: string): void;
150
+ /**
151
+ * Force close all connections (for testing cleanup).
152
+ */
153
+ static closeAll(): void;
154
+ }
155
+ declare class LocalDB {
134
156
  private db;
157
+ private usePool;
135
158
  readonly path: string;
136
159
  readonly version: number;
137
160
  readonly things: ThingsAPI;
138
161
  readonly relationships: RelationshipsAPI;
139
162
  readonly actions: ActionsAPI;
140
163
  readonly events: EventsAPI;
141
- constructor(dbPath?: string);
164
+ constructor(dbPath?: string, options?: {
165
+ usePool?: boolean;
166
+ });
142
167
  private initSchema;
168
+ /**
169
+ * Run any pending database migrations.
170
+ */
171
+ private runMigrations;
143
172
  /**
144
173
  * Closes the database connection.
145
174
  */
@@ -232,5 +261,5 @@ declare class EventsAPI {
232
261
  */
233
262
  list(params?: ListEventsParams): Promise<DBEvent[]>;
234
263
  }
235
- export default LocalDB;
236
- //# sourceMappingURL=index.d.ts.map
264
+
265
+ export { type Action, type CompleteActionParams, ConnectionPool, type CreateActionParams, type CreateRelationshipParams, type DBEvent, type EmitEventParams, type FailActionParams, type GetParams, type IncomingParams, type ListEventsParams, type ListParams, LocalDB, type Relationship, type Thing, type TraverseMultiHopParams, type TraverseMultiHopResult, type TraverseParams, type UpsertParams, type UpsertResult, LocalDB as default };