amateras 0.7.3 → 0.10.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/README.md +76 -85
- package/package.json +27 -21
- package/tsconfig.json +4 -3
- package/packages/core/package.json +0 -32
- package/packages/core/src/env.browser.ts +0 -21
- package/packages/core/src/env.node.ts +0 -21
- package/packages/core/src/global.ts +0 -18
- package/packages/core/src/index.ts +0 -96
- package/packages/core/src/lib/assignNodeProperties.ts +0 -11
- package/packages/core/src/lib/assignProperties.ts +0 -57
- package/packages/core/src/lib/chain.ts +0 -17
- package/packages/core/src/lib/dom.ts +0 -20
- package/packages/core/src/main.ts +0 -4
- package/packages/core/src/node/$Element.ts +0 -366
- package/packages/core/src/node/$EventTarget.ts +0 -48
- package/packages/core/src/node/$HTMLElement.ts +0 -99
- package/packages/core/src/node/$Node.ts +0 -201
- package/packages/core/src/node/$Virtual.ts +0 -65
- package/packages/css/README.md +0 -128
- package/packages/css/package.json +0 -17
- package/packages/css/src/ext/colors/amber.ts +0 -25
- package/packages/css/src/ext/colors/blackwhite.ts +0 -13
- package/packages/css/src/ext/colors/blue.ts +0 -25
- package/packages/css/src/ext/colors/cyan.ts +0 -25
- package/packages/css/src/ext/colors/emerald.ts +0 -25
- package/packages/css/src/ext/colors/fuchsia.ts +0 -25
- package/packages/css/src/ext/colors/gray.ts +0 -25
- package/packages/css/src/ext/colors/green.ts +0 -25
- package/packages/css/src/ext/colors/indigo.ts +0 -25
- package/packages/css/src/ext/colors/lime.ts +0 -25
- package/packages/css/src/ext/colors/neutral.ts +0 -25
- package/packages/css/src/ext/colors/orange.ts +0 -25
- package/packages/css/src/ext/colors/pink.ts +0 -25
- package/packages/css/src/ext/colors/purple.ts +0 -25
- package/packages/css/src/ext/colors/red.ts +0 -25
- package/packages/css/src/ext/colors/rose.ts +0 -25
- package/packages/css/src/ext/colors/sky.ts +0 -25
- package/packages/css/src/ext/colors/slate.ts +0 -25
- package/packages/css/src/ext/colors/stone.ts +0 -25
- package/packages/css/src/ext/colors/teal.ts +0 -25
- package/packages/css/src/ext/colors/violet.ts +0 -25
- package/packages/css/src/ext/colors/yellow.ts +0 -25
- package/packages/css/src/ext/colors/zinc.ts +0 -25
- package/packages/css/src/ext/colors.ts +0 -23
- package/packages/css/src/ext/container.ts +0 -32
- package/packages/css/src/ext/keyframes.ts +0 -54
- package/packages/css/src/ext/media.ts +0 -32
- package/packages/css/src/ext/property.ts +0 -48
- package/packages/css/src/ext/variable.ts +0 -51
- package/packages/css/src/index.ts +0 -436
- package/packages/css/src/lib/colorAssign.ts +0 -6
- package/packages/css/src/lib/utils.ts +0 -11
- package/packages/css/src/structure/$CSSContainerRule.ts +0 -13
- package/packages/css/src/structure/$CSSDeclaration.ts +0 -16
- package/packages/css/src/structure/$CSSKeyframesRule.ts +0 -13
- package/packages/css/src/structure/$CSSMediaRule.ts +0 -10
- package/packages/css/src/structure/$CSSProperty.ts +0 -19
- package/packages/css/src/structure/$CSSRule.ts +0 -13
- package/packages/css/src/structure/$CSSStyleRule.ts +0 -14
- package/packages/css/src/structure/$CSSVariable.ts +0 -30
- package/packages/dom/package.json +0 -20
- package/packages/dom/src/lib/HTMLElementMap.ts +0 -213
- package/packages/dom/src/lib/assignAttributes.ts +0 -16
- package/packages/dom/src/structure/CSS.ts +0 -7
- package/packages/dom/src/structure/CSSStyleSheet.ts +0 -10
- package/packages/dom/src/structure/DOMTokenList.ts +0 -19
- package/packages/dom/src/structure/Document.ts +0 -36
- package/packages/dom/src/structure/Element.ts +0 -106
- package/packages/dom/src/structure/HTMLElement.ts +0 -34
- package/packages/dom/src/structure/History.ts +0 -11
- package/packages/dom/src/structure/Location.ts +0 -9
- package/packages/dom/src/structure/Node.ts +0 -51
- package/packages/dom/src/structure/NodeList.ts +0 -10
- package/packages/dom/src/structure/Storage.ts +0 -8
- package/packages/dom/src/structure/Text.ts +0 -20
- package/packages/dom/src/structure/Window.ts +0 -14
- package/packages/dom/src/structure/html/HTMLAbbrElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLAddressElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLAnchorElement.ts +0 -25
- package/packages/dom/src/structure/html/HTMLAreaElement.ts +0 -26
- package/packages/dom/src/structure/html/HTMLArticleElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLAsideElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLAudioElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLBDIElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLBDOElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLBElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLBRElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLBaseElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLBodyElement.ts +0 -22
- package/packages/dom/src/structure/html/HTMLButtonElement.ts +0 -26
- package/packages/dom/src/structure/html/HTMLCanvasElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLCiteElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLCodeElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLDDElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLDFNElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLDListElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLDTElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLDataElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLDataListElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLDetailsElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLDialogElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLDivElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLEMElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLEmbedElement.ts +0 -20
- package/packages/dom/src/structure/html/HTMLFieldSetElement.ts +0 -19
- package/packages/dom/src/structure/html/HTMLFigCaptionElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLFigureElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLFooterElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLFormElement.ts +0 -24
- package/packages/dom/src/structure/html/HTMLHGroupElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLHRElement.ts +0 -21
- package/packages/dom/src/structure/html/HTMLHeadElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLHeaderElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLHeadingElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLHtmlElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLIElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLIFrameElement.ts +0 -31
- package/packages/dom/src/structure/html/HTMLImageElement.ts +0 -38
- package/packages/dom/src/structure/html/HTMLInputElement.ts +0 -55
- package/packages/dom/src/structure/html/HTMLKBDElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLLIElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLLabelElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLLegendElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLLinkElement.ts +0 -31
- package/packages/dom/src/structure/html/HTMLMainElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLMapElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLMarkElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLMediaElement.ts +0 -48
- package/packages/dom/src/structure/html/HTMLMenuElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLMetaElement.ts +0 -22
- package/packages/dom/src/structure/html/HTMLMeterElement.ts +0 -23
- package/packages/dom/src/structure/html/HTMLModElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLNavElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLNoscriptElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLOListElement.ts +0 -20
- package/packages/dom/src/structure/html/HTMLObjectElement.ts +0 -34
- package/packages/dom/src/structure/html/HTMLOptGroupElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLOptionElement.ts +0 -20
- package/packages/dom/src/structure/html/HTMLOutputElement.ts +0 -20
- package/packages/dom/src/structure/html/HTMLParagraphElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLPictureElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLPreElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLProgressElement.ts +0 -19
- package/packages/dom/src/structure/html/HTMLQuoteElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLRPElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLRTElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLRubyElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLSElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLSampElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLScriptElement.ts +0 -27
- package/packages/dom/src/structure/html/HTMLSectionElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLSelectElement.ts +0 -27
- package/packages/dom/src/structure/html/HTMLSlotElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLSmallElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLSourceElement.ts +0 -21
- package/packages/dom/src/structure/html/HTMLSpanElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLStrongElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLStyleElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLSubElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLSummaryElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLSupElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLTableCaptionElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLTableCellElement.ts +0 -31
- package/packages/dom/src/structure/html/HTMLTableColElement.ts +0 -23
- package/packages/dom/src/structure/html/HTMLTableElement.ts +0 -26
- package/packages/dom/src/structure/html/HTMLTableRowElement.ts +0 -23
- package/packages/dom/src/structure/html/HTMLTableSectionElement.ts +0 -20
- package/packages/dom/src/structure/html/HTMLTemplateElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLTextAreaElement.ts +0 -33
- package/packages/dom/src/structure/html/HTMLTimeElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLTitleElement.ts +0 -17
- package/packages/dom/src/structure/html/HTMLTrackElement.ts +0 -21
- package/packages/dom/src/structure/html/HTMLUElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLUListElement.ts +0 -18
- package/packages/dom/src/structure/html/HTMLVarElement.ts +0 -16
- package/packages/dom/src/structure/html/HTMLVideoElement.ts +0 -22
- package/packages/dom/src/structure/html/HTMLWBRElement.ts +0 -16
- package/packages/html/package.json +0 -18
- package/packages/html/src/index.ts +0 -13
- package/packages/html/src/node/$Anchor.ts +0 -49
- package/packages/html/src/node/$Canvas.ts +0 -38
- package/packages/html/src/node/$Dialog.ts +0 -16
- package/packages/html/src/node/$Form.ts +0 -16
- package/packages/html/src/node/$Image.ts +0 -72
- package/packages/html/src/node/$Input.ts +0 -193
- package/packages/html/src/node/$Label.ts +0 -25
- package/packages/html/src/node/$Media.ts +0 -16
- package/packages/html/src/node/$OptGroup.ts +0 -23
- package/packages/html/src/node/$Option.ts +0 -40
- package/packages/html/src/node/$Select.ts +0 -76
- package/packages/html/src/node/$TextArea.ts +0 -16
- package/packages/i18n/README.md +0 -73
- package/packages/i18n/package.json +0 -19
- package/packages/i18n/src/index.ts +0 -140
- package/packages/i18n/src/structure/I18n.ts +0 -44
- package/packages/i18n/src/structure/I18nDictionary.ts +0 -31
- package/packages/i18n/src/structure/I18nTranslation.ts +0 -41
- package/packages/idb/README.md +0 -127
- package/packages/idb/package.json +0 -19
- package/packages/idb/src/core.ts +0 -6
- package/packages/idb/src/index.ts +0 -17
- package/packages/idb/src/lib/$IDBRequest.ts +0 -8
- package/packages/idb/src/structure/$IDB.ts +0 -63
- package/packages/idb/src/structure/$IDBCursor.ts +0 -34
- package/packages/idb/src/structure/$IDBIndex.ts +0 -48
- package/packages/idb/src/structure/$IDBStore.ts +0 -103
- package/packages/idb/src/structure/$IDBStoreBase.ts +0 -30
- package/packages/idb/src/structure/$IDBTransaction.ts +0 -38
- package/packages/idb/src/structure/builder/$IDBBuilder.ts +0 -229
- package/packages/idb/src/structure/builder/$IDBStoreBuilder.ts +0 -100
- package/packages/markdown/README.md +0 -53
- package/packages/markdown/package.json +0 -19
- package/packages/markdown/src/index.ts +0 -3
- package/packages/markdown/src/lib/type.ts +0 -26
- package/packages/markdown/src/lib/util.ts +0 -21
- package/packages/markdown/src/structure/Markdown.ts +0 -54
- package/packages/markdown/src/structure/MarkdownLexer.ts +0 -111
- package/packages/markdown/src/structure/MarkdownParser.ts +0 -34
- package/packages/markdown/src/syntax/alert.ts +0 -46
- package/packages/markdown/src/syntax/blockquote.ts +0 -35
- package/packages/markdown/src/syntax/bold.ts +0 -11
- package/packages/markdown/src/syntax/code.ts +0 -11
- package/packages/markdown/src/syntax/codeblock.ts +0 -44
- package/packages/markdown/src/syntax/heading.ts +0 -14
- package/packages/markdown/src/syntax/horizontalRule.ts +0 -11
- package/packages/markdown/src/syntax/image.ts +0 -23
- package/packages/markdown/src/syntax/italic.ts +0 -11
- package/packages/markdown/src/syntax/link.ts +0 -46
- package/packages/markdown/src/syntax/list.ts +0 -121
- package/packages/markdown/src/syntax/table.ts +0 -67
- package/packages/markdown/src/syntax/text.ts +0 -19
- package/packages/router/README.md +0 -175
- package/packages/router/package.json +0 -19
- package/packages/router/src/index.ts +0 -68
- package/packages/router/src/node/Page.ts +0 -38
- package/packages/router/src/node/Router.ts +0 -212
- package/packages/router/src/node/RouterAnchor.ts +0 -24
- package/packages/router/src/structure/PageBuilder.ts +0 -24
- package/packages/router/src/structure/Route.ts +0 -105
- package/packages/signal/README.md +0 -93
- package/packages/signal/package.json +0 -18
- package/packages/signal/src/index.ts +0 -221
- package/packages/signal/src/structure/Signal.ts +0 -38
- package/packages/ui/lib/VirtualScroll.ts +0 -25
- package/packages/ui/node/Accordian.ts +0 -97
- package/packages/ui/node/Carousel.ts +0 -20
- package/packages/ui/node/Form.ts +0 -54
- package/packages/ui/node/Grid.ts +0 -0
- package/packages/ui/node/Modal.ts +0 -45
- package/packages/ui/node/Table.ts +0 -43
- package/packages/ui/node/Tabs.ts +0 -129
- package/packages/ui/node/Toast.ts +0 -16
- package/packages/ui/node/Waterfall.ts +0 -94
- package/packages/ui/package.json +0 -21
- package/packages/utils/package.json +0 -17
- package/packages/utils/src/global.ts +0 -25
- package/packages/utils/src/index.ts +0 -90
package/packages/i18n/README.md
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# amateras/i18n
|
|
2
|
-
|
|
3
|
-
## Usage
|
|
4
|
-
```ts
|
|
5
|
-
import 'amateras';
|
|
6
|
-
import 'amateras/i18n';
|
|
7
|
-
|
|
8
|
-
const $t = $.i18n()
|
|
9
|
-
// add 'en' locale dictionary context
|
|
10
|
-
.add('en', {
|
|
11
|
-
homepage: {
|
|
12
|
-
_: 'Home',
|
|
13
|
-
hello: 'Hello, $name$!',
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
// set 'en' as locale language
|
|
17
|
-
.locale('en')
|
|
18
|
-
|
|
19
|
-
$(document.body).content([
|
|
20
|
-
$('h1').content( $t('homepage') )
|
|
21
|
-
// <h1><text>Home</text></h1>
|
|
22
|
-
$t('homepage.hello', {name: 'Amateras'})
|
|
23
|
-
// <text>Hello, Amateras!</text>
|
|
24
|
-
])
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Change Language
|
|
28
|
-
```ts
|
|
29
|
-
$t.locale('zh')
|
|
30
|
-
// all translation text will be updated
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Import Dictionary Context
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
// ./i18n/en.ts
|
|
37
|
-
export default {
|
|
38
|
-
hello: 'Hello, $name$!'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// ./i18n/zh.ts
|
|
42
|
-
export default {
|
|
43
|
-
hello: '您好,$name$!'
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ./entry_file.ts
|
|
47
|
-
const $t = $.i18n()
|
|
48
|
-
.add('en', () => import('./i18n/en.ts'))
|
|
49
|
-
.add('zh', () => import('./i18n/zh.ts'))
|
|
50
|
-
// set 'zh' as locale language
|
|
51
|
-
// and fetch file automatically from path
|
|
52
|
-
.locale('zh');
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Directory Shortcut
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
const $t = $.i18n('en')
|
|
59
|
-
.add('en', {
|
|
60
|
-
page1: {
|
|
61
|
-
section2: {
|
|
62
|
-
button3: {
|
|
63
|
-
text: 'Too deep!'
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
const $t_button = $t.dir('page1.section2.button3');
|
|
70
|
-
|
|
71
|
-
$t_button('text') // Too deep!
|
|
72
|
-
$t('page1.section2.button3.text') // Too deep!
|
|
73
|
-
```
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@amateras/i18n",
|
|
3
|
-
"peerDependencies": {
|
|
4
|
-
"@amateras/core": "workspace:*",
|
|
5
|
-
"@amateras/signal": "workspace:*",
|
|
6
|
-
"@amateras/utils": "workspace:*"
|
|
7
|
-
},
|
|
8
|
-
"imports": {
|
|
9
|
-
"#structure/*": "./src/structure/*.ts",
|
|
10
|
-
"#lib/*": "./src/lib/*.ts",
|
|
11
|
-
"#node/*": "./src/node/*.ts"
|
|
12
|
-
},
|
|
13
|
-
"exports": {
|
|
14
|
-
".": "./src/index.ts",
|
|
15
|
-
"./structure/*": "./src/structure/*.ts",
|
|
16
|
-
"./lib/*": "./src/lib/*.ts",
|
|
17
|
-
"./node/*": "./src/node/*.ts"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import "@amateras/core"
|
|
2
|
-
import { _Array_from, _instanceof, _Object_assign } from "@amateras/utils"
|
|
3
|
-
import { I18n } from "#structure/I18n"
|
|
4
|
-
import { I18nDictionary, type I18nDictionaryContext, type I18nDictionaryContextImporter } from "#structure/I18nDictionary";
|
|
5
|
-
import { $Node, type $NodeContentResolver } from "@amateras/core/node/$Node";
|
|
6
|
-
import { I18nTranslation as _I18nTranslation, I18nTranslation, type I18nTranslationOptions } from "#structure/I18nTranslation";
|
|
7
|
-
|
|
8
|
-
$Node.setters.add((value, set) => {
|
|
9
|
-
if (_instanceof(value, _I18nTranslation)) {
|
|
10
|
-
value.content$.signal.subscribe(set);
|
|
11
|
-
return value.content$.value();
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
_Object_assign($, {
|
|
16
|
-
i18n(defaultLocale: string) {
|
|
17
|
-
const i18n = new I18n(defaultLocale);
|
|
18
|
-
const i18nFn = (key: string, options?: I18nTranslationOptions) => i18n.translate(key, options);
|
|
19
|
-
_Object_assign(i18nFn, {
|
|
20
|
-
i18n,
|
|
21
|
-
locale(locale: string) {
|
|
22
|
-
if (!arguments.length) return i18n.locale();
|
|
23
|
-
i18n.locale(locale);
|
|
24
|
-
return this;
|
|
25
|
-
},
|
|
26
|
-
add(lang: string, context: I18nDictionaryContext | I18nDictionaryContextImporter) {
|
|
27
|
-
i18n.map.set(lang, new I18nDictionary(context));
|
|
28
|
-
return this;
|
|
29
|
-
},
|
|
30
|
-
delete(lang: string) {
|
|
31
|
-
i18n.map.delete(lang);
|
|
32
|
-
return this;
|
|
33
|
-
},
|
|
34
|
-
dir(path: string) {
|
|
35
|
-
return (key: string, options?: I18nTranslationOptions) => i18n.translate(`${path}.${key}`, options)
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
return i18nFn
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
type ResolvedAsyncDictionary<F extends I18nDictionaryContextImporter> = Awaited<ReturnType<F>>['default'];
|
|
43
|
-
|
|
44
|
-
type I18nTranslationKey<T> =
|
|
45
|
-
T extends I18nDictionaryContext
|
|
46
|
-
? {
|
|
47
|
-
[K in keyof T]: K extends string
|
|
48
|
-
? K extends '_'
|
|
49
|
-
? never
|
|
50
|
-
: T[K] extends string
|
|
51
|
-
? `${K}`
|
|
52
|
-
: '_' extends keyof T[K]
|
|
53
|
-
? `${K}` | `${K}.${I18nTranslationKey<T[K]>}`
|
|
54
|
-
: `${K}.${I18nTranslationKey<T[K]>}`
|
|
55
|
-
: never;
|
|
56
|
-
}[keyof T]
|
|
57
|
-
: never;
|
|
58
|
-
|
|
59
|
-
type I18nTranslationDirKey<T> =
|
|
60
|
-
T extends I18nDictionaryContext
|
|
61
|
-
? {
|
|
62
|
-
[K in keyof T]: K extends string
|
|
63
|
-
? T[K] extends string
|
|
64
|
-
? never
|
|
65
|
-
: `${K}` | `${K}.${I18nTranslationDirKey<T[K]>}`
|
|
66
|
-
: never;
|
|
67
|
-
}[keyof T]
|
|
68
|
-
: never;
|
|
69
|
-
|
|
70
|
-
type I18nTranslationParams<K extends string, T extends I18nDictionaryContext> =
|
|
71
|
-
FindTranslationByKey<K, T> extends infer O
|
|
72
|
-
? O extends string
|
|
73
|
-
? FindParam<O>
|
|
74
|
-
: never
|
|
75
|
-
: never
|
|
76
|
-
|
|
77
|
-
type FindParam<T extends string> =
|
|
78
|
-
T extends `${string}$${infer Param}$${infer Rest}`
|
|
79
|
-
? Param extends `${string}${' '}${string}`
|
|
80
|
-
? Prettify<{} & FindParam<Rest>>
|
|
81
|
-
: Prettify<Record<Param, $NodeContentResolver<I18nTranslation>> & FindParam<Rest>>
|
|
82
|
-
: {}
|
|
83
|
-
|
|
84
|
-
type FindTranslationByKey<K extends string, T extends I18nDictionaryContext> =
|
|
85
|
-
K extends `${infer Prefix}.${infer Rest}`
|
|
86
|
-
? Prefix extends keyof T
|
|
87
|
-
? T[Prefix] extends I18nDictionaryContext
|
|
88
|
-
? FindTranslationByKey<Rest, T[Prefix]>
|
|
89
|
-
: T[Prefix]
|
|
90
|
-
: ''
|
|
91
|
-
: T[K] extends object
|
|
92
|
-
? '_' extends keyof T[K]
|
|
93
|
-
? T[K]['_']
|
|
94
|
-
: never
|
|
95
|
-
: T[K]
|
|
96
|
-
|
|
97
|
-
type GetDictionaryContextByKey<K extends string, T extends I18nDictionaryContext> =
|
|
98
|
-
K extends `${infer Prefix}.${infer Rest}`
|
|
99
|
-
? Prefix extends keyof T
|
|
100
|
-
? T[Prefix] extends I18nDictionaryContext
|
|
101
|
-
? GetDictionaryContextByKey<Rest, T[Prefix]>
|
|
102
|
-
: never
|
|
103
|
-
: never
|
|
104
|
-
: T[K] extends object
|
|
105
|
-
? T[K]
|
|
106
|
-
: never
|
|
107
|
-
|
|
108
|
-
type Mixin<A, B> =
|
|
109
|
-
(Omit<A, keyof B> & Omit<B, keyof A>) & {
|
|
110
|
-
[key in (keyof A & keyof B)]:
|
|
111
|
-
A[key] extends object
|
|
112
|
-
? B[key] extends object
|
|
113
|
-
? Mixin<A[key], B[key]>
|
|
114
|
-
: A[key] | B[key]
|
|
115
|
-
: A[key] | B[key]
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
declare module "@amateras/core" {
|
|
119
|
-
export namespace $ {
|
|
120
|
-
export interface I18nFunction<D extends I18nDictionaryContext = {}> {
|
|
121
|
-
<K extends I18nTranslationKey<D>, P extends I18nTranslationParams<K, D>>(path: K, ...params: P extends Record<string, never> ? [] : [P]): I18nTranslation;
|
|
122
|
-
i18n: I18n;
|
|
123
|
-
locale(): string;
|
|
124
|
-
locale(lang?: $Parameter<string>): this;
|
|
125
|
-
add<F extends I18nDictionaryContext | I18nDictionaryContextImporter>(lang: string, dictionary: F): I18nFunction<Mixin<D, (F extends I18nDictionaryContextImporter ? ResolvedAsyncDictionary<F> : F)>>;
|
|
126
|
-
delete(lang: string): this;
|
|
127
|
-
dir<K extends I18nTranslationDirKey<D>>(path: K): I18nFunction<GetDictionaryContextByKey<K, D>>
|
|
128
|
-
}
|
|
129
|
-
export function i18n(defaultLocale: string): I18nFunction;
|
|
130
|
-
export type I18nTranslation = _I18nTranslation;
|
|
131
|
-
|
|
132
|
-
export interface $NodeContentMap {
|
|
133
|
-
i18n: I18nTranslation
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface $NodeParameterMap<T> {
|
|
137
|
-
i18n: I18nTranslation
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import '@amateras/signal';
|
|
2
|
-
import { _instanceof, _null } from "@amateras/utils";
|
|
3
|
-
import { I18nDictionary } from "#structure/I18nDictionary";
|
|
4
|
-
import { I18nTranslation, type I18nTranslationOptions } from "./I18nTranslation";
|
|
5
|
-
|
|
6
|
-
export class I18n {
|
|
7
|
-
locale$ = $.signal<string>('');
|
|
8
|
-
map = new Map<string, I18nDictionary>();
|
|
9
|
-
#defaultLocale: string;
|
|
10
|
-
constructor(defaultLocale: string) {
|
|
11
|
-
this.#defaultLocale = defaultLocale;
|
|
12
|
-
this.locale$.set(defaultLocale);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
defaultLocale(): string;
|
|
16
|
-
defaultLocale(locale: string): this;
|
|
17
|
-
defaultLocale(locale?: string) {
|
|
18
|
-
if (!arguments.length) return this.#defaultLocale;
|
|
19
|
-
if (locale) this.locale$.set(locale);
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
locale(): string;
|
|
24
|
-
locale(locale: string): this;
|
|
25
|
-
locale(locale?: string) {
|
|
26
|
-
if (!arguments.length) return this.locale$.value();
|
|
27
|
-
if (locale) {
|
|
28
|
-
if (!this.map.has(locale)) locale = locale.split('-')[0]!;
|
|
29
|
-
if (this.map.has(locale)) this.locale$.set(locale)
|
|
30
|
-
}
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
dictionary(locale = this.locale$.value()) {
|
|
35
|
-
if (!locale) return _null;
|
|
36
|
-
const dictionary = this.map.get(locale);
|
|
37
|
-
return dictionary;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
translate(key: string, options?: I18nTranslationOptions) {
|
|
41
|
-
return new I18nTranslation(this, key, options);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { _instanceof, isFunction, isObject } from "@amateras/utils";
|
|
2
|
-
|
|
3
|
-
export class I18nDictionary {
|
|
4
|
-
#context: I18nDictionaryContext | Promise<I18nDictionaryContext> | null = null;
|
|
5
|
-
#fetch: I18nDictionaryContextImporter | null = null;
|
|
6
|
-
constructor(resolver: I18nDictionaryContext | I18nDictionaryContextImporter) {
|
|
7
|
-
if (isFunction(resolver)) this.#fetch = resolver;
|
|
8
|
-
else this.#context = resolver;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async context(): Promise<I18nDictionaryContext> {
|
|
12
|
-
if (this.#context) return await this.#context;
|
|
13
|
-
if (!this.#fetch) throw 'I18n Context Fetch Error';
|
|
14
|
-
return this.#context = this.#fetch().then((module) => module.default);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async find(path: string, context?: I18nDictionaryContext): Promise<string | undefined> {
|
|
18
|
-
if (!context) context = await this.context();
|
|
19
|
-
const [snippet, ...rest] = path.split('.') as [string, ...string[]];
|
|
20
|
-
const target = context[snippet];
|
|
21
|
-
if (isObject(target)) {
|
|
22
|
-
if (rest.length) return this.find(rest.join('.'), target);
|
|
23
|
-
else return target['_'] as string;
|
|
24
|
-
}
|
|
25
|
-
if (rest.length) return path;
|
|
26
|
-
else return target;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type I18nDictionaryContext = {[key: string]: string | I18nDictionaryContext}
|
|
31
|
-
export type I18nDictionaryContextImporter = () => Promise<{default: I18nDictionaryContext}>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { _Array_from, _null, isUndefined } from "@amateras/utils";
|
|
2
|
-
import type { I18n } from "#structure/I18n";
|
|
3
|
-
import { $Node, type $NodeContentResolver, type $NodeContentTypes } from "@amateras/core/node/$Node";
|
|
4
|
-
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
5
|
-
|
|
6
|
-
export class I18nTranslation extends $HTMLElement {
|
|
7
|
-
i18n: I18n;
|
|
8
|
-
key: string;
|
|
9
|
-
options: I18nTranslationOptions | undefined;
|
|
10
|
-
content$ = $.signal('');
|
|
11
|
-
constructor(i18n: I18n, key: string, options?: I18nTranslationOptions) {
|
|
12
|
-
super('t')
|
|
13
|
-
this.i18n = i18n;
|
|
14
|
-
this.key = key;
|
|
15
|
-
this.options = options;
|
|
16
|
-
i18n.locale$.signal.subscribe(() => this.update())
|
|
17
|
-
this.update();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async update() {
|
|
21
|
-
const {key, i18n, options} = this;
|
|
22
|
-
const contentUpdate = (content: $NodeContentResolver<this>) => {
|
|
23
|
-
this.content(content);
|
|
24
|
-
this.content$.set(this.textContent() ?? '')
|
|
25
|
-
}
|
|
26
|
-
update: {
|
|
27
|
-
const dictionary = i18n.dictionary();
|
|
28
|
-
if (!dictionary) { contentUpdate(key); break update }
|
|
29
|
-
const target = await dictionary.find(key);
|
|
30
|
-
if (isUndefined(target)) break update;
|
|
31
|
-
const snippets = target.split(/\$[a-zA-Z0-9_]+\$/);
|
|
32
|
-
if (snippets.length === 1 || !options) { contentUpdate(target); break update }
|
|
33
|
-
const matches = target.matchAll(/(\$([a-zA-Z0-9_]+)\$)/g);
|
|
34
|
-
const content = snippets.map(text => [text, options[matches.next().value?.at(2)!] ?? null]).flat();
|
|
35
|
-
contentUpdate(content);
|
|
36
|
-
}
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type I18nTranslationOptions = {[key: string]: any}
|
package/packages/idb/README.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# amateras/idb
|
|
2
|
-
|
|
3
|
-
## Usage
|
|
4
|
-
```ts
|
|
5
|
-
import 'amateras';
|
|
6
|
-
import 'amateras/idb';
|
|
7
|
-
|
|
8
|
-
// configure indexedDB
|
|
9
|
-
const idb = await $.idb('MyDB', 1)
|
|
10
|
-
// add store
|
|
11
|
-
.store('userStore', store => store
|
|
12
|
-
.keyPath('id')
|
|
13
|
-
.autoIncrement(true)
|
|
14
|
-
// define store object type
|
|
15
|
-
.schema<{
|
|
16
|
-
id: number,
|
|
17
|
-
name: string,
|
|
18
|
-
age: number
|
|
19
|
-
}>()
|
|
20
|
-
.index('by_age', { keyPath: 'age' })
|
|
21
|
-
)
|
|
22
|
-
// open idb
|
|
23
|
-
.open();
|
|
24
|
-
|
|
25
|
-
// open `readwrite` transaction with `userStore`
|
|
26
|
-
const result = await idb.store('userStore', true, async store => {
|
|
27
|
-
store.put({name: 'Amateras', age: 16});
|
|
28
|
-
return store.getAll();
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
console.log(result); // [ { name: 'Amateras', age: 16, id: 1 } ]
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Quick Examples
|
|
35
|
-
|
|
36
|
-
### Get object from store
|
|
37
|
-
```ts
|
|
38
|
-
await idb.store('userStore', store => store.get(1))
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Get all object from store
|
|
42
|
-
```ts
|
|
43
|
-
await idb.store('userStore', store => store.getAll())
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Add object to store
|
|
47
|
-
Any changes to database without `readwrite` mode is resisted, pass `true` value to `writable` argument to enable `readwrite` mode.
|
|
48
|
-
``` ts
|
|
49
|
-
await idb.store('userStore', true, store => store.add({name: 'Tsukimi', age: 16}))
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Put object to store
|
|
53
|
-
The `.put()` method is different with `.add()` method, put object will replace the object of existed key.
|
|
54
|
-
``` ts
|
|
55
|
-
await idb.store('userStore', true, store => store.put({name: 'Amateras', age: 17}))
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Use index
|
|
59
|
-
```ts
|
|
60
|
-
await idb.store('userStore', true, store => store.index('by_age').getAll(16))
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Operating multiple stores in one transaction
|
|
64
|
-
```ts
|
|
65
|
-
await idb.transaction(['userStore', 'itemStore'], true, async transaction => {
|
|
66
|
-
transaction.store('itemStore').put({id: 2, name: 'Item 2'})
|
|
67
|
-
return {
|
|
68
|
-
users: await transaction.store('userStore').getAll(),
|
|
69
|
-
items: await transaction.store('itemStore').getAll()
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Open cursor for advance operations
|
|
75
|
-
```ts
|
|
76
|
-
await idb.store('userStore', true, async store => {
|
|
77
|
-
const teenagers = []
|
|
78
|
-
await store.cursor(cursor => {
|
|
79
|
-
if (cursor.value.age < 18) teenagers.push(cursor.value);
|
|
80
|
-
cursor.continue();
|
|
81
|
-
})
|
|
82
|
-
return teenagers;
|
|
83
|
-
})
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Upgrade Database
|
|
87
|
-
Using `.upgrade()` in `$IDBStoreBuilder` can set the store upgrade handle function to list. The store upgrade function is used for change object structure when the store is upgrading.
|
|
88
|
-
|
|
89
|
-
For example, in version 10:
|
|
90
|
-
```ts
|
|
91
|
-
{
|
|
92
|
-
id: number,
|
|
93
|
-
name: string
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
After version 11, we want to change the object structure:
|
|
98
|
-
```ts
|
|
99
|
-
{
|
|
100
|
-
id: string,
|
|
101
|
-
name: string,
|
|
102
|
-
intro: string
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
You see the `id` is change to `string` type, and come with the new property `intro`. In the following example, we will upgrade this object structure, and this upgrade is only executed when client IDB version is lower than argument `version`.
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
store.upgrade(11, (objects) => {
|
|
110
|
-
return objects.map({key, value} => {
|
|
111
|
-
// since we didn't defined the object type in every different version,
|
|
112
|
-
// the object is any type, please handle the upgrade carefully
|
|
113
|
-
return { key,
|
|
114
|
-
value: {
|
|
115
|
-
...value,
|
|
116
|
-
id: value.id.toString(), // convert to string
|
|
117
|
-
intro: `Hi, my name is ${object.name}` // add new intro property
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
The upgrade function is set, this will be executed on `$IDBBuilder.open()`.
|
|
125
|
-
|
|
126
|
-
> [!NOTE]
|
|
127
|
-
> You should leave all the upgrade function in your codebase, unless you are sure the client database version is larger than this upgrade function.
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@amateras/idb",
|
|
3
|
-
"peerDependencies": {
|
|
4
|
-
"@amateras/core": "workspace:*",
|
|
5
|
-
"@amateras/signal": "workspace:*",
|
|
6
|
-
"@amateras/utils": "workspace:*"
|
|
7
|
-
},
|
|
8
|
-
"imports": {
|
|
9
|
-
"#structure/*": "./src/structure/*.ts",
|
|
10
|
-
"#lib/*": "./src/lib/*.ts",
|
|
11
|
-
"#node/*": "./src/node/*.ts"
|
|
12
|
-
},
|
|
13
|
-
"exports": {
|
|
14
|
-
".": "./src/index.ts",
|
|
15
|
-
"./structure/*": "./src/structure/*.ts",
|
|
16
|
-
"./lib/*": "./src/lib/*.ts",
|
|
17
|
-
"./node/*": "./src/node/*.ts"
|
|
18
|
-
}
|
|
19
|
-
}
|
package/packages/idb/src/core.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { _Object_assign } from "@amateras/utils"
|
|
2
|
-
import { $IDBBuilder } from "#structure/builder/$IDBBuilder"
|
|
3
|
-
|
|
4
|
-
declare module '@amateras/core' {
|
|
5
|
-
export namespace $ {
|
|
6
|
-
/**
|
|
7
|
-
* Create {@link $IDBBuilder} with IDB name and version number.
|
|
8
|
-
* @param name - Database name
|
|
9
|
-
* @param version - Version number
|
|
10
|
-
*/
|
|
11
|
-
export function idb<N extends string, V extends number>(name: N, version: V): $IDBBuilder<{name: N, version: V, stores: {}}>;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
_Object_assign($, {
|
|
16
|
-
idb: (name: string, version: number) => new $IDBBuilder({name, version, stores: {}})
|
|
17
|
-
})
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { _Promise } from "@amateras/utils";
|
|
2
|
-
|
|
3
|
-
export const $IDBRequest = <T>(req: IDBRequest<T>, handle?: (req: IDBRequest<T>, resolve: (value: T) => void) => void) => {
|
|
4
|
-
return new _Promise<T>((resolve, reject) => {
|
|
5
|
-
req.onsuccess = _ => handle ? handle(req, resolve) : resolve(req.result);
|
|
6
|
-
req.onerror = _ => reject(req.error);
|
|
7
|
-
})
|
|
8
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { _Array_from, _null, _Object_assign, _Object_fromEntries, _Promise, isBoolean } from "@amateras/utils";
|
|
2
|
-
import { $IDBStore, type $IDBStoreConfig } from "./$IDBStore";
|
|
3
|
-
import { $IDBTransaction } from "./$IDBTransaction";
|
|
4
|
-
|
|
5
|
-
export interface $IDB<Config extends $IDBConfig = any> {
|
|
6
|
-
/** Object with store name key and `$IDBStoreConfig` value. */
|
|
7
|
-
readonly stores: Config['stores'];
|
|
8
|
-
}
|
|
9
|
-
export class $IDB<Config extends $IDBConfig = any> {
|
|
10
|
-
/** {@link IDBDatabase} instance. */
|
|
11
|
-
readonly idb: IDBDatabase;
|
|
12
|
-
/** IndexedDB database name. */
|
|
13
|
-
readonly name: Config['name'];
|
|
14
|
-
/** IndexedDB database version. */
|
|
15
|
-
readonly version: Config['version'];
|
|
16
|
-
constructor(idb: IDBDatabase, config: Omit<Config, 'name' | 'version'>) {
|
|
17
|
-
this.idb = idb;
|
|
18
|
-
this.name = idb.name;
|
|
19
|
-
this.version = idb.version;
|
|
20
|
-
_Object_assign(this, config);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Create new transaction with the store name, you can directly operating the target store with `handle` function. This method will return a `Promise` with the `handle` return type value.
|
|
25
|
-
* @param name - Store name
|
|
26
|
-
* @param writable - Enable readwrite mode
|
|
27
|
-
* @param handle - Function execute on transaction opened
|
|
28
|
-
* @returns The handle function return type
|
|
29
|
-
*/
|
|
30
|
-
async store<K extends keyof Config['stores'] & string, T>(name: K, handle: (store: $IDBStore<Config['stores'][K]>) => T): Promise<T>
|
|
31
|
-
async store<K extends keyof Config['stores'] & string, T>(name: K, writable: boolean, handle: (store: $IDBStore<Config['stores'][K]>) => T): Promise<T>
|
|
32
|
-
async store<K extends keyof Config['stores'] & string, T>(name: K, resolver: boolean | Function, handle?: Function) {
|
|
33
|
-
if (isBoolean(resolver)) return this.transaction(name, resolver, $tx => handle!($tx.store(name)));
|
|
34
|
-
else return this.transaction(name, $tx => resolver($tx.store(name)))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Create new transaction with the store name, you can pass multiple store name into `storeName` argument for operating multiple store in one transaction.
|
|
39
|
-
* @param store - Store name, allow string array
|
|
40
|
-
* @param writable - Enable readwrite mode
|
|
41
|
-
* @param handle - Function execute on transaction opened
|
|
42
|
-
* @returns The handle function return type
|
|
43
|
-
*/
|
|
44
|
-
async transaction<K extends keyof Config['stores'] & string, T>(store: K | K[], handle: (transaction: $IDBTransaction<{ stores: Pick<Config['stores'], K> }>) => T): Promise<T>
|
|
45
|
-
async transaction<K extends keyof Config['stores'] & string, T>(store: K | K[], writable: boolean, handle: (transaction: $IDBTransaction<{ stores: Pick<Config['stores'], K> }>) => T): Promise<T>
|
|
46
|
-
async transaction<K extends keyof Config['stores'] & string, T>(store: K | K[], resolver?: boolean | Function, handle?: Function) {
|
|
47
|
-
handle = isBoolean(resolver) ? handle : resolver;
|
|
48
|
-
resolver = isBoolean(resolver) ? resolver : false;
|
|
49
|
-
const tx = this.idb.transaction(store, resolver ? 'readwrite' : 'readonly');
|
|
50
|
-
const $tx = new $IDBTransaction(this, tx);
|
|
51
|
-
const result = handle!($tx);
|
|
52
|
-
return new _Promise<T>((resolve, reject) => {
|
|
53
|
-
tx.oncomplete = _ => resolve(result);
|
|
54
|
-
tx.onerror = tx.onabort = _ => tx.error && reject(tx.error);
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type $IDBConfig = {
|
|
60
|
-
name: string;
|
|
61
|
-
version: number;
|
|
62
|
-
stores: { [key: string]: $IDBStoreConfig }
|
|
63
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { _instanceof, _Object_assign, _Promise } from "@amateras/utils";
|
|
2
|
-
import { $IDBRequest } from "#lib/$IDBRequest";
|
|
3
|
-
import { $IDBStore, type $IDBStoreConfig } from "./$IDBStore";
|
|
4
|
-
import { $IDBIndex } from "./$IDBIndex";
|
|
5
|
-
import type { $IDBStoreBase } from "./$IDBStoreBase";
|
|
6
|
-
|
|
7
|
-
export interface $IDBCursor {}
|
|
8
|
-
export class $IDBCursor<StoreConfig extends $IDBStoreConfig = any> {
|
|
9
|
-
#cursor: IDBCursorWithValue;
|
|
10
|
-
readonly store: $IDBStore<StoreConfig>;
|
|
11
|
-
readonly direction;
|
|
12
|
-
constructor(store: $IDBStoreBase, cursor: IDBCursorWithValue) {
|
|
13
|
-
this.#cursor = cursor;
|
|
14
|
-
this.store = _instanceof(store, $IDBIndex<StoreConfig>) ? store.store : store as $IDBStore;
|
|
15
|
-
this.direction = cursor.direction;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get value() { return this.#cursor.value }
|
|
19
|
-
get key() { return this.#cursor.key }
|
|
20
|
-
get primaryKey() { return this.#cursor.primaryKey }
|
|
21
|
-
|
|
22
|
-
async update<T>(value: T) {
|
|
23
|
-
return $IDBRequest(this.#cursor.update(value))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async delete() {
|
|
27
|
-
return $IDBRequest(this.#cursor.delete())
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
continue(key?: IDBValidKey) { this.#cursor.continue(key) }
|
|
31
|
-
continuePrimaryKey(key: IDBValidKey, primaryKey: IDBValidKey) { this.#cursor.continuePrimaryKey(key, primaryKey) }
|
|
32
|
-
advance(count: number) { this.#cursor.advance(count) }
|
|
33
|
-
abort() { this.#cursor.request.transaction?.abort() }
|
|
34
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { _Object_assign } from "@amateras/utils";
|
|
2
|
-
import type { $IDBStore, $IDBStoreConfig, QueryMultipleKeyPath } from "./$IDBStore";
|
|
3
|
-
import { $IDBStoreBase } from "./$IDBStoreBase";
|
|
4
|
-
import type { $IDBCursor } from "./$IDBCursor";
|
|
5
|
-
|
|
6
|
-
export class $IDBIndex<StoreConfig extends $IDBStoreConfig = any, Config extends $IDBIndexConfig = any> extends $IDBStoreBase{
|
|
7
|
-
readonly store: $IDBStore;
|
|
8
|
-
constructor(store: $IDBStore, index: IDBIndex, config: Config) {
|
|
9
|
-
super(index);
|
|
10
|
-
this.store = store;
|
|
11
|
-
_Object_assign(this, config);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface $IDBIndex<StoreConfig extends $IDBStoreConfig, Config extends $IDBIndexConfig = any> {
|
|
16
|
-
readonly unique: Config['unique'];
|
|
17
|
-
readonly multiEntry: Config['multiEntry'];
|
|
18
|
-
readonly keyPath: Config['keyPath'];
|
|
19
|
-
|
|
20
|
-
/** {@link IDBIndex.cursor} */
|
|
21
|
-
cursor(handle: (cursor: $IDBCursor) => void, query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): Promise<null>
|
|
22
|
-
|
|
23
|
-
/** {@link IDBIndex.keyCursor} */
|
|
24
|
-
keyCursor(handle: (cursor: $IDBCursor) => void, query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): Promise<null>
|
|
25
|
-
|
|
26
|
-
/** {@link IDBIndex.count} */
|
|
27
|
-
count(query?: $IDBIndexKey<StoreConfig, Config> | IDBKeyRange): Promise<number>;
|
|
28
|
-
|
|
29
|
-
/** {@link IDBIndex.get} */
|
|
30
|
-
get(query: $IDBIndexKey<StoreConfig, Config> | IDBKeyRange): Promise<StoreConfig['schema']>
|
|
31
|
-
|
|
32
|
-
/** {@link IDBIndex.getAll} */
|
|
33
|
-
getAll(query?: $IDBIndexKey<StoreConfig, Config> | IDBKeyRange): Promise<StoreConfig['schema'][]>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type $IDBIndexConfig = {
|
|
37
|
-
unique: boolean;
|
|
38
|
-
multiEntry: boolean;
|
|
39
|
-
keyPath: string | string[];
|
|
40
|
-
name: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type $IDBIndexKey<StoreConfig extends $IDBStoreConfig, Config extends $IDBIndexConfig> =
|
|
44
|
-
Config['keyPath'] extends string
|
|
45
|
-
? StoreConfig['schema'][Config['keyPath']]
|
|
46
|
-
: Config['keyPath'] extends string[]
|
|
47
|
-
? QueryMultipleKeyPath<Config['keyPath'], StoreConfig>
|
|
48
|
-
: IDBValidKey;
|