@koolbase/js 12.9.0 → 12.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 +27 -0
- package/dist/cjs/react.d.ts +5 -0
- package/dist/cjs/react.js +13 -0
- package/dist/esm/react.d.ts +5 -0
- package/dist/esm/react.js +10 -0
- package/package.json +23 -4
- package/react/package.json +7 -0
package/README.md
CHANGED
|
@@ -175,6 +175,33 @@ identical.
|
|
|
175
175
|
|
|
176
176
|
---
|
|
177
177
|
|
|
178
|
+
## React
|
|
179
|
+
|
|
180
|
+
`useCollection` and `useRecord` hold a collection or one record as React state,
|
|
181
|
+
exactly as in `@koolbase/react-native`. They come from their own entry, so
|
|
182
|
+
`@koolbase/js` itself never loads React; install `react` (18 or later) to use them.
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { useCollection, useRecord } from '@koolbase/js/react';
|
|
186
|
+
|
|
187
|
+
function Songs() {
|
|
188
|
+
const songs = useCollection('songs', { where: { genre: 'jazz' }, orderBy: 'title' });
|
|
189
|
+
if (songs.status === 'loading') return <p>Loading...</p>;
|
|
190
|
+
if (songs.status === 'error') return <button onClick={() => songs.refresh()}>Retry</button>;
|
|
191
|
+
return <ul>{songs.records.map((r) => <li key={r.id}>{String(r.data.title)}</li>)}</ul>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function Song({ id }: { id: string }) {
|
|
195
|
+
const song = useRecord('songs', id);
|
|
196
|
+
if (song.status === 'notFound') return <p>No such song.</p>;
|
|
197
|
+
return song.record ? <h1>{String(song.record.data.title)}</h1> : null;
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Use them after `Koolbase.initialize()`. `useCollection` also offers `loadMore()`
|
|
202
|
+
while `hasMore`; `useRecord`'s `notFound` covers a record that does not exist or
|
|
203
|
+
that this user may not read.
|
|
204
|
+
|
|
178
205
|
## Offline
|
|
179
206
|
|
|
180
207
|
Reads come from a local cache when the network is unavailable. `insert`,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { UseCollectionResult, UseRecordResult } from '@koolbase/core/react';
|
|
2
|
+
/** A collection as React state: loading, loaded or error, with refresh and loadMore. Use it after Koolbase.initialize(). */
|
|
3
|
+
export declare const useCollection: (collection: string, query?: import("@koolbase/core/dist/cjs").CollectionQuery) => import("@koolbase/core/react").UseCollectionResult;
|
|
4
|
+
/** One record, by id, as React state: loading, loaded, notFound or error, with refresh. Use it after Koolbase.initialize(). */
|
|
5
|
+
export declare const useRecord: (collection: string, id: string | null | undefined) => import("@koolbase/core/react").UseRecordResult;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @koolbase/js/react -- useCollection and useRecord for React in the browser.
|
|
3
|
+
// The same implementation @koolbase/react-native exports (@koolbase/core's
|
|
4
|
+
// React entry), bound to this package's Koolbase. A separate entry on purpose:
|
|
5
|
+
// `import { Koolbase } from '@koolbase/js'` never loads React.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useRecord = exports.useCollection = void 0;
|
|
8
|
+
const react_1 = require("@koolbase/core/react");
|
|
9
|
+
const index_js_1 = require("./index.js");
|
|
10
|
+
/** A collection as React state: loading, loaded or error, with refresh and loadMore. Use it after Koolbase.initialize(). */
|
|
11
|
+
exports.useCollection = (0, react_1.createUseCollection)(() => index_js_1.Koolbase.db);
|
|
12
|
+
/** One record, by id, as React state: loading, loaded, notFound or error, with refresh. Use it after Koolbase.initialize(). */
|
|
13
|
+
exports.useRecord = (0, react_1.createUseRecord)(() => index_js_1.Koolbase.db);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { UseCollectionResult, UseRecordResult } from '@koolbase/core/react';
|
|
2
|
+
/** A collection as React state: loading, loaded or error, with refresh and loadMore. Use it after Koolbase.initialize(). */
|
|
3
|
+
export declare const useCollection: (collection: string, query?: import("@koolbase/core").CollectionQuery) => import("@koolbase/core/react").UseCollectionResult;
|
|
4
|
+
/** One record, by id, as React state: loading, loaded, notFound or error, with refresh. Use it after Koolbase.initialize(). */
|
|
5
|
+
export declare const useRecord: (collection: string, id: string | null | undefined) => import("@koolbase/core/react").UseRecordResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @koolbase/js/react -- useCollection and useRecord for React in the browser.
|
|
2
|
+
// The same implementation @koolbase/react-native exports (@koolbase/core's
|
|
3
|
+
// React entry), bound to this package's Koolbase. A separate entry on purpose:
|
|
4
|
+
// `import { Koolbase } from '@koolbase/js'` never loads React.
|
|
5
|
+
import { createUseCollection, createUseRecord } from '@koolbase/core/react';
|
|
6
|
+
import { Koolbase } from './index.js';
|
|
7
|
+
/** A collection as React state: loading, loaded or error, with refresh and loadMore. Use it after Koolbase.initialize(). */
|
|
8
|
+
export const useCollection = createUseCollection(() => Koolbase.db);
|
|
9
|
+
/** One record, by id, as React state: loading, loaded, notFound or error, with refresh. Use it after Koolbase.initialize(). */
|
|
10
|
+
export const useRecord = createUseRecord(() => Koolbase.db);
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/js",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.10.0",
|
|
4
4
|
"description": "Koolbase SDK for the browser \u2014 auth, database, storage, realtime, functions, flags and offline sync in one package.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
|
-
"CHANGELOG.md"
|
|
9
|
+
"CHANGELOG.md",
|
|
10
|
+
"react"
|
|
10
11
|
],
|
|
11
12
|
"scripts": {
|
|
12
13
|
"build": "node ../../scripts/build-package.js js"
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"url": "https://github.com/koolbase/koolbase-react-native"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@koolbase/core": "12.
|
|
29
|
+
"@koolbase/core": "12.10.0"
|
|
29
30
|
},
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
|
@@ -42,7 +43,25 @@
|
|
|
42
43
|
"default": "./dist/cjs/index.js"
|
|
43
44
|
}
|
|
44
45
|
},
|
|
46
|
+
"./react": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/esm/react.d.ts",
|
|
49
|
+
"default": "./dist/esm/react.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/cjs/react.d.ts",
|
|
53
|
+
"default": "./dist/cjs/react.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
45
56
|
"./package.json": "./package.json"
|
|
46
57
|
},
|
|
47
|
-
"sideEffects": false
|
|
58
|
+
"sideEffects": false,
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"react": ">=18.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"react": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
48
67
|
}
|