@workflow/world-postgres 4.1.0-beta.9 → 4.1.1
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 +48 -8
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -13
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +17 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/drizzle/cbor.d.ts +38 -0
- package/dist/drizzle/cbor.d.ts.map +1 -0
- package/dist/drizzle/cbor.js +10 -0
- package/dist/drizzle/cbor.js.map +1 -0
- package/dist/drizzle/index.d.ts +4 -2
- package/dist/drizzle/index.d.ts.map +1 -1
- package/dist/drizzle/index.js +3 -3
- package/dist/drizzle/index.js.map +1 -1
- package/dist/drizzle/schema.d.ts +756 -59
- package/dist/drizzle/schema.d.ts.map +1 -1
- package/dist/drizzle/schema.js +68 -37
- package/dist/drizzle/schema.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -9
- package/dist/index.js.map +1 -1
- package/dist/message.d.ts +16 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/{boss.js → message.js} +7 -6
- package/dist/message.js.map +1 -0
- package/dist/queue.d.ts +8 -6
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +335 -59
- package/dist/queue.js.map +1 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +1046 -232
- package/dist/storage.js.map +1 -1
- package/dist/streamer.d.ts +13 -2
- package/dist/streamer.d.ts.map +1 -1
- package/dist/streamer.js +184 -12
- package/dist/streamer.js.map +1 -1
- package/dist/util.js.map +1 -1
- package/dist/zod.d.ts +1 -1
- package/dist/zod.d.ts.map +1 -1
- package/dist/zod.js +1 -1
- package/dist/zod.js.map +1 -1
- package/package.json +22 -19
- package/src/drizzle/migrations/{0000_redundant_smasher.sql → 0000_cultured_the_anarchist.sql} +17 -13
- package/src/drizzle/migrations/0001_tricky_sersi.sql +11 -0
- package/src/drizzle/migrations/0002_add_expired_at.sql +2 -0
- package/src/drizzle/migrations/0003_add_stream_run_id.sql +3 -0
- package/src/drizzle/migrations/0004_remove_run_pause_status.sql +14 -0
- package/src/drizzle/migrations/0005_add_spec_version.sql +5 -0
- package/src/drizzle/migrations/0006_add_error_cbor.sql +5 -0
- package/src/drizzle/migrations/0007_add_waits_table.sql +13 -0
- package/src/drizzle/migrations/0008_migrate_pgboss_to_graphile.sql +20 -0
- package/src/drizzle/migrations/0009_add_is_webhook.sql +1 -0
- package/src/drizzle/migrations/meta/0000_snapshot.json +499 -0
- package/src/drizzle/migrations/meta/0001_snapshot.json +548 -0
- package/src/drizzle/migrations/meta/0002_snapshot.json +554 -0
- package/src/drizzle/migrations/meta/0003_snapshot.json +576 -0
- package/src/drizzle/migrations/meta/0005_snapshot.json +575 -0
- package/src/drizzle/migrations/meta/_journal.json +76 -0
- package/dist/boss.d.ts +0 -15
- package/dist/boss.d.ts.map +0 -1
- package/dist/boss.js.map +0 -1
package/README.md
CHANGED
|
@@ -35,12 +35,16 @@ export WORKFLOW_POSTGRES_JOB_PREFIX="myapp"
|
|
|
35
35
|
|
|
36
36
|
# Optional: Worker concurrency (default: 10)
|
|
37
37
|
export WORKFLOW_POSTGRES_WORKER_CONCURRENCY="10"
|
|
38
|
+
|
|
39
|
+
# Optional: Internal pg.Pool max size (default: 10)
|
|
40
|
+
export WORKFLOW_POSTGRES_MAX_POOL_SIZE="10"
|
|
38
41
|
```
|
|
39
42
|
|
|
40
43
|
### Programmatic Usage
|
|
41
44
|
|
|
42
45
|
You can also create a PostgreSQL world directly in your code:
|
|
43
46
|
|
|
47
|
+
<!-- @skip-typecheck: incomplete code sample -->
|
|
44
48
|
```typescript
|
|
45
49
|
import { createWorld } from "@workflow/world-postgres";
|
|
46
50
|
|
|
@@ -48,16 +52,24 @@ const world = createWorld({
|
|
|
48
52
|
connectionString: "postgres://username:password@localhost:5432/database",
|
|
49
53
|
jobPrefix: "myapp", // optional
|
|
50
54
|
queueConcurrency: 10, // optional
|
|
55
|
+
maxPoolSize: 10, // optional, overrides WORKFLOW_POSTGRES_MAX_POOL_SIZE when `pool` is omitted
|
|
51
56
|
});
|
|
57
|
+
|
|
58
|
+
// Or pass an existing pg.Pool (shared with your app Drizzle, etc.); `world.close()` will not end it.
|
|
59
|
+
import { Pool } from "pg";
|
|
60
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
61
|
+
const worldFromPool = createWorld({ pool });
|
|
52
62
|
```
|
|
53
63
|
|
|
54
64
|
## Configuration Options
|
|
55
65
|
|
|
56
|
-
| Option | Type
|
|
57
|
-
| ------------------ |
|
|
58
|
-
| `connectionString` | `string`
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
66
|
+
| Option | Type | Default | Description |
|
|
67
|
+
| ------------------ | --------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `connectionString` | `string` | `process.env.WORKFLOW_POSTGRES_URL` or `'postgres://world:world@localhost:5432/world'` | Used only when `pool` is omitted, to construct an internal pool |
|
|
69
|
+
| `maxPoolSize` | `number` | `process.env.WORKFLOW_POSTGRES_MAX_POOL_SIZE` or `pg.Pool` default (`10`) | Optional. Sets the internal `pg.Pool` max size when `createWorld()` creates the pool |
|
|
70
|
+
| `pool` | `pg.Pool` | — | Optional. When set, used for Drizzle, Graphile Worker, and stream writes. `world.close()` does not end it. |
|
|
71
|
+
| `jobPrefix` | `string` | `process.env.WORKFLOW_POSTGRES_JOB_PREFIX` | Optional prefix for queue job names |
|
|
72
|
+
| `queueConcurrency` | `number` | `10` | Number of concurrent active step executions per process |
|
|
61
73
|
|
|
62
74
|
## Environment Variables
|
|
63
75
|
|
|
@@ -67,14 +79,19 @@ const world = createWorld({
|
|
|
67
79
|
| `WORKFLOW_POSTGRES_URL` | PostgreSQL connection string | `'postgres://world:world@localhost:5432/world'` |
|
|
68
80
|
| `WORKFLOW_POSTGRES_JOB_PREFIX` | Prefix for queue job names | - |
|
|
69
81
|
| `WORKFLOW_POSTGRES_WORKER_CONCURRENCY` | Number of concurrent workers | `10` |
|
|
82
|
+
| `WORKFLOW_POSTGRES_MAX_POOL_SIZE` | Internal `pg.Pool` max size | `10` |
|
|
83
|
+
|
|
84
|
+
When `pool` is omitted, `maxPoolSize` precedence is: `createWorld({ maxPoolSize })`, then `WORKFLOW_POSTGRES_MAX_POOL_SIZE`, then the `pg.Pool` default.
|
|
85
|
+
|
|
86
|
+
For higher worker concurrency, Graphile Worker recommends setting `maxPoolSize` to `10` or `queueConcurrency + 2`, whichever is larger.
|
|
70
87
|
|
|
71
88
|
## Database Setup
|
|
72
89
|
|
|
73
90
|
This package uses PostgreSQL with the following components:
|
|
74
91
|
|
|
75
|
-
- **
|
|
92
|
+
- **graphile-worker**: For queue processing and job management
|
|
76
93
|
- **Drizzle ORM**: For database operations and schema management
|
|
77
|
-
- **postgres
|
|
94
|
+
- **pg** (node-postgres): For PostgreSQL client connections. Drizzle and Graphile Worker share a `pg.Pool`, while LISTEN uses a dedicated `pg.Client` created from the same connection options.
|
|
78
95
|
|
|
79
96
|
### Quick Setup with CLI
|
|
80
97
|
|
|
@@ -114,11 +131,20 @@ Make sure your PostgreSQL database is accessible and the user has sufficient per
|
|
|
114
131
|
## Features
|
|
115
132
|
|
|
116
133
|
- **Durable Storage**: Stores workflow runs, events, steps, hooks, and webhooks in PostgreSQL
|
|
117
|
-
- **Queue Processing**: Uses
|
|
134
|
+
- **Queue Processing**: Uses graphile-worker as the durable queue and executes jobs over the workflow HTTP routes
|
|
135
|
+
- **Durable Delays**: Re-schedules waits and retries in PostgreSQL
|
|
118
136
|
- **Streaming**: Real-time event streaming capabilities
|
|
119
137
|
- **Health Checks**: Built-in connection health monitoring
|
|
120
138
|
- **Configurable Concurrency**: Adjustable worker concurrency for queue processing
|
|
121
139
|
|
|
140
|
+
## Queue Behavior
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
- Graphile jobs are acknowledged only after the workflow or step execution finishes, or after the worker durably schedules a delayed follow-up job
|
|
144
|
+
- Backlog stays in PostgreSQL when all execution slots are busy
|
|
145
|
+
- Retry and sleep-style delays use Graphile `runAt` scheduling
|
|
146
|
+
- Workflow and step execution is sent through `/.well-known/workflow/v1/flow` and `/.well-known/workflow/v1/step`
|
|
147
|
+
|
|
122
148
|
## Development
|
|
123
149
|
|
|
124
150
|
For local development, you can use the included Docker Compose configuration:
|
|
@@ -136,6 +162,20 @@ export WORKFLOW_POSTGRES_URL="postgres://world:world@localhost:5432/world"
|
|
|
136
162
|
export WORKFLOW_TARGET_WORLD="@workflow/world-postgres"
|
|
137
163
|
```
|
|
138
164
|
|
|
165
|
+
## Testing
|
|
166
|
+
|
|
167
|
+
Integration tests use [Testcontainers](https://testcontainers.com/) to start a PostgreSQL container. **Docker must be installed and running** before you run tests.
|
|
168
|
+
|
|
169
|
+
- **Linux/macOS**: Start the Docker daemon (e.g. `sudo systemctl start docker` or Docker Desktop).
|
|
170
|
+
- **WSL2**: Use Docker Desktop with WSL2 integration, or run the Docker engine inside WSL and ensure the daemon is started. Verify with `docker info`.
|
|
171
|
+
|
|
172
|
+
Then from the package directory:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
pnpm build
|
|
176
|
+
pnpm test
|
|
177
|
+
```
|
|
178
|
+
|
|
139
179
|
## World Selection
|
|
140
180
|
|
|
141
181
|
To use the PostgreSQL world, set the `WORKFLOW_TARGET_WORLD` environment variable to the package name:
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AASA,iBAAe,aAAa,kBA8C3B;AAOD,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
1
|
import { dirname, join } from 'node:path';
|
|
3
2
|
import { fileURLToPath } from 'node:url';
|
|
4
3
|
import { config } from 'dotenv';
|
|
5
|
-
import
|
|
4
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
5
|
+
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
6
|
+
import { Pool } from 'pg';
|
|
6
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
8
|
async function setupDatabase() {
|
|
8
9
|
// Load .env file if it exists
|
|
@@ -12,26 +13,26 @@ async function setupDatabase() {
|
|
|
12
13
|
'postgres://world:world@localhost:5432/world';
|
|
13
14
|
console.log('🔧 Setting up database schema...');
|
|
14
15
|
console.log(`📍 Connection: ${connectionString.replace(/^(\w+:\/\/)([^@]+)@/, '$1[redacted]@')}`);
|
|
16
|
+
const pool = new Pool({ connectionString, max: 1 });
|
|
17
|
+
const db = drizzle(pool);
|
|
15
18
|
try {
|
|
16
|
-
const sql = postgres(connectionString);
|
|
17
19
|
// Read the migration SQL file
|
|
18
20
|
// The migrations are in src/drizzle/migrations, and this CLI is in dist/
|
|
19
21
|
// So we need to go up one level from dist/ to reach src/
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
+
const migrationsFolder = join(__dirname, '..', 'src', 'drizzle', 'migrations');
|
|
23
|
+
console.log(`📂 Running migrations from: ${migrationsFolder}`);
|
|
22
24
|
// Execute the migration
|
|
23
|
-
await
|
|
25
|
+
await migrate(db, {
|
|
26
|
+
migrationsFolder,
|
|
27
|
+
migrationsTable: 'workflow_migrations',
|
|
28
|
+
migrationsSchema: 'workflow_drizzle',
|
|
29
|
+
});
|
|
24
30
|
console.log('✅ Database schema created successfully!');
|
|
25
|
-
|
|
26
|
-
console.log(' - workflow_runs');
|
|
27
|
-
console.log(' - workflow_events');
|
|
28
|
-
console.log(' - workflow_steps');
|
|
29
|
-
console.log(' - workflow_hooks');
|
|
30
|
-
console.log(' - workflow_stream_chunks');
|
|
31
|
-
await sql.end();
|
|
31
|
+
await pool.end();
|
|
32
32
|
process.exit(0);
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
+
await pool.end().catch(() => { });
|
|
35
36
|
console.error('❌ Failed to setup database:', error);
|
|
36
37
|
process.exit(1);
|
|
37
38
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,KAAK,UAAU,aAAa;IAC1B,8BAA8B;IAC9B,MAAM,EAAE,CAAC;IAET,MAAM,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,qBAAqB;QACjC,OAAO,CAAC,GAAG,CAAC,YAAY;QACxB,6CAA6C,CAAC;IAEhD,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CACT,kBAAkB,gBAAgB,CAAC,OAAO,CAAC,qBAAqB,EAAE,eAAe,CAAC,EAAE,CACrF,CAAC;IAEF,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IACpD,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,IAAI,CAAC;QACH,8BAA8B;QAC9B,yEAAyE;QACzE,yDAAyD;QACzD,MAAM,gBAAgB,GAAG,IAAI,CAC3B,SAAS,EACT,IAAI,EACJ,KAAK,EACL,SAAS,EACT,YAAY,CACb,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,+BAA+B,gBAAgB,EAAE,CAAC,CAAC;QAE/D,wBAAwB;QACxB,MAAM,OAAO,CAAC,EAAE,EAAE;YAChB,gBAAgB;YAChB,eAAe,EAAE,qBAAqB;YACtC,gBAAgB,EAAE,kBAAkB;SACrC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;QAEvD,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACjC,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,kCAAkC;AAClC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACpD,aAAa,EAAE,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["import { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { config } from 'dotenv';\nimport { drizzle } from 'drizzle-orm/node-postgres';\nimport { migrate } from 'drizzle-orm/node-postgres/migrator';\nimport { Pool } from 'pg';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nasync function setupDatabase() {\n // Load .env file if it exists\n config();\n\n const connectionString =\n process.env.WORKFLOW_POSTGRES_URL ||\n process.env.DATABASE_URL ||\n 'postgres://world:world@localhost:5432/world';\n\n console.log('🔧 Setting up database schema...');\n console.log(\n `📍 Connection: ${connectionString.replace(/^(\\w+:\\/\\/)([^@]+)@/, '$1[redacted]@')}`\n );\n\n const pool = new Pool({ connectionString, max: 1 });\n const db = drizzle(pool);\n\n try {\n // Read the migration SQL file\n // The migrations are in src/drizzle/migrations, and this CLI is in dist/\n // So we need to go up one level from dist/ to reach src/\n const migrationsFolder = join(\n __dirname,\n '..',\n 'src',\n 'drizzle',\n 'migrations'\n );\n console.log(`📂 Running migrations from: ${migrationsFolder}`);\n\n // Execute the migration\n await migrate(db, {\n migrationsFolder,\n migrationsTable: 'workflow_migrations',\n migrationsSchema: 'workflow_drizzle',\n });\n\n console.log('✅ Database schema created successfully!');\n\n await pool.end();\n process.exit(0);\n } catch (error) {\n await pool.end().catch(() => {});\n console.error('❌ Failed to setup database:', error);\n process.exit(1);\n }\n}\n\n// Check if running as main module\nif (import.meta.url === `file://${process.argv[1]}`) {\n setupDatabase();\n}\n\nexport { setupDatabase };\n"]}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Pool } from 'pg';
|
|
2
|
+
type PgConnectionConfig = {
|
|
2
3
|
connectionString: string;
|
|
4
|
+
maxPoolSize?: number;
|
|
5
|
+
pool?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
pool: Pool;
|
|
8
|
+
connectionString?: undefined;
|
|
9
|
+
maxPoolSize?: undefined;
|
|
10
|
+
};
|
|
11
|
+
export type PostgresWorldConfig = PgConnectionConfig & {
|
|
3
12
|
jobPrefix?: string;
|
|
4
13
|
queueConcurrency?: number;
|
|
5
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Override the flush interval (in ms) for buffered stream writes.
|
|
16
|
+
* Default is 10ms. Set to 0 for immediate flushing.
|
|
17
|
+
*/
|
|
18
|
+
streamFlushIntervalMs?: number;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
6
21
|
//# sourceMappingURL=config.d.ts.map
|
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,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,KAAK,kBAAkB,GACnB;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE1E,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,GAAG;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC"}
|
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":"","sourcesContent":["import type { Pool } from 'pg';\n\ntype PgConnectionConfig =\n | { connectionString: string; maxPoolSize?: number; pool?: undefined }\n | { pool: Pool; connectionString?: undefined; maxPoolSize?: undefined };\n\nexport type PostgresWorldConfig = PgConnectionConfig & {\n jobPrefix?: string;\n queueConcurrency?: number;\n /**\n * Override the flush interval (in ms) for buffered stream writes.\n * Default is 10ms. Set to 0 for immediate flushing.\n */\n streamFlushIntervalMs?: number;\n};\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare function Cbor<T>(): {
|
|
2
|
+
(): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
3
|
+
name: "";
|
|
4
|
+
dataType: "custom";
|
|
5
|
+
columnType: "PgCustomColumn";
|
|
6
|
+
data: T;
|
|
7
|
+
driverParam: Buffer<ArrayBufferLike>;
|
|
8
|
+
enumValues: undefined;
|
|
9
|
+
}>;
|
|
10
|
+
<TConfig extends Record<string, any>>(fieldConfig?: TConfig | undefined): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
11
|
+
name: "";
|
|
12
|
+
dataType: "custom";
|
|
13
|
+
columnType: "PgCustomColumn";
|
|
14
|
+
data: T;
|
|
15
|
+
driverParam: Buffer<ArrayBufferLike>;
|
|
16
|
+
enumValues: undefined;
|
|
17
|
+
}>;
|
|
18
|
+
<TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
19
|
+
name: TName;
|
|
20
|
+
dataType: "custom";
|
|
21
|
+
columnType: "PgCustomColumn";
|
|
22
|
+
data: T;
|
|
23
|
+
driverParam: Buffer<ArrayBufferLike>;
|
|
24
|
+
enumValues: undefined;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Adds a `{key}Json` property to the given type V, representing a key that was
|
|
29
|
+
* migrated to CBOR and can contain a previous JSONB representation.
|
|
30
|
+
*
|
|
31
|
+
* We migrated from JSONB to CBOR, but to avoid breaking changes in the codebase,
|
|
32
|
+
* we keep both representations in the database, and therefore we need to extend
|
|
33
|
+
* the types accordingly.
|
|
34
|
+
*/
|
|
35
|
+
export type Cborized<V extends object, K extends keyof V> = V & {
|
|
36
|
+
[key in `${Extract<K, string>}Json`]: unknown;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=cbor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cbor.d.ts","sourceRoot":"","sources":["../../src/drizzle/cbor.ts"],"names":[],"mappings":"AAGA,wBAAgB,IAAI,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;EAMrB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG;KAC7D,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,OAAO;CAC9C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { decode, encode } from 'cbor-x';
|
|
2
|
+
import { customType } from 'drizzle-orm/pg-core';
|
|
3
|
+
export function Cbor() {
|
|
4
|
+
return customType({
|
|
5
|
+
dataType: () => 'bytea',
|
|
6
|
+
fromDriver: (value) => decode(value),
|
|
7
|
+
toDriver: (value) => encode(value),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=cbor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cbor.js","sourceRoot":"","sources":["../../src/drizzle/cbor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,UAAU,IAAI;IAClB,OAAO,UAAU,CAAkC;QACjD,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO;QACvB,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;QACpC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;KACnC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decode, encode } from 'cbor-x';\nimport { customType } from 'drizzle-orm/pg-core';\n\nexport function Cbor<T>() {\n return customType<{ data: T; driverData: Buffer }>({\n dataType: () => 'bytea',\n fromDriver: (value) => decode(value),\n toDriver: (value) => encode(value),\n });\n}\n\n/**\n * Adds a `{key}Json` property to the given type V, representing a key that was\n * migrated to CBOR and can contain a previous JSONB representation.\n *\n * We migrated from JSONB to CBOR, but to avoid breaking changes in the codebase,\n * we keep both representations in the database, and therefore we need to extend\n * the types accordingly.\n */\nexport type Cborized<V extends object, K extends keyof V> = V & {\n [key in `${Extract<K, string>}Json`]: unknown;\n};\n"]}
|
package/dist/drizzle/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { Pool } from 'pg';
|
|
2
2
|
import * as Schema from './schema.js';
|
|
3
3
|
export { Schema };
|
|
4
4
|
export type Drizzle = ReturnType<typeof createClient>;
|
|
5
|
-
export declare function createClient(
|
|
5
|
+
export declare function createClient(pool: Pool): import("drizzle-orm/node-postgres").NodePgDatabase<typeof Schema> & {
|
|
6
|
+
$client: Pool;
|
|
7
|
+
};
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAEtD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI;;EAEtC"}
|
package/dist/drizzle/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { drizzle } from 'drizzle-orm/postgres
|
|
1
|
+
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
2
2
|
import * as Schema from './schema.js';
|
|
3
3
|
export { Schema };
|
|
4
|
-
export function createClient(
|
|
5
|
-
return drizzle(
|
|
4
|
+
export function createClient(pool) {
|
|
5
|
+
return drizzle(pool, { schema: Schema });
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/drizzle/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,CAAC;AAIlB,MAAM,UAAU,YAAY,CAAC,IAAU;IACrC,OAAO,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { drizzle } from 'drizzle-orm/node-postgres';\nimport type { Pool } from 'pg';\nimport * as Schema from './schema.js';\n\nexport { Schema };\n\nexport type Drizzle = ReturnType<typeof createClient>;\n\nexport function createClient(pool: Pool) {\n return drizzle(pool, { schema: Schema });\n}\n"]}
|