@koolbase/react-native 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.
@@ -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 './use-collection.js';
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("./use-collection.js").UseCollectionResult;
32
- export type { UseRecordResult } from './use-record.js';
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("./use-record.js").UseRecordResult;
43
+ export declare const useRecord: (collection: string, id: string | null | undefined) => import("@koolbase/core/react").UseRecordResult;
package/dist/cjs/index.js CHANGED
@@ -1,10 +1,4 @@
1
1
  "use strict";
2
- // @koolbase/react-native — composes @koolbase/core for a React Native host.
3
- //
4
- // Everything the core exports is re-exported here unchanged, so an app that
5
- // installed this package before the split sees the same surface. What this
6
- // file adds is the composition: one Koolbase singleton, initialized with the
7
- // React Native platform adapter and keychain-backed session storage.
8
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
3
  if (k2 === undefined) k2 = k;
10
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -21,13 +15,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
15
  };
22
16
  Object.defineProperty(exports, "__esModule", { value: true });
23
17
  exports.useRecord = exports.useCollection = exports.SecureAuthStorage = exports.Koolbase = exports.reactNativePlatform = void 0;
18
+ const react_native_1 = require("react-native");
19
+ // @koolbase/react-native — composes @koolbase/core for a React Native host.
20
+ //
21
+ // Everything the core exports is re-exported here unchanged, so an app that
22
+ // installed this package before the split sees the same surface. What this
23
+ // file adds is the composition: one Koolbase singleton, initialized with the
24
+ // React Native platform adapter and keychain-backed session storage.
24
25
  __exportStar(require("@koolbase/core"), exports);
25
26
  var platform_js_1 = require("./platform.js");
26
27
  Object.defineProperty(exports, "reactNativePlatform", { enumerable: true, get: function () { return platform_js_1.reactNativePlatform; } });
27
28
  const core_1 = require("@koolbase/core");
28
29
  const platform_js_2 = require("./platform.js");
29
- const use_collection_js_1 = require("./use-collection.js");
30
- const use_record_js_1 = require("./use-record.js");
30
+ const react_1 = require("@koolbase/core/react");
31
31
  let _auth = null;
32
32
  let _db = null;
33
33
  let _storage = null;
@@ -70,7 +70,10 @@ exports.Koolbase = {
70
70
  // app catching KoolbaseUnauthenticatedError is already signed out and can
71
71
  // route to login, rather than looping on a dead token.
72
72
  async () => { await _auth?.clearStoredSession(); });
73
- _storage = new core_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
73
+ _storage = new core_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); },
74
+ // Project identity for publicUrlFor, from the bootstrap payload; a
75
+ // missing one nudges a refresh (as Flutter's storage client).
76
+ () => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
74
77
  _fiscal = new core_1.KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
75
78
  _realtime = new core_1.KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
76
79
  _functions = new core_1.KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
@@ -78,6 +81,9 @@ exports.Koolbase = {
78
81
  // (code push), and registration keying (messaging) must all agree on it.
79
82
  const deviceId = await (0, core_1.getOrCreateDeviceId)();
80
83
  _flags = new core_1.KoolbaseFlags(config, deviceId);
84
+ // The bootstrap payload (flags, config, version policy, project identity),
85
+ // fetched in the background as Flutter's SDK does: never blocks startup.
86
+ void _flags.koolbaseFetch(config.appVersion ?? '0.0.0', react_native_1.Platform.OS);
81
87
  // Initialize analytics
82
88
  // Opt-in: nothing is sent unless the app asks for it.
83
89
  if (config.analyticsEnabled === true) {
@@ -164,7 +170,7 @@ Object.defineProperty(exports, "SecureAuthStorage", { enumerable: true, get: fun
164
170
  * const songs = useCollection('songs', { where: { genre: 'jazz' }, orderBy: 'title' });
165
171
  * ```
166
172
  */
167
- exports.useCollection = (0, use_collection_js_1.createUseCollection)(() => exports.Koolbase.db);
173
+ exports.useCollection = (0, react_1.createUseCollection)(() => exports.Koolbase.db);
168
174
  /**
169
175
  * One record, by id, as React state: loading, loaded, notFound or error,
170
176
  * with refresh. notFound covers a missing id, a record that does not exist,
@@ -175,4 +181,4 @@ exports.useCollection = (0, use_collection_js_1.createUseCollection)(() => expor
175
181
  * const song = useRecord('songs', songId);
176
182
  * ```
177
183
  */
178
- exports.useRecord = (0, use_record_js_1.createUseRecord)(() => exports.Koolbase.db);
184
+ exports.useRecord = (0, react_1.createUseRecord)(() => exports.Koolbase.db);
@@ -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 './use-collection.js';
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("./use-collection.js").UseCollectionResult;
32
- export type { UseRecordResult } from './use-record.js';
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("./use-record.js").UseRecordResult;
43
+ export declare const useRecord: (collection: string, id: string | null | undefined) => import("@koolbase/core/react").UseRecordResult;
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { Platform } from 'react-native';
1
2
  // @koolbase/react-native — composes @koolbase/core for a React Native host.
2
3
  //
3
4
  // Everything the core exports is re-exported here unchanged, so an app that
@@ -8,8 +9,7 @@ export * from '@koolbase/core';
8
9
  export { reactNativePlatform } from './platform.js';
9
10
  import { KoolbaseAuth, KoolbaseDatabase, KoolbaseFiscal, KoolbaseStorage, KoolbaseRealtime, KoolbaseFunctions, KoolbaseFlags, KoolbaseAnalytics, disabledAnalytics, KoolbaseMessaging, getOrCreateDeviceId, setPlatform, } from '@koolbase/core';
10
11
  import { reactNativePlatform } from './platform.js';
11
- import { createUseCollection } from './use-collection.js';
12
- import { createUseRecord } from './use-record.js';
12
+ import { createUseCollection, createUseRecord } from '@koolbase/core/react';
13
13
  let _auth = null;
14
14
  let _db = null;
15
15
  let _storage = null;
@@ -52,7 +52,10 @@ export const Koolbase = {
52
52
  // app catching KoolbaseUnauthenticatedError is already signed out and can
53
53
  // route to login, rather than looping on a dead token.
54
54
  async () => { await _auth?.clearStoredSession(); });
55
- _storage = new KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
55
+ _storage = new KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); },
56
+ // Project identity for publicUrlFor, from the bootstrap payload; a
57
+ // missing one nudges a refresh (as Flutter's storage client).
58
+ () => _flags?.projectId() ?? '', () => { void _flags?.refresh(); });
56
59
  _fiscal = new KoolbaseFiscal(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
57
60
  _realtime = new KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), () => _auth?.currentUser?.id ?? null);
58
61
  _functions = new KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null), async () => { await _auth?.clearStoredSession(); });
@@ -60,6 +63,9 @@ export const Koolbase = {
60
63
  // (code push), and registration keying (messaging) must all agree on it.
61
64
  const deviceId = await getOrCreateDeviceId();
62
65
  _flags = new KoolbaseFlags(config, deviceId);
66
+ // The bootstrap payload (flags, config, version policy, project identity),
67
+ // fetched in the background as Flutter's SDK does: never blocks startup.
68
+ void _flags.koolbaseFetch(config.appVersion ?? '0.0.0', Platform.OS);
63
69
  // Initialize analytics
64
70
  // Opt-in: nothing is sent unless the app asks for it.
65
71
  if (config.analyticsEnabled === true) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koolbase/react-native",
3
- "version": "12.8.0",
4
- "description": "React Native SDK for Koolbase — auth, database, storage, realtime, feature flags, and functions in one package.",
3
+ "version": "12.10.0",
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",
7
7
  "files": [
@@ -24,7 +24,7 @@
24
24
  "url": "https://github.com/koolbase/koolbase-react-native"
25
25
  },
26
26
  "dependencies": {
27
- "@koolbase/core": "12.8.0"
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
- }
@@ -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;
@@ -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
- }
@@ -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;
@@ -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
- }