@koolbase/js 12.8.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/index.js +7 -1
- package/dist/cjs/react.d.ts +5 -0
- package/dist/cjs/react.js +13 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/react.d.ts +5 -0
- package/dist/esm/react.js +10 -0
- package/package.json +24 -5
- 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`,
|
package/dist/cjs/index.js
CHANGED
|
@@ -65,12 +65,18 @@ exports.Koolbase = {
|
|
|
65
65
|
(0, core_1.setPlatform)(config.platform ?? (0, platform_js_2.browserPlatform)());
|
|
66
66
|
_auth = new core_1.KoolbaseAuth(config);
|
|
67
67
|
_db = new core_1.KoolbaseDatabase(config, () => _auth?.currentUser?.id ?? null, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
|
|
68
|
-
_storage = new core_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); }
|
|
68
|
+
_storage = new core_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); },
|
|
69
|
+
// Project identity for publicUrlFor, from the bootstrap payload; a
|
|
70
|
+
// missing one nudges a refresh (as Flutter's storage client).
|
|
71
|
+
() => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
|
|
69
72
|
_fiscal = new core_1.KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
|
|
70
73
|
_realtime = new core_1.KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
|
|
71
74
|
_functions = new core_1.KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
|
|
72
75
|
const deviceId = await (0, core_1.getOrCreateDeviceId)();
|
|
73
76
|
_flags = new core_1.KoolbaseFlags(config, deviceId);
|
|
77
|
+
// The bootstrap payload (flags, config, version policy, project identity),
|
|
78
|
+
// fetched in the background as Flutter's SDK does: never blocks startup.
|
|
79
|
+
void _flags.koolbaseFetch(config.appVersion ?? '0.0.0', 'web');
|
|
74
80
|
// Opt-in: nothing is sent unless the app asks for it.
|
|
75
81
|
if (config.analyticsEnabled === true) {
|
|
76
82
|
_analytics = new core_1.KoolbaseAnalytics(config, () => _auth?.currentUser?.id ?? null);
|
|
@@ -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);
|
package/dist/esm/index.js
CHANGED
|
@@ -46,12 +46,18 @@ export const Koolbase = {
|
|
|
46
46
|
setPlatform(config.platform ?? browserPlatform());
|
|
47
47
|
_auth = new KoolbaseAuth(config);
|
|
48
48
|
_db = new KoolbaseDatabase(config, () => _auth?.currentUser?.id ?? null, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
|
|
49
|
-
_storage = new KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); }
|
|
49
|
+
_storage = new KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); },
|
|
50
|
+
// Project identity for publicUrlFor, from the bootstrap payload; a
|
|
51
|
+
// missing one nudges a refresh (as Flutter's storage client).
|
|
52
|
+
() => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
|
|
50
53
|
_fiscal = new KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
|
|
51
54
|
_realtime = new KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
|
|
52
55
|
_functions = new KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
|
|
53
56
|
const deviceId = await getOrCreateDeviceId();
|
|
54
57
|
_flags = new KoolbaseFlags(config, deviceId);
|
|
58
|
+
// The bootstrap payload (flags, config, version policy, project identity),
|
|
59
|
+
// fetched in the background as Flutter's SDK does: never blocks startup.
|
|
60
|
+
void _flags.koolbaseFetch(config.appVersion ?? '0.0.0', 'web');
|
|
55
61
|
// Opt-in: nothing is sent unless the app asks for it.
|
|
56
62
|
if (config.analyticsEnabled === true) {
|
|
57
63
|
_analytics = new KoolbaseAnalytics(config, () => _auth?.currentUser?.id ?? null);
|
|
@@ -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.
|
|
4
|
-
"description": "Koolbase SDK for the browser
|
|
3
|
+
"version": "12.10.0",
|
|
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
|
}
|