wn-turso 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 +21 -0
- package/dist/adapters/adapter.d.ts +53 -0
- package/dist/adapters/adapter.d.ts.map +1 -0
- package/dist/adapters/adapter.js +4 -0
- package/dist/adapters/embedded-adapter.d.ts +24 -0
- package/dist/adapters/embedded-adapter.d.ts.map +1 -0
- package/dist/adapters/embedded-adapter.js +78 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +5 -0
- package/dist/adapters/remote-adapter.d.ts +21 -0
- package/dist/adapters/remote-adapter.d.ts.map +1 -0
- package/dist/adapters/remote-adapter.js +49 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +61 -0
- package/dist/config.d.ts +77 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +37 -0
- package/dist/database/index.d.ts +10 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +8 -0
- package/dist/database/kysely-query-service.d.ts +32 -0
- package/dist/database/kysely-query-service.d.ts.map +1 -0
- package/dist/database/kysely-query-service.js +39 -0
- package/dist/database/turso-connection.d.ts +15 -0
- package/dist/database/turso-connection.d.ts.map +1 -0
- package/dist/database/turso-connection.js +29 -0
- package/dist/database/turso-database.d.ts +49 -0
- package/dist/database/turso-database.d.ts.map +1 -0
- package/dist/database/turso-database.js +124 -0
- package/dist/database/turso-dialect.d.ts +16 -0
- package/dist/database/turso-dialect.d.ts.map +1 -0
- package/dist/database/turso-dialect.js +25 -0
- package/dist/database/turso-driver.d.ts +25 -0
- package/dist/database/turso-driver.d.ts.map +1 -0
- package/dist/database/turso-driver.js +43 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/pipeline/index.d.ts +10 -0
- package/dist/pipeline/index.d.ts.map +1 -0
- package/dist/pipeline/index.js +13 -0
- package/dist/pipeline/operators.d.ts +65 -0
- package/dist/pipeline/operators.d.ts.map +1 -0
- package/dist/pipeline/operators.js +174 -0
- package/dist/pipeline/pipeline-builder.d.ts +107 -0
- package/dist/pipeline/pipeline-builder.d.ts.map +1 -0
- package/dist/pipeline/pipeline-builder.js +181 -0
- package/dist/pipeline/sink.d.ts +22 -0
- package/dist/pipeline/sink.d.ts.map +1 -0
- package/dist/pipeline/sink.js +63 -0
- package/dist/pipeline/source.d.ts +20 -0
- package/dist/pipeline/source.d.ts.map +1 -0
- package/dist/pipeline/source.js +66 -0
- package/dist/pipeline/streams.d.ts +18 -0
- package/dist/pipeline/streams.d.ts.map +1 -0
- package/dist/pipeline/streams.js +115 -0
- package/dist/pipeline/types.d.ts +86 -0
- package/dist/pipeline/types.d.ts.map +1 -0
- package/dist/pipeline/types.js +4 -0
- package/dist/wordnet/index.d.ts +5 -0
- package/dist/wordnet/index.d.ts.map +1 -0
- package/dist/wordnet/index.js +4 -0
- package/dist/wordnet/turso-wordnet.d.ts +85 -0
- package/dist/wordnet/turso-wordnet.d.ts.map +1 -0
- package/dist/wordnet/turso-wordnet.js +107 -0
- package/package.json +80 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso database wrapper
|
|
3
|
+
*/
|
|
4
|
+
import { Kysely } from 'kysely';
|
|
5
|
+
import { TursoQueryService } from './kysely-query-service.js';
|
|
6
|
+
import type { TursoDatabaseConfig } from '../config.js';
|
|
7
|
+
import type { TursoAdapter } from '../adapters/adapter.js';
|
|
8
|
+
import type { Database } from 'wn-ts-core/shared';
|
|
9
|
+
/**
|
|
10
|
+
* Main Turso database class
|
|
11
|
+
* Provides a unified interface for remote and embedded Turso connections
|
|
12
|
+
*/
|
|
13
|
+
export declare class TursoDatabase {
|
|
14
|
+
private adapter?;
|
|
15
|
+
private db?;
|
|
16
|
+
private queryService?;
|
|
17
|
+
private config;
|
|
18
|
+
private initialized;
|
|
19
|
+
constructor(config: TursoDatabaseConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the database connection
|
|
22
|
+
*/
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Get the Kysely database instance
|
|
26
|
+
*/
|
|
27
|
+
getDatabase(): Kysely<Database>;
|
|
28
|
+
/**
|
|
29
|
+
* Get the query service
|
|
30
|
+
*/
|
|
31
|
+
getQueryService(): TursoQueryService;
|
|
32
|
+
/**
|
|
33
|
+
* Get the underlying adapter
|
|
34
|
+
*/
|
|
35
|
+
getAdapter(): TursoAdapter;
|
|
36
|
+
/**
|
|
37
|
+
* Check if the database is initialized
|
|
38
|
+
*/
|
|
39
|
+
isInitialized(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Sync embedded replica with remote (only for embedded mode)
|
|
42
|
+
*/
|
|
43
|
+
sync(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Close the database connection
|
|
46
|
+
*/
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=turso-database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turso-database.d.ts","sourceRoot":"","sources":["../../src/database/turso-database.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAiB,MAAM,QAAQ,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAC,CAAe;IAC/B,OAAO,CAAC,EAAE,CAAC,CAAmB;IAC9B,OAAO,CAAC,YAAY,CAAC,CAAoB;IACzC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,mBAAmB;IAKvC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA8CjC;;OAEG;IACH,WAAW,IAAI,MAAM,CAAC,QAAQ,CAAC;IAO/B;;OAEG;IACH,eAAe,IAAI,iBAAiB;IAOpC;;OAEG;IACH,UAAU,IAAI,YAAY;IAO1B;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAU3B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAY7B"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso database wrapper
|
|
3
|
+
*/
|
|
4
|
+
import { Kysely, CompiledQuery } from 'kysely';
|
|
5
|
+
import { createTursoDialect } from './turso-dialect.js';
|
|
6
|
+
import { TursoQueryService } from './kysely-query-service.js';
|
|
7
|
+
import { RemoteTursoAdapter } from '../adapters/remote-adapter.js';
|
|
8
|
+
import { EmbeddedTursoAdapter } from '../adapters/embedded-adapter.js';
|
|
9
|
+
import { validateTursoConfig } from '../config.js';
|
|
10
|
+
import { SchemaBuilder } from 'wn-ts-core/shared';
|
|
11
|
+
/**
|
|
12
|
+
* Main Turso database class
|
|
13
|
+
* Provides a unified interface for remote and embedded Turso connections
|
|
14
|
+
*/
|
|
15
|
+
export class TursoDatabase {
|
|
16
|
+
adapter;
|
|
17
|
+
db;
|
|
18
|
+
queryService;
|
|
19
|
+
config;
|
|
20
|
+
initialized = false;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
validateTursoConfig(config);
|
|
23
|
+
this.config = config;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the database connection
|
|
27
|
+
*/
|
|
28
|
+
async initialize() {
|
|
29
|
+
if (this.initialized) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Select adapter based on mode
|
|
33
|
+
switch (this.config.mode) {
|
|
34
|
+
case 'remote':
|
|
35
|
+
this.adapter = new RemoteTursoAdapter();
|
|
36
|
+
break;
|
|
37
|
+
case 'embedded':
|
|
38
|
+
this.adapter = new EmbeddedTursoAdapter();
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unknown connection mode: ${this.config.mode}`);
|
|
42
|
+
}
|
|
43
|
+
await this.adapter.initialize(this.config);
|
|
44
|
+
// Create Kysely instance
|
|
45
|
+
const dialect = createTursoDialect({
|
|
46
|
+
client: this.adapter.getClient(),
|
|
47
|
+
onCreateConnection: async (connection) => {
|
|
48
|
+
if (this.config.enableForeignKeys) {
|
|
49
|
+
await connection.executeQuery(CompiledQuery.raw('PRAGMA foreign_keys = ON'));
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
this.db = new Kysely({ dialect });
|
|
54
|
+
// Create query service
|
|
55
|
+
this.queryService = new TursoQueryService(this.db);
|
|
56
|
+
// Initialize schema if not readonly
|
|
57
|
+
if (!this.config.readonly) {
|
|
58
|
+
await SchemaBuilder.createTables(this.db);
|
|
59
|
+
await SchemaBuilder.migrateSchema(this.db);
|
|
60
|
+
await SchemaBuilder.createIndexes(this.db);
|
|
61
|
+
}
|
|
62
|
+
this.initialized = true;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the Kysely database instance
|
|
66
|
+
*/
|
|
67
|
+
getDatabase() {
|
|
68
|
+
if (!this.db) {
|
|
69
|
+
throw new Error('Database not initialized');
|
|
70
|
+
}
|
|
71
|
+
return this.db;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the query service
|
|
75
|
+
*/
|
|
76
|
+
getQueryService() {
|
|
77
|
+
if (!this.queryService) {
|
|
78
|
+
throw new Error('Query service not initialized');
|
|
79
|
+
}
|
|
80
|
+
return this.queryService;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the underlying adapter
|
|
84
|
+
*/
|
|
85
|
+
getAdapter() {
|
|
86
|
+
if (!this.adapter) {
|
|
87
|
+
throw new Error('Adapter not initialized');
|
|
88
|
+
}
|
|
89
|
+
return this.adapter;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Check if the database is initialized
|
|
93
|
+
*/
|
|
94
|
+
isInitialized() {
|
|
95
|
+
return this.initialized;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Sync embedded replica with remote (only for embedded mode)
|
|
99
|
+
*/
|
|
100
|
+
async sync() {
|
|
101
|
+
if (!this.adapter) {
|
|
102
|
+
throw new Error('Database not initialized');
|
|
103
|
+
}
|
|
104
|
+
if (!this.adapter.sync) {
|
|
105
|
+
throw new Error('Sync not available for this adapter (remote mode)');
|
|
106
|
+
}
|
|
107
|
+
await this.adapter.sync();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Close the database connection
|
|
111
|
+
*/
|
|
112
|
+
async close() {
|
|
113
|
+
if (this.db) {
|
|
114
|
+
await this.db.destroy();
|
|
115
|
+
this.db = undefined;
|
|
116
|
+
}
|
|
117
|
+
if (this.adapter) {
|
|
118
|
+
await this.adapter.close();
|
|
119
|
+
this.adapter = undefined;
|
|
120
|
+
}
|
|
121
|
+
this.queryService = undefined;
|
|
122
|
+
this.initialized = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso/libsql Kysely dialect
|
|
3
|
+
*/
|
|
4
|
+
import { type Dialect } from 'kysely';
|
|
5
|
+
import type { Client } from '@libsql/client';
|
|
6
|
+
export interface TursoDialectConfig {
|
|
7
|
+
client: Client;
|
|
8
|
+
onCreateConnection?: (connection: any) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a Kysely dialect for Turso/libsql
|
|
12
|
+
*
|
|
13
|
+
* This follows the same pattern as sqlite-wasm-dialect.ts in wn-ts-web
|
|
14
|
+
*/
|
|
15
|
+
export declare function createTursoDialect(config: TursoDialectConfig): Dialect;
|
|
16
|
+
//# sourceMappingURL=turso-dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turso-dialect.d.ts","sourceRoot":"","sources":["../../src/database/turso-dialect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAKL,KAAK,OAAO,EAEb,MAAM,QAAQ,CAAC;AAEhB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAetE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso/libsql Kysely dialect
|
|
3
|
+
*/
|
|
4
|
+
import { SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler, } from 'kysely';
|
|
5
|
+
import { TursoDriver } from './turso-driver.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create a Kysely dialect for Turso/libsql
|
|
8
|
+
*
|
|
9
|
+
* This follows the same pattern as sqlite-wasm-dialect.ts in wn-ts-web
|
|
10
|
+
*/
|
|
11
|
+
export function createTursoDialect(config) {
|
|
12
|
+
return {
|
|
13
|
+
createAdapter: () => new SqliteAdapter(),
|
|
14
|
+
createDriver: () => new TursoDriver({
|
|
15
|
+
client: config.client,
|
|
16
|
+
async onCreateConnection(connection) {
|
|
17
|
+
if (config.onCreateConnection) {
|
|
18
|
+
await config.onCreateConnection(connection);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
createIntrospector: (db) => new SqliteIntrospector(db),
|
|
23
|
+
createQueryCompiler: () => new SqliteQueryCompiler(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso/libsql Kysely driver implementation
|
|
3
|
+
*/
|
|
4
|
+
import { type DatabaseConnection, type Driver } from 'kysely';
|
|
5
|
+
import type { Client } from '@libsql/client';
|
|
6
|
+
export interface TursoDriverConfig {
|
|
7
|
+
client: Client;
|
|
8
|
+
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Kysely Driver implementation for Turso/libsql
|
|
12
|
+
*/
|
|
13
|
+
export declare class TursoDriver implements Driver {
|
|
14
|
+
private config;
|
|
15
|
+
private connection?;
|
|
16
|
+
constructor(config: TursoDriverConfig);
|
|
17
|
+
init(): Promise<void>;
|
|
18
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
19
|
+
beginTransaction(connection: DatabaseConnection): Promise<void>;
|
|
20
|
+
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
21
|
+
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
22
|
+
releaseConnection(): Promise<void>;
|
|
23
|
+
destroy(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=turso-driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turso-driver.d.ts","sourceRoot":"","sources":["../../src/database/turso-driver.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAiB,KAAK,kBAAkB,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxE;AAED;;GAEG;AACH,qBAAa,WAAY,YAAW,MAAM;IACxC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,UAAU,CAAC,CAAkB;gBAEzB,MAAM,EAAE,iBAAiB;IAI/B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,iBAAiB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAOhD,gBAAgB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE,mBAAmB,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAI/B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso/libsql Kysely driver implementation
|
|
3
|
+
*/
|
|
4
|
+
import { CompiledQuery } from 'kysely';
|
|
5
|
+
import { TursoConnection } from './turso-connection.js';
|
|
6
|
+
/**
|
|
7
|
+
* Kysely Driver implementation for Turso/libsql
|
|
8
|
+
*/
|
|
9
|
+
export class TursoDriver {
|
|
10
|
+
config;
|
|
11
|
+
connection;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
async init() {
|
|
16
|
+
this.connection = new TursoConnection(this.config.client);
|
|
17
|
+
if (this.config.onCreateConnection) {
|
|
18
|
+
await this.config.onCreateConnection(this.connection);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async acquireConnection() {
|
|
22
|
+
if (!this.connection) {
|
|
23
|
+
throw new Error('Driver not initialized');
|
|
24
|
+
}
|
|
25
|
+
return this.connection;
|
|
26
|
+
}
|
|
27
|
+
async beginTransaction(connection) {
|
|
28
|
+
await connection.executeQuery(CompiledQuery.raw('BEGIN'));
|
|
29
|
+
}
|
|
30
|
+
async commitTransaction(connection) {
|
|
31
|
+
await connection.executeQuery(CompiledQuery.raw('COMMIT'));
|
|
32
|
+
}
|
|
33
|
+
async rollbackTransaction(connection) {
|
|
34
|
+
await connection.executeQuery(CompiledQuery.raw('ROLLBACK'));
|
|
35
|
+
}
|
|
36
|
+
async releaseConnection() {
|
|
37
|
+
// No-op for libsql client - connection pooling handled internally
|
|
38
|
+
}
|
|
39
|
+
async destroy() {
|
|
40
|
+
this.config.client.close();
|
|
41
|
+
this.connection = undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wn-turso - Turso/libsql database backend and data pipeline utilities for WordNet
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { TursoWordnet, type TursoWordnetOptions } from './wordnet/index.js';
|
|
7
|
+
export { TursoDatabase, TursoQueryService, createTursoDialect, TursoDriver, TursoConnection, type Database, } from './database/index.js';
|
|
8
|
+
export { RemoteTursoAdapter, EmbeddedTursoAdapter, type TursoAdapter, type TursoAdapterInfo, } from './adapters/index.js';
|
|
9
|
+
export { type TursoDatabaseConfig, type TursoConnectionMode, type SyncConfig, defaultSyncConfig, validateTursoConfig, } from './config.js';
|
|
10
|
+
export { Pipeline } from './pipeline/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAG5E,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,KAAK,QAAQ,GACd,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EACf,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wn-turso - Turso/libsql database backend and data pipeline utilities for WordNet
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
// Main WordNet class
|
|
7
|
+
export { TursoWordnet } from './wordnet/index.js';
|
|
8
|
+
// Database components
|
|
9
|
+
export { TursoDatabase, TursoQueryService, createTursoDialect, TursoDriver, TursoConnection, } from './database/index.js';
|
|
10
|
+
// Adapters
|
|
11
|
+
export { RemoteTursoAdapter, EmbeddedTursoAdapter, } from './adapters/index.js';
|
|
12
|
+
// Configuration
|
|
13
|
+
export { defaultSyncConfig, validateTursoConfig, } from './config.js';
|
|
14
|
+
// Pipeline (re-export from subpath for convenience)
|
|
15
|
+
export { Pipeline } from './pipeline/index.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline module exports
|
|
3
|
+
*/
|
|
4
|
+
export { Pipeline } from './pipeline-builder.js';
|
|
5
|
+
export { tursoSource, kyselySource, arraySource } from './source.js';
|
|
6
|
+
export { tursoSink, kyselySink, arraySink } from './sink.js';
|
|
7
|
+
export { filter, map, transform, transformAsync, extend, extendAsync, batch, unbatch, tap, tapAsync, take, skip, distinct, compose, } from './operators.js';
|
|
8
|
+
export { streamTable, writeBatches, countRows } from './streams.js';
|
|
9
|
+
export type { PipelineSource, PipelineSink, PipelineResult, PipelineProgress, ProgressCallback, SourceOptions, SinkOptions, Operator, } from './types.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pipeline/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGrE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG7D,OAAO,EACL,MAAM,EACN,GAAG,EACH,SAAS,EACT,cAAc,EACd,MAAM,EACN,WAAW,EACX,KAAK,EACL,OAAO,EACP,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,GACR,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,YAAY,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,QAAQ,GACT,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline module exports
|
|
3
|
+
*/
|
|
4
|
+
// High-level pipeline builder
|
|
5
|
+
export { Pipeline } from './pipeline-builder.js';
|
|
6
|
+
// Sources
|
|
7
|
+
export { tursoSource, kyselySource, arraySource } from './source.js';
|
|
8
|
+
// Sinks
|
|
9
|
+
export { tursoSink, kyselySink, arraySink } from './sink.js';
|
|
10
|
+
// Operators
|
|
11
|
+
export { filter, map, transform, transformAsync, extend, extendAsync, batch, unbatch, tap, tapAsync, take, skip, distinct, compose, } from './operators.js';
|
|
12
|
+
// Low-level streaming utilities
|
|
13
|
+
export { streamTable, writeBatches, countRows } from './streams.js';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline operators for transforming data streams
|
|
3
|
+
*/
|
|
4
|
+
import type { Operator } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Filter rows based on a predicate
|
|
7
|
+
*/
|
|
8
|
+
export declare function filter<T>(predicate: (row: T) => boolean): Operator<T, T>;
|
|
9
|
+
/**
|
|
10
|
+
* Map rows to a new shape
|
|
11
|
+
*/
|
|
12
|
+
export declare function map<In, Out>(fn: (row: In) => Out): Operator<In, Out>;
|
|
13
|
+
/**
|
|
14
|
+
* Transform rows, optionally filtering out nulls
|
|
15
|
+
* Return null to skip a row
|
|
16
|
+
*/
|
|
17
|
+
export declare function transform<In, Out>(fn: (row: In) => Out | null | undefined): Operator<In, Out>;
|
|
18
|
+
/**
|
|
19
|
+
* Async transform for operations that need to await
|
|
20
|
+
*/
|
|
21
|
+
export declare function transformAsync<In, Out>(fn: (row: In) => Promise<Out | null | undefined>): Operator<In, Out>;
|
|
22
|
+
/**
|
|
23
|
+
* Extend rows with additional properties
|
|
24
|
+
* Useful for adding columns to a "working DB" schema
|
|
25
|
+
*/
|
|
26
|
+
export declare function extend<T extends Record<string, any>, Ext extends Record<string, any>>(fn: (row: T) => Ext): Operator<T, T & Ext>;
|
|
27
|
+
/**
|
|
28
|
+
* Async extend for operations that need to await
|
|
29
|
+
*/
|
|
30
|
+
export declare function extendAsync<T extends Record<string, any>, Ext extends Record<string, any>>(fn: (row: T) => Promise<Ext>): Operator<T, T & Ext>;
|
|
31
|
+
/**
|
|
32
|
+
* Batch rows into arrays
|
|
33
|
+
*/
|
|
34
|
+
export declare function batch<T>(size: number): Operator<T, T[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Flatten batches back to individual rows
|
|
37
|
+
*/
|
|
38
|
+
export declare function unbatch<T>(): Operator<T[], T>;
|
|
39
|
+
/**
|
|
40
|
+
* Side effect for each row (logging, metrics)
|
|
41
|
+
*/
|
|
42
|
+
export declare function tap<T>(fn: (row: T) => void): Operator<T, T>;
|
|
43
|
+
/**
|
|
44
|
+
* Async side effect
|
|
45
|
+
*/
|
|
46
|
+
export declare function tapAsync<T>(fn: (row: T) => Promise<void>): Operator<T, T>;
|
|
47
|
+
/**
|
|
48
|
+
* Take first n rows
|
|
49
|
+
*/
|
|
50
|
+
export declare function take<T>(n: number): Operator<T, T>;
|
|
51
|
+
/**
|
|
52
|
+
* Skip first n rows
|
|
53
|
+
*/
|
|
54
|
+
export declare function skip<T>(n: number): Operator<T, T>;
|
|
55
|
+
/**
|
|
56
|
+
* Deduplicate rows by key
|
|
57
|
+
*/
|
|
58
|
+
export declare function distinct<T, K>(keyFn: (row: T) => K): Operator<T, T>;
|
|
59
|
+
/**
|
|
60
|
+
* Compose multiple operators into one
|
|
61
|
+
*/
|
|
62
|
+
export declare function compose<A, B, C>(op1: Operator<A, B>, op2: Operator<B, C>): Operator<A, C>;
|
|
63
|
+
export declare function compose<A, B, C, D>(op1: Operator<A, B>, op2: Operator<B, C>, op3: Operator<C, D>): Operator<A, D>;
|
|
64
|
+
export declare function compose<A, B, C, D, E>(op1: Operator<A, B>, op2: Operator<B, C>, op3: Operator<C, D>, op4: Operator<D, E>): Operator<A, E>;
|
|
65
|
+
//# sourceMappingURL=operators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../../src/pipeline/operators.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,SAAS,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAC7B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAQhB;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,EAAE,EAAE,GAAG,EACzB,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,KAAK,GAAG,GACnB,QA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AAC,EAAE,CAAC,EAAE,CAAC,EACnC,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EACnB,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EACnB,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EACnB,GAAG,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAClB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline operators for transforming data streams
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Filter rows based on a predicate
|
|
6
|
+
*/
|
|
7
|
+
export function filter(predicate) {
|
|
8
|
+
return async function* (input) {
|
|
9
|
+
for await (const row of input) {
|
|
10
|
+
if (predicate(row)) {
|
|
11
|
+
yield row;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Map rows to a new shape
|
|
18
|
+
*/
|
|
19
|
+
export function map(fn) {
|
|
20
|
+
return async function* (input) {
|
|
21
|
+
for await (const row of input) {
|
|
22
|
+
yield fn(row);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Transform rows, optionally filtering out nulls
|
|
28
|
+
* Return null to skip a row
|
|
29
|
+
*/
|
|
30
|
+
export function transform(fn) {
|
|
31
|
+
return async function* (input) {
|
|
32
|
+
for await (const row of input) {
|
|
33
|
+
const result = fn(row);
|
|
34
|
+
if (result !== null && result !== undefined) {
|
|
35
|
+
yield result;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Async transform for operations that need to await
|
|
42
|
+
*/
|
|
43
|
+
export function transformAsync(fn) {
|
|
44
|
+
return async function* (input) {
|
|
45
|
+
for await (const row of input) {
|
|
46
|
+
const result = await fn(row);
|
|
47
|
+
if (result !== null && result !== undefined) {
|
|
48
|
+
yield result;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extend rows with additional properties
|
|
55
|
+
* Useful for adding columns to a "working DB" schema
|
|
56
|
+
*/
|
|
57
|
+
export function extend(fn) {
|
|
58
|
+
return async function* (input) {
|
|
59
|
+
for await (const row of input) {
|
|
60
|
+
const extension = fn(row);
|
|
61
|
+
yield { ...row, ...extension };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Async extend for operations that need to await
|
|
67
|
+
*/
|
|
68
|
+
export function extendAsync(fn) {
|
|
69
|
+
return async function* (input) {
|
|
70
|
+
for await (const row of input) {
|
|
71
|
+
const extension = await fn(row);
|
|
72
|
+
yield { ...row, ...extension };
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Batch rows into arrays
|
|
78
|
+
*/
|
|
79
|
+
export function batch(size) {
|
|
80
|
+
return async function* (input) {
|
|
81
|
+
let buffer = [];
|
|
82
|
+
for await (const row of input) {
|
|
83
|
+
buffer.push(row);
|
|
84
|
+
if (buffer.length >= size) {
|
|
85
|
+
yield buffer;
|
|
86
|
+
buffer = [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Yield remaining items
|
|
90
|
+
if (buffer.length > 0) {
|
|
91
|
+
yield buffer;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Flatten batches back to individual rows
|
|
97
|
+
*/
|
|
98
|
+
export function unbatch() {
|
|
99
|
+
return async function* (input) {
|
|
100
|
+
for await (const rows of input) {
|
|
101
|
+
for (const row of rows) {
|
|
102
|
+
yield row;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Side effect for each row (logging, metrics)
|
|
109
|
+
*/
|
|
110
|
+
export function tap(fn) {
|
|
111
|
+
return async function* (input) {
|
|
112
|
+
for await (const row of input) {
|
|
113
|
+
fn(row);
|
|
114
|
+
yield row;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Async side effect
|
|
120
|
+
*/
|
|
121
|
+
export function tapAsync(fn) {
|
|
122
|
+
return async function* (input) {
|
|
123
|
+
for await (const row of input) {
|
|
124
|
+
await fn(row);
|
|
125
|
+
yield row;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Take first n rows
|
|
131
|
+
*/
|
|
132
|
+
export function take(n) {
|
|
133
|
+
return async function* (input) {
|
|
134
|
+
let count = 0;
|
|
135
|
+
for await (const row of input) {
|
|
136
|
+
if (count >= n)
|
|
137
|
+
break;
|
|
138
|
+
yield row;
|
|
139
|
+
count++;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Skip first n rows
|
|
145
|
+
*/
|
|
146
|
+
export function skip(n) {
|
|
147
|
+
return async function* (input) {
|
|
148
|
+
let count = 0;
|
|
149
|
+
for await (const row of input) {
|
|
150
|
+
if (count >= n) {
|
|
151
|
+
yield row;
|
|
152
|
+
}
|
|
153
|
+
count++;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Deduplicate rows by key
|
|
159
|
+
*/
|
|
160
|
+
export function distinct(keyFn) {
|
|
161
|
+
return async function* (input) {
|
|
162
|
+
const seen = new Set();
|
|
163
|
+
for await (const row of input) {
|
|
164
|
+
const key = keyFn(row);
|
|
165
|
+
if (!seen.has(key)) {
|
|
166
|
+
seen.add(key);
|
|
167
|
+
yield row;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export function compose(...operators) {
|
|
173
|
+
return (input) => operators.reduce((acc, op) => op(acc), input);
|
|
174
|
+
}
|