Skip to content

Commit 35d50bc

Browse files
override nodejs imports
1 parent 1f4dcb3 commit 35d50bc

File tree

6 files changed

+39
-42
lines changed

6 files changed

+39
-42
lines changed

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,8 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
429429
}
430430
this._schema = schema;
431431

432-
console.log('updating schema', JSON.stringify(this.schema.toJSON()));
433432
await this.database.execute('SELECT powersync_replace_schema(?)', [JSON.stringify(this.schema.toJSON())]);
434-
console.log('schema updated', JSON.stringify(this.schema.toJSON()));
435433
await this.database.refreshSchema();
436-
console.log('schema refreshed', JSON.stringify(this.schema.toJSON()));
437434
this.iterateListeners(async (cb) => cb.schemaChanged?.(schema));
438435
}
439436

packages/dev-adapter/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
"test": "vitest"
2929
},
3030
"dependencies": {
31-
"async-mutex": "^0.4.0",
32-
"@powersync/common": "workspace:^"
31+
"@powersync/common": "workspace:^",
32+
"async-mutex": "^0.4.0"
3333
},
3434
"devDependencies": {
35+
"@rollup/plugin-alias": "^5.1.0",
3536
"@types/sql.js": "^1.4.9",
36-
"sql.js": "link:/Users/stevenontong/Documents/sql.js",
37-
"rollup": "4.14.3"
37+
"rollup": "4.14.3",
38+
"sql.js": "link:/Users/stevenontong/Documents/sql.js"
3839
}
3940
}

packages/dev-adapter/rollup.config.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import alias from '@rollup/plugin-alias';
12
import commonjs from '@rollup/plugin-commonjs';
23
import nodeResolve from '@rollup/plugin-node-resolve';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
39

410
/**
511
* @returns {import('rollup').RollupOptions}
@@ -17,7 +23,18 @@ export default (commandLineArgs) => {
1723
format: 'esm',
1824
sourcemap: sourceMap
1925
},
20-
plugins: [nodeResolve({ preferBuiltins: false, browser: true }), commonjs({})],
26+
plugins: [
27+
nodeResolve({ preferBuiltins: false, browser: true }),
28+
commonjs({}),
29+
alias({
30+
entries: [
31+
{ find: 'fs', replacement: path.resolve(__dirname, 'vendored/empty.js') },
32+
{ find: 'path', replacement: path.resolve(__dirname, 'vendored/empty.js') },
33+
{ find: 'crypto', replacement: path.resolve(__dirname, 'vendored/empty.js') }
34+
// add others as needed
35+
]
36+
})
37+
],
2138
external: ['@powersync/common']
2239
};
2340
};

packages/dev-adapter/src/SQLJSAdapter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '@powersync/common';
1313
import { Mutex } from 'async-mutex';
1414
// This uses a pure JS version which avoids the need for WebAssembly, which is not supported in React Native.
15-
import SQLJs from 'sql.js/dist/sql-asm.js';
15+
import SQLJs from 'sql.js/dist/sql-asm-debug.js';
1616

1717
export interface SQLJSPersister {
1818
readFile: () => Promise<ArrayLike<number> | Buffer | null>;
@@ -59,9 +59,11 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
5959
console.log('SQL.js loaded:');
6060
const existing = await this.options.persister.readFile();
6161
const db = new SQL.Database(existing);
62-
(db as any).updateHook((operation, database, table) => {
63-
this.tableUpdateCache.add(table);
64-
});
62+
// debugger;
63+
// (db as any).updateHook(function (operation, database, table, rowId) {
64+
// console.log(`Update Hook: ${operation} on ${table}`);
65+
// this.tableUpdateCache.add(table);
66+
// });
6567
this._db = db;
6668
return db;
6769
}
@@ -92,7 +94,7 @@ export class SQLJSDBAdapter extends BaseObserver<DBAdapterListener> implements D
9294
return Object.fromEntries(row.map((value, index) => [columnNames![index], value]));
9395
});
9496
return {
95-
insertId: 0, // does not seem to be available in SQL.js??
97+
insertId: (db as any).lastInsertId(), // does not seem to be available in SQL.js??
9698
rowsAffected: db.getRowsModified(),
9799
rows: {
98100
_array: rows,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {};

pnpm-lock.yaml

Lines changed: 8 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)