bisonbase 0.0.0-stage → 0.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/README.md +112 -2
- package/dist/auth.d.ts +16 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +75 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +149 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +478 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +12 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +34 -0
- package/dist/react.js.map +1 -0
- package/dist/schema.d.ts +22 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +57 -0
- package/dist/schema.js.map +1 -0
- package/dist/sql.d.ts +29 -0
- package/dist/sql.d.ts.map +1 -0
- package/dist/sql.js +203 -0
- package/dist/sql.js.map +1 -0
- package/dist/table.d.ts +20 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +30 -0
- package/dist/table.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/values.d.ts +10 -0
- package/dist/values.d.ts.map +1 -0
- package/dist/values.js +109 -0
- package/dist/values.js.map +1 -0
- package/package.json +48 -4
- package/src/auth.ts +90 -0
- package/src/client.ts +551 -0
- package/src/index.ts +29 -0
- package/src/react.tsx +56 -0
- package/src/schema.ts +67 -0
- package/src/sql.ts +204 -0
- package/src/table.ts +48 -0
- package/src/types.ts +87 -0
- package/src/values.ts +99 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
// The client: BisonBase (sign-in and the connection to the server), UserDb (one SQLite file
|
|
2
|
+
// per user) and Table (typed select / insert / update / delete, plus cached live queries).
|
|
3
|
+
import { revoke, startSignIn, takeSignInResponse } from "./auth.js";
|
|
4
|
+
import { migrationSql, SchemaError } from "./schema.js";
|
|
5
|
+
import { deleteSql, insertSql, selectSql, updateSql } from "./sql.js";
|
|
6
|
+
import { checkName, parseTable } from "./table.js";
|
|
7
|
+
import { decode, encodeParam } from "./values.js";
|
|
8
|
+
/** An error response from the bisonbase API. */
|
|
9
|
+
export class ApiError extends Error {
|
|
10
|
+
name = 'ApiError';
|
|
11
|
+
status;
|
|
12
|
+
code;
|
|
13
|
+
constructor(status, code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** An operation needed the user to be signed in. */
|
|
20
|
+
export class NotSignedInError extends Error {
|
|
21
|
+
name = 'NotSignedInError';
|
|
22
|
+
constructor() {
|
|
23
|
+
super('Not signed in');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let hooks = null;
|
|
27
|
+
/** @internal */
|
|
28
|
+
export function setHooks(h) {
|
|
29
|
+
hooks = h;
|
|
30
|
+
}
|
|
31
|
+
const EMPTY = Object.freeze([]);
|
|
32
|
+
const SIGNED_OUT = Object.freeze({ rows: EMPTY, loading: false, error: null });
|
|
33
|
+
const LOADING = Object.freeze({ rows: EMPTY, loading: true, error: null });
|
|
34
|
+
const EXPIRED = 'Your sign-in expired or was revoked. Please sign in again.';
|
|
35
|
+
function storage() {
|
|
36
|
+
try {
|
|
37
|
+
return globalThis.localStorage ?? null;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** JSON with object keys sorted, so equal options give equal cache keys. */
|
|
44
|
+
function stableKey(value) {
|
|
45
|
+
return JSON.stringify(value, (_, v) => v && typeof v === 'object' && !Array.isArray(v) && !(v instanceof Uint8Array)
|
|
46
|
+
? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
47
|
+
: v instanceof Uint8Array
|
|
48
|
+
? { $bytes: Array.from(v) }
|
|
49
|
+
: v);
|
|
50
|
+
}
|
|
51
|
+
/** The connection to a bisonbase server for one app. Make one per page. */
|
|
52
|
+
export class BisonBase {
|
|
53
|
+
/** The instance `<AuthElement />` and other React helpers use. */
|
|
54
|
+
static instance = null;
|
|
55
|
+
appId;
|
|
56
|
+
appName;
|
|
57
|
+
/** The server's origin, e.g. `https://example.com/bb`, without a trailing slash. */
|
|
58
|
+
url;
|
|
59
|
+
#token = null;
|
|
60
|
+
#persist;
|
|
61
|
+
#auth = { status: 'signed-out' };
|
|
62
|
+
/** Resolves when no sign-in is pending. */
|
|
63
|
+
#settled = Promise.resolve();
|
|
64
|
+
/** Bumped whenever the token changes, so results fetched with an old token are dropped. */
|
|
65
|
+
#epoch = 0;
|
|
66
|
+
#authListeners = new Set();
|
|
67
|
+
#dbs = new Map();
|
|
68
|
+
#queries = new Map();
|
|
69
|
+
/**
|
|
70
|
+
* @param appId A UUID that identifies the app and never changes; the app's files live in
|
|
71
|
+
* `apps/<appId>/` in each user's account. Make one with `crypto.randomUUID()`.
|
|
72
|
+
* @param appName The name shown to users when they sign in and in their file browser.
|
|
73
|
+
*/
|
|
74
|
+
constructor(appId, appName, options = {}) {
|
|
75
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(appId)) {
|
|
76
|
+
throw new Error(`App id must be a UUID (make one with crypto.randomUUID()), got "${appId}"`);
|
|
77
|
+
}
|
|
78
|
+
this.appId = appId.toLowerCase();
|
|
79
|
+
this.appName = appName;
|
|
80
|
+
const base = options.url ?? (typeof location !== 'undefined' ? `${location.origin}/bb` : undefined);
|
|
81
|
+
if (!base)
|
|
82
|
+
throw new Error('Pass options.url: there is no current page to default to');
|
|
83
|
+
this.url = base.replace(/\/+$/, '');
|
|
84
|
+
this.#persist = options.token === undefined;
|
|
85
|
+
if (BisonBase.instance) {
|
|
86
|
+
console.warn('BisonBase: more than one instance was created; React helpers use the latest one');
|
|
87
|
+
}
|
|
88
|
+
BisonBase.instance = this;
|
|
89
|
+
if (options.token !== undefined) {
|
|
90
|
+
this.#setToken(options.token);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const response = takeSignInResponse(this.url);
|
|
94
|
+
if (response) {
|
|
95
|
+
this.#setAuth({ status: 'pending' });
|
|
96
|
+
this.#settled = response.then((token) => this.#setToken(token), (e) => this.#setToken(null, e.message));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const saved = storage()?.getItem(this.#tokenKey) ?? null;
|
|
100
|
+
if (saved)
|
|
101
|
+
this.#setToken(saved);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
105
|
+
// Pick up changes made in other tabs or apps when the user comes back to this one.
|
|
106
|
+
window.addEventListener('focus', () => this.#refreshAll());
|
|
107
|
+
window.addEventListener('storage', (e) => {
|
|
108
|
+
if (e.key === this.#tokenKey && this.#persist && e.newValue !== this.#token)
|
|
109
|
+
this.#setToken(e.newValue);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
get #tokenKey() {
|
|
114
|
+
return `bisonbase:token:${this.url}:${this.appId}`;
|
|
115
|
+
}
|
|
116
|
+
/** Whether the user is signed in. */
|
|
117
|
+
get auth() {
|
|
118
|
+
return this.#auth;
|
|
119
|
+
}
|
|
120
|
+
/** Call `listener` whenever `auth` changes. Returns a function that stops listening. */
|
|
121
|
+
onAuthChange(listener) {
|
|
122
|
+
this.#authListeners.add(listener);
|
|
123
|
+
return () => this.#authListeners.delete(listener);
|
|
124
|
+
}
|
|
125
|
+
/** Send the browser to the server to sign in; it comes back to the current page. */
|
|
126
|
+
signIn() {
|
|
127
|
+
return startSignIn({ server: this.url, appId: this.appId, appName: this.appName, scope: 'db:write' });
|
|
128
|
+
}
|
|
129
|
+
/** Forget the token here and revoke it on the server. */
|
|
130
|
+
async signOut() {
|
|
131
|
+
const token = this.#token;
|
|
132
|
+
this.#setToken(null);
|
|
133
|
+
if (token && this.#persist)
|
|
134
|
+
await revoke(this.url, token);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A database that each user gets their own copy of, stored as `apps/<appId>/<name>.db`
|
|
138
|
+
* in their account. Only that user can read or change it.
|
|
139
|
+
*/
|
|
140
|
+
createUserDb(name) {
|
|
141
|
+
if (!/^[A-Za-z0-9_-]+$/.test(name))
|
|
142
|
+
throw new Error(`Database name "${name}" must be letters, digits, "_" and "-"`);
|
|
143
|
+
if (this.#dbs.has(name))
|
|
144
|
+
throw new Error(`Database "${name}" was already created`);
|
|
145
|
+
const db = new UserDb(this, name);
|
|
146
|
+
this.#dbs.set(name, db);
|
|
147
|
+
return db;
|
|
148
|
+
}
|
|
149
|
+
#setAuth(state) {
|
|
150
|
+
this.#auth = state;
|
|
151
|
+
for (const listener of [...this.#authListeners])
|
|
152
|
+
listener();
|
|
153
|
+
}
|
|
154
|
+
#setToken(token, error) {
|
|
155
|
+
const changed = token !== this.#token;
|
|
156
|
+
this.#token = token;
|
|
157
|
+
if (this.#persist) {
|
|
158
|
+
const s = storage();
|
|
159
|
+
if (token)
|
|
160
|
+
s?.setItem(this.#tokenKey, token);
|
|
161
|
+
else
|
|
162
|
+
s?.removeItem(this.#tokenKey);
|
|
163
|
+
}
|
|
164
|
+
this.#setAuth(token ? { status: 'signed-in' } : error ? { status: 'signed-out', error } : { status: 'signed-out' });
|
|
165
|
+
if (!changed)
|
|
166
|
+
return;
|
|
167
|
+
this.#epoch++;
|
|
168
|
+
for (const db of this.#dbs.values())
|
|
169
|
+
db._reset();
|
|
170
|
+
for (const q of this.#queries.values())
|
|
171
|
+
q._authChanged();
|
|
172
|
+
}
|
|
173
|
+
#refreshAll() {
|
|
174
|
+
for (const q of this.#queries.values())
|
|
175
|
+
q._invalidate();
|
|
176
|
+
}
|
|
177
|
+
/** @internal A cached live query, shared by everything that asks for the same rows. */
|
|
178
|
+
_liveQuery(key, run, table) {
|
|
179
|
+
let q = this.#queries.get(key);
|
|
180
|
+
if (!q) {
|
|
181
|
+
q = new LiveQuery(this, run, table, () => this.#queries.delete(key));
|
|
182
|
+
this.#queries.set(key, q);
|
|
183
|
+
}
|
|
184
|
+
return q;
|
|
185
|
+
}
|
|
186
|
+
/** @internal Mark live queries on `table` (or on every table in `db`) stale, and reload the ones in use. */
|
|
187
|
+
_invalidate(db, table) {
|
|
188
|
+
for (const q of this.#queries.values()) {
|
|
189
|
+
if (table ? q.table === table : q.table.db === db)
|
|
190
|
+
q._invalidate();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** @internal */
|
|
194
|
+
get _epoch() {
|
|
195
|
+
return this.#epoch;
|
|
196
|
+
}
|
|
197
|
+
/** @internal Whether a query can run now (signed in or signing in). */
|
|
198
|
+
get _active() {
|
|
199
|
+
return this.#auth.status !== 'signed-out';
|
|
200
|
+
}
|
|
201
|
+
/** @internal Call the files API, after any pending sign-in. */
|
|
202
|
+
async _request(path, op, body) {
|
|
203
|
+
await this.#settled;
|
|
204
|
+
const token = this.#token;
|
|
205
|
+
if (!token)
|
|
206
|
+
throw new NotSignedInError();
|
|
207
|
+
const headers = { authorization: `Bearer ${token}` };
|
|
208
|
+
if (body !== undefined)
|
|
209
|
+
headers['content-type'] = 'application/json';
|
|
210
|
+
const res = await fetch(`${this.url}/api/v1/files/${path}?op=${op}`, {
|
|
211
|
+
method: op === 'schema' ? 'GET' : 'POST',
|
|
212
|
+
headers,
|
|
213
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
214
|
+
});
|
|
215
|
+
const json = await res.json().catch(() => ({}));
|
|
216
|
+
if (!res.ok) {
|
|
217
|
+
if (res.status === 401 && this.#token === token)
|
|
218
|
+
this.#setToken(null, EXPIRED);
|
|
219
|
+
throw new ApiError(res.status, json.error?.code ?? 'unknown', json.error?.message ?? res.statusText);
|
|
220
|
+
}
|
|
221
|
+
return json;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** A query whose rows are kept up to date while something is subscribed to it. */
|
|
225
|
+
export class LiveQuery {
|
|
226
|
+
#bb;
|
|
227
|
+
#run;
|
|
228
|
+
#dispose;
|
|
229
|
+
#state;
|
|
230
|
+
#listeners = new Set();
|
|
231
|
+
#stale = true;
|
|
232
|
+
#running = false;
|
|
233
|
+
#again = false;
|
|
234
|
+
#gc;
|
|
235
|
+
table;
|
|
236
|
+
constructor(bb, run, table, dispose) {
|
|
237
|
+
this.#bb = bb;
|
|
238
|
+
this.#run = run;
|
|
239
|
+
this.table = table;
|
|
240
|
+
this.#dispose = dispose;
|
|
241
|
+
this.#state = bb._active ? LOADING : SIGNED_OUT;
|
|
242
|
+
}
|
|
243
|
+
/** For `useSyncExternalStore`. */
|
|
244
|
+
subscribe = (listener) => {
|
|
245
|
+
this.#listeners.add(listener);
|
|
246
|
+
clearTimeout(this.#gc);
|
|
247
|
+
if (this.#stale)
|
|
248
|
+
void this.#load();
|
|
249
|
+
return () => {
|
|
250
|
+
this.#listeners.delete(listener);
|
|
251
|
+
// Keep the rows a little while in case the same query is used again soon.
|
|
252
|
+
if (this.#listeners.size === 0) {
|
|
253
|
+
this.#gc = setTimeout(this.#dispose, 30_000);
|
|
254
|
+
this.#gc.unref?.();
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
/** For `useSyncExternalStore`. Returns the same object until something changes. */
|
|
259
|
+
getSnapshot = () => this.#state;
|
|
260
|
+
#set(state) {
|
|
261
|
+
this.#state = state;
|
|
262
|
+
for (const listener of [...this.#listeners])
|
|
263
|
+
listener();
|
|
264
|
+
}
|
|
265
|
+
/** @internal */
|
|
266
|
+
_invalidate() {
|
|
267
|
+
this.#stale = true;
|
|
268
|
+
if (this.#listeners.size)
|
|
269
|
+
void this.#load();
|
|
270
|
+
}
|
|
271
|
+
/** @internal */
|
|
272
|
+
_authChanged() {
|
|
273
|
+
this.#set(this.#bb._active ? LOADING : SIGNED_OUT);
|
|
274
|
+
this._invalidate();
|
|
275
|
+
}
|
|
276
|
+
async #load() {
|
|
277
|
+
if (!this.#bb._active) {
|
|
278
|
+
if (this.#state !== SIGNED_OUT)
|
|
279
|
+
this.#set(SIGNED_OUT);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (this.#running) {
|
|
283
|
+
this.#again = true;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this.#running = true;
|
|
287
|
+
try {
|
|
288
|
+
do {
|
|
289
|
+
this.#again = false;
|
|
290
|
+
this.#stale = false;
|
|
291
|
+
const epoch = this.#bb._epoch;
|
|
292
|
+
try {
|
|
293
|
+
const rows = await this.#run();
|
|
294
|
+
if (!this.#again && epoch === this.#bb._epoch)
|
|
295
|
+
this.#set({ rows, loading: false, error: null });
|
|
296
|
+
}
|
|
297
|
+
catch (e) {
|
|
298
|
+
if (this.#again || epoch !== this.#bb._epoch)
|
|
299
|
+
continue;
|
|
300
|
+
if (e instanceof NotSignedInError)
|
|
301
|
+
this.#set(SIGNED_OUT);
|
|
302
|
+
else
|
|
303
|
+
this.#set({ rows: this.#state.rows, loading: false, error: e });
|
|
304
|
+
}
|
|
305
|
+
} while (this.#again);
|
|
306
|
+
}
|
|
307
|
+
finally {
|
|
308
|
+
this.#running = false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/** A database each signed-in user has their own copy of. Make one with `bb.createUserDb`. */
|
|
313
|
+
export class UserDb {
|
|
314
|
+
bb;
|
|
315
|
+
name;
|
|
316
|
+
/** Path within the user's files, e.g. `apps/<appId>/todos.db`. */
|
|
317
|
+
path;
|
|
318
|
+
#tables = new Map();
|
|
319
|
+
#ready = null;
|
|
320
|
+
/** @internal Use `bb.createUserDb`. */
|
|
321
|
+
constructor(bb, name) {
|
|
322
|
+
this.bb = bb;
|
|
323
|
+
this.name = name;
|
|
324
|
+
this.path = `apps/${bb.appId}/${name}.db`;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Declare a table. It's created, or new columns are added, the first time it's used after
|
|
328
|
+
* signing in. Every table also has an `id` integer primary key.
|
|
329
|
+
*
|
|
330
|
+
* ```ts
|
|
331
|
+
* const todos = db.createTable("todos", { content: "text", done: ["boolean", false] })
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
createTable(name, columns) {
|
|
335
|
+
checkName('Table', name);
|
|
336
|
+
if ([...this.#tables.keys()].some((t) => t.toLowerCase() === name.toLowerCase())) {
|
|
337
|
+
throw new Error(`Table "${name}" was already created in ${this.name}`);
|
|
338
|
+
}
|
|
339
|
+
const table = new Table(this, parseTable(name, columns));
|
|
340
|
+
this.#tables.set(name, table);
|
|
341
|
+
this.#ready = null;
|
|
342
|
+
return table;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Run raw SQL against this database, returning rows as objects. Values interpolated into
|
|
346
|
+
* the template are sent as bound parameters. Booleans come back as 0/1 and JSON as text.
|
|
347
|
+
*
|
|
348
|
+
* ```ts
|
|
349
|
+
* const rows = await db.sql`SELECT count(*) AS n FROM todos WHERE done = ${false}`
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
async sql(strings, ...values) {
|
|
353
|
+
const result = await this._query({ sql: strings.join('?'), params: values.map(encodeParam) });
|
|
354
|
+
this.bb._invalidate(this);
|
|
355
|
+
return result.rows.map((row) => Object.fromEntries(result.columns.map((c, i) => [c, row[i]])));
|
|
356
|
+
}
|
|
357
|
+
/** @internal Forget that the schema was set up (the user changed). */
|
|
358
|
+
_reset() {
|
|
359
|
+
this.#ready = null;
|
|
360
|
+
}
|
|
361
|
+
/** @internal Create the database and bring its tables up to date, once per sign-in. */
|
|
362
|
+
_ensure() {
|
|
363
|
+
if (!this.#ready) {
|
|
364
|
+
const ready = this.#setUp();
|
|
365
|
+
this.#ready = ready;
|
|
366
|
+
ready.catch(() => {
|
|
367
|
+
if (this.#ready === ready)
|
|
368
|
+
this.#ready = null; // try again next time
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return this.#ready;
|
|
372
|
+
}
|
|
373
|
+
async #setUp(attempt = 0) {
|
|
374
|
+
const tables = [...this.#tables.values()].map((t) => t.def);
|
|
375
|
+
await this.bb._request(this.path, 'mkdb');
|
|
376
|
+
const schema = await this.bb._request(this.path, 'schema');
|
|
377
|
+
const statements = migrationSql(tables, schema, this.path);
|
|
378
|
+
if (statements.length === 0)
|
|
379
|
+
return;
|
|
380
|
+
try {
|
|
381
|
+
await this.bb._request(this.path, 'batch', { statements: statements.map((sql) => ({ sql })) });
|
|
382
|
+
}
|
|
383
|
+
catch (e) {
|
|
384
|
+
// Another tab may have made the same change at the same time; look again.
|
|
385
|
+
if (attempt === 0 && e instanceof ApiError && e.status === 400)
|
|
386
|
+
return this.#setUp(1);
|
|
387
|
+
throw e;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/** @internal */
|
|
391
|
+
async _query(stmt) {
|
|
392
|
+
await this._ensure();
|
|
393
|
+
return this.bb._request(this.path, 'query', stmt);
|
|
394
|
+
}
|
|
395
|
+
/** @internal Run statements in one transaction. */
|
|
396
|
+
async _batch(stmts) {
|
|
397
|
+
await this._ensure();
|
|
398
|
+
return (await this.bb._request(this.path, 'batch', { statements: stmts })).results;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/** A table in a database. Make one with `db.createTable`. */
|
|
402
|
+
export class Table {
|
|
403
|
+
db;
|
|
404
|
+
/** @internal */
|
|
405
|
+
def;
|
|
406
|
+
/** @internal Use `db.createTable`. */
|
|
407
|
+
constructor(db, def) {
|
|
408
|
+
this.db = db;
|
|
409
|
+
this.def = def;
|
|
410
|
+
}
|
|
411
|
+
get name() {
|
|
412
|
+
return this.def.name;
|
|
413
|
+
}
|
|
414
|
+
#rows(result) {
|
|
415
|
+
const types = result.columns.map((c) => (c === 'id' ? null : this.def.byName.get(c)?.type ?? null));
|
|
416
|
+
return result.rows.map((row) => Object.fromEntries(row.map((v, i) => [result.columns[i], types[i] ? decode(types[i], v) : v])));
|
|
417
|
+
}
|
|
418
|
+
/** Fetch rows once. For rows that stay up to date in a component, use `useSelect`. */
|
|
419
|
+
async select(options) {
|
|
420
|
+
const result = await this.db._query(selectSql(this.def, options));
|
|
421
|
+
if (result.truncated)
|
|
422
|
+
console.warn(`BisonBase: results from ${this.name} were truncated by the server's row limit`);
|
|
423
|
+
return this.#rows(result);
|
|
424
|
+
}
|
|
425
|
+
async insert(rows) {
|
|
426
|
+
const many = Array.isArray(rows);
|
|
427
|
+
const list = (many ? rows : [rows]);
|
|
428
|
+
const stmts = list.map((row) => insertSql(this.def, row));
|
|
429
|
+
if (stmts.length === 0)
|
|
430
|
+
return [];
|
|
431
|
+
const results = many ? await this.db._batch(stmts) : [await this.db._query(stmts[0])];
|
|
432
|
+
this.db.bb._invalidate(this.db, this);
|
|
433
|
+
const inserted = results.flatMap((r) => this.#rows(r));
|
|
434
|
+
return many ? inserted : inserted[0];
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Change the rows matching `where` (or the row with that id). Returns how many changed.
|
|
438
|
+
* Pass `{}` to change every row.
|
|
439
|
+
*/
|
|
440
|
+
async update(where, changes) {
|
|
441
|
+
const stmt = updateSql(this.def, where, changes);
|
|
442
|
+
if (!stmt)
|
|
443
|
+
return 0;
|
|
444
|
+
const result = await this.db._query(stmt);
|
|
445
|
+
this.db.bb._invalidate(this.db, this);
|
|
446
|
+
return result.changes;
|
|
447
|
+
}
|
|
448
|
+
/** Delete the rows matching `where` (or the row with that id). Returns how many were deleted. Pass `{}` to delete every row. */
|
|
449
|
+
async delete(where) {
|
|
450
|
+
if (where === undefined)
|
|
451
|
+
throw new Error('delete needs a where; pass {} to delete every row');
|
|
452
|
+
const result = await this.db._query(deleteSql(this.def, where));
|
|
453
|
+
this.db.bb._invalidate(this.db, this);
|
|
454
|
+
return result.changes;
|
|
455
|
+
}
|
|
456
|
+
/** The live query for these options, shared with every other user of the same options. */
|
|
457
|
+
liveQuery(options) {
|
|
458
|
+
const key = stableKey([this.db.name, this.name, options ?? {}]);
|
|
459
|
+
// Validate now so mistakes throw where the query is written, not later in a fetch.
|
|
460
|
+
selectSql(this.def, options);
|
|
461
|
+
return this.db.bb._liveQuery(key, () => this.select(options), this);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* React hook: the rows matching `options`, kept up to date. Empty while signed out or
|
|
465
|
+
* loading. Needs `import "bisonbase/react"` somewhere in the app.
|
|
466
|
+
*/
|
|
467
|
+
useSelect(options) {
|
|
468
|
+
return this.useSelectState(options).rows;
|
|
469
|
+
}
|
|
470
|
+
/** React hook: like `useSelect`, plus whether it's loading and the last error. */
|
|
471
|
+
useSelectState(options) {
|
|
472
|
+
if (!hooks)
|
|
473
|
+
throw new Error('useSelect needs React: add `import "bisonbase/react"` to your app');
|
|
474
|
+
return hooks.useQuery(this.liveQuery(options));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
export { SchemaError };
|
|
478
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2FAA2F;AAE3F,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAqB,MAAM,aAAa,CAAA;AAC1E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAkB,MAAM,UAAU,CAAA;AACrF,OAAO,EAAE,SAAS,EAAE,UAAU,EAAiB,MAAM,YAAY,CAAA;AAEjE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAmBjD,gDAAgD;AAChD,MAAM,OAAO,QAAS,SAAQ,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Q,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;IAChD,CAAC;CACF;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { ApiError, BisonBase, LiveQuery, NotSignedInError, SchemaError, Table, UserDb, type AuthState, type BisonBaseOptions, type QueryResult, type QueryState, type InsertOf, type RowOf, } from './client.ts';
|
|
2
|
+
export type { ColumnSpec, ColumnType, Columns, InsertFor, Json, Ops, OrderBy, RowFor, SelectOptions, UpdateFor, Where, Wire, } from './types.ts';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,KAAK,EACL,MAAM,EACN,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,KAAK,GACX,MAAM,aAAa,CAAA;AACpB,YAAY,EACV,UAAU,EACV,UAAU,EACV,OAAO,EACP,SAAS,EACT,IAAI,EACJ,GAAG,EACH,OAAO,EACP,MAAM,EACN,aAAa,EACb,SAAS,EACT,KAAK,EACL,IAAI,GACL,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,KAAK,EACL,MAAM,GAOP,MAAM,aAAa,CAAA"}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BisonBase, type AuthState } from './client.ts';
|
|
2
|
+
/** Whether the user is signed in; re-renders when that changes. */
|
|
3
|
+
export declare function useAuth(bb?: BisonBase): AuthState;
|
|
4
|
+
export interface AuthElementProps {
|
|
5
|
+
/** Default: the BisonBase created last. */
|
|
6
|
+
bb?: BisonBase;
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A sign-in button, or a sign-out button once signed in. Unstyled; target `.bb-auth`. */
|
|
10
|
+
export declare function AuthElement({ bb, className }: AuthElementProps): import("react").JSX.Element;
|
|
11
|
+
export { BisonBase };
|
|
12
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAY,KAAK,SAAS,EAAmC,MAAM,aAAa,CAAA;AAclG,mEAAmE;AACnE,wBAAgB,OAAO,CAAC,EAAE,CAAC,EAAE,SAAS,GAAG,SAAS,CAOjD;AAED,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,EAAE,CAAC,EAAE,SAAS,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,0FAA0F;AAC1F,wBAAgB,WAAW,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,gBAAgB,+BAmB9D;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// React bindings. Importing this module makes `table.useSelect()` work.
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import { BisonBase, setHooks } from "./client.js";
|
|
5
|
+
setHooks({
|
|
6
|
+
useQuery(query) {
|
|
7
|
+
return useSyncExternalStore(query.subscribe, query.getSnapshot, query.getSnapshot);
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
function instance(bb) {
|
|
11
|
+
const found = bb ?? BisonBase.instance;
|
|
12
|
+
if (!found)
|
|
13
|
+
throw new Error('Create a BisonBase before rendering components that use it');
|
|
14
|
+
return found;
|
|
15
|
+
}
|
|
16
|
+
/** Whether the user is signed in; re-renders when that changes. */
|
|
17
|
+
export function useAuth(bb) {
|
|
18
|
+
const b = instance(bb);
|
|
19
|
+
return useSyncExternalStore((listener) => b.onAuthChange(listener), () => b.auth, () => b.auth);
|
|
20
|
+
}
|
|
21
|
+
/** A sign-in button, or a sign-out button once signed in. Unstyled; target `.bb-auth`. */
|
|
22
|
+
export function AuthElement({ bb, className }) {
|
|
23
|
+
const b = instance(bb);
|
|
24
|
+
const auth = useAuth(b);
|
|
25
|
+
const cls = className ? `bb-auth ${className}` : 'bb-auth';
|
|
26
|
+
if (auth.status === 'pending')
|
|
27
|
+
return _jsx("span", { className: cls, "data-status": "pending", children: "Signing in\u2026" });
|
|
28
|
+
if (auth.status === 'signed-in') {
|
|
29
|
+
return (_jsxs("span", { className: cls, "data-status": "signed-in", children: [_jsx("span", { className: "bb-auth-label", children: "Signed in" }), ' ', _jsx("button", { type: "button", onClick: () => void b.signOut(), children: "Sign out" })] }));
|
|
30
|
+
}
|
|
31
|
+
return (_jsxs("span", { className: cls, "data-status": "signed-out", children: [_jsx("button", { type: "button", onClick: () => void b.signIn(), children: "Sign in" }), auth.error && _jsxs("span", { className: "bb-auth-error", role: "alert", children: [" ", auth.error] })] }));
|
|
32
|
+
}
|
|
33
|
+
export { BisonBase };
|
|
34
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";AAAA,wEAAwE;AAExE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAmD,MAAM,aAAa,CAAA;AAElG,QAAQ,CAAC;IACP,QAAQ,CAAI,KAAmB;QAC7B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AO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,yBAAmB,IACnE,CACR,CAAA;IACH,CAAC;IACD,OAAO,CACL,gBAAM,SAAS,EAAE,GAAG,iBAAc,YAAY,aAC5C,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,wBAAkB,EACrE,IAAI,CAAC,KAAK,IAAI,gBAAM,SAAS,EAAC,eAAe,EAAC,IAAI,EAAC,OAAO,kBAAG,IAAI,CAAC,KAAK,IAAQ,IAC3E,CACR,CAAA;AACH,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TableDef } from './table.ts';
|
|
2
|
+
/** What `GET ?op=schema` returns. */
|
|
3
|
+
export interface ServerSchema {
|
|
4
|
+
tables: {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
columns: {
|
|
8
|
+
name: string;
|
|
9
|
+
type: string;
|
|
10
|
+
not_null: boolean;
|
|
11
|
+
default: unknown;
|
|
12
|
+
pk: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
/** The database's tables don't match the app's and can't be changed to match safely. */
|
|
17
|
+
export declare class SchemaError extends Error {
|
|
18
|
+
name: string;
|
|
19
|
+
}
|
|
20
|
+
/** The statements that bring `server` in line with `tables`. Throws SchemaError if that's unsafe. */
|
|
21
|
+
export declare function migrationSql(tables: Iterable<TableDef>, server: ServerSchema, db: string): string[];
|
|
22
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,OAAO,CAAC;YAAC,OAAO,EAAE,OAAO,CAAC;YAAC,EAAE,EAAE,OAAO,CAAA;SAAE,EAAE,CAAA;KAC5F,EAAE,CAAA;CACJ;AAED,wFAAwF;AACxF,qBAAa,WAAY,SAAQ,KAAK;IAC3B,IAAI,SAAgB;CAC9B;AAED,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CA6CnG"}
|