shelving 1.271.3 → 1.272.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/cloudflare/CloudflareKVProvider.d.ts +9 -9
- package/cloudflare/CloudflareKVProvider.js +17 -17
- package/db/migrate/DBMigrator.d.ts +1 -1
- package/db/migrate/SQLMigrator.js +6 -6
- package/db/migrate/SQLiteMigrator.js +3 -3
- package/db/provider/SQLProvider.d.ts +9 -9
- package/db/provider/SQLProvider.js +16 -16
- package/error/{UnimplementedError.d.ts → UnsupportedError.d.ts} +4 -4
- package/error/UnsupportedError.js +14 -0
- package/error/index.d.ts +1 -1
- package/error/index.js +1 -1
- package/firestore/lite/FirestoreLiteProvider.d.ts +3 -3
- package/firestore/lite/FirestoreLiteProvider.js +6 -6
- package/package.json +1 -1
- package/ui/block/List.d.ts +3 -2
- package/ui/block/List.tsx +3 -2
- package/ui/input/Popover.d.ts +1 -1
- package/ui/input/Popover.tsx +1 -1
- package/ui/menu/Menu.d.ts +1 -1
- package/ui/menu/Menu.tsx +1 -1
- package/error/UnimplementedError.js +0 -14
|
@@ -16,9 +16,9 @@ import type { KVNamespace } from "./types.js";
|
|
|
16
16
|
* - ID generation: `addItem()` generates a UUID v4 identifier automatically.
|
|
17
17
|
*
|
|
18
18
|
* ### Not supported
|
|
19
|
-
* - **Realtime subscriptions:** `getItemSequence()` and `getQuerySequence()` throw `
|
|
19
|
+
* - **Realtime subscriptions:** `getItemSequence()` and `getQuerySequence()` throw `UnsupportedError`.
|
|
20
20
|
* KV has no change feed or push notification mechanism.
|
|
21
|
-
* - **Updates:** `updateItem()` and `updateQuery()` throw `
|
|
21
|
+
* - **Updates:** `updateItem()` and `updateQuery()` throw `UnsupportedError`.
|
|
22
22
|
* - **Collection queries:** `getQuery()`, `setQuery()`, `deleteQuery()`, and `countQuery()` are not supported.
|
|
23
23
|
* KV does not expose efficient filtering, sorting, or collection scans, so this provider avoids the old "read everything and filter in memory" behavior.
|
|
24
24
|
*
|
|
@@ -33,22 +33,22 @@ export declare class CloudflareKVProvider<I extends string = string, T extends D
|
|
|
33
33
|
private readonly _kv;
|
|
34
34
|
constructor(kv: KVNamespace);
|
|
35
35
|
getItem<II extends I, TT extends T>({ name }: Collection<string, II, TT>, id: II): Promise<OptionalItem<II, TT>>;
|
|
36
|
-
/** Not supported — KV has no change feed, so this throws `
|
|
36
|
+
/** Not supported — KV has no change feed, so this throws `UnsupportedError`. */
|
|
37
37
|
getItemSequence<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _id: II): OptionalItemSequence<II, TT>;
|
|
38
38
|
/** Generates a UUID v4 identifier for the new item. */
|
|
39
39
|
addItem<II extends I, TT extends T>({ name }: Collection<string, II, TT>, data: TT): Promise<II>;
|
|
40
40
|
setItem<II extends I, TT extends T>({ name }: Collection<string, II, TT>, id: II, data: TT): Promise<void>;
|
|
41
|
-
/** Not supported — KV cannot apply partial updates, so this throws `
|
|
41
|
+
/** Not supported — KV cannot apply partial updates, so this throws `UnsupportedError`. */
|
|
42
42
|
updateItem<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _id: II, _updates: Updates<Item<II, TT>>): Promise<void>;
|
|
43
43
|
deleteItem<II extends I, TT extends T>({ name }: Collection<string, II, TT>, id: II): Promise<void>;
|
|
44
|
-
/** Not supported — KV cannot filter, sort, or scan collections, so this throws `
|
|
44
|
+
/** Not supported — KV cannot filter, sort, or scan collections, so this throws `UnsupportedError`. */
|
|
45
45
|
getQuery<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _query?: Query<Item<II, TT>>): Promise<Items<II, TT>>;
|
|
46
|
-
/** Not supported — KV has no change feed, so this throws `
|
|
46
|
+
/** Not supported — KV has no change feed, so this throws `UnsupportedError`. */
|
|
47
47
|
getQuerySequence<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _query?: Query<Item<II, TT>>): ItemsSequence<II, TT>;
|
|
48
|
-
/** Not supported — KV cannot run collection queries, so this throws `
|
|
48
|
+
/** Not supported — KV cannot run collection queries, so this throws `UnsupportedError`. */
|
|
49
49
|
setQuery<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _query: Query<Item<II, TT>>, _data: TT): Promise<void>;
|
|
50
|
-
/** Not supported — KV supports neither updates nor collection queries, so this throws `
|
|
50
|
+
/** Not supported — KV supports neither updates nor collection queries, so this throws `UnsupportedError`. */
|
|
51
51
|
updateQuery<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _query: Query<Item<II, TT>>, _updates: Updates<TT>): Promise<void>;
|
|
52
|
-
/** Not supported — KV cannot run collection queries, so this throws `
|
|
52
|
+
/** Not supported — KV cannot run collection queries, so this throws `UnsupportedError`. */
|
|
53
53
|
deleteQuery<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _query: Query<Item<II, TT>>): Promise<void>;
|
|
54
54
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DBProvider } from "../db/provider/DBProvider.js";
|
|
2
|
-
import {
|
|
2
|
+
import { UnsupportedError } from "../error/UnsupportedError.js";
|
|
3
3
|
import { getItem } from "../util/item.js";
|
|
4
4
|
import { randomUUID } from "../util/uuid.js";
|
|
5
5
|
/**
|
|
@@ -13,9 +13,9 @@ import { randomUUID } from "../util/uuid.js";
|
|
|
13
13
|
* - ID generation: `addItem()` generates a UUID v4 identifier automatically.
|
|
14
14
|
*
|
|
15
15
|
* ### Not supported
|
|
16
|
-
* - **Realtime subscriptions:** `getItemSequence()` and `getQuerySequence()` throw `
|
|
16
|
+
* - **Realtime subscriptions:** `getItemSequence()` and `getQuerySequence()` throw `UnsupportedError`.
|
|
17
17
|
* KV has no change feed or push notification mechanism.
|
|
18
|
-
* - **Updates:** `updateItem()` and `updateQuery()` throw `
|
|
18
|
+
* - **Updates:** `updateItem()` and `updateQuery()` throw `UnsupportedError`.
|
|
19
19
|
* - **Collection queries:** `getQuery()`, `setQuery()`, `deleteQuery()`, and `countQuery()` are not supported.
|
|
20
20
|
* KV does not expose efficient filtering, sorting, or collection scans, so this provider avoids the old "read everything and filter in memory" behavior.
|
|
21
21
|
*
|
|
@@ -37,9 +37,9 @@ export class CloudflareKVProvider extends DBProvider {
|
|
|
37
37
|
if (data)
|
|
38
38
|
return getItem(id, data);
|
|
39
39
|
}
|
|
40
|
-
/** Not supported — KV has no change feed, so this throws `
|
|
40
|
+
/** Not supported — KV has no change feed, so this throws `UnsupportedError`. */
|
|
41
41
|
getItemSequence(_collection, _id) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new UnsupportedError("CloudflareKVProvider does not support realtime subscriptions");
|
|
43
43
|
}
|
|
44
44
|
/** Generates a UUID v4 identifier for the new item. */
|
|
45
45
|
async addItem({ name }, data) {
|
|
@@ -50,32 +50,32 @@ export class CloudflareKVProvider extends DBProvider {
|
|
|
50
50
|
async setItem({ name }, id, data) {
|
|
51
51
|
await this._kv.put(_getKey(name, id), JSON.stringify(data));
|
|
52
52
|
}
|
|
53
|
-
/** Not supported — KV cannot apply partial updates, so this throws `
|
|
53
|
+
/** Not supported — KV cannot apply partial updates, so this throws `UnsupportedError`. */
|
|
54
54
|
async updateItem(_collection, _id, _updates) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new UnsupportedError("CloudflareKVProvider does not support updates to items");
|
|
56
56
|
}
|
|
57
57
|
async deleteItem({ name }, id) {
|
|
58
58
|
await this._kv.delete(_getKey(name, id));
|
|
59
59
|
}
|
|
60
|
-
/** Not supported — KV cannot filter, sort, or scan collections, so this throws `
|
|
60
|
+
/** Not supported — KV cannot filter, sort, or scan collections, so this throws `UnsupportedError`. */
|
|
61
61
|
async getQuery(_collection, _query) {
|
|
62
|
-
throw new
|
|
62
|
+
throw new UnsupportedError("CloudflareKVProvider does not support querying items");
|
|
63
63
|
}
|
|
64
|
-
/** Not supported — KV has no change feed, so this throws `
|
|
64
|
+
/** Not supported — KV has no change feed, so this throws `UnsupportedError`. */
|
|
65
65
|
getQuerySequence(_collection, _query) {
|
|
66
|
-
throw new
|
|
66
|
+
throw new UnsupportedError("CloudflareKVProvider does not support realtime subscriptions");
|
|
67
67
|
}
|
|
68
|
-
/** Not supported — KV cannot run collection queries, so this throws `
|
|
68
|
+
/** Not supported — KV cannot run collection queries, so this throws `UnsupportedError`. */
|
|
69
69
|
async setQuery(_collection, _query, _data) {
|
|
70
|
-
throw new
|
|
70
|
+
throw new UnsupportedError("CloudflareKVProvider does not support querying items");
|
|
71
71
|
}
|
|
72
|
-
/** Not supported — KV supports neither updates nor collection queries, so this throws `
|
|
72
|
+
/** Not supported — KV supports neither updates nor collection queries, so this throws `UnsupportedError`. */
|
|
73
73
|
async updateQuery(_collection, _query, _updates) {
|
|
74
|
-
throw new
|
|
74
|
+
throw new UnsupportedError("CloudflareKVProvider does not support updates to items");
|
|
75
75
|
}
|
|
76
|
-
/** Not supported — KV cannot run collection queries, so this throws `
|
|
76
|
+
/** Not supported — KV cannot run collection queries, so this throws `UnsupportedError`. */
|
|
77
77
|
async deleteQuery(_collection, _query) {
|
|
78
|
-
throw new
|
|
78
|
+
throw new UnsupportedError("CloudflareKVProvider does not support querying items");
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function _getKey(collection, id) {
|
|
@@ -18,7 +18,7 @@ export declare abstract class DBMigrator<T extends DBProvider = DBProvider> {
|
|
|
18
18
|
* Bring the provider's storage into line with the given collection schemas.
|
|
19
19
|
*
|
|
20
20
|
* @param collections The collections whose schemas the storage should match.
|
|
21
|
-
* @throws `
|
|
21
|
+
* @throws `UnsupportedError` if a schema feature can't be represented by the backend.
|
|
22
22
|
* @example await migrator.migrate(users, posts)
|
|
23
23
|
* @see https://shelving.cc/db/DBMigrator/migrate
|
|
24
24
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnsupportedError } from "../../error/UnsupportedError.js";
|
|
2
2
|
import { ArraySchema } from "../../schema/ArraySchema.js";
|
|
3
3
|
import { BooleanSchema } from "../../schema/BooleanSchema.js";
|
|
4
4
|
import { ChoiceSchema } from "../../schema/ChoiceSchema.js";
|
|
@@ -97,12 +97,12 @@ export class SQLMigrator extends DBMigrator {
|
|
|
97
97
|
}
|
|
98
98
|
getAddColumnQuery(tableName, column) {
|
|
99
99
|
if (column.name === "id")
|
|
100
|
-
throw new
|
|
100
|
+
throw new UnsupportedError(`Cannot add primary key column to existing table "${tableName}"`);
|
|
101
101
|
return `ALTER TABLE ${this.quoteIdentifier(tableName)} ADD COLUMN ${this.getTableColumnDefinition(column)};`;
|
|
102
102
|
}
|
|
103
103
|
getDropColumnQuery(tableName, columnName) {
|
|
104
104
|
if (columnName === "id")
|
|
105
|
-
throw new
|
|
105
|
+
throw new UnsupportedError(`Cannot drop primary key column from existing table "${tableName}"`);
|
|
106
106
|
return `ALTER TABLE ${this.quoteIdentifier(tableName)} DROP COLUMN ${this.quoteIdentifier(columnName)};`;
|
|
107
107
|
}
|
|
108
108
|
getTableMigrations(collection, table) {
|
|
@@ -129,7 +129,7 @@ export class SQLMigrator extends DBMigrator {
|
|
|
129
129
|
const schema = _getColumnSchema(collection, key);
|
|
130
130
|
const definition = this.definition(schema);
|
|
131
131
|
if (!definition)
|
|
132
|
-
throw new
|
|
132
|
+
throw new UnsupportedError(`Cannot generate SQL column for "${key}"`, { received: schema });
|
|
133
133
|
return { name: column, statement: this.getGeneratedColumnDefinition(column, path, definition) };
|
|
134
134
|
}
|
|
135
135
|
isSameColumn(from, to) {
|
|
@@ -180,10 +180,10 @@ function _getColumnSchema(collection, key) {
|
|
|
180
180
|
for (const part of key.split(".")) {
|
|
181
181
|
const current = _unwrapSchema(schema);
|
|
182
182
|
if (!(current instanceof DataSchema))
|
|
183
|
-
throw new
|
|
183
|
+
throw new UnsupportedError(`Cannot resolve schema path "${key}"`);
|
|
184
184
|
const next = current.props[part];
|
|
185
185
|
if (!next)
|
|
186
|
-
throw new
|
|
186
|
+
throw new UnsupportedError(`Cannot resolve schema path "${key}"`);
|
|
187
187
|
schema = next;
|
|
188
188
|
}
|
|
189
189
|
return schema;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnsupportedError } from "../../error/UnsupportedError.js";
|
|
2
2
|
import { ChoiceSchema } from "../../schema/ChoiceSchema.js";
|
|
3
3
|
import { DateSchema } from "../../schema/DateSchema.js";
|
|
4
4
|
import { NumberSchema } from "../../schema/NumberSchema.js";
|
|
@@ -47,7 +47,7 @@ export class SQLiteMigrator extends SQLMigrator {
|
|
|
47
47
|
if (id instanceof NumberSchema) {
|
|
48
48
|
if (id.step === 1)
|
|
49
49
|
return "INTEGER PRIMARY KEY";
|
|
50
|
-
throw new
|
|
50
|
+
throw new UnsupportedError("SQLiteMigrator only supports string and integer identifiers", { received: id });
|
|
51
51
|
}
|
|
52
52
|
if (id instanceof ChoiceSchema || id instanceof DateSchema)
|
|
53
53
|
return "TEXT PRIMARY KEY";
|
|
@@ -62,7 +62,7 @@ export class SQLiteMigrator extends SQLMigrator {
|
|
|
62
62
|
}
|
|
63
63
|
getAlterColumnQueries(tableName, from, to) {
|
|
64
64
|
if (from.name === "id" || from.name === "data") {
|
|
65
|
-
throw new
|
|
65
|
+
throw new UnsupportedError(`Cannot alter SQLite column "${from.name}" in existing table "${tableName}"`);
|
|
66
66
|
}
|
|
67
67
|
return super.getAlterColumnQueries(tableName, from, to);
|
|
68
68
|
}
|
|
@@ -19,7 +19,7 @@ export interface SQLFragment {
|
|
|
19
19
|
*
|
|
20
20
|
* - Subclasses implement `exec()` to run a query against a concrete database (e.g. SQLite, PostgreSQL).
|
|
21
21
|
* - The `sql*` helpers build composable `SQLFragment` objects so dialect differences can be overridden.
|
|
22
|
-
* - Realtime subscriptions are unsupported and throw `
|
|
22
|
+
* - Realtime subscriptions are unsupported and throw `UnsupportedError`.
|
|
23
23
|
*
|
|
24
24
|
* @see https://shelving.cc/db/SQLProvider
|
|
25
25
|
*/
|
|
@@ -34,7 +34,7 @@ export declare abstract class SQLProvider<I extends Identifier = Identifier, T e
|
|
|
34
34
|
*/
|
|
35
35
|
abstract exec<X extends Data>(strings: TemplateStringsArray, ...values: ImmutableArray<unknown>): Promise<ImmutableArray<X>>;
|
|
36
36
|
getItem<II extends I, TT extends T>(collection: Collection<string, II, TT>, id: II): Promise<OptionalItem<II, TT>>;
|
|
37
|
-
/** Unsupported by SQL providers — always throws `
|
|
37
|
+
/** Unsupported by SQL providers — always throws `UnsupportedError`. */
|
|
38
38
|
getItemSequence<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _id: II): OptionalItemSequence<II, TT>;
|
|
39
39
|
/** Insert via `INSERT ... RETURNING`; throws `RequiredError` if no id comes back. */
|
|
40
40
|
addItem<II extends I, TT extends T>(collection: Collection<string, II, TT>, data: TT): Promise<II>;
|
|
@@ -43,7 +43,7 @@ export declare abstract class SQLProvider<I extends Identifier = Identifier, T e
|
|
|
43
43
|
deleteItem<II extends I, TT extends T>(collection: Collection<string, II, TT>, id: II): Promise<void>;
|
|
44
44
|
countQuery<II extends I, TT extends T>(collection: Collection<string, II, TT>, query?: Query<Item<II, TT>>): Promise<number>;
|
|
45
45
|
getQuery<II extends I, TT extends T>(collection: Collection<string, II, TT>, query?: Query<Item<II, TT>>): Promise<Items<II, TT>>;
|
|
46
|
-
/** Unsupported by SQL providers — always throws `
|
|
46
|
+
/** Unsupported by SQL providers — always throws `UnsupportedError`. */
|
|
47
47
|
getQuerySequence<II extends I, TT extends T>(_collection: Collection<string, II, TT>, _query?: Query<Item<II, TT>>): ItemsSequence<II, TT>;
|
|
48
48
|
setQuery<II extends I, TT extends T>(collection: Collection<string, II, TT>, query: Query<Item<II, TT>>, data: TT): Promise<void>;
|
|
49
49
|
updateQuery<II extends I, TT extends T>(collection: Collection<string, II, TT>, query: Query<Item<II, TT>>, updates: Updates<TT>): Promise<void>;
|
|
@@ -70,7 +70,7 @@ export declare abstract class SQLProvider<I extends Identifier = Identifier, T e
|
|
|
70
70
|
* - Base implementation only supports flat (single-segment) keys; subclasses override for nested JSON paths.
|
|
71
71
|
*
|
|
72
72
|
* @param key The key segments identifying the column (and any nested path).
|
|
73
|
-
* @throws `
|
|
73
|
+
* @throws `UnsupportedError` if the key is nested (multi-segment).
|
|
74
74
|
* @example this.sqlExtract(["name"]); // "name"
|
|
75
75
|
* @see https://shelving.cc/db/SQLProvider/sqlExtract
|
|
76
76
|
*/
|
|
@@ -105,11 +105,11 @@ export declare abstract class SQLProvider<I extends Identifier = Identifier, T e
|
|
|
105
105
|
/**
|
|
106
106
|
* Define an SQL fragment for a single update action.
|
|
107
107
|
* - Handles flat `set` and `sum` only (single-segment key).
|
|
108
|
-
* - Nested keys (multi-segment) and `with`/`omit` actions throw `
|
|
108
|
+
* - Nested keys (multi-segment) and `with`/`omit` actions throw `UnsupportedError`.
|
|
109
109
|
* - Subclasses should override to support nested keys and array mutation actions.
|
|
110
110
|
*
|
|
111
111
|
* @param update The update action (`action`, `key`, `value`) to convert.
|
|
112
|
-
* @throws `
|
|
112
|
+
* @throws `UnsupportedError` if the key is nested or the action is unsupported.
|
|
113
113
|
* @example this.sqlUpdate({ action: "set", key: ["a"], value: 1 }); // "a" = 1
|
|
114
114
|
* @see https://shelving.cc/db/SQLProvider/sqlUpdate
|
|
115
115
|
*/
|
|
@@ -144,7 +144,7 @@ export declare abstract class SQLProvider<I extends Identifier = Identifier, T e
|
|
|
144
144
|
* Define an SQL fragment for a single filter clause on a column, e.g. `x = 1` or `x IN (1, 2)`.
|
|
145
145
|
*
|
|
146
146
|
* @param filter The filter (`key`, `operator`, `value`) to translate.
|
|
147
|
-
* @throws `
|
|
147
|
+
* @throws `UnsupportedError` if the operator is unsupported.
|
|
148
148
|
* @example this.sqlFilter({ key: ["x"], operator: "is", value: 1 }); // "x" = 1
|
|
149
149
|
* @see https://shelving.cc/db/SQLProvider/sqlFilter
|
|
150
150
|
*/
|
|
@@ -152,10 +152,10 @@ export declare abstract class SQLProvider<I extends Identifier = Identifier, T e
|
|
|
152
152
|
/**
|
|
153
153
|
* Define an SQL fragment for an `ORDER BY` clause, e.g. ` ORDER BY "a" ASC, "b" DESC`.
|
|
154
154
|
* - Returns an empty fragment when the query has no orders.
|
|
155
|
-
* - Nested keys (multi-segment) throw `
|
|
155
|
+
* - Nested keys (multi-segment) throw `UnsupportedError`.
|
|
156
156
|
*
|
|
157
157
|
* @param query The query whose orders become the `ORDER BY` clause.
|
|
158
|
-
* @throws `
|
|
158
|
+
* @throws `UnsupportedError` if an order key is nested (multi-segment).
|
|
159
159
|
* @example this.sqlOrder(query); // ORDER BY "a" ASC
|
|
160
160
|
* @see https://shelving.cc/db/SQLProvider/sqlOrder
|
|
161
161
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequiredError } from "../../error/RequiredError.js";
|
|
2
|
-
import {
|
|
2
|
+
import { UnsupportedError } from "../../error/UnsupportedError.js";
|
|
3
3
|
import { getQueryFilters, getQueryLimit, getQueryOrders } from "../../util/query.js";
|
|
4
4
|
import { getUpdates } from "../../util/update.js";
|
|
5
5
|
import { DBProvider } from "./DBProvider.js";
|
|
@@ -8,7 +8,7 @@ import { DBProvider } from "./DBProvider.js";
|
|
|
8
8
|
*
|
|
9
9
|
* - Subclasses implement `exec()` to run a query against a concrete database (e.g. SQLite, PostgreSQL).
|
|
10
10
|
* - The `sql*` helpers build composable `SQLFragment` objects so dialect differences can be overridden.
|
|
11
|
-
* - Realtime subscriptions are unsupported and throw `
|
|
11
|
+
* - Realtime subscriptions are unsupported and throw `UnsupportedError`.
|
|
12
12
|
*
|
|
13
13
|
* @see https://shelving.cc/db/SQLProvider
|
|
14
14
|
*/
|
|
@@ -21,9 +21,9 @@ export class SQLProvider extends DBProvider {
|
|
|
21
21
|
`;
|
|
22
22
|
return rows[0];
|
|
23
23
|
}
|
|
24
|
-
/** Unsupported by SQL providers — always throws `
|
|
24
|
+
/** Unsupported by SQL providers — always throws `UnsupportedError`. */
|
|
25
25
|
getItemSequence(_collection, _id) {
|
|
26
|
-
throw new
|
|
26
|
+
throw new UnsupportedError(`SQLProvider does not support realtime subscriptions`);
|
|
27
27
|
}
|
|
28
28
|
/** Insert via `INSERT ... RETURNING`; throws `RequiredError` if no id comes back. */
|
|
29
29
|
async addItem(collection, data) {
|
|
@@ -65,9 +65,9 @@ export class SQLProvider extends DBProvider {
|
|
|
65
65
|
${query ? this.sqlClauses(query) : this.sql ``}
|
|
66
66
|
`;
|
|
67
67
|
}
|
|
68
|
-
/** Unsupported by SQL providers — always throws `
|
|
68
|
+
/** Unsupported by SQL providers — always throws `UnsupportedError`. */
|
|
69
69
|
getQuerySequence(_collection, _query) {
|
|
70
|
-
throw new
|
|
70
|
+
throw new UnsupportedError(`SQLProvider does not support realtime subscriptions`);
|
|
71
71
|
}
|
|
72
72
|
async setQuery(collection, query, data) {
|
|
73
73
|
await this.exec `UPDATE ${this.sqlIdentifier(collection.name)} SET ${this.sqlSetters(data)}${this.sqlClauses(query)}`;
|
|
@@ -104,13 +104,13 @@ export class SQLProvider extends DBProvider {
|
|
|
104
104
|
* - Base implementation only supports flat (single-segment) keys; subclasses override for nested JSON paths.
|
|
105
105
|
*
|
|
106
106
|
* @param key The key segments identifying the column (and any nested path).
|
|
107
|
-
* @throws `
|
|
107
|
+
* @throws `UnsupportedError` if the key is nested (multi-segment).
|
|
108
108
|
* @example this.sqlExtract(["name"]); // "name"
|
|
109
109
|
* @see https://shelving.cc/db/SQLProvider/sqlExtract
|
|
110
110
|
*/
|
|
111
111
|
sqlExtract(key) {
|
|
112
112
|
if (key.length > 1)
|
|
113
|
-
throw new
|
|
113
|
+
throw new UnsupportedError("SQLProvider does not support nested filter keys");
|
|
114
114
|
return this.sqlIdentifier(key[0]);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -151,23 +151,23 @@ export class SQLProvider extends DBProvider {
|
|
|
151
151
|
/**
|
|
152
152
|
* Define an SQL fragment for a single update action.
|
|
153
153
|
* - Handles flat `set` and `sum` only (single-segment key).
|
|
154
|
-
* - Nested keys (multi-segment) and `with`/`omit` actions throw `
|
|
154
|
+
* - Nested keys (multi-segment) and `with`/`omit` actions throw `UnsupportedError`.
|
|
155
155
|
* - Subclasses should override to support nested keys and array mutation actions.
|
|
156
156
|
*
|
|
157
157
|
* @param update The update action (`action`, `key`, `value`) to convert.
|
|
158
|
-
* @throws `
|
|
158
|
+
* @throws `UnsupportedError` if the key is nested or the action is unsupported.
|
|
159
159
|
* @example this.sqlUpdate({ action: "set", key: ["a"], value: 1 }); // "a" = 1
|
|
160
160
|
* @see https://shelving.cc/db/SQLProvider/sqlUpdate
|
|
161
161
|
*/
|
|
162
162
|
sqlUpdate({ action, key, value }) {
|
|
163
163
|
if (key.length > 1)
|
|
164
|
-
throw new
|
|
164
|
+
throw new UnsupportedError("SQLProvider does not support nested update keys");
|
|
165
165
|
const column = this.sqlIdentifier(key[0]);
|
|
166
166
|
if (action === "set")
|
|
167
167
|
return this.sql `${column} = ${value}`;
|
|
168
168
|
if (action === "sum")
|
|
169
169
|
return this.sql `${column} = ${column} + ${value}`;
|
|
170
|
-
throw new
|
|
170
|
+
throw new UnsupportedError(`SQLProvider does not support "${action}" updates`);
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
173
|
* Define an SQL fragment for `VALUES` syntax, e.g. `("a", "b") VALUES (1, 2)`.
|
|
@@ -211,7 +211,7 @@ export class SQLProvider extends DBProvider {
|
|
|
211
211
|
* Define an SQL fragment for a single filter clause on a column, e.g. `x = 1` or `x IN (1, 2)`.
|
|
212
212
|
*
|
|
213
213
|
* @param filter The filter (`key`, `operator`, `value`) to translate.
|
|
214
|
-
* @throws `
|
|
214
|
+
* @throws `UnsupportedError` if the operator is unsupported.
|
|
215
215
|
* @example this.sqlFilter({ key: ["x"], operator: "is", value: 1 }); // "x" = 1
|
|
216
216
|
* @see https://shelving.cc/db/SQLProvider/sqlFilter
|
|
217
217
|
*/
|
|
@@ -239,15 +239,15 @@ export class SQLProvider extends DBProvider {
|
|
|
239
239
|
return this.sql `${path} > ${value}`;
|
|
240
240
|
if (operator === "gte")
|
|
241
241
|
return this.sql `${path} >= ${value}`;
|
|
242
|
-
throw new
|
|
242
|
+
throw new UnsupportedError(`SQLProvider does not support "${operator}" filters`);
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
245
|
* Define an SQL fragment for an `ORDER BY` clause, e.g. ` ORDER BY "a" ASC, "b" DESC`.
|
|
246
246
|
* - Returns an empty fragment when the query has no orders.
|
|
247
|
-
* - Nested keys (multi-segment) throw `
|
|
247
|
+
* - Nested keys (multi-segment) throw `UnsupportedError`.
|
|
248
248
|
*
|
|
249
249
|
* @param query The query whose orders become the `ORDER BY` clause.
|
|
250
|
-
* @throws `
|
|
250
|
+
* @throws `UnsupportedError` if an order key is nested (multi-segment).
|
|
251
251
|
* @example this.sqlOrder(query); // ORDER BY "a" ASC
|
|
252
252
|
* @see https://shelving.cc/db/SQLProvider/sqlOrder
|
|
253
253
|
*/
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type BaseError, type BaseErrorOptions } from "./BaseError.js";
|
|
2
2
|
/**
|
|
3
|
-
* Error thrown when functionality is called but is not
|
|
3
|
+
* Error thrown when functionality is called but is not supported — by a backend, an environment, or an implementation.
|
|
4
4
|
*
|
|
5
|
-
* @see https://shelving.cc/error/
|
|
5
|
+
* @see https://shelving.cc/error/UnsupportedError
|
|
6
6
|
*/
|
|
7
|
-
export declare class
|
|
7
|
+
export declare class UnsupportedError extends Error implements BaseError {
|
|
8
8
|
/** Provide additional named contextual data that is relevant to the `Error` instance. */
|
|
9
9
|
readonly [key: string]: unknown;
|
|
10
|
-
/** @param message Optional human-readable description of the
|
|
10
|
+
/** @param message Optional human-readable description of the unsupported functionality. */
|
|
11
11
|
constructor(message?: string, options?: BaseErrorOptions);
|
|
12
12
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { setBaseErrorOptions } from "./BaseError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when functionality is called but is not supported — by a backend, an environment, or an implementation.
|
|
4
|
+
*
|
|
5
|
+
* @see https://shelving.cc/error/UnsupportedError
|
|
6
|
+
*/
|
|
7
|
+
export class UnsupportedError extends Error {
|
|
8
|
+
/** @param message Optional human-readable description of the unsupported functionality. */
|
|
9
|
+
constructor(message, options = {}) {
|
|
10
|
+
super(message, options);
|
|
11
|
+
setBaseErrorOptions(UnsupportedError, this, options);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
UnsupportedError.prototype.name = "UnsupportedError";
|
package/error/index.d.ts
CHANGED
package/error/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import type { Updates } from "../../util/update.js";
|
|
|
10
10
|
*
|
|
11
11
|
* - Works with the Firebase JS SDK via `firebase/firestore/lite`, which keeps bundle size small.
|
|
12
12
|
* - Does not support offline mode.
|
|
13
|
-
* - Does not support realtime subscriptions: `getItemSequence()` and `getQuerySequence()` throw `
|
|
13
|
+
* - Does not support realtime subscriptions: `getItemSequence()` and `getQuerySequence()` throw `UnsupportedError`.
|
|
14
14
|
*
|
|
15
15
|
* @see https://shelving.cc/firestore/lite/FirestoreLiteProvider
|
|
16
16
|
*/
|
|
@@ -24,7 +24,7 @@ export declare class FirestoreLiteProvider<I extends string = string, T extends
|
|
|
24
24
|
/** Get a Firestore QueryReference for a given query. */
|
|
25
25
|
private _query;
|
|
26
26
|
getItem<II extends I, TT extends T>(c: Collection<string, II, TT>, id: II): Promise<OptionalItem<II, TT>>;
|
|
27
|
-
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `
|
|
27
|
+
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `UnsupportedError`. */
|
|
28
28
|
getItemSequence<II extends I, TT extends T>(_c: Collection<string, II, TT>, _id: II): OptionalItemSequence<II, TT>;
|
|
29
29
|
addItem<II extends I, TT extends T>(c: Collection<string, II, TT>, data: TT): Promise<II>;
|
|
30
30
|
setItem<II extends I, TT extends T>(c: Collection<string, II, TT>, id: II, data: TT): Promise<void>;
|
|
@@ -32,7 +32,7 @@ export declare class FirestoreLiteProvider<I extends string = string, T extends
|
|
|
32
32
|
deleteItem<II extends I, TT extends T>(c: Collection<string, II, TT>, id: II): Promise<void>;
|
|
33
33
|
countQuery<II extends I, TT extends T>(c: Collection<string, II, TT>, q?: Query<Item<II, TT>>): Promise<number>;
|
|
34
34
|
getQuery<II extends I, TT extends T>(c: Collection<string, II, TT>, q?: Query<Item<II, TT>>): Promise<Items<II, TT>>;
|
|
35
|
-
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `
|
|
35
|
+
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `UnsupportedError`. */
|
|
36
36
|
getQuerySequence<II extends I, TT extends T>(_c: Collection<string, II, TT>, _q?: Query<Item<II, TT>>): ItemsSequence<II, TT>;
|
|
37
37
|
setQuery<II extends I, TT extends T>(c: Collection<string, II, TT>, q: Query<Item<II, TT>>, data: TT): Promise<void>;
|
|
38
38
|
updateQuery<II extends I, TT extends T>(c: Collection<string, II, TT>, q: Query<Item<II, TT>>, updates: Updates<TT>): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addDoc, arrayRemove, arrayUnion, collection, deleteDoc, doc, documentId, getCount, getDoc, getDocs, increment, limit, orderBy, query, setDoc, updateDoc, where, } from "firebase/firestore/lite";
|
|
2
2
|
import { DBProvider } from "../../db/provider/DBProvider.js";
|
|
3
|
-
import {
|
|
3
|
+
import { UnsupportedError } from "../../error/UnsupportedError.js";
|
|
4
4
|
import { joinDataPath } from "../../util/data.js";
|
|
5
5
|
import { getItem } from "../../util/item.js";
|
|
6
6
|
import { getObject } from "../../util/object.js";
|
|
@@ -66,7 +66,7 @@ function _getFieldValue({ key, action, value }) {
|
|
|
66
66
|
*
|
|
67
67
|
* - Works with the Firebase JS SDK via `firebase/firestore/lite`, which keeps bundle size small.
|
|
68
68
|
* - Does not support offline mode.
|
|
69
|
-
* - Does not support realtime subscriptions: `getItemSequence()` and `getQuerySequence()` throw `
|
|
69
|
+
* - Does not support realtime subscriptions: `getItemSequence()` and `getQuerySequence()` throw `UnsupportedError`.
|
|
70
70
|
*
|
|
71
71
|
* @see https://shelving.cc/firestore/lite/FirestoreLiteProvider
|
|
72
72
|
*/
|
|
@@ -92,9 +92,9 @@ export class FirestoreLiteProvider extends DBProvider {
|
|
|
92
92
|
const snapshot = await getDoc(this._doc(c, id));
|
|
93
93
|
return _getOptionalItem(snapshot);
|
|
94
94
|
}
|
|
95
|
-
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `
|
|
95
|
+
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `UnsupportedError`. */
|
|
96
96
|
getItemSequence(_c, _id) {
|
|
97
|
-
throw new
|
|
97
|
+
throw new UnsupportedError("FirestoreLiteProvider does not support realtime subscriptions");
|
|
98
98
|
}
|
|
99
99
|
async addItem(c, data) {
|
|
100
100
|
const reference = await addDoc(this._collection(c), data);
|
|
@@ -116,9 +116,9 @@ export class FirestoreLiteProvider extends DBProvider {
|
|
|
116
116
|
async getQuery(c, q) {
|
|
117
117
|
return _getItems(await getDocs(this._query(c, q)));
|
|
118
118
|
}
|
|
119
|
-
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `
|
|
119
|
+
/** Not supported — the Firebase Lite SDK has no realtime listeners, so this throws `UnsupportedError`. */
|
|
120
120
|
getQuerySequence(_c, _q) {
|
|
121
|
-
throw new
|
|
121
|
+
throw new UnsupportedError("FirestoreLiteProvider does not support realtime subscriptions");
|
|
122
122
|
}
|
|
123
123
|
async setQuery(c, q, data) {
|
|
124
124
|
const snapshot = await getDocs(this._query(c, q));
|
package/package.json
CHANGED
package/ui/block/List.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { ImmutableArray } from "../../util/array.js";
|
|
2
3
|
import { type BlockVariants } from "../style/Block.js";
|
|
3
4
|
import { type GapVariants } from "../style/Gap.js";
|
|
4
5
|
/**
|
|
@@ -7,8 +8,8 @@ import { type GapVariants } from "../style/Gap.js";
|
|
|
7
8
|
* @see https://shelving.cc/ui/ListProps
|
|
8
9
|
*/
|
|
9
10
|
export interface ListProps extends GapVariants, BlockVariants {
|
|
10
|
-
children: ReactNode
|
|
11
|
-
ordered?: boolean;
|
|
11
|
+
readonly children: ImmutableArray<ReactNode>;
|
|
12
|
+
readonly ordered?: boolean | undefined;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* List block — wraps each child in an `<li>` and renders an `<ul>` or `<ol>`.
|
package/ui/block/List.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import type { ImmutableArray } from "../../util/array.js";
|
|
2
3
|
import { type BlockVariants, getBlockClass } from "../style/Block.js";
|
|
3
4
|
import { type GapVariants, getGapClass } from "../style/Gap.js";
|
|
4
5
|
import { getClass, getModuleClass } from "../util/css.js";
|
|
@@ -13,8 +14,8 @@ const LIST_UNORDERED_CLASS = getModuleClass(LIST_CSS, "unordered");
|
|
|
13
14
|
* @see https://shelving.cc/ui/ListProps
|
|
14
15
|
*/
|
|
15
16
|
export interface ListProps extends GapVariants, BlockVariants {
|
|
16
|
-
children: ReactNode
|
|
17
|
-
ordered?: boolean;
|
|
17
|
+
readonly children: ImmutableArray<ReactNode>;
|
|
18
|
+
readonly ordered?: boolean | undefined;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
package/ui/input/Popover.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Callback } from "../../util/function.js";
|
|
|
7
7
|
*
|
|
8
8
|
* @see https://shelving.cc/ui/PopoverChildren
|
|
9
9
|
*/
|
|
10
|
-
export type PopoverChildren = [
|
|
10
|
+
export type PopoverChildren = readonly [
|
|
11
11
|
/**
|
|
12
12
|
* First child of the <Popover> is element that activates the popover.
|
|
13
13
|
* - Should be a `<Button>` or `<Input>` that activates or provides the children.
|
package/ui/input/Popover.tsx
CHANGED
|
@@ -15,7 +15,7 @@ import styles from "./Popover.module.css";
|
|
|
15
15
|
*
|
|
16
16
|
* @see https://shelving.cc/ui/PopoverChildren
|
|
17
17
|
*/
|
|
18
|
-
export type PopoverChildren = [
|
|
18
|
+
export type PopoverChildren = readonly [
|
|
19
19
|
/**
|
|
20
20
|
* First child of the <Popover> is element that activates the popover.
|
|
21
21
|
* - Should be a `<Button>` or `<Input>` that activates or provides the children.
|
package/ui/menu/Menu.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface MenuItemProps extends ClickableProps {
|
|
|
28
28
|
* The first child becomes the link label (rendered inside the `<a>`).
|
|
29
29
|
* - Any additional children form the submenu — only rendered when this item is "proud" (an ancestor of the current page). The caller is responsible for wrapping the submenu in a nested `<Menu>` if it wants the CSS `.menu .menu` descendant rules to apply.
|
|
30
30
|
*/
|
|
31
|
-
readonly children: ReactNode | [ReactNode, ...ReactNode[]];
|
|
31
|
+
readonly children: ReactNode | readonly [ReactNode, ...ReactNode[]];
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* A `<li>` containing an `<a>` link, plus optional submenu content shown when this item is "proud".
|
package/ui/menu/Menu.tsx
CHANGED
|
@@ -52,7 +52,7 @@ export interface MenuItemProps extends ClickableProps {
|
|
|
52
52
|
* The first child becomes the link label (rendered inside the `<a>`).
|
|
53
53
|
* - Any additional children form the submenu — only rendered when this item is "proud" (an ancestor of the current page). The caller is responsible for wrapping the submenu in a nested `<Menu>` if it wants the CSS `.menu .menu` descendant rules to apply.
|
|
54
54
|
*/
|
|
55
|
-
readonly children: ReactNode | [ReactNode, ...ReactNode[]];
|
|
55
|
+
readonly children: ReactNode | readonly [ReactNode, ...ReactNode[]];
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { setBaseErrorOptions } from "./BaseError.js";
|
|
2
|
-
/**
|
|
3
|
-
* Error thrown when functionality is called but is not implemented by an interface.
|
|
4
|
-
*
|
|
5
|
-
* @see https://shelving.cc/error/UnimplementedError
|
|
6
|
-
*/
|
|
7
|
-
export class UnimplementedError extends Error {
|
|
8
|
-
/** @param message Optional human-readable description of the missing implementation. */
|
|
9
|
-
constructor(message, options = {}) {
|
|
10
|
-
super(message, options);
|
|
11
|
-
setBaseErrorOptions(UnimplementedError, this, options);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
UnimplementedError.prototype.name = "UnimplementedError";
|