@effect/platform-browser 4.0.0-beta.65 → 4.0.0-beta.67
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/BrowserHttpClient.d.ts +18 -8
- package/dist/BrowserHttpClient.d.ts.map +1 -1
- package/dist/BrowserHttpClient.js +45 -8
- package/dist/BrowserHttpClient.js.map +1 -1
- package/dist/BrowserKeyValueStore.d.ts +13 -6
- package/dist/BrowserKeyValueStore.d.ts.map +1 -1
- package/dist/BrowserKeyValueStore.js +126 -2
- package/dist/BrowserKeyValueStore.js.map +1 -1
- package/dist/BrowserPersistence.d.ts +6 -2
- package/dist/BrowserPersistence.d.ts.map +1 -1
- package/dist/BrowserPersistence.js +6 -2
- package/dist/BrowserPersistence.js.map +1 -1
- package/dist/BrowserRuntime.d.ts +31 -4
- package/dist/BrowserRuntime.d.ts.map +1 -1
- package/dist/BrowserRuntime.js +3 -1
- package/dist/BrowserRuntime.js.map +1 -1
- package/dist/BrowserSocket.d.ts +29 -4
- package/dist/BrowserSocket.d.ts.map +1 -1
- package/dist/BrowserSocket.js +29 -4
- package/dist/BrowserSocket.js.map +1 -1
- package/dist/BrowserStream.d.ts +25 -3
- package/dist/BrowserStream.d.ts.map +1 -1
- package/dist/BrowserStream.js +25 -3
- package/dist/BrowserStream.js.map +1 -1
- package/dist/BrowserWorker.d.ts +6 -2
- package/dist/BrowserWorker.d.ts.map +1 -1
- package/dist/BrowserWorker.js +28 -4
- package/dist/BrowserWorker.js.map +1 -1
- package/dist/BrowserWorkerRunner.d.ts +9 -3
- package/dist/BrowserWorkerRunner.d.ts.map +1 -1
- package/dist/BrowserWorkerRunner.js +30 -6
- package/dist/BrowserWorkerRunner.js.map +1 -1
- package/dist/Clipboard.d.ts +30 -6
- package/dist/Clipboard.d.ts.map +1 -1
- package/dist/Clipboard.js +27 -5
- package/dist/Clipboard.js.map +1 -1
- package/dist/Geolocation.d.ts +44 -10
- package/dist/Geolocation.d.ts.map +1 -1
- package/dist/Geolocation.js +38 -8
- package/dist/Geolocation.js.map +1 -1
- package/dist/IndexedDb.d.ts +38 -11
- package/dist/IndexedDb.d.ts.map +1 -1
- package/dist/IndexedDb.js +35 -13
- package/dist/IndexedDb.js.map +1 -1
- package/dist/IndexedDbDatabase.d.ts +57 -10
- package/dist/IndexedDbDatabase.d.ts.map +1 -1
- package/dist/IndexedDbDatabase.js +36 -3
- package/dist/IndexedDbDatabase.js.map +1 -1
- package/dist/IndexedDbQueryBuilder.d.ts +103 -28
- package/dist/IndexedDbQueryBuilder.d.ts.map +1 -1
- package/dist/IndexedDbQueryBuilder.js +56 -26
- package/dist/IndexedDbQueryBuilder.js.map +1 -1
- package/dist/IndexedDbTable.d.ts +57 -13
- package/dist/IndexedDbTable.d.ts.map +1 -1
- package/dist/IndexedDbTable.js +21 -1
- package/dist/IndexedDbTable.js.map +1 -1
- package/dist/IndexedDbVersion.d.ts +37 -7
- package/dist/IndexedDbVersion.d.ts.map +1 -1
- package/dist/IndexedDbVersion.js +3 -1
- package/dist/IndexedDbVersion.js.map +1 -1
- package/dist/Permissions.d.ts +35 -8
- package/dist/Permissions.d.ts.map +1 -1
- package/dist/Permissions.js +31 -6
- package/dist/Permissions.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.js +12 -12
- package/package.json +3 -3
- package/src/BrowserHttpClient.ts +48 -9
- package/src/BrowserKeyValueStore.ts +142 -4
- package/src/BrowserPersistence.ts +19 -3
- package/src/BrowserRuntime.ts +31 -4
- package/src/BrowserSocket.ts +29 -4
- package/src/BrowserStream.ts +25 -3
- package/src/BrowserWorker.ts +28 -4
- package/src/BrowserWorkerRunner.ts +30 -6
- package/src/Clipboard.ts +30 -6
- package/src/Geolocation.ts +44 -10
- package/src/IndexedDb.ts +39 -21
- package/src/IndexedDbDatabase.ts +57 -10
- package/src/IndexedDbQueryBuilder.ts +172 -58
- package/src/IndexedDbTable.ts +57 -13
- package/src/IndexedDbVersion.ts +37 -7
- package/src/Permissions.ts +35 -8
- package/src/index.ts +12 -12
package/src/IndexedDbDatabase.ts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Builds and opens typed IndexedDB databases from versioned schema migrations.
|
|
3
|
+
*
|
|
4
|
+
* This module turns an `IndexedDbVersion` migration chain into an
|
|
5
|
+
* `IndexedDbDatabase` layer. The layer opens the browser database, runs any
|
|
6
|
+
* pending upgrade migrations, provides a query builder for the current schema,
|
|
7
|
+
* and exposes a `rebuild` effect that deletes and reopens the database. It is
|
|
8
|
+
* the database-level companion to the table, version, and query builder
|
|
9
|
+
* modules.
|
|
10
|
+
*
|
|
11
|
+
* Use it for browser-local persistence such as offline-first application
|
|
12
|
+
* state, cached server data, background queues, drafts, and other client-side
|
|
13
|
+
* stores that need typed reads and writes backed by IndexedDB transactions.
|
|
14
|
+
*
|
|
15
|
+
* IndexedDB schema changes can only happen inside upgrade transactions, so
|
|
16
|
+
* every call to `make` or `.add` represents the next browser database version
|
|
17
|
+
* and only migrations after the existing browser version are run. Table and
|
|
18
|
+
* index definitions type the migration and query APIs, but object stores and
|
|
19
|
+
* indexes still need to be created or removed explicitly with the migration
|
|
20
|
+
* transaction helpers. Include the complete target table set in each version,
|
|
21
|
+
* create indexes before querying them, and treat key path or auto-increment
|
|
22
|
+
* changes as store migrations that copy data into a replacement object store.
|
|
23
|
+
* Upgrades can be blocked by other open connections, and all migration reads,
|
|
24
|
+
* writes, store changes, and index changes share the single upgrade
|
|
25
|
+
* transaction supplied by the browser.
|
|
26
|
+
*
|
|
2
27
|
* @since 4.0.0
|
|
3
28
|
*/
|
|
4
29
|
import * as Context from "effect/Context"
|
|
@@ -60,8 +85,10 @@ const SchemaProto = {
|
|
|
60
85
|
}
|
|
61
86
|
|
|
62
87
|
/**
|
|
63
|
-
*
|
|
88
|
+
* String union describing the failure categories for IndexedDB database opening, migration, and schema operations.
|
|
89
|
+
*
|
|
64
90
|
* @category errors
|
|
91
|
+
* @since 4.0.0
|
|
65
92
|
*/
|
|
66
93
|
export type ErrorReason =
|
|
67
94
|
| "TransactionError"
|
|
@@ -73,8 +100,10 @@ export type ErrorReason =
|
|
|
73
100
|
| "MissingIndex"
|
|
74
101
|
|
|
75
102
|
/**
|
|
76
|
-
*
|
|
103
|
+
* Tagged error for IndexedDB database operations, carrying a database error reason and the original cause.
|
|
104
|
+
*
|
|
77
105
|
* @category errors
|
|
106
|
+
* @since 4.0.0
|
|
78
107
|
*/
|
|
79
108
|
export class IndexedDbDatabaseError extends Data.TaggedError(
|
|
80
109
|
"IndexedDbDatabaseError"
|
|
@@ -83,6 +112,8 @@ export class IndexedDbDatabaseError extends Data.TaggedError(
|
|
|
83
112
|
cause: unknown
|
|
84
113
|
}> {
|
|
85
114
|
/**
|
|
115
|
+
* Marks this value as an IndexedDB database error for runtime guards.
|
|
116
|
+
*
|
|
86
117
|
* @since 4.0.0
|
|
87
118
|
*/
|
|
88
119
|
readonly [ErrorTypeId]: typeof ErrorTypeId = ErrorTypeId
|
|
@@ -90,8 +121,10 @@ export class IndexedDbDatabaseError extends Data.TaggedError(
|
|
|
90
121
|
}
|
|
91
122
|
|
|
92
123
|
/**
|
|
93
|
-
*
|
|
124
|
+
* Service tag for an open IndexedDB database, its `IDBKeyRange` constructor, reactivity service, and rebuild effect.
|
|
125
|
+
*
|
|
94
126
|
* @category models
|
|
127
|
+
* @since 4.0.0
|
|
95
128
|
*/
|
|
96
129
|
export class IndexedDbDatabase extends Context.Service<
|
|
97
130
|
IndexedDbDatabase,
|
|
@@ -104,8 +137,10 @@ export class IndexedDbDatabase extends Context.Service<
|
|
|
104
137
|
>()(TypeId) {}
|
|
105
138
|
|
|
106
139
|
/**
|
|
107
|
-
*
|
|
140
|
+
* Describes an IndexedDB schema version and its migrations, and acts as an effect that yields a query builder for the target version.
|
|
141
|
+
*
|
|
108
142
|
* @category models
|
|
143
|
+
* @since 4.0.0
|
|
109
144
|
*/
|
|
110
145
|
export interface IndexedDbSchema<
|
|
111
146
|
in out FromVersion extends IndexedDbVersion.AnyWithProps,
|
|
@@ -155,8 +190,10 @@ export interface IndexedDbSchema<
|
|
|
155
190
|
}
|
|
156
191
|
|
|
157
192
|
/**
|
|
158
|
-
*
|
|
193
|
+
* Query builder available during a database migration, extended with object-store and index management helpers for the active `IDBTransaction`.
|
|
194
|
+
*
|
|
159
195
|
* @category models
|
|
196
|
+
* @since 4.0.0
|
|
160
197
|
*/
|
|
161
198
|
export interface Transaction<
|
|
162
199
|
Source extends IndexedDbVersion.AnyWithProps = never
|
|
@@ -192,8 +229,10 @@ export interface Transaction<
|
|
|
192
229
|
}
|
|
193
230
|
|
|
194
231
|
/**
|
|
195
|
-
*
|
|
232
|
+
* Extracts the string-literal index names defined by an `IndexedDbTable`.
|
|
233
|
+
*
|
|
196
234
|
* @category models
|
|
235
|
+
* @since 4.0.0
|
|
197
236
|
*/
|
|
198
237
|
export type IndexFromTable<Table extends IndexedDbTable.AnyWithProps> = IsStringLiteral<
|
|
199
238
|
Extract<keyof IndexedDbTable.Indexes<Table>, string>
|
|
@@ -201,8 +240,10 @@ export type IndexFromTable<Table extends IndexedDbTable.AnyWithProps> = IsString
|
|
|
201
240
|
: never
|
|
202
241
|
|
|
203
242
|
/**
|
|
204
|
-
*
|
|
243
|
+
* Extracts the valid index names for a table name within an IndexedDB version.
|
|
244
|
+
*
|
|
205
245
|
* @category models
|
|
246
|
+
* @since 4.0.0
|
|
206
247
|
*/
|
|
207
248
|
export type IndexFromTableName<
|
|
208
249
|
Version extends IndexedDbVersion.AnyWithProps,
|
|
@@ -212,8 +253,10 @@ export type IndexFromTableName<
|
|
|
212
253
|
>
|
|
213
254
|
|
|
214
255
|
/**
|
|
215
|
-
*
|
|
256
|
+
* Type-erased IndexedDB schema shape used when traversing schema migration chains.
|
|
257
|
+
*
|
|
216
258
|
* @category models
|
|
259
|
+
* @since 4.0.0
|
|
217
260
|
*/
|
|
218
261
|
export interface Any {
|
|
219
262
|
readonly previous?: Any | undefined
|
|
@@ -227,8 +270,10 @@ export interface Any {
|
|
|
227
270
|
}
|
|
228
271
|
|
|
229
272
|
/**
|
|
230
|
-
*
|
|
273
|
+
* Type-erased `IndexedDbSchema` covering any source version, target version, and migration error type.
|
|
274
|
+
*
|
|
231
275
|
* @category models
|
|
276
|
+
* @since 4.0.0
|
|
232
277
|
*/
|
|
233
278
|
export type AnySchema = IndexedDbSchema<
|
|
234
279
|
IndexedDbVersion.AnyWithProps,
|
|
@@ -237,8 +282,10 @@ export type AnySchema = IndexedDbSchema<
|
|
|
237
282
|
>
|
|
238
283
|
|
|
239
284
|
/**
|
|
240
|
-
*
|
|
285
|
+
* Creates the initial `IndexedDbSchema` from a version and an initialization migration run during database upgrade.
|
|
286
|
+
*
|
|
241
287
|
* @category constructors
|
|
288
|
+
* @since 4.0.0
|
|
242
289
|
*/
|
|
243
290
|
export const make = <
|
|
244
291
|
InitialVersion extends IndexedDbVersion.AnyWithProps,
|
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Builds effectful, schema-aware queries for typed browser IndexedDB versions.
|
|
3
|
+
*
|
|
4
|
+
* An `IndexedDbQueryBuilder` is created from an open database and a version's
|
|
5
|
+
* table descriptors, then exposes `from(tableName)` as the entry point for
|
|
6
|
+
* table operations. The resulting query objects can select, count, delete,
|
|
7
|
+
* insert, upsert, clear tables, stream paged reads, react to invalidations, and
|
|
8
|
+
* run multiple effects in a shared `IDBTransaction` with `withTransaction`.
|
|
9
|
+
*
|
|
10
|
+
* Use this module for local browser persistence such as caches, offline-first
|
|
11
|
+
* state, background queues, drafts, and other client-side data where writes
|
|
12
|
+
* should be encoded through `Schema` and reads should be decoded before they
|
|
13
|
+
* reach application code.
|
|
14
|
+
*
|
|
15
|
+
* Index and range helpers are thinly typed wrappers around IndexedDB object
|
|
16
|
+
* stores, indexes, `IDBKeyRange`, and cursors. Index names must be declared on
|
|
17
|
+
* the table and created during migrations; without an index, queries use the
|
|
18
|
+
* object store key path. Range values are encoded IndexedDB key values, and
|
|
19
|
+
* compound key paths must follow the declared key order. Filters, offsets,
|
|
20
|
+
* reverse reads, out-of-line keys, and limited deletes require cursor-based
|
|
21
|
+
* scans, while simpler selects can use `getAll`.
|
|
22
|
+
*
|
|
23
|
+
* Table schema details affect runtime behavior: auto-increment writes may omit
|
|
24
|
+
* the generated numeric key, stores without a key path require an out-of-line
|
|
25
|
+
* `key` for writes and add that `key` back to selected rows, and schema
|
|
26
|
+
* mismatches surface as `EncodeError` or `DecodeError` query failures.
|
|
27
|
+
*
|
|
2
28
|
* @since 4.0.0
|
|
3
29
|
*/
|
|
4
30
|
import type { NonEmptyReadonlyArray } from "effect/Array"
|
|
31
|
+
import * as Cause from "effect/Cause"
|
|
5
32
|
import * as Context from "effect/Context"
|
|
6
33
|
import * as Data from "effect/Data"
|
|
7
34
|
import * as Effect from "effect/Effect"
|
|
@@ -43,19 +70,22 @@ const CommonProto = {
|
|
|
43
70
|
}
|
|
44
71
|
|
|
45
72
|
/**
|
|
46
|
-
*
|
|
73
|
+
* String union describing IndexedDB query failure categories such as decoding, encoding, and transaction errors.
|
|
74
|
+
*
|
|
47
75
|
* @category errors
|
|
76
|
+
* @since 4.0.0
|
|
48
77
|
*/
|
|
49
78
|
export type ErrorReason =
|
|
50
|
-
| "NotFoundError"
|
|
51
79
|
| "UnknownError"
|
|
52
80
|
| "DecodeError"
|
|
53
81
|
| "EncodeError"
|
|
54
82
|
| "TransactionError"
|
|
55
83
|
|
|
56
84
|
/**
|
|
57
|
-
*
|
|
85
|
+
* Tagged error for IndexedDB query operations, carrying a query error reason and the original cause.
|
|
86
|
+
*
|
|
58
87
|
* @category errors
|
|
88
|
+
* @since 4.0.0
|
|
59
89
|
*/
|
|
60
90
|
export class IndexedDbQueryError extends Data.TaggedError(
|
|
61
91
|
"IndexedDbQueryError"
|
|
@@ -64,6 +94,8 @@ export class IndexedDbQueryError extends Data.TaggedError(
|
|
|
64
94
|
cause: unknown
|
|
65
95
|
}> {
|
|
66
96
|
/**
|
|
97
|
+
* Marks this value as an IndexedDB query builder error for runtime guards.
|
|
98
|
+
*
|
|
67
99
|
* @since 4.0.0
|
|
68
100
|
*/
|
|
69
101
|
readonly [ErrorTypeId]: typeof ErrorTypeId = ErrorTypeId
|
|
@@ -72,8 +104,10 @@ export class IndexedDbQueryError extends Data.TaggedError(
|
|
|
72
104
|
}
|
|
73
105
|
|
|
74
106
|
/**
|
|
75
|
-
*
|
|
107
|
+
* Typed query builder for an IndexedDB version, with helpers for table queries, database access, clearing data, and running effects in a shared transaction.
|
|
108
|
+
*
|
|
76
109
|
* @category models
|
|
110
|
+
* @since 4.0.0
|
|
77
111
|
*/
|
|
78
112
|
export interface IndexedDbQueryBuilder<
|
|
79
113
|
Source extends IndexedDbVersion.AnyWithProps
|
|
@@ -96,6 +130,9 @@ export interface IndexedDbQueryBuilder<
|
|
|
96
130
|
table: Name
|
|
97
131
|
) => IndexedDbQuery.From<IndexedDbVersion.TableWithName<Source, Name>>
|
|
98
132
|
|
|
133
|
+
/** @internal */
|
|
134
|
+
readonly fromCache: Map<string, IndexedDbQuery.From<IndexedDbVersion.TableWithName<Source, any>>>
|
|
135
|
+
|
|
99
136
|
readonly clearAll: Effect.Effect<void, IndexedDbQueryError>
|
|
100
137
|
|
|
101
138
|
readonly withTransaction: <
|
|
@@ -111,29 +148,37 @@ export interface IndexedDbQueryBuilder<
|
|
|
111
148
|
}
|
|
112
149
|
|
|
113
150
|
/**
|
|
114
|
-
*
|
|
151
|
+
* Valid key-path type for a table schema, using encoded fields whose values are IndexedDB-valid keys.
|
|
152
|
+
*
|
|
115
153
|
* @category models
|
|
154
|
+
* @since 4.0.0
|
|
116
155
|
*/
|
|
117
156
|
export type KeyPath<TableSchema extends IndexedDbTable.AnySchemaStruct> =
|
|
118
157
|
| IndexedDbValidKeys<TableSchema>
|
|
119
158
|
| NonEmptyReadonlyArray<IndexedDbValidKeys<TableSchema>>
|
|
120
159
|
|
|
121
160
|
/**
|
|
122
|
-
*
|
|
161
|
+
* Valid numeric key-path type for a table schema, used for auto-increment key paths.
|
|
162
|
+
*
|
|
123
163
|
* @category models
|
|
164
|
+
* @since 4.0.0
|
|
124
165
|
*/
|
|
125
166
|
export type KeyPathNumber<TableSchema extends IndexedDbTable.AnySchemaStruct> =
|
|
126
167
|
| IndexedDbValidNumberKeys<TableSchema>
|
|
127
168
|
| NonEmptyReadonlyArray<IndexedDbValidNumberKeys<TableSchema>>
|
|
128
169
|
|
|
129
170
|
/**
|
|
130
|
-
*
|
|
171
|
+
* Namespace containing the typed IndexedDB query model interfaces and helper types.
|
|
172
|
+
*
|
|
131
173
|
* @category models
|
|
174
|
+
* @since 4.0.0
|
|
132
175
|
*/
|
|
133
176
|
export declare namespace IndexedDbQuery {
|
|
134
177
|
/**
|
|
135
|
-
*
|
|
178
|
+
* Decoded row type returned by select queries, adding a `key` field when the table does not define a key path.
|
|
179
|
+
*
|
|
136
180
|
* @category models
|
|
181
|
+
* @since 4.0.0
|
|
137
182
|
*/
|
|
138
183
|
export type SelectType<
|
|
139
184
|
Table extends IndexedDbTable.AnyWithProps
|
|
@@ -143,8 +188,10 @@ export declare namespace IndexedDbQuery {
|
|
|
143
188
|
IndexedDbTable.TableSchema<Table>["Type"]
|
|
144
189
|
|
|
145
190
|
/**
|
|
146
|
-
*
|
|
191
|
+
* Input type for insert and upsert operations, adjusted for auto-increment keys and out-of-line keys.
|
|
192
|
+
*
|
|
147
193
|
* @category models
|
|
194
|
+
* @since 4.0.0
|
|
148
195
|
*/
|
|
149
196
|
export type ModifyType<
|
|
150
197
|
Table extends IndexedDbTable.AnyWithProps
|
|
@@ -175,8 +222,10 @@ export declare namespace IndexedDbQuery {
|
|
|
175
222
|
: {})
|
|
176
223
|
|
|
177
224
|
/**
|
|
178
|
-
*
|
|
225
|
+
* Value type accepted by `equals` comparisons for a table key path or index.
|
|
226
|
+
*
|
|
179
227
|
* @category models
|
|
228
|
+
* @since 4.0.0
|
|
180
229
|
*/
|
|
181
230
|
export type EqualsType<
|
|
182
231
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -187,8 +236,10 @@ export declare namespace IndexedDbQuery {
|
|
|
187
236
|
: { [I in keyof KeyPath]: KeyPath[I] extends keyof Type ? Type[KeyPath[I]] | [] : never }
|
|
188
237
|
|
|
189
238
|
/**
|
|
190
|
-
*
|
|
239
|
+
* Value type accepted by range comparisons for a table key path or index, including partial tuples for compound indexes.
|
|
240
|
+
*
|
|
191
241
|
* @category models
|
|
242
|
+
* @since 4.0.0
|
|
192
243
|
*/
|
|
193
244
|
export type ExtractIndexType<
|
|
194
245
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -204,14 +255,18 @@ export declare namespace IndexedDbQuery {
|
|
|
204
255
|
never
|
|
205
256
|
|
|
206
257
|
/**
|
|
207
|
-
*
|
|
258
|
+
* Mutation input type for insert and upsert operations, including any required key fields.
|
|
259
|
+
*
|
|
208
260
|
* @category models
|
|
261
|
+
* @since 4.0.0
|
|
209
262
|
*/
|
|
210
263
|
export type ModifyWithKey<Table extends IndexedDbTable.AnyWithProps> = ModifyType<Table>
|
|
211
264
|
|
|
212
265
|
/**
|
|
213
|
-
*
|
|
266
|
+
* Query entry point for a table, exposing clear, select, count, delete, insert, and upsert operations.
|
|
267
|
+
*
|
|
214
268
|
* @category models
|
|
269
|
+
* @since 4.0.0
|
|
215
270
|
*/
|
|
216
271
|
export interface From<Table extends IndexedDbTable.AnyWithProps> {
|
|
217
272
|
readonly table: Table
|
|
@@ -228,6 +283,12 @@ export declare namespace IndexedDbQuery {
|
|
|
228
283
|
(): Select<Table, never>
|
|
229
284
|
}
|
|
230
285
|
|
|
286
|
+
/** @internal */
|
|
287
|
+
readonly selectCache: Map<
|
|
288
|
+
string | undefined,
|
|
289
|
+
IndexedDbQuery.Select<any, never>
|
|
290
|
+
>
|
|
291
|
+
|
|
231
292
|
readonly count: {
|
|
232
293
|
<Index extends IndexedDbDatabase.IndexFromTable<Table>>(
|
|
233
294
|
index: Index
|
|
@@ -235,6 +296,12 @@ export declare namespace IndexedDbQuery {
|
|
|
235
296
|
(): Count<Table, never>
|
|
236
297
|
}
|
|
237
298
|
|
|
299
|
+
/** @internal */
|
|
300
|
+
readonly countCache: Map<
|
|
301
|
+
string | undefined,
|
|
302
|
+
IndexedDbQuery.Count<any, never>
|
|
303
|
+
>
|
|
304
|
+
|
|
238
305
|
readonly delete: {
|
|
239
306
|
<Index extends IndexedDbDatabase.IndexFromTable<Table>>(
|
|
240
307
|
index: Index
|
|
@@ -242,6 +309,12 @@ export declare namespace IndexedDbQuery {
|
|
|
242
309
|
(): DeletePartial<Table, never>
|
|
243
310
|
}
|
|
244
311
|
|
|
312
|
+
/** @internal */
|
|
313
|
+
readonly deleteCache: Map<
|
|
314
|
+
string | undefined,
|
|
315
|
+
IndexedDbQuery.DeletePartial<any, never>
|
|
316
|
+
>
|
|
317
|
+
|
|
245
318
|
readonly insert: (value: ModifyWithKey<Table>) => Modify<Table>
|
|
246
319
|
readonly insertAll: (
|
|
247
320
|
values: Array<ModifyWithKey<Table>>
|
|
@@ -253,8 +326,10 @@ export declare namespace IndexedDbQuery {
|
|
|
253
326
|
}
|
|
254
327
|
|
|
255
328
|
/**
|
|
256
|
-
*
|
|
329
|
+
* Effect model for clearing all rows from a table.
|
|
330
|
+
*
|
|
257
331
|
* @category models
|
|
332
|
+
* @since 4.0.0
|
|
258
333
|
*/
|
|
259
334
|
export interface Clear<
|
|
260
335
|
Table extends IndexedDbTable.AnyWithProps
|
|
@@ -265,8 +340,10 @@ export declare namespace IndexedDbQuery {
|
|
|
265
340
|
type ComparisonKeys = "equals" | "gte" | "lte" | "gt" | "lt" | "between"
|
|
266
341
|
|
|
267
342
|
/**
|
|
268
|
-
*
|
|
343
|
+
* Effect model for counting table rows, optionally constrained by an index and key-range comparisons.
|
|
344
|
+
*
|
|
269
345
|
* @category models
|
|
346
|
+
* @since 4.0.0
|
|
270
347
|
*/
|
|
271
348
|
export interface Count<
|
|
272
349
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -308,8 +385,10 @@ export declare namespace IndexedDbQuery {
|
|
|
308
385
|
}
|
|
309
386
|
|
|
310
387
|
/**
|
|
311
|
-
*
|
|
388
|
+
* Intermediate delete builder used to choose a key range or limit before producing an executable delete query.
|
|
389
|
+
*
|
|
312
390
|
* @category models
|
|
391
|
+
* @since 4.0.0
|
|
313
392
|
*/
|
|
314
393
|
export interface DeletePartial<
|
|
315
394
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -356,8 +435,10 @@ export declare namespace IndexedDbQuery {
|
|
|
356
435
|
> = Omit<Delete<Table, Index, ExcludedKeys>, ExcludedKeys>
|
|
357
436
|
|
|
358
437
|
/**
|
|
359
|
-
*
|
|
438
|
+
* Effect model for deleting rows from a table, with optional key-range, limit, filter, and reactivity invalidation helpers.
|
|
439
|
+
*
|
|
360
440
|
* @category models
|
|
441
|
+
* @since 4.0.0
|
|
361
442
|
*/
|
|
362
443
|
export interface Delete<
|
|
363
444
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -399,8 +480,10 @@ export declare namespace IndexedDbQuery {
|
|
|
399
480
|
> = Omit<Select<Table, Index, ExcludedKeys>, ExcludedKeys>
|
|
400
481
|
|
|
401
482
|
/**
|
|
402
|
-
*
|
|
483
|
+
* Effect model for selecting rows from a table, with chainable range, paging, filtering, streaming, and reactive query helpers.
|
|
484
|
+
*
|
|
403
485
|
* @category models
|
|
486
|
+
* @since 4.0.0
|
|
404
487
|
*/
|
|
405
488
|
export interface Select<
|
|
406
489
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -502,8 +585,10 @@ export declare namespace IndexedDbQuery {
|
|
|
502
585
|
}
|
|
503
586
|
|
|
504
587
|
/**
|
|
505
|
-
*
|
|
588
|
+
* Effect model for selecting the first matching row, failing with `NoSuchElementError` when no row is found.
|
|
589
|
+
*
|
|
506
590
|
* @category models
|
|
591
|
+
* @since 4.0.0
|
|
507
592
|
*/
|
|
508
593
|
export interface First<
|
|
509
594
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -511,7 +596,7 @@ export declare namespace IndexedDbQuery {
|
|
|
511
596
|
> extends
|
|
512
597
|
Effect.Effect<
|
|
513
598
|
SelectType<Table>,
|
|
514
|
-
IndexedDbQueryError,
|
|
599
|
+
IndexedDbQueryError | Cause.NoSuchElementError,
|
|
515
600
|
IndexedDbTable.Context<Table>
|
|
516
601
|
>
|
|
517
602
|
{
|
|
@@ -526,7 +611,7 @@ export declare namespace IndexedDbQuery {
|
|
|
526
611
|
keys?: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
|
|
527
612
|
) => Stream.Stream<
|
|
528
613
|
SelectType<Table>,
|
|
529
|
-
IndexedDbQueryError,
|
|
614
|
+
IndexedDbQueryError | Cause.NoSuchElementError,
|
|
530
615
|
IndexedDbTable.Context<Table>
|
|
531
616
|
>
|
|
532
617
|
|
|
@@ -538,15 +623,17 @@ export declare namespace IndexedDbQuery {
|
|
|
538
623
|
readonly reactiveQueue: (
|
|
539
624
|
keys: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>>
|
|
540
625
|
) => Effect.Effect<
|
|
541
|
-
Queue.Dequeue<SelectType<Table>, IndexedDbQueryError>,
|
|
626
|
+
Queue.Dequeue<SelectType<Table>, IndexedDbQueryError | Cause.NoSuchElementError>,
|
|
542
627
|
never,
|
|
543
628
|
Scope.Scope | IndexedDbTable.Context<Table>
|
|
544
629
|
>
|
|
545
630
|
}
|
|
546
631
|
|
|
547
632
|
/**
|
|
548
|
-
*
|
|
633
|
+
* Effect model for a select query filtered by one or more predicates over encoded table rows.
|
|
634
|
+
*
|
|
549
635
|
* @category models
|
|
636
|
+
* @since 4.0.0
|
|
550
637
|
*/
|
|
551
638
|
export interface Filter<
|
|
552
639
|
Table extends IndexedDbTable.AnyWithProps,
|
|
@@ -566,8 +653,10 @@ export declare namespace IndexedDbQuery {
|
|
|
566
653
|
}
|
|
567
654
|
|
|
568
655
|
/**
|
|
569
|
-
*
|
|
656
|
+
* Effect model for inserting or upserting one row, returning the resulting IndexedDB key and supporting reactivity invalidation.
|
|
657
|
+
*
|
|
570
658
|
* @category models
|
|
659
|
+
* @since 4.0.0
|
|
571
660
|
*/
|
|
572
661
|
export interface Modify<
|
|
573
662
|
Table extends IndexedDbTable.AnyWithProps
|
|
@@ -593,8 +682,10 @@ export declare namespace IndexedDbQuery {
|
|
|
593
682
|
}
|
|
594
683
|
|
|
595
684
|
/**
|
|
596
|
-
*
|
|
685
|
+
* Effect model for inserting or upserting multiple rows, returning the resulting IndexedDB keys and supporting reactivity invalidation.
|
|
686
|
+
*
|
|
597
687
|
* @category models
|
|
688
|
+
* @since 4.0.0
|
|
598
689
|
*/
|
|
599
690
|
export interface ModifyAll<
|
|
600
691
|
Table extends IndexedDbTable.AnyWithProps
|
|
@@ -621,8 +712,10 @@ export declare namespace IndexedDbQuery {
|
|
|
621
712
|
}
|
|
622
713
|
|
|
623
714
|
/**
|
|
624
|
-
*
|
|
715
|
+
* Service tag for the active `IDBTransaction` used to share a transaction across IndexedDB query effects.
|
|
716
|
+
*
|
|
625
717
|
* @category models
|
|
718
|
+
* @since 4.0.0
|
|
626
719
|
*/
|
|
627
720
|
export class IndexedDbTransaction extends Context.Service<IndexedDbTransaction, globalThis.IDBTransaction>()(
|
|
628
721
|
"@effect/platform-browser/IndexedDbQueryBuilder/IndexedDbTransaction"
|
|
@@ -885,7 +978,7 @@ const applyFirst = Effect.fnUntraced(function*(
|
|
|
885
978
|
) {
|
|
886
979
|
const keyPath = query.select.from.table.keyPath
|
|
887
980
|
|
|
888
|
-
const data = yield* Effect.callback<any, IndexedDbQueryError>((resume) => {
|
|
981
|
+
const data = yield* Effect.callback<any, IndexedDbQueryError | Cause.NoSuchElementError>((resume) => {
|
|
889
982
|
const { keyRange, store } = getReadonlyObjectStore(query.select)
|
|
890
983
|
|
|
891
984
|
if (keyRange !== undefined) {
|
|
@@ -925,12 +1018,7 @@ const applyFirst = Effect.fnUntraced(function*(
|
|
|
925
1018
|
|
|
926
1019
|
if (value === undefined) {
|
|
927
1020
|
resume(
|
|
928
|
-
Effect.fail(
|
|
929
|
-
new IndexedDbQueryError({
|
|
930
|
-
reason: "NotFoundError",
|
|
931
|
-
cause: request.error
|
|
932
|
-
})
|
|
933
|
-
)
|
|
1021
|
+
Effect.fail(new Cause.NoSuchElementError(`No such element in table ${query.select.from.table.tableName}`))
|
|
934
1022
|
)
|
|
935
1023
|
} else {
|
|
936
1024
|
resume(
|
|
@@ -964,15 +1052,11 @@ const applyModify = Effect.fnUntraced(function*({
|
|
|
964
1052
|
const autoIncrement = query.from.table.autoIncrement as boolean
|
|
965
1053
|
const keyPath = query.from.table.keyPath
|
|
966
1054
|
const table = query.from.table
|
|
967
|
-
const schema = autoIncrement && value[keyPath] === undefined
|
|
1055
|
+
const schema: Schema.Top = autoIncrement && value[keyPath] === undefined
|
|
968
1056
|
? table.autoincrementSchema
|
|
969
1057
|
: table.tableSchema
|
|
970
1058
|
|
|
971
|
-
const encodedValue = yield*
|
|
972
|
-
autoIncrement && value[keyPath] === undefined
|
|
973
|
-
? table.autoincrementSchema
|
|
974
|
-
: table.tableSchema
|
|
975
|
-
)(value).pipe(
|
|
1059
|
+
const encodedValue = yield* schema.makeEffect(value).pipe(
|
|
976
1060
|
Effect.flatMap(Schema.encodeUnknownEffect(schema)),
|
|
977
1061
|
Effect.mapError(
|
|
978
1062
|
(error) =>
|
|
@@ -1229,34 +1313,52 @@ const FromProto: Omit<
|
|
|
1229
1313
|
| "IDBKeyRange"
|
|
1230
1314
|
| "transaction"
|
|
1231
1315
|
| "reactivity"
|
|
1316
|
+
| "selectCache"
|
|
1317
|
+
| "countCache"
|
|
1318
|
+
| "deleteCache"
|
|
1232
1319
|
> = {
|
|
1233
1320
|
...CommonProto,
|
|
1234
1321
|
select<Index extends IndexedDbDatabase.IndexFromTable<any>>(
|
|
1235
1322
|
this: IndexedDbQuery.From<any>,
|
|
1236
1323
|
index?: Index
|
|
1237
1324
|
) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1325
|
+
let select = this.selectCache.get(index)
|
|
1326
|
+
if (select === undefined) {
|
|
1327
|
+
select = makeSelect({
|
|
1328
|
+
from: this,
|
|
1329
|
+
index
|
|
1330
|
+
})
|
|
1331
|
+
this.selectCache.set(index, select)
|
|
1332
|
+
}
|
|
1333
|
+
return select
|
|
1242
1334
|
},
|
|
1243
1335
|
count<Index extends IndexedDbDatabase.IndexFromTable<any>>(
|
|
1244
1336
|
this: IndexedDbQuery.From<any>,
|
|
1245
1337
|
index?: Index
|
|
1246
1338
|
) {
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1339
|
+
let count = this.countCache.get(index)
|
|
1340
|
+
if (count === undefined) {
|
|
1341
|
+
count = makeCount({
|
|
1342
|
+
from: this,
|
|
1343
|
+
index
|
|
1344
|
+
})
|
|
1345
|
+
this.countCache.set(index, count)
|
|
1346
|
+
}
|
|
1347
|
+
return count
|
|
1251
1348
|
},
|
|
1252
1349
|
delete<Index extends IndexedDbDatabase.IndexFromTable<any>>(
|
|
1253
1350
|
this: IndexedDbQuery.From<any>,
|
|
1254
1351
|
index?: Index
|
|
1255
1352
|
) {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1353
|
+
let cached = this.deleteCache.get(index)
|
|
1354
|
+
if (cached === undefined) {
|
|
1355
|
+
cached = makeDeletePartial({
|
|
1356
|
+
from: this,
|
|
1357
|
+
index
|
|
1358
|
+
})
|
|
1359
|
+
this.deleteCache.set(index, cached)
|
|
1360
|
+
}
|
|
1361
|
+
return cached
|
|
1260
1362
|
},
|
|
1261
1363
|
insert(this: IndexedDbQuery.From<any>, value: any) {
|
|
1262
1364
|
return makeModify({ from: this, value, operation: "add" })
|
|
@@ -1292,6 +1394,9 @@ const makeFrom = <
|
|
|
1292
1394
|
self.database = options.database
|
|
1293
1395
|
self.IDBKeyRange = options.IDBKeyRange
|
|
1294
1396
|
self.reactivity = options.reactivity
|
|
1397
|
+
self.selectCache = new Map()
|
|
1398
|
+
self.countCache = new Map()
|
|
1399
|
+
self.deleteCache = new Map()
|
|
1295
1400
|
return self
|
|
1296
1401
|
}
|
|
1297
1402
|
|
|
@@ -1825,6 +1930,7 @@ const makeModifyAll = <
|
|
|
1825
1930
|
|
|
1826
1931
|
const QueryBuilderProto: Omit<
|
|
1827
1932
|
IndexedDbQueryBuilder<any>,
|
|
1933
|
+
| "fromCache"
|
|
1828
1934
|
| "tables"
|
|
1829
1935
|
| "database"
|
|
1830
1936
|
| "IDBKeyRange"
|
|
@@ -1843,12 +1949,17 @@ const QueryBuilderProto: Omit<
|
|
|
1843
1949
|
})
|
|
1844
1950
|
},
|
|
1845
1951
|
from(this: IndexedDbQueryBuilder<any>, table: any) {
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1952
|
+
let cached = this.fromCache.get(table)
|
|
1953
|
+
if (cached === undefined) {
|
|
1954
|
+
cached = makeFrom({
|
|
1955
|
+
database: this.database,
|
|
1956
|
+
IDBKeyRange: this.IDBKeyRange,
|
|
1957
|
+
table: this.tables.get(table)!,
|
|
1958
|
+
reactivity: this.reactivity
|
|
1959
|
+
})
|
|
1960
|
+
this.fromCache.set(table, cached)
|
|
1961
|
+
}
|
|
1962
|
+
return cached as any
|
|
1852
1963
|
},
|
|
1853
1964
|
get clearAll() {
|
|
1854
1965
|
const self = this as IndexedDbQueryBuilder<any>
|
|
@@ -1871,8 +1982,10 @@ const QueryBuilderProto: Omit<
|
|
|
1871
1982
|
}
|
|
1872
1983
|
|
|
1873
1984
|
/**
|
|
1874
|
-
*
|
|
1985
|
+
* Creates an `IndexedDbQueryBuilder` from an open database reference, key-range constructor, table map, and reactivity service.
|
|
1986
|
+
*
|
|
1875
1987
|
* @category constructors
|
|
1988
|
+
* @since 4.0.0
|
|
1876
1989
|
*/
|
|
1877
1990
|
export const make = <Source extends IndexedDbVersion.AnyWithProps>({
|
|
1878
1991
|
IDBKeyRange,
|
|
@@ -1890,6 +2003,7 @@ export const make = <Source extends IndexedDbVersion.AnyWithProps>({
|
|
|
1890
2003
|
self.database = database
|
|
1891
2004
|
self.reactivity = reactivity
|
|
1892
2005
|
self.IDBKeyRange = IDBKeyRange
|
|
2006
|
+
self.fromCache = new Map()
|
|
1893
2007
|
return self
|
|
1894
2008
|
}
|
|
1895
2009
|
|