Skip to content

Commit d514ef8

Browse files
author
Amine
committed
Merge branch 'main' into attachment-package-refactor
# Conflicts: # pnpm-lock.yaml
2 parents 62b0bdc + 2f8b30c commit d514ef8

40 files changed

+7978
-10389
lines changed

.changeset/four-pans-laugh.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@powersync/common': minor
3+
'@powersync/web': minor
4+
'@powersync/node': minor
5+
'@powersync/react-native': minor
6+
---
7+
8+
Populate Table `name` values in `schema.props` for Schemas created with typed `Table`s. e.g. `schema.props['some_table'].name` will contain the table name.

demos/angular-supabase-todolist/extra-webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = (config, options, targetOptions) => {
1818
...config.plugins,
1919
new webpack.DefinePlugin({
2020
// Embed environment variables starting with `WEBPACK_PUBLIC_`
21-
'process.env': JSON.stringify(
21+
env: JSON.stringify(
2222
Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith('WEBPACK_PUBLIC_')))
2323
)
2424
})

demos/angular-supabase-todolist/src/env.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const environment = {
2-
supabaseUrl: process.env.WEBPACK_PUBLIC_SUPABASE_URL,
3-
supabaseKey: process.env.WEBPACK_PUBLIC_SUPABASE_ANON_KEY,
4-
powersyncUrl: process.env.WEBPACK_PUBLIC_POWERSYNC_URL
2+
supabaseUrl: env.WEBPACK_PUBLIC_SUPABASE_URL,
3+
supabaseKey: env.WEBPACK_PUBLIC_SUPABASE_ANON_KEY,
4+
powersyncUrl: env.WEBPACK_PUBLIC_POWERSYNC_URL
55
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Ambient declarations for webpack-injected environment variables.
2+
// webpack's DefinePlugin injects `env` at build time.
3+
4+
declare global {
5+
const env: {
6+
WEBPACK_PUBLIC_SUPABASE_URL: string;
7+
WEBPACK_PUBLIC_SUPABASE_ANON_KEY: string;
8+
WEBPACK_PUBLIC_POWERSYNC_URL: string;
9+
};
10+
}
11+
12+
export {};

demos/example-electron-node/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ In particular:
99
queries. This worker is part of the `@powersync/node` package and wouldn't be copied into the resulting Electron
1010
app by default. For this reason, this example has its own `src/main/worker.ts` loaded with `new URL('./worker.ts', import.meta.url)`.
1111
2. In addition to the worker, PowerSync requires access to a SQLite extension providing sync functionality.
12-
This file is also part of the `@powersync/node` package and called `powersync.dll`, `libpowersync.dylib` or
13-
`libpowersync.so` depending on the operating system.
12+
This file is also part of the `@powersync/node` package and is the prebuilt release asset (for example
13+
`powersync_x64.dll`, `libpowersync_x64.dylib` or `libpowersync_x64.so`) depending on the operating system and
14+
architecture.
1415
We use the `copy-webpack-plugin` package to make sure a copy of that file is available to the main process,
1516
and load it in the custom `src/main/worker.ts`.
1617
3. The `get()` and `getAll()` methods are exposed to the renderer process with an IPC channel.
@@ -21,7 +22,7 @@ To see it in action:
2122
2. Copy `.env.local.template` to `.env.local`, and complete the environment variables. You can generate a [temporary development token](https://docs.powersync.com/usage/installation/authentication-setup/development-tokens), or leave blank to test with local-only data.
2223
The example works with the schema from the [PowerSync + Supabase tutorial](https://docs.powersync.com/integration-guides/supabase-+-powersync#supabase-powersync).
2324
3. `cd` into this directory. In this mono-repo, you'll have to run `./node_modules/.bin/electron-rebuild` once to make sure `@powersync/better-sqlite3` was compiled with Electron's toolchain.
24-
3. Finally, run `pnpm start`.
25+
4. Finally, run `pnpm start`.
2526

2627
Apart from the build setup, this example is purposefully kept simple.
2728
To make sure PowerSync is working, you can run `await powersync.get('SELECT powersync_rs_version()');` in the DevTools

demos/example-electron-node/config.ts

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import OS from 'node:os';
21
import path from 'node:path';
3-
import { createRequire } from 'node:module';
42

5-
import type { ForgeConfig } from '@electron-forge/shared-types';
6-
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
7-
import { MakerZIP } from '@electron-forge/maker-zip';
83
import { MakerDeb } from '@electron-forge/maker-deb';
94
import { MakerRpm } from '@electron-forge/maker-rpm';
5+
import { MakerSquirrel } from '@electron-forge/maker-squirrel';
6+
import { MakerZIP } from '@electron-forge/maker-zip';
107
import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives';
118
import { WebpackPlugin } from '@electron-forge/plugin-webpack';
12-
import { type Configuration, type ModuleOptions, type DefinePlugin } from 'webpack';
9+
import type { ForgeConfig } from '@electron-forge/shared-types';
10+
import { getPowerSyncExtensionFilename } from '@powersync/node/worker.js';
11+
import type ICopyPlugin from 'copy-webpack-plugin';
1312
import * as dotenv from 'dotenv';
1413
import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
15-
import type ICopyPlugin from 'copy-webpack-plugin';
16-
17-
dotenv.config({path: '.env.local'});
14+
import { type Configuration, type DefinePlugin, type ModuleOptions } from 'webpack';
15+
dotenv.config({ path: '.env.local' });
1816

1917
const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
2018
const CopyPlugin: typeof ICopyPlugin = require('copy-webpack-plugin');
@@ -58,17 +56,7 @@ const defaultWebpackRules: () => Required<ModuleOptions>['rules'] = () => {
5856
];
5957
};
6058

61-
const platform = OS.platform();
62-
let extensionPath: string;
63-
if (platform === 'win32') {
64-
extensionPath = 'powersync.dll';
65-
} else if (platform === 'linux') {
66-
extensionPath = 'libpowersync.so';
67-
} else if (platform === 'darwin') {
68-
extensionPath = 'libpowersync.dylib';
69-
} else {
70-
throw 'Unknown platform, PowerSync for Node.js currently supports Windows, Linux and macOS.';
71-
}
59+
let extensionFilename = getPowerSyncExtensionFilename();
7260

7361
const mainConfig: Configuration = {
7462
/**
@@ -78,25 +66,27 @@ const mainConfig: Configuration = {
7866
entry: './src/main/index.ts',
7967
// Put your normal webpack config below here
8068
module: {
81-
rules: defaultWebpackRules(),
69+
rules: defaultWebpackRules()
8270
},
8371
plugins: [
8472
...webpackPlugins,
8573
new CopyPlugin({
86-
patterns: [{
87-
from: path.resolve(require.resolve('@powersync/node/package.json'), `../lib/${extensionPath}`),
88-
to: path.join('powersync', extensionPath),
89-
}],
74+
patterns: [
75+
{
76+
from: path.resolve(require.resolve('@powersync/node/package.json'), `../lib/${extensionFilename}`),
77+
to: path.join('powersync', extensionFilename)
78+
}
79+
]
9080
}),
9181
new DefinePluginImpl({
9282
POWERSYNC_URL: JSON.stringify(process.env.POWERSYNC_URL),
93-
POWERSYNC_TOKEN: JSON.stringify(process.env.POWERSYNC_TOKEN),
94-
}),
83+
POWERSYNC_TOKEN: JSON.stringify(process.env.POWERSYNC_TOKEN)
84+
})
9585
],
9686
resolve: {
9787
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json']
9888
},
99-
target: "electron-main",
89+
target: 'electron-main'
10090
};
10191

10292
const rendererConfig: Configuration = {
@@ -107,7 +97,7 @@ const rendererConfig: Configuration = {
10797
test: /\.css$/,
10898
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }]
10999
}
110-
],
100+
]
111101
},
112102
plugins: webpackPlugins,
113103
resolve: {
@@ -119,10 +109,10 @@ const config: ForgeConfig = {
119109
packagerConfig: {
120110
asar: {
121111
unpack: '**/{.**,**}/**/powersync/*'
122-
},
112+
}
123113
},
124114
rebuildConfig: {
125-
force: true,
115+
force: true
126116
},
127117
makers: [
128118
new MakerSquirrel(),
@@ -142,7 +132,7 @@ const config: ForgeConfig = {
142132
html: './src/render/index.html',
143133
js: './src/render/main.ts',
144134
preload: {
145-
js: './src/render/preload.ts',
135+
js: './src/render/preload.ts'
146136
}
147137
}
148138
]

demos/example-electron-node/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
"@electron-forge/maker-zip": "^7.7.0",
2424
"@electron-forge/plugin-auto-unpack-natives": "^7.7.0",
2525
"@electron-forge/plugin-webpack": "^7.7.0",
26+
"@types/better-sqlite3": "^7.6.13",
2627
"@vercel/webpack-asset-relocator-loader": "1.7.3",
2728
"copy-webpack-plugin": "^13.0.0",
2829
"css-loader": "^6.11.0",
2930
"dotenv": "^16.4.7",
30-
"electron": "30.0.2",
31+
"electron": "37.0.0",
3132
"electron-rebuild": "^3.2.9",
3233
"fork-ts-checker-webpack-plugin": "^9.0.2",
3334
"node-loader": "^2.1.0",
@@ -40,6 +41,7 @@
4041
},
4142
"dependencies": {
4243
"@powersync/node": "workspace:*",
44+
"better-sqlite3": "^12.2.0",
4345
"electron-squirrel-startup": "^1.0.1"
4446
}
4547
}
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1+
import Database from 'better-sqlite3';
12
import * as path from 'node:path';
2-
import OS from 'node:os';
33

4-
import { startPowerSyncWorker } from '@powersync/node/worker.js';
4+
import { getPowerSyncExtensionFilename, startPowerSyncWorker } from '@powersync/node/worker.js';
55

66
function resolvePowerSyncCoreExtension() {
7-
const platform = OS.platform();
8-
let extensionPath: string;
9-
if (platform === 'win32') {
10-
extensionPath = 'powersync.dll';
11-
} else if (platform === 'linux') {
12-
extensionPath = 'libpowersync.so';
13-
} else if (platform === 'darwin') {
14-
extensionPath = 'libpowersync.dylib';
15-
} else {
16-
throw 'Unknown platform, PowerSync for Node.js currently supports Windows, Linux and macOS.';
17-
}
7+
const extensionFilename = getPowerSyncExtensionFilename();
188

199
// This example uses copy-webpack-plugin to copy the prebuilt library over. This ensures that it is
2010
// available in packaged release builds.
21-
let libraryPath = path.resolve(__dirname, 'powersync', extensionPath);
11+
let libraryPath = path.resolve(__dirname, 'powersync', extensionFilename);
2212

2313
if (__dirname.indexOf('app.asar') != -1) {
2414
// Our build configuration ensures the extension is always available outside of the archive too.
@@ -28,4 +18,8 @@ function resolvePowerSyncCoreExtension() {
2818
return libraryPath;
2919
}
3020

31-
startPowerSyncWorker({ extensionPath: resolvePowerSyncCoreExtension });
21+
async function resolveBetterSqlite3() {
22+
return Database;
23+
}
24+
25+
startPowerSyncWorker({ extensionPath: resolvePowerSyncCoreExtension, loadBetterSqlite3: resolveBetterSqlite3 });

demos/example-node/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
BACKEND=http://localhost:6060
22
SYNC_SERVICE=http://localhost:8080
33
POWERSYNC_TOKEN=
4-
POWERSYNC_DEBUG=1
4+
POWERSYNC_DEBUG=1
5+
ENCRYPTION_KEY=

0 commit comments

Comments
 (0)