duron 0.1.0
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/LICENSE +7 -0
- package/README.md +140 -0
- package/dist/action-job.d.ts +24 -0
- package/dist/action-job.d.ts.map +1 -0
- package/dist/action-job.js +108 -0
- package/dist/action-manager.d.ts +21 -0
- package/dist/action-manager.d.ts.map +1 -0
- package/dist/action-manager.js +78 -0
- package/dist/action.d.ts +129 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/action.js +87 -0
- package/dist/adapters/adapter.d.ts +92 -0
- package/dist/adapters/adapter.d.ts.map +1 -0
- package/dist/adapters/adapter.js +424 -0
- package/dist/adapters/postgres/drizzle.config.d.ts +3 -0
- package/dist/adapters/postgres/drizzle.config.d.ts.map +1 -0
- package/dist/adapters/postgres/drizzle.config.js +10 -0
- package/dist/adapters/postgres/pglite.d.ts +13 -0
- package/dist/adapters/postgres/pglite.d.ts.map +1 -0
- package/dist/adapters/postgres/pglite.js +36 -0
- package/dist/adapters/postgres/postgres.d.ts +51 -0
- package/dist/adapters/postgres/postgres.d.ts.map +1 -0
- package/dist/adapters/postgres/postgres.js +867 -0
- package/dist/adapters/postgres/schema.d.ts +581 -0
- package/dist/adapters/postgres/schema.d.ts.map +1 -0
- package/dist/adapters/postgres/schema.default.d.ts +577 -0
- package/dist/adapters/postgres/schema.default.d.ts.map +1 -0
- package/dist/adapters/postgres/schema.default.js +3 -0
- package/dist/adapters/postgres/schema.js +87 -0
- package/dist/adapters/schemas.d.ts +516 -0
- package/dist/adapters/schemas.d.ts.map +1 -0
- package/dist/adapters/schemas.js +184 -0
- package/dist/client.d.ts +85 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +416 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +22 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +75 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/server.d.ts +1193 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +516 -0
- package/dist/step-manager.d.ts +46 -0
- package/dist/step-manager.d.ts.map +1 -0
- package/dist/step-manager.js +216 -0
- package/dist/utils/checksum.d.ts +2 -0
- package/dist/utils/checksum.d.ts.map +1 -0
- package/dist/utils/checksum.js +6 -0
- package/dist/utils/p-retry.d.ts +19 -0
- package/dist/utils/p-retry.d.ts.map +1 -0
- package/dist/utils/p-retry.js +130 -0
- package/dist/utils/wait-for-abort.d.ts +5 -0
- package/dist/utils/wait-for-abort.d.ts.map +1 -0
- package/dist/utils/wait-for-abort.js +32 -0
- package/migrations/postgres/0000_lethal_speed_demon.sql +64 -0
- package/migrations/postgres/meta/0000_snapshot.json +606 -0
- package/migrations/postgres/meta/_journal.json +13 -0
- package/package.json +88 -0
- package/src/action-job.ts +201 -0
- package/src/action-manager.ts +166 -0
- package/src/action.ts +247 -0
- package/src/adapters/adapter.ts +969 -0
- package/src/adapters/postgres/drizzle.config.ts +11 -0
- package/src/adapters/postgres/pglite.ts +86 -0
- package/src/adapters/postgres/postgres.ts +1346 -0
- package/src/adapters/postgres/schema.default.ts +5 -0
- package/src/adapters/postgres/schema.ts +119 -0
- package/src/adapters/schemas.ts +320 -0
- package/src/client.ts +859 -0
- package/src/constants.ts +37 -0
- package/src/errors.ts +205 -0
- package/src/index.ts +14 -0
- package/src/server.ts +718 -0
- package/src/step-manager.ts +471 -0
- package/src/utils/checksum.ts +7 -0
- package/src/utils/p-retry.ts +213 -0
- package/src/utils/wait-for-abort.ts +40 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { drizzle } from 'drizzle-orm/pglite'
|
|
2
|
+
|
|
3
|
+
import type { PostgresAdapterOptions } from './postgres.js'
|
|
4
|
+
import { type DB, PostgresAdapter } from './postgres.js'
|
|
5
|
+
|
|
6
|
+
type PGLiteDB = ReturnType<typeof drizzle>
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* PGLite adapter implementation for Duron.
|
|
10
|
+
* Extends PostgresAdapter to work with PGLite (in-memory PostgreSQL).
|
|
11
|
+
*
|
|
12
|
+
* @template Options - The adapter options type
|
|
13
|
+
*/
|
|
14
|
+
export class PGLiteAdapter extends PostgresAdapter {
|
|
15
|
+
override async _stop() {
|
|
16
|
+
await (this.db as unknown as PGLiteDB).$client.close()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Map database query results to the expected format.
|
|
21
|
+
* PGLite returns results in a `rows` property, so we extract that.
|
|
22
|
+
*
|
|
23
|
+
* @param result - The raw database query result
|
|
24
|
+
* @returns The mapped result (result.rows)
|
|
25
|
+
*/
|
|
26
|
+
protected override _map(result: any) {
|
|
27
|
+
return result.rows
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the PGLite database connection.
|
|
32
|
+
* Creates a new Drizzle instance without connection options.
|
|
33
|
+
*/
|
|
34
|
+
protected override _initDb() {
|
|
35
|
+
let connection = ':memory:'
|
|
36
|
+
// it means that the user is using a file path, so we need to use the file path
|
|
37
|
+
if (typeof this.options.connection === 'string' && !this.options.connection.startsWith('postgres://')) {
|
|
38
|
+
connection = this.options.connection
|
|
39
|
+
}
|
|
40
|
+
if (connection === ':memory:') {
|
|
41
|
+
this.db = drizzle() as unknown as DB
|
|
42
|
+
} else {
|
|
43
|
+
this.db = drizzle(connection) as unknown as DB
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Send a PGLite notification.
|
|
49
|
+
*
|
|
50
|
+
* @param event - The event name
|
|
51
|
+
* @param data - The data to send
|
|
52
|
+
* @returns Promise resolving to `void`
|
|
53
|
+
*/
|
|
54
|
+
protected override async _notify(event: string, data: any): Promise<void> {
|
|
55
|
+
await (this.db as unknown as PGLiteDB).$client.query(
|
|
56
|
+
`NOTIFY "${this.options.schema}.${event}", '${JSON.stringify(data)}'`,
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Listen for PGLite notifications.
|
|
62
|
+
*
|
|
63
|
+
* @param event - The event name to listen for
|
|
64
|
+
* @param callback - Callback function to handle notifications
|
|
65
|
+
* @returns Promise resolving to an object with an `unlisten` function
|
|
66
|
+
*/
|
|
67
|
+
protected override async _listen(
|
|
68
|
+
event: string,
|
|
69
|
+
callback: (payload: string) => void,
|
|
70
|
+
): Promise<{ unlisten: () => void }> {
|
|
71
|
+
const unlisten = await (this.db as unknown as PGLiteDB).$client.listen(
|
|
72
|
+
`"${this.options.schema}.${event}"`,
|
|
73
|
+
(payload: string) => {
|
|
74
|
+
callback(payload)
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
unlisten,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const pgliteAdapter = (options: PostgresAdapterOptions) => {
|
|
85
|
+
return new PGLiteAdapter(options)
|
|
86
|
+
}
|