@effect/sql-sqlite-wasm 0.50.0 → 4.0.0-beta.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/dist/{dts/OpfsWorker.d.ts → OpfsWorker.d.ts} +1 -4
- package/dist/OpfsWorker.d.ts.map +1 -0
- package/dist/{esm/OpfsWorker.js → OpfsWorker.js} +3 -2
- package/dist/OpfsWorker.js.map +1 -0
- package/dist/{dts/SqliteClient.d.ts → SqliteClient.d.ts} +12 -17
- package/dist/SqliteClient.d.ts.map +1 -0
- package/dist/{esm/SqliteClient.js → SqliteClient.js} +38 -27
- package/dist/SqliteClient.js.map +1 -0
- package/dist/{dts/SqliteMigrator.d.ts → SqliteMigrator.d.ts} +4 -4
- package/dist/SqliteMigrator.d.ts.map +1 -0
- package/dist/{esm/SqliteMigrator.js → SqliteMigrator.js} +2 -5
- package/dist/SqliteMigrator.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/opfsWorker.d.ts.map +1 -0
- package/dist/internal/opfsWorker.js.map +1 -0
- package/package.json +48 -63
- package/src/OpfsWorker.ts +4 -3
- package/src/SqliteClient.ts +58 -66
- package/src/SqliteMigrator.ts +4 -4
- package/src/index.ts +3 -3
- package/src/sqlite-wasm.d.ts +2 -0
- package/OpfsWorker/package.json +0 -6
- package/SqliteClient/package.json +0 -6
- package/SqliteMigrator/package.json +0 -6
- package/dist/cjs/OpfsWorker.js +0 -102
- package/dist/cjs/OpfsWorker.js.map +0 -1
- package/dist/cjs/SqliteClient.js +0 -338
- package/dist/cjs/SqliteClient.js.map +0 -1
- package/dist/cjs/SqliteMigrator.js +0 -44
- package/dist/cjs/SqliteMigrator.js.map +0 -1
- package/dist/cjs/index.js +0 -14
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internal/opfsWorker.js +0 -6
- package/dist/cjs/internal/opfsWorker.js.map +0 -1
- package/dist/dts/OpfsWorker.d.ts.map +0 -1
- package/dist/dts/SqliteClient.d.ts.map +0 -1
- package/dist/dts/SqliteMigrator.d.ts.map +0 -1
- package/dist/dts/index.d.ts +0 -13
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/dts/internal/opfsWorker.d.ts.map +0 -1
- package/dist/esm/OpfsWorker.js.map +0 -1
- package/dist/esm/SqliteClient.js.map +0 -1
- package/dist/esm/SqliteMigrator.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internal/opfsWorker.js.map +0 -1
- package/dist/esm/package.json +0 -4
- package/index/package.json +0 -6
- package/sqlite-wasm.d/package.json +0 -6
- /package/dist/{esm/index.js → index.js} +0 -0
- /package/dist/{dts/internal → internal}/opfsWorker.d.ts +0 -0
- /package/dist/{esm/internal → internal}/opfsWorker.js +0 -0
package/src/SqliteClient.ts
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
import * as Client from "@effect/sql/SqlClient"
|
|
6
|
-
import type { Connection } from "@effect/sql/SqlConnection"
|
|
7
|
-
import { SqlError } from "@effect/sql/SqlError"
|
|
8
|
-
import * as Statement from "@effect/sql/Statement"
|
|
4
|
+
// oxlint-disable-next-line effect/no-import-from-barrel-package
|
|
9
5
|
import * as WaSqlite from "@effect/wa-sqlite"
|
|
10
6
|
import SQLiteESMFactory from "@effect/wa-sqlite/dist/wa-sqlite.mjs"
|
|
11
7
|
import { MemoryVFS } from "@effect/wa-sqlite/src/examples/MemoryVFS.js"
|
|
12
|
-
import * as Chunk from "effect/Chunk"
|
|
13
8
|
import * as Config from "effect/Config"
|
|
14
|
-
import type { ConfigError } from "effect/ConfigError"
|
|
15
|
-
import * as Context from "effect/Context"
|
|
16
9
|
import * as Deferred from "effect/Deferred"
|
|
17
10
|
import * as Effect from "effect/Effect"
|
|
18
11
|
import * as Exit from "effect/Exit"
|
|
19
|
-
import * as
|
|
12
|
+
import * as Fiber from "effect/Fiber"
|
|
20
13
|
import { identity } from "effect/Function"
|
|
21
|
-
import { globalValue } from "effect/GlobalValue"
|
|
22
14
|
import * as Layer from "effect/Layer"
|
|
23
15
|
import * as Scope from "effect/Scope"
|
|
24
16
|
import * as ScopedRef from "effect/ScopedRef"
|
|
17
|
+
import * as ServiceMap from "effect/ServiceMap"
|
|
25
18
|
import * as Stream from "effect/Stream"
|
|
26
|
-
import
|
|
19
|
+
import * as Reactivity from "effect/unstable/reactivity/Reactivity"
|
|
20
|
+
import * as Client from "effect/unstable/sql/SqlClient"
|
|
21
|
+
import type { Connection } from "effect/unstable/sql/SqlConnection"
|
|
22
|
+
import { SqlError } from "effect/unstable/sql/SqlError"
|
|
23
|
+
import * as Statement from "effect/unstable/sql/Statement"
|
|
24
|
+
import type { OpfsWorkerMessage } from "./internal/opfsWorker.ts"
|
|
27
25
|
|
|
28
26
|
const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
29
27
|
|
|
@@ -31,13 +29,13 @@ const ATTR_DB_SYSTEM_NAME = "db.system.name"
|
|
|
31
29
|
* @category type ids
|
|
32
30
|
* @since 1.0.0
|
|
33
31
|
*/
|
|
34
|
-
export const TypeId:
|
|
32
|
+
export const TypeId: TypeId = "~@effect/sql-sqlite-wasm/SqliteClient"
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
35
|
* @category type ids
|
|
38
36
|
* @since 1.0.0
|
|
39
37
|
*/
|
|
40
|
-
export type TypeId =
|
|
38
|
+
export type TypeId = "~@effect/sql-sqlite-wasm/SqliteClient"
|
|
41
39
|
|
|
42
40
|
/**
|
|
43
41
|
* @category models
|
|
@@ -57,7 +55,7 @@ export interface SqliteClient extends Client.SqlClient {
|
|
|
57
55
|
* @category tags
|
|
58
56
|
* @since 1.0.0
|
|
59
57
|
*/
|
|
60
|
-
export const SqliteClient =
|
|
58
|
+
export const SqliteClient = ServiceMap.Service<SqliteClient>("@effect/sql-sqlite-wasm/SqliteClient")
|
|
61
59
|
|
|
62
60
|
/**
|
|
63
61
|
* @category models
|
|
@@ -95,7 +93,7 @@ const initEffect = Effect.runSync(
|
|
|
95
93
|
Effect.cached(initModule.pipe(Effect.map((module) => WaSqlite.Factory(module))))
|
|
96
94
|
)
|
|
97
95
|
|
|
98
|
-
const registered =
|
|
96
|
+
const registered = new Set<string>()
|
|
99
97
|
|
|
100
98
|
/**
|
|
101
99
|
* @category constructor
|
|
@@ -135,7 +133,7 @@ export const makeMemory = (
|
|
|
135
133
|
sqlite3.update_hook(db, (_op, _db, table, rowid) => {
|
|
136
134
|
if (!table) return
|
|
137
135
|
const id = String(Number(rowid))
|
|
138
|
-
reactivity.
|
|
136
|
+
reactivity.invalidateUnsafe({ [table]: [id] })
|
|
139
137
|
})
|
|
140
138
|
}
|
|
141
139
|
|
|
@@ -202,7 +200,7 @@ export const makeMemory = (
|
|
|
202
200
|
}
|
|
203
201
|
return Stream.suspend(() => Stream.fromIteratorSucceed(stream()[Symbol.iterator]())).pipe(
|
|
204
202
|
transformRows
|
|
205
|
-
? Stream.
|
|
203
|
+
? Stream.mapArray((chunk) => transformRows(chunk) as any)
|
|
206
204
|
: identity,
|
|
207
205
|
Stream.mapError((cause) => new SqlError({ cause, message: "Failed to execute statement" }))
|
|
208
206
|
)
|
|
@@ -224,18 +222,17 @@ export const makeMemory = (
|
|
|
224
222
|
const connection = yield* makeConnection
|
|
225
223
|
|
|
226
224
|
const acquirer = semaphore.withPermits(1)(Effect.succeed(connection))
|
|
227
|
-
const transactionAcquirer = Effect.uninterruptibleMask((restore) =>
|
|
228
|
-
|
|
229
|
-
|
|
225
|
+
const transactionAcquirer = Effect.uninterruptibleMask((restore) => {
|
|
226
|
+
const fiber = Fiber.getCurrent()!
|
|
227
|
+
const scope = ServiceMap.getUnsafe(fiber.services, Scope.Scope)
|
|
228
|
+
return Effect.as(
|
|
229
|
+
Effect.tap(
|
|
230
230
|
restore(semaphore.take(1)),
|
|
231
|
-
|
|
232
|
-
Effect.scope,
|
|
233
|
-
(scope) => Scope.addFinalizer(scope, semaphore.release(1))
|
|
234
|
-
)
|
|
231
|
+
() => Scope.addFinalizer(scope, semaphore.release(1))
|
|
235
232
|
),
|
|
236
233
|
connection
|
|
237
234
|
)
|
|
238
|
-
)
|
|
235
|
+
})
|
|
239
236
|
|
|
240
237
|
return Object.assign(
|
|
241
238
|
(yield* Client.make({
|
|
@@ -289,10 +286,10 @@ export const make = (
|
|
|
289
286
|
const onMessage = (event: any) => {
|
|
290
287
|
const [id, error, results] = event.data
|
|
291
288
|
if (id === "ready") {
|
|
292
|
-
Deferred.
|
|
289
|
+
Deferred.doneUnsafe(readyDeferred, Exit.void)
|
|
293
290
|
return
|
|
294
291
|
} else if (id === "update_hook") {
|
|
295
|
-
reactivity.
|
|
292
|
+
reactivity.invalidateUnsafe({ [error]: [results] })
|
|
296
293
|
return
|
|
297
294
|
} else {
|
|
298
295
|
const resume = pending.get(id)
|
|
@@ -329,7 +326,7 @@ export const make = (
|
|
|
329
326
|
}
|
|
330
327
|
|
|
331
328
|
const send = (id: number, message: OpfsWorkerMessage, transferables?: ReadonlyArray<any>) =>
|
|
332
|
-
Effect.
|
|
329
|
+
Effect.callback<any, SqlError>((resume) => {
|
|
333
330
|
pending.set(id, resume)
|
|
334
331
|
postMessage(message, transferables)
|
|
335
332
|
})
|
|
@@ -339,9 +336,9 @@ export const make = (
|
|
|
339
336
|
params: ReadonlyArray<unknown> = [],
|
|
340
337
|
rowMode: "object" | "array" = "object"
|
|
341
338
|
): Effect.Effect<Array<any>, SqlError, never> => {
|
|
342
|
-
const rows = Effect.
|
|
339
|
+
const rows = Effect.withFiber<[Array<string>, Array<any>], SqlError>((fiber) => {
|
|
343
340
|
const id = currentId++
|
|
344
|
-
return send(id, [id, sql, params], fiber.
|
|
341
|
+
return send(id, [id, sql, params], fiber.getRef(Transferables))
|
|
345
342
|
})
|
|
346
343
|
return rowMode === "object"
|
|
347
344
|
? Effect.map(rows, extractObject)
|
|
@@ -364,7 +361,7 @@ export const make = (
|
|
|
364
361
|
return this.execute(sql, params, transformRows)
|
|
365
362
|
},
|
|
366
363
|
executeStream() {
|
|
367
|
-
return
|
|
364
|
+
return Stream.die("executeStream not implemented")
|
|
368
365
|
},
|
|
369
366
|
export: Effect.suspend(() => {
|
|
370
367
|
const id = currentId++
|
|
@@ -383,18 +380,13 @@ export const make = (
|
|
|
383
380
|
|
|
384
381
|
const semaphore = yield* Effect.makeSemaphore(1)
|
|
385
382
|
const acquirer = semaphore.withPermits(1)(ScopedRef.get(connectionRef))
|
|
386
|
-
const transactionAcquirer = Effect.uninterruptibleMask((restore)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
)
|
|
394
|
-
),
|
|
395
|
-
ScopedRef.get(connectionRef)
|
|
396
|
-
)
|
|
397
|
-
)
|
|
383
|
+
const transactionAcquirer = Effect.uninterruptibleMask(Effect.fnUntraced(function*(restore) {
|
|
384
|
+
const fiber = Fiber.getCurrent()!
|
|
385
|
+
const scope = ServiceMap.getUnsafe(fiber.services, Scope.Scope)
|
|
386
|
+
yield* restore(semaphore.take(1))
|
|
387
|
+
yield* Scope.addFinalizer(scope, semaphore.release(1))
|
|
388
|
+
return yield* ScopedRef.get(connectionRef)
|
|
389
|
+
}))
|
|
398
390
|
|
|
399
391
|
return Object.assign(
|
|
400
392
|
(yield* Client.make({
|
|
@@ -432,9 +424,9 @@ const extractRows = (rows: [Array<string>, Array<any>]) => rows[1]
|
|
|
432
424
|
* @category tranferables
|
|
433
425
|
* @since 1.0.0
|
|
434
426
|
*/
|
|
435
|
-
export const
|
|
427
|
+
export const Transferables = ServiceMap.Reference<ReadonlyArray<Transferable>>(
|
|
436
428
|
"@effect/sql-sqlite-wasm/currentTransferables",
|
|
437
|
-
() =>
|
|
429
|
+
{ defaultValue: () => [] }
|
|
438
430
|
)
|
|
439
431
|
|
|
440
432
|
/**
|
|
@@ -443,21 +435,21 @@ export const currentTransferables: FiberRef.FiberRef<ReadonlyArray<Transferable>
|
|
|
443
435
|
*/
|
|
444
436
|
export const withTransferables =
|
|
445
437
|
(transferables: ReadonlyArray<Transferable>) => <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
446
|
-
Effect.
|
|
438
|
+
Effect.provideService(effect, Transferables, transferables)
|
|
447
439
|
|
|
448
440
|
/**
|
|
449
441
|
* @category layers
|
|
450
442
|
* @since 1.0.0
|
|
451
443
|
*/
|
|
452
444
|
export const layerMemoryConfig = (
|
|
453
|
-
config: Config.
|
|
454
|
-
): Layer.Layer<SqliteClient | Client.SqlClient, ConfigError | SqlError> =>
|
|
455
|
-
Layer.
|
|
456
|
-
Config.unwrap(config).pipe(
|
|
445
|
+
config: Config.Wrap<SqliteClientMemoryConfig>
|
|
446
|
+
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError | SqlError> =>
|
|
447
|
+
Layer.effectServices(
|
|
448
|
+
Config.unwrap(config).asEffect().pipe(
|
|
457
449
|
Effect.flatMap(makeMemory),
|
|
458
450
|
Effect.map((client) =>
|
|
459
|
-
|
|
460
|
-
|
|
451
|
+
ServiceMap.make(SqliteClient, client).pipe(
|
|
452
|
+
ServiceMap.add(Client.SqlClient, client)
|
|
461
453
|
)
|
|
462
454
|
)
|
|
463
455
|
)
|
|
@@ -469,11 +461,11 @@ export const layerMemoryConfig = (
|
|
|
469
461
|
*/
|
|
470
462
|
export const layerMemory = (
|
|
471
463
|
config: SqliteClientMemoryConfig
|
|
472
|
-
): Layer.Layer<SqliteClient | Client.SqlClient,
|
|
473
|
-
Layer.
|
|
464
|
+
): Layer.Layer<SqliteClient | Client.SqlClient, SqlError> =>
|
|
465
|
+
Layer.effectServices(
|
|
474
466
|
Effect.map(makeMemory(config), (client) =>
|
|
475
|
-
|
|
476
|
-
|
|
467
|
+
ServiceMap.make(SqliteClient, client).pipe(
|
|
468
|
+
ServiceMap.add(Client.SqlClient, client)
|
|
477
469
|
))
|
|
478
470
|
).pipe(Layer.provide(Reactivity.layer))
|
|
479
471
|
|
|
@@ -483,11 +475,11 @@ export const layerMemory = (
|
|
|
483
475
|
*/
|
|
484
476
|
export const layer = (
|
|
485
477
|
config: SqliteClientConfig
|
|
486
|
-
): Layer.Layer<SqliteClient | Client.SqlClient,
|
|
487
|
-
Layer.
|
|
478
|
+
): Layer.Layer<SqliteClient | Client.SqlClient, SqlError> =>
|
|
479
|
+
Layer.effectServices(
|
|
488
480
|
Effect.map(make(config), (client) =>
|
|
489
|
-
|
|
490
|
-
|
|
481
|
+
ServiceMap.make(SqliteClient, client).pipe(
|
|
482
|
+
ServiceMap.add(Client.SqlClient, client)
|
|
491
483
|
))
|
|
492
484
|
).pipe(Layer.provide(Reactivity.layer))
|
|
493
485
|
|
|
@@ -496,14 +488,14 @@ export const layer = (
|
|
|
496
488
|
* @since 1.0.0
|
|
497
489
|
*/
|
|
498
490
|
export const layerConfig = (
|
|
499
|
-
config: Config.
|
|
500
|
-
): Layer.Layer<SqliteClient | Client.SqlClient, ConfigError | SqlError> =>
|
|
501
|
-
Layer.
|
|
502
|
-
Config.unwrap(config).pipe(
|
|
491
|
+
config: Config.Wrap<SqliteClientConfig>
|
|
492
|
+
): Layer.Layer<SqliteClient | Client.SqlClient, Config.ConfigError | SqlError> =>
|
|
493
|
+
Layer.effectServices(
|
|
494
|
+
Config.unwrap(config).asEffect().pipe(
|
|
503
495
|
Effect.flatMap(make),
|
|
504
496
|
Effect.map((client) =>
|
|
505
|
-
|
|
506
|
-
|
|
497
|
+
ServiceMap.make(SqliteClient, client).pipe(
|
|
498
|
+
ServiceMap.add(Client.SqlClient, client)
|
|
507
499
|
)
|
|
508
500
|
)
|
|
509
501
|
)
|
package/src/SqliteMigrator.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
import * as Migrator from "@effect/sql/Migrator"
|
|
5
|
-
import type * as Client from "@effect/sql/SqlClient"
|
|
6
|
-
import type { SqlError } from "@effect/sql/SqlError"
|
|
7
4
|
import type * as Effect from "effect/Effect"
|
|
8
5
|
import * as Layer from "effect/Layer"
|
|
6
|
+
import * as Migrator from "effect/unstable/sql/Migrator"
|
|
7
|
+
import type * as Client from "effect/unstable/sql/SqlClient"
|
|
8
|
+
import type { SqlError } from "effect/unstable/sql/SqlError"
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @since 1.0.0
|
|
12
12
|
*/
|
|
13
|
-
export * from "
|
|
13
|
+
export * from "effect/unstable/sql/Migrator"
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @category constructor
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
-
export * as OpfsWorker from "./OpfsWorker.
|
|
4
|
+
export * as OpfsWorker from "./OpfsWorker.ts"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @since 1.0.0
|
|
8
8
|
*/
|
|
9
|
-
export * as SqliteClient from "./SqliteClient.
|
|
9
|
+
export * as SqliteClient from "./SqliteClient.ts"
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @since 1.0.0
|
|
13
13
|
*/
|
|
14
|
-
export * as SqliteMigrator from "./SqliteMigrator.
|
|
14
|
+
export * as SqliteMigrator from "./SqliteMigrator.ts"
|
package/src/sqlite-wasm.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
declare module "@effect/wa-sqlite/src/examples/IDBBatchAtomicVFS.js" {
|
|
5
|
+
// oxlint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
5
6
|
export class IDBBatchAtomicVFS {
|
|
6
7
|
static async create(name: string, module: any, options?: any): Promise<any>
|
|
7
8
|
}
|
|
@@ -11,6 +12,7 @@ declare module "@effect/wa-sqlite/src/examples/IDBBatchAtomicVFS.js" {
|
|
|
11
12
|
* @since 1.0.0
|
|
12
13
|
*/
|
|
13
14
|
declare module "@effect/wa-sqlite/src/examples/AccessHandlePoolVFS.js" {
|
|
15
|
+
// oxlint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
14
16
|
export class AccessHandlePoolVFS {
|
|
15
17
|
static async create(name: string, module: any, options?: any): Promise<any>
|
|
16
18
|
}
|
package/OpfsWorker/package.json
DELETED
package/dist/cjs/OpfsWorker.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.run = void 0;
|
|
7
|
-
var _SqlError = require("@effect/sql/SqlError");
|
|
8
|
-
var WaSqlite = _interopRequireWildcard(require("@effect/wa-sqlite"));
|
|
9
|
-
var _waSqlite2 = _interopRequireDefault(require("@effect/wa-sqlite/dist/wa-sqlite.mjs"));
|
|
10
|
-
var _AccessHandlePoolVFS = require("@effect/wa-sqlite/src/examples/AccessHandlePoolVFS.js");
|
|
11
|
-
var Effect = _interopRequireWildcard(require("effect/Effect"));
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
-
/**
|
|
15
|
-
* @since 1.0.0
|
|
16
|
-
*/
|
|
17
|
-
/// <reference lib="webworker" />
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @category constructor
|
|
21
|
-
* @since 1.0.0
|
|
22
|
-
*/
|
|
23
|
-
const run = options => Effect.gen(function* () {
|
|
24
|
-
const factory = yield* Effect.promise(() => (0, _waSqlite2.default)());
|
|
25
|
-
const sqlite3 = WaSqlite.Factory(factory);
|
|
26
|
-
const vfs = yield* Effect.promise(() => _AccessHandlePoolVFS.AccessHandlePoolVFS.create("opfs", factory));
|
|
27
|
-
sqlite3.vfs_register(vfs, false);
|
|
28
|
-
const db = yield* Effect.acquireRelease(Effect.try({
|
|
29
|
-
try: () => sqlite3.open_v2(options.dbName, undefined, "opfs"),
|
|
30
|
-
catch: cause => new _SqlError.SqlError({
|
|
31
|
-
cause,
|
|
32
|
-
message: "Failed to open database"
|
|
33
|
-
})
|
|
34
|
-
}), db => Effect.sync(() => sqlite3.close(db)));
|
|
35
|
-
return yield* Effect.async(resume => {
|
|
36
|
-
const onMessage = event => {
|
|
37
|
-
let messageId;
|
|
38
|
-
const message = event.data;
|
|
39
|
-
try {
|
|
40
|
-
switch (message[0]) {
|
|
41
|
-
case "close":
|
|
42
|
-
{
|
|
43
|
-
options.port.close();
|
|
44
|
-
return resume(Effect.void);
|
|
45
|
-
}
|
|
46
|
-
case "import":
|
|
47
|
-
{
|
|
48
|
-
const [, id, data] = message;
|
|
49
|
-
messageId = id;
|
|
50
|
-
sqlite3.deserialize(db, "main", data, data.length, data.length, 1 | 2);
|
|
51
|
-
options.port.postMessage([id, void 0, void 0]);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
case "export":
|
|
55
|
-
{
|
|
56
|
-
const [, id] = message;
|
|
57
|
-
messageId = id;
|
|
58
|
-
const data = sqlite3.serialize(db, "main");
|
|
59
|
-
options.port.postMessage([id, undefined, data], [data.buffer]);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
case "update_hook":
|
|
63
|
-
{
|
|
64
|
-
messageId = -1;
|
|
65
|
-
sqlite3.update_hook(db, (_op, _db, table, rowid) => {
|
|
66
|
-
if (!table) return;
|
|
67
|
-
options.port.postMessage(["update_hook", table, Number(rowid)]);
|
|
68
|
-
});
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
default:
|
|
72
|
-
{
|
|
73
|
-
const [id, sql, params] = message;
|
|
74
|
-
messageId = id;
|
|
75
|
-
const results = [];
|
|
76
|
-
let columns;
|
|
77
|
-
for (const stmt of sqlite3.statements(db, sql)) {
|
|
78
|
-
sqlite3.bind_collection(stmt, params);
|
|
79
|
-
while (sqlite3.step(stmt) === WaSqlite.SQLITE_ROW) {
|
|
80
|
-
columns = columns ?? sqlite3.column_names(stmt);
|
|
81
|
-
const row = sqlite3.row(stmt);
|
|
82
|
-
results.push(row);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
options.port.postMessage([id, undefined, [columns, results]]);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch (e) {
|
|
90
|
-
const message = "message" in e ? e.message : String(e);
|
|
91
|
-
options.port.postMessage([messageId, message, undefined]);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
options.port.addEventListener("message", onMessage);
|
|
95
|
-
options.port.postMessage(["ready", undefined, undefined]);
|
|
96
|
-
return Effect.sync(() => {
|
|
97
|
-
options.port.removeEventListener("message", onMessage);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
}).pipe(Effect.scoped);
|
|
101
|
-
exports.run = run;
|
|
102
|
-
//# sourceMappingURL=OpfsWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OpfsWorker.js","names":["_SqlError","require","WaSqlite","_interopRequireWildcard","_waSqlite2","_interopRequireDefault","_AccessHandlePoolVFS","Effect","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","run","options","gen","factory","promise","SQLiteESMFactory","sqlite3","Factory","vfs","AccessHandlePoolVFS","create","vfs_register","db","acquireRelease","try","open_v2","dbName","undefined","catch","cause","SqlError","message","sync","close","async","resume","onMessage","event","messageId","data","port","void","id","deserialize","length","postMessage","serialize","buffer","update_hook","_op","_db","table","rowid","Number","sql","params","results","columns","stmt","statements","bind_collection","step","SQLITE_ROW","column_names","row","push","String","addEventListener","removeEventListener","pipe","scoped","exports"],"sources":["../../src/OpfsWorker.ts"],"sourcesContent":[null],"mappings":";;;;;;AAIA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,UAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAJ,uBAAA,CAAAF,OAAA;AAAuC,SAAAI,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAK,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAA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