@effect/platform-browser 4.0.0-beta.42 → 4.0.0-beta.44

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