diff --git a/e2e/satellite_client/package.json b/e2e/satellite_client/package.json index 9fe753980d..9e70dc2171 100644 --- a/e2e/satellite_client/package.json +++ b/e2e/satellite_client/package.json @@ -17,6 +17,7 @@ "lint": "eslint src --fix" }, "dependencies": { + "@electric-sql/drivers": "workspace:*", "better-sqlite3": "^11.0.0", "electric-sql": "workspace:*", "jsonwebtoken": "^9.0.0", diff --git a/e2e/satellite_client/src/client.ts b/e2e/satellite_client/src/client.ts index e0aa54c8ee..4ac6974687 100644 --- a/e2e/satellite_client/src/client.ts +++ b/e2e/satellite_client/src/client.ts @@ -12,7 +12,7 @@ import { schema, Electric, } from './generated/client' -import { globalRegistry } from 'electric-sql/satellite' +import { globalRegistry, Satellite } from 'electric-sql/satellite' import { QualifiedTablename, SatelliteErrorCode } from 'electric-sql/util' import { Shape } from 'electric-sql/satellite' import { @@ -23,7 +23,8 @@ import { import { postgresConverter, sqliteConverter, -} from 'electric-sql/client/conversions' +} from 'electric-sql/client' +import type { RunResult } from '@electric-sql/drivers' setLogLevel('DEBUG') @@ -184,7 +185,7 @@ export const syncOtherItemsTable = ( } export const syncTable = async (table: string) => { - const satellite = globalRegistry.satellites[dbName] + const satellite: Satellite = globalRegistry.satellites[dbName as keyof typeof globalRegistry.satellites] const { synced } = await satellite.subscribe([{ tablename: table }]) return await synced } @@ -218,7 +219,7 @@ type Datetime = { id: string; d: Date; t: Date } export const write_timestamp = ( electric: Electric, timestamp: Timestamp -) => { +): Promise => { const row = converter.encodeRow(timestamp, schema.tables.timestamps) return electric.adapter.run({ sql: `INSERT INTO timestamps (id, created_at, updated_at) VALUES (${builder.makePositionalParam( @@ -479,21 +480,6 @@ export const write_float = async ( return converter.decodeRow(row, schema.tables.floats) } -const write_float_raw = async ( - electric: Electric, - id: string, - f4: number, - f8: number -) => { - const [ row ] = await electric.adapter.query({ - sql: `INSERT INTO floats (id, f4, f8) VALUES (${builder.makePositionalParam(1)}, ${builder.makePositionalParam(2)}, ${builder.makePositionalParam(3)}) RETURNING *;`, - args: [id, converter.encode(f4, PgBasicType.PG_FLOAT4), converter.encode(f8, PgBasicType.PG_FLOAT8)], - }) - return decodeRow(row, 'floats') -} - -export const write_float = withDal ? write_float_dal : write_float_raw - export const get_json_raw = async (electric: Electric, id: string) => { const res = (await electric.db.rawQuery({ sql: `SELECT js FROM jsons WHERE id = ${builder.makePositionalParam(1)};`, @@ -665,7 +651,7 @@ export const insert_extended_into = async ( }) } -const delete_item_dal = async (electric: Electric, keys: [string]) => { +export const delete_item = async (electric: Electric, keys: [string]) => { for (const key of keys) { await electric.adapter.run({ sql: `DELETE FROM items WHERE content = ${builder.makePositionalParam(1)};`, @@ -736,39 +722,6 @@ export const set_item_replication_transform = (electric: Electric) => { ) } -export const delete_other_item = withDal ? delete_other_item_dal : delete_other_item_raw - -const replicationTransformer = { - transformOutbound: (item: Readonly) => ({ - ...item, - content: item.content - .split('') - .map((char) => String.fromCharCode(char.charCodeAt(0) + 1)) - .join(''), - }), - transformInbound: (item: Readonly) => ({ - ...item, - content: item.content - .split('') - .map((char) => String.fromCharCode(char.charCodeAt(0) - 1)) - .join(''), - }), -} - -const set_item_replication_transform_dal = (electric: Electric) => { - electric.db.items.setReplicationTransform(replicationTransformer) -} - -const set_item_replication_transform_raw = (electric: Electric) => { - const namespace = builder.defaultNamespace - electric.setReplicationTransform( - new QualifiedTablename(namespace, 'items'), - replicationTransformer - ) -} - -export const set_item_replication_transform = withDal ? set_item_replication_transform_dal : set_item_replication_transform_raw - export const stop = async () => { await globalRegistry.stopAll() } diff --git a/e2e/satellite_client/src/generated/client/db-description.ts b/e2e/satellite_client/src/generated/client/db-description.ts deleted file mode 100644 index a4c5851979..0000000000 --- a/e2e/satellite_client/src/generated/client/db-description.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { type TableSchemas, DbSchema, Relation } from 'electric-sql/client/model'; -import migrations from './migrations'; -import pgMigrations from './pg-migrations'; - -export const tableSchemas = { - blobs: { - fields: { - "id": "TEXT", - "blob": "BYTEA" - }, - relations: [] - }, - bools: { - fields: { - "id": "TEXT", - "b": "BOOL" - }, - relations: [] - }, - datetimes: { - fields: { - "id": "TEXT", - "d": "DATE", - "t": "TIME" - }, - relations: [] - }, - enums: { - fields: { - "id": "TEXT", - "c": "TEXT" - }, - relations: [] - }, - floats: { - fields: { - "id": "TEXT", - "f4": "FLOAT4", - "f8": "FLOAT8" - }, - relations: [] - }, - ints: { - fields: { - "id": "TEXT", - "i2": "INT2", - "i4": "INT4", - "i8": "INT8" - }, - relations: [] - }, - items: { - fields: { - "id": "TEXT", - "content": "TEXT", - "content_text_null": "TEXT", - "content_text_null_default": "TEXT", - "intvalue_null": "INT4", - "intvalue_null_default": "INT4" - }, - relations: [ - new Relation("other_items", "", "", "other_items", "ItemsToOther_items", "many"), - ] - }, - jsons: { - fields: { - "id": "TEXT", - "jsb": "JSONB" - }, - relations: [] - }, - other_items: { - fields: { - "id": "TEXT", - "content": "TEXT", - "item_id": "TEXT" - }, - relations: [ - new Relation("items", "item_id", "id", "items", "ItemsToOther_items", "one"), - ] - }, - timestamps: { - fields: { - "id": "TEXT", - "created_at": "TIMESTAMP", - "updated_at": "TIMESTAMPTZ" - }, - relations: [] - }, - uuids: { - fields: { - "id": "UUID" - }, - relations: [] - }, -} as unknown as TableSchemas - -export const schema = new DbSchema(tableSchemas, migrations, pgMigrations) \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f130940abb..b2ee24e53d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -479,6 +479,9 @@ importers: e2e/satellite_client: dependencies: + '@electric-sql/drivers': + specifier: workspace:* + version: link:../../components/drivers better-sqlite3: specifier: ^11.0.0 version: 11.0.0