@effect/platform-browser 4.0.0-beta.7 → 4.0.0-beta.71
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 +81 -0
- package/dist/BrowserCrypto.d.ts.map +1 -0
- package/dist/BrowserCrypto.js +119 -0
- package/dist/BrowserCrypto.js.map +1 -0
- package/dist/BrowserHttpClient.d.ts +40 -16
- package/dist/BrowserHttpClient.d.ts.map +1 -1
- package/dist/BrowserHttpClient.js +74 -18
- package/dist/BrowserHttpClient.js.map +1 -1
- package/dist/BrowserKeyValueStore.d.ts +37 -14
- package/dist/BrowserKeyValueStore.d.ts.map +1 -1
- package/dist/BrowserKeyValueStore.js +185 -10
- package/dist/BrowserKeyValueStore.js.map +1 -1
- package/dist/BrowserPersistence.d.ts +40 -0
- package/dist/BrowserPersistence.d.ts.map +1 -0
- package/dist/BrowserPersistence.js +207 -0
- package/dist/BrowserPersistence.js.map +1 -0
- package/dist/BrowserRuntime.d.ts +79 -4
- package/dist/BrowserRuntime.d.ts.map +1 -1
- package/dist/BrowserRuntime.js +19 -1
- package/dist/BrowserRuntime.js.map +1 -1
- package/dist/BrowserSocket.d.ts +64 -6
- package/dist/BrowserSocket.d.ts.map +1 -1
- package/dist/BrowserSocket.js +64 -6
- package/dist/BrowserSocket.js.map +1 -1
- package/dist/BrowserStream.d.ts +48 -5
- package/dist/BrowserStream.d.ts.map +1 -1
- package/dist/BrowserStream.js +48 -5
- package/dist/BrowserStream.js.map +1 -1
- package/dist/BrowserWorker.d.ts +25 -4
- package/dist/BrowserWorker.d.ts.map +1 -1
- package/dist/BrowserWorker.js +62 -6
- package/dist/BrowserWorker.js.map +1 -1
- package/dist/BrowserWorkerRunner.d.ts +31 -6
- package/dist/BrowserWorkerRunner.d.ts.map +1 -1
- package/dist/BrowserWorkerRunner.js +65 -10
- package/dist/BrowserWorkerRunner.js.map +1 -1
- package/dist/Clipboard.d.ts +77 -13
- package/dist/Clipboard.d.ts.map +1 -1
- package/dist/Clipboard.js +57 -11
- package/dist/Clipboard.js.map +1 -1
- package/dist/Geolocation.d.ts +101 -24
- package/dist/Geolocation.d.ts.map +1 -1
- package/dist/Geolocation.js +69 -16
- package/dist/Geolocation.js.map +1 -1
- package/dist/IndexedDb.d.ts +89 -0
- package/dist/IndexedDb.d.ts.map +1 -0
- package/dist/IndexedDb.js +99 -0
- package/dist/IndexedDb.js.map +1 -0
- package/dist/IndexedDbDatabase.d.ts +169 -0
- package/dist/IndexedDbDatabase.d.ts.map +1 -0
- package/dist/IndexedDbDatabase.js +343 -0
- package/dist/IndexedDbDatabase.js.map +1 -0
- package/dist/IndexedDbQueryBuilder.d.ts +438 -0
- package/dist/IndexedDbQueryBuilder.d.ts.map +1 -0
- package/dist/IndexedDbQueryBuilder.js +935 -0
- package/dist/IndexedDbQueryBuilder.js.map +1 -0
- package/dist/IndexedDbTable.d.ts +191 -0
- package/dist/IndexedDbTable.d.ts.map +1 -0
- package/dist/IndexedDbTable.js +96 -0
- package/dist/IndexedDbTable.js.map +1 -0
- package/dist/IndexedDbVersion.d.ts +94 -0
- package/dist/IndexedDbVersion.d.ts.map +1 -0
- package/dist/IndexedDbVersion.js +39 -0
- package/dist/IndexedDbVersion.js.map +1 -0
- package/dist/Permissions.d.ts +76 -16
- package/dist/Permissions.d.ts.map +1 -1
- package/dist/Permissions.js +66 -11
- package/dist/Permissions.js.map +1 -1
- package/dist/index.d.ts +38 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/BrowserCrypto.ts +129 -0
- package/src/BrowserHttpClient.ts +84 -24
- package/src/BrowserKeyValueStore.ts +201 -12
- package/src/BrowserPersistence.ts +376 -0
- package/src/BrowserRuntime.ts +79 -4
- package/src/BrowserSocket.ts +64 -6
- package/src/BrowserStream.ts +48 -5
- package/src/BrowserWorker.ts +62 -6
- package/src/BrowserWorkerRunner.ts +65 -10
- package/src/Clipboard.ts +74 -13
- package/src/Geolocation.ts +97 -20
- package/src/IndexedDb.ts +127 -0
- package/src/IndexedDbDatabase.ts +664 -0
- package/src/IndexedDbQueryBuilder.ts +2048 -0
- package/src/IndexedDbTable.ts +285 -0
- package/src/IndexedDbVersion.ts +133 -0
- package/src/Permissions.ts +71 -14
- package/src/index.ts +45 -10
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed object-store descriptors for the browser IndexedDB integration.
|
|
3
|
+
*
|
|
4
|
+
* An {@link IndexedDbTable} is the schema-backed description of one IndexedDB
|
|
5
|
+
* object store. It carries the store name, row schema, key path, index key
|
|
6
|
+
* paths, auto-increment mode, and transaction durability used by database
|
|
7
|
+
* versions, migrations, and typed queries.
|
|
8
|
+
*
|
|
9
|
+
* **Mental model**
|
|
10
|
+
*
|
|
11
|
+
* A table value is metadata. `make` does not create an object store; it gives
|
|
12
|
+
* database versions, migration helpers, and the query builder the information
|
|
13
|
+
* they need to type table names, validate rows, and choose schemas for reads
|
|
14
|
+
* and writes. The stored values are the encoded schema values accepted by
|
|
15
|
+
* IndexedDB, with derived schemas for out-of-line keys and generated
|
|
16
|
+
* auto-increment keys.
|
|
17
|
+
*
|
|
18
|
+
* **Common tasks**
|
|
19
|
+
*
|
|
20
|
+
* - Define object stores for browser caches, offline state, drafts, and
|
|
21
|
+
* background queues.
|
|
22
|
+
* - Reuse the same table descriptor in database versions, migrations, and
|
|
23
|
+
* typed queries.
|
|
24
|
+
* - Declare index key paths so query builders can restrict index names and key
|
|
25
|
+
* values.
|
|
26
|
+
*
|
|
27
|
+
* **Gotchas**
|
|
28
|
+
*
|
|
29
|
+
* Key paths and index paths point at encoded schema fields whose values must be
|
|
30
|
+
* valid IndexedDB keys. Tables without an inline key path use an out-of-line
|
|
31
|
+
* `key`, so the row schema cannot define a `key` field. Auto-increment tables
|
|
32
|
+
* require a numeric key path, and declared indexes still have to be created in
|
|
33
|
+
* migrations.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link make} for constructing table descriptors.
|
|
36
|
+
*
|
|
37
|
+
* @since 4.0.0
|
|
38
|
+
*/
|
|
39
|
+
import { type Pipeable, pipeArguments } from "effect/Pipeable"
|
|
40
|
+
import * as Schema from "effect/Schema"
|
|
41
|
+
import * as Struct from "effect/Struct"
|
|
42
|
+
import type { NoInfer } from "effect/Types"
|
|
43
|
+
import * as IndexedDb from "./IndexedDb.ts"
|
|
44
|
+
import type * as IndexedDbQueryBuilder from "./IndexedDbQueryBuilder.ts"
|
|
45
|
+
|
|
46
|
+
const TypeId = "~@effect/platform-browser/IndexedDbTable"
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Typed IndexedDB table definition containing its name, schema, key path, indexes, auto-increment setting, and transaction durability.
|
|
50
|
+
*
|
|
51
|
+
* @category interface
|
|
52
|
+
* @since 4.0.0
|
|
53
|
+
*/
|
|
54
|
+
export interface IndexedDbTable<
|
|
55
|
+
out Name extends string,
|
|
56
|
+
out TableSchema extends AnySchemaStruct,
|
|
57
|
+
out Indexes extends Record<
|
|
58
|
+
string,
|
|
59
|
+
IndexedDbQueryBuilder.KeyPath<TableSchema>
|
|
60
|
+
>,
|
|
61
|
+
out KeyPath extends Readonly<IDBValidKey | undefined>,
|
|
62
|
+
out AutoIncrement extends boolean
|
|
63
|
+
> extends Pipeable {
|
|
64
|
+
new(_: never): {}
|
|
65
|
+
readonly [TypeId]: typeof TypeId
|
|
66
|
+
readonly tableName: Name
|
|
67
|
+
readonly tableSchema: TableSchema
|
|
68
|
+
readonly readSchema: Schema.Top
|
|
69
|
+
readonly autoincrementSchema: Schema.Top
|
|
70
|
+
readonly arraySchema: Schema.Top
|
|
71
|
+
readonly keyPath: KeyPath
|
|
72
|
+
readonly indexes: Indexes
|
|
73
|
+
readonly autoIncrement: AutoIncrement
|
|
74
|
+
readonly durability: IDBTransactionDurability
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Schema constraint for table schemas that expose struct fields.
|
|
79
|
+
*
|
|
80
|
+
* @category models
|
|
81
|
+
* @since 4.0.0
|
|
82
|
+
*/
|
|
83
|
+
export type AnySchemaStruct = Schema.Top & {
|
|
84
|
+
readonly fields: Schema.Struct.Fields
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Type-erased shape of an `IndexedDbTable` used when table type parameters are not needed.
|
|
89
|
+
*
|
|
90
|
+
* @category models
|
|
91
|
+
* @since 4.0.0
|
|
92
|
+
*/
|
|
93
|
+
export interface Any {
|
|
94
|
+
readonly [TypeId]: typeof TypeId
|
|
95
|
+
readonly keyPath: any
|
|
96
|
+
readonly tableName: string
|
|
97
|
+
readonly tableSchema: Schema.Top
|
|
98
|
+
readonly readSchema: Schema.Top
|
|
99
|
+
readonly autoincrementSchema: Schema.Top
|
|
100
|
+
readonly arraySchema: Schema.Top
|
|
101
|
+
readonly autoIncrement: boolean
|
|
102
|
+
readonly indexes: any
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Type-erased `IndexedDbTable` retaining the table interface properties with broad type parameters.
|
|
107
|
+
*
|
|
108
|
+
* @category models
|
|
109
|
+
* @since 4.0.0
|
|
110
|
+
*/
|
|
111
|
+
export type AnyWithProps = IndexedDbTable<
|
|
112
|
+
string,
|
|
113
|
+
AnySchemaStruct,
|
|
114
|
+
any,
|
|
115
|
+
any,
|
|
116
|
+
boolean
|
|
117
|
+
>
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Extracts the table name type from an `IndexedDbTable`.
|
|
121
|
+
*
|
|
122
|
+
* @category models
|
|
123
|
+
* @since 4.0.0
|
|
124
|
+
*/
|
|
125
|
+
export type TableName<Table extends Any> = Table["tableName"]
|
|
126
|
+
/**
|
|
127
|
+
* Extracts the key-path type from an `IndexedDbTable`.
|
|
128
|
+
*
|
|
129
|
+
* @category models
|
|
130
|
+
* @since 4.0.0
|
|
131
|
+
*/
|
|
132
|
+
export type KeyPath<Table extends Any> = Table["keyPath"]
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Extracts the auto-increment flag type from an `IndexedDbTable`.
|
|
136
|
+
*
|
|
137
|
+
* @category models
|
|
138
|
+
* @since 4.0.0
|
|
139
|
+
*/
|
|
140
|
+
export type AutoIncrement<Table extends Any> = Table["autoIncrement"]
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Extracts the schema type from an `IndexedDbTable`.
|
|
144
|
+
*
|
|
145
|
+
* @category models
|
|
146
|
+
* @since 4.0.0
|
|
147
|
+
*/
|
|
148
|
+
export type TableSchema<Table extends Any> = Table["tableSchema"]
|
|
149
|
+
/**
|
|
150
|
+
* Extracts the decoding or encoding service requirements needed by an `IndexedDbTable` schema.
|
|
151
|
+
*
|
|
152
|
+
* @category models
|
|
153
|
+
* @since 4.0.0
|
|
154
|
+
*/
|
|
155
|
+
export type Context<Table extends Any> =
|
|
156
|
+
| Table["tableSchema"]["DecodingServices"]
|
|
157
|
+
| Table["tableSchema"]["EncodingServices"]
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Extracts the encoded row type from an `IndexedDbTable` schema.
|
|
161
|
+
*
|
|
162
|
+
* @category models
|
|
163
|
+
* @since 4.0.0
|
|
164
|
+
*/
|
|
165
|
+
export type Encoded<Table extends Any> = Table["tableSchema"]["Encoded"]
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Extracts the index definition map from an `IndexedDbTable`.
|
|
169
|
+
*
|
|
170
|
+
* @category models
|
|
171
|
+
* @since 4.0.0
|
|
172
|
+
*/
|
|
173
|
+
export type Indexes<Table extends Any> = Table["indexes"]
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Selects the table with the given name from a union of `IndexedDbTable` types.
|
|
177
|
+
*
|
|
178
|
+
* @category models
|
|
179
|
+
* @since 4.0.0
|
|
180
|
+
*/
|
|
181
|
+
export type WithName<Table extends Any, TableName extends string> = Extract<
|
|
182
|
+
Table,
|
|
183
|
+
{ readonly tableName: TableName }
|
|
184
|
+
>
|
|
185
|
+
|
|
186
|
+
const Proto = {
|
|
187
|
+
[TypeId]: TypeId,
|
|
188
|
+
pipe() {
|
|
189
|
+
return pipeArguments(this, arguments)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Creates a typed IndexedDB table definition from its name, schema, optional key path, indexes, auto-increment flag, and durability.
|
|
195
|
+
*
|
|
196
|
+
* **When to use**
|
|
197
|
+
*
|
|
198
|
+
* Use to define a typed object-store descriptor for inclusion in an
|
|
199
|
+
* `IndexedDbVersion` and for migration or query APIs.
|
|
200
|
+
*
|
|
201
|
+
* **Details**
|
|
202
|
+
*
|
|
203
|
+
* `autoIncrement` defaults to `false` and `durability` defaults to `"relaxed"`.
|
|
204
|
+
* Tables without a key path get a read schema that includes an out-of-line
|
|
205
|
+
* `key`, while auto-increment tables use a write schema where the generated key
|
|
206
|
+
* may be omitted.
|
|
207
|
+
*
|
|
208
|
+
* **Gotchas**
|
|
209
|
+
*
|
|
210
|
+
* Tables without a key path cannot define a `key` field in their row schema.
|
|
211
|
+
* Key paths and index paths must point to encoded fields whose values are valid
|
|
212
|
+
* IndexedDB keys, and declared indexes still need to be created during
|
|
213
|
+
* database migrations.
|
|
214
|
+
*
|
|
215
|
+
* @see `IndexedDbVersion.make` for grouping table definitions into a schema version
|
|
216
|
+
*
|
|
217
|
+
* @category constructors
|
|
218
|
+
* @since 4.0.0
|
|
219
|
+
*/
|
|
220
|
+
export const make = <
|
|
221
|
+
const Name extends string,
|
|
222
|
+
TableSchema extends AnySchemaStruct,
|
|
223
|
+
const Indexes extends Record<
|
|
224
|
+
string,
|
|
225
|
+
IndexedDbQueryBuilder.KeyPath<TableSchema>
|
|
226
|
+
>,
|
|
227
|
+
const KeyPath extends
|
|
228
|
+
| (AutoIncrement extends true ? IndexedDbQueryBuilder.KeyPathNumber<NoInfer<TableSchema>>
|
|
229
|
+
: IndexedDbQueryBuilder.KeyPath<NoInfer<TableSchema>>)
|
|
230
|
+
| undefined = undefined,
|
|
231
|
+
const AutoIncrement extends boolean = false
|
|
232
|
+
>(options: {
|
|
233
|
+
readonly name: Name
|
|
234
|
+
readonly schema: [KeyPath] extends [undefined]
|
|
235
|
+
? "key" extends keyof TableSchema["fields"] ? "Cannot have a 'key' field when keyPath is undefined"
|
|
236
|
+
: TableSchema
|
|
237
|
+
: TableSchema
|
|
238
|
+
readonly keyPath?: KeyPath
|
|
239
|
+
readonly indexes?: Indexes | undefined
|
|
240
|
+
readonly autoIncrement?: IsValidAutoIncrementKeyPath<
|
|
241
|
+
TableSchema,
|
|
242
|
+
KeyPath
|
|
243
|
+
> extends true ? AutoIncrement | undefined
|
|
244
|
+
: never
|
|
245
|
+
readonly durability?: IDBTransactionDurability | undefined
|
|
246
|
+
}): IndexedDbTable<
|
|
247
|
+
Name,
|
|
248
|
+
TableSchema,
|
|
249
|
+
Indexes,
|
|
250
|
+
Extract<KeyPath, Readonly<IDBValidKey | undefined>>,
|
|
251
|
+
AutoIncrement
|
|
252
|
+
> => {
|
|
253
|
+
// oxlint-disable-next-line typescript/no-extraneous-class
|
|
254
|
+
class Table {}
|
|
255
|
+
Object.assign(Table, Proto)
|
|
256
|
+
const readSchema = options.keyPath === undefined
|
|
257
|
+
? Schema.Struct({
|
|
258
|
+
...(options.schema as Schema.Struct<{}>).fields,
|
|
259
|
+
key: IndexedDb.IDBValidKey
|
|
260
|
+
})
|
|
261
|
+
: options.schema
|
|
262
|
+
;(Table as any).tableName = options.name
|
|
263
|
+
;(Table as any).tableSchema = options.schema
|
|
264
|
+
;(Table as any).readSchema = readSchema
|
|
265
|
+
;(Table as any).arraySchema = Schema.Array(readSchema as any)
|
|
266
|
+
;(Table as any).autoincrementSchema = options.autoIncrement
|
|
267
|
+
? Schema.Struct(Struct.omit((options.schema as Schema.Struct<{}>).fields, [options.keyPath!] as any))
|
|
268
|
+
: options.schema
|
|
269
|
+
;(Table as any).keyPath = options.keyPath
|
|
270
|
+
;(Table as any).indexes = options.indexes
|
|
271
|
+
;(Table as any).autoIncrement = options.autoIncrement === true
|
|
272
|
+
;(Table as any).durability = options.durability ?? "relaxed"
|
|
273
|
+
return Table as any
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// -----------------------------------------------------------------------------
|
|
277
|
+
// internal
|
|
278
|
+
// -----------------------------------------------------------------------------
|
|
279
|
+
|
|
280
|
+
type IsValidAutoIncrementKeyPath<
|
|
281
|
+
TableSchema extends AnySchemaStruct,
|
|
282
|
+
KeyPath
|
|
283
|
+
> = KeyPath extends keyof TableSchema["Encoded"] ? TableSchema["Encoded"][KeyPath] extends number ? true
|
|
284
|
+
: false
|
|
285
|
+
: false
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed IndexedDB schema version definitions.
|
|
3
|
+
*
|
|
4
|
+
* This module represents one logical IndexedDB database version as a non-empty set of `IndexedDbTable` definitions.
|
|
5
|
+
* Versions are consumed by `IndexedDbDatabase.make` and `.add` to type query builders and migration transactions, so
|
|
6
|
+
* applications can describe the tables available after initialization or after each schema upgrade.
|
|
7
|
+
*
|
|
8
|
+
* Use an `IndexedDbVersion` when defining the initial stores for a browser database, adding or removing object stores,
|
|
9
|
+
* changing indexes, or moving data between differently shaped table schemas. The version value is a typed description of
|
|
10
|
+
* the target schema; creating and deleting object stores or indexes still happens explicitly inside the corresponding
|
|
11
|
+
* `IndexedDbDatabase` migration callback.
|
|
12
|
+
*
|
|
13
|
+
* IndexedDB versioning is ordered by the migration chain rather than by a number stored here. Each `.add` step becomes
|
|
14
|
+
* the next browser database version, and only migrations after the browser's current version are run. Include every table
|
|
15
|
+
* that should be queryable in each target version, avoid duplicate table names, and remember that key-path or
|
|
16
|
+
* auto-increment changes usually require creating a new object store and copying data during the upgrade transaction.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.0.0
|
|
19
|
+
*/
|
|
20
|
+
import type { NonEmptyReadonlyArray } from "effect/Array"
|
|
21
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
22
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
23
|
+
import type * as IndexedDbTable from "./IndexedDbTable.ts"
|
|
24
|
+
|
|
25
|
+
const TypeId = "~@effect/platform-browser/IndexedDbVersion"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Typed IndexedDB version definition containing the tables available in that schema version.
|
|
29
|
+
*
|
|
30
|
+
* @category interface
|
|
31
|
+
* @since 4.0.0
|
|
32
|
+
*/
|
|
33
|
+
export interface IndexedDbVersion<
|
|
34
|
+
out Tables extends IndexedDbTable.AnyWithProps
|
|
35
|
+
> extends Pipeable {
|
|
36
|
+
new(_: never): {}
|
|
37
|
+
readonly [TypeId]: typeof TypeId
|
|
38
|
+
readonly tables: ReadonlyMap<string, Tables>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Type-erased shape of an `IndexedDbVersion`.
|
|
43
|
+
*
|
|
44
|
+
* @category models
|
|
45
|
+
* @since 4.0.0
|
|
46
|
+
*/
|
|
47
|
+
export interface Any {
|
|
48
|
+
readonly [TypeId]: typeof TypeId
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type-erased `IndexedDbVersion` retaining version properties with broad table types.
|
|
53
|
+
*
|
|
54
|
+
* @category models
|
|
55
|
+
* @since 4.0.0
|
|
56
|
+
*/
|
|
57
|
+
export type AnyWithProps = IndexedDbVersion<IndexedDbTable.AnyWithProps>
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Extracts the table union from an `IndexedDbVersion`.
|
|
61
|
+
*
|
|
62
|
+
* @category models
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
export type Tables<Db extends Any> = Db extends IndexedDbVersion<infer _Tables> ? _Tables : never
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Selects a table by name from an `IndexedDbVersion`.
|
|
69
|
+
*
|
|
70
|
+
* @category models
|
|
71
|
+
* @since 4.0.0
|
|
72
|
+
*/
|
|
73
|
+
export type TableWithName<
|
|
74
|
+
Db extends Any,
|
|
75
|
+
TableName extends string
|
|
76
|
+
> = IndexedDbTable.WithName<Tables<Db>, TableName>
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Extracts the schema for a named table within an `IndexedDbVersion`.
|
|
80
|
+
*
|
|
81
|
+
* @category models
|
|
82
|
+
* @since 4.0.0
|
|
83
|
+
*/
|
|
84
|
+
export type SchemaWithName<
|
|
85
|
+
Db extends Any,
|
|
86
|
+
TableName extends string
|
|
87
|
+
> = IndexedDbTable.TableSchema<IndexedDbTable.WithName<Tables<Db>, TableName>>
|
|
88
|
+
|
|
89
|
+
const Proto = {
|
|
90
|
+
[TypeId]: TypeId,
|
|
91
|
+
pipe() {
|
|
92
|
+
return pipeArguments(this, arguments)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const makeProto = <Tables extends IndexedDbTable.AnyWithProps>(options: {
|
|
97
|
+
readonly tables: ReadonlyMap<string, Tables>
|
|
98
|
+
}): IndexedDbVersion<Tables> => {
|
|
99
|
+
// oxlint-disable-next-line typescript/no-extraneous-class
|
|
100
|
+
class Version {}
|
|
101
|
+
Object.assign(Version, Proto)
|
|
102
|
+
;(Version as any).tables = options.tables
|
|
103
|
+
return Version as any
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates an `IndexedDbVersion` from one or more table definitions.
|
|
108
|
+
*
|
|
109
|
+
* **Details**
|
|
110
|
+
*
|
|
111
|
+
* The returned version exposes a `tables` map keyed by each table's
|
|
112
|
+
* `tableName`, and its type is the union of the supplied table definitions.
|
|
113
|
+
*
|
|
114
|
+
* **Gotchas**
|
|
115
|
+
*
|
|
116
|
+
* This constructor only describes the target schema; object stores and indexes
|
|
117
|
+
* still need to be created in the corresponding `IndexedDbDatabase` migration.
|
|
118
|
+
* Duplicate table names are not rejected, and the runtime map keeps the later
|
|
119
|
+
* table for a repeated key.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link IndexedDbTable.make} for creating table definitions consumed by this constructor
|
|
122
|
+
*
|
|
123
|
+
* @category constructors
|
|
124
|
+
* @since 4.0.0
|
|
125
|
+
*/
|
|
126
|
+
export const make = <
|
|
127
|
+
const Tables extends NonEmptyReadonlyArray<IndexedDbTable.AnyWithProps>
|
|
128
|
+
>(
|
|
129
|
+
...tables: Tables
|
|
130
|
+
): IndexedDbVersion<Tables[number]> =>
|
|
131
|
+
makeProto({
|
|
132
|
+
tables: new Map(tables.map((table) => [table.tableName, table]))
|
|
133
|
+
})
|
package/src/Permissions.ts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Effect service for the browser Permissions API.
|
|
3
|
+
*
|
|
4
|
+
* This module wraps `navigator.permissions` in a `Permissions` service and a
|
|
5
|
+
* browser-backed layer. It lets browser programs query whether a capability is
|
|
6
|
+
* currently `granted`, `prompt`, or `denied` before deciding which UI or
|
|
7
|
+
* feature flow to show for geolocation, notifications, clipboard access,
|
|
8
|
+
* camera, microphone, persistent storage, and other browser-gated features.
|
|
9
|
+
*
|
|
10
|
+
* **Mental model**
|
|
11
|
+
*
|
|
12
|
+
* A permission query is a status read, not an access request. The service
|
|
13
|
+
* delegates to `navigator.permissions.query({ name })` and returns the browser's
|
|
14
|
+
* `PermissionStatus`, while browser rejections are represented as
|
|
15
|
+
* `PermissionsError` values.
|
|
16
|
+
*
|
|
17
|
+
* **Common tasks**
|
|
18
|
+
*
|
|
19
|
+
* - Check whether a feature is already available before rendering a prompt or
|
|
20
|
+
* settings path.
|
|
21
|
+
* - Require permission querying through Effect context instead of reaching for
|
|
22
|
+
* the ambient `navigator` in application code.
|
|
23
|
+
* - Provide the live browser implementation with `layer`.
|
|
24
|
+
*
|
|
25
|
+
* **Gotchas**
|
|
26
|
+
*
|
|
27
|
+
* Browser support for permission names and states is uneven, and unsupported or
|
|
28
|
+
* invalid descriptors may reject. Some permissions are only meaningful in
|
|
29
|
+
* secure contexts or after user activation. Returned `PermissionStatus` objects
|
|
30
|
+
* can change when the user updates browser settings or responds to prompts; if
|
|
31
|
+
* you subscribe to `change` or `onchange`, clean up listeners with the
|
|
32
|
+
* surrounding Effect scope.
|
|
33
|
+
*
|
|
34
|
+
* @since 4.0.0
|
|
3
35
|
*/
|
|
36
|
+
import * as Context from "effect/Context"
|
|
4
37
|
import * as Data from "effect/Data"
|
|
5
38
|
import * as Effect from "effect/Effect"
|
|
6
39
|
import * as Layer from "effect/Layer"
|
|
7
|
-
import * as ServiceMap from "effect/ServiceMap"
|
|
8
40
|
|
|
9
41
|
const TypeId = "~@effect/platform-browser/Permissions"
|
|
10
42
|
const ErrorTypeId = "~@effect/platform-browser/Permissions/PermissionsError"
|
|
@@ -13,8 +45,8 @@ const ErrorTypeId = "~@effect/platform-browser/Permissions/PermissionsError"
|
|
|
13
45
|
* Wrapper on the Permission API (`navigator.permissions`) with methods for
|
|
14
46
|
* querying status of permissions.
|
|
15
47
|
*
|
|
16
|
-
* @
|
|
17
|
-
* @
|
|
48
|
+
* @category models
|
|
49
|
+
* @since 4.0.0
|
|
18
50
|
*/
|
|
19
51
|
export interface Permissions {
|
|
20
52
|
readonly [TypeId]: typeof TypeId
|
|
@@ -33,8 +65,10 @@ export interface Permissions {
|
|
|
33
65
|
}
|
|
34
66
|
|
|
35
67
|
/**
|
|
36
|
-
*
|
|
68
|
+
* Error reason for an `InvalidStateError` raised by the browser Permissions API.
|
|
69
|
+
*
|
|
37
70
|
* @category errors
|
|
71
|
+
* @since 4.0.0
|
|
38
72
|
*/
|
|
39
73
|
export class PermissionsInvalidStateError extends Data.TaggedError("InvalidStateError")<{
|
|
40
74
|
readonly cause: unknown
|
|
@@ -45,8 +79,10 @@ export class PermissionsInvalidStateError extends Data.TaggedError("InvalidState
|
|
|
45
79
|
}
|
|
46
80
|
|
|
47
81
|
/**
|
|
48
|
-
*
|
|
82
|
+
* Error reason for a `TypeError` raised by the browser Permissions API.
|
|
83
|
+
*
|
|
49
84
|
* @category errors
|
|
85
|
+
* @since 4.0.0
|
|
50
86
|
*/
|
|
51
87
|
export class PermissionsTypeError extends Data.TaggedError("TypeError")<{
|
|
52
88
|
readonly cause: unknown
|
|
@@ -57,14 +93,18 @@ export class PermissionsTypeError extends Data.TaggedError("TypeError")<{
|
|
|
57
93
|
}
|
|
58
94
|
|
|
59
95
|
/**
|
|
60
|
-
*
|
|
96
|
+
* Union of browser Permissions API error reasons represented by the service.
|
|
97
|
+
*
|
|
61
98
|
* @category errors
|
|
99
|
+
* @since 4.0.0
|
|
62
100
|
*/
|
|
63
101
|
export type PermissionsErrorReason = PermissionsInvalidStateError | PermissionsTypeError
|
|
64
102
|
|
|
65
103
|
/**
|
|
66
|
-
*
|
|
104
|
+
* Tagged error wrapping a browser Permissions API failure reason.
|
|
105
|
+
*
|
|
67
106
|
* @category errors
|
|
107
|
+
* @since 4.0.0
|
|
68
108
|
*/
|
|
69
109
|
export class PermissionsError extends Data.TaggedError("PermissionsError")<{
|
|
70
110
|
readonly reason: PermissionsErrorReason
|
|
@@ -84,16 +124,33 @@ export class PermissionsError extends Data.TaggedError("PermissionsError")<{
|
|
|
84
124
|
}
|
|
85
125
|
|
|
86
126
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
127
|
+
* Service tag for the browser `Permissions` service.
|
|
128
|
+
*
|
|
129
|
+
* **When to use**
|
|
130
|
+
*
|
|
131
|
+
* Use when an Effect needs to require or provide browser permission querying
|
|
132
|
+
* through the context.
|
|
133
|
+
*
|
|
134
|
+
* @category services
|
|
135
|
+
* @since 4.0.0
|
|
89
136
|
*/
|
|
90
|
-
export const Permissions:
|
|
137
|
+
export const Permissions: Context.Service<Permissions, Permissions> = Context.Service<Permissions>(TypeId)
|
|
91
138
|
|
|
92
139
|
/**
|
|
93
|
-
*
|
|
140
|
+
* Provides the `Permissions` service using the browser `navigator.permissions` API.
|
|
141
|
+
*
|
|
142
|
+
* **When to use**
|
|
143
|
+
*
|
|
144
|
+
* Use when browser programs need a live `Permissions` service backed by the
|
|
145
|
+
* ambient `navigator.permissions` implementation.
|
|
146
|
+
*
|
|
147
|
+
* **Details**
|
|
148
|
+
*
|
|
149
|
+
* `query` delegates to `navigator.permissions.query({ name })` and wraps
|
|
150
|
+
* rejected browser operations in `PermissionsError`.
|
|
94
151
|
*
|
|
95
|
-
* @
|
|
96
|
-
* @
|
|
152
|
+
* @category layers
|
|
153
|
+
* @since 4.0.0
|
|
97
154
|
*/
|
|
98
155
|
export const layer: Layer.Layer<Permissions> = Layer.succeed(
|
|
99
156
|
Permissions,
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// @barrel: Auto-generated exports. Do not edit manually.
|
|
@@ -7,49 +7,84 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* @since 1.0.0
|
|
9
9
|
*/
|
|
10
|
+
export * as BrowserCrypto from "./BrowserCrypto.ts"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @since 4.0.0
|
|
14
|
+
*/
|
|
10
15
|
export * as BrowserHttpClient from "./BrowserHttpClient.ts"
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
|
-
* @since
|
|
18
|
+
* @since 4.0.0
|
|
14
19
|
*/
|
|
15
20
|
export * as BrowserKeyValueStore from "./BrowserKeyValueStore.ts"
|
|
16
21
|
|
|
17
22
|
/**
|
|
18
|
-
* @since
|
|
23
|
+
* @since 4.0.0
|
|
24
|
+
*/
|
|
25
|
+
export * as BrowserPersistence from "./BrowserPersistence.ts"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @since 4.0.0
|
|
19
29
|
*/
|
|
20
30
|
export * as BrowserRuntime from "./BrowserRuntime.ts"
|
|
21
31
|
|
|
22
32
|
/**
|
|
23
|
-
* @since
|
|
33
|
+
* @since 4.0.0
|
|
24
34
|
*/
|
|
25
35
|
export * as BrowserSocket from "./BrowserSocket.ts"
|
|
26
36
|
|
|
27
37
|
/**
|
|
28
|
-
* @since
|
|
38
|
+
* @since 4.0.0
|
|
29
39
|
*/
|
|
30
40
|
export * as BrowserStream from "./BrowserStream.ts"
|
|
31
41
|
|
|
32
42
|
/**
|
|
33
|
-
* @since
|
|
43
|
+
* @since 4.0.0
|
|
34
44
|
*/
|
|
35
45
|
export * as BrowserWorker from "./BrowserWorker.ts"
|
|
36
46
|
|
|
37
47
|
/**
|
|
38
|
-
* @since
|
|
48
|
+
* @since 4.0.0
|
|
39
49
|
*/
|
|
40
50
|
export * as BrowserWorkerRunner from "./BrowserWorkerRunner.ts"
|
|
41
51
|
|
|
42
52
|
/**
|
|
43
|
-
* @since
|
|
53
|
+
* @since 4.0.0
|
|
44
54
|
*/
|
|
45
55
|
export * as Clipboard from "./Clipboard.ts"
|
|
46
56
|
|
|
47
57
|
/**
|
|
48
|
-
* @since
|
|
58
|
+
* @since 4.0.0
|
|
49
59
|
*/
|
|
50
60
|
export * as Geolocation from "./Geolocation.ts"
|
|
51
61
|
|
|
52
62
|
/**
|
|
53
|
-
* @since
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
export * as IndexedDb from "./IndexedDb.ts"
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @since 4.0.0
|
|
69
|
+
*/
|
|
70
|
+
export * as IndexedDbDatabase from "./IndexedDbDatabase.ts"
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
export * as IndexedDbQueryBuilder from "./IndexedDbQueryBuilder.ts"
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @since 4.0.0
|
|
79
|
+
*/
|
|
80
|
+
export * as IndexedDbTable from "./IndexedDbTable.ts"
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @since 4.0.0
|
|
84
|
+
*/
|
|
85
|
+
export * as IndexedDbVersion from "./IndexedDbVersion.ts"
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @since 4.0.0
|
|
54
89
|
*/
|
|
55
90
|
export * as Permissions from "./Permissions.ts"
|