@effect/platform-browser 4.0.0-beta.41 → 4.0.0-beta.43
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/IndexedDb.d.ts +50 -0
- package/dist/IndexedDb.d.ts.map +1 -0
- package/dist/IndexedDb.js +65 -0
- package/dist/IndexedDb.js.map +1 -0
- package/dist/IndexedDbDatabase.d.ts +100 -0
- package/dist/IndexedDbDatabase.d.ts.map +1 -0
- package/dist/IndexedDbDatabase.js +299 -0
- package/dist/IndexedDbDatabase.js.map +1 -0
- package/dist/IndexedDbQueryBuilder.d.ts +284 -0
- package/dist/IndexedDbQueryBuilder.d.ts.map +1 -0
- package/dist/IndexedDbQueryBuilder.js +862 -0
- package/dist/IndexedDbQueryBuilder.js.map +1 -0
- package/dist/IndexedDbTable.d.ts +110 -0
- package/dist/IndexedDbTable.d.ts.map +1 -0
- package/dist/IndexedDbTable.js +36 -0
- package/dist/IndexedDbTable.js.map +1 -0
- package/dist/IndexedDbVersion.d.ts +50 -0
- package/dist/IndexedDbVersion.d.ts.map +1 -0
- package/dist/IndexedDbVersion.js +23 -0
- package/dist/IndexedDbVersion.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/IndexedDb.ts +97 -0
- package/src/IndexedDbDatabase.ts +598 -0
- package/src/IndexedDbQueryBuilder.ts +1895 -0
- package/src/IndexedDbTable.ts +205 -0
- package/src/IndexedDbVersion.ts +89 -0
- package/src/index.ts +25 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 4.0.0
|
|
3
|
+
*/
|
|
4
|
+
import { type Pipeable, pipeArguments } from "effect/Pipeable"
|
|
5
|
+
import * as Schema from "effect/Schema"
|
|
6
|
+
import * as Struct from "effect/Struct"
|
|
7
|
+
import type { NoInfer } from "effect/Types"
|
|
8
|
+
import * as IndexedDb from "./IndexedDb.ts"
|
|
9
|
+
import type * as IndexedDbQueryBuilder from "./IndexedDbQueryBuilder.ts"
|
|
10
|
+
|
|
11
|
+
const TypeId = "~@effect/platform-browser/IndexedDbTable"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @since 4.0.0
|
|
15
|
+
* @category interface
|
|
16
|
+
*/
|
|
17
|
+
export interface IndexedDbTable<
|
|
18
|
+
out Name extends string,
|
|
19
|
+
out TableSchema extends AnySchemaStruct,
|
|
20
|
+
out Indexes extends Record<
|
|
21
|
+
string,
|
|
22
|
+
IndexedDbQueryBuilder.KeyPath<TableSchema>
|
|
23
|
+
>,
|
|
24
|
+
out KeyPath extends Readonly<IDBValidKey | undefined>,
|
|
25
|
+
out AutoIncrement extends boolean
|
|
26
|
+
> extends Pipeable {
|
|
27
|
+
new(_: never): {}
|
|
28
|
+
readonly [TypeId]: typeof TypeId
|
|
29
|
+
readonly tableName: Name
|
|
30
|
+
readonly tableSchema: TableSchema
|
|
31
|
+
readonly readSchema: Schema.Top
|
|
32
|
+
readonly autoincrementSchema: Schema.Top
|
|
33
|
+
readonly arraySchema: Schema.Top
|
|
34
|
+
readonly keyPath: KeyPath
|
|
35
|
+
readonly indexes: Indexes
|
|
36
|
+
readonly autoIncrement: AutoIncrement
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @since 4.0.0
|
|
41
|
+
* @category models
|
|
42
|
+
*/
|
|
43
|
+
export type AnySchemaStruct = Schema.Top & {
|
|
44
|
+
readonly fields: Schema.Struct.Fields
|
|
45
|
+
mapFields<To extends Schema.Struct.Fields>(
|
|
46
|
+
f: (fields: Schema.Struct.Fields) => To,
|
|
47
|
+
options?:
|
|
48
|
+
| {
|
|
49
|
+
readonly unsafePreserveChecks?: boolean | undefined
|
|
50
|
+
}
|
|
51
|
+
| undefined
|
|
52
|
+
): Schema.Struct<To>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @since 4.0.0
|
|
57
|
+
* @category models
|
|
58
|
+
*/
|
|
59
|
+
export interface Any {
|
|
60
|
+
readonly [TypeId]: typeof TypeId
|
|
61
|
+
readonly keyPath: any
|
|
62
|
+
readonly tableName: string
|
|
63
|
+
readonly tableSchema: Schema.Top
|
|
64
|
+
readonly readSchema: Schema.Top
|
|
65
|
+
readonly autoincrementSchema: Schema.Top
|
|
66
|
+
readonly arraySchema: Schema.Top
|
|
67
|
+
readonly autoIncrement: boolean
|
|
68
|
+
readonly indexes: any
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @since 4.0.0
|
|
73
|
+
* @category models
|
|
74
|
+
*/
|
|
75
|
+
export type AnyWithProps = IndexedDbTable<
|
|
76
|
+
string,
|
|
77
|
+
AnySchemaStruct,
|
|
78
|
+
any,
|
|
79
|
+
any,
|
|
80
|
+
boolean
|
|
81
|
+
>
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @since 4.0.0
|
|
85
|
+
* @category models
|
|
86
|
+
*/
|
|
87
|
+
export type TableName<Table extends Any> = Table["tableName"]
|
|
88
|
+
/**
|
|
89
|
+
* @since 4.0.0
|
|
90
|
+
* @category models
|
|
91
|
+
*/
|
|
92
|
+
export type KeyPath<Table extends Any> = Table["keyPath"]
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @since 4.0.0
|
|
96
|
+
* @category models
|
|
97
|
+
*/
|
|
98
|
+
export type AutoIncrement<Table extends Any> = Table["autoIncrement"]
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @since 4.0.0
|
|
102
|
+
* @category models
|
|
103
|
+
*/
|
|
104
|
+
export type TableSchema<Table extends Any> = Table["tableSchema"]
|
|
105
|
+
/**
|
|
106
|
+
* @since 4.0.0
|
|
107
|
+
* @category models
|
|
108
|
+
*/
|
|
109
|
+
export type Context<Table extends Any> =
|
|
110
|
+
| Table["tableSchema"]["DecodingServices"]
|
|
111
|
+
| Table["tableSchema"]["EncodingServices"]
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @since 4.0.0
|
|
115
|
+
* @category models
|
|
116
|
+
*/
|
|
117
|
+
export type Encoded<Table extends Any> = Table["tableSchema"]["Encoded"]
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @since 4.0.0
|
|
121
|
+
* @category models
|
|
122
|
+
*/
|
|
123
|
+
export type Indexes<Table extends Any> = Table["indexes"]
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @since 4.0.0
|
|
127
|
+
* @category models
|
|
128
|
+
*/
|
|
129
|
+
export type WithName<Table extends Any, TableName extends string> = Extract<
|
|
130
|
+
Table,
|
|
131
|
+
{ readonly tableName: TableName }
|
|
132
|
+
>
|
|
133
|
+
|
|
134
|
+
const Proto = {
|
|
135
|
+
[TypeId]: TypeId,
|
|
136
|
+
pipe() {
|
|
137
|
+
return pipeArguments(this, arguments)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @since 4.0.0
|
|
143
|
+
* @category constructors
|
|
144
|
+
*/
|
|
145
|
+
export const make = <
|
|
146
|
+
const Name extends string,
|
|
147
|
+
TableSchema extends AnySchemaStruct,
|
|
148
|
+
const Indexes extends Record<
|
|
149
|
+
string,
|
|
150
|
+
IndexedDbQueryBuilder.KeyPath<TableSchema>
|
|
151
|
+
>,
|
|
152
|
+
const KeyPath extends
|
|
153
|
+
| (AutoIncrement extends true ? IndexedDbQueryBuilder.KeyPathNumber<NoInfer<TableSchema>>
|
|
154
|
+
: IndexedDbQueryBuilder.KeyPath<NoInfer<TableSchema>>)
|
|
155
|
+
| undefined = undefined,
|
|
156
|
+
const AutoIncrement extends boolean = false
|
|
157
|
+
>(options: {
|
|
158
|
+
readonly name: Name
|
|
159
|
+
readonly schema: [KeyPath] extends [undefined]
|
|
160
|
+
? "key" extends keyof TableSchema["fields"] ? "Cannot have a 'key' field when keyPath is undefined"
|
|
161
|
+
: TableSchema
|
|
162
|
+
: TableSchema
|
|
163
|
+
readonly keyPath?: KeyPath
|
|
164
|
+
readonly indexes?: Indexes | undefined
|
|
165
|
+
readonly autoIncrement?: IsValidAutoIncrementKeyPath<
|
|
166
|
+
TableSchema,
|
|
167
|
+
KeyPath
|
|
168
|
+
> extends true ? AutoIncrement | undefined
|
|
169
|
+
: never
|
|
170
|
+
}): IndexedDbTable<
|
|
171
|
+
Name,
|
|
172
|
+
TableSchema,
|
|
173
|
+
Indexes,
|
|
174
|
+
Extract<KeyPath, Readonly<IDBValidKey | undefined>>,
|
|
175
|
+
AutoIncrement
|
|
176
|
+
> => {
|
|
177
|
+
// oxlint-disable-next-line typescript/no-extraneous-class
|
|
178
|
+
class Table {}
|
|
179
|
+
Object.assign(Table, Proto)
|
|
180
|
+
const readSchema = options.keyPath === undefined
|
|
181
|
+
? (options.schema as Schema.Struct<{}>).mapFields(Struct.assign({ key: IndexedDb.IDBValidKey }))
|
|
182
|
+
: options.schema
|
|
183
|
+
;(Table as any).tableName = options.name
|
|
184
|
+
;(Table as any).tableSchema = options.schema
|
|
185
|
+
;(Table as any).readSchema = readSchema
|
|
186
|
+
;(Table as any).arraySchema = Schema.Array(readSchema as any)
|
|
187
|
+
;(Table as any).autoincrementSchema = options.autoIncrement
|
|
188
|
+
? (options.schema as Schema.Struct<{}>).mapFields(Struct.omit([options.keyPath!] as any))
|
|
189
|
+
: options.schema
|
|
190
|
+
;(Table as any).keyPath = options.keyPath
|
|
191
|
+
;(Table as any).indexes = options.indexes
|
|
192
|
+
;(Table as any).autoIncrement = options.autoIncrement === true
|
|
193
|
+
return Table as any
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// -----------------------------------------------------------------------------
|
|
197
|
+
// internal
|
|
198
|
+
// -----------------------------------------------------------------------------
|
|
199
|
+
|
|
200
|
+
type IsValidAutoIncrementKeyPath<
|
|
201
|
+
TableSchema extends AnySchemaStruct,
|
|
202
|
+
KeyPath
|
|
203
|
+
> = KeyPath extends keyof TableSchema["Encoded"] ? TableSchema["Encoded"][KeyPath] extends number ? true
|
|
204
|
+
: false
|
|
205
|
+
: false
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 4.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { NonEmptyReadonlyArray } from "effect/Array"
|
|
5
|
+
import type { Pipeable } from "effect/Pipeable"
|
|
6
|
+
import { pipeArguments } from "effect/Pipeable"
|
|
7
|
+
import type * as IndexedDbTable from "./IndexedDbTable.ts"
|
|
8
|
+
|
|
9
|
+
const TypeId = "~@effect/platform-browser/IndexedDbVersion"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @since 4.0.0
|
|
13
|
+
* @category interface
|
|
14
|
+
*/
|
|
15
|
+
export interface IndexedDbVersion<
|
|
16
|
+
out Tables extends IndexedDbTable.AnyWithProps
|
|
17
|
+
> extends Pipeable {
|
|
18
|
+
new(_: never): {}
|
|
19
|
+
readonly [TypeId]: typeof TypeId
|
|
20
|
+
readonly tables: ReadonlyMap<string, Tables>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @since 4.0.0
|
|
25
|
+
* @category models
|
|
26
|
+
*/
|
|
27
|
+
export interface Any {
|
|
28
|
+
readonly [TypeId]: typeof TypeId
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @since 4.0.0
|
|
33
|
+
* @category models
|
|
34
|
+
*/
|
|
35
|
+
export type AnyWithProps = IndexedDbVersion<IndexedDbTable.AnyWithProps>
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @since 4.0.0
|
|
39
|
+
* @category models
|
|
40
|
+
*/
|
|
41
|
+
export type Tables<Db extends Any> = Db extends IndexedDbVersion<infer _Tables> ? _Tables : never
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @since 4.0.0
|
|
45
|
+
* @category models
|
|
46
|
+
*/
|
|
47
|
+
export type TableWithName<
|
|
48
|
+
Db extends Any,
|
|
49
|
+
TableName extends string
|
|
50
|
+
> = IndexedDbTable.WithName<Tables<Db>, TableName>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @since 4.0.0
|
|
54
|
+
* @category models
|
|
55
|
+
*/
|
|
56
|
+
export type SchemaWithName<
|
|
57
|
+
Db extends Any,
|
|
58
|
+
TableName extends string
|
|
59
|
+
> = IndexedDbTable.TableSchema<IndexedDbTable.WithName<Tables<Db>, TableName>>
|
|
60
|
+
|
|
61
|
+
const Proto = {
|
|
62
|
+
[TypeId]: TypeId,
|
|
63
|
+
pipe() {
|
|
64
|
+
return pipeArguments(this, arguments)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const makeProto = <Tables extends IndexedDbTable.AnyWithProps>(options: {
|
|
69
|
+
readonly tables: ReadonlyMap<string, Tables>
|
|
70
|
+
}): IndexedDbVersion<Tables> => {
|
|
71
|
+
// oxlint-disable-next-line typescript/no-extraneous-class
|
|
72
|
+
class Version {}
|
|
73
|
+
Object.assign(Version, Proto)
|
|
74
|
+
;(Version as any).tables = options.tables
|
|
75
|
+
return Version as any
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @since 4.0.0
|
|
80
|
+
* @category constructors
|
|
81
|
+
*/
|
|
82
|
+
export const make = <
|
|
83
|
+
const Tables extends NonEmptyReadonlyArray<IndexedDbTable.AnyWithProps>
|
|
84
|
+
>(
|
|
85
|
+
...tables: Tables
|
|
86
|
+
): IndexedDbVersion<Tables[number]> =>
|
|
87
|
+
makeProto({
|
|
88
|
+
tables: new Map(tables.map((table) => [table.tableName, table]))
|
|
89
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -49,6 +49,31 @@ export * as Clipboard from "./Clipboard.ts"
|
|
|
49
49
|
*/
|
|
50
50
|
export * as Geolocation from "./Geolocation.ts"
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @since 4.0.0
|
|
54
|
+
*/
|
|
55
|
+
export * as IndexedDb from "./IndexedDb.ts"
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @since 4.0.0
|
|
59
|
+
*/
|
|
60
|
+
export * as IndexedDbDatabase from "./IndexedDbDatabase.ts"
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
export * as IndexedDbQueryBuilder from "./IndexedDbQueryBuilder.ts"
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @since 4.0.0
|
|
69
|
+
*/
|
|
70
|
+
export * as IndexedDbTable from "./IndexedDbTable.ts"
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
export * as IndexedDbVersion from "./IndexedDbVersion.ts"
|
|
76
|
+
|
|
52
77
|
/**
|
|
53
78
|
* @since 1.0.0
|
|
54
79
|
*/
|