orez 0.0.11 → 0.0.13
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.
- package/README.md +56 -16
- package/dist/cli.js +24 -1
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/pglite-manager.d.ts.map +1 -1
- package/dist/pglite-manager.js +9 -0
- package/dist/pglite-manager.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +25 -1
- package/src/config.ts +5 -1
- package/src/pglite-manager.ts +10 -0
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# orez
|
|
2
2
|
|
|
3
|
-
[Zero](https://zero.rocicorp.dev) development backend powered by [PGlite](https://pglite.dev). Bundles PostgreSQL and zero-cache into a single process — no Docker, no Postgres install.
|
|
3
|
+
[Zero](https://zero.rocicorp.dev) development backend powered by [PGlite](https://pglite.dev). Bundles PostgreSQL and zero-cache into a single process — no Docker, no Postgres install, no native compilation.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
|
|
6
|
+
bunx orez
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
Starts PGlite, the TCP proxy, and zero-cache. Ports auto-increment if already in use.
|
|
@@ -13,7 +13,7 @@ Exports a CLI, programmatic API, and Vite plugin.
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
15
|
```
|
|
16
|
-
|
|
16
|
+
bun install orez
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
`@rocicorp/zero` is included as a dependency and provides the zero-cache binary.
|
|
@@ -21,14 +21,14 @@ npm install orez
|
|
|
21
21
|
## CLI
|
|
22
22
|
|
|
23
23
|
```
|
|
24
|
-
|
|
24
|
+
bunx orez
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```
|
|
28
28
|
--pg-port postgresql proxy port (default: 6434)
|
|
29
29
|
--zero-port zero-cache port (default: 5849)
|
|
30
30
|
--data-dir data directory (default: .zero-lite)
|
|
31
|
-
--migrations migrations directory (
|
|
31
|
+
--migrations migrations directory (skipped if not set)
|
|
32
32
|
--seed seed file path
|
|
33
33
|
--pg-user postgresql user (default: user)
|
|
34
34
|
--pg-password postgresql password (default: password)
|
|
@@ -36,13 +36,15 @@ npx orez
|
|
|
36
36
|
--log-level error, warn, info, debug (default: info)
|
|
37
37
|
--s3 also start a local s3-compatible server
|
|
38
38
|
--s3-port s3 server port (default: 9200)
|
|
39
|
+
--bunny also start a local bunny cdn storage-compatible server
|
|
40
|
+
--bunny-port bunny storage server port (default: 3533)
|
|
39
41
|
```
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
Subcommands for standalone servers:
|
|
42
44
|
|
|
43
45
|
```
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
bunx orez s3 --port 9200 --data-dir .orez
|
|
47
|
+
bunx orez bunny --port 3533 --data-dir .orez
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
## Programmatic
|
|
@@ -78,12 +80,14 @@ export default {
|
|
|
78
80
|
zeroPort: 5849,
|
|
79
81
|
migrationsDir: 'src/database/migrations',
|
|
80
82
|
s3: true,
|
|
83
|
+
bunny: true,
|
|
84
|
+
bunnyPort: 3533,
|
|
81
85
|
}),
|
|
82
86
|
],
|
|
83
87
|
}
|
|
84
88
|
```
|
|
85
89
|
|
|
86
|
-
Starts orez when vite dev server starts, stops on close. Pass `s3: true` to also start
|
|
90
|
+
Starts orez when vite dev server starts, stops on close. Pass `s3: true` or `bunny: true` to also start local storage servers.
|
|
87
91
|
|
|
88
92
|
## How it works
|
|
89
93
|
|
|
@@ -97,6 +101,12 @@ The trick is in the TCP proxy. zero-cache needs logical replication to stay in s
|
|
|
97
101
|
|
|
98
102
|
The proxy also handles multi-database routing. zero-cache expects three separate databases (upstream, CVR, change), but PGlite is a single database. orez maps database names to schemas, so `zero_cvr` becomes the `zero_cvr` schema and `zero_cdb` becomes `zero_cdb`.
|
|
99
103
|
|
|
104
|
+
### WASM SQLite override
|
|
105
|
+
|
|
106
|
+
zero-cache uses `@rocicorp/zero-sqlite3` which requires native SQLite bindings (compiled C addon). orez ships with [bedrock-sqlite](https://www.npmjs.com/package/bedrock-sqlite), a pure WASM build of SQLite compiled from the [bedrock branch](https://sqlite.org/src/timeline?t=begin-concurrent) with BEGIN CONCURRENT and WAL2 support.
|
|
107
|
+
|
|
108
|
+
At startup, orez patches `@rocicorp/zero-sqlite3` to load bedrock-sqlite instead of native bindings. This means zero-cache runs entirely without native compilation — no `node-gyp`, no build tools, no platform-specific binaries. Just `bun install` and go.
|
|
109
|
+
|
|
100
110
|
## Environment variables
|
|
101
111
|
|
|
102
112
|
Your entire environment is forwarded to the zero-cache child process. This means any `ZERO_*` env vars you set are passed through automatically.
|
|
@@ -154,25 +164,45 @@ const server = await startS3Local({
|
|
|
154
164
|
})
|
|
155
165
|
```
|
|
156
166
|
|
|
157
|
-
Or via CLI: `
|
|
167
|
+
Or via CLI: `bunx orez --s3` or standalone `bunx orez s3`.
|
|
158
168
|
|
|
159
169
|
Handles GET, PUT, DELETE, HEAD with CORS. Files stored on disk. No multipart, no ACLs, no versioning.
|
|
160
170
|
|
|
171
|
+
## Extra: orez/bunny
|
|
172
|
+
|
|
173
|
+
Local Bunny CDN storage-compatible server for dev. Drop-in replacement for Bunny's storage API.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { startBunnyLocal } from 'orez/bunny'
|
|
177
|
+
|
|
178
|
+
const server = await startBunnyLocal({
|
|
179
|
+
port: 3533,
|
|
180
|
+
dataDir: '.orez',
|
|
181
|
+
})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Or via CLI: `bunx orez --bunny` or standalone `bunx orez bunny`.
|
|
185
|
+
|
|
186
|
+
Handles GET, PUT, DELETE, HEAD with CORS, plus directory listing. Files stored on disk.
|
|
187
|
+
|
|
161
188
|
## Tests
|
|
162
189
|
|
|
163
|
-
82 tests across 6 test files covering the full stack from binary encoding to TCP-level integration:
|
|
190
|
+
119 tests — 82 orez tests across 6 test files covering the full stack from binary encoding to TCP-level integration, plus 37 bedrock-sqlite tests covering the WASM SQLite engine:
|
|
164
191
|
|
|
165
192
|
```
|
|
166
|
-
bun test
|
|
193
|
+
bun test # orez tests
|
|
194
|
+
cd sqlite-wasm && bunx vitest run # bedrock-sqlite tests
|
|
167
195
|
```
|
|
168
196
|
|
|
169
|
-
The test suite includes a zero-cache compatibility layer that decodes pgoutput messages into the same typed format that zero-cache's PgoutputParser produces, validating end-to-end compatibility.
|
|
197
|
+
The orez test suite includes a zero-cache compatibility layer that decodes pgoutput messages into the same typed format that zero-cache's PgoutputParser produces, validating end-to-end compatibility.
|
|
198
|
+
|
|
199
|
+
The bedrock-sqlite tests cover Database/Statement API, transactions, WAL/WAL2 modes, BEGIN CONCURRENT, FTS5, JSON functions, custom functions, aggregates, bigint handling, and file persistence.
|
|
170
200
|
|
|
171
201
|
## Limitations
|
|
172
202
|
|
|
173
203
|
This is a development tool. It is not suitable for production use.
|
|
174
204
|
|
|
175
|
-
- PGlite
|
|
205
|
+
- PGlite is single-connection. All queries are serialized through a mutex. Fine for development but would bottleneck under real load.
|
|
176
206
|
- Column types are all encoded as text in the replication stream. Zero-cache handles this, but other pgoutput consumers might not.
|
|
177
207
|
- Triggers add overhead to every write. Again, fine for development.
|
|
178
208
|
- PGlite stores data on the local filesystem. No replication, no backups, no high availability.
|
|
@@ -181,19 +211,29 @@ This is a development tool. It is not suitable for production use.
|
|
|
181
211
|
|
|
182
212
|
```
|
|
183
213
|
src/
|
|
184
|
-
index.ts main entry, orchestrates startup
|
|
214
|
+
index.ts main entry, orchestrates startup + sqlite wasm patching
|
|
185
215
|
cli.ts cli with citty
|
|
186
216
|
config.ts configuration with defaults
|
|
187
217
|
log.ts colored log prefixes
|
|
188
218
|
port.ts auto port finding
|
|
189
219
|
pg-proxy.ts tcp proxy with query rewriting
|
|
190
220
|
pglite-manager.ts pglite instance and migration runner
|
|
191
|
-
s3-local.ts
|
|
221
|
+
s3-local.ts local s3-compatible server (orez/s3)
|
|
222
|
+
bunny-local.ts local bunny cdn storage server (orez/bunny)
|
|
192
223
|
vite-plugin.ts vite dev server plugin (orez/vite)
|
|
193
224
|
replication/
|
|
194
225
|
handler.ts replication protocol state machine
|
|
195
226
|
pgoutput-encoder.ts binary pgoutput message encoder
|
|
196
227
|
change-tracker.ts trigger installation and change reader
|
|
228
|
+
sqlite-wasm/
|
|
229
|
+
Makefile emscripten build for bedrock-sqlite wasm binary
|
|
230
|
+
bedrock-sqlite.d.ts typescript declarations
|
|
231
|
+
native/
|
|
232
|
+
api.js better-sqlite3 compatible database/statement API
|
|
233
|
+
vfs.c custom VFS with SHM support for WAL/WAL2
|
|
234
|
+
vfs.js javascript VFS bridge
|
|
235
|
+
test/
|
|
236
|
+
database.test.ts 37 tests for the wasm sqlite engine
|
|
197
237
|
```
|
|
198
238
|
|
|
199
239
|
## License
|
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
2
3
|
import { defineCommand, runMain } from 'citty';
|
|
3
4
|
import { startZeroLite } from './index.js';
|
|
4
5
|
import { log } from './log.js';
|
|
@@ -92,7 +93,7 @@ const main = defineCommand({
|
|
|
92
93
|
migrations: {
|
|
93
94
|
type: 'string',
|
|
94
95
|
description: 'migrations directory',
|
|
95
|
-
default: '
|
|
96
|
+
default: '',
|
|
96
97
|
},
|
|
97
98
|
seed: {
|
|
98
99
|
type: 'string',
|
|
@@ -139,6 +140,11 @@ const main = defineCommand({
|
|
|
139
140
|
description: 'bunny storage server port',
|
|
140
141
|
default: '3533',
|
|
141
142
|
},
|
|
143
|
+
'on-healthy': {
|
|
144
|
+
type: 'string',
|
|
145
|
+
description: 'command to run once all services are healthy',
|
|
146
|
+
default: '',
|
|
147
|
+
},
|
|
142
148
|
},
|
|
143
149
|
subCommands: {
|
|
144
150
|
s3: s3Command,
|
|
@@ -177,6 +183,23 @@ const main = defineCommand({
|
|
|
177
183
|
if (!config.skipZeroCache) {
|
|
178
184
|
log.zero(`http://localhost:${config.zeroPort}`);
|
|
179
185
|
}
|
|
186
|
+
if (args['on-healthy']) {
|
|
187
|
+
log.orez(`running on-healthy: ${args['on-healthy']}`);
|
|
188
|
+
const child = spawn(args['on-healthy'], {
|
|
189
|
+
shell: true,
|
|
190
|
+
stdio: 'inherit',
|
|
191
|
+
env: {
|
|
192
|
+
...process.env,
|
|
193
|
+
OREZ_PG_PORT: String(config.pgPort),
|
|
194
|
+
OREZ_ZERO_PORT: String(config.zeroPort),
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
child.on('exit', (code) => {
|
|
198
|
+
if (code !== 0 && code !== null) {
|
|
199
|
+
log.orez(`on-healthy command exited with code ${code}`);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
180
203
|
process.on('SIGINT', async () => {
|
|
181
204
|
bunnyServer?.close();
|
|
182
205
|
s3Server?.close();
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,MAAM,SAAS,GAAG,aAAa,CAAC;IAC9B,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI;QACV,WAAW,EAAE,oCAAoC;KAClD;IACD,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,mBAAmB;YAChC,OAAO,EAAE,MAAM;SAChB;QACD,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,iCAAiC;YA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
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PGliteOptions } from '@electric-sql/pglite';
|
|
1
2
|
export type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
2
3
|
export interface ZeroLiteConfig {
|
|
3
4
|
dataDir: string;
|
|
@@ -9,6 +10,7 @@ export interface ZeroLiteConfig {
|
|
|
9
10
|
seedFile: string;
|
|
10
11
|
skipZeroCache: boolean;
|
|
11
12
|
logLevel: LogLevel;
|
|
13
|
+
pgliteOptions: Partial<PGliteOptions>;
|
|
12
14
|
}
|
|
13
15
|
export declare function getConfig(overrides?: Partial<ZeroLiteConfig>): ZeroLiteConfig;
|
|
14
16
|
export declare function getConnectionString(config: ZeroLiteConfig, dbName?: string): string;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE1D,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,OAAO,CAAA;IACtB,QAAQ,EAAE,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE1D,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,OAAO,CAAA;IACtB,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CACtC;AAED,wBAAgB,SAAS,CAAC,SAAS,GAAE,OAAO,CAAC,cAAc,CAAM,GAAG,cAAc,CAajF;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,SAAa,GAAG,MAAM,CAEvF"}
|
package/dist/config.js
CHANGED
|
@@ -5,10 +5,11 @@ export function getConfig(overrides = {}) {
|
|
|
5
5
|
zeroPort: overrides.zeroPort || 5849,
|
|
6
6
|
pgUser: overrides.pgUser || 'user',
|
|
7
7
|
pgPassword: overrides.pgPassword || 'password',
|
|
8
|
-
migrationsDir: overrides.migrationsDir || '
|
|
8
|
+
migrationsDir: overrides.migrationsDir || '',
|
|
9
9
|
seedFile: overrides.seedFile || 'src/database/seed.sql',
|
|
10
10
|
skipZeroCache: overrides.skipZeroCache || false,
|
|
11
11
|
logLevel: overrides.logLevel || 'info',
|
|
12
|
+
pgliteOptions: overrides.pgliteOptions || {},
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
export function getConnectionString(config, dbName = 'postgres') {
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,SAAS,CAAC,YAAqC,EAAE;IAC/D,OAAO;QACL,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,YAAY;QAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,IAAI;QAChC,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,IAAI;QACpC,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,MAAM;QAClC,UAAU,EAAE,SAAS,CAAC,UAAU,IAAI,UAAU;QAC9C,aAAa,EAAE,SAAS,CAAC,aAAa,IAAI,EAAE;QAC5C,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,uBAAuB;QACvD,aAAa,EAAE,SAAS,CAAC,aAAa,IAAI,KAAK;QAC/C,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,MAAM;QACtC,aAAa,EAAE,SAAS,CAAC,aAAa,IAAI,EAAE;KAC7C,CAAA;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAsB,EAAE,MAAM,GAAG,UAAU;IAC7E,OAAO,gBAAgB,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,cAAc,MAAM,CAAC,MAAM,IAAI,MAAM,EAAE,CAAA;AAClG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pglite-manager.d.ts","sourceRoot":"","sources":["../src/pglite-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"pglite-manager.d.ts","sourceRoot":"","sources":["../src/pglite-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAM7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAgClF;AAED,wBAAsB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA+DrF"}
|
package/dist/pglite-manager.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { readFileSync, readdirSync, existsSync, mkdirSync } from 'node:fs';
|
|
2
2
|
import { join, resolve } from 'node:path';
|
|
3
3
|
import { PGlite } from '@electric-sql/pglite';
|
|
4
|
+
import { vector } from '@electric-sql/pglite/vector';
|
|
5
|
+
import { pg_trgm } from '@electric-sql/pglite/contrib/pg_trgm';
|
|
4
6
|
import { log } from './log.js';
|
|
5
7
|
export async function createPGliteInstance(config) {
|
|
6
8
|
const dataPath = resolve(config.dataDir, 'pgdata');
|
|
7
9
|
mkdirSync(dataPath, { recursive: true });
|
|
8
10
|
log.pglite(`creating instance at ${dataPath}`);
|
|
11
|
+
const { dataDir: _d, debug: _dbg, ...userOpts } = config.pgliteOptions;
|
|
9
12
|
const db = new PGlite({
|
|
10
13
|
dataDir: dataPath,
|
|
11
14
|
debug: config.logLevel === 'debug' ? 1 : 0,
|
|
15
|
+
...userOpts,
|
|
16
|
+
extensions: userOpts.extensions || { vector, pg_trgm },
|
|
12
17
|
});
|
|
13
18
|
await db.waitReady;
|
|
14
19
|
log.pglite('ready');
|
|
@@ -25,6 +30,10 @@ export async function createPGliteInstance(config) {
|
|
|
25
30
|
return db;
|
|
26
31
|
}
|
|
27
32
|
export async function runMigrations(db, config) {
|
|
33
|
+
if (!config.migrationsDir) {
|
|
34
|
+
log.orez('no migrations directory configured, skipping');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
28
37
|
const migrationsDir = resolve(config.migrationsDir);
|
|
29
38
|
if (!existsSync(migrationsDir)) {
|
|
30
39
|
log.orez('no migrations directory found, skipping');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pglite-manager.js","sourceRoot":"","sources":["../src/pglite-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,EAAE,MAAM,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AA;QACrB,CAAC;QAED,MAAM,EAAE,CAAC,KAAK,CAAC,kDAAkD,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QAC1E,GAAG,CAAC,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,GAAG,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;AACjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orez",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "PGlite-powered zero-sync development backend. No Docker required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@electric-sql/pglite": "^0.2.17",
|
|
49
49
|
"@rocicorp/zero": ">=0.1.0",
|
|
50
|
-
"bedrock-sqlite": "0.0.
|
|
50
|
+
"bedrock-sqlite": "0.0.5",
|
|
51
51
|
"citty": "^0.2.0",
|
|
52
52
|
"pg-gateway": "^0.3.0-beta.4"
|
|
53
53
|
},
|
package/src/cli.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process'
|
|
2
3
|
import { defineCommand, runMain } from 'citty'
|
|
3
4
|
|
|
4
5
|
import { startZeroLite } from './index.js'
|
|
@@ -98,7 +99,7 @@ const main = defineCommand({
|
|
|
98
99
|
migrations: {
|
|
99
100
|
type: 'string',
|
|
100
101
|
description: 'migrations directory',
|
|
101
|
-
default: '
|
|
102
|
+
default: '',
|
|
102
103
|
},
|
|
103
104
|
seed: {
|
|
104
105
|
type: 'string',
|
|
@@ -145,6 +146,11 @@ const main = defineCommand({
|
|
|
145
146
|
description: 'bunny storage server port',
|
|
146
147
|
default: '3533',
|
|
147
148
|
},
|
|
149
|
+
'on-healthy': {
|
|
150
|
+
type: 'string',
|
|
151
|
+
description: 'command to run once all services are healthy',
|
|
152
|
+
default: '',
|
|
153
|
+
},
|
|
148
154
|
},
|
|
149
155
|
subCommands: {
|
|
150
156
|
s3: s3Command,
|
|
@@ -189,6 +195,24 @@ const main = defineCommand({
|
|
|
189
195
|
log.zero(`http://localhost:${config.zeroPort}`)
|
|
190
196
|
}
|
|
191
197
|
|
|
198
|
+
if (args['on-healthy']) {
|
|
199
|
+
log.orez(`running on-healthy: ${args['on-healthy']}`)
|
|
200
|
+
const child = spawn(args['on-healthy'], {
|
|
201
|
+
shell: true,
|
|
202
|
+
stdio: 'inherit',
|
|
203
|
+
env: {
|
|
204
|
+
...process.env,
|
|
205
|
+
OREZ_PG_PORT: String(config.pgPort),
|
|
206
|
+
OREZ_ZERO_PORT: String(config.zeroPort),
|
|
207
|
+
},
|
|
208
|
+
})
|
|
209
|
+
child.on('exit', (code) => {
|
|
210
|
+
if (code !== 0 && code !== null) {
|
|
211
|
+
log.orez(`on-healthy command exited with code ${code}`)
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
192
216
|
process.on('SIGINT', async () => {
|
|
193
217
|
bunnyServer?.close()
|
|
194
218
|
s3Server?.close()
|
package/src/config.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { PGliteOptions } from '@electric-sql/pglite'
|
|
2
|
+
|
|
1
3
|
export type LogLevel = 'error' | 'warn' | 'info' | 'debug'
|
|
2
4
|
|
|
3
5
|
export interface ZeroLiteConfig {
|
|
@@ -10,6 +12,7 @@ export interface ZeroLiteConfig {
|
|
|
10
12
|
seedFile: string
|
|
11
13
|
skipZeroCache: boolean
|
|
12
14
|
logLevel: LogLevel
|
|
15
|
+
pgliteOptions: Partial<PGliteOptions>
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export function getConfig(overrides: Partial<ZeroLiteConfig> = {}): ZeroLiteConfig {
|
|
@@ -19,10 +22,11 @@ export function getConfig(overrides: Partial<ZeroLiteConfig> = {}): ZeroLiteConf
|
|
|
19
22
|
zeroPort: overrides.zeroPort || 5849,
|
|
20
23
|
pgUser: overrides.pgUser || 'user',
|
|
21
24
|
pgPassword: overrides.pgPassword || 'password',
|
|
22
|
-
migrationsDir: overrides.migrationsDir || '
|
|
25
|
+
migrationsDir: overrides.migrationsDir || '',
|
|
23
26
|
seedFile: overrides.seedFile || 'src/database/seed.sql',
|
|
24
27
|
skipZeroCache: overrides.skipZeroCache || false,
|
|
25
28
|
logLevel: overrides.logLevel || 'info',
|
|
29
|
+
pgliteOptions: overrides.pgliteOptions || {},
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
|
package/src/pglite-manager.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { readFileSync, readdirSync, existsSync, mkdirSync } from 'node:fs'
|
|
|
2
2
|
import { join, resolve } from 'node:path'
|
|
3
3
|
|
|
4
4
|
import { PGlite } from '@electric-sql/pglite'
|
|
5
|
+
import { vector } from '@electric-sql/pglite/vector'
|
|
6
|
+
import { pg_trgm } from '@electric-sql/pglite/contrib/pg_trgm'
|
|
5
7
|
|
|
6
8
|
import { log } from './log.js'
|
|
7
9
|
|
|
@@ -12,9 +14,12 @@ export async function createPGliteInstance(config: ZeroLiteConfig): Promise<PGli
|
|
|
12
14
|
mkdirSync(dataPath, { recursive: true })
|
|
13
15
|
|
|
14
16
|
log.pglite(`creating instance at ${dataPath}`)
|
|
17
|
+
const { dataDir: _d, debug: _dbg, ...userOpts } = config.pgliteOptions as Record<string, any>
|
|
15
18
|
const db = new PGlite({
|
|
16
19
|
dataDir: dataPath,
|
|
17
20
|
debug: config.logLevel === 'debug' ? 1 : 0,
|
|
21
|
+
...userOpts,
|
|
22
|
+
extensions: userOpts.extensions || { vector, pg_trgm },
|
|
18
23
|
})
|
|
19
24
|
|
|
20
25
|
await db.waitReady
|
|
@@ -39,6 +44,11 @@ export async function createPGliteInstance(config: ZeroLiteConfig): Promise<PGli
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
export async function runMigrations(db: PGlite, config: ZeroLiteConfig): Promise<void> {
|
|
47
|
+
if (!config.migrationsDir) {
|
|
48
|
+
log.orez('no migrations directory configured, skipping')
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
const migrationsDir = resolve(config.migrationsDir)
|
|
43
53
|
if (!existsSync(migrationsDir)) {
|
|
44
54
|
log.orez('no migrations directory found, skipping')
|