tinybase 2.2.5 → 3.0.0-beta.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/lib/debug/ui-react.d.ts +299 -235
- package/lib/es6/ui-react.d.ts +299 -235
- package/lib/ui-react.d.ts +299 -235
- package/lib/umd/ui-react.d.ts +299 -235
- package/lib/umd-es6/ui-react.d.ts +299 -235
- package/package.json +21 -21
- package/readme.md +17 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinybase",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinybase",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,38 +63,38 @@
|
|
|
63
63
|
"publishPackage": "gulp publishPackage"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@babel/cli": "^7.
|
|
67
|
-
"@babel/core": "^7.20.
|
|
66
|
+
"@babel/cli": "^7.20.7",
|
|
67
|
+
"@babel/core": "^7.20.7",
|
|
68
68
|
"@babel/preset-env": "^7.20.2",
|
|
69
69
|
"@babel/preset-react": "^7.18.6",
|
|
70
70
|
"@babel/preset-typescript": "^7.18.6",
|
|
71
|
-
"@rollup/plugin-replace": "^5.0.
|
|
72
|
-
"@rollup/plugin-terser": "^0.1
|
|
71
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
72
|
+
"@rollup/plugin-terser": "^0.2.1",
|
|
73
73
|
"@types/asciichart": "^1.5.6",
|
|
74
74
|
"@types/expect-puppeteer": "^5.0.2",
|
|
75
75
|
"@types/http-server": "^0.12.1",
|
|
76
76
|
"@types/jest": "^29.2.4",
|
|
77
77
|
"@types/jest-environment-puppeteer": "^5.0.3",
|
|
78
78
|
"@types/less": "^3.0.3",
|
|
79
|
-
"@types/node": "^18.11.
|
|
79
|
+
"@types/node": "^18.11.18",
|
|
80
80
|
"@types/puppeteer": "^5.4.7",
|
|
81
|
-
"@types/react": "^
|
|
82
|
-
"@types/react-dom": "^
|
|
83
|
-
"@types/react-test-renderer": "^
|
|
81
|
+
"@types/react": "^18.0.26",
|
|
82
|
+
"@types/react-dom": "^18.0.10",
|
|
83
|
+
"@types/react-test-renderer": "^18.0.0",
|
|
84
84
|
"@types/tmp": "^0.2.3",
|
|
85
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
86
|
-
"@typescript-eslint/parser": "^5.
|
|
85
|
+
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
|
86
|
+
"@typescript-eslint/parser": "^5.47.1",
|
|
87
87
|
"asciichart": "^1.5.25",
|
|
88
88
|
"babel-eslint": "^10.1.0",
|
|
89
89
|
"babel-jest": "^29.3.1",
|
|
90
90
|
"babel-preset-minify": "^0.5.2",
|
|
91
91
|
"buffer-replace": "^1.0.0",
|
|
92
92
|
"country-flag-emoji-json": "^2.0.0",
|
|
93
|
-
"cspell": "^6.
|
|
94
|
-
"esbuild": "^0.
|
|
95
|
-
"eslint": "^8.
|
|
93
|
+
"cspell": "^6.18.0",
|
|
94
|
+
"esbuild": "^0.16.11",
|
|
95
|
+
"eslint": "^8.30.0",
|
|
96
96
|
"eslint-config-prettier": "^8.5.0",
|
|
97
|
-
"eslint-plugin-jest": "^27.1.
|
|
97
|
+
"eslint-plugin-jest": "^27.1.7",
|
|
98
98
|
"eslint-plugin-jsdoc": "^39.6.4",
|
|
99
99
|
"eslint-plugin-react": "^7.31.11",
|
|
100
100
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
@@ -108,17 +108,17 @@
|
|
|
108
108
|
"less": "^4.1.3",
|
|
109
109
|
"prettier": "^2.8.1",
|
|
110
110
|
"puppeteer": "^17.1.3",
|
|
111
|
-
"react": "^
|
|
112
|
-
"react-dom": "^
|
|
113
|
-
"react-test-renderer": "^
|
|
114
|
-
"rollup": "^3.
|
|
111
|
+
"react": "^18.2.0",
|
|
112
|
+
"react-dom": "^18.2.0",
|
|
113
|
+
"react-test-renderer": "^18.2.0",
|
|
114
|
+
"rollup": "^3.8.1",
|
|
115
115
|
"rollup-plugin-esbuild": "^5.0.0",
|
|
116
116
|
"rollup-plugin-gzip": "^3.1.0",
|
|
117
117
|
"rollup-plugin-preserve-shebang": "^1.0.1",
|
|
118
118
|
"rollup-plugin-prettier": "^3.0.0",
|
|
119
|
-
"tinydocs": "^0.1.
|
|
119
|
+
"tinydocs": "^0.1.23",
|
|
120
120
|
"tmp": "^0.2.1",
|
|
121
|
-
"ts-unused-exports": "^
|
|
121
|
+
"ts-unused-exports": "^9.0.0",
|
|
122
122
|
"typescript": "4.9.4"
|
|
123
123
|
},
|
|
124
124
|
"peerDependencies": {
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<section id="hero"><h2 id="the-reactive-data-store-for-local-first-apps">The <em>reactive</em> data store for local‑first apps.</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Why sacrifice store features for bundle size? And why should the cloud do all the work <a href="https://www.inkandswitch.com/local-first/" target="_blank">anyway</a>?</p><p><em>TinyBase is a smart new way to structure your local app data:</em></p><ul><li>Familiar concepts of <a href="#set-and-get-tables-rows-and-cells">tables, rows, and cells</a>, and <a href="#apply-schemas-to-tables">schematization</a> to model your data domain.</li><li><a href="#register-listeners-at-any-granularity">Flexibly reactive</a> to reconciled updates, so your UI only spends cycles on the data that changes.</li><li><a href="#build-complex-queries-with-tinyql">Powerful query engine</a> to select, join, filter, group, sort and paginate data - reactively.</li><li><a href="#create-indexes-for-fast-lookups">Indexing</a>, <a href="#define-metrics-and-aggregations">metrics</a>, <a href="#configure-relationships-between-tables">relationships</a> - and even an <a href="#use-checkpoints-for-an-easy-undo-stack">undo stack</a> for your app state! - out of the box.</li><li>Easily <a href="#persist-data-to-browser-file-or-server">sync your data</a> to local or remote storage, and use <a href="#call-hooks-to-bind-to-data">idiomatic bindings</a> to your UI.</li><li><em>NEW!</em> <a href="#generate-orm-like-apis">Generate ORM-like APIs</a> in TypeScript, based on your schema or inferred from actual data.</li></ul><p><em>Tiny by name, tiny by nature</em>, TinyBase only costs <a href="#did-we-say-tiny">3.5kB - 7.9kB</a> when compressed, and has zero dependencies. And of course it's <a href="#well-tested-and-documented">well tested</a>, <a href="https://tinybase.org/guides/the-basics/getting-started">fully documented</a>, and <a href="https://github.com/tinyplex/tinybase">open source</a>. Other <a href="https://tinybase.org/guides/faq/">FAQs</a>?</p></section><p><a id="new" href="https://tinybase.org/guides/releases/#v2-2"><em>NEW!</em> v2.2 release</a></p><hr><p><a
|
|
1
|
+
<section id="hero"><h2 id="the-reactive-data-store-for-local-first-apps">The <em>reactive</em> data store for local‑first apps.</h2><p>Modern apps deserve better. Why trade reactive user experiences to be able to use relational data? Why sacrifice store features for bundle size? And why should the cloud do all the work <a href="https://www.inkandswitch.com/local-first/" target="_blank">anyway</a>?</p><p><em>TinyBase is a smart new way to structure your local app data:</em></p><ul><li>Familiar concepts of <a href="#set-and-get-tables-rows-and-cells">tables, rows, and cells</a>, and <a href="#apply-schemas-to-tables">schematization</a> to model your data domain.</li><li><a href="#register-listeners-at-any-granularity">Flexibly reactive</a> to reconciled updates, so your UI only spends cycles on the data that changes.</li><li><a href="#build-complex-queries-with-tinyql">Powerful query engine</a> to select, join, filter, group, sort and paginate data - reactively.</li><li><a href="#create-indexes-for-fast-lookups">Indexing</a>, <a href="#define-metrics-and-aggregations">metrics</a>, <a href="#configure-relationships-between-tables">relationships</a> - and even an <a href="#use-checkpoints-for-an-easy-undo-stack">undo stack</a> for your app state! - out of the box.</li><li>Easily <a href="#persist-data-to-browser-file-or-server">sync your data</a> to local or remote storage, and use <a href="#call-hooks-to-bind-to-data">idiomatic bindings</a> to your UI.</li><li><em>NEW!</em> <a href="#generate-orm-like-apis">Generate ORM-like APIs</a> in TypeScript, based on your schema or inferred from actual data.</li></ul><p><em>Tiny by name, tiny by nature</em>, TinyBase only costs <a href="#did-we-say-tiny">3.5kB - 7.9kB</a> when compressed, and has zero dependencies. And of course it's <a href="#well-tested-and-documented">well tested</a>, <a href="https://beta.tinybase.org/guides/the-basics/getting-started/">fully documented</a>, and <a href="https://github.com/tinyplex/tinybase">open source</a>. Other <a href="https://beta.tinybase.org/guides/faq/">FAQs</a>?</p></section><p><a id="new" href="https://beta.tinybase.org/guides/releases/#v2-2"><em>NEW!</em> v2.2 release</a></p><hr><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="set-and-get-tables-rows-and-cells">Set and get tables, rows, and cells.</h2><p>Creating a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> requires just a simple call to the <a href="https://beta.tinybase.org/api/store/functions/creation/createstore/"><code>createStore</code></a> function. Once you have one, you can easily set <a href="https://beta.tinybase.org/api/store/type-aliases/store/table/"><code>Table</code></a>, <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a>, or <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a> values by their <a href="https://beta.tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a>. And of course you can easily get the values back out again.</p><p>Read more about setting and changing data in <a href="https://beta.tinybase.org/guides/the-basics/">The Basics</a> guide.</p></section>
|
|
2
2
|
|
|
3
3
|
```js
|
|
4
4
|
const store = createStore()
|
|
@@ -9,7 +9,7 @@ console.log(store.getRow('pets', 'fido'));
|
|
|
9
9
|
// -> {species: 'dog', color: 'brown'}
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
<section><h2 id="register-listeners-at-any-granularity">Register listeners at any granularity.</h2><p>The magic starts to happen when you register listeners on a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>, <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>, <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a>, or <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>. They get called when any part of that object changes. You can also use wildcards - useful when you don't know the <a href="https://tinybase.org/api/common/type-aliases/identity/id"><code>Id</code></a> of the objects that might change.</p><p>Read more about listeners in the <a href="https://tinybase.org/guides/the-basics/listening-to-stores">Listening To Stores</a> guide.</p></section>
|
|
12
|
+
<section><h2 id="register-listeners-at-any-granularity">Register listeners at any granularity.</h2><p>The magic starts to happen when you register listeners on a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a>, <a href="https://beta.tinybase.org/api/store/type-aliases/store/table/"><code>Table</code></a>, <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a>, or <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a>. They get called when any part of that object changes. You can also use wildcards - useful when you don't know the <a href="https://beta.tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a> of the objects that might change.</p><p>Read more about listeners in the <a href="https://beta.tinybase.org/guides/the-basics/listening-to-stores/">Listening To Stores</a> guide.</p></section>
|
|
13
13
|
|
|
14
14
|
```js
|
|
15
15
|
const listenerId = store.addTableListener('pets', () =>
|
|
@@ -22,7 +22,7 @@ store.setCell('pets', 'fido', 'sold', false);
|
|
|
22
22
|
store.delListener(listenerId);
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
<section><h2 id="call-hooks-to-bind-to-data">Call hooks to bind to data.</h2><p>If you're using React in your application, the optional <a href="https://tinybase.org/api/ui-react"><code>ui-react</code></a> module provides hooks to bind to the data in a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>.</p><p>More magic! The <a href="https://tinybase.org/api/ui-react/functions/store-hooks/usecell"><code>useCell</code></a> hook in this example fetches the dog's color. But it also registers a listener on that cell that will fire and re-render the component whenever the value changes.</p><p>Basically you simply describe what data you want in your user interface and TinyBase will take care of the whole lifecycle of updating it for you.</p><p>Read more about the using hooks in the <a href="https://tinybase.org/guides/building-uis/using-react-hooks">Using React Hooks</a> guide.</p></section>
|
|
25
|
+
<section><h2 id="call-hooks-to-bind-to-data">Call hooks to bind to data.</h2><p>If you're using React in your application, the optional <a href="https://beta.tinybase.org/api/ui-react/"><code>ui-react</code></a> module provides hooks to bind to the data in a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a>.</p><p>More magic! The <a href="https://beta.tinybase.org/api/ui-react/functions/store-hooks/usecell/"><code>useCell</code></a> hook in this example fetches the dog's color. But it also registers a listener on that cell that will fire and re-render the component whenever the value changes.</p><p>Basically you simply describe what data you want in your user interface and TinyBase will take care of the whole lifecycle of updating it for you.</p><p>Read more about the using hooks in the <a href="https://beta.tinybase.org/guides/building-uis/using-react-hooks/">Using React Hooks</a> guide.</p></section>
|
|
26
26
|
|
|
27
27
|
```jsx
|
|
28
28
|
const App1 = () => {
|
|
@@ -31,7 +31,8 @@ const App1 = () => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const app = document.createElement('div');
|
|
34
|
-
|
|
34
|
+
const root = ReactDOMClient.createRoot(app);
|
|
35
|
+
root.render(<App1 />);
|
|
35
36
|
console.log(app.innerHTML);
|
|
36
37
|
// -> 'Color: brown'
|
|
37
38
|
|
|
@@ -40,7 +41,7 @@ console.log(app.innerHTML);
|
|
|
40
41
|
// -> 'Color: walnut'
|
|
41
42
|
```
|
|
42
43
|
|
|
43
|
-
<section><h2 id="use-components-to-make-reactive-apps">Use components to make reactive apps.</h2><p>The react module provides simple React components with bindings that make it easy to create a fully reactive user interface based on a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>.</p><p>In this example, the library's <a href="https://tinybase.org/api/ui-react/functions/store-components/rowview"><code>RowView</code></a> component just needs a reference to the <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>, the <code>tableId</code>, and the <code>rowId</code> in order to render the contents of that row. An optional <code>cellComponent</code> prop lets you override how you want each <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> rendered. Again, all the listeners and updates are taken care of for you.</p><p>The module also includes a context Provider that sets up default for an entire app to use, reducing the need to drill all your props down into your app's hierarchy.</p><p>Most of the demos showcase the use of these React hooks and components. Take a look at <a href="https://tinybase.org/demos/todo-app/todo-app-v1-the-basics">Todo App v1 (the basics)</a> to see these user interface binding patterns in action.</p><p>Read more about the <a href="https://tinybase.org/api/ui-react"><code>ui-react</code></a> module in the <a href="https://tinybase.org/guides/building-uis">Building UIs</a> guides.</p></section>
|
|
44
|
+
<section><h2 id="use-components-to-make-reactive-apps">Use components to make reactive apps.</h2><p>The react module provides simple React components with bindings that make it easy to create a fully reactive user interface based on a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a>.</p><p>In this example, the library's <a href="https://beta.tinybase.org/api/ui-react/functions/store-components/rowview/"><code>RowView</code></a> component just needs a reference to the <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a>, the <code>tableId</code>, and the <code>rowId</code> in order to render the contents of that row. An optional <code>cellComponent</code> prop lets you override how you want each <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a> rendered. Again, all the listeners and updates are taken care of for you.</p><p>The module also includes a context Provider that sets up default for an entire app to use, reducing the need to drill all your props down into your app's hierarchy.</p><p>Most of the demos showcase the use of these React hooks and components. Take a look at <a href="https://beta.tinybase.org/demos/todo-app/todo-app-v1-the-basics/">Todo App v1 (the basics)</a> to see these user interface binding patterns in action.</p><p>Read more about the <a href="https://beta.tinybase.org/api/ui-react/"><code>ui-react</code></a> module in the <a href="https://beta.tinybase.org/guides/building-uis/">Building UIs</a> guides.</p></section>
|
|
44
45
|
|
|
45
46
|
```jsx
|
|
46
47
|
const MyCellView = (props) => (
|
|
@@ -59,7 +60,7 @@ const App2 = () => (
|
|
|
59
60
|
/>
|
|
60
61
|
);
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
root.render(<App2 />);
|
|
63
64
|
console.log(app.innerHTML);
|
|
64
65
|
// -> 'species: dog<hr>color: walnut<hr>sold: false<hr>'
|
|
65
66
|
|
|
@@ -67,10 +68,10 @@ store.setCell('pets', 'fido', 'sold', true);
|
|
|
67
68
|
console.log(app.innerHTML);
|
|
68
69
|
// -> 'species: dog<hr>color: walnut<hr>sold: true<hr>'
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
root.unmount();
|
|
71
72
|
```
|
|
72
73
|
|
|
73
|
-
<section><h2 id="apply-schemas-to-tables">Apply schemas to tables.</h2><p>By default, a <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> can contain any arbitrary <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>. But you can add a schema to a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a> to ensure that the values are always what you expect. For example, you can limit their types, and provide defaults. You can also create mutating listeners that can programmatically enforce a schema.</p><p>In this example, we set a second <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> without the <code>sold</code> <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> in it. The schema ensures it's present with default of <code>false</code>.</p><p>Read more about schemas in the <a href="https://tinybase.org/guides/schemas-and-persistence/using-schemas">Using Schemas</a> guide.</p></section>
|
|
74
|
+
<section><h2 id="apply-schemas-to-tables">Apply schemas to tables.</h2><p>By default, a <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a> can contain any arbitrary <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a>. But you can add a schema to a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> to ensure that the values are always what you expect. For example, you can limit their types, and provide defaults. You can also create mutating listeners that can programmatically enforce a schema.</p><p>In this example, we set a second <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a> without the <code>sold</code> <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a> in it. The schema ensures it's present with default of <code>false</code>.</p><p>Read more about schemas in the <a href="https://beta.tinybase.org/guides/schemas-and-persistence/using-schemas/">Using Schemas</a> guide.</p></section>
|
|
74
75
|
|
|
75
76
|
```js
|
|
76
77
|
store.setSchema({
|
|
@@ -88,7 +89,7 @@ console.log(store.getRow('pets', 'felix'));
|
|
|
88
89
|
store.delSchema();
|
|
89
90
|
```
|
|
90
91
|
|
|
91
|
-
<section><h2 id="persist-data-to-browser-file-or-server">Persist data to browser, file, or server.</h2><p>You can easily persist a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a> between browser page reloads or sessions. You can also synchronize it with a web endpoint, or (if you're using TinyBase in an appropriate environment), load and save it to a file.</p><p>Read more about persisters in the <a href="https://tinybase.org/guides/schemas-and-persistence/persisting-data">Persisting Data</a> guide.</p></section>
|
|
92
|
+
<section><h2 id="persist-data-to-browser-file-or-server">Persist data to browser, file, or server.</h2><p>You can easily persist a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a> between browser page reloads or sessions. You can also synchronize it with a web endpoint, or (if you're using TinyBase in an appropriate environment), load and save it to a file.</p><p>Read more about persisters in the <a href="https://beta.tinybase.org/guides/schemas-and-persistence/persisting-data/">Persisting Data</a> guide.</p></section>
|
|
92
93
|
|
|
93
94
|
```js
|
|
94
95
|
const persister = createSessionPersister(store, 'demo');
|
|
@@ -101,7 +102,7 @@ persister.destroy();
|
|
|
101
102
|
sessionStorage.clear();
|
|
102
103
|
```
|
|
103
104
|
|
|
104
|
-
<section><h2 id="build-complex-queries-with-tinyql">Build complex queries with <a href="https://tinybase.org/guides/making-queries/tinyql">TinyQL</a>.</h2><p>The <a href="https://tinybase.org/api/queries/interfaces/queries/queries"><code>Queries</code></a> object lets you query data across tables, with filtering and aggregation - using a SQL-adjacent syntax called <a href="https://tinybase.org/guides/making-queries/tinyql">TinyQL</a>.</p><p>Accessors and listeners let you sort and paginate the results efficiently, making building rich tabular interfaces easier than ever.</p><p>In this example, we have two tables: of pets and their owners. They are joined together by the pet's ownerId <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>. We select the pet's species, and the owner's state, and then aggregate the prices for the combinations.</p><p>We access the results by descending price, essentially answering the question: "which is the highest-priced species, and in which state?"</p><p>Needless to say, the results are reactive too! You can add listeners to queries just as easily as you do to raw tables.</p><p>Read more about <a href="https://tinybase.org/api/queries/interfaces/queries/queries"><code>Queries</code></a> in the <a href="https://tinybase.org/guides/releases/#v2-0">v2.0 Release Notes</a>, the <a href="https://tinybase.org/guides/making-queries">Making Queries</a> guide, and the <a href="https://tinybase.org/demos/car-analysis">Car Analysis</a> demo and <a href="https://tinybase.org/demos/movie-database">Movie Database</a> demo.</p></section>
|
|
105
|
+
<section><h2 id="build-complex-queries-with-tinyql">Build complex queries with <a href="https://beta.tinybase.org/guides/making-queries/tinyql/">TinyQL</a>.</h2><p>The <a href="https://beta.tinybase.org/api/queries/interfaces/queries/queries/"><code>Queries</code></a> object lets you query data across tables, with filtering and aggregation - using a SQL-adjacent syntax called <a href="https://beta.tinybase.org/guides/making-queries/tinyql/">TinyQL</a>.</p><p>Accessors and listeners let you sort and paginate the results efficiently, making building rich tabular interfaces easier than ever.</p><p>In this example, we have two tables: of pets and their owners. They are joined together by the pet's ownerId <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a>. We select the pet's species, and the owner's state, and then aggregate the prices for the combinations.</p><p>We access the results by descending price, essentially answering the question: "which is the highest-priced species, and in which state?"</p><p>Needless to say, the results are reactive too! You can add listeners to queries just as easily as you do to raw tables.</p><p>Read more about <a href="https://beta.tinybase.org/api/queries/interfaces/queries/queries/"><code>Queries</code></a> in the <a href="https://beta.tinybase.org/guides/releases/#v2-0">v2.0 Release Notes</a>, the <a href="https://beta.tinybase.org/guides/making-queries/">Making Queries</a> guide, and the <a href="https://beta.tinybase.org/demos/car-analysis/">Car Analysis</a> demo and <a href="https://beta.tinybase.org/demos/movie-database/">Movie Database</a> demo.</p></section>
|
|
105
106
|
|
|
106
107
|
```js
|
|
107
108
|
store
|
|
@@ -142,7 +143,7 @@ queries
|
|
|
142
143
|
queries.destroy();
|
|
143
144
|
```
|
|
144
145
|
|
|
145
|
-
<section><h2 id="define-metrics-and-aggregations">Define metrics and aggregations.</h2><p>A <a href="https://tinybase.org/api/metrics/interfaces/metrics/metrics"><code>Metrics</code></a> object makes it easy to keep a running aggregation of <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> values in each <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> of a <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>. This is useful for counting rows, but also supports averages, ranges of values, or arbitrary aggregations.</p><p>In this example, we create a new table of the pet species, and keep a track of which is most expensive. When we add horses to our pet store, the listener detects that the highest price has changed.</p><p>Read more about <a href="https://tinybase.org/api/metrics/interfaces/metrics/metrics"><code>Metrics</code></a> in the <a href="https://tinybase.org/guides/metrics-and-indexes/using-metrics">Using Metrics</a> guide.</p></section>
|
|
146
|
+
<section><h2 id="define-metrics-and-aggregations">Define metrics and aggregations.</h2><p>A <a href="https://beta.tinybase.org/api/metrics/interfaces/metrics/metrics/"><code>Metrics</code></a> object makes it easy to keep a running aggregation of <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a> values in each <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a> of a <a href="https://beta.tinybase.org/api/store/type-aliases/store/table/"><code>Table</code></a>. This is useful for counting rows, but also supports averages, ranges of values, or arbitrary aggregations.</p><p>In this example, we create a new table of the pet species, and keep a track of which is most expensive. When we add horses to our pet store, the listener detects that the highest price has changed.</p><p>Read more about <a href="https://beta.tinybase.org/api/metrics/interfaces/metrics/metrics/"><code>Metrics</code></a> in the <a href="https://beta.tinybase.org/guides/metrics-and-indexes/using-metrics/">Using Metrics</a> guide.</p></section>
|
|
146
147
|
|
|
147
148
|
```js
|
|
148
149
|
store.setTable('species', {
|
|
@@ -171,7 +172,7 @@ store.setCell('species', 'horse', 'price', 20);
|
|
|
171
172
|
metrics.destroy();
|
|
172
173
|
```
|
|
173
174
|
|
|
174
|
-
<section><h2 id="create-indexes-for-fast-lookups">Create indexes for fast lookups.</h2><p>An <a href="https://tinybase.org/api/indexes/interfaces/indexes/indexes"><code>Indexes</code></a> object makes it easy to look up all the <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> objects that have a certain value in a <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a>.</p><p>In this example, we create an index on the <code>species</code> <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> values. We can then get the the list of distinct <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> value present for that index (known as 'slices'), and the set of <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> objects that match each value.</p><p><a href="https://tinybase.org/api/indexes/interfaces/indexes/indexes"><code>Indexes</code></a> objects are reactive too. So you can set listeners on them just as you do for the data in the underlying <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>.</p><p>Read more about <a href="https://tinybase.org/api/indexes/interfaces/indexes/indexes"><code>Indexes</code></a> in the <a href="https://tinybase.org/guides/metrics-and-indexes/using-indexes">Using Indexes</a> guide.</p></section>
|
|
175
|
+
<section><h2 id="create-indexes-for-fast-lookups">Create indexes for fast lookups.</h2><p>An <a href="https://beta.tinybase.org/api/indexes/interfaces/indexes/indexes/"><code>Indexes</code></a> object makes it easy to look up all the <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a> objects that have a certain value in a <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a>.</p><p>In this example, we create an index on the <code>species</code> <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a> values. We can then get the the list of distinct <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a> value present for that index (known as 'slices'), and the set of <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a> objects that match each value.</p><p><a href="https://beta.tinybase.org/api/indexes/interfaces/indexes/indexes/"><code>Indexes</code></a> objects are reactive too. So you can set listeners on them just as you do for the data in the underlying <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a>.</p><p>Read more about <a href="https://beta.tinybase.org/api/indexes/interfaces/indexes/indexes/"><code>Indexes</code></a> in the <a href="https://beta.tinybase.org/guides/metrics-and-indexes/using-indexes/">Using Indexes</a> guide.</p></section>
|
|
175
176
|
|
|
176
177
|
```js
|
|
177
178
|
const indexes = createIndexes(store);
|
|
@@ -195,7 +196,7 @@ store.setRow('pets', 'lowly', {species: 'worm'});
|
|
|
195
196
|
indexes.destroy();
|
|
196
197
|
```
|
|
197
198
|
|
|
198
|
-
<section><h2 id="model-relationships-between-tables">Model relationships between tables.</h2><p>A <a href="https://tinybase.org/api/relationships/interfaces/relationships/relationships"><code>Relationships</code></a> object lets you associate a <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> in a local <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a> with the <a href="https://tinybase.org/api/common/type-aliases/identity/id"><code>Id</code></a> of a <a href="https://tinybase.org/api/store/type-aliases/store/row"><code>Row</code></a> in a remote <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>. You can also reference a table to itself to create linked lists.</p><p>In this example, the <code>species</code> <a href="https://tinybase.org/api/store/type-aliases/store/cell"><code>Cell</code></a> of the <code>pets</code> <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a> is used to create a relationship to the <code>species</code> <a href="https://tinybase.org/api/store/type-aliases/store/table"><code>Table</code></a>, so that we can access the price of a given pet.</p><p>Like everything else, you can set listeners on <a href="https://tinybase.org/api/relationships/interfaces/relationships/relationships"><code>Relationships</code></a> too.</p><p>Read more about <a href="https://tinybase.org/api/relationships/interfaces/relationships/relationships"><code>Relationships</code></a> in the <a href="https://tinybase.org/guides/relationships-and-checkpoints/using-relationships">Using Relationships</a> guide.</p></section>
|
|
199
|
+
<section><h2 id="model-relationships-between-tables">Model relationships between tables.</h2><p>A <a href="https://beta.tinybase.org/api/relationships/interfaces/relationships/relationships/"><code>Relationships</code></a> object lets you associate a <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a> in a local <a href="https://beta.tinybase.org/api/store/type-aliases/store/table/"><code>Table</code></a> with the <a href="https://beta.tinybase.org/api/common/type-aliases/identity/id/"><code>Id</code></a> of a <a href="https://beta.tinybase.org/api/store/type-aliases/store/row/"><code>Row</code></a> in a remote <a href="https://beta.tinybase.org/api/store/type-aliases/store/table/"><code>Table</code></a>. You can also reference a table to itself to create linked lists.</p><p>In this example, the <code>species</code> <a href="https://beta.tinybase.org/api/store/type-aliases/store/cell/"><code>Cell</code></a> of the <code>pets</code> <a href="https://beta.tinybase.org/api/store/type-aliases/store/table/"><code>Table</code></a> is used to create a relationship to the <code>species</code> <a href="https://beta.tinybase.org/api/store/type-aliases/store/table/"><code>Table</code></a>, so that we can access the price of a given pet.</p><p>Like everything else, you can set listeners on <a href="https://beta.tinybase.org/api/relationships/interfaces/relationships/relationships/"><code>Relationships</code></a> too.</p><p>Read more about <a href="https://beta.tinybase.org/api/relationships/interfaces/relationships/relationships/"><code>Relationships</code></a> in the <a href="https://beta.tinybase.org/guides/relationships-and-checkpoints/using-relationships/">Using Relationships</a> guide.</p></section>
|
|
199
200
|
|
|
200
201
|
```js
|
|
201
202
|
const relationships = createRelationships(store);
|
|
@@ -218,7 +219,7 @@ console.log(
|
|
|
218
219
|
relationships.destroy();
|
|
219
220
|
```
|
|
220
221
|
|
|
221
|
-
<section><h2 id="set-checkpoints-for-an-undo-stack">Set checkpoints for an undo stack.</h2><p>A <a href="https://tinybase.org/api/checkpoints/interfaces/checkpoints/checkpoints"><code>Checkpoints</code></a> object lets you set checkpoints on a <a href="https://tinybase.org/api/store/interfaces/store/store"><code>Store</code></a>. Move forward and backward through them to create undo and redo functions.</p><p>In this example, we set a checkpoint, then sell one of the pets. Later, the pet is brought back to the shop, and we go back to that checkpoint to revert the store to its previous state.</p><p>Read more about <a href="https://tinybase.org/api/checkpoints/interfaces/checkpoints/checkpoints"><code>Checkpoints</code></a> in the <a href="https://tinybase.org/guides/relationships-and-checkpoints/using-checkpoints">Using Checkpoints</a> guide.</p></section>
|
|
222
|
+
<section><h2 id="set-checkpoints-for-an-undo-stack">Set checkpoints for an undo stack.</h2><p>A <a href="https://beta.tinybase.org/api/checkpoints/interfaces/checkpoints/checkpoints/"><code>Checkpoints</code></a> object lets you set checkpoints on a <a href="https://beta.tinybase.org/api/store/interfaces/store/store/"><code>Store</code></a>. Move forward and backward through them to create undo and redo functions.</p><p>In this example, we set a checkpoint, then sell one of the pets. Later, the pet is brought back to the shop, and we go back to that checkpoint to revert the store to its previous state.</p><p>Read more about <a href="https://beta.tinybase.org/api/checkpoints/interfaces/checkpoints/checkpoints/"><code>Checkpoints</code></a> in the <a href="https://beta.tinybase.org/guides/relationships-and-checkpoints/using-checkpoints/">Using Checkpoints</a> guide.</p></section>
|
|
222
223
|
|
|
223
224
|
```js
|
|
224
225
|
const checkpoints = createCheckpoints(store);
|
|
@@ -235,7 +236,7 @@ console.log(store.getCell('pets', 'felix', 'sold'));
|
|
|
235
236
|
// -> false
|
|
236
237
|
```
|
|
237
238
|
|
|
238
|
-
<section><h2 id="generate-orm-like-apis">Generate ORM-like APIs</h2><p>You can easily create TypeScript <code>.d.ts</code> definitions that model your data and encourage type-safety when reading and writing data - as well as <code>.ts</code> implementations that provide ORM-like methods for your named tables.</p><p>Read more about TinyBase's tools and CLI in the <a href="https://tinybase.org/guides/developer-tools">Developer Tools</a> guide.</p></section>
|
|
239
|
+
<section><h2 id="generate-orm-like-apis">Generate ORM-like APIs</h2><p>You can easily create TypeScript <code>.d.ts</code> definitions that model your data and encourage type-safety when reading and writing data - as well as <code>.ts</code> implementations that provide ORM-like methods for your named tables.</p><p>Read more about TinyBase's tools and CLI in the <a href="https://beta.tinybase.org/guides/developer-tools/">Developer Tools</a> guide.</p></section>
|
|
239
240
|
|
|
240
241
|
```js yolo
|
|
241
242
|
const tools = createTools(store);
|
|
@@ -254,4 +255,4 @@ export const createShop: typeof createShopDecl = () => {
|
|
|
254
255
|
};
|
|
255
256
|
```
|
|
256
257
|
|
|
257
|
-
<section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://tinybase.org/api/store"><code>store</code></a> module alone, you'll only add a gzipped <em>3.5kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>7.9kB</em>.</p><p>The <code>ui-react</code> adaptor is just another <em>3.2kB</em>, the developer <a href="https://tinybase.org/api/tools"><code>tools</code></a> module is <em>4.7kB</em>, and everything is fast. Life's easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>.js.gz</th><th>.js</th><th>debug.js</th><th>.d.ts</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store">store</a></th><td>3.5kB</td><td>7.7kB</td><td>33.2kB</td><td>127.2kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/metrics">metrics</a></th><td>1.8kB</td><td>3.5kB</td><td>14.7kB</td><td>29.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/indexes">indexes</a></th><td>1.9kB</td><td>3.7kB</td><td>16.5kB</td><td>33.9kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/relationships">relationships</a></th><td>1.8kB</td><td>3.6kB</td><td>16.6kB</td><td>42.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/queries">queries</a></th><td>2.6kB</td><td>5.5kB</td><td>24.9kB</td><td>106.8kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/checkpoints">checkpoints</a></th><td>1.4kB</td><td>2.8kB</td><td>11.3kB</td><td>33.0kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/persisters">persisters</a></th><td>0.8kB</td><td>1.6kB</td><td>5.0kB</td><td>26.8kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/common">common</a></th><td>0.1kB</td><td>0.1kB</td><td>0.1kB</td><td>3.5kB</td></tr><tr><th class="right">tinybase (all)</th><td>7.9kB</td><td>18.4kB</td><td>81.0kB</td><td>0.3kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible to get up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://tinybase.org/guides/how-tinybase-is-built/testing">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>1,249</td><td>1,249</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,353</td><td>1,353</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>511</td><td>511</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>471</td><td>471</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,157</td></tr><tr><th class="right">Assertions</th><td colspan="3">11,068</td></tr></tbody></table></div><hr><p><a
|
|
258
|
+
<section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://beta.tinybase.org/api/store/"><code>store</code></a> module alone, you'll only add a gzipped <em>3.5kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>7.9kB</em>.</p><p>The <code>ui-react</code> adaptor is just another <em>3.2kB</em>, the developer <a href="https://beta.tinybase.org/api/tools/"><code>tools</code></a> module is <em>4.7kB</em>, and everything is fast. Life's easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured in the <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>.js.gz</th><th>.js</th><th>debug.js</th><th>.d.ts</th></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/store/">store</a></th><td>3.5kB</td><td>7.7kB</td><td>33.2kB</td><td>127.2kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/metrics/">metrics</a></th><td>1.8kB</td><td>3.5kB</td><td>14.7kB</td><td>29.1kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/indexes/">indexes</a></th><td>1.9kB</td><td>3.7kB</td><td>16.5kB</td><td>33.9kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/relationships/">relationships</a></th><td>1.8kB</td><td>3.6kB</td><td>16.6kB</td><td>42.1kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/queries/">queries</a></th><td>2.6kB</td><td>5.5kB</td><td>24.9kB</td><td>106.8kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/checkpoints/">checkpoints</a></th><td>1.4kB</td><td>2.8kB</td><td>11.3kB</td><td>33.0kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/persisters/">persisters</a></th><td>0.8kB</td><td>1.6kB</td><td>5.0kB</td><td>26.8kB</td></tr><tr><th class="right"><a href="https://beta.tinybase.org/api/common/">common</a></th><td>0.1kB</td><td>0.1kB</td><td>0.1kB</td><td>3.5kB</td></tr><tr><th class="right">tinybase (all)</th><td>7.9kB</td><td>18.4kB</td><td>81.0kB</td><td>0.3kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible to get up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/testing/">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>1,249</td><td>1,249</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,353</td><td>1,353</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>511</td><td>511</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>471</td><td>471</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,157</td></tr><tr><th class="right">Assertions</th><td colspan="3">11,068</td></tr></tbody></table></div><hr><p><a class="start" href="https://beta.tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://beta.tinybase.org/demos/">Try the demos</a></p><p><a href="https://beta.tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="follow">Follow</h2><ul><li>News and updates on <a href="https://twitter.com/tinybasejs">Twitter</a> and <a href="https://facebook.com/tinybasejs">Facebook</a>.</li><li><a href="https://beta.tinybase.org/guides/releases/">Release notes</a> for each version.</li><li>Packages on <a href="https://www.npmjs.com/package/tinybase/v/3.0.0-beta.0">NPM</a>.</li><li><a href="https://github.com/tinyplex/tinybase/issues">Issues</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://hachyderm.io/@jamesgpearce">me</a> in API design, minification, and documentation. It could not have been built without these great <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://beta.tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it!</p></section>
|