@effect/platform-browser 4.0.0-beta.66 → 4.0.0-beta.68
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/BrowserCrypto.d.ts +23 -0
- package/dist/BrowserCrypto.d.ts.map +1 -0
- package/dist/BrowserCrypto.js +61 -0
- package/dist/BrowserCrypto.js.map +1 -0
- package/dist/BrowserHttpClient.d.ts +23 -13
- package/dist/BrowserHttpClient.d.ts.map +1 -1
- package/dist/BrowserHttpClient.js +49 -12
- package/dist/BrowserHttpClient.js.map +1 -1
- package/dist/BrowserKeyValueStore.d.ts +15 -8
- package/dist/BrowserKeyValueStore.d.ts.map +1 -1
- package/dist/BrowserKeyValueStore.js +128 -4
- 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 +31 -6
- package/dist/BrowserSocket.d.ts.map +1 -1
- package/dist/BrowserSocket.js +31 -6
- 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 +8 -4
- package/dist/BrowserWorker.d.ts.map +1 -1
- package/dist/BrowserWorker.js +29 -5
- package/dist/BrowserWorker.js.map +1 -1
- package/dist/BrowserWorkerRunner.d.ts +12 -6
- package/dist/BrowserWorkerRunner.d.ts.map +1 -1
- package/dist/BrowserWorkerRunner.js +31 -7
- package/dist/BrowserWorkerRunner.js.map +1 -1
- package/dist/Clipboard.d.ts +35 -11
- package/dist/Clipboard.d.ts.map +1 -1
- package/dist/Clipboard.js +31 -9
- package/dist/Clipboard.js.map +1 -1
- package/dist/Geolocation.d.ts +52 -18
- package/dist/Geolocation.d.ts.map +1 -1
- package/dist/Geolocation.js +44 -14
- 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 +102 -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 +38 -11
- package/dist/Permissions.d.ts.map +1 -1
- package/dist/Permissions.js +33 -8
- package/dist/Permissions.js.map +1 -1
- package/dist/index.d.ts +334 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +334 -11
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/BrowserCrypto.ts +71 -0
- package/src/BrowserHttpClient.ts +53 -14
- package/src/BrowserKeyValueStore.ts +144 -6
- package/src/BrowserPersistence.ts +19 -3
- package/src/BrowserRuntime.ts +31 -4
- package/src/BrowserSocket.ts +31 -6
- package/src/BrowserStream.ts +25 -3
- package/src/BrowserWorker.ts +29 -5
- package/src/BrowserWorkerRunner.ts +31 -7
- package/src/Clipboard.ts +35 -11
- package/src/Geolocation.ts +52 -18
- package/src/IndexedDb.ts +39 -21
- package/src/IndexedDbDatabase.ts +57 -10
- package/src/IndexedDbQueryBuilder.ts +171 -58
- package/src/IndexedDbTable.ts +57 -13
- package/src/IndexedDbVersion.ts +37 -7
- package/src/Permissions.ts +38 -11
- package/src/index.ts +335 -11
|
@@ -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";
|
|
@@ -12,22 +37,28 @@ import type * as IndexedDbTable from "./IndexedDbTable.ts";
|
|
|
12
37
|
import type * as IndexedDbVersion from "./IndexedDbVersion.ts";
|
|
13
38
|
declare const ErrorTypeId = "~@effect/platform-browser/IndexedDbDatabase/IndexedDbDatabaseError";
|
|
14
39
|
/**
|
|
15
|
-
*
|
|
40
|
+
* String union describing the failure categories for IndexedDB database opening, migration, and schema operations.
|
|
41
|
+
*
|
|
16
42
|
* @category errors
|
|
43
|
+
* @since 4.0.0
|
|
17
44
|
*/
|
|
18
45
|
export type ErrorReason = "TransactionError" | "MissingTable" | "OpenError" | "UpgradeError" | "Aborted" | "Blocked" | "MissingIndex";
|
|
19
46
|
declare const IndexedDbDatabaseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
20
47
|
readonly _tag: "IndexedDbDatabaseError";
|
|
21
48
|
} & Readonly<A>;
|
|
22
49
|
/**
|
|
23
|
-
*
|
|
50
|
+
* Tagged error for IndexedDB database operations, carrying a database error reason and the original cause.
|
|
51
|
+
*
|
|
24
52
|
* @category errors
|
|
53
|
+
* @since 4.0.0
|
|
25
54
|
*/
|
|
26
55
|
export declare class IndexedDbDatabaseError extends IndexedDbDatabaseError_base<{
|
|
27
56
|
reason: ErrorReason;
|
|
28
57
|
cause: unknown;
|
|
29
58
|
}> {
|
|
30
59
|
/**
|
|
60
|
+
* Marks this value as an IndexedDB database error for runtime guards.
|
|
61
|
+
*
|
|
31
62
|
* @since 4.0.0
|
|
32
63
|
*/
|
|
33
64
|
readonly [ErrorTypeId]: typeof ErrorTypeId;
|
|
@@ -40,14 +71,18 @@ declare const IndexedDbDatabase_base: Context.ServiceClass<IndexedDbDatabase, "~
|
|
|
40
71
|
readonly rebuild: Effect.Effect<void, IndexedDbDatabaseError>;
|
|
41
72
|
}>;
|
|
42
73
|
/**
|
|
43
|
-
*
|
|
74
|
+
* Service tag for an open IndexedDB database, its `IDBKeyRange` constructor, reactivity service, and rebuild effect.
|
|
75
|
+
*
|
|
44
76
|
* @category models
|
|
77
|
+
* @since 4.0.0
|
|
45
78
|
*/
|
|
46
79
|
export declare class IndexedDbDatabase extends IndexedDbDatabase_base {
|
|
47
80
|
}
|
|
48
81
|
/**
|
|
49
|
-
*
|
|
82
|
+
* Describes an IndexedDB schema version and its migrations, and acts as an effect that yields a query builder for the target version.
|
|
83
|
+
*
|
|
50
84
|
* @category models
|
|
85
|
+
* @since 4.0.0
|
|
51
86
|
*/
|
|
52
87
|
export interface IndexedDbSchema<in out FromVersion extends IndexedDbVersion.AnyWithProps, in out ToVersion extends IndexedDbVersion.AnyWithProps, out Error = never> extends Effect.Effect<IndexedDbQueryBuilder.IndexedDbQueryBuilder<ToVersion>, never, IndexedDbDatabase> {
|
|
53
88
|
new (_: never): {};
|
|
@@ -60,8 +95,10 @@ export interface IndexedDbSchema<in out FromVersion extends IndexedDbVersion.Any
|
|
|
60
95
|
readonly layer: (databaseName: string) => Layer.Layer<IndexedDbDatabase, IndexedDbDatabaseError, IndexedDb.IndexedDb>;
|
|
61
96
|
}
|
|
62
97
|
/**
|
|
63
|
-
*
|
|
98
|
+
* Query builder available during a database migration, extended with object-store and index management helpers for the active `IDBTransaction`.
|
|
99
|
+
*
|
|
64
100
|
* @category models
|
|
101
|
+
* @since 4.0.0
|
|
65
102
|
*/
|
|
66
103
|
export interface Transaction<Source extends IndexedDbVersion.AnyWithProps = never> extends Omit<IndexedDbQueryBuilder.IndexedDbQueryBuilder<Source>, "transaction"> {
|
|
67
104
|
readonly transaction: globalThis.IDBTransaction;
|
|
@@ -71,31 +108,41 @@ export interface Transaction<Source extends IndexedDbVersion.AnyWithProps = neve
|
|
|
71
108
|
readonly deleteIndex: <Name extends IndexedDbTable.TableName<IndexedDbVersion.Tables<Source>>>(table: Name, indexName: IndexFromTableName<Source, Name>) => Effect.Effect<void, IndexedDbDatabaseError>;
|
|
72
109
|
}
|
|
73
110
|
/**
|
|
74
|
-
*
|
|
111
|
+
* Extracts the string-literal index names defined by an `IndexedDbTable`.
|
|
112
|
+
*
|
|
75
113
|
* @category models
|
|
114
|
+
* @since 4.0.0
|
|
76
115
|
*/
|
|
77
116
|
export type IndexFromTable<Table extends IndexedDbTable.AnyWithProps> = IsStringLiteral<Extract<keyof IndexedDbTable.Indexes<Table>, string>> extends true ? Extract<keyof IndexedDbTable.Indexes<Table>, string> : never;
|
|
78
117
|
/**
|
|
79
|
-
*
|
|
118
|
+
* Extracts the valid index names for a table name within an IndexedDB version.
|
|
119
|
+
*
|
|
80
120
|
* @category models
|
|
121
|
+
* @since 4.0.0
|
|
81
122
|
*/
|
|
82
123
|
export type IndexFromTableName<Version extends IndexedDbVersion.AnyWithProps, Table extends string> = IndexFromTable<IndexedDbTable.WithName<IndexedDbVersion.Tables<Version>, Table>>;
|
|
83
124
|
/**
|
|
84
|
-
*
|
|
125
|
+
* Type-erased IndexedDB schema shape used when traversing schema migration chains.
|
|
126
|
+
*
|
|
85
127
|
* @category models
|
|
128
|
+
* @since 4.0.0
|
|
86
129
|
*/
|
|
87
130
|
export interface Any {
|
|
88
131
|
readonly previous?: Any | undefined;
|
|
89
132
|
readonly layer: (databaseName: string) => Layer.Layer<IndexedDbDatabase, IndexedDbDatabaseError, IndexedDb.IndexedDb>;
|
|
90
133
|
}
|
|
91
134
|
/**
|
|
92
|
-
*
|
|
135
|
+
* Type-erased `IndexedDbSchema` covering any source version, target version, and migration error type.
|
|
136
|
+
*
|
|
93
137
|
* @category models
|
|
138
|
+
* @since 4.0.0
|
|
94
139
|
*/
|
|
95
140
|
export type AnySchema = IndexedDbSchema<IndexedDbVersion.AnyWithProps, IndexedDbVersion.AnyWithProps, any>;
|
|
96
141
|
/**
|
|
97
|
-
*
|
|
142
|
+
* Creates the initial `IndexedDbSchema` from a version and an initialization migration run during database upgrade.
|
|
143
|
+
*
|
|
98
144
|
* @category constructors
|
|
145
|
+
* @since 4.0.0
|
|
99
146
|
*/
|
|
100
147
|
export declare const make: <InitialVersion extends IndexedDbVersion.AnyWithProps, Error>(initialVersion: InitialVersion, init: (toQuery: Transaction<InitialVersion>) => Effect.Effect<void, Error>) => IndexedDbSchema<never, InitialVersion, Error>;
|
|
101
148
|
type IsStringLiteral<T> = T extends string ? string extends T ? false : true : false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDbDatabase.d.ts","sourceRoot":"","sources":["../src/IndexedDbDatabase.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"IndexedDbDatabase.d.ts","sourceRoot":"","sources":["../src/IndexedDbDatabase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA;AACnE,OAAO,KAAK,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AAG9D,QAAA,MAAM,WAAW,uEAAuE,CAAA;AA2CxF;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB,kBAAkB,GAClB,cAAc,GACd,WAAW,GACX,cAAc,GACd,SAAS,GACT,SAAS,GACT,cAAc,CAAA;;;;AAElB;;;;;GAKG;AACH,qBAAa,sBAAuB,SAAQ,4BAE1C;IACA,MAAM,EAAE,WAAW,CAAA;IACnB,KAAK,EAAE,OAAO,CAAA;CACf,CAAC;IACA;;;;OAIG;IACH,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,WAAW,CAAc;IACxD,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AE,MAAM,KACjB,KAAK,CAAC,KAAK,CACd,iBAAiB,EACjB,sBAAsB,EACtB,SAAS,CAAC,SAAS,CACpB,CAAA;CACF;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,eAAe,CACrC,gBAAgB,CAAC,YAAY,EAC7B,gBAAgB,CAAC,YAAY,EAC7B,GAAG,CACJ,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GACf,cAAc,SAAS,gBAAgB,CAAC,YAAY,EACpD,KAAK,EAEL,gBAAgB,cAAc,EAC9B,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,cAAc,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,KACzE,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,CAO9C,CAAA;AAqOD,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,KAAK,GACjE,IAAI,GACJ,KAAK,CAAA"}
|
|
@@ -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";
|
|
@@ -50,24 +75,32 @@ const SchemaProto = {
|
|
|
50
75
|
}
|
|
51
76
|
};
|
|
52
77
|
/**
|
|
53
|
-
*
|
|
78
|
+
* Tagged error for IndexedDB database operations, carrying a database error reason and the original cause.
|
|
79
|
+
*
|
|
54
80
|
* @category errors
|
|
81
|
+
* @since 4.0.0
|
|
55
82
|
*/
|
|
56
83
|
export class IndexedDbDatabaseError extends /*#__PURE__*/Data.TaggedError("IndexedDbDatabaseError") {
|
|
57
84
|
/**
|
|
85
|
+
* Marks this value as an IndexedDB database error for runtime guards.
|
|
86
|
+
*
|
|
58
87
|
* @since 4.0.0
|
|
59
88
|
*/
|
|
60
89
|
[ErrorTypeId] = ErrorTypeId;
|
|
61
90
|
message = this.reason;
|
|
62
91
|
}
|
|
63
92
|
/**
|
|
64
|
-
*
|
|
93
|
+
* Service tag for an open IndexedDB database, its `IDBKeyRange` constructor, reactivity service, and rebuild effect.
|
|
94
|
+
*
|
|
65
95
|
* @category models
|
|
96
|
+
* @since 4.0.0
|
|
66
97
|
*/
|
|
67
98
|
export class IndexedDbDatabase extends /*#__PURE__*/Context.Service()(TypeId) {}
|
|
68
99
|
/**
|
|
69
|
-
*
|
|
100
|
+
* Creates the initial `IndexedDbSchema` from a version and an initialization migration run during database upgrade.
|
|
101
|
+
*
|
|
70
102
|
* @category constructors
|
|
103
|
+
* @since 4.0.0
|
|
71
104
|
*/
|
|
72
105
|
export const make = (initialVersion, init) => {
|
|
73
106
|
// oxlint-disable-next-line typescript/no-extraneous-class
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDbDatabase.js","names":["Context","Data","Effect","Effectable","Fiber","Layer","MutableRef","Semaphore","Reactivity","IndexedDb","IndexedDbQueryBuilder","TypeId","ErrorTypeId","SchemaProto","_A","_","Prototype","label","evaluate","getQueryBuilder","self","IndexedDbDatabase","useSync","database","IDBKeyRange","reactivity","make","tables","version","add","migrate","makeMigration","fromVersion","previous","layer","databaseName","IndexedDbDatabaseError","TaggedError","message","reason","Service","initialVersion","init","Initial","Object","setPrototypeOf","options","Migration","migration","effect","gen","indexedDB","context","runForkWith","oldVersion","migrations","current","unshift","length","open","callback","resume","request","onblocked","event","fail","cause","onerror","idbRequest","target","error","fiber","onupgradeneeded","db","result","transaction","set","onabort","forEach","slice","untypedMigration","undefined","api","makeTransactionProto","fromApi","toApi","die","Error","discard","pipe","mapError","provideService","IndexedDbTransaction","currentDispatcher","flush","onsuccess","asVoid","join","void","addFinalizer","close","rebuildLock","makeUnsafe","withPermit","rebuild","deleteDatabase","flatMap","of","provide","createObjectStore","fnUntraced","table","createTable","fromNullishOr","get","try","tableName","keyPath","autoIncrement","catch","deleteObjectStore","createIndex","indexName","store","objectStore","sourceTable","indexes","deleteIndex"],"sources":["../src/IndexedDbDatabase.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAA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AAK,GAAGhD,WAAW,CAACiD,WAAW,CAACb,KAAK,CAAC;IAC5C,MAAMc,WAAW,GAAGlG,MAAM,CAACuF,GAAG,CAACH,KAAK,CAAE;IAEtC,MAAMM,OAAO,GAAG,OAAOnH,MAAM,CAAC+G,aAAa,CACzCY,WAAW,CAACC,OAAO,CAACJ,SAAS,CAAC,CAC/B,CAACjC,IAAI,CACJvF,MAAM,CAACwF,QAAQ,CACZxB,KAAK,IACJ,IAAI9B,sBAAsB,CAAC;MACzBG,MAAM,EAAE,cAAc;MACtB2B;KACD,CAAC,CACL,CACF;IAED,OAAO,OAAOhE,MAAM,CAACiH,GAAG,CAAC;MACvBA,GAAG,EAAEA,CAAA,KAAMQ,KAAK,CAACF,WAAW,CAACC,SAAS,EAAEL,OAAO,EAAEvE,OAAO,CAAC;MACzDyE,KAAK,EAAGrD,KAAK,IACX,IAAI9B,sBAAsB,CAAC;QACzBG,MAAM,EAAE,kBAAkB;QAC1B2B;OACD;KACJ,CAAC;EACJ,CAAC,CAAC;EAEFlB,SAAS,CAAC+E,WAAW,GAAG,CAAChB,KAAa,EAAEW,SAAiB,KACvDxH,MAAM,CAACiH,GAAG,CAAC;IACTA,GAAG,EAAEA,CAAA,KAAMxC,WAAW,CAACiD,WAAW,CAACb,KAAK,CAAC,CAACgB,WAAW,CAACL,SAAS,CAAC;IAChEH,KAAK,EAAGrD,KAAK,IACX,IAAI9B,sBAAsB,CAAC;MACzBG,MAAM,EAAE,kBAAkB;MAC1B2B;KACD;GACJ,CAAC;EAEJ,OAAOlB,SAAS;AAClB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"IndexedDbDatabase.js","names":["Context","Data","Effect","Effectable","Fiber","Layer","MutableRef","Semaphore","Reactivity","IndexedDb","IndexedDbQueryBuilder","TypeId","ErrorTypeId","SchemaProto","_A","_","Prototype","label","evaluate","getQueryBuilder","self","IndexedDbDatabase","useSync","database","IDBKeyRange","reactivity","make","tables","version","add","migrate","makeMigration","fromVersion","previous","layer","databaseName","IndexedDbDatabaseError","TaggedError","message","reason","Service","initialVersion","init","Initial","Object","setPrototypeOf","options","Migration","migration","effect","gen","indexedDB","context","runForkWith","oldVersion","migrations","current","unshift","length","open","callback","resume","request","onblocked","event","fail","cause","onerror","idbRequest","target","error","fiber","onupgradeneeded","db","result","transaction","set","onabort","forEach","slice","untypedMigration","undefined","api","makeTransactionProto","fromApi","toApi","die","Error","discard","pipe","mapError","provideService","IndexedDbTransaction","currentDispatcher","flush","onsuccess","asVoid","join","void","addFinalizer","close","rebuildLock","makeUnsafe","withPermit","rebuild","deleteDatabase","flatMap","of","provide","createObjectStore","fnUntraced","table","createTable","fromNullishOr","get","try","tableName","keyPath","autoIncrement","catch","deleteObjectStore","createIndex","indexName","store","objectStore","sourceTable","indexes","deleteIndex"],"sources":["../src/IndexedDbDatabase.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,SAAS,MAAM,kBAAkB;AAC7C,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAC3C,OAAO,KAAKC,qBAAqB,MAAM,4BAA4B;AAInE,MAAMC,MAAM,GAAG,6CAA6C;AAC5D,MAAMC,WAAW,GAAG,oEAAoE;AAExF,MAAMC,WAAW,GAAG;EAClB,CAACF,MAAM,GAAG;IACRG,EAAE,EAAGC,CAAQ,IAAKA;GACnB;EACD,iBAAGZ,UAAU,CAACa,SAAS,CAAiC;IACtDC,KAAK,E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ACzBG,MAAM,EAAE,cAAc;MACtB2B;KACD,CAAC,CACL,CACF;IAED,OAAO,OAAOhE,MAAM,CAACiH,GAAG,CAAC;MACvBA,GAAG,EAAEA,CAAA,KAAMQ,KAAK,CAACF,WAAW,CAACC,SAAS,EAAEL,OAAO,EAAEvE,OAAO,CAAC;MACzDyE,KAAK,EAAGrD,KAAK,IACX,IAAI9B,sBAAsB,CAAC;QACzBG,MAAM,EAAE,kBAAkB;QAC1B2B;OACD;KACJ,CAAC;EACJ,CAAC,CAAC;EAEFlB,SAAS,CAAC+E,WAAW,GAAG,CAAChB,KAAa,EAAEW,SAAiB,KACvDxH,MAAM,CAACiH,GAAG,CAAC;IACTA,GAAG,EAAEA,CAAA,KAAMxC,WAAW,CAACiD,WAAW,CAACb,KAAK,CAAC,CAACgB,WAAW,CAACL,SAAS,CAAC;IAChEH,KAAK,EAAGrD,KAAK,IACX,IAAI9B,sBAAsB,CAAC;MACzBG,MAAM,EAAE,kBAAkB;MAC1B2B;KACD;GACJ,CAAC;EAEJ,OAAOlB,SAAS;AAClB,CAAC","ignoreList":[]}
|
|
@@ -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 Effect from "effect/Effect";
|
|
7
34
|
import type { Inspectable } from "effect/Inspectable";
|
|
@@ -19,30 +46,38 @@ import type * as IndexedDbTable from "./IndexedDbTable.ts";
|
|
|
19
46
|
import type * as IndexedDbVersion from "./IndexedDbVersion.ts";
|
|
20
47
|
declare const ErrorTypeId = "~@effect/platform-browser/IndexedDbQueryBuilder/IndexedDbQueryError";
|
|
21
48
|
/**
|
|
22
|
-
*
|
|
49
|
+
* String union describing IndexedDB query failure categories such as decoding, encoding, and transaction errors.
|
|
50
|
+
*
|
|
23
51
|
* @category errors
|
|
52
|
+
* @since 4.0.0
|
|
24
53
|
*/
|
|
25
|
-
export type ErrorReason = "
|
|
26
|
-
declare const IndexedDbQueryError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) =>
|
|
54
|
+
export type ErrorReason = "UnknownError" | "DecodeError" | "EncodeError" | "TransactionError";
|
|
55
|
+
declare const IndexedDbQueryError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
27
56
|
readonly _tag: "IndexedDbQueryError";
|
|
28
57
|
} & Readonly<A>;
|
|
29
58
|
/**
|
|
30
|
-
*
|
|
59
|
+
* Tagged error for IndexedDB query operations, carrying a query error reason and the original cause.
|
|
60
|
+
*
|
|
31
61
|
* @category errors
|
|
62
|
+
* @since 4.0.0
|
|
32
63
|
*/
|
|
33
64
|
export declare class IndexedDbQueryError extends IndexedDbQueryError_base<{
|
|
34
65
|
reason: ErrorReason;
|
|
35
66
|
cause: unknown;
|
|
36
67
|
}> {
|
|
37
68
|
/**
|
|
69
|
+
* Marks this value as an IndexedDB query builder error for runtime guards.
|
|
70
|
+
*
|
|
38
71
|
* @since 4.0.0
|
|
39
72
|
*/
|
|
40
73
|
readonly [ErrorTypeId]: typeof ErrorTypeId;
|
|
41
74
|
readonly message: ErrorReason;
|
|
42
75
|
}
|
|
43
76
|
/**
|
|
44
|
-
*
|
|
77
|
+
* Typed query builder for an IndexedDB version, with helpers for table queries, database access, clearing data, and running effects in a shared transaction.
|
|
78
|
+
*
|
|
45
79
|
* @category models
|
|
80
|
+
* @since 4.0.0
|
|
46
81
|
*/
|
|
47
82
|
export interface IndexedDbQueryBuilder<Source extends IndexedDbVersion.AnyWithProps> extends Pipeable.Pipeable, Inspectable {
|
|
48
83
|
readonly tables: ReadonlyMap<string, IndexedDbVersion.Tables<Source>>;
|
|
@@ -60,30 +95,39 @@ export interface IndexedDbQueryBuilder<Source extends IndexedDbVersion.AnyWithPr
|
|
|
60
95
|
}) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, IndexedDbTransaction>>;
|
|
61
96
|
}
|
|
62
97
|
/**
|
|
63
|
-
*
|
|
98
|
+
* Valid key-path type for a table schema, using encoded fields whose values are IndexedDB-valid keys.
|
|
99
|
+
*
|
|
64
100
|
* @category models
|
|
101
|
+
* @since 4.0.0
|
|
65
102
|
*/
|
|
66
103
|
export type KeyPath<TableSchema extends IndexedDbTable.AnySchemaStruct> = IndexedDbValidKeys<TableSchema> | NonEmptyReadonlyArray<IndexedDbValidKeys<TableSchema>>;
|
|
67
104
|
/**
|
|
68
|
-
*
|
|
105
|
+
* Valid numeric key-path type for a table schema, used for auto-increment key paths.
|
|
106
|
+
*
|
|
69
107
|
* @category models
|
|
108
|
+
* @since 4.0.0
|
|
70
109
|
*/
|
|
71
110
|
export type KeyPathNumber<TableSchema extends IndexedDbTable.AnySchemaStruct> = IndexedDbValidNumberKeys<TableSchema> | NonEmptyReadonlyArray<IndexedDbValidNumberKeys<TableSchema>>;
|
|
72
111
|
/**
|
|
112
|
+
* Namespace containing the typed IndexedDB query model interfaces and helper types.
|
|
113
|
+
*
|
|
73
114
|
* @since 4.0.0
|
|
74
|
-
* @category models
|
|
75
115
|
*/
|
|
76
116
|
export declare namespace IndexedDbQuery {
|
|
77
117
|
/**
|
|
78
|
-
*
|
|
118
|
+
* Decoded row type returned by select queries, adding a `key` field when the table does not define a key path.
|
|
119
|
+
*
|
|
79
120
|
* @category models
|
|
121
|
+
* @since 4.0.0
|
|
80
122
|
*/
|
|
81
123
|
type SelectType<Table extends IndexedDbTable.AnyWithProps> = [IndexedDbTable.KeyPath<Table>] extends [undefined] ? IndexedDbTable.TableSchema<Table>["Type"] & {
|
|
82
124
|
readonly key: (typeof IndexedDb.IDBValidKey)["Type"];
|
|
83
125
|
} : IndexedDbTable.TableSchema<Table>["Type"];
|
|
84
126
|
/**
|
|
85
|
-
*
|
|
127
|
+
* Input type for insert and upsert operations, adjusted for auto-increment keys and out-of-line keys.
|
|
128
|
+
*
|
|
86
129
|
* @category models
|
|
130
|
+
* @since 4.0.0
|
|
87
131
|
*/
|
|
88
132
|
type ModifyType<Table extends IndexedDbTable.AnyWithProps> = (IndexedDbTable.AutoIncrement<Table> extends true ? {
|
|
89
133
|
[key in keyof Schema.Struct.MakeIn<Omit<IndexedDbTable.TableSchema<Table>["fields"], IndexedDbTable.KeyPath<Table>>>]: key extends keyof Schema.Struct.MakeIn<IndexedDbTable.TableSchema<Table>["fields"]> ? Schema.Struct.MakeIn<IndexedDbTable.TableSchema<Table>["fields"]>[key] : never;
|
|
@@ -93,15 +137,19 @@ export declare namespace IndexedDbQuery {
|
|
|
93
137
|
key: IDBValidKey;
|
|
94
138
|
} : {});
|
|
95
139
|
/**
|
|
96
|
-
*
|
|
140
|
+
* Value type accepted by `equals` comparisons for a table key path or index.
|
|
141
|
+
*
|
|
97
142
|
* @category models
|
|
143
|
+
* @since 4.0.0
|
|
98
144
|
*/
|
|
99
145
|
type EqualsType<Table extends IndexedDbTable.AnyWithProps, Index extends keyof Table["indexes"], KeyPath = [Index] extends [never] ? Table["keyPath"] : Table["indexes"][Index], Type = Table["tableSchema"]["Encoded"]> = KeyPath extends keyof Type ? Type[KeyPath] : {
|
|
100
146
|
[I in keyof KeyPath]: KeyPath[I] extends keyof Type ? Type[KeyPath[I]] | [] : never;
|
|
101
147
|
};
|
|
102
148
|
/**
|
|
103
|
-
*
|
|
149
|
+
* Value type accepted by range comparisons for a table key path or index, including partial tuples for compound indexes.
|
|
150
|
+
*
|
|
104
151
|
* @category models
|
|
152
|
+
* @since 4.0.0
|
|
105
153
|
*/
|
|
106
154
|
type ExtractIndexType<Table extends IndexedDbTable.AnyWithProps, Index extends keyof Table["indexes"], KeyPath = [Index] extends [never] ? Table["keyPath"] : Table["indexes"][Index], Type = Table["tableSchema"]["Encoded"]> = KeyPath extends keyof Type ? Type[KeyPath] : KeyPath extends readonly [infer K, ...infer Rest] ? K extends keyof Type ? [
|
|
107
155
|
Type[K],
|
|
@@ -110,13 +158,17 @@ export declare namespace IndexedDbQuery {
|
|
|
110
158
|
}
|
|
111
159
|
] : never : never;
|
|
112
160
|
/**
|
|
113
|
-
*
|
|
161
|
+
* Mutation input type for insert and upsert operations, including any required key fields.
|
|
162
|
+
*
|
|
114
163
|
* @category models
|
|
164
|
+
* @since 4.0.0
|
|
115
165
|
*/
|
|
116
166
|
type ModifyWithKey<Table extends IndexedDbTable.AnyWithProps> = ModifyType<Table>;
|
|
117
167
|
/**
|
|
118
|
-
*
|
|
168
|
+
* Query entry point for a table, exposing clear, select, count, delete, insert, and upsert operations.
|
|
169
|
+
*
|
|
119
170
|
* @category models
|
|
171
|
+
* @since 4.0.0
|
|
120
172
|
*/
|
|
121
173
|
interface From<Table extends IndexedDbTable.AnyWithProps> {
|
|
122
174
|
readonly table: Table;
|
|
@@ -142,16 +194,20 @@ export declare namespace IndexedDbQuery {
|
|
|
142
194
|
readonly upsertAll: (values: Array<ModifyWithKey<Table>>) => ModifyAll<Table>;
|
|
143
195
|
}
|
|
144
196
|
/**
|
|
145
|
-
*
|
|
197
|
+
* Effect model for clearing all rows from a table.
|
|
198
|
+
*
|
|
146
199
|
* @category models
|
|
200
|
+
* @since 4.0.0
|
|
147
201
|
*/
|
|
148
202
|
interface Clear<Table extends IndexedDbTable.AnyWithProps> extends Effect.Effect<void, IndexedDbQueryError> {
|
|
149
203
|
readonly from: From<Table>;
|
|
150
204
|
}
|
|
151
205
|
type ComparisonKeys = "equals" | "gte" | "lte" | "gt" | "lt" | "between";
|
|
152
206
|
/**
|
|
153
|
-
*
|
|
207
|
+
* Effect model for counting table rows, optionally constrained by an index and key-range comparisons.
|
|
208
|
+
*
|
|
154
209
|
* @category models
|
|
210
|
+
* @since 4.0.0
|
|
155
211
|
*/
|
|
156
212
|
interface Count<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>> extends Effect.Effect<number, IndexedDbQueryError> {
|
|
157
213
|
readonly from: From<Table>;
|
|
@@ -172,8 +228,10 @@ export declare namespace IndexedDbQuery {
|
|
|
172
228
|
}) => Omit<Count<Table, Index>, ComparisonKeys>;
|
|
173
229
|
}
|
|
174
230
|
/**
|
|
175
|
-
*
|
|
231
|
+
* Intermediate delete builder used to choose a key range or limit before producing an executable delete query.
|
|
232
|
+
*
|
|
176
233
|
* @category models
|
|
234
|
+
* @since 4.0.0
|
|
177
235
|
*/
|
|
178
236
|
interface DeletePartial<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>> {
|
|
179
237
|
readonly from: From<Table>;
|
|
@@ -191,8 +249,10 @@ export declare namespace IndexedDbQuery {
|
|
|
191
249
|
}
|
|
192
250
|
type DeleteWithout<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>, ExcludedKeys extends string> = Omit<Delete<Table, Index, ExcludedKeys>, ExcludedKeys>;
|
|
193
251
|
/**
|
|
194
|
-
*
|
|
252
|
+
* Effect model for deleting rows from a table, with optional key-range, limit, filter, and reactivity invalidation helpers.
|
|
253
|
+
*
|
|
195
254
|
* @category models
|
|
255
|
+
* @since 4.0.0
|
|
196
256
|
*/
|
|
197
257
|
interface Delete<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>, ExcludedKeys extends string = never> extends Effect.Effect<void, IndexedDbQueryError> {
|
|
198
258
|
readonly delete: DeletePartial<Table, Index>;
|
|
@@ -215,8 +275,10 @@ export declare namespace IndexedDbQuery {
|
|
|
215
275
|
}
|
|
216
276
|
type SelectWithout<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>, ExcludedKeys extends string> = Omit<Select<Table, Index, ExcludedKeys>, ExcludedKeys>;
|
|
217
277
|
/**
|
|
218
|
-
*
|
|
278
|
+
* Effect model for selecting rows from a table, with chainable range, paging, filtering, streaming, and reactive query helpers.
|
|
279
|
+
*
|
|
219
280
|
* @category models
|
|
281
|
+
* @since 4.0.0
|
|
220
282
|
*/
|
|
221
283
|
interface Select<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>, ExcludedKeys extends string = never> extends Effect.Effect<Array<SelectType<Table>>, IndexedDbQueryError, IndexedDbTable.Context<Table>> {
|
|
222
284
|
readonly from: From<Table>;
|
|
@@ -261,27 +323,31 @@ export declare namespace IndexedDbQuery {
|
|
|
261
323
|
readonly reactiveQueue: (keys?: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined) => Effect.Effect<Queue.Dequeue<Array<SelectType<Table>>, IndexedDbQueryError>, never, Scope.Scope | IndexedDbTable.Context<Table>>;
|
|
262
324
|
}
|
|
263
325
|
/**
|
|
264
|
-
*
|
|
326
|
+
* Effect model for selecting the first matching row, failing with `NoSuchElementError` when no row is found.
|
|
327
|
+
*
|
|
265
328
|
* @category models
|
|
329
|
+
* @since 4.0.0
|
|
266
330
|
*/
|
|
267
|
-
interface First<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>> extends Effect.Effect<SelectType<Table>, IndexedDbQueryError, IndexedDbTable.Context<Table>> {
|
|
331
|
+
interface First<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>> extends Effect.Effect<SelectType<Table>, IndexedDbQueryError | Cause.NoSuchElementError, IndexedDbTable.Context<Table>> {
|
|
268
332
|
readonly select: Select<Table, Index>;
|
|
269
333
|
/**
|
|
270
334
|
* Use the Reactivity service to react to changes to the selected data.
|
|
271
335
|
*
|
|
272
336
|
* By default it uses the table name as a key.
|
|
273
337
|
*/
|
|
274
|
-
readonly reactive: (keys?: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined) => Stream.Stream<SelectType<Table>, IndexedDbQueryError, IndexedDbTable.Context<Table>>;
|
|
338
|
+
readonly reactive: (keys?: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined) => Stream.Stream<SelectType<Table>, IndexedDbQueryError | Cause.NoSuchElementError, IndexedDbTable.Context<Table>>;
|
|
275
339
|
/**
|
|
276
340
|
* Use the Reactivity service to react to changes to the selected data.
|
|
277
341
|
*
|
|
278
342
|
* By default it uses the table name as a key.
|
|
279
343
|
*/
|
|
280
|
-
readonly reactiveQueue: (keys: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>>) => Effect.Effect<Queue.Dequeue<SelectType<Table>, IndexedDbQueryError>, never, Scope.Scope | IndexedDbTable.Context<Table>>;
|
|
344
|
+
readonly reactiveQueue: (keys: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>>) => Effect.Effect<Queue.Dequeue<SelectType<Table>, IndexedDbQueryError | Cause.NoSuchElementError>, never, Scope.Scope | IndexedDbTable.Context<Table>>;
|
|
281
345
|
}
|
|
282
346
|
/**
|
|
283
|
-
*
|
|
347
|
+
* Effect model for a select query filtered by one or more predicates over encoded table rows.
|
|
348
|
+
*
|
|
284
349
|
* @category models
|
|
350
|
+
* @since 4.0.0
|
|
285
351
|
*/
|
|
286
352
|
interface Filter<Table extends IndexedDbTable.AnyWithProps, Index extends IndexedDbDatabase.IndexFromTable<Table>> extends Effect.Effect<Array<SelectType<Table>>, IndexedDbQueryError, IndexedDbTable.Context<Table>> {
|
|
287
353
|
readonly select: Select<Table, Index>;
|
|
@@ -289,8 +355,10 @@ export declare namespace IndexedDbQuery {
|
|
|
289
355
|
readonly filter: (f: (value: IndexedDbTable.Encoded<Table>) => boolean) => Filter<Table, Index>;
|
|
290
356
|
}
|
|
291
357
|
/**
|
|
292
|
-
*
|
|
358
|
+
* Effect model for inserting or upserting one row, returning the resulting IndexedDB key and supporting reactivity invalidation.
|
|
359
|
+
*
|
|
293
360
|
* @category models
|
|
361
|
+
* @since 4.0.0
|
|
294
362
|
*/
|
|
295
363
|
interface Modify<Table extends IndexedDbTable.AnyWithProps> extends Effect.Effect<globalThis.IDBValidKey, IndexedDbQueryError, IndexedDbTable.Context<Table>> {
|
|
296
364
|
readonly operation: "add" | "put";
|
|
@@ -304,8 +372,10 @@ export declare namespace IndexedDbQuery {
|
|
|
304
372
|
readonly invalidate: (keys?: ReadonlyArray<unknown> | Record.ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined) => Effect.Effect<globalThis.IDBValidKey, IndexedDbQueryError, IndexedDbTable.Context<Table>>;
|
|
305
373
|
}
|
|
306
374
|
/**
|
|
307
|
-
*
|
|
375
|
+
* Effect model for inserting or upserting multiple rows, returning the resulting IndexedDB keys and supporting reactivity invalidation.
|
|
376
|
+
*
|
|
308
377
|
* @category models
|
|
378
|
+
* @since 4.0.0
|
|
309
379
|
*/
|
|
310
380
|
interface ModifyAll<Table extends IndexedDbTable.AnyWithProps> extends Effect.Effect<Array<globalThis.IDBValidKey>, IndexedDbQueryError, IndexedDbTable.Context<Table>> {
|
|
311
381
|
readonly operation: "add" | "put";
|
|
@@ -321,16 +391,20 @@ export declare namespace IndexedDbQuery {
|
|
|
321
391
|
}
|
|
322
392
|
declare const IndexedDbTransaction_base: Context.ServiceClass<IndexedDbTransaction, "@effect/platform-browser/IndexedDbQueryBuilder/IndexedDbTransaction", IDBTransaction>;
|
|
323
393
|
/**
|
|
324
|
-
*
|
|
394
|
+
* Service tag for the active `IDBTransaction` used to share a transaction across IndexedDB query effects.
|
|
395
|
+
*
|
|
325
396
|
* @category models
|
|
397
|
+
* @since 4.0.0
|
|
326
398
|
*/
|
|
327
399
|
export declare class IndexedDbTransaction extends IndexedDbTransaction_base {
|
|
328
400
|
}
|
|
329
401
|
type IndexedDbValidKeys<TableSchema extends IndexedDbTable.AnySchemaStruct> = keyof TableSchema["Encoded"] extends infer K ? K extends keyof TableSchema["Encoded"] ? TableSchema["Encoded"][K] extends Readonly<IDBValidKey> ? K : never : never : never;
|
|
330
402
|
type IndexedDbValidNumberKeys<TableSchema extends IndexedDbTable.AnySchemaStruct> = keyof TableSchema["Encoded"] extends infer K ? K extends keyof TableSchema["Encoded"] ? [TableSchema["Encoded"][K]] extends [number | undefined] ? K : never : never : never;
|
|
331
403
|
/**
|
|
332
|
-
*
|
|
404
|
+
* Creates an `IndexedDbQueryBuilder` from an open database reference, key-range constructor, table map, and reactivity service.
|
|
405
|
+
*
|
|
333
406
|
* @category constructors
|
|
407
|
+
* @since 4.0.0
|
|
334
408
|
*/
|
|
335
409
|
export declare const make: <Source extends IndexedDbVersion.AnyWithProps>({ IDBKeyRange, database, tables, reactivity }: {
|
|
336
410
|
readonly database: MutableRef.MutableRef<globalThis.IDBDatabase>;
|