@koolbase/js 10.0.1 → 10.1.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/CHANGELOG.md +33 -0
- package/dist/cjs/platform.d.ts +24 -1
- package/dist/cjs/platform.js +54 -3
- package/dist/esm/platform.d.ts +24 -1
- package/dist/esm/platform.js +54 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,39 @@ is based on [Keep a Changelog][kac], and this project adheres to
|
|
|
7
7
|
[kac]: https://keepachangelog.com/en/1.1.0/
|
|
8
8
|
[semver]: https://semver.org/
|
|
9
9
|
|
|
10
|
+
## 10.1.0
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **Uploads could not work from a browser.** `upload()` required
|
|
15
|
+
`{ uri, name, type }` — a React Native shape — and fetched that URI to get
|
|
16
|
+
the bytes. A browser `File` has no `uri`, so every upload from the web
|
|
17
|
+
failed before it reached the network, while the README showed a file input
|
|
18
|
+
as if it worked. `file` now accepts a `Blob` or `File` directly and the
|
|
19
|
+
React Native form is unchanged. Round-tripped in a browser: upload,
|
|
20
|
+
download, byte-for-byte comparison.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- **`storageTier()`** on the browser adapter — `'indexeddb'`,
|
|
25
|
+
`'localstorage'` or `'memory'`. Storage is now chosen by *trying* each
|
|
26
|
+
store rather than checking whether the API exists: Safari in private
|
|
27
|
+
browsing exposes `indexedDB` and may refuse to open it, and a browser with
|
|
28
|
+
site data blocked exposes `localStorage` and throws on write. A failure at
|
|
29
|
+
any tier falls to the next, ending in memory with one console warning. An
|
|
30
|
+
app can read the tier and tell the user their session will not survive a
|
|
31
|
+
reload.
|
|
32
|
+
|
|
33
|
+
## 10.0.2
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- **A Node process that initialized the SDK never exited.** The analytics
|
|
38
|
+
flush interval, and a pending realtime reconnect, counted as work on Node's
|
|
39
|
+
event loop, so a CLI, a test runner or an SSR build step hung after its last
|
|
40
|
+
line. Both timers are now unref'd where the runtime supports it. A browser
|
|
41
|
+
is unaffected: the page keeps itself alive regardless.
|
|
42
|
+
|
|
10
43
|
## 10.0.1
|
|
11
44
|
|
|
12
45
|
### Fixed
|
package/dist/cjs/platform.d.ts
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
1
|
import type { PlatformAdapter } from '@koolbase/core';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* What a browser is actually willing to persist, decided by trying.
|
|
4
|
+
*
|
|
5
|
+
* Feature detection is not capability detection. Safari in private browsing
|
|
6
|
+
* exposes `indexedDB` and then refuses to open a database; a browser with
|
|
7
|
+
* site data blocked exposes `localStorage` and throws on write; a storage
|
|
8
|
+
* quota can be exhausted at any point afterwards. A selector that checks
|
|
9
|
+
* `typeof` commits to a store that may never work.
|
|
10
|
+
*
|
|
11
|
+
* So the store is resolved on first use, by using it, and the result is
|
|
12
|
+
* cached. A failure at any tier falls to the next, ending in memory — which
|
|
13
|
+
* always works and persists nothing.
|
|
14
|
+
*/
|
|
15
|
+
type Tier = 'indexeddb' | 'localstorage' | 'memory';
|
|
16
|
+
/**
|
|
17
|
+
* The browser adapter, plus what only a browser needs: which storage tier it
|
|
18
|
+
* settled on. Not on PlatformAdapter, because no other host has tiers — React
|
|
19
|
+
* Native's keychain either works or its package is absent.
|
|
20
|
+
*/
|
|
21
|
+
export interface BrowserPlatformAdapter extends PlatformAdapter {
|
|
22
|
+
storageTier(): Promise<Tier>;
|
|
23
|
+
}
|
|
24
|
+
export declare function browserPlatform(): BrowserPlatformAdapter;
|
|
25
|
+
export {};
|
package/dist/cjs/platform.js
CHANGED
|
@@ -107,11 +107,62 @@ function memoryStorage() {
|
|
|
107
107
|
getAllKeys: async () => Array.from(m.keys()),
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
+
async function probe(store) {
|
|
111
|
+
const k = '__koolbase_probe__';
|
|
112
|
+
try {
|
|
113
|
+
await store.setItem(k, '1');
|
|
114
|
+
const v = await store.getItem(k);
|
|
115
|
+
await store.removeItem(k);
|
|
116
|
+
return v === '1';
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function makeResolver() {
|
|
123
|
+
// Per adapter, not per module: two adapters must not share a store, or a
|
|
124
|
+
// server that built one client per request would hand one request's
|
|
125
|
+
// session to the next.
|
|
126
|
+
let resolved = null;
|
|
127
|
+
let resolving = null;
|
|
128
|
+
return () => {
|
|
129
|
+
if (resolved)
|
|
130
|
+
return Promise.resolve(resolved);
|
|
131
|
+
resolving ?? (resolving = (async () => {
|
|
132
|
+
if (typeof indexedDB !== 'undefined') {
|
|
133
|
+
const s = indexedDBStorage();
|
|
134
|
+
if (await probe(s))
|
|
135
|
+
return { tier: 'indexeddb', store: s };
|
|
136
|
+
}
|
|
137
|
+
if (typeof localStorage !== 'undefined') {
|
|
138
|
+
const s = localStorageStorage();
|
|
139
|
+
if (await probe(s))
|
|
140
|
+
return { tier: 'localstorage', store: s };
|
|
141
|
+
}
|
|
142
|
+
// eslint-disable-next-line no-console
|
|
143
|
+
console.warn('[Koolbase] No persistent storage available in this browser ' +
|
|
144
|
+
'(private browsing, blocked site data, or an exhausted quota). ' +
|
|
145
|
+
'The session and the offline queue will not survive a reload.');
|
|
146
|
+
return { tier: 'memory', store: memoryStorage() };
|
|
147
|
+
})());
|
|
148
|
+
return resolving.then((r) => { resolved = r; return r; });
|
|
149
|
+
};
|
|
150
|
+
}
|
|
110
151
|
function browserPlatform() {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
152
|
+
const resolve = makeResolver();
|
|
153
|
+
// Every call resolves first, so a browser that only reveals its refusal on
|
|
154
|
+
// use is handled here rather than by the caller.
|
|
155
|
+
const storage = {
|
|
156
|
+
getItem: async (k) => (await resolve()).store.getItem(k),
|
|
157
|
+
setItem: async (k, v) => { await (await resolve()).store.setItem(k, v); },
|
|
158
|
+
removeItem: async (k) => { await (await resolve()).store.removeItem(k); },
|
|
159
|
+
getAllKeys: async () => (await resolve()).store.getAllKeys(),
|
|
160
|
+
};
|
|
161
|
+
// Which tier this adapter settled on: 'indexeddb', 'localstorage' or
|
|
162
|
+
// 'memory'. An app that cares can warn the user before they lose a session.
|
|
163
|
+
const storageTier = async () => (await resolve()).tier;
|
|
114
164
|
return {
|
|
165
|
+
storageTier,
|
|
115
166
|
storage,
|
|
116
167
|
network: {
|
|
117
168
|
onChange: (cb) => {
|
package/dist/esm/platform.d.ts
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
1
|
import type { PlatformAdapter } from '@koolbase/core';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* What a browser is actually willing to persist, decided by trying.
|
|
4
|
+
*
|
|
5
|
+
* Feature detection is not capability detection. Safari in private browsing
|
|
6
|
+
* exposes `indexedDB` and then refuses to open a database; a browser with
|
|
7
|
+
* site data blocked exposes `localStorage` and throws on write; a storage
|
|
8
|
+
* quota can be exhausted at any point afterwards. A selector that checks
|
|
9
|
+
* `typeof` commits to a store that may never work.
|
|
10
|
+
*
|
|
11
|
+
* So the store is resolved on first use, by using it, and the result is
|
|
12
|
+
* cached. A failure at any tier falls to the next, ending in memory — which
|
|
13
|
+
* always works and persists nothing.
|
|
14
|
+
*/
|
|
15
|
+
type Tier = 'indexeddb' | 'localstorage' | 'memory';
|
|
16
|
+
/**
|
|
17
|
+
* The browser adapter, plus what only a browser needs: which storage tier it
|
|
18
|
+
* settled on. Not on PlatformAdapter, because no other host has tiers — React
|
|
19
|
+
* Native's keychain either works or its package is absent.
|
|
20
|
+
*/
|
|
21
|
+
export interface BrowserPlatformAdapter extends PlatformAdapter {
|
|
22
|
+
storageTier(): Promise<Tier>;
|
|
23
|
+
}
|
|
24
|
+
export declare function browserPlatform(): BrowserPlatformAdapter;
|
|
25
|
+
export {};
|
package/dist/esm/platform.js
CHANGED
|
@@ -104,11 +104,62 @@ function memoryStorage() {
|
|
|
104
104
|
getAllKeys: async () => Array.from(m.keys()),
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
|
+
async function probe(store) {
|
|
108
|
+
const k = '__koolbase_probe__';
|
|
109
|
+
try {
|
|
110
|
+
await store.setItem(k, '1');
|
|
111
|
+
const v = await store.getItem(k);
|
|
112
|
+
await store.removeItem(k);
|
|
113
|
+
return v === '1';
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function makeResolver() {
|
|
120
|
+
// Per adapter, not per module: two adapters must not share a store, or a
|
|
121
|
+
// server that built one client per request would hand one request's
|
|
122
|
+
// session to the next.
|
|
123
|
+
let resolved = null;
|
|
124
|
+
let resolving = null;
|
|
125
|
+
return () => {
|
|
126
|
+
if (resolved)
|
|
127
|
+
return Promise.resolve(resolved);
|
|
128
|
+
resolving ?? (resolving = (async () => {
|
|
129
|
+
if (typeof indexedDB !== 'undefined') {
|
|
130
|
+
const s = indexedDBStorage();
|
|
131
|
+
if (await probe(s))
|
|
132
|
+
return { tier: 'indexeddb', store: s };
|
|
133
|
+
}
|
|
134
|
+
if (typeof localStorage !== 'undefined') {
|
|
135
|
+
const s = localStorageStorage();
|
|
136
|
+
if (await probe(s))
|
|
137
|
+
return { tier: 'localstorage', store: s };
|
|
138
|
+
}
|
|
139
|
+
// eslint-disable-next-line no-console
|
|
140
|
+
console.warn('[Koolbase] No persistent storage available in this browser ' +
|
|
141
|
+
'(private browsing, blocked site data, or an exhausted quota). ' +
|
|
142
|
+
'The session and the offline queue will not survive a reload.');
|
|
143
|
+
return { tier: 'memory', store: memoryStorage() };
|
|
144
|
+
})());
|
|
145
|
+
return resolving.then((r) => { resolved = r; return r; });
|
|
146
|
+
};
|
|
147
|
+
}
|
|
107
148
|
export function browserPlatform() {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
149
|
+
const resolve = makeResolver();
|
|
150
|
+
// Every call resolves first, so a browser that only reveals its refusal on
|
|
151
|
+
// use is handled here rather than by the caller.
|
|
152
|
+
const storage = {
|
|
153
|
+
getItem: async (k) => (await resolve()).store.getItem(k),
|
|
154
|
+
setItem: async (k, v) => { await (await resolve()).store.setItem(k, v); },
|
|
155
|
+
removeItem: async (k) => { await (await resolve()).store.removeItem(k); },
|
|
156
|
+
getAllKeys: async () => (await resolve()).store.getAllKeys(),
|
|
157
|
+
};
|
|
158
|
+
// Which tier this adapter settled on: 'indexeddb', 'localstorage' or
|
|
159
|
+
// 'memory'. An app that cares can warn the user before they lose a session.
|
|
160
|
+
const storageTier = async () => (await resolve()).tier;
|
|
111
161
|
return {
|
|
162
|
+
storageTier,
|
|
112
163
|
storage,
|
|
113
164
|
network: {
|
|
114
165
|
onChange: (cb) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/js",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.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",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/koolbase/koolbase-react-native"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@koolbase/core": "10.0
|
|
28
|
+
"@koolbase/core": "10.1.0"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|