Skip to content

Commit 44c7e6b

Browse files
authored
Merge pull request #358 from objectstack-ai/copilot/update-packages-according-spec
2 parents c573d03 + 12c1ac1 commit 44c7e6b

5 files changed

Lines changed: 90 additions & 16 deletions

File tree

packages/drivers/pg-wasm/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class PgWasmDriver implements Driver {
5757
bulkDelete: true,
5858
transactions: true,
5959
savepoints: true,
60-
isolationLevels: ['read-uncommitted', 'read-committed', 'repeatable-read', 'serializable'],
60+
isolationLevels: ['read_uncommitted', 'read_committed', 'repeatable_read', 'serializable'],
6161
queryFilters: true,
6262
queryAggregations: true,
6363
querySorting: true,
@@ -76,9 +76,7 @@ export class PgWasmDriver implements Driver {
7676
indexes: true,
7777
connectionPooling: false,
7878
preparedStatements: true,
79-
queryCache: false,
80-
mutationLog: true,
81-
changeTracking: true
79+
queryCache: false
8280
};
8381

8482
private config: Required<PgWasmDriverConfig>;

packages/drivers/pg-wasm/test/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ describe('PgWasmDriver - Capabilities', () => {
9696
});
9797

9898
it('should support all isolation levels', () => {
99-
expect(driver.supports.isolationLevels).toContain('read-uncommitted');
100-
expect(driver.supports.isolationLevels).toContain('read-committed');
101-
expect(driver.supports.isolationLevels).toContain('repeatable-read');
99+
expect(driver.supports.isolationLevels).toContain('read_uncommitted');
100+
expect(driver.supports.isolationLevels).toContain('read_committed');
101+
expect(driver.supports.isolationLevels).toContain('repeatable_read');
102102
expect(driver.supports.isolationLevels).toContain('serializable');
103103
});
104104

packages/drivers/sqlite-wasm/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ export class SqliteWasmDriver implements Driver {
7373
indexes: true,
7474
connectionPooling: false,
7575
preparedStatements: true,
76-
queryCache: false,
77-
mutationLog: true,
78-
changeTracking: true
76+
queryCache: false
7977
};
8078

8179
private config: SqliteWasmDriverConfig;

packages/foundation/types/src/driver.ts

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ export interface IntrospectedSchema {
6868

6969
/**
7070
* Transaction isolation levels supported by the driver.
71+
*
72+
* Aligned with @objectstack/spec DriverCapabilitiesSchema — uses snake_case per protocol convention.
7173
*/
72-
export type IsolationLevel = 'read-uncommitted' | 'read-committed' | 'repeatable-read' | 'serializable';
74+
export type IsolationLevel = 'read_uncommitted' | 'read_committed' | 'repeatable_read' | 'serializable' | 'snapshot';
7375

7476
/**
7577
* Driver Capabilities
@@ -131,8 +133,18 @@ export interface DriverCapabilities {
131133
readonly connectionPooling?: boolean;
132134
readonly preparedStatements?: boolean;
133135
readonly queryCache?: boolean;
136+
}
134137

135-
// Sync support (Q3 — Offline-First Sync Protocol)
138+
/**
139+
* Runtime Driver Capabilities (extends spec with sync-specific properties)
140+
*
141+
* These properties are NOT part of the @objectstack/spec DriverCapabilitiesSchema
142+
* (which sets additionalProperties: false). They are runtime-only extensions
143+
* used by the Offline-First Sync Protocol (Q3).
144+
*
145+
* Use this interface for drivers that need sync capabilities.
146+
*/
147+
export interface RuntimeDriverCapabilities extends DriverCapabilities {
136148
/** Driver can record mutations to an append-only log for offline sync */
137149
readonly mutationLog?: boolean;
138150
/** Driver supports checkpoint-based change tracking */
@@ -190,8 +202,14 @@ export interface Driver {
190202

191203
// Transaction support
192204
beginTransaction?(): Promise<any>;
205+
/** @deprecated Use `commit` — aligned with @objectstack/spec DriverInterfaceSchema. Will be removed in v5.0. */
193206
commitTransaction?(transaction: any): Promise<void>;
207+
/** @deprecated Use `rollback` — aligned with @objectstack/spec DriverInterfaceSchema. Will be removed in v5.0. */
194208
rollbackTransaction?(transaction: any): Promise<void>;
209+
/** Commit a transaction (spec-aligned name) */
210+
commit?(transaction: any): Promise<void>;
211+
/** Rollback a transaction (spec-aligned name) */
212+
rollback?(transaction: any): Promise<void>;
195213

196214
// Schema / Lifecycle
197215
init?(objects: any[]): Promise<void>;
@@ -229,5 +247,67 @@ export interface Driver {
229247
*/
230248
directQuery?(sql: string, params?: any[]): Promise<any[]>;
231249
query?(sql: string, params?: any[]): Promise<any[]>;
250+
251+
// ========================================================================
252+
// Methods from @objectstack/spec DriverInterfaceSchema
253+
// ========================================================================
254+
255+
/**
256+
* Upsert (create or update) a record.
257+
* If the record exists (matched by ID or unique key), update it; otherwise, create it.
258+
*
259+
* @param objectName - The object name.
260+
* @param data - Key-value map of field data (must include ID or unique key).
261+
* @param options - Driver options.
262+
* @returns The upserted record.
263+
*/
264+
upsert?(objectName: string, data: Record<string, unknown>, options?: any): Promise<any>;
265+
266+
/**
267+
* Stream records matching the structured query.
268+
* Optimized for large datasets to avoid memory overflow.
269+
*
270+
* @param objectName - The name of the object.
271+
* @param query - The structured QueryAST.
272+
* @param options - Driver options.
273+
* @returns AsyncIterable/ReadableStream of records.
274+
*/
275+
findStream?(objectName: string, query: any, options?: any): AsyncIterable<any> | any;
276+
277+
/**
278+
* Get connection pool statistics.
279+
* Useful for monitoring database load.
280+
*
281+
* @returns Pool stats object, or undefined if pooling is not supported by the driver.
282+
*/
283+
getPoolStats?(): { total: number; idle: number; active: number; waiting: number } | undefined;
284+
285+
/**
286+
* Synchronize the schema for one or more objects.
287+
* Creates or alters tables/collections to match the object definitions.
288+
*
289+
* @param objects - Object definitions to synchronize.
290+
* @param options - Driver options.
291+
*/
292+
syncSchema?(objects: any[], options?: any): Promise<void>;
293+
294+
/**
295+
* Drop a table/collection by name.
296+
*
297+
* @param objectName - The name of the object/table to drop.
298+
* @param options - Driver options.
299+
*/
300+
dropTable?(objectName: string, options?: any): Promise<void>;
301+
302+
/**
303+
* Explain the execution plan for a query.
304+
* Useful for debugging and performance optimization.
305+
*
306+
* @param objectName - The name of the object.
307+
* @param query - The structured QueryAST.
308+
* @param options - Driver options.
309+
* @returns Execution plan details.
310+
*/
311+
explain?(objectName: string, query: any, options?: any): Promise<any>;
232312
}
233313

packages/foundation/types/src/field.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ export interface ImageAttachmentData extends AttachmentData {
8787
* Runtime Field Type
8888
*
8989
* Extends the Protocol FieldType with runtime-specific types.
90-
* The Protocol Constitution defines the core field types.
91-
* We add runtime-specific types like 'vector', 'grid', 'location', 'object' here.
90+
* The Protocol Constitution defines the core field types (including 'location' and 'vector').
91+
* We add runtime-specific types like 'grid' and 'object' here.
9292
*/
9393
export type FieldType =
9494
| ProtocolFieldType
95-
| 'location' // Runtime: Geographic location
9695
| 'object' // Runtime: Nested object/JSON
97-
| 'vector' // Runtime: Vector embeddings for AI
9896
| 'grid'; // Runtime: Inline grid/table
9997

10098
/**

0 commit comments

Comments
 (0)