ctrl-fx 0.0.1 → 0.1.0
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/clipboard.d.ts +7 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +3 -0
- package/dist/db/effects.d.ts +78 -0
- package/dist/db/effects.d.ts.map +1 -0
- package/dist/db/effects.js +98 -0
- package/dist/db/errors.d.ts +21 -0
- package/dist/db/errors.d.ts.map +1 -0
- package/dist/db/errors.js +13 -0
- package/dist/db/index.d.ts +32 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +19 -0
- package/dist/db/keypath.d.ts +40 -0
- package/dist/db/keypath.d.ts.map +1 -0
- package/dist/db/keypath.js +20 -0
- package/dist/db/setup.d.ts +83 -0
- package/dist/db/setup.d.ts.map +1 -0
- package/dist/db/setup.js +100 -0
- package/dist/db/testdb.d.ts +19 -0
- package/dist/db/testdb.d.ts.map +1 -0
- package/dist/db/testdb.js +34 -0
- package/dist/dom/attrs.d.ts +67 -0
- package/dist/dom/attrs.d.ts.map +1 -0
- package/dist/dom/attrs.js +154 -0
- package/dist/dom/components.d.ts +43 -0
- package/dist/dom/components.d.ts.map +1 -0
- package/dist/dom/components.js +86 -0
- package/dist/dom/elems.d.ts +121 -0
- package/dist/dom/elems.d.ts.map +1 -0
- package/dist/dom/elems.js +52 -0
- package/dist/dom/events.d.ts +232 -0
- package/dist/dom/events.d.ts.map +1 -0
- package/dist/dom/events.js +289 -0
- package/dist/dom/index.d.ts +248 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +266 -0
- package/dist/dom/nodeid.d.ts +9 -0
- package/dist/dom/nodeid.d.ts.map +1 -0
- package/dist/dom/nodeid.js +27 -0
- package/dist/dom/svg.d.ts +23 -0
- package/dist/dom/svg.d.ts.map +1 -0
- package/dist/dom/svg.js +1 -0
- package/dist/dom/views.d.ts +60 -0
- package/dist/dom/views.d.ts.map +1 -0
- package/dist/dom/views.js +154 -0
- package/dist/effects.d.ts +580 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +1556 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/internal/clipboard.d.ts +5 -0
- package/dist/internal/clipboard.d.ts.map +1 -0
- package/dist/internal/clipboard.js +33 -0
- package/dist/internal/cmpmgr.d.ts +46 -0
- package/dist/internal/cmpmgr.d.ts.map +1 -0
- package/dist/internal/cmpmgr.js +561 -0
- package/dist/internal/dbmgr.d.ts +11 -0
- package/dist/internal/dbmgr.d.ts.map +1 -0
- package/dist/internal/dbmgr.js +200 -0
- package/dist/internal/dominterpreter.d.ts +5 -0
- package/dist/internal/dominterpreter.d.ts.map +1 -0
- package/dist/internal/dominterpreter.js +337 -0
- package/dist/internal/eventmgr.d.ts +41 -0
- package/dist/internal/eventmgr.d.ts.map +1 -0
- package/dist/internal/eventmgr.js +696 -0
- package/dist/internal/index.d.ts +19 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +38 -0
- package/dist/internal/interpreter.d.ts +10 -0
- package/dist/internal/interpreter.d.ts.map +1 -0
- package/dist/internal/interpreter.js +1 -0
- package/dist/internal/locutils.d.ts +4 -0
- package/dist/internal/locutils.d.ts.map +1 -0
- package/dist/internal/locutils.js +22 -0
- package/dist/internal/net.d.ts +4 -0
- package/dist/internal/net.d.ts.map +1 -0
- package/dist/internal/net.js +64 -0
- package/dist/internal/realdom.d.ts +249 -0
- package/dist/internal/realdom.d.ts.map +1 -0
- package/dist/internal/realdom.js +1 -0
- package/dist/internal/styleregistry.d.ts +6 -0
- package/dist/internal/styleregistry.d.ts.map +1 -0
- package/dist/internal/styleregistry.js +18 -0
- package/dist/internal/taskreg.d.ts +9 -0
- package/dist/internal/taskreg.d.ts.map +1 -0
- package/dist/internal/taskreg.js +28 -0
- package/dist/internal/testing.d.ts +12 -0
- package/dist/internal/testing.d.ts.map +1 -0
- package/dist/internal/testing.js +974 -0
- package/dist/internal/testinginterpreter.d.ts +10 -0
- package/dist/internal/testinginterpreter.d.ts.map +1 -0
- package/dist/internal/testinginterpreter.js +646 -0
- package/dist/internal/vdom.d.ts +93 -0
- package/dist/internal/vdom.d.ts.map +1 -0
- package/dist/internal/vdom.js +470 -0
- package/dist/json/index.d.ts +5 -0
- package/dist/json/index.d.ts.map +1 -0
- package/dist/json/index.js +2 -0
- package/dist/json/validation.d.ts +28 -0
- package/dist/json/validation.d.ts.map +1 -0
- package/dist/json/validation.js +8 -0
- package/dist/net/fragment.d.ts +10 -0
- package/dist/net/fragment.d.ts.map +1 -0
- package/dist/net/fragment.js +27 -0
- package/dist/net/index.d.ts +42 -0
- package/dist/net/index.d.ts.map +1 -0
- package/dist/net/index.js +60 -0
- package/dist/net/location.d.ts +21 -0
- package/dist/net/location.d.ts.map +1 -0
- package/dist/net/location.js +41 -0
- package/dist/net/path.d.ts +12 -0
- package/dist/net/path.d.ts.map +1 -0
- package/dist/net/path.js +29 -0
- package/dist/net/queryparam.d.ts +10 -0
- package/dist/net/queryparam.d.ts.map +1 -0
- package/dist/net/queryparam.js +34 -0
- package/dist/router.d.ts +40 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +77 -0
- package/dist/scroll.d.ts +7 -0
- package/dist/scroll.d.ts.map +1 -0
- package/dist/scroll.js +3 -0
- package/dist/testing.d.ts +248 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +159 -0
- package/dist/utils/apply.d.ts +9 -0
- package/dist/utils/apply.d.ts.map +1 -0
- package/dist/utils/apply.js +10 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +138 -0
- package/dist/utils/lens.d.ts +18 -0
- package/dist/utils/lens.d.ts.map +1 -0
- package/dist/utils/lens.js +27 -0
- package/dist/utils/match.d.ts +17 -0
- package/dist/utils/match.d.ts.map +1 -0
- package/dist/utils/match.js +28 -0
- package/dist/utils/result.d.ts +47 -0
- package/dist/utils/result.d.ts.map +1 -0
- package/dist/utils/result.js +97 -0
- package/dist/webcomponent.d.ts +15 -0
- package/dist/webcomponent.d.ts.map +1 -0
- package/dist/webcomponent.js +43 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ClipboardError = {
|
|
2
|
+
_type: 'ClipboardError';
|
|
3
|
+
cause: 'NotAllowed' | 'NotSupported' | 'UnexpectedError';
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function clipboardError(cause: ClipboardError['cause'], message: string): ClipboardError;
|
|
7
|
+
//# sourceMappingURL=clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,gBAAgB,CAAA;IACvB,KAAK,EAAE,YAAY,GAAG,cAAc,GAAG,iBAAiB,CAAA;IACxD,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,EAC9B,OAAO,EAAE,MAAM,GACd,cAAc,CAEhB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { JsonValue } from '../json';
|
|
2
|
+
import type { ObjectStore } from './index';
|
|
3
|
+
type DbAdd = {
|
|
4
|
+
readonly _type: 'Add';
|
|
5
|
+
readonly objectStore: ObjectStore;
|
|
6
|
+
readonly value: JsonValue;
|
|
7
|
+
};
|
|
8
|
+
type DbPut = {
|
|
9
|
+
readonly _type: 'Put';
|
|
10
|
+
readonly objectStore: ObjectStore;
|
|
11
|
+
readonly value: JsonValue;
|
|
12
|
+
};
|
|
13
|
+
type DbGet = {
|
|
14
|
+
readonly _type: 'Get';
|
|
15
|
+
readonly objectStore: ObjectStore;
|
|
16
|
+
readonly key: IDBValidKey;
|
|
17
|
+
};
|
|
18
|
+
type DbGetAll = {
|
|
19
|
+
readonly _type: 'GetAll';
|
|
20
|
+
readonly objectStore: ObjectStore;
|
|
21
|
+
};
|
|
22
|
+
type DbDelete = {
|
|
23
|
+
readonly _type: 'Delete';
|
|
24
|
+
readonly objectStore: ObjectStore;
|
|
25
|
+
readonly key: IDBValidKey;
|
|
26
|
+
};
|
|
27
|
+
type DbCount = {
|
|
28
|
+
readonly _type: 'Count';
|
|
29
|
+
readonly objectStore: ObjectStore;
|
|
30
|
+
};
|
|
31
|
+
export type DbOperation = DbAdd | DbPut | DbGet | DbGetAll | DbDelete | DbCount;
|
|
32
|
+
type DbReturn<A> = {
|
|
33
|
+
readonly _type: 'Return';
|
|
34
|
+
readonly value: A;
|
|
35
|
+
flatMap<B>(f: (a: A) => DbEffect<B>): DbEffect<B>;
|
|
36
|
+
map<B>(f: (a: A) => B): DbEffect<B>;
|
|
37
|
+
as<B>(b: B): DbEffect<B>;
|
|
38
|
+
void(): DbEffect<void>;
|
|
39
|
+
};
|
|
40
|
+
type DbSuspend<A> = {
|
|
41
|
+
readonly _type: 'Suspend';
|
|
42
|
+
readonly operation: DbOperation;
|
|
43
|
+
flatMap<B>(f: (a: A) => DbEffect<B>): DbEffect<B>;
|
|
44
|
+
map<B>(f: (a: A) => B): DbEffect<B>;
|
|
45
|
+
as<B>(b: B): DbEffect<B>;
|
|
46
|
+
void(): DbEffect<void>;
|
|
47
|
+
};
|
|
48
|
+
type DbChain<A> = {
|
|
49
|
+
readonly _type: 'FlatMap';
|
|
50
|
+
readonly effect: DbEffect<any>;
|
|
51
|
+
readonly next: (x: any) => DbEffect<A>;
|
|
52
|
+
flatMap<B>(f: (a: A) => DbEffect<B>): DbEffect<B>;
|
|
53
|
+
map<B>(f: (a: A) => B): DbEffect<B>;
|
|
54
|
+
as<B>(b: B): DbEffect<B>;
|
|
55
|
+
void(): DbEffect<void>;
|
|
56
|
+
};
|
|
57
|
+
/** A lazy, composable IndexedDB operation that produces a value of type `A`. Chain with `.flatMap`. */
|
|
58
|
+
export type DbEffect<A> = DbReturn<A> | DbSuspend<A> | DbChain<A>;
|
|
59
|
+
/** Lifts a plain value into a `DbEffect` without performing any database operation. */
|
|
60
|
+
export declare function pure<A>(a: A): DbEffect<A>;
|
|
61
|
+
/** A `DbEffect` that does nothing. Useful as a no-op in conditional chains. */
|
|
62
|
+
export declare function noop(): DbEffect<void>;
|
|
63
|
+
/** Runs a `DbEffect` against an interpreter callback. Called by the framework; not needed in application code. */
|
|
64
|
+
export declare function run<A>(effect: DbEffect<A>, interpreter: (op: DbOperation, onComplete: (a: A) => void) => void, onComplete: (a: A) => void): void;
|
|
65
|
+
/** A DbEffect describing an insert of `value` into `objectStore`. Fails if a record with the same key already exists. */
|
|
66
|
+
export declare function add(objectStore: ObjectStore, value: JsonValue): DbEffect<void>;
|
|
67
|
+
/** A DbEffect describing an insert-or-replace of `value` in `objectStore` (upsert). */
|
|
68
|
+
export declare function put(objectStore: ObjectStore, value: JsonValue): DbEffect<void>;
|
|
69
|
+
/** A DbEffect describing a retrieval of the record with `key` from `objectStore`, or `undefined` if not found. */
|
|
70
|
+
export declare function get(objectStore: ObjectStore, key: IDBValidKey): DbEffect<JsonValue | undefined>;
|
|
71
|
+
/** A DbEffect describing a retrieval of all records from `objectStore`. */
|
|
72
|
+
export declare function getAll(objectStore: ObjectStore): DbEffect<JsonValue[]>;
|
|
73
|
+
/** A DbEffect describing the deletion of the record with `key` from `objectStore`. */
|
|
74
|
+
export declare function deleteRecord(objectStore: ObjectStore, key: IDBValidKey): DbEffect<void>;
|
|
75
|
+
/** A DbEffect describing a record count in `objectStore`. */
|
|
76
|
+
export declare function count(objectStore: ObjectStore): DbEffect<number>;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.d.ts","sourceRoot":"","sources":["../../src/db/effects.ts"],"names":[],"mappings":"AAAA,O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,EAAE,WAAW,GACf,QAAQ,CAAC,SAAS,GAAG,SAAS,CAAC,CAEjC;AAED,2EAA2E;AAC3E,wBAAgB,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,CAEtE;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAC1B,WAAW,EAAE,WAAW,EACxB,GAAG,EAAE,WAAW,GACf,QAAQ,CAAC,IAAI,CAAC,CAEhB;AAED,6DAA6D;AAC7D,wBAAgB,KAAK,CAAC,WAAW,EAAE,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,CAEhE"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
function chain(effect, next) {
|
|
2
|
+
return {
|
|
3
|
+
_type: 'FlatMap',
|
|
4
|
+
effect,
|
|
5
|
+
next,
|
|
6
|
+
flatMap(f) {
|
|
7
|
+
return chain(this, f);
|
|
8
|
+
},
|
|
9
|
+
map(f) {
|
|
10
|
+
return chain(this, b => ret(f(b)));
|
|
11
|
+
},
|
|
12
|
+
as(c) {
|
|
13
|
+
return chain(this, _ => ret(c));
|
|
14
|
+
},
|
|
15
|
+
void() {
|
|
16
|
+
return this.map(_ => { });
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function ret(value) {
|
|
21
|
+
return {
|
|
22
|
+
_type: 'Return',
|
|
23
|
+
value,
|
|
24
|
+
flatMap(f) {
|
|
25
|
+
return chain(this, f);
|
|
26
|
+
},
|
|
27
|
+
map(f) {
|
|
28
|
+
return chain(this, a => ret(f(a)));
|
|
29
|
+
},
|
|
30
|
+
as(b) {
|
|
31
|
+
return chain(this, _ => ret(b));
|
|
32
|
+
},
|
|
33
|
+
void() {
|
|
34
|
+
return this.map(_ => { });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function suspend(operation) {
|
|
39
|
+
return {
|
|
40
|
+
_type: 'Suspend',
|
|
41
|
+
operation,
|
|
42
|
+
flatMap(f) {
|
|
43
|
+
return chain(this, f);
|
|
44
|
+
},
|
|
45
|
+
map(f) {
|
|
46
|
+
return chain(this, a => ret(f(a)));
|
|
47
|
+
},
|
|
48
|
+
as(b) {
|
|
49
|
+
return chain(this, _ => ret(b));
|
|
50
|
+
},
|
|
51
|
+
void() {
|
|
52
|
+
return this.map(_ => { });
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Lifts a plain value into a `DbEffect` without performing any database operation. */
|
|
57
|
+
export function pure(a) {
|
|
58
|
+
return ret(a);
|
|
59
|
+
}
|
|
60
|
+
/** A `DbEffect` that does nothing. Useful as a no-op in conditional chains. */
|
|
61
|
+
export function noop() {
|
|
62
|
+
return ret(undefined);
|
|
63
|
+
}
|
|
64
|
+
/** Runs a `DbEffect` against an interpreter callback. Called by the framework; not needed in application code. */
|
|
65
|
+
export function run(effect, interpreter, onComplete) {
|
|
66
|
+
switch (effect._type) {
|
|
67
|
+
case 'Return':
|
|
68
|
+
return onComplete(effect.value);
|
|
69
|
+
case 'Suspend':
|
|
70
|
+
return interpreter(effect.operation, onComplete);
|
|
71
|
+
case 'FlatMap':
|
|
72
|
+
return run(effect.effect, interpreter, result => run(effect.next(result), interpreter, onComplete));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** A DbEffect describing an insert of `value` into `objectStore`. Fails if a record with the same key already exists. */
|
|
76
|
+
export function add(objectStore, value) {
|
|
77
|
+
return suspend({ _type: 'Add', objectStore, value });
|
|
78
|
+
}
|
|
79
|
+
/** A DbEffect describing an insert-or-replace of `value` in `objectStore` (upsert). */
|
|
80
|
+
export function put(objectStore, value) {
|
|
81
|
+
return suspend({ _type: 'Put', objectStore, value });
|
|
82
|
+
}
|
|
83
|
+
/** A DbEffect describing a retrieval of the record with `key` from `objectStore`, or `undefined` if not found. */
|
|
84
|
+
export function get(objectStore, key) {
|
|
85
|
+
return suspend({ _type: 'Get', objectStore, key });
|
|
86
|
+
}
|
|
87
|
+
/** A DbEffect describing a retrieval of all records from `objectStore`. */
|
|
88
|
+
export function getAll(objectStore) {
|
|
89
|
+
return suspend({ _type: 'GetAll', objectStore });
|
|
90
|
+
}
|
|
91
|
+
/** A DbEffect describing the deletion of the record with `key` from `objectStore`. */
|
|
92
|
+
export function deleteRecord(objectStore, key) {
|
|
93
|
+
return suspend({ _type: 'Delete', objectStore, key });
|
|
94
|
+
}
|
|
95
|
+
/** A DbEffect describing a record count in `objectStore`. */
|
|
96
|
+
export function count(objectStore) {
|
|
97
|
+
return suspend({ _type: 'Count', objectStore });
|
|
98
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type DbError = UnexpectedError | NotFoundError | ConstraintError;
|
|
2
|
+
export interface UnexpectedError {
|
|
3
|
+
readonly _type: 'UnexpectedError';
|
|
4
|
+
readonly message?: string;
|
|
5
|
+
readonly cause?: Error;
|
|
6
|
+
}
|
|
7
|
+
export interface NotFoundError {
|
|
8
|
+
readonly _type: 'NotFoundError';
|
|
9
|
+
readonly cause: Error;
|
|
10
|
+
}
|
|
11
|
+
export interface ConstraintError {
|
|
12
|
+
readonly _type: 'ConstraintError';
|
|
13
|
+
readonly cause: Error;
|
|
14
|
+
}
|
|
15
|
+
export declare function unexpectedError(params: {
|
|
16
|
+
cause?: Error;
|
|
17
|
+
message?: string;
|
|
18
|
+
}): DbError;
|
|
19
|
+
export declare function notFoundError(cause: Error): DbError;
|
|
20
|
+
export declare function constraintError(cause: Error): DbError;
|
|
21
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/db/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,eAAe,GAAG,aAAa,GAAG,eAAe,CAAA;AAEvE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAA;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CACtB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAA;IACjC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CACtB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,OAAO,CAMV;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEnD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function unexpectedError(params) {
|
|
2
|
+
return {
|
|
3
|
+
_type: 'UnexpectedError',
|
|
4
|
+
cause: params.cause,
|
|
5
|
+
message: params.message,
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function notFoundError(cause) {
|
|
9
|
+
return { _type: 'NotFoundError', cause };
|
|
10
|
+
}
|
|
11
|
+
export function constraintError(cause) {
|
|
12
|
+
return { _type: 'ConstraintError', cause };
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Branded string representing an IndexedDB database name. */
|
|
2
|
+
export type DbName = string & {
|
|
3
|
+
__brand: 'DbName';
|
|
4
|
+
};
|
|
5
|
+
/** Creates a `DbName`. */
|
|
6
|
+
export declare function dbName(value: string): DbName;
|
|
7
|
+
/** Branded number representing an IndexedDB database schema version. */
|
|
8
|
+
export type DbVersion = number & {
|
|
9
|
+
__brand: 'DbVersion';
|
|
10
|
+
};
|
|
11
|
+
/** Creates a `DbVersion`. */
|
|
12
|
+
export declare function dbVersion(value: number): DbVersion;
|
|
13
|
+
/** Branded string representing the name of an IndexedDB object store. */
|
|
14
|
+
export type ObjectStore = string & {
|
|
15
|
+
__brand: 'ObjectStore';
|
|
16
|
+
};
|
|
17
|
+
/** Creates an `ObjectStore` name. */
|
|
18
|
+
export declare function objectStore(value: string): ObjectStore;
|
|
19
|
+
/** Branded string representing the name of an IndexedDB index. */
|
|
20
|
+
export type Index = string & {
|
|
21
|
+
__brand: 'Index';
|
|
22
|
+
};
|
|
23
|
+
/** Creates an `Index` name. */
|
|
24
|
+
export declare function index(value: string): Index;
|
|
25
|
+
export type { DbEffect } from './effects';
|
|
26
|
+
export { add, count, deleteRecord, get, getAll, noop as dbNoop, pure as dbPure, put, } from './effects';
|
|
27
|
+
export type { DbSetupEffect } from './setup';
|
|
28
|
+
export { createIndex, createObjectStore, deleteIndex, deleteObjectStore, getIndexNames, getObjectStoreNames, runDbEffect, } from './setup';
|
|
29
|
+
export type { DbError, UnexpectedError, NotFoundError, ConstraintError, } from './errors';
|
|
30
|
+
export { autoIncrementPath, type AutoIncrementPath, type IndexKeyPath, type KeyPath, type ManualPath, type MultiIndexPath, type MultiPath, type SingleIndexPath, manualPath, multiIndexPath, multiPath, singleIndexPath, } from './keypath';
|
|
31
|
+
export type { JsonValue, JsonPrimitive } from '../json';
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAA;AAEnD,0BAA0B;AAC1B,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,wEAAwE;AACxE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAA;A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DbName`. */
|
|
2
|
+
export function dbName(value) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
/** Creates a `DbVersion`. */
|
|
6
|
+
export function dbVersion(value) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
/** Creates an `ObjectStore` name. */
|
|
10
|
+
export function objectStore(value) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
/** Creates an `Index` name. */
|
|
14
|
+
export function index(value) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export { add, count, deleteRecord, get, getAll, noop as dbNoop, pure as dbPure, put, } from './effects';
|
|
18
|
+
export { createIndex, createObjectStore, deleteIndex, deleteObjectStore, getIndexNames, getObjectStoreNames, runDbEffect, } from './setup';
|
|
19
|
+
export { autoIncrementPath, manualPath, multiIndexPath, multiPath, singleIndexPath, } from './keypath';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type AutoIncrementPath = {
|
|
2
|
+
readonly _type: 'AutoIncrement';
|
|
3
|
+
readonly value: string;
|
|
4
|
+
};
|
|
5
|
+
export type ManualPath = {
|
|
6
|
+
readonly _type: 'Manual';
|
|
7
|
+
readonly value: string;
|
|
8
|
+
};
|
|
9
|
+
export type MultiPath = {
|
|
10
|
+
readonly _type: 'Multi';
|
|
11
|
+
readonly first: string;
|
|
12
|
+
readonly second: string;
|
|
13
|
+
readonly rest: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
/** Describes how an object store's primary key is derived from stored values. */
|
|
16
|
+
export type KeyPath = AutoIncrementPath | ManualPath | MultiPath;
|
|
17
|
+
/** Key is stored under `value` and auto-incremented by IndexedDB if absent. */
|
|
18
|
+
export declare function autoIncrementPath(value: string): KeyPath;
|
|
19
|
+
/** Key is read from the `value` property of each stored object; caller must provide it. */
|
|
20
|
+
export declare function manualPath(value: string): KeyPath;
|
|
21
|
+
/** Key is a compound of two or more property paths. */
|
|
22
|
+
export declare function multiPath(first: string, second: string, ...rest: string[]): KeyPath;
|
|
23
|
+
export type SingleIndexPath = {
|
|
24
|
+
readonly _type: 'SingleIndex';
|
|
25
|
+
readonly value: string;
|
|
26
|
+
};
|
|
27
|
+
export type MultiIndexPath = {
|
|
28
|
+
readonly _type: 'MultiIndex';
|
|
29
|
+
readonly first: string;
|
|
30
|
+
readonly second: string;
|
|
31
|
+
readonly rest: readonly string[];
|
|
32
|
+
readonly multiEntry: boolean;
|
|
33
|
+
};
|
|
34
|
+
/** Describes how an IndexedDB index key is derived from stored values. */
|
|
35
|
+
export type IndexKeyPath = SingleIndexPath | MultiIndexPath;
|
|
36
|
+
/** Index key is read from a single property. */
|
|
37
|
+
export declare function singleIndexPath(value: string): IndexKeyPath;
|
|
38
|
+
/** Index key is a compound of two or more properties. Set `multiEntry: true` to index array values individually. */
|
|
39
|
+
export declare function multiIndexPath(first: string, second: string, rest: readonly string[], multiEntry: boolean): IndexKeyPath;
|
|
40
|
+
//# sourceMappingURL=keypath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keypath.d.ts","sourceRoot":"","sources":["../../src/db/keypath.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC,CAAA;AAED,iFAAiF;AACjF,MAAM,MAAM,OAAO,GAAG,iBAAiB,GAAG,UAAU,GAAG,SAAS,CAAA;AAEhE,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,2FAA2F;AAC3F,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,uDAAuD;AACvD,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,GAAG,IAAI,EAAE,MAAM,EAAE,GAChB,OAAO,CAET;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IAChC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,0EAA0E;AAC1E,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,cAAc,CAAA;AAE3D,gDAAgD;AAChD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAE3D;AAED,oHAAoH;AACpH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,UAAU,EAAE,OAAO,GAClB,YAAY,CAEd"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Key is stored under `value` and auto-incremented by IndexedDB if absent. */
|
|
2
|
+
export function autoIncrementPath(value) {
|
|
3
|
+
return { _type: 'AutoIncrement', value };
|
|
4
|
+
}
|
|
5
|
+
/** Key is read from the `value` property of each stored object; caller must provide it. */
|
|
6
|
+
export function manualPath(value) {
|
|
7
|
+
return { _type: 'Manual', value };
|
|
8
|
+
}
|
|
9
|
+
/** Key is a compound of two or more property paths. */
|
|
10
|
+
export function multiPath(first, second, ...rest) {
|
|
11
|
+
return { _type: 'Multi', first, second, rest };
|
|
12
|
+
}
|
|
13
|
+
/** Index key is read from a single property. */
|
|
14
|
+
export function singleIndexPath(value) {
|
|
15
|
+
return { _type: 'SingleIndex', value };
|
|
16
|
+
}
|
|
17
|
+
/** Index key is a compound of two or more properties. Set `multiEntry: true` to index array values individually. */
|
|
18
|
+
export function multiIndexPath(first, second, rest, multiEntry) {
|
|
19
|
+
return { _type: 'MultiIndex', first, second, rest, multiEntry };
|
|
20
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { DbEffect, DbOperation } from './effects';
|
|
2
|
+
import type { Index, ObjectStore } from './index';
|
|
3
|
+
import type { IndexKeyPath, KeyPath } from './keypath';
|
|
4
|
+
type CreateObjectStore = {
|
|
5
|
+
readonly _type: 'CreateObjectStore';
|
|
6
|
+
readonly objectStore: ObjectStore;
|
|
7
|
+
readonly keyPath: KeyPath;
|
|
8
|
+
};
|
|
9
|
+
type CreateIndex = {
|
|
10
|
+
readonly _type: 'CreateIndex';
|
|
11
|
+
readonly objectStore: ObjectStore;
|
|
12
|
+
readonly index: Index;
|
|
13
|
+
readonly keyPath: IndexKeyPath;
|
|
14
|
+
readonly unique: boolean;
|
|
15
|
+
};
|
|
16
|
+
type DeleteObjectStore = {
|
|
17
|
+
readonly _type: 'DeleteObjectStore';
|
|
18
|
+
readonly objectStore: ObjectStore;
|
|
19
|
+
};
|
|
20
|
+
type DeleteIndex = {
|
|
21
|
+
readonly _type: 'DeleteIndex';
|
|
22
|
+
readonly objectStore: ObjectStore;
|
|
23
|
+
readonly index: Index;
|
|
24
|
+
};
|
|
25
|
+
type GetObjectStoreNames = {
|
|
26
|
+
readonly _type: 'GetObjectStoreNames';
|
|
27
|
+
};
|
|
28
|
+
type GetIndexNames = {
|
|
29
|
+
readonly _type: 'GetIndexNames';
|
|
30
|
+
readonly objectStore: ObjectStore;
|
|
31
|
+
};
|
|
32
|
+
type RunDbEffect = {
|
|
33
|
+
readonly _type: 'RunDbEffect';
|
|
34
|
+
readonly effect: DbEffect<void>;
|
|
35
|
+
};
|
|
36
|
+
export type DbSetupOperation = CreateObjectStore | CreateIndex | DeleteObjectStore | DeleteIndex | GetObjectStoreNames | GetIndexNames | RunDbEffect;
|
|
37
|
+
type DbSetupReturn<A> = {
|
|
38
|
+
readonly _type: 'Return';
|
|
39
|
+
readonly value: A;
|
|
40
|
+
flatMap<B>(f: (a: A) => DbSetupEffect<B>): DbSetupEffect<B>;
|
|
41
|
+
map<B>(f: (a: A) => B): DbSetupEffect<B>;
|
|
42
|
+
as<B>(b: B): DbSetupEffect<B>;
|
|
43
|
+
void(): DbSetupEffect<void>;
|
|
44
|
+
};
|
|
45
|
+
type DbSetupSuspend<A> = {
|
|
46
|
+
readonly _type: 'Suspend';
|
|
47
|
+
readonly operation: DbSetupOperation;
|
|
48
|
+
flatMap<B>(f: (a: A) => DbSetupEffect<B>): DbSetupEffect<B>;
|
|
49
|
+
map<B>(f: (a: A) => B): DbSetupEffect<B>;
|
|
50
|
+
as<B>(b: B): DbSetupEffect<B>;
|
|
51
|
+
void(): DbSetupEffect<void>;
|
|
52
|
+
};
|
|
53
|
+
type DbSetupChain<A> = {
|
|
54
|
+
readonly _type: 'FlatMap';
|
|
55
|
+
readonly effect: DbSetupEffect<any>;
|
|
56
|
+
readonly next: (x: any) => DbSetupEffect<A>;
|
|
57
|
+
flatMap<B>(f: (a: A) => DbSetupEffect<B>): DbSetupEffect<B>;
|
|
58
|
+
map<B>(f: (a: A) => B): DbSetupEffect<B>;
|
|
59
|
+
as<B>(b: B): DbSetupEffect<B>;
|
|
60
|
+
void(): DbSetupEffect<void>;
|
|
61
|
+
};
|
|
62
|
+
/** A lazy schema-migration operation that produces a value of type `A`. Run via `runDbEffect`. */
|
|
63
|
+
export type DbSetupEffect<A> = DbSetupReturn<A> | DbSetupSuspend<A> | DbSetupChain<A>;
|
|
64
|
+
export declare function pure<A>(a: A): DbSetupEffect<A>;
|
|
65
|
+
export declare function noop(): DbSetupEffect<void>;
|
|
66
|
+
/** Runs a `DbSetupEffect` against an interpreter callback. Called by the framework; not needed in application code. */
|
|
67
|
+
export declare function run<A>(effect: DbSetupEffect<A>, interpreter: (op: DbSetupOperation, onComplete: (a: A) => void) => void, onComplete: (a: A) => void): void;
|
|
68
|
+
/** A DbSetupEffect describing the creation of a new object store with the given key path. */
|
|
69
|
+
export declare function createObjectStore(objectStore: ObjectStore, keyPath: KeyPath): DbSetupEffect<void>;
|
|
70
|
+
/** A DbSetupEffect describing the creation of an index on an object store. */
|
|
71
|
+
export declare function createIndex(objectStore: ObjectStore, index: Index, keyPath: IndexKeyPath, unique: boolean): DbSetupEffect<void>;
|
|
72
|
+
/** A DbSetupEffect describing the deletion of an object store. */
|
|
73
|
+
export declare function deleteObjectStore(objectStore: ObjectStore): DbSetupEffect<void>;
|
|
74
|
+
/** A DbSetupEffect describing the deletion of an index from an object store. */
|
|
75
|
+
export declare function deleteIndex(objectStore: ObjectStore, index: Index): DbSetupEffect<void>;
|
|
76
|
+
/** A DbSetupEffect describing a read of all object store names in the database. */
|
|
77
|
+
export declare function getObjectStoreNames(): DbSetupEffect<readonly string[]>;
|
|
78
|
+
/** A DbSetupEffect describing a read of all index names on the given object store. */
|
|
79
|
+
export declare function getIndexNames(objectStore: ObjectStore): DbSetupEffect<readonly string[]>;
|
|
80
|
+
/** A DbSetupEffect describing the embedding of a `DbEffect` inside a setup operation, useful for seeding data during an upgrade. */
|
|
81
|
+
export declare function runDbEffect(effect: DbEffect<void>): DbSetupEffect<void>;
|
|
82
|
+
export type { DbOperation };
|
|
83
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot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CAC/B,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,GACf,aAAa,CAAC,IAAI,CAAC,CAErB;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CACzB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,OAAO,GACd,aAAa,CAAC,IAAI,CAAC,CAErB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,WAAW,GACvB,aAAa,CAAC,IAAI,CAAC,CAErB;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CACzB,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,GACX,aAAa,CAAC,IAAI,CAAC,CAErB;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,IAAI,aAAa,CAAC,SAAS,MAAM,EAAE,CAAC,CAEtE;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAC3B,WAAW,EAAE,WAAW,GACvB,aAAa,CAAC,SAAS,MAAM,EAAE,CAAC,CAElC;AAED,oIAAoI;AACpI,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAEvE;AAED,YAAY,EAAE,WAAW,EAAE,CAAA"}
|
package/dist/db/setup.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
function chain(effect, next) {
|
|
2
|
+
return {
|
|
3
|
+
_type: 'FlatMap',
|
|
4
|
+
effect,
|
|
5
|
+
next,
|
|
6
|
+
flatMap(f) {
|
|
7
|
+
return chain(this, f);
|
|
8
|
+
},
|
|
9
|
+
map(f) {
|
|
10
|
+
return chain(this, b => ret(f(b)));
|
|
11
|
+
},
|
|
12
|
+
as(c) {
|
|
13
|
+
return chain(this, _ => ret(c));
|
|
14
|
+
},
|
|
15
|
+
void() {
|
|
16
|
+
return this.map(_ => { });
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function ret(value) {
|
|
21
|
+
return {
|
|
22
|
+
_type: 'Return',
|
|
23
|
+
value,
|
|
24
|
+
flatMap(f) {
|
|
25
|
+
return chain(this, f);
|
|
26
|
+
},
|
|
27
|
+
map(f) {
|
|
28
|
+
return chain(this, a => ret(f(a)));
|
|
29
|
+
},
|
|
30
|
+
as(b) {
|
|
31
|
+
return chain(this, _ => ret(b));
|
|
32
|
+
},
|
|
33
|
+
void() {
|
|
34
|
+
return this.map(_ => { });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function suspend(operation) {
|
|
39
|
+
return {
|
|
40
|
+
_type: 'Suspend',
|
|
41
|
+
operation,
|
|
42
|
+
flatMap(f) {
|
|
43
|
+
return chain(this, f);
|
|
44
|
+
},
|
|
45
|
+
map(f) {
|
|
46
|
+
return chain(this, a => ret(f(a)));
|
|
47
|
+
},
|
|
48
|
+
as(b) {
|
|
49
|
+
return chain(this, _ => ret(b));
|
|
50
|
+
},
|
|
51
|
+
void() {
|
|
52
|
+
return this.map(_ => { });
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function pure(a) {
|
|
57
|
+
return ret(a);
|
|
58
|
+
}
|
|
59
|
+
export function noop() {
|
|
60
|
+
return ret(undefined);
|
|
61
|
+
}
|
|
62
|
+
/** Runs a `DbSetupEffect` against an interpreter callback. Called by the framework; not needed in application code. */
|
|
63
|
+
export function run(effect, interpreter, onComplete) {
|
|
64
|
+
switch (effect._type) {
|
|
65
|
+
case 'Return':
|
|
66
|
+
return onComplete(effect.value);
|
|
67
|
+
case 'Suspend':
|
|
68
|
+
return interpreter(effect.operation, onComplete);
|
|
69
|
+
case 'FlatMap':
|
|
70
|
+
return run(effect.effect, interpreter, result => run(effect.next(result), interpreter, onComplete));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** A DbSetupEffect describing the creation of a new object store with the given key path. */
|
|
74
|
+
export function createObjectStore(objectStore, keyPath) {
|
|
75
|
+
return suspend({ _type: 'CreateObjectStore', objectStore, keyPath });
|
|
76
|
+
}
|
|
77
|
+
/** A DbSetupEffect describing the creation of an index on an object store. */
|
|
78
|
+
export function createIndex(objectStore, index, keyPath, unique) {
|
|
79
|
+
return suspend({ _type: 'CreateIndex', objectStore, index, keyPath, unique });
|
|
80
|
+
}
|
|
81
|
+
/** A DbSetupEffect describing the deletion of an object store. */
|
|
82
|
+
export function deleteObjectStore(objectStore) {
|
|
83
|
+
return suspend({ _type: 'DeleteObjectStore', objectStore });
|
|
84
|
+
}
|
|
85
|
+
/** A DbSetupEffect describing the deletion of an index from an object store. */
|
|
86
|
+
export function deleteIndex(objectStore, index) {
|
|
87
|
+
return suspend({ _type: 'DeleteIndex', objectStore, index });
|
|
88
|
+
}
|
|
89
|
+
/** A DbSetupEffect describing a read of all object store names in the database. */
|
|
90
|
+
export function getObjectStoreNames() {
|
|
91
|
+
return suspend({ _type: 'GetObjectStoreNames' });
|
|
92
|
+
}
|
|
93
|
+
/** A DbSetupEffect describing a read of all index names on the given object store. */
|
|
94
|
+
export function getIndexNames(objectStore) {
|
|
95
|
+
return suspend({ _type: 'GetIndexNames', objectStore });
|
|
96
|
+
}
|
|
97
|
+
/** A DbSetupEffect describing the embedding of a `DbEffect` inside a setup operation, useful for seeding data during an upgrade. */
|
|
98
|
+
export function runDbEffect(effect) {
|
|
99
|
+
return suspend({ _type: 'RunDbEffect', effect });
|
|
100
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JsonValue } from '../json';
|
|
2
|
+
import type { KeyPath } from './keypath';
|
|
3
|
+
import type { DbName, ObjectStore } from './index';
|
|
4
|
+
export type DbStoreSnapshot = {
|
|
5
|
+
readonly keyPath: KeyPath;
|
|
6
|
+
readonly records: ReadonlyMap<string, JsonValue>;
|
|
7
|
+
readonly autoIncrementCounter: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function serializeIdbKey(key: IDBValidKey): string;
|
|
10
|
+
export declare class TestDatabaseData {
|
|
11
|
+
readonly _databases: ReadonlyMap<string, ReadonlyMap<string, DbStoreSnapshot>>;
|
|
12
|
+
constructor(databases: ReadonlyMap<string, ReadonlyMap<string, DbStoreSnapshot>>);
|
|
13
|
+
records(db: DbName, store: ObjectStore): readonly JsonValue[];
|
|
14
|
+
getByKey(db: DbName, store: ObjectStore, key: IDBValidKey): JsonValue | undefined;
|
|
15
|
+
size(db: DbName, store: ObjectStore): number;
|
|
16
|
+
hasDatabase(db: DbName): boolean;
|
|
17
|
+
hasStore(db: DbName, store: ObjectStore): boolean;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=testdb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testdb.d.ts","sourceRoot":"","sources":["../../src/db/testdb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;IAChD,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAA;CACtC,CAAA;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAGxD;AAED,qBAAa,gBAAgB;IAC3B,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAA;gBAG5E,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAKtE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,SAAS,SAAS,EAAE;IAI7D,QAAQ,CACN,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,WAAW,GACf,SAAS,GAAG,SAAS;IAOxB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM;IAI5C,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIhC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO;CAGlD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function serializeIdbKey(key) {
|
|
2
|
+
if (key instanceof Date)
|
|
3
|
+
return key.toISOString();
|
|
4
|
+
return JSON.stringify(key);
|
|
5
|
+
}
|
|
6
|
+
export class TestDatabaseData {
|
|
7
|
+
constructor(databases) {
|
|
8
|
+
Object.defineProperty(this, "_databases", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
this._databases = databases;
|
|
15
|
+
}
|
|
16
|
+
records(db, store) {
|
|
17
|
+
return [...(this._databases.get(db)?.get(store)?.records.values() ?? [])];
|
|
18
|
+
}
|
|
19
|
+
getByKey(db, store, key) {
|
|
20
|
+
return this._databases
|
|
21
|
+
.get(db)
|
|
22
|
+
?.get(store)
|
|
23
|
+
?.records.get(serializeIdbKey(key));
|
|
24
|
+
}
|
|
25
|
+
size(db, store) {
|
|
26
|
+
return this._databases.get(db)?.get(store)?.records.size ?? 0;
|
|
27
|
+
}
|
|
28
|
+
hasDatabase(db) {
|
|
29
|
+
return this._databases.has(db);
|
|
30
|
+
}
|
|
31
|
+
hasStore(db, store) {
|
|
32
|
+
return this._databases.get(db)?.has(store) ?? false;
|
|
33
|
+
}
|
|
34
|
+
}
|