@effect/platform-browser 4.0.0-beta.65 → 4.0.0-beta.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BrowserHttpClient.d.ts +18 -8
- package/dist/BrowserHttpClient.d.ts.map +1 -1
- package/dist/BrowserHttpClient.js +45 -8
- package/dist/BrowserHttpClient.js.map +1 -1
- package/dist/BrowserKeyValueStore.d.ts +13 -6
- package/dist/BrowserKeyValueStore.d.ts.map +1 -1
- package/dist/BrowserKeyValueStore.js +126 -2
- package/dist/BrowserKeyValueStore.js.map +1 -1
- package/dist/BrowserPersistence.d.ts +6 -2
- package/dist/BrowserPersistence.d.ts.map +1 -1
- package/dist/BrowserPersistence.js +6 -2
- package/dist/BrowserPersistence.js.map +1 -1
- package/dist/BrowserRuntime.d.ts +31 -4
- package/dist/BrowserRuntime.d.ts.map +1 -1
- package/dist/BrowserRuntime.js +3 -1
- package/dist/BrowserRuntime.js.map +1 -1
- package/dist/BrowserSocket.d.ts +29 -4
- package/dist/BrowserSocket.d.ts.map +1 -1
- package/dist/BrowserSocket.js +29 -4
- package/dist/BrowserSocket.js.map +1 -1
- package/dist/BrowserStream.d.ts +25 -3
- package/dist/BrowserStream.d.ts.map +1 -1
- package/dist/BrowserStream.js +25 -3
- package/dist/BrowserStream.js.map +1 -1
- package/dist/BrowserWorker.d.ts +6 -2
- package/dist/BrowserWorker.d.ts.map +1 -1
- package/dist/BrowserWorker.js +28 -4
- package/dist/BrowserWorker.js.map +1 -1
- package/dist/BrowserWorkerRunner.d.ts +9 -3
- package/dist/BrowserWorkerRunner.d.ts.map +1 -1
- package/dist/BrowserWorkerRunner.js +30 -6
- package/dist/BrowserWorkerRunner.js.map +1 -1
- package/dist/Clipboard.d.ts +30 -6
- package/dist/Clipboard.d.ts.map +1 -1
- package/dist/Clipboard.js +27 -5
- package/dist/Clipboard.js.map +1 -1
- package/dist/Geolocation.d.ts +44 -10
- package/dist/Geolocation.d.ts.map +1 -1
- package/dist/Geolocation.js +38 -8
- package/dist/Geolocation.js.map +1 -1
- package/dist/IndexedDb.d.ts +38 -11
- package/dist/IndexedDb.d.ts.map +1 -1
- package/dist/IndexedDb.js +35 -13
- package/dist/IndexedDb.js.map +1 -1
- package/dist/IndexedDbDatabase.d.ts +57 -10
- package/dist/IndexedDbDatabase.d.ts.map +1 -1
- package/dist/IndexedDbDatabase.js +36 -3
- package/dist/IndexedDbDatabase.js.map +1 -1
- package/dist/IndexedDbQueryBuilder.d.ts +103 -28
- package/dist/IndexedDbQueryBuilder.d.ts.map +1 -1
- package/dist/IndexedDbQueryBuilder.js +56 -26
- package/dist/IndexedDbQueryBuilder.js.map +1 -1
- package/dist/IndexedDbTable.d.ts +57 -13
- package/dist/IndexedDbTable.d.ts.map +1 -1
- package/dist/IndexedDbTable.js +21 -1
- package/dist/IndexedDbTable.js.map +1 -1
- package/dist/IndexedDbVersion.d.ts +37 -7
- package/dist/IndexedDbVersion.d.ts.map +1 -1
- package/dist/IndexedDbVersion.js +3 -1
- package/dist/IndexedDbVersion.js.map +1 -1
- package/dist/Permissions.d.ts +35 -8
- package/dist/Permissions.d.ts.map +1 -1
- package/dist/Permissions.js +31 -6
- package/dist/Permissions.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.js +12 -12
- package/package.json +3 -3
- package/src/BrowserHttpClient.ts +48 -9
- package/src/BrowserKeyValueStore.ts +142 -4
- package/src/BrowserPersistence.ts +19 -3
- package/src/BrowserRuntime.ts +31 -4
- package/src/BrowserSocket.ts +29 -4
- package/src/BrowserStream.ts +25 -3
- package/src/BrowserWorker.ts +28 -4
- package/src/BrowserWorkerRunner.ts +30 -6
- package/src/Clipboard.ts +30 -6
- package/src/Geolocation.ts +44 -10
- package/src/IndexedDb.ts +39 -21
- package/src/IndexedDbDatabase.ts +57 -10
- package/src/IndexedDbQueryBuilder.ts +172 -58
- package/src/IndexedDbTable.ts +57 -13
- package/src/IndexedDbVersion.ts +37 -7
- package/src/Permissions.ts +35 -8
- package/src/index.ts +12 -12
package/dist/Geolocation.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Browser geolocation support for Effect programs.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a `Geolocation` service and browser-backed layer for
|
|
5
|
+
* reading device location through `navigator.geolocation`. Use
|
|
6
|
+
* `getCurrentPosition` when an application needs one location fix, such as a
|
|
7
|
+
* nearby-search, check-in, or delivery estimate, and `watchPosition` when it
|
|
8
|
+
* needs a stream of updates for navigation, tracking, or location-aware UI.
|
|
9
|
+
*
|
|
10
|
+
* The implementation is browser-only and relies on the browser permission and
|
|
11
|
+
* policy model for geolocation. Calls may prompt the user, fail when permission
|
|
12
|
+
* is denied, time out, or report that position data is unavailable because of
|
|
13
|
+
* device, browser, privacy, origin, or secure-context restrictions. Watched
|
|
14
|
+
* positions are scoped so the underlying browser watch is cleared when the
|
|
15
|
+
* stream is finalized, and slow consumers should account for the sliding
|
|
16
|
+
* buffer used by `watchPosition`.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.0.0
|
|
3
19
|
*/
|
|
4
20
|
import * as Cause from "effect/Cause";
|
|
5
21
|
import * as Context from "effect/Context";
|
|
@@ -9,8 +25,10 @@ import * as Stream from "effect/Stream";
|
|
|
9
25
|
declare const TypeId = "~@effect/platform-browser/Geolocation";
|
|
10
26
|
declare const ErrorTypeId = "~@effect/platform-browser/Geolocation/GeolocationError";
|
|
11
27
|
/**
|
|
12
|
-
*
|
|
28
|
+
* Service interface for browser geolocation, providing effects for the current position and streams of watched positions.
|
|
29
|
+
*
|
|
13
30
|
* @category Models
|
|
31
|
+
* @since 4.0.0
|
|
14
32
|
*/
|
|
15
33
|
export interface Geolocation {
|
|
16
34
|
readonly [TypeId]: typeof TypeId;
|
|
@@ -20,16 +38,20 @@ export interface Geolocation {
|
|
|
20
38
|
} | undefined) => Stream.Stream<GeolocationPosition, GeolocationError>;
|
|
21
39
|
}
|
|
22
40
|
/**
|
|
23
|
-
*
|
|
41
|
+
* Service tag for the browser `Geolocation` service.
|
|
42
|
+
*
|
|
24
43
|
* @category Service
|
|
44
|
+
* @since 4.0.0
|
|
25
45
|
*/
|
|
26
46
|
export declare const Geolocation: Context.Service<Geolocation, Geolocation>;
|
|
27
47
|
declare const GeolocationError_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 & {
|
|
28
48
|
readonly _tag: "GeolocationError";
|
|
29
49
|
} & Readonly<A>;
|
|
30
50
|
/**
|
|
31
|
-
*
|
|
51
|
+
* Tagged error wrapping a browser geolocation failure reason.
|
|
52
|
+
*
|
|
32
53
|
* @category Errors
|
|
54
|
+
* @since 4.0.0
|
|
33
55
|
*/
|
|
34
56
|
export declare class GeolocationError extends GeolocationError_base<{
|
|
35
57
|
readonly reason: GeolocationErrorReason;
|
|
@@ -44,8 +66,10 @@ declare const PositionUnavailable_base: new <A extends Record<string, any> = {}>
|
|
|
44
66
|
readonly _tag: "PositionUnavailable";
|
|
45
67
|
} & Readonly<A>;
|
|
46
68
|
/**
|
|
47
|
-
*
|
|
69
|
+
* Error reason for the browser geolocation `POSITION_UNAVAILABLE` failure.
|
|
70
|
+
*
|
|
48
71
|
* @category Errors
|
|
72
|
+
* @since 4.0.0
|
|
49
73
|
*/
|
|
50
74
|
export declare class PositionUnavailable extends PositionUnavailable_base<{
|
|
51
75
|
readonly cause: unknown;
|
|
@@ -56,8 +80,10 @@ declare const PermissionDenied_base: new <A extends Record<string, any> = {}>(ar
|
|
|
56
80
|
readonly _tag: "PermissionDenied";
|
|
57
81
|
} & Readonly<A>;
|
|
58
82
|
/**
|
|
59
|
-
*
|
|
83
|
+
* Error reason for the browser geolocation `PERMISSION_DENIED` failure.
|
|
84
|
+
*
|
|
60
85
|
* @category Errors
|
|
86
|
+
* @since 4.0.0
|
|
61
87
|
*/
|
|
62
88
|
export declare class PermissionDenied extends PermissionDenied_base<{
|
|
63
89
|
readonly cause: unknown;
|
|
@@ -68,8 +94,10 @@ declare const Timeout_base: new <A extends Record<string, any> = {}>(args: impor
|
|
|
68
94
|
readonly _tag: "Timeout";
|
|
69
95
|
} & Readonly<A>;
|
|
70
96
|
/**
|
|
71
|
-
*
|
|
97
|
+
* Error reason for the browser geolocation `TIMEOUT` failure.
|
|
98
|
+
*
|
|
72
99
|
* @category Errors
|
|
100
|
+
* @since 4.0.0
|
|
73
101
|
*/
|
|
74
102
|
export declare class Timeout extends Timeout_base<{
|
|
75
103
|
readonly cause: unknown;
|
|
@@ -77,18 +105,24 @@ export declare class Timeout extends Timeout_base<{
|
|
|
77
105
|
get message(): string;
|
|
78
106
|
}
|
|
79
107
|
/**
|
|
80
|
-
*
|
|
108
|
+
* Union of browser geolocation error reasons represented by the service.
|
|
109
|
+
*
|
|
81
110
|
* @category Errors
|
|
111
|
+
* @since 4.0.0
|
|
82
112
|
*/
|
|
83
113
|
export type GeolocationErrorReason = PositionUnavailable | PermissionDenied | Timeout;
|
|
84
114
|
/**
|
|
85
|
-
*
|
|
115
|
+
* Layer that provides `Geolocation` using `navigator.geolocation`, with watched positions buffered in a sliding queue.
|
|
116
|
+
*
|
|
86
117
|
* @category Layers
|
|
118
|
+
* @since 4.0.0
|
|
87
119
|
*/
|
|
88
120
|
export declare const layer: Layer.Layer<Geolocation>;
|
|
89
121
|
/**
|
|
90
|
-
*
|
|
122
|
+
* Streams positions from the `Geolocation` service using `watchPosition`, with an optional sliding buffer size.
|
|
123
|
+
*
|
|
91
124
|
* @category Accessors
|
|
125
|
+
* @since 4.0.0
|
|
92
126
|
*/
|
|
93
127
|
export declare const watchPosition: (options?: (PositionOptions & {
|
|
94
128
|
readonly bufferSize?: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Geolocation.d.ts","sourceRoot":"","sources":["../src/Geolocation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
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;;;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,yBAAwC;IAC/E,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;;;;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,SAAQ,sBAAqC;IACzE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;;;;AAED;;;;;GAKG;AACH,qBAAa,OAAQ,SAAQ,aAA4B;IACvD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,GAAG,gBAAgB,GAAG,OAAO,CAAA;AAyCrF;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAe1C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GACxB,UACE,CAAE,eAAe,GAAG;IAClB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACzC,IACC,SAAS,KACZ,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,CAI/D,CAAA"}
|
package/dist/Geolocation.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Browser geolocation support for Effect programs.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a `Geolocation` service and browser-backed layer for
|
|
5
|
+
* reading device location through `navigator.geolocation`. Use
|
|
6
|
+
* `getCurrentPosition` when an application needs one location fix, such as a
|
|
7
|
+
* nearby-search, check-in, or delivery estimate, and `watchPosition` when it
|
|
8
|
+
* needs a stream of updates for navigation, tracking, or location-aware UI.
|
|
9
|
+
*
|
|
10
|
+
* The implementation is browser-only and relies on the browser permission and
|
|
11
|
+
* policy model for geolocation. Calls may prompt the user, fail when permission
|
|
12
|
+
* is denied, time out, or report that position data is unavailable because of
|
|
13
|
+
* device, browser, privacy, origin, or secure-context restrictions. Watched
|
|
14
|
+
* positions are scoped so the underlying browser watch is cleared when the
|
|
15
|
+
* stream is finalized, and slow consumers should account for the sliding
|
|
16
|
+
* buffer used by `watchPosition`.
|
|
17
|
+
*
|
|
18
|
+
* @since 4.0.0
|
|
3
19
|
*/
|
|
4
20
|
import * as Cause from "effect/Cause";
|
|
5
21
|
import * as Context from "effect/Context";
|
|
@@ -11,13 +27,17 @@ import * as Stream from "effect/Stream";
|
|
|
11
27
|
const TypeId = "~@effect/platform-browser/Geolocation";
|
|
12
28
|
const ErrorTypeId = "~@effect/platform-browser/Geolocation/GeolocationError";
|
|
13
29
|
/**
|
|
14
|
-
*
|
|
30
|
+
* Service tag for the browser `Geolocation` service.
|
|
31
|
+
*
|
|
15
32
|
* @category Service
|
|
33
|
+
* @since 4.0.0
|
|
16
34
|
*/
|
|
17
35
|
export const Geolocation = /*#__PURE__*/Context.Service(TypeId);
|
|
18
36
|
/**
|
|
19
|
-
*
|
|
37
|
+
* Tagged error wrapping a browser geolocation failure reason.
|
|
38
|
+
*
|
|
20
39
|
* @category Errors
|
|
40
|
+
* @since 4.0.0
|
|
21
41
|
*/
|
|
22
42
|
export class GeolocationError extends /*#__PURE__*/Data.TaggedError("GeolocationError") {
|
|
23
43
|
constructor(props) {
|
|
@@ -32,8 +52,10 @@ export class GeolocationError extends /*#__PURE__*/Data.TaggedError("Geolocation
|
|
|
32
52
|
}
|
|
33
53
|
}
|
|
34
54
|
/**
|
|
35
|
-
*
|
|
55
|
+
* Error reason for the browser geolocation `POSITION_UNAVAILABLE` failure.
|
|
56
|
+
*
|
|
36
57
|
* @category Errors
|
|
58
|
+
* @since 4.0.0
|
|
37
59
|
*/
|
|
38
60
|
export class PositionUnavailable extends /*#__PURE__*/Data.TaggedError("PositionUnavailable") {
|
|
39
61
|
get message() {
|
|
@@ -41,8 +63,10 @@ export class PositionUnavailable extends /*#__PURE__*/Data.TaggedError("Position
|
|
|
41
63
|
}
|
|
42
64
|
}
|
|
43
65
|
/**
|
|
44
|
-
*
|
|
66
|
+
* Error reason for the browser geolocation `PERMISSION_DENIED` failure.
|
|
67
|
+
*
|
|
45
68
|
* @category Errors
|
|
69
|
+
* @since 4.0.0
|
|
46
70
|
*/
|
|
47
71
|
export class PermissionDenied extends /*#__PURE__*/Data.TaggedError("PermissionDenied") {
|
|
48
72
|
get message() {
|
|
@@ -50,8 +74,10 @@ export class PermissionDenied extends /*#__PURE__*/Data.TaggedError("PermissionD
|
|
|
50
74
|
}
|
|
51
75
|
}
|
|
52
76
|
/**
|
|
53
|
-
*
|
|
77
|
+
* Error reason for the browser geolocation `TIMEOUT` failure.
|
|
78
|
+
*
|
|
54
79
|
* @category Errors
|
|
80
|
+
* @since 4.0.0
|
|
55
81
|
*/
|
|
56
82
|
export class Timeout extends /*#__PURE__*/Data.TaggedError("Timeout") {
|
|
57
83
|
get message() {
|
|
@@ -83,8 +109,10 @@ const makeQueue = options => Queue.sliding(options?.bufferSize ?? 16).pipe(Effec
|
|
|
83
109
|
}
|
|
84
110
|
}, options)), handleId => Effect.sync(() => navigator.geolocation.clearWatch(handleId)))));
|
|
85
111
|
/**
|
|
86
|
-
*
|
|
112
|
+
* Layer that provides `Geolocation` using `navigator.geolocation`, with watched positions buffered in a sliding queue.
|
|
113
|
+
*
|
|
87
114
|
* @category Layers
|
|
115
|
+
* @since 4.0.0
|
|
88
116
|
*/
|
|
89
117
|
export const layer = /*#__PURE__*/Layer.succeed(Geolocation, /*#__PURE__*/Geolocation.of({
|
|
90
118
|
[TypeId]: TypeId,
|
|
@@ -92,8 +120,10 @@ export const layer = /*#__PURE__*/Layer.succeed(Geolocation, /*#__PURE__*/Geoloc
|
|
|
92
120
|
watchPosition: options => makeQueue(options).pipe(Effect.map(Stream.fromQueue), Stream.unwrap)
|
|
93
121
|
}));
|
|
94
122
|
/**
|
|
95
|
-
*
|
|
123
|
+
* Streams positions from the `Geolocation` service using `watchPosition`, with an optional sliding buffer size.
|
|
124
|
+
*
|
|
96
125
|
* @category Accessors
|
|
126
|
+
* @since 4.0.0
|
|
97
127
|
*/
|
|
98
128
|
export const watchPosition = options => Stream.unwrap(Effect.map(Effect.service(Geolocation), geolocation => geolocation.watchPosition(options)));
|
|
99
129
|
//# sourceMappingURL=Geolocation.js.map
|
package/dist/Geolocation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Geolocation.js","names":["Cause","Context","Data","Effect","Layer","Queue","Stream","TypeId","ErrorTypeId","Geolocation","Service","GeolocationError","TaggedError","constructor","props","cause","reason","message","PositionUnavailable","_tag","PermissionDenied","Timeout","makeQueue","options","sliding","bufferSize","pipe","tap","queue","acquireRelease","sync","navigator","geolocation","watchPosition","position","offerUnsafe","code","PERMISSION_DENIED","error","failCauseUnsafe","fail","TIMEOUT","POSITION_UNAVAILABLE","handleId","clearWatch","layer","succeed","of","getCurrentPosition","flatMap","take","scoped","map","fromQueue","unwrap","service"],"sources":["../src/Geolocation.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Geolocation.js","names":["Cause","Context","Data","Effect","Layer","Queue","Stream","TypeId","ErrorTypeId","Geolocation","Service","GeolocationError","TaggedError","constructor","props","cause","reason","message","PositionUnavailable","_tag","PermissionDenied","Timeout","makeQueue","options","sliding","bufferSize","pipe","tap","queue","acquireRelease","sync","navigator","geolocation","watchPosition","position","offerUnsafe","code","PERMISSION_DENIED","error","failCauseUnsafe","fail","TIMEOUT","POSITION_UNAVAILABLE","handleId","clearWatch","layer","succeed","of","getCurrentPosition","flatMap","take","scoped","map","fromQueue","unwrap","service"],"sources":["../src/Geolocation.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;AAmBA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,O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Y,UAAU,CAACD,QAAQ,CAAC,CAAC,CAC5E,CACF,CACF;AAEH;;;;;;AAMA,OAAO,MAAME,KAAK,gBAA6BzC,KAAK,CAAC0C,OAAO,CAC1DrC,WAAW,eACXA,WAAW,CAACsC,EAAE,CAAC;EACb,CAACxC,MAAM,GAAGA,MAAM;EAChByC,kBAAkB,EAAGzB,OAAO,IAC1BD,SAAS,CAACC,OAAO,CAAC,CAACG,IAAI,CACrBvB,MAAM,CAAC8C,OAAO,CAAC5C,KAAK,CAAC6C,IAAI,CAAC,EAC1B/C,MAAM,CAACgD,MAAM,CACd;EACHlB,aAAa,EAAGV,OAAO,IACrBD,SAAS,CAACC,OAAO,CAAC,CAACG,IAAI,CACrBvB,MAAM,CAACiD,GAAG,CAAC9C,MAAM,CAAC+C,SAAS,CAAC,EAC5B/C,MAAM,CAACgD,MAAM;CAElB,CAAC,CACH;AAED;;;;;;AAMA,OAAO,MAAMrB,aAAa,GACxBV,OAIa,IAEbjB,MAAM,CAACgD,MAAM,CAACnD,MAAM,CAACiD,GAAG,CACtBjD,MAAM,CAACoD,OAAO,CAAC9C,WAAW,CAAC,EAC1BuB,WAAW,IAAKA,WAAW,CAACC,aAAa,CAACV,OAAO,CAAC,CACpD,CAAC","ignoreList":[]}
|
package/dist/IndexedDb.d.ts
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Browser IndexedDB primitives and key schemas for Effect applications.
|
|
3
|
+
*
|
|
4
|
+
* This module is the low-level bridge used by the platform-browser IndexedDB
|
|
5
|
+
* integration. It provides an `IndexedDb` service around the browser
|
|
6
|
+
* `indexedDB` factory and `IDBKeyRange` constructor, a `layerWindow` layer for
|
|
7
|
+
* wiring those primitives from `window`, and schemas for the key shapes accepted
|
|
8
|
+
* by IndexedDB object stores and indexes.
|
|
9
|
+
*
|
|
10
|
+
* Use it when building typed local persistence for browser caches,
|
|
11
|
+
* offline-first state, background queues, drafts, or other client-side data
|
|
12
|
+
* that should be validated before it reaches IndexedDB. Higher-level database,
|
|
13
|
+
* version, table, and query modules build on these primitives for migrations
|
|
14
|
+
* and typed transactions.
|
|
15
|
+
*
|
|
16
|
+
* IndexedDB still follows the browser rules: schema changes happen only during
|
|
17
|
+
* version upgrades, upgrades may be blocked by other open tabs or connections,
|
|
18
|
+
* and reads or writes must run in transactions scoped to the object stores they
|
|
19
|
+
* touch. The `layerWindow` constructor should be used only where browser
|
|
20
|
+
* globals are available, and code that also runs during SSR or in restricted
|
|
21
|
+
* browser contexts should account for `indexedDB` or `IDBKeyRange` being
|
|
22
|
+
* missing.
|
|
23
|
+
*
|
|
2
24
|
* @since 4.0.0
|
|
3
25
|
*/
|
|
4
|
-
import * as Config from "effect/Config";
|
|
5
26
|
import * as Context from "effect/Context";
|
|
6
27
|
import * as Layer from "effect/Layer";
|
|
7
28
|
import * as Schema from "effect/Schema";
|
|
8
29
|
declare const TypeId = "~@effect/platform-browser/IndexedDb";
|
|
9
30
|
/**
|
|
10
|
-
*
|
|
31
|
+
* Service interface that provides the browser `indexedDB` factory and `IDBKeyRange` constructor.
|
|
32
|
+
*
|
|
11
33
|
* @category models
|
|
34
|
+
* @since 4.0.0
|
|
12
35
|
*/
|
|
13
36
|
export interface IndexedDb {
|
|
14
37
|
readonly [TypeId]: typeof TypeId;
|
|
@@ -16,35 +39,39 @@ export interface IndexedDb {
|
|
|
16
39
|
readonly IDBKeyRange: typeof globalThis.IDBKeyRange;
|
|
17
40
|
}
|
|
18
41
|
/**
|
|
19
|
-
*
|
|
42
|
+
* Service tag for browser IndexedDB primitives.
|
|
43
|
+
*
|
|
20
44
|
* @category tag
|
|
45
|
+
* @since 4.0.0
|
|
21
46
|
*/
|
|
22
47
|
export declare const IndexedDb: Context.Service<IndexedDb, IndexedDb>;
|
|
23
48
|
/**
|
|
24
|
-
* Schema for
|
|
49
|
+
* Schema for IndexedDB keys: strings, non-NaN numbers, valid dates, buffer sources, or arrays of those flat key values.
|
|
25
50
|
*
|
|
26
|
-
* @since 4.0.0
|
|
27
51
|
* @category schemas
|
|
52
|
+
* @since 4.0.0
|
|
28
53
|
*/
|
|
29
54
|
export declare const IDBValidKey: Schema.Union<readonly [Schema.Union<readonly [Schema.String, Schema.Number, Schema.DateValid, Schema.declare<BufferSource, unknown>]>, Schema.$Array<Schema.Union<readonly [Schema.String, Schema.Number, Schema.DateValid, Schema.declare<BufferSource, unknown>]>>]>;
|
|
30
55
|
/**
|
|
31
|
-
* Schema for
|
|
56
|
+
* Schema for auto-incremented IndexedDB keys, accepting integers from 1 through `2 ** 53`.
|
|
32
57
|
*
|
|
33
|
-
* @since 4.0.0
|
|
34
58
|
* @category schemas
|
|
59
|
+
* @since 4.0.0
|
|
35
60
|
*/
|
|
36
61
|
export declare const AutoIncrement: Schema.Int;
|
|
37
62
|
/**
|
|
38
|
-
*
|
|
63
|
+
* Creates an `IndexedDb` service from an `IDBFactory` and `IDBKeyRange` constructor.
|
|
64
|
+
*
|
|
39
65
|
* @category constructor
|
|
66
|
+
* @since 4.0.0
|
|
40
67
|
*/
|
|
41
68
|
export declare const make: (impl: Omit<IndexedDb, typeof TypeId>) => IndexedDb;
|
|
42
69
|
/**
|
|
43
|
-
*
|
|
70
|
+
* Layer that provides `IndexedDb` from `window.indexedDB` and `window.IDBKeyRange`, failing with a config error when they are unavailable.
|
|
44
71
|
*
|
|
45
|
-
* @since 4.0.0
|
|
46
72
|
* @category constructors
|
|
73
|
+
* @since 4.0.0
|
|
47
74
|
*/
|
|
48
|
-
export declare const layerWindow: Layer.Layer<IndexedDb
|
|
75
|
+
export declare const layerWindow: Layer.Layer<IndexedDb>;
|
|
49
76
|
export {};
|
|
50
77
|
//# sourceMappingURL=IndexedDb.d.ts.map
|
package/dist/IndexedDb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDb.d.ts","sourceRoot":"","sources":["../src/IndexedDb.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"IndexedDb.d.ts","sourceRoot":"","sources":["../src/IndexedDb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,QAAA,MAAM,MAAM,wCAAwC,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,MAAM,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,UAAU,CAAA;IACzC,QAAQ,CAAC,WAAW,EAAE,OAAO,UAAU,CAAC,WAAW,CAAA;CACpD;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAiD,CAAA;AAc7G;;;;;GAKG;AACH,eAAO,MAAM,WAAW,wQAAuD,CAAA;AAE/E;;;;;GAKG;AACH,eAAO,MAAM,aAAa,YAMxB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,MAAM,IAAI,CAAC,SAAS,EAAE,OAAO,MAAM,CAAC,KAAG,SAAwD,CAAA;AAEpH;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAc9C,CAAA"}
|
package/dist/IndexedDb.js
CHANGED
|
@@ -1,32 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Browser IndexedDB primitives and key schemas for Effect applications.
|
|
3
|
+
*
|
|
4
|
+
* This module is the low-level bridge used by the platform-browser IndexedDB
|
|
5
|
+
* integration. It provides an `IndexedDb` service around the browser
|
|
6
|
+
* `indexedDB` factory and `IDBKeyRange` constructor, a `layerWindow` layer for
|
|
7
|
+
* wiring those primitives from `window`, and schemas for the key shapes accepted
|
|
8
|
+
* by IndexedDB object stores and indexes.
|
|
9
|
+
*
|
|
10
|
+
* Use it when building typed local persistence for browser caches,
|
|
11
|
+
* offline-first state, background queues, drafts, or other client-side data
|
|
12
|
+
* that should be validated before it reaches IndexedDB. Higher-level database,
|
|
13
|
+
* version, table, and query modules build on these primitives for migrations
|
|
14
|
+
* and typed transactions.
|
|
15
|
+
*
|
|
16
|
+
* IndexedDB still follows the browser rules: schema changes happen only during
|
|
17
|
+
* version upgrades, upgrades may be blocked by other open tabs or connections,
|
|
18
|
+
* and reads or writes must run in transactions scoped to the object stores they
|
|
19
|
+
* touch. The `layerWindow` constructor should be used only where browser
|
|
20
|
+
* globals are available, and code that also runs during SSR or in restricted
|
|
21
|
+
* browser contexts should account for `indexedDB` or `IDBKeyRange` being
|
|
22
|
+
* missing.
|
|
23
|
+
*
|
|
2
24
|
* @since 4.0.0
|
|
3
25
|
*/
|
|
4
|
-
import * as Config from "effect/Config";
|
|
5
26
|
import * as Context from "effect/Context";
|
|
6
27
|
import * as Effect from "effect/Effect";
|
|
7
28
|
import * as Layer from "effect/Layer";
|
|
8
29
|
import * as Schema from "effect/Schema";
|
|
9
|
-
import * as SchemaIssue from "effect/SchemaIssue";
|
|
10
30
|
const TypeId = "~@effect/platform-browser/IndexedDb";
|
|
11
31
|
/**
|
|
12
|
-
*
|
|
32
|
+
* Service tag for browser IndexedDB primitives.
|
|
33
|
+
*
|
|
13
34
|
* @category tag
|
|
35
|
+
* @since 4.0.0
|
|
14
36
|
*/
|
|
15
37
|
export const IndexedDb = /*#__PURE__*/Context.Service(TypeId);
|
|
16
38
|
/** @internal */
|
|
17
39
|
const IDBFlatKey = /*#__PURE__*/Schema.Union([Schema.String, /*#__PURE__*/Schema.Number.check(/*#__PURE__*/Schema.makeFilter(input => !Number.isNaN(input))), Schema.DateValid, /*#__PURE__*/Schema.declare(input => input instanceof ArrayBuffer || ArrayBuffer.isView(input) && input.buffer instanceof ArrayBuffer)]);
|
|
18
40
|
/**
|
|
19
|
-
* Schema for
|
|
41
|
+
* Schema for IndexedDB keys: strings, non-NaN numbers, valid dates, buffer sources, or arrays of those flat key values.
|
|
20
42
|
*
|
|
21
|
-
* @since 4.0.0
|
|
22
43
|
* @category schemas
|
|
44
|
+
* @since 4.0.0
|
|
23
45
|
*/
|
|
24
46
|
export const IDBValidKey = /*#__PURE__*/Schema.Union([IDBFlatKey, /*#__PURE__*/Schema.Array(IDBFlatKey)]);
|
|
25
47
|
/**
|
|
26
|
-
* Schema for
|
|
48
|
+
* Schema for auto-incremented IndexedDB keys, accepting integers from 1 through `2 ** 53`.
|
|
27
49
|
*
|
|
28
|
-
* @since 4.0.0
|
|
29
50
|
* @category schemas
|
|
51
|
+
* @since 4.0.0
|
|
30
52
|
*/
|
|
31
53
|
export const AutoIncrement = /*#__PURE__*/Schema.Int.check(Schema.isBetween({
|
|
32
54
|
minimum: 1,
|
|
@@ -37,18 +59,20 @@ export const AutoIncrement = /*#__PURE__*/Schema.Int.check(Schema.isBetween({
|
|
|
37
59
|
description: "Defines a valid autoIncrement key path for the IndexedDb table"
|
|
38
60
|
});
|
|
39
61
|
/**
|
|
40
|
-
*
|
|
62
|
+
* Creates an `IndexedDb` service from an `IDBFactory` and `IDBKeyRange` constructor.
|
|
63
|
+
*
|
|
41
64
|
* @category constructor
|
|
65
|
+
* @since 4.0.0
|
|
42
66
|
*/
|
|
43
67
|
export const make = impl => IndexedDb.of({
|
|
44
68
|
[TypeId]: TypeId,
|
|
45
69
|
...impl
|
|
46
70
|
});
|
|
47
71
|
/**
|
|
48
|
-
*
|
|
72
|
+
* Layer that provides `IndexedDb` from `window.indexedDB` and `window.IDBKeyRange`, failing with a config error when they are unavailable.
|
|
49
73
|
*
|
|
50
|
-
* @since 4.0.0
|
|
51
74
|
* @category constructors
|
|
75
|
+
* @since 4.0.0
|
|
52
76
|
*/
|
|
53
77
|
export const layerWindow = /*#__PURE__*/Layer.effect(IndexedDb, /*#__PURE__*/Effect.suspend(() => {
|
|
54
78
|
if (window.indexedDB && window.IDBKeyRange) {
|
|
@@ -57,9 +81,7 @@ export const layerWindow = /*#__PURE__*/Layer.effect(IndexedDb, /*#__PURE__*/Eff
|
|
|
57
81
|
IDBKeyRange: window.IDBKeyRange
|
|
58
82
|
}));
|
|
59
83
|
} else {
|
|
60
|
-
return Effect.
|
|
61
|
-
messageMissingKey: "window.indexedDB is not available"
|
|
62
|
-
}))));
|
|
84
|
+
return Effect.die(new Error("window.indexedDB is not available"));
|
|
63
85
|
}
|
|
64
86
|
}));
|
|
65
87
|
//# sourceMappingURL=IndexedDb.js.map
|
package/dist/IndexedDb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IndexedDb.js","names":["
|
|
1
|
+
{"version":3,"file":"IndexedDb.js","names":["Context","Effect","Layer","Schema","TypeId","IndexedDb","Service","IDBFlatKey","Union","String","Number","check","makeFilter","input","isNaN","DateValid","declare","ArrayBuffer","isView","buffer","IDBValidKey","Array","AutoIncrement","Int","isBetween","minimum","maximum","annotate","identifier","title","description","make","impl","of","layerWindow","effect","suspend","window","indexedDB","IDBKeyRange","succeed","die","Error"],"sources":["../src/IndexedDb.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC,MAAMC,MAAM,GAAG,qCAAqC;AAcpD;;;;;;AAMA,OAAO,MAAMC,SAAS,gBAA0CL,OAAO,CAACM,OAAO,CAAuBF,MAAM,CAAC;AAE7G;AACA,MAAMG,UAAU,gBAAGJ,MAAM,CAACK,KAAK,CAAC,CAC9BL,MAAM,CAACM,MAAM,eACbN,MAAM,CAACO,MAAM,CAACC,KAAK,cAACR,MAAM,CAACS,UAAU,CAAEC,KAAK,IAAK,CAACH,MAAM,CAACI,KAAK,CAACD,KA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AC,CAAC,CACH","ignoreList":[]}
|
|
@@ -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,SAAkB,OAAO,cAAc;CACxC;;uBAWsB,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC;0BAC1C,OAAO,UAAU,CAAC,WAAW;yBAC9B,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC;sBACnC,MAAM,CAAC,MAAM,CAAC,IAAI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