@indietabletop/appkit 6.1.5 → 7.0.0-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/AppConfig/AppConfig.d.ts +29 -0
- package/dist/AuthCard/AuthCard.d.ts +10 -0
- package/dist/AuthCard/AuthCard.stories.d.ts +34 -0
- package/dist/AuthCard/style.css.d.ts +23 -0
- package/dist/DialogTrigger/index.d.ts +13 -0
- package/dist/DocumentTitle/DocumentTitle.d.ts +3 -0
- package/dist/EnumMapper.d.ts +25 -0
- package/dist/ExternalLink.d.ts +3 -0
- package/dist/FullscreenDismissBlocker.d.ts +5 -0
- package/{lib/HistoryState.ts → dist/HistoryState.d.ts} +2 -5
- package/dist/IndieTabletopClubLogo.d.ts +7 -0
- package/dist/IndieTabletopClubSymbol.d.ts +7 -0
- package/dist/InfoPage/index.d.ts +8 -0
- package/dist/InfoPage/pages.d.ts +2 -0
- package/dist/InfoPage/style.css.d.ts +5 -0
- package/dist/Letterhead/index.d.ts +19 -0
- package/dist/Letterhead/stories.d.ts +13 -0
- package/dist/Letterhead/style.css.d.ts +46 -0
- package/dist/LetterheadForm/LetterheadReadonlyTextField.stories.d.ts +17 -0
- package/dist/LetterheadForm/LetterheadSubmitError.stories.d.ts +11 -0
- package/dist/LetterheadForm/LetterheadTextField.stories.d.ts +336 -0
- package/dist/LetterheadForm/index.d.ts +44 -0
- package/dist/LetterheadForm/style.css.d.ts +8 -0
- package/dist/LoadingIndicator.d.ts +3 -0
- package/dist/MiddotSeparated/MiddotSeparated.d.ts +8 -0
- package/dist/MiddotSeparated/MiddotSeparated.stories.d.ts +586 -0
- package/dist/MiddotSeparated/style.css.d.ts +1 -0
- package/dist/ModalDialog/index.d.ts +12 -0
- package/dist/ModalDialog/style.css.d.ts +58 -0
- package/dist/ModernIDB/Cursor.d.ts +56 -0
- package/dist/ModernIDB/ModernIDB.d.ts +66 -0
- package/dist/ModernIDB/ModernIDBError.d.ts +3 -0
- package/dist/ModernIDB/ObjectStore.d.ts +112 -0
- package/dist/ModernIDB/ObjectStoreIndex.d.ts +53 -0
- package/dist/ModernIDB/Transaction.d.ts +16 -0
- package/dist/ModernIDB/VersionChangeManager.d.ts +30 -0
- package/dist/ModernIDB/bindings/factory.d.ts +12 -0
- package/dist/ModernIDB/bindings/index.d.ts +2 -0
- package/{lib/ModernIDB/bindings/types.ts → dist/ModernIDB/bindings/types.d.ts} +13 -32
- package/dist/ModernIDB/bindings/utils.d.ts +2 -0
- package/dist/ModernIDB/index.d.ts +10 -0
- package/dist/ModernIDB/types.d.ts +88 -0
- package/dist/ModernIDB/utils.d.ts +4 -0
- package/dist/QRCode/QRCode.d.ts +7 -0
- package/dist/QRCode/QRCode.stories.d.ts +33 -0
- package/dist/QRCode/style.css.d.ts +4 -0
- package/dist/ReleaseInfo/index.d.ts +5 -0
- package/dist/RulesetResolver.d.ts +87 -0
- package/dist/SafariCheck/SafariCheck.d.ts +23 -0
- package/dist/SafariCheck/SafariCheck.stories.d.ts +73 -0
- package/dist/SafariCheck/style.css.d.ts +17 -0
- package/dist/ServiceWorkerHandler.d.ts +11 -0
- package/dist/ShareButton/ShareButton.d.ts +57 -0
- package/dist/ShareButton/ShareButton.stories.d.ts +1577 -0
- package/dist/ShareButton/test.css.d.ts +1 -0
- package/dist/SubscribeCard/LetterheadInfoCard.d.ts +2 -0
- package/dist/SubscribeCard/SubscribeByEmailCard.d.ts +24 -0
- package/dist/SubscribeCard/SubscribeByEmailCard.stories.d.ts +10 -0
- package/dist/SubscribeCard/SubscribeByPledgeCard.d.ts +36 -0
- package/dist/SubscribeCard/SubscribeByPledgeCard.stories.d.ts +65 -0
- package/dist/SubscribeCard/style.css.d.ts +4 -0
- package/dist/account/AccountIssueView.d.ts +3 -0
- package/dist/account/AlreadyLoggedInView.d.ts +5 -0
- package/dist/account/CurrentUserFetcher.d.ts +20 -0
- package/dist/account/CurrentUserFetcher.stories.d.ts +136 -0
- package/dist/account/FailureFallbackView.d.ts +1 -0
- package/dist/account/JoinCard.d.ts +14 -0
- package/dist/account/JoinCard.stories.d.ts +143 -0
- package/dist/account/LoadingView.d.ts +1 -0
- package/dist/account/LoginCard.d.ts +39 -0
- package/dist/account/LoginCard.stories.d.ts +217 -0
- package/dist/account/LoginView.d.ts +10 -0
- package/dist/account/NoConnectionView.d.ts +4 -0
- package/dist/account/PasswordResetCard.d.ts +15 -0
- package/dist/account/PasswordResetCard.stories.d.ts +128 -0
- package/dist/account/UserMismatchView.d.ts +6 -0
- package/dist/account/VerifyPage.d.ts +13 -0
- package/dist/account/style.css.d.ts +10 -0
- package/{lib/account/types.ts → dist/account/types.d.ts} +3 -6
- package/dist/account/useFetchCurrentUser.d.ts +28 -0
- package/dist/account/useRedirectPath.d.ts +6 -0
- package/dist/animations.css.d.ts +3 -0
- package/dist/append-copy-to-text.d.ts +10 -0
- package/dist/append-copy-to-text.test.d.ts +1 -0
- package/dist/appkit.css +1 -0
- package/dist/appkit.js +10692 -0
- package/dist/async-op.d.ts +101 -0
- package/dist/atomic.css.d.ts +6 -0
- package/{lib/caught-value.ts → dist/caught-value.d.ts} +1 -11
- package/{lib/class-names.ts → dist/class-names.d.ts} +6 -17
- package/dist/client.d.ts +424 -0
- package/dist/common.css.d.ts +5 -0
- package/dist/copyrightRange.d.ts +1 -0
- package/dist/copyrightRange.test.d.ts +1 -0
- package/dist/createSafeStorage.d.ts +34 -0
- package/dist/failureMessages.d.ts +20 -0
- package/dist/failureMessages.test.d.ts +1 -0
- package/dist/form/FormSubmitButton.d.ts +17 -0
- package/dist/form/SubmitErrorAlert.d.ts +5 -0
- package/dist/form/style.css.d.ts +3 -0
- package/dist/globals.css.d.ts +0 -0
- package/dist/groupBy.d.ts +1 -0
- package/dist/groupBy.test.d.ts +1 -0
- package/dist/hrefs.d.ts +32 -0
- package/dist/hrefs.test.d.ts +1 -0
- package/dist/idToDate.d.ts +5 -0
- package/dist/idToDate.test.d.ts +1 -0
- package/dist/ids.d.ts +1 -0
- package/dist/ids.test.d.ts +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/internal.css.d.ts +2 -0
- package/dist/mailto.d.ts +8 -0
- package/dist/mailto.test.d.ts +1 -0
- package/dist/media.d.ts +39 -0
- package/dist/random.d.ts +3 -0
- package/dist/result/swr.d.ts +4 -0
- package/{lib/sleep.ts → dist/sleep.d.ts} +1 -3
- package/dist/store/index.d.ts +237 -0
- package/dist/store/store.d.ts +144 -0
- package/dist/store/types.d.ts +49 -0
- package/dist/store/utils.d.ts +10 -0
- package/dist/storybook/decorators.d.ts +3 -0
- package/dist/structs.d.ts +1 -0
- package/{lib/typeguards.ts → dist/typeguards.d.ts} +1 -3
- package/dist/typeguards.test.d.ts +1 -0
- package/{lib/types.ts → dist/types.d.ts} +12 -23
- package/dist/unique.d.ts +10 -0
- package/dist/unique.test.d.ts +1 -0
- package/dist/use-async-op.d.ts +6 -0
- package/dist/use-document-background-color.d.ts +4 -0
- package/dist/use-form.d.ts +29 -0
- package/dist/use-is-installed.d.ts +8 -0
- package/dist/use-media-query.d.ts +1 -0
- package/dist/use-reverting-state.d.ts +5 -0
- package/dist/use-scroll-restoration.d.ts +25 -0
- package/dist/useEnsureValue.d.ts +6 -0
- package/dist/useInvokeClient.d.ts +25 -0
- package/dist/useIsVisible.d.ts +4 -0
- package/dist/utm.d.ts +58 -0
- package/dist/utm.test.d.ts +1 -0
- package/dist/validations.d.ts +3 -0
- package/dist/vars.css.d.ts +10 -0
- package/package.json +12 -5
- package/lib/AppConfig/AppConfig.tsx +0 -61
- package/lib/AuthCard/AuthCard.stories.ts +0 -34
- package/lib/AuthCard/AuthCard.tsx +0 -64
- package/lib/AuthCard/style.css.ts +0 -49
- package/lib/DialogTrigger/index.tsx +0 -36
- package/lib/DocumentTitle/DocumentTitle.tsx +0 -10
- package/lib/EnumMapper.ts +0 -50
- package/lib/ExternalLink.tsx +0 -10
- package/lib/FullscreenDismissBlocker.tsx +0 -23
- package/lib/IndieTabletopClubLogo.tsx +0 -44
- package/lib/IndieTabletopClubSymbol.tsx +0 -37
- package/lib/InfoPage/index.tsx +0 -46
- package/lib/InfoPage/pages.tsx +0 -36
- package/lib/InfoPage/style.css.ts +0 -36
- package/lib/Letterhead/index.tsx +0 -85
- package/lib/Letterhead/stories.tsx +0 -41
- package/lib/Letterhead/style.css.ts +0 -152
- package/lib/LetterheadForm/LetterheadReadonlyTextField.stories.tsx +0 -17
- package/lib/LetterheadForm/LetterheadSubmitError.stories.tsx +0 -19
- package/lib/LetterheadForm/LetterheadTextField.stories.tsx +0 -19
- package/lib/LetterheadForm/index.tsx +0 -137
- package/lib/LetterheadForm/style.css.ts +0 -89
- package/lib/LoadingIndicator.tsx +0 -40
- package/lib/MiddotSeparated/MiddotSeparated.stories.ts +0 -26
- package/lib/MiddotSeparated/MiddotSeparated.tsx +0 -24
- package/lib/MiddotSeparated/style.css.ts +0 -10
- package/lib/ModalDialog/index.tsx +0 -28
- package/lib/ModalDialog/style.css.ts +0 -88
- package/lib/ModernIDB/Cursor.ts +0 -91
- package/lib/ModernIDB/ModernIDB.ts +0 -337
- package/lib/ModernIDB/ModernIDBError.ts +0 -9
- package/lib/ModernIDB/ObjectStore.ts +0 -195
- package/lib/ModernIDB/ObjectStoreIndex.ts +0 -102
- package/lib/ModernIDB/README.md +0 -9
- package/lib/ModernIDB/Transaction.ts +0 -40
- package/lib/ModernIDB/VersionChangeManager.ts +0 -57
- package/lib/ModernIDB/bindings/factory.tsx +0 -165
- package/lib/ModernIDB/bindings/index.ts +0 -2
- package/lib/ModernIDB/bindings/utils.tsx +0 -32
- package/lib/ModernIDB/index.ts +0 -10
- package/lib/ModernIDB/types.ts +0 -120
- package/lib/ModernIDB/utils.ts +0 -51
- package/lib/QRCode/QRCode.stories.tsx +0 -41
- package/lib/QRCode/QRCode.tsx +0 -54
- package/lib/QRCode/style.css.ts +0 -23
- package/lib/ReleaseInfo/index.tsx +0 -29
- package/lib/RulesetResolver.ts +0 -214
- package/lib/SafariCheck/SafariCheck.stories.tsx +0 -99
- package/lib/SafariCheck/SafariCheck.tsx +0 -273
- package/lib/SafariCheck/addToDock.svg +0 -13
- package/lib/SafariCheck/addToHomeScreen.svg +0 -12
- package/lib/SafariCheck/safari.svg +0 -32
- package/lib/SafariCheck/shareIcon.svg +0 -11
- package/lib/SafariCheck/style.css.ts +0 -106
- package/lib/ServiceWorkerHandler.tsx +0 -53
- package/lib/ShareButton/ShareButton.stories.tsx +0 -58
- package/lib/ShareButton/ShareButton.tsx +0 -153
- package/lib/ShareButton/test.css.ts +0 -3
- package/lib/SubscribeCard/LetterheadInfoCard.tsx +0 -23
- package/lib/SubscribeCard/SubscribeByEmailCard.stories.tsx +0 -69
- package/lib/SubscribeCard/SubscribeByEmailCard.tsx +0 -183
- package/lib/SubscribeCard/SubscribeByPledgeCard.stories.tsx +0 -133
- package/lib/SubscribeCard/SubscribeByPledgeCard.tsx +0 -127
- package/lib/SubscribeCard/style.css.ts +0 -14
- package/lib/account/AccountIssueView.tsx +0 -44
- package/lib/account/AlreadyLoggedInView.tsx +0 -47
- package/lib/account/CurrentUserFetcher.stories.tsx +0 -292
- package/lib/account/CurrentUserFetcher.tsx +0 -118
- package/lib/account/FailureFallbackView.tsx +0 -36
- package/lib/account/JoinCard.stories.tsx +0 -257
- package/lib/account/JoinCard.tsx +0 -301
- package/lib/account/LoadingView.tsx +0 -14
- package/lib/account/LoginCard.stories.tsx +0 -288
- package/lib/account/LoginCard.tsx +0 -100
- package/lib/account/LoginView.tsx +0 -151
- package/lib/account/NoConnectionView.tsx +0 -34
- package/lib/account/PasswordResetCard.stories.tsx +0 -242
- package/lib/account/PasswordResetCard.tsx +0 -296
- package/lib/account/UserMismatchView.tsx +0 -62
- package/lib/account/VerifyPage.tsx +0 -195
- package/lib/account/style.css.ts +0 -57
- package/lib/account/useFetchCurrentUser.tsx +0 -63
- package/lib/account/useRedirectPath.ts +0 -21
- package/lib/animations.css.ts +0 -17
- package/lib/append-copy-to-text.ts +0 -35
- package/lib/async-op.ts +0 -286
- package/lib/atomic.css.ts +0 -11
- package/lib/client.ts +0 -662
- package/lib/common.css.ts +0 -48
- package/lib/copyrightRange.ts +0 -10
- package/lib/createSafeStorage.ts +0 -91
- package/lib/failureMessages.ts +0 -108
- package/lib/form/FormSubmitButton.tsx +0 -58
- package/lib/form/SubmitErrorAlert.tsx +0 -21
- package/lib/form/style.css.ts +0 -9
- package/lib/globals.css.ts +0 -62
- package/lib/groupBy.ts +0 -25
- package/lib/hrefs.ts +0 -48
- package/lib/idToDate.ts +0 -8
- package/lib/ids.ts +0 -6
- package/lib/index.ts +0 -71
- package/lib/internal.css.ts +0 -10
- package/lib/mailto.ts +0 -40
- package/lib/media.ts +0 -50
- package/lib/random.ts +0 -19
- package/lib/result/swr.ts +0 -18
- package/lib/store/index.tsx +0 -241
- package/lib/store/store.ts +0 -479
- package/lib/store/types.ts +0 -45
- package/lib/store/utils.ts +0 -54
- package/lib/storybook/decorators.tsx +0 -10
- package/lib/structs.ts +0 -3
- package/lib/unique.ts +0 -24
- package/lib/use-async-op.ts +0 -16
- package/lib/use-document-background-color.ts +0 -16
- package/lib/use-form.ts +0 -78
- package/lib/use-is-installed.ts +0 -17
- package/lib/use-media-query.ts +0 -21
- package/lib/use-reverting-state.ts +0 -32
- package/lib/use-scroll-restoration.ts +0 -99
- package/lib/useEnsureValue.ts +0 -31
- package/lib/useInvokeClient.ts +0 -54
- package/lib/useIsVisible.ts +0 -27
- package/lib/utm.ts +0 -92
- package/lib/validations.ts +0 -25
- package/lib/vars.css.ts +0 -13
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare const dialog: import('@vanilla-extract/recipes').RuntimeFn<{
|
|
2
|
+
size: {
|
|
3
|
+
large: {
|
|
4
|
+
inlineSize: "100%";
|
|
5
|
+
blockSize: "100%";
|
|
6
|
+
"@media": {
|
|
7
|
+
"(min-width: 50em)": {
|
|
8
|
+
blockSize: "fit-content";
|
|
9
|
+
maxInlineSize: "40rem";
|
|
10
|
+
maxBlockSize: "90%";
|
|
11
|
+
borderRadius: "1rem";
|
|
12
|
+
transition: string;
|
|
13
|
+
transform: string;
|
|
14
|
+
selectors: {
|
|
15
|
+
"&[data-enter]": {
|
|
16
|
+
opacity: number;
|
|
17
|
+
transform: string;
|
|
18
|
+
};
|
|
19
|
+
"&[data-leave]": {
|
|
20
|
+
opacity: number;
|
|
21
|
+
transform: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
transition: string;
|
|
27
|
+
transform: string;
|
|
28
|
+
selectors: {
|
|
29
|
+
"&[data-enter]": {
|
|
30
|
+
opacity: number;
|
|
31
|
+
transform: string;
|
|
32
|
+
};
|
|
33
|
+
"&[data-leave]": {
|
|
34
|
+
opacity: number;
|
|
35
|
+
transform: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
small: {
|
|
40
|
+
inlineSize: "min(24rem, 90svw)";
|
|
41
|
+
blockSize: "fit-content";
|
|
42
|
+
borderRadius: "1rem";
|
|
43
|
+
transition: string;
|
|
44
|
+
transform: string;
|
|
45
|
+
selectors: {
|
|
46
|
+
"&[data-enter]": {
|
|
47
|
+
opacity: number;
|
|
48
|
+
transform: string;
|
|
49
|
+
};
|
|
50
|
+
"&[data-leave]": {
|
|
51
|
+
opacity: number;
|
|
52
|
+
transform: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
58
|
+
export declare const backdrop: string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare class Cursor<C extends IDBCursor = IDBCursor> {
|
|
2
|
+
idbCursor: C;
|
|
3
|
+
constructor(idbCursor: C);
|
|
4
|
+
get key(): IDBValidKey;
|
|
5
|
+
get primaryKey(): IDBValidKey;
|
|
6
|
+
get direction(): IDBCursorDirection;
|
|
7
|
+
/**
|
|
8
|
+
* Advances the cursor through the next count records in range.
|
|
9
|
+
*
|
|
10
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBCursor/advance
|
|
11
|
+
*/
|
|
12
|
+
advance(count: number): void;
|
|
13
|
+
/**
|
|
14
|
+
* Advances the cursor to the next record in range.
|
|
15
|
+
*
|
|
16
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBCursor/continue)
|
|
17
|
+
*/
|
|
18
|
+
continue(key?: IDBValidKey): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class CursorWithValue<Item> extends Cursor<IDBCursorWithValue> {
|
|
21
|
+
get value(): Item;
|
|
22
|
+
/**
|
|
23
|
+
* Delete the record pointed at by the cursor.
|
|
24
|
+
*
|
|
25
|
+
* If successful, request's result will be undefined.
|
|
26
|
+
*
|
|
27
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBCursor/delete)
|
|
28
|
+
*/
|
|
29
|
+
delete(): Promise<undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Updated the record pointed at by the cursor with a new value.
|
|
32
|
+
*
|
|
33
|
+
* Throws a "DataError" DOMException if the effective object store uses in-line keys and the key would have changed.
|
|
34
|
+
*
|
|
35
|
+
* If successful, request's result will be the record's key.
|
|
36
|
+
*
|
|
37
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBCursor/update)
|
|
38
|
+
*/
|
|
39
|
+
update(value: Item): Promise<IDBValidKey>;
|
|
40
|
+
}
|
|
41
|
+
export declare class IndexCursor extends Cursor {
|
|
42
|
+
/**
|
|
43
|
+
* Advances the cursor to the next record in range matching or after key and primaryKey. Throws an "InvalidAccessError" DOMException if the source is not an index.
|
|
44
|
+
*
|
|
45
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBCursor/continuePrimaryKey)
|
|
46
|
+
*/
|
|
47
|
+
continuePrimaryKey(key: IDBValidKey, primaryKey: IDBValidKey): void;
|
|
48
|
+
}
|
|
49
|
+
export declare class IndexCursorWithValue<Item> extends CursorWithValue<Item> {
|
|
50
|
+
/**
|
|
51
|
+
* Advances the cursor to the next record in range matching or after key and primaryKey. Throws an "InvalidAccessError" DOMException if the source is not an index.
|
|
52
|
+
*
|
|
53
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBCursor/continuePrimaryKey)
|
|
54
|
+
*/
|
|
55
|
+
continuePrimaryKey(key: IDBValidKey, primaryKey: IDBValidKey): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ObjectStore } from './ObjectStore.ts';
|
|
2
|
+
import { ModernIDBIndexes, ModernIDBSchema, ModernIDBState, OpenRequestHandlers, TransactionMode } from './types.ts';
|
|
3
|
+
export declare class TransactionEvent<StoreName extends string> extends CustomEvent<{
|
|
4
|
+
storeNames: StoreName[];
|
|
5
|
+
}> {
|
|
6
|
+
constructor(type: TransactionMode, storeNames: StoreName[]);
|
|
7
|
+
}
|
|
8
|
+
type TransactionOptions = IDBTransactionOptions & {
|
|
9
|
+
/**
|
|
10
|
+
* Do not emit events when this transaction completes.
|
|
11
|
+
*/
|
|
12
|
+
noEmit?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type DatabaseProps = {
|
|
15
|
+
name: string;
|
|
16
|
+
version: number;
|
|
17
|
+
};
|
|
18
|
+
export declare class ModernIDB<Schema extends ModernIDBSchema, IndexNames extends ModernIDBIndexes<Schema>> {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly version: number;
|
|
21
|
+
protected state: ModernIDBState;
|
|
22
|
+
protected idbDatabase: IDBDatabase | null;
|
|
23
|
+
private eventTarget;
|
|
24
|
+
private onBlocking?;
|
|
25
|
+
private onUpgrade?;
|
|
26
|
+
private onInit?;
|
|
27
|
+
constructor(props: DatabaseProps & OpenRequestHandlers<Schema, IndexNames>);
|
|
28
|
+
addEventListener(type: TransactionMode, callback: (event: TransactionEvent<string & keyof Schema>) => void, options?: boolean | AddEventListenerOptions): void;
|
|
29
|
+
removeEventListener(type: TransactionMode, callback: (event: TransactionEvent<string & keyof Schema>) => void, options?: boolean | EventListenerOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Opens a connection to IndexedDB.
|
|
32
|
+
*
|
|
33
|
+
* ModernIDB instance must be in a `closed` state, otherwise an
|
|
34
|
+
* `InvalidConnectionStateError` will be thrown.
|
|
35
|
+
*
|
|
36
|
+
* If the database needs to upgrade (i.e. supplied version is higher than
|
|
37
|
+
* the current version), but there are existing connections that don't
|
|
38
|
+
* close on `versionchange` event (the onBlocking handler), an
|
|
39
|
+
* `OpenRequestBlockedError` will be thrown.
|
|
40
|
+
*
|
|
41
|
+
* Additional browser-specific exceptions can also be thrown. Make
|
|
42
|
+
* sure to inspect any error's `name` property to differentiate
|
|
43
|
+
* between the various types of errors that could occur.
|
|
44
|
+
*/
|
|
45
|
+
open(handlers?: OpenRequestHandlers<Schema, IndexNames>): Promise<Event>;
|
|
46
|
+
close(): void;
|
|
47
|
+
isOpen(): this is this & {
|
|
48
|
+
idbDatabase: IDBDatabase;
|
|
49
|
+
};
|
|
50
|
+
private assertOpen;
|
|
51
|
+
transaction<StoreName extends string & keyof Schema>(name: StoreName, mode?: TransactionMode, options?: TransactionOptions): [
|
|
52
|
+
ObjectStore<Schema[StoreName], IndexNames[StoreName] extends string ? IndexNames[StoreName] : never>,
|
|
53
|
+
Promise<Event>
|
|
54
|
+
];
|
|
55
|
+
transaction<StoreNamesArray extends readonly (string & keyof Schema)[] | []>(names: StoreNamesArray, mode?: TransactionMode, options?: TransactionOptions): [
|
|
56
|
+
{
|
|
57
|
+
-readonly [Index in keyof StoreNamesArray]: ObjectStore<Schema[StoreNamesArray[Index]], IndexNames[StoreNamesArray[Index]] extends string ? IndexNames[StoreNamesArray[Index]] : never>;
|
|
58
|
+
},
|
|
59
|
+
Promise<Event>
|
|
60
|
+
];
|
|
61
|
+
deleteFromStore(storeName: string & keyof Schema, query: IDBValidKey | IDBKeyRange, options?: IDBTransactionOptions): Promise<void>;
|
|
62
|
+
getFromStore<StoreName extends string & keyof Schema>(storeName: StoreName, query: IDBValidKey | IDBKeyRange, options?: IDBTransactionOptions): Promise<Schema[StoreName] | undefined>;
|
|
63
|
+
putToStore<StoreName extends string & keyof Schema>(storeName: StoreName, value: Schema[StoreName], key?: IDBValidKey): Promise<IDBValidKey>;
|
|
64
|
+
}
|
|
65
|
+
export declare function deleteDatabase(name: string): Promise<IDBDatabase>;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Cursor, CursorWithValue } from './Cursor.ts';
|
|
2
|
+
import { ObjectStoreIndex } from './ObjectStoreIndex.ts';
|
|
3
|
+
import { KeyPath } from './types.ts';
|
|
4
|
+
export declare class ObjectStore<Item, IndexName extends string> {
|
|
5
|
+
readonly idbObjectStore: IDBObjectStore;
|
|
6
|
+
constructor(objectStore: IDBObjectStore);
|
|
7
|
+
/**
|
|
8
|
+
* Adds or updates a record in store with the given value and key.
|
|
9
|
+
*
|
|
10
|
+
* If the store uses in-line keys and key is specified a "DataError" DOMException will be thrown.
|
|
11
|
+
*
|
|
12
|
+
* If put() is used, any existing record with the key will be replaced. If add() is used, and if a record with the key already exists the request will fail, with request's error set to a "ConstraintError" DOMException.
|
|
13
|
+
*
|
|
14
|
+
* If successful, request's result will be the record's key.
|
|
15
|
+
*
|
|
16
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/add)
|
|
17
|
+
*/
|
|
18
|
+
add(value: Item, key?: IDBValidKey): Promise<IDBValidKey>;
|
|
19
|
+
/**
|
|
20
|
+
* Deletes all records in store.
|
|
21
|
+
*
|
|
22
|
+
* If successful, request's result will be undefined.
|
|
23
|
+
*
|
|
24
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/clear)
|
|
25
|
+
*/
|
|
26
|
+
clear(): Promise<undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the number of records matching the given key or key range in query.
|
|
29
|
+
*
|
|
30
|
+
* If successful, request's result will be the count.
|
|
31
|
+
*
|
|
32
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/count)
|
|
33
|
+
*/
|
|
34
|
+
count(query?: IDBValidKey | IDBKeyRange): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* Deletes records in store with the given key or in the given key range in query.
|
|
37
|
+
*
|
|
38
|
+
* If successful, request's result will be undefined.
|
|
39
|
+
*
|
|
40
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/delete)
|
|
41
|
+
*/
|
|
42
|
+
delete(query: IDBValidKey | IDBKeyRange): Promise<undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the value of the first record matching the given key or key range in query.
|
|
45
|
+
*
|
|
46
|
+
* If successful, request's result will be the value, or undefined if there was no matching record.
|
|
47
|
+
*
|
|
48
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/get)
|
|
49
|
+
*/
|
|
50
|
+
get(query: IDBValidKey | IDBKeyRange): Promise<Item | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the values of the records matching the given key or key range in query (up to count if given).
|
|
53
|
+
*
|
|
54
|
+
* If successful, request's result will be an Array of the values.
|
|
55
|
+
*
|
|
56
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/getAll)
|
|
57
|
+
*/
|
|
58
|
+
getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<Item[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the keys of records matching the given key or key range in query (up to count if given).
|
|
61
|
+
*
|
|
62
|
+
* If successful, request's result will be an Array of the keys.
|
|
63
|
+
*
|
|
64
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/getAllKeys)
|
|
65
|
+
*/
|
|
66
|
+
getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<IDBValidKey[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves the key of the first record matching the given key or key range in query.
|
|
69
|
+
*
|
|
70
|
+
* If successful, request's result will be the key, or undefined if there was no matching record.
|
|
71
|
+
*
|
|
72
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/getKey)
|
|
73
|
+
*/
|
|
74
|
+
getKey(query: IDBValidKey | IDBKeyRange): Promise<IDBValidKey | undefined>;
|
|
75
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/index) */
|
|
76
|
+
index(name: IndexName): ObjectStoreIndex<Item>;
|
|
77
|
+
/**
|
|
78
|
+
* Opens a cursor over the records matching query, ordered by direction. If query is null, all records in store are matched.
|
|
79
|
+
*/
|
|
80
|
+
openCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): AsyncGenerator<CursorWithValue<Item>, void, undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in store are matched.
|
|
83
|
+
*/
|
|
84
|
+
openKeyCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): AsyncGenerator<Cursor, void, undefined>;
|
|
85
|
+
/**
|
|
86
|
+
* Adds or updates a record in store with the given value and key.
|
|
87
|
+
*
|
|
88
|
+
* If the store uses in-line keys and key is specified a "DataError" DOMException will be thrown.
|
|
89
|
+
*
|
|
90
|
+
* If put() is used, any existing record with the key will be replaced. If add() is used, and if a record with the key already exists the request will fail, with request's error set to a "ConstraintError" DOMException.
|
|
91
|
+
*
|
|
92
|
+
* If successful, request's result will be the record's key.
|
|
93
|
+
*
|
|
94
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/put)
|
|
95
|
+
*/
|
|
96
|
+
put(value: Item, key?: IDBValidKey): Promise<IDBValidKey>;
|
|
97
|
+
}
|
|
98
|
+
export declare class VersionChangeObjectStore<Item, IndexName extends string> extends ObjectStore<Item, IndexName> {
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be satisfied with the data already in store the upgrade transaction will abort with a "ConstraintError" DOMException.
|
|
101
|
+
*
|
|
102
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/createIndex)
|
|
103
|
+
*/
|
|
104
|
+
createIndex(name: IndexName, keyPath: KeyPath<Item> | KeyPath<Item>[], options?: IDBIndexParameters): ObjectStoreIndex<Item>;
|
|
105
|
+
/**
|
|
106
|
+
* Deletes the index in store with the given name.
|
|
107
|
+
*
|
|
108
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/deleteIndex)
|
|
109
|
+
*/
|
|
110
|
+
deleteIndex(name: IndexName): void;
|
|
111
|
+
renameIndex(currentName: string, newName: IndexName): void;
|
|
112
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IndexCursor, IndexCursorWithValue } from './Cursor.ts';
|
|
2
|
+
export declare class ObjectStoreIndex<Item> {
|
|
3
|
+
readonly idbIndex: IDBIndex;
|
|
4
|
+
constructor(idbIndex: IDBIndex);
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the number of records matching the given key or key range in query.
|
|
7
|
+
*
|
|
8
|
+
* If successful, request's result will be the count.
|
|
9
|
+
*
|
|
10
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/count)
|
|
11
|
+
*/
|
|
12
|
+
count(query?: IDBValidKey | IDBKeyRange): Promise<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the value of the first record matching the given key or key range in query.
|
|
15
|
+
*
|
|
16
|
+
* If successful, request's result will be the value, or undefined if there was no matching record.
|
|
17
|
+
*
|
|
18
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/get)
|
|
19
|
+
*/
|
|
20
|
+
get(query: IDBValidKey | IDBKeyRange): Promise<Item | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the values of the records matching the given key or key range in query (up to count if given).
|
|
23
|
+
*
|
|
24
|
+
* If successful, request's result will be an Array of the values.
|
|
25
|
+
*
|
|
26
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/getAll)
|
|
27
|
+
*/
|
|
28
|
+
getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<Item[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the keys of records matching the given key or key range in query (up to count if given).
|
|
31
|
+
*
|
|
32
|
+
* If successful, request's result will be an Array of the keys.
|
|
33
|
+
*
|
|
34
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/getAllKeys)
|
|
35
|
+
*/
|
|
36
|
+
getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<IDBValidKey[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the key of the first record matching the given key or key range in query.
|
|
39
|
+
*
|
|
40
|
+
* If successful, request's result will be the key, or undefined if there was no matching record.
|
|
41
|
+
*
|
|
42
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBObjectStore/getKey)
|
|
43
|
+
*/
|
|
44
|
+
getKey(query: IDBValidKey | IDBKeyRange): Promise<IDBValidKey | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* Opens a cursor over the records matching query, ordered by direction. If query is null, all records in store are matched.
|
|
47
|
+
*/
|
|
48
|
+
openCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): AsyncGenerator<IndexCursorWithValue<Item>, void, undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in store are matched.
|
|
51
|
+
*/
|
|
52
|
+
openKeyCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): AsyncGenerator<IndexCursor, void, undefined>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ObjectStore, VersionChangeObjectStore } from './ObjectStore.ts';
|
|
2
|
+
import { ModernIDBSchema } from './types.ts';
|
|
3
|
+
export declare class Transaction<Schema extends ModernIDBSchema, IndexNames extends {
|
|
4
|
+
[K in keyof Schema]?: string;
|
|
5
|
+
}> {
|
|
6
|
+
idbTransaction: IDBTransaction;
|
|
7
|
+
constructor(props: {
|
|
8
|
+
transaction: IDBTransaction;
|
|
9
|
+
});
|
|
10
|
+
objectStore<StoreName extends string & keyof Schema>(name: StoreName): ObjectStore<Schema[StoreName], IndexNames[StoreName] extends string ? IndexNames[StoreName] : never>;
|
|
11
|
+
}
|
|
12
|
+
export declare class VersionChangeTransaction<Schema extends ModernIDBSchema, IndexNames extends {
|
|
13
|
+
[K in keyof Schema]?: string;
|
|
14
|
+
}> extends Transaction<Schema, IndexNames> {
|
|
15
|
+
objectStore<StoreName extends string & keyof Schema>(name: StoreName): VersionChangeObjectStore<Schema[StoreName], IndexNames[StoreName] extends string ? IndexNames[StoreName] : never>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { VersionChangeObjectStore } from './ObjectStore.ts';
|
|
2
|
+
import { VersionChangeTransaction } from './Transaction.ts';
|
|
3
|
+
import { KeyPath, ModernIDBSchema } from './types.ts';
|
|
4
|
+
export declare class VersionChangeManager<Schema extends ModernIDBSchema, IndexNames extends {
|
|
5
|
+
[K in keyof Schema]?: string;
|
|
6
|
+
} = never> {
|
|
7
|
+
readonly idbDatabase: IDBDatabase;
|
|
8
|
+
readonly event: IDBVersionChangeEvent;
|
|
9
|
+
readonly transaction: VersionChangeTransaction<Schema, IndexNames>;
|
|
10
|
+
constructor(props: {
|
|
11
|
+
idbDatabase: IDBDatabase;
|
|
12
|
+
event: IDBVersionChangeEvent;
|
|
13
|
+
idbTransaction: IDBTransaction;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new object store with the given name and options and returns a new IDBObjectStore.
|
|
17
|
+
*
|
|
18
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBDatabase/createObjectStore)
|
|
19
|
+
*/
|
|
20
|
+
createObjectStore<StoreName extends string & keyof Schema>(name: StoreName, options?: {
|
|
21
|
+
autoIncrement?: boolean;
|
|
22
|
+
keyPath?: KeyPath<Schema[StoreName]> | KeyPath<Schema[StoreName]>[] | null;
|
|
23
|
+
}): VersionChangeObjectStore<Schema[StoreName], IndexNames[StoreName] extends string ? IndexNames[StoreName] : never>;
|
|
24
|
+
/**
|
|
25
|
+
* Deletes the object store with the given name.
|
|
26
|
+
*
|
|
27
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBDatabase/deleteObjectStore)
|
|
28
|
+
*/
|
|
29
|
+
deleteObjectStore(name: string): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AnyModernIDB } from '../types.ts';
|
|
3
|
+
import { DatabaseOpenRequestOp, FlattenSuccessOps, QueryOp } from './types.ts';
|
|
4
|
+
export declare function createDatabaseBindings<T extends AnyModernIDB>(db: T): {
|
|
5
|
+
useQuery: <Output>(query: (db: T) => Promise<Output>, cacheKey?: string) => FlattenSuccessOps<QueryOp<Output>>;
|
|
6
|
+
useDatabase: () => T;
|
|
7
|
+
useDatabaseOpenRequest: () => DatabaseOpenRequestOp<T>;
|
|
8
|
+
DatabaseProvider: (props: {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
open?: boolean;
|
|
11
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
};
|
|
@@ -1,56 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { AsyncOp, Success } from '../../async-op.ts';
|
|
2
|
+
import { AnyModernIDB } from '../types.ts';
|
|
4
3
|
export type DatabaseQueryOpFailure = QueryError | InaccessibleDatabaseError;
|
|
5
|
-
|
|
6
4
|
export type QueryOp<Output> = AsyncOp<Output, DatabaseQueryOpFailure>;
|
|
7
|
-
|
|
8
|
-
export type FlattenSuccessOps<T> = T extends Success<
|
|
9
|
-
infer S extends AsyncOp<unknown, unknown>
|
|
10
|
-
>
|
|
11
|
-
? S
|
|
12
|
-
: T;
|
|
13
|
-
|
|
5
|
+
export type FlattenSuccessOps<T> = T extends Success<infer S extends AsyncOp<unknown, unknown>> ? S : T;
|
|
14
6
|
export type QueryError = {
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
type: "QUERY_ERROR";
|
|
8
|
+
error: string;
|
|
17
9
|
};
|
|
18
|
-
|
|
19
10
|
/**
|
|
20
11
|
* The stored database version is higher than the version requested.
|
|
21
12
|
*/
|
|
22
13
|
export type VersionHigherState = {
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
type: "DB_VERSION_HIGHER_THAN_REQUESTED";
|
|
15
|
+
message: string;
|
|
25
16
|
};
|
|
26
|
-
|
|
27
17
|
/**
|
|
28
18
|
* Database could not be opened for an unrecognized reason.
|
|
29
19
|
*/
|
|
30
20
|
export type UnexpectedErrorState = {
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
type: "UNKNOWN_ERROR";
|
|
22
|
+
message: string;
|
|
33
23
|
};
|
|
34
|
-
|
|
35
24
|
/**
|
|
36
25
|
* This happens if the database needs an upgrade due to version change, but there are connections open to it from other tabs.
|
|
37
26
|
*/
|
|
38
27
|
export type UpgradeBlockedState = {
|
|
39
|
-
|
|
28
|
+
type: "UPGRADE_BLOCKED";
|
|
40
29
|
};
|
|
41
|
-
|
|
42
30
|
/**
|
|
43
31
|
* The DB has been closed to allow for version change.
|
|
44
32
|
*/
|
|
45
33
|
export type ClosedForUpgradeState = {
|
|
46
|
-
|
|
34
|
+
type: "CLOSED_FOR_UPGRADE";
|
|
47
35
|
};
|
|
48
|
-
|
|
49
|
-
export type
|
|
50
|
-
| UpgradeBlockedState
|
|
51
|
-
| ClosedForUpgradeState
|
|
52
|
-
| VersionHigherState
|
|
53
|
-
| UnexpectedErrorState;
|
|
54
|
-
|
|
55
|
-
export type DatabaseOpenRequestOp<T extends AnyModernIDB = AnyModernIDB> =
|
|
56
|
-
AsyncOp<T, InaccessibleDatabaseError>;
|
|
36
|
+
export type InaccessibleDatabaseError = UpgradeBlockedState | ClosedForUpgradeState | VersionHigherState | UnexpectedErrorState;
|
|
37
|
+
export type DatabaseOpenRequestOp<T extends AnyModernIDB = AnyModernIDB> = AsyncOp<T, InaccessibleDatabaseError>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './bindings/index.ts';
|
|
2
|
+
export * from './Cursor.ts';
|
|
3
|
+
export * from './ModernIDB.ts';
|
|
4
|
+
export * from './ModernIDBError.ts';
|
|
5
|
+
export * from './ObjectStore.ts';
|
|
6
|
+
export * from './ObjectStoreIndex.ts';
|
|
7
|
+
export * from './Transaction.ts';
|
|
8
|
+
export * from './types.ts';
|
|
9
|
+
export * from './utils.ts';
|
|
10
|
+
export * from './VersionChangeManager.ts';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ModernIDB } from './ModernIDB.ts';
|
|
2
|
+
import { VersionChangeManager } from './VersionChangeManager.ts';
|
|
3
|
+
/**
|
|
4
|
+
* IDB supports "readonly", "readwrite", and "versionchange" transaction modes,
|
|
5
|
+
* but "versionchange" can only be initiated automatically during DB upgrade.
|
|
6
|
+
*/
|
|
7
|
+
export type TransactionMode = "readonly" | "readwrite";
|
|
8
|
+
export type ModernIDBState = "open" | "opening" | "closed";
|
|
9
|
+
export type ModernIDBSchema = {
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
export type ModernIDBIndexes<Schema extends ModernIDBSchema> = {
|
|
13
|
+
[K in keyof Schema]?: string;
|
|
14
|
+
};
|
|
15
|
+
export type VersionChangeHandlerProps<Schema extends ModernIDBSchema, IndexNames extends ModernIDBIndexes<Schema>> = {
|
|
16
|
+
event: IDBVersionChangeEvent;
|
|
17
|
+
manager: VersionChangeManager<Schema, IndexNames>;
|
|
18
|
+
db: ModernIDB<Schema, IndexNames>;
|
|
19
|
+
};
|
|
20
|
+
export type VersionChangeHandler<Schema extends ModernIDBSchema, IndexNames extends ModernIDBIndexes<Schema>> = (props: VersionChangeHandlerProps<Schema, IndexNames>) => void;
|
|
21
|
+
export type BlockingHandlerProps<Schema extends ModernIDBSchema, IndexNames extends ModernIDBIndexes<Schema>> = {
|
|
22
|
+
event: IDBVersionChangeEvent;
|
|
23
|
+
db: ModernIDB<Schema, IndexNames>;
|
|
24
|
+
};
|
|
25
|
+
export type BlockingHandler<Schema extends ModernIDBSchema, IndexNames extends ModernIDBIndexes<Schema>> = (props: BlockingHandlerProps<Schema, IndexNames>) => void;
|
|
26
|
+
export type OpenRequestHandlers<Schema extends ModernIDBSchema, IndexNames extends ModernIDBIndexes<Schema>> = {
|
|
27
|
+
/**
|
|
28
|
+
* Called when the database is initialized from scratch.
|
|
29
|
+
*
|
|
30
|
+
* Should be used to set up all required stores and indexes.
|
|
31
|
+
*
|
|
32
|
+
* If error is thrown in this handler, the version change transaction will
|
|
33
|
+
* be aborted.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* onInit({ manager }) {
|
|
39
|
+
* const store = manager.createObjectStore("items", { keyPath: "id" });
|
|
40
|
+
* store.createIndex("createdTs", "createdTs");
|
|
41
|
+
*
|
|
42
|
+
* console.info("DB initialized.");
|
|
43
|
+
* },
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
onInit?: VersionChangeHandler<Schema, IndexNames>;
|
|
47
|
+
/**
|
|
48
|
+
* Called when there is an existing IDB database present, but is is of a lower
|
|
49
|
+
* version than the latest.
|
|
50
|
+
*
|
|
51
|
+
* If error is thrown inside this handler, the version change transaction
|
|
52
|
+
* will be aborted.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* onUpgrade({ manager, event }) {
|
|
57
|
+
* switch (event.oldVersion) {
|
|
58
|
+
* case 1: {
|
|
59
|
+
* // We need a `settings` store in v2, but it did't exist in v1
|
|
60
|
+
* const store = manager.createObjectStore("settings", { keyPath: "id" });
|
|
61
|
+
* store.createIndex("createdTs", "createdTs");
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* default: {
|
|
65
|
+
* console.info(`Migration from DB v${event.oldVersion} complete.`);
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
onUpgrade?: VersionChangeHandler<Schema, IndexNames>;
|
|
72
|
+
/**
|
|
73
|
+
* If a new connection opens which requests a higher version number than
|
|
74
|
+
* is the current version number, a `versionchange` event will be dispatched
|
|
75
|
+
* on the IDBDatabase instance. This handler can specify desired behaviour.
|
|
76
|
+
* For example, you might want to close currently connected connections
|
|
77
|
+
* to allow the version change to proceed.
|
|
78
|
+
*/
|
|
79
|
+
onBlocking?: BlockingHandler<Schema, IndexNames>;
|
|
80
|
+
};
|
|
81
|
+
type ValidKeyValue = string | number | Date;
|
|
82
|
+
export type KeyPath<T> = T extends {
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
} ? {
|
|
85
|
+
[K in keyof T]: K extends string ? T[K] extends ValidKeyValue ? `${K}` : `${K}.${KeyPath<T[K]>}` : never;
|
|
86
|
+
}[keyof T] : never;
|
|
87
|
+
export type AnyModernIDB = ModernIDB<any, any>;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function transactionToPromise(transaction: IDBTransaction): Promise<Event>;
|
|
2
|
+
export declare function requestToPromise<T>(request: IDBRequest<T>): Promise<T>;
|
|
3
|
+
export declare function openRequestToPromise(request: IDBOpenDBRequest): Promise<IDBDatabase>;
|
|
4
|
+
export declare function requestToAsyncGenerator(request: IDBRequest<IDBCursorWithValue | null>): AsyncGenerator<IDBCursorWithValue, void, unknown>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Failure, Pending } from '../async-op.ts';
|
|
2
|
+
export declare const SuccessCase: import('@storybook/react').ReactStory<import('@storybook/react').ReactTypes & import('@storybook/addon-docs').DocsTypes & {
|
|
3
|
+
csf4: true;
|
|
4
|
+
} & {
|
|
5
|
+
args: {
|
|
6
|
+
url: import('../async-op.ts').AsyncOp<string, unknown>;
|
|
7
|
+
className?: string | undefined;
|
|
8
|
+
};
|
|
9
|
+
}, {}>;
|
|
10
|
+
export declare const PendingCase: import('@storybook/react').ReactStory<import('@storybook/react').ReactTypes & import('@storybook/addon-docs').DocsTypes & {
|
|
11
|
+
csf4: true;
|
|
12
|
+
} & {
|
|
13
|
+
args: {
|
|
14
|
+
url: import('../async-op.ts').AsyncOp<string, unknown>;
|
|
15
|
+
className?: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
}, {
|
|
18
|
+
args: {
|
|
19
|
+
url: Pending;
|
|
20
|
+
};
|
|
21
|
+
}>;
|
|
22
|
+
export declare const FailureCase: import('@storybook/react').ReactStory<import('@storybook/react').ReactTypes & import('@storybook/addon-docs').DocsTypes & {
|
|
23
|
+
csf4: true;
|
|
24
|
+
} & {
|
|
25
|
+
args: {
|
|
26
|
+
url: import('../async-op.ts').AsyncOp<string, unknown>;
|
|
27
|
+
className?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
}, {
|
|
30
|
+
args: {
|
|
31
|
+
url: Failure<string>;
|
|
32
|
+
};
|
|
33
|
+
}>;
|