@koolbase/react-native 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/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.js +3 -4
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +1 -2
- package/package.json +2 -2
- package/dist/cjs/use-collection.d.ts +0 -12
- package/dist/cjs/use-collection.js +0 -39
- package/dist/cjs/use-record.d.ts +0 -6
- package/dist/cjs/use-record.js +0 -35
- package/dist/esm/use-collection.d.ts +0 -12
- package/dist/esm/use-collection.js +0 -36
- package/dist/esm/use-record.d.ts +0 -6
- package/dist/esm/use-record.js +0 -32
package/dist/cjs/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const Koolbase: {
|
|
|
18
18
|
checkVersion(currentVersion: string): VersionCheckResult;
|
|
19
19
|
};
|
|
20
20
|
export { SecureAuthStorage } from './auth-storage.js';
|
|
21
|
-
export type { UseCollectionResult } from '
|
|
21
|
+
export type { UseCollectionResult } from '@koolbase/core/react';
|
|
22
22
|
/**
|
|
23
23
|
* A collection as React state: loading, loaded or error, with refresh and
|
|
24
24
|
* loadMore. Equality filters only for now: `where: { field: value }`.
|
|
@@ -28,8 +28,8 @@ export type { UseCollectionResult } from './use-collection.js';
|
|
|
28
28
|
* const songs = useCollection('songs', { where: { genre: 'jazz' }, orderBy: 'title' });
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export declare const useCollection: (collection: string, query?: import("@koolbase/core").CollectionQuery) => import("
|
|
32
|
-
export type { UseRecordResult } from '
|
|
31
|
+
export declare const useCollection: (collection: string, query?: import("@koolbase/core/dist/cjs").CollectionQuery) => import("@koolbase/core/react").UseCollectionResult;
|
|
32
|
+
export type { UseRecordResult } from '@koolbase/core/react';
|
|
33
33
|
/**
|
|
34
34
|
* One record, by id, as React state: loading, loaded, notFound or error,
|
|
35
35
|
* with refresh. notFound covers a missing id, a record that does not exist,
|
|
@@ -40,4 +40,4 @@ export type { UseRecordResult } from './use-record.js';
|
|
|
40
40
|
* const song = useRecord('songs', songId);
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
export declare const useRecord: (collection: string, id: string | null | undefined) => import("
|
|
43
|
+
export declare const useRecord: (collection: string, id: string | null | undefined) => import("@koolbase/core/react").UseRecordResult;
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,8 +27,7 @@ var platform_js_1 = require("./platform.js");
|
|
|
27
27
|
Object.defineProperty(exports, "reactNativePlatform", { enumerable: true, get: function () { return platform_js_1.reactNativePlatform; } });
|
|
28
28
|
const core_1 = require("@koolbase/core");
|
|
29
29
|
const platform_js_2 = require("./platform.js");
|
|
30
|
-
const
|
|
31
|
-
const use_record_js_1 = require("./use-record.js");
|
|
30
|
+
const react_1 = require("@koolbase/core/react");
|
|
32
31
|
let _auth = null;
|
|
33
32
|
let _db = null;
|
|
34
33
|
let _storage = null;
|
|
@@ -171,7 +170,7 @@ Object.defineProperty(exports, "SecureAuthStorage", { enumerable: true, get: fun
|
|
|
171
170
|
* const songs = useCollection('songs', { where: { genre: 'jazz' }, orderBy: 'title' });
|
|
172
171
|
* ```
|
|
173
172
|
*/
|
|
174
|
-
exports.useCollection = (0,
|
|
173
|
+
exports.useCollection = (0, react_1.createUseCollection)(() => exports.Koolbase.db);
|
|
175
174
|
/**
|
|
176
175
|
* One record, by id, as React state: loading, loaded, notFound or error,
|
|
177
176
|
* with refresh. notFound covers a missing id, a record that does not exist,
|
|
@@ -182,4 +181,4 @@ exports.useCollection = (0, use_collection_js_1.createUseCollection)(() => expor
|
|
|
182
181
|
* const song = useRecord('songs', songId);
|
|
183
182
|
* ```
|
|
184
183
|
*/
|
|
185
|
-
exports.useRecord = (0,
|
|
184
|
+
exports.useRecord = (0, react_1.createUseRecord)(() => exports.Koolbase.db);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const Koolbase: {
|
|
|
18
18
|
checkVersion(currentVersion: string): VersionCheckResult;
|
|
19
19
|
};
|
|
20
20
|
export { SecureAuthStorage } from './auth-storage.js';
|
|
21
|
-
export type { UseCollectionResult } from '
|
|
21
|
+
export type { UseCollectionResult } from '@koolbase/core/react';
|
|
22
22
|
/**
|
|
23
23
|
* A collection as React state: loading, loaded or error, with refresh and
|
|
24
24
|
* loadMore. Equality filters only for now: `where: { field: value }`.
|
|
@@ -28,8 +28,8 @@ export type { UseCollectionResult } from './use-collection.js';
|
|
|
28
28
|
* const songs = useCollection('songs', { where: { genre: 'jazz' }, orderBy: 'title' });
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export declare const useCollection: (collection: string, query?: import("@koolbase/core").CollectionQuery) => import("
|
|
32
|
-
export type { UseRecordResult } from '
|
|
31
|
+
export declare const useCollection: (collection: string, query?: import("@koolbase/core").CollectionQuery) => import("@koolbase/core/react").UseCollectionResult;
|
|
32
|
+
export type { UseRecordResult } from '@koolbase/core/react';
|
|
33
33
|
/**
|
|
34
34
|
* One record, by id, as React state: loading, loaded, notFound or error,
|
|
35
35
|
* with refresh. notFound covers a missing id, a record that does not exist,
|
|
@@ -40,4 +40,4 @@ export type { UseRecordResult } from './use-record.js';
|
|
|
40
40
|
* const song = useRecord('songs', songId);
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
export declare const useRecord: (collection: string, id: string | null | undefined) => import("
|
|
43
|
+
export declare const useRecord: (collection: string, id: string | null | undefined) => import("@koolbase/core/react").UseRecordResult;
|
package/dist/esm/index.js
CHANGED
|
@@ -9,8 +9,7 @@ export * from '@koolbase/core';
|
|
|
9
9
|
export { reactNativePlatform } from './platform.js';
|
|
10
10
|
import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, KoolbaseMessaging, getOrCreateDeviceId, setPlatform, } from '@koolbase/core';
|
|
11
11
|
import { reactNativePlatform } from './platform.js';
|
|
12
|
-
import { createUseCollection } from '
|
|
13
|
-
import { createUseRecord } from './use-record.js';
|
|
12
|
+
import { createUseCollection, createUseRecord } from '@koolbase/core/react';
|
|
14
13
|
let _auth = null;
|
|
15
14
|
let _db = null;
|
|
16
15
|
let _storage = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/react-native",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.10.0",
|
|
4
4
|
"description": "React Native SDK for Koolbase \u2014 auth, database, storage, realtime, feature flags, and functions in one package.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "https://github.com/koolbase/koolbase-react-native"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@koolbase/core": "12.
|
|
27
|
+
"@koolbase/core": "12.10.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@react-native-async-storage/async-storage": "^2.2.0 || ^3.0.2",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type CollectionQuery, type CollectionState, type KoolbaseDatabase } from '@koolbase/core';
|
|
2
|
-
export interface UseCollectionResult extends CollectionState {
|
|
3
|
-
/** Page one again, from the server. What is shown stays while it runs, and stays if it fails. */
|
|
4
|
-
refresh: () => Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* The next page, appended, while hasMore. If rows are added or removed on
|
|
7
|
-
* the server between pages, one can be skipped until refresh(); none is
|
|
8
|
-
* ever shown twice.
|
|
9
|
-
*/
|
|
10
|
-
loadMore: () => Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare function createUseCollection(getDb: () => Pick<KoolbaseDatabase, 'query'>): (collection: string, query?: CollectionQuery) => UseCollectionResult;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// useCollection: a Koolbase collection as React state.
|
|
3
|
-
//
|
|
4
|
-
// A thin wrapper. Everything about getting the records right lives in
|
|
5
|
-
// @koolbase/core's KoolbaseCollectionController, which is tested there; this
|
|
6
|
-
// file only ties one controller's lifetime to a component's.
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.createUseCollection = createUseCollection;
|
|
9
|
-
const react_1 = require("react");
|
|
10
|
-
const core_1 = require("@koolbase/core");
|
|
11
|
-
const noop = () => { };
|
|
12
|
-
const done = () => Promise.resolve();
|
|
13
|
-
function createUseCollection(getDb) {
|
|
14
|
-
return function useCollection(collection, query = {}) {
|
|
15
|
-
// The query as a value: an inline `where` object is a new object every
|
|
16
|
-
// render, and must not start a new fetch every render.
|
|
17
|
-
const key = (0, core_1.collectionQueryKey)(collection, query);
|
|
18
|
-
const [current, setCurrent] = (0, react_1.useState)(null);
|
|
19
|
-
(0, react_1.useEffect)(() => {
|
|
20
|
-
// Created here, not during render. Under React strict mode an effect
|
|
21
|
-
// runs, cleans up and runs again; each run gets its own controller, so
|
|
22
|
-
// the one left running is never one that was already disposed.
|
|
23
|
-
const controller = new core_1.KoolbaseCollectionController(getDb(), collection, query);
|
|
24
|
-
setCurrent({ key, controller });
|
|
25
|
-
void controller.load();
|
|
26
|
-
return () => controller.dispose();
|
|
27
|
-
// Depends on key alone: key is collection + query, as a value.
|
|
28
|
-
}, [key]);
|
|
29
|
-
// A controller from the previous key reads as a fresh load, never as
|
|
30
|
-
// the previous query's records.
|
|
31
|
-
const controller = current?.key === key ? current.controller : null;
|
|
32
|
-
const subscribe = (0, react_1.useCallback)((onChange) => (controller ? controller.subscribe(onChange) : noop), [controller]);
|
|
33
|
-
const getSnapshot = (0, react_1.useCallback)(() => (controller ? controller.getState() : core_1.initialCollectionState), [controller]);
|
|
34
|
-
const state = (0, react_1.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
35
|
-
const refresh = (0, react_1.useCallback)(() => (controller ? controller.refresh() : done()), [controller]);
|
|
36
|
-
const loadMore = (0, react_1.useCallback)(() => (controller ? controller.loadMore() : done()), [controller]);
|
|
37
|
-
return { ...state, refresh, loadMore };
|
|
38
|
-
};
|
|
39
|
-
}
|
package/dist/cjs/use-record.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type KoolbaseDatabase, type RecordState } from '@koolbase/core';
|
|
2
|
-
export interface UseRecordResult extends RecordState {
|
|
3
|
-
/** The record again, from the server. What is shown stays while it runs, and stays if it fails. */
|
|
4
|
-
refresh: () => Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
export declare function createUseRecord(getDb: () => Pick<KoolbaseDatabase, 'get'>): (collection: string, id: string | null | undefined) => UseRecordResult;
|
package/dist/cjs/use-record.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// useRecord: one Koolbase record, by id, as React state.
|
|
3
|
-
//
|
|
4
|
-
// A thin wrapper, like useCollection: everything about getting the record
|
|
5
|
-
// right lives in @koolbase/core's KoolbaseRecordController, tested there;
|
|
6
|
-
// this file only ties one controller's lifetime to a component's.
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.createUseRecord = createUseRecord;
|
|
9
|
-
const react_1 = require("react");
|
|
10
|
-
const core_1 = require("@koolbase/core");
|
|
11
|
-
const noop = () => { };
|
|
12
|
-
const done = () => Promise.resolve();
|
|
13
|
-
function createUseRecord(getDb) {
|
|
14
|
-
return function useRecord(collection, id) {
|
|
15
|
-
const key = JSON.stringify([collection, id ?? '']);
|
|
16
|
-
const [current, setCurrent] = (0, react_1.useState)(null);
|
|
17
|
-
(0, react_1.useEffect)(() => {
|
|
18
|
-
// Created here, not during render: under React strict mode an effect
|
|
19
|
-
// runs, cleans up and runs again, and each run gets its own controller.
|
|
20
|
-
const controller = new core_1.KoolbaseRecordController(getDb(), collection, id ?? '');
|
|
21
|
-
setCurrent({ key, controller });
|
|
22
|
-
void controller.load();
|
|
23
|
-
return () => controller.dispose();
|
|
24
|
-
// Depends on key alone: key is collection + id, as a value.
|
|
25
|
-
}, [key]);
|
|
26
|
-
// A controller from the previous key reads as a fresh load, never as the
|
|
27
|
-
// previous record.
|
|
28
|
-
const controller = current?.key === key ? current.controller : null;
|
|
29
|
-
const subscribe = (0, react_1.useCallback)((onChange) => (controller ? controller.subscribe(onChange) : noop), [controller]);
|
|
30
|
-
const getSnapshot = (0, react_1.useCallback)(() => (controller ? controller.getState() : core_1.initialRecordState), [controller]);
|
|
31
|
-
const state = (0, react_1.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
32
|
-
const refresh = (0, react_1.useCallback)(() => (controller ? controller.refresh() : done()), [controller]);
|
|
33
|
-
return { ...state, refresh };
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type CollectionQuery, type CollectionState, type KoolbaseDatabase } from '@koolbase/core';
|
|
2
|
-
export interface UseCollectionResult extends CollectionState {
|
|
3
|
-
/** Page one again, from the server. What is shown stays while it runs, and stays if it fails. */
|
|
4
|
-
refresh: () => Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* The next page, appended, while hasMore. If rows are added or removed on
|
|
7
|
-
* the server between pages, one can be skipped until refresh(); none is
|
|
8
|
-
* ever shown twice.
|
|
9
|
-
*/
|
|
10
|
-
loadMore: () => Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare function createUseCollection(getDb: () => Pick<KoolbaseDatabase, 'query'>): (collection: string, query?: CollectionQuery) => UseCollectionResult;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// useCollection: a Koolbase collection as React state.
|
|
2
|
-
//
|
|
3
|
-
// A thin wrapper. Everything about getting the records right lives in
|
|
4
|
-
// @koolbase/core's KoolbaseCollectionController, which is tested there; this
|
|
5
|
-
// file only ties one controller's lifetime to a component's.
|
|
6
|
-
import { useCallback, useEffect, useState, useSyncExternalStore } from 'react';
|
|
7
|
-
import { KoolbaseCollectionController, collectionQueryKey, initialCollectionState, } from '@koolbase/core';
|
|
8
|
-
const noop = () => { };
|
|
9
|
-
const done = () => Promise.resolve();
|
|
10
|
-
export function createUseCollection(getDb) {
|
|
11
|
-
return function useCollection(collection, query = {}) {
|
|
12
|
-
// The query as a value: an inline `where` object is a new object every
|
|
13
|
-
// render, and must not start a new fetch every render.
|
|
14
|
-
const key = collectionQueryKey(collection, query);
|
|
15
|
-
const [current, setCurrent] = useState(null);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
// Created here, not during render. Under React strict mode an effect
|
|
18
|
-
// runs, cleans up and runs again; each run gets its own controller, so
|
|
19
|
-
// the one left running is never one that was already disposed.
|
|
20
|
-
const controller = new KoolbaseCollectionController(getDb(), collection, query);
|
|
21
|
-
setCurrent({ key, controller });
|
|
22
|
-
void controller.load();
|
|
23
|
-
return () => controller.dispose();
|
|
24
|
-
// Depends on key alone: key is collection + query, as a value.
|
|
25
|
-
}, [key]);
|
|
26
|
-
// A controller from the previous key reads as a fresh load, never as
|
|
27
|
-
// the previous query's records.
|
|
28
|
-
const controller = current?.key === key ? current.controller : null;
|
|
29
|
-
const subscribe = useCallback((onChange) => (controller ? controller.subscribe(onChange) : noop), [controller]);
|
|
30
|
-
const getSnapshot = useCallback(() => (controller ? controller.getState() : initialCollectionState), [controller]);
|
|
31
|
-
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
32
|
-
const refresh = useCallback(() => (controller ? controller.refresh() : done()), [controller]);
|
|
33
|
-
const loadMore = useCallback(() => (controller ? controller.loadMore() : done()), [controller]);
|
|
34
|
-
return { ...state, refresh, loadMore };
|
|
35
|
-
};
|
|
36
|
-
}
|
package/dist/esm/use-record.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type KoolbaseDatabase, type RecordState } from '@koolbase/core';
|
|
2
|
-
export interface UseRecordResult extends RecordState {
|
|
3
|
-
/** The record again, from the server. What is shown stays while it runs, and stays if it fails. */
|
|
4
|
-
refresh: () => Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
export declare function createUseRecord(getDb: () => Pick<KoolbaseDatabase, 'get'>): (collection: string, id: string | null | undefined) => UseRecordResult;
|
package/dist/esm/use-record.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// useRecord: one Koolbase record, by id, as React state.
|
|
2
|
-
//
|
|
3
|
-
// A thin wrapper, like useCollection: everything about getting the record
|
|
4
|
-
// right lives in @koolbase/core's KoolbaseRecordController, tested there;
|
|
5
|
-
// this file only ties one controller's lifetime to a component's.
|
|
6
|
-
import { useCallback, useEffect, useState, useSyncExternalStore } from 'react';
|
|
7
|
-
import { KoolbaseRecordController, initialRecordState, } from '@koolbase/core';
|
|
8
|
-
const noop = () => { };
|
|
9
|
-
const done = () => Promise.resolve();
|
|
10
|
-
export function createUseRecord(getDb) {
|
|
11
|
-
return function useRecord(collection, id) {
|
|
12
|
-
const key = JSON.stringify([collection, id ?? '']);
|
|
13
|
-
const [current, setCurrent] = useState(null);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
// Created here, not during render: under React strict mode an effect
|
|
16
|
-
// runs, cleans up and runs again, and each run gets its own controller.
|
|
17
|
-
const controller = new KoolbaseRecordController(getDb(), collection, id ?? '');
|
|
18
|
-
setCurrent({ key, controller });
|
|
19
|
-
void controller.load();
|
|
20
|
-
return () => controller.dispose();
|
|
21
|
-
// Depends on key alone: key is collection + id, as a value.
|
|
22
|
-
}, [key]);
|
|
23
|
-
// A controller from the previous key reads as a fresh load, never as the
|
|
24
|
-
// previous record.
|
|
25
|
-
const controller = current?.key === key ? current.controller : null;
|
|
26
|
-
const subscribe = useCallback((onChange) => (controller ? controller.subscribe(onChange) : noop), [controller]);
|
|
27
|
-
const getSnapshot = useCallback(() => (controller ? controller.getState() : initialRecordState), [controller]);
|
|
28
|
-
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
29
|
-
const refresh = useCallback(() => (controller ? controller.refresh() : done()), [controller]);
|
|
30
|
-
return { ...state, refresh };
|
|
31
|
-
};
|
|
32
|
-
}
|