shelving 1.127.0 → 1.128.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/api/Resource.js +1 -1
- package/db/Change.d.ts +2 -2
- package/db/Change.js +2 -2
- package/db/ChangesProvider.d.ts +1 -1
- package/db/DebugProvider.d.ts +0 -3
- package/db/DebugProvider.js +0 -7
- package/db/ItemStore.d.ts +4 -4
- package/db/MemoryProvider.d.ts +1 -1
- package/db/MemoryProvider.js +9 -8
- package/db/QueryStore.d.ts +4 -4
- package/db/QueryStore.js +1 -1
- package/db/ThroughProvider.d.ts +1 -1
- package/db/ThroughProvider.js +6 -6
- package/db/ValidationProvider.d.ts +1 -1
- package/db/ValidationProvider.js +6 -6
- package/firestore/client/FirestoreClientProvider.d.ts +2 -2
- package/firestore/client/FirestoreClientProvider.js +4 -2
- package/firestore/lite/FirestoreLiteProvider.d.ts +2 -2
- package/firestore/lite/FirestoreLiteProvider.js +4 -2
- package/firestore/server/FirestoreServerProvider.d.ts +2 -2
- package/markup/options.d.ts +1 -1
- package/markup/regexp.d.ts +0 -10
- package/markup/render.d.ts +1 -1
- package/markup/render.js +0 -1
- package/markup/rule.d.ts +2 -3
- package/markup/rule.js +1 -2
- package/markup/rules.js +4 -4
- package/package.json +8 -18
- package/react/createCacheContext.d.ts +3 -3
- package/react/createCacheContext.js +1 -0
- package/react/createDataContext.d.ts +8 -6
- package/react/createDataContext.js +5 -2
- package/react/index.d.ts +0 -2
- package/react/index.js +0 -2
- package/react/useInstance.js +7 -8
- package/react/useInternals.d.ts +5 -0
- package/react/useInternals.js +3 -0
- package/react/useLazy.d.ts +1 -1
- package/react/useLazy.js +5 -6
- package/react/useReduce.d.ts +1 -1
- package/react/useReduce.js +3 -2
- package/react/useSequence.d.ts +1 -1
- package/react/useSequence.js +5 -3
- package/react/useStore.d.ts +1 -2
- package/react/useStore.js +13 -3
- package/schema/AllowSchema.d.ts +1 -1
- package/schema/ArraySchema.d.ts +1 -1
- package/schema/ArraySchema.js +1 -1
- package/schema/DataSchema.d.ts +2 -2
- package/schema/DateSchema.d.ts +1 -1
- package/schema/DictionarySchema.d.ts +1 -1
- package/schema/DictionarySchema.js +1 -1
- package/schema/LinkSchema.d.ts +1 -1
- package/schema/NumberSchema.js +8 -2
- package/schema/Schema.d.ts +1 -1
- package/schema/StringSchema.js +1 -1
- package/schema/ThroughSchema.d.ts +1 -1
- package/schema/TimeSchema.d.ts +1 -1
- package/sequence/DeferredSequence.js +3 -1
- package/sequence/LazyDeferredSequence.d.ts +0 -1
- package/sequence/LazyDeferredSequence.js +1 -0
- package/store/ArrayStore.js +1 -1
- package/store/Store.js +1 -1
- package/test/basics.js +99 -10
- package/test/util.d.ts +0 -7
- package/test/util.js +4 -5
- package/util/array.js +7 -6
- package/util/assert.js +2 -2
- package/util/async.d.ts +2 -2
- package/util/async.js +9 -5
- package/util/boolean.js +5 -5
- package/util/color.js +1 -1
- package/util/date.js +2 -2
- package/util/debug.js +12 -2
- package/util/dictionary.js +1 -1
- package/util/diff.d.ts +1 -1
- package/util/dispose.d.ts +0 -1
- package/util/equal.d.ts +4 -4
- package/util/error.js +1 -2
- package/util/function.js +1 -0
- package/util/hydrate.js +9 -11
- package/util/item.d.ts +1 -1
- package/util/item.js +0 -1
- package/util/link.d.ts +1 -1
- package/util/link.js +0 -1
- package/util/map.js +1 -1
- package/util/null.d.ts +2 -2
- package/util/number.js +5 -5
- package/util/object.js +2 -2
- package/util/optional.d.ts +1 -1
- package/util/query.js +7 -9
- package/util/sequence.d.ts +1 -1
- package/util/sequence.js +6 -10
- package/util/serialise.js +5 -5
- package/util/set.js +1 -1
- package/util/sort.js +10 -6
- package/util/start.d.ts +0 -1
- package/util/string.js +5 -6
- package/util/template.js +1 -1
- package/util/time.js +5 -2
- package/util/undefined.d.ts +4 -4
- package/util/units.d.ts +1 -1
- package/util/units.js +58 -19
- package/util/update.d.ts +26 -2
- package/react/useFocus.d.ts +0 -11
- package/react/useFocus.js +0 -49
- package/react/useMount.d.ts +0 -4
- package/react/useMount.js +0 -25
package/api/Resource.js
CHANGED
package/db/Change.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
1
|
import type { ImmutableArray } from "../util/array.js";
|
|
3
2
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
3
|
import type { ItemQuery } from "../util/item.js";
|
|
5
|
-
import type { Updates } from "../util/update.js";
|
|
6
4
|
import { type Optional } from "../util/optional.js";
|
|
5
|
+
import type { Updates } from "../util/update.js";
|
|
6
|
+
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
7
7
|
/** A change to a database. */
|
|
8
8
|
export interface Change {
|
|
9
9
|
readonly action: string;
|
package/db/Change.js
CHANGED
|
@@ -6,7 +6,7 @@ export function writeChange(provider, change) {
|
|
|
6
6
|
// `add` change returns a `set` change so it includes the ID to reflect the change that was written.
|
|
7
7
|
return { action: "set", collection, id: provider.addItem(collection, change.data), data: change.data };
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
if (id) {
|
|
10
10
|
if (action === "set")
|
|
11
11
|
provider.setItem(collection, id, change.data);
|
|
12
12
|
else if (action === "update")
|
|
@@ -35,7 +35,7 @@ export async function writeAsyncChange(provider, change) {
|
|
|
35
35
|
// `add` change returns a `set` change so it includes the ID to reflect the change that was written.
|
|
36
36
|
return { action: "set", collection, id: await provider.addItem(collection, change.data), data: change.data };
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
if (id) {
|
|
39
39
|
if (action === "set")
|
|
40
40
|
await provider.setItem(collection, id, change.data);
|
|
41
41
|
else if (action === "update")
|
package/db/ChangesProvider.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { DatabaseChange, DatabaseChanges } from "./Change.js";
|
|
2
1
|
import type { MutableArray } from "../util/array.js";
|
|
3
2
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
3
|
import type { ItemQuery } from "../util/item.js";
|
|
5
4
|
import type { Updates } from "../util/update.js";
|
|
5
|
+
import type { DatabaseChange, DatabaseChanges } from "./Change.js";
|
|
6
6
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
7
7
|
/** Synchronous provider that keeps a log of any written changes to its `.changes` property. */
|
|
8
8
|
export declare class ChangesProvider<T extends Database> extends ThroughProvider<T> {
|
package/db/DebugProvider.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
1
|
import type { DataKey, Database } from "../util/data.js";
|
|
3
2
|
import type { ItemQuery, Items, OptionalItem } from "../util/item.js";
|
|
4
3
|
import type { Updates } from "../util/update.js";
|
|
5
4
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
6
5
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
7
6
|
export declare class DebugProvider<T extends Database> extends ThroughProvider<T> {
|
|
8
|
-
constructor(source: Provider<T>);
|
|
9
7
|
getItem<K extends DataKey<T>>(collection: K, id: string): OptionalItem<T[K]>;
|
|
10
8
|
getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterableIterator<OptionalItem<T[K]>>;
|
|
11
9
|
addItem<K extends DataKey<T>>(collection: K, data: T[K]): string;
|
|
@@ -21,7 +19,6 @@ export declare class DebugProvider<T extends Database> extends ThroughProvider<T
|
|
|
21
19
|
}
|
|
22
20
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
23
21
|
export declare class AsyncDebugProvider<T extends Database> extends AsyncThroughProvider<T> {
|
|
24
|
-
constructor(source: AsyncProvider<T>);
|
|
25
22
|
getItem<K extends DataKey<T>>(collection: K, id: string): Promise<OptionalItem<T[K]>>;
|
|
26
23
|
getItemSequence<K extends DataKey<T>>(collection: K, id: string): AsyncIterableIterator<OptionalItem<T[K]>>;
|
|
27
24
|
addItem<K extends DataKey<T>>(collection: K, data: T[K]): Promise<string>;
|
package/db/DebugProvider.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
1
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
3
2
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
4
3
|
export class DebugProvider extends ThroughProvider {
|
|
5
|
-
constructor(source) {
|
|
6
|
-
super(source);
|
|
7
|
-
}
|
|
8
4
|
getItem(collection, id) {
|
|
9
5
|
try {
|
|
10
6
|
const item = super.getItem(collection, id);
|
|
@@ -138,9 +134,6 @@ export class DebugProvider extends ThroughProvider {
|
|
|
138
134
|
}
|
|
139
135
|
/** Provider that logs operations to a synchronous source provider to the console. */
|
|
140
136
|
export class AsyncDebugProvider extends AsyncThroughProvider {
|
|
141
|
-
constructor(source) {
|
|
142
|
-
super(source);
|
|
143
|
-
}
|
|
144
137
|
async getItem(collection, id) {
|
|
145
138
|
try {
|
|
146
139
|
console.debug("⋯ GET", collection, id);
|
package/db/ItemStore.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { BooleanStore } from "../store/BooleanStore.js";
|
|
2
|
+
import { OptionalDataStore } from "../store/DataStore.js";
|
|
3
3
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
4
|
import type { Item } from "../util/item.js";
|
|
5
5
|
import type { Stop } from "../util/start.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import type { MemoryProvider } from "./MemoryProvider.js";
|
|
7
|
+
import type { AbstractProvider } from "./Provider.js";
|
|
8
8
|
/** Store a single item. */
|
|
9
9
|
export declare class ItemStore<T extends Database, K extends DataKey<T>> extends OptionalDataStore<Item<T[K]>> {
|
|
10
10
|
readonly provider: AbstractProvider<T>;
|
package/db/MemoryProvider.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
1
2
|
import type { Data, DataKey, Database } from "../util/data.js";
|
|
2
3
|
import type { Item, ItemQuery, Items, OptionalItem } from "../util/item.js";
|
|
3
4
|
import type { Updates } from "../util/update.js";
|
|
4
|
-
import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
5
5
|
import { Provider } from "./Provider.js";
|
|
6
6
|
/**
|
|
7
7
|
* Fast in-memory store for data.
|
package/db/MemoryProvider.js
CHANGED
|
@@ -17,6 +17,7 @@ export class MemoryProvider extends Provider {
|
|
|
17
17
|
_tables = {};
|
|
18
18
|
/** Get a table for a collection. */
|
|
19
19
|
getTable(collection) {
|
|
20
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: This is convenient.
|
|
20
21
|
return (this._tables[collection] ||= new MemoryTable());
|
|
21
22
|
}
|
|
22
23
|
getItemTime(collection, id) {
|
|
@@ -35,16 +36,16 @@ export class MemoryProvider extends Provider {
|
|
|
35
36
|
return this.getTable(collection).addItem(data);
|
|
36
37
|
}
|
|
37
38
|
setItem(collection, id, data) {
|
|
38
|
-
|
|
39
|
+
this.getTable(collection).setItem(id, data);
|
|
39
40
|
}
|
|
40
41
|
setItemSequence(collection, id, sequence) {
|
|
41
42
|
return this.getTable(collection).setItemSequence(id, sequence);
|
|
42
43
|
}
|
|
43
44
|
updateItem(collection, id, updates) {
|
|
44
|
-
|
|
45
|
+
this.getTable(collection).updateItem(id, updates);
|
|
45
46
|
}
|
|
46
47
|
deleteItem(collection, id) {
|
|
47
|
-
|
|
48
|
+
this.getTable(collection).deleteItem(id);
|
|
48
49
|
}
|
|
49
50
|
getQueryTime(collection, query) {
|
|
50
51
|
return this.getTable(collection).getQueryTime(query);
|
|
@@ -62,16 +63,16 @@ export class MemoryProvider extends Provider {
|
|
|
62
63
|
return this.getTable(collection).getCachedQuerySequence(query);
|
|
63
64
|
}
|
|
64
65
|
setQuery(collection, query, data) {
|
|
65
|
-
|
|
66
|
+
this.getTable(collection).setQuery(query, data);
|
|
66
67
|
}
|
|
67
68
|
updateQuery(collection, query, updates) {
|
|
68
|
-
|
|
69
|
+
this.getTable(collection).updateQuery(query, updates);
|
|
69
70
|
}
|
|
70
71
|
deleteQuery(collection, query) {
|
|
71
|
-
|
|
72
|
+
this.getTable(collection).deleteQuery(query);
|
|
72
73
|
}
|
|
73
74
|
setItems(collection, items, query) {
|
|
74
|
-
|
|
75
|
+
this.getTable(collection).setItems(items, query);
|
|
75
76
|
}
|
|
76
77
|
setItemsSequence(collection, sequence, query) {
|
|
77
78
|
return this.getTable(collection).setItemsSequence(sequence, query);
|
|
@@ -141,7 +142,7 @@ export class MemoryTable {
|
|
|
141
142
|
updateItem(id, updates) {
|
|
142
143
|
const oldItem = this._data.get(id);
|
|
143
144
|
if (oldItem)
|
|
144
|
-
|
|
145
|
+
this.setItem(id, updateData(oldItem, updates));
|
|
145
146
|
}
|
|
146
147
|
deleteItem(id) {
|
|
147
148
|
if (this._data.has(id)) {
|
package/db/QueryStore.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ArrayStore } from "../store/ArrayStore.js";
|
|
2
|
+
import { BooleanStore } from "../store/BooleanStore.js";
|
|
3
3
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
4
|
import type { Item, ItemQuery } from "../util/item.js";
|
|
5
5
|
import type { Stop } from "../util/start.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import type { MemoryProvider } from "./MemoryProvider.js";
|
|
7
|
+
import type { AbstractProvider } from "./Provider.js";
|
|
8
8
|
/** Store a set of multiple items. */
|
|
9
9
|
export declare class QueryStore<T extends Database, K extends DataKey<T>> extends ArrayStore<Item<T[K]>> {
|
|
10
10
|
readonly provider: AbstractProvider<T>;
|
package/db/QueryStore.js
CHANGED
|
@@ -24,7 +24,7 @@ export class QueryStore extends ArrayStore {
|
|
|
24
24
|
this.provider = provider;
|
|
25
25
|
this.collection = collection;
|
|
26
26
|
this.query = query;
|
|
27
|
-
this.limit = getLimit(query) ??
|
|
27
|
+
this.limit = getLimit(query) ?? Number.POSITIVE_INFINITY;
|
|
28
28
|
// Start loading the value from the provider if it is not definitely cached.
|
|
29
29
|
if (typeof time !== "number")
|
|
30
30
|
this.refresh();
|
package/db/ThroughProvider.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
1
|
import type { DataKey, Database } from "../util/data.js";
|
|
3
2
|
import type { Item, ItemQuery, Items, OptionalItem } from "../util/item.js";
|
|
4
3
|
import type { Sourceable } from "../util/source.js";
|
|
5
4
|
import type { Updates } from "../util/update.js";
|
|
5
|
+
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
6
6
|
/** A provider that passes through to a synchronous source. */
|
|
7
7
|
export declare class ThroughProvider<T extends Database> implements Provider<T>, Sourceable<Provider<T>> {
|
|
8
8
|
readonly source: Provider<T>;
|
package/db/ThroughProvider.js
CHANGED
|
@@ -17,13 +17,13 @@ export class ThroughProvider {
|
|
|
17
17
|
return this.source.addItem(collection, data);
|
|
18
18
|
}
|
|
19
19
|
setItem(collection, id, data) {
|
|
20
|
-
|
|
20
|
+
this.source.setItem(collection, id, data);
|
|
21
21
|
}
|
|
22
22
|
updateItem(collection, id, update) {
|
|
23
|
-
|
|
23
|
+
this.source.updateItem(collection, id, update);
|
|
24
24
|
}
|
|
25
25
|
deleteItem(collection, id) {
|
|
26
|
-
|
|
26
|
+
this.source.deleteItem(collection, id);
|
|
27
27
|
}
|
|
28
28
|
countQuery(collection, query) {
|
|
29
29
|
return this.source.countQuery(collection, query);
|
|
@@ -35,13 +35,13 @@ export class ThroughProvider {
|
|
|
35
35
|
return this.source.getQuerySequence(collection, query);
|
|
36
36
|
}
|
|
37
37
|
setQuery(collection, query, data) {
|
|
38
|
-
|
|
38
|
+
this.source.setQuery(collection, query, data);
|
|
39
39
|
}
|
|
40
40
|
updateQuery(collection, query, update) {
|
|
41
|
-
|
|
41
|
+
this.source.updateQuery(collection, query, update);
|
|
42
42
|
}
|
|
43
43
|
deleteQuery(collection, query) {
|
|
44
|
-
|
|
44
|
+
this.source.deleteQuery(collection, query);
|
|
45
45
|
}
|
|
46
46
|
getFirst(collection, query) {
|
|
47
47
|
return this.source.getFirst(collection, query);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
2
1
|
import type { DataSchema, DatabaseSchemas } from "../schema/DataSchema.js";
|
|
3
2
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
3
|
import type { ItemQuery, Items, OptionalItem } from "../util/item.js";
|
|
5
4
|
import type { Sourceable } from "../util/source.js";
|
|
6
5
|
import type { Updates } from "../util/update.js";
|
|
6
|
+
import type { AsyncProvider, Provider } from "./Provider.js";
|
|
7
7
|
import { AsyncThroughProvider, ThroughProvider } from "./ThroughProvider.js";
|
|
8
8
|
/** Validate a synchronous source provider (source can have any type because validation guarantees the type). */
|
|
9
9
|
export declare class ValidationProvider<T extends Database> extends ThroughProvider<T> implements Provider<T>, Sourceable<Provider<T>> {
|
package/db/ValidationProvider.js
CHANGED
|
@@ -31,14 +31,14 @@ export class ValidationProvider extends ThroughProvider {
|
|
|
31
31
|
return super.addItem(collection, validateWithContext(data, this.getSchema(collection), VALIDATION_CONTEXT_ADD));
|
|
32
32
|
}
|
|
33
33
|
setItem(collection, id, data) {
|
|
34
|
-
|
|
34
|
+
super.setItem(collection, id, validateWithContext(data, this.getSchema(collection), VALIDATION_CONTEXT_SET));
|
|
35
35
|
}
|
|
36
36
|
updateItem(collection, id, updates) {
|
|
37
37
|
validateWithContext(updateData({}, updates), this.getSchema(collection), VALIDATION_CONTEXT_UPDATE);
|
|
38
|
-
|
|
38
|
+
super.updateItem(collection, id, updates);
|
|
39
39
|
}
|
|
40
40
|
deleteItem(collection, id) {
|
|
41
|
-
|
|
41
|
+
super.deleteItem(collection, id);
|
|
42
42
|
}
|
|
43
43
|
countQuery(collection, query) {
|
|
44
44
|
return super.countQuery(collection, query);
|
|
@@ -47,14 +47,14 @@ export class ValidationProvider extends ThroughProvider {
|
|
|
47
47
|
return _validateItems(collection, super.getQuery(collection, query), this.getSchema(collection));
|
|
48
48
|
}
|
|
49
49
|
setQuery(collection, query, data) {
|
|
50
|
-
|
|
50
|
+
super.setQuery(collection, query, this.getSchema(collection).validate(data));
|
|
51
51
|
}
|
|
52
52
|
updateQuery(collection, query, updates) {
|
|
53
53
|
validateWithContext(updateData({}, updates), this.getSchema(collection), VALIDATION_CONTEXT_UPDATE);
|
|
54
|
-
|
|
54
|
+
super.updateQuery(collection, query, updates);
|
|
55
55
|
}
|
|
56
56
|
deleteQuery(collection, query) {
|
|
57
|
-
|
|
57
|
+
super.deleteQuery(collection, query);
|
|
58
58
|
}
|
|
59
59
|
async *getQuerySequence(collection, query) {
|
|
60
60
|
const schema = this.getSchema(collection);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { Firestore } from "firebase/firestore";
|
|
2
|
+
import { AsyncProvider } from "../../db/Provider.js";
|
|
1
3
|
import type { Data, DataKey, Database } from "../../util/data.js";
|
|
2
4
|
import type { ItemQuery, Items, OptionalItem } from "../../util/item.js";
|
|
3
5
|
import type { Updates } from "../../util/update.js";
|
|
4
|
-
import type { Firestore } from "firebase/firestore";
|
|
5
|
-
import { AsyncProvider } from "../../db/Provider.js";
|
|
6
6
|
/**
|
|
7
7
|
* Firestore client database provider.
|
|
8
8
|
* - Works with the Firebase JS SDK.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addDoc, arrayRemove, arrayUnion, collection, deleteDoc, doc, documentId, getCountFromServer, getDoc, getDocs, increment, limit, onSnapshot, orderBy, query, setDoc, updateDoc, where } from "firebase/firestore";
|
|
1
|
+
import { addDoc, arrayRemove, arrayUnion, collection, deleteDoc, doc, documentId, getCountFromServer, getDoc, getDocs, increment, limit, onSnapshot, orderBy, query, setDoc, updateDoc, where, } from "firebase/firestore";
|
|
2
2
|
import { AsyncProvider } from "../../db/Provider.js";
|
|
3
3
|
import { LazyDeferredSequence } from "../../sequence/LazyDeferredSequence.js";
|
|
4
4
|
import { getItem } from "../../util/item.js";
|
|
@@ -22,7 +22,9 @@ const OPERATORS = {
|
|
|
22
22
|
};
|
|
23
23
|
/** Get a Firestore QueryReference for a given query. */
|
|
24
24
|
function _getQuery(firestore, c, q) {
|
|
25
|
-
return q
|
|
25
|
+
return q
|
|
26
|
+
? query(collection(firestore, c), ..._getConstraints(q))
|
|
27
|
+
: collection(firestore, c);
|
|
26
28
|
}
|
|
27
29
|
function* _getConstraints(q) {
|
|
28
30
|
for (const { key, direction } of getOrders(q))
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { Firestore } from "firebase/firestore/lite";
|
|
2
|
+
import { AsyncProvider } from "../../db/Provider.js";
|
|
1
3
|
import type { Data, DataKey, Database } from "../../util/data.js";
|
|
2
4
|
import type { ItemQuery, Items, OptionalItem } from "../../util/item.js";
|
|
3
5
|
import type { Updates } from "../../util/update.js";
|
|
4
|
-
import type { Firestore } from "firebase/firestore/lite";
|
|
5
|
-
import { AsyncProvider } from "../../db/Provider.js";
|
|
6
6
|
/**
|
|
7
7
|
* Firestore Lite client database provider.
|
|
8
8
|
* - Works with the Firebase JS SDK.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addDoc, arrayRemove, arrayUnion, collection, deleteDoc, doc, documentId, getCount, getDoc, getDocs, increment, limit, orderBy, query, setDoc, updateDoc, where } from "firebase/firestore/lite";
|
|
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 { AsyncProvider } from "../../db/Provider.js";
|
|
3
3
|
import { UnimplementedError } from "../../error/UnimplementedError.js";
|
|
4
4
|
import { getItem } from "../../util/item.js";
|
|
@@ -22,7 +22,9 @@ const OPERATORS = {
|
|
|
22
22
|
};
|
|
23
23
|
/** Create a corresponding `QueryReference` from a Query. */
|
|
24
24
|
function _getQuery(firestore, c, q) {
|
|
25
|
-
return q
|
|
25
|
+
return q
|
|
26
|
+
? query(collection(firestore, c), ..._getConstraints(q))
|
|
27
|
+
: collection(firestore, c);
|
|
26
28
|
}
|
|
27
29
|
function* _getConstraints(q) {
|
|
28
30
|
for (const { key, direction } of getOrders(q))
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Firestore } from "@google-cloud/firestore";
|
|
2
|
+
import { AsyncProvider } from "../../db/Provider.js";
|
|
1
3
|
import type { DataKey, Database } from "../../util/data.js";
|
|
2
4
|
import type { ItemQuery, Items, OptionalItem } from "../../util/item.js";
|
|
3
5
|
import type { Updates } from "../../util/update.js";
|
|
4
|
-
import { Firestore } from "@google-cloud/firestore";
|
|
5
|
-
import { AsyncProvider } from "../../db/Provider.js";
|
|
6
6
|
/**
|
|
7
7
|
* Firestore server database provider.
|
|
8
8
|
* - Works with the Firebase Admin SDK for Node.JS
|
package/markup/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MarkupRules } from "./rule.js";
|
|
2
1
|
import type { AbsoluteLink, LinkHosts, LinkSchemes } from "../util/link.js";
|
|
2
|
+
import type { MarkupRules } from "./rule.js";
|
|
3
3
|
/** The current parsing options (represents the current state of the parsing). */
|
|
4
4
|
export type MarkupOptions = {
|
|
5
5
|
/** The active list of parsing rules. */
|
package/markup/regexp.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import type { MarkupOptions } from "./options.js";
|
|
2
|
-
import type { Data } from "../util/data.js";
|
|
3
1
|
import type { NamedRegExp, NamedRegExpData, PossibleRegExp } from "../util/regexp.js";
|
|
4
|
-
/** Subset of `NamedRegExpArray<T>` that are the only things we're required return from a `MarkupMatcher` function. */
|
|
5
|
-
export type MarkupMatch<T extends Data | undefined> = {
|
|
6
|
-
0: string;
|
|
7
|
-
index: number;
|
|
8
|
-
groups: T;
|
|
9
|
-
};
|
|
10
|
-
/** Function that matches a string and returns a `MarkupMatch` or `null` or `void` */
|
|
11
|
-
export type MarkupMatcher<T extends Data> = (input: string, options: MarkupOptions) => MarkupMatch<T> | null | void;
|
|
12
2
|
export declare const BLOCK_REGEXP: RegExp;
|
|
13
3
|
export declare const BLOCK_START_REGEXP: RegExp;
|
|
14
4
|
export declare const BLOCK_END_REGEXP: RegExp;
|
package/markup/render.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MarkupOptions } from "./options.js";
|
|
2
1
|
import type { JSXNode } from "../util/jsx.js";
|
|
2
|
+
import type { MarkupOptions } from "./options.js";
|
|
3
3
|
/**
|
|
4
4
|
* Parse a text string as Markdownish syntax and render it as a JSX node.
|
|
5
5
|
* - Syntax is not defined by this code, but by the rules supplied to it.
|
package/markup/render.js
CHANGED
package/markup/rule.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { MarkupOptions } from "./options.js";
|
|
2
1
|
import type { ImmutableArray } from "../util/array.js";
|
|
3
2
|
import type { JSXElement } from "../util/jsx.js";
|
|
4
3
|
import type { NamedRegExp, NamedRegExpData, TypedRegExp, TypedRegExpExecArray } from "../util/regexp.js";
|
|
4
|
+
import type { MarkupOptions } from "./options.js";
|
|
5
5
|
export type MarkupElement = {
|
|
6
6
|
/** String index where this element was matched in the input string. */
|
|
7
7
|
index: number;
|
|
@@ -41,8 +41,7 @@ export declare class NamedRegExpMarkupRule<T extends NamedRegExpData> implements
|
|
|
41
41
|
readonly render: (data: T, options: MarkupOptions) => JSXElement;
|
|
42
42
|
readonly contexts: ImmutableArray<string>;
|
|
43
43
|
readonly priority?: number | undefined;
|
|
44
|
-
constructor(regexp: NamedRegExp<T>,
|
|
45
|
-
render: (data: T, options: MarkupOptions) => JSXElement, contexts: ImmutableArray<string>, priority?: number | undefined);
|
|
44
|
+
constructor(regexp: NamedRegExp<T>, render: (data: T, options: MarkupOptions) => JSXElement, contexts: ImmutableArray<string>, priority?: number | undefined);
|
|
46
45
|
match(input: string, options: MarkupOptions): MarkupElement | undefined;
|
|
47
46
|
}
|
|
48
47
|
export declare class LinkRegExpMarkupRule implements MarkupRule {
|
package/markup/rule.js
CHANGED
|
@@ -26,8 +26,7 @@ export class NamedRegExpMarkupRule {
|
|
|
26
26
|
render;
|
|
27
27
|
contexts;
|
|
28
28
|
priority;
|
|
29
|
-
constructor(regexp,
|
|
30
|
-
render, contexts, priority) {
|
|
29
|
+
constructor(regexp, render, contexts, priority) {
|
|
31
30
|
this.regexp = regexp;
|
|
32
31
|
this.render = render;
|
|
33
32
|
this.contexts = contexts;
|
package/markup/rules.js
CHANGED
|
@@ -78,7 +78,7 @@ const _mapOrdered = (item, key) => ({
|
|
|
78
78
|
ref: null,
|
|
79
79
|
$$typeof,
|
|
80
80
|
props: {
|
|
81
|
-
value: parseInt(item, 10),
|
|
81
|
+
value: Number.parseInt(item, 10),
|
|
82
82
|
children: item
|
|
83
83
|
.slice(item.indexOf(" ") + 1)
|
|
84
84
|
.trim()
|
|
@@ -110,7 +110,7 @@ export const BLOCKQUOTE_RULE = new NamedRegExpMarkupRule(getLineRegExp(`(?<quote
|
|
|
110
110
|
*/
|
|
111
111
|
export const FENCED_CODE_RULE = new NamedRegExpMarkupRule(
|
|
112
112
|
// Matcher has its own end that only stops when it reaches a matching closing fence or the end of the string.
|
|
113
|
-
getLineRegExp(`(?<wrap>\`{3,}|~{3,}) *(?<title>${LINE_REGEXP.source})\n(?<code>${BLOCK_REGEXP.source})`,
|
|
113
|
+
getLineRegExp(`(?<wrap>\`{3,}|~{3,}) *(?<title>${LINE_REGEXP.source})\n(?<code>${BLOCK_REGEXP.source})`, "(?:\n\\k<wrap>|$)"), ({ title, code }) => ({
|
|
114
114
|
type: "pre",
|
|
115
115
|
key: null,
|
|
116
116
|
ref: null,
|
|
@@ -130,7 +130,7 @@ getLineRegExp(`(?<wrap>\`{3,}|~{3,}) *(?<title>${LINE_REGEXP.source})\n(?<code>$
|
|
|
130
130
|
* - When ordering rules, paragraph should go after other "block" context elements (because it has a very generous capture).
|
|
131
131
|
*/
|
|
132
132
|
export const PARAGRAPH_RULE = new NamedRegExpMarkupRule(getBlockRegExp(`(?<paragraph>${BLOCK_REGEXP.source})`), ({ paragraph }) => ({
|
|
133
|
-
type:
|
|
133
|
+
type: "p",
|
|
134
134
|
key: null,
|
|
135
135
|
ref: null,
|
|
136
136
|
$$typeof,
|
|
@@ -194,7 +194,7 @@ export const CODE_RULE = new NamedRegExpMarkupRule(new RegExp(`(?<wrap>\`+)(?<co
|
|
|
194
194
|
* - Closing characters must exactly match opening characters.
|
|
195
195
|
* - Different to Markdown: strong is always surrounded by `*asterisks*` and emphasis is always surrounded by `_underscores_` (strong isn't 'double emphasis').
|
|
196
196
|
*/
|
|
197
|
-
const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong",
|
|
197
|
+
const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong", _: "em", "=": "mark", ":": "mark" }; // Hyphen must be first so it works when we use the keys as a character class.
|
|
198
198
|
export const INLINE_RULE = new NamedRegExpMarkupRule(getWordRegExp(`(?<wrap>(?<char>[${Object.keys(INLINE_CHARS).join("")}])+)(?<text>(?!\\k<char>)\\S(?:[\\s\\S]*?(?!\\k<char>)\\S)?)\\k<wrap>`), // prettier-ignore
|
|
199
199
|
({ char, text }) => ({
|
|
200
200
|
type: INLINE_CHARS[char],
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.128.0",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -43,40 +43,30 @@
|
|
|
43
43
|
"node": ">=16.0.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"fix:eslint": "eslint --cache --fix './**/*.{ts,tsx}'",
|
|
49
|
-
"test": "npm run test:prettier && npm run test:eslint && npm run test:typescript && npm run test:jest",
|
|
50
|
-
"test:prettier": "prettier --check './**/*.{md,json}'",
|
|
51
|
-
"test:eslint": "eslint --cache './**/*.{ts,tsx}'",
|
|
46
|
+
"test": "npm run test:biome && npm run test:typescript && npm run test:jest",
|
|
47
|
+
"test:biome": "biome check .",
|
|
52
48
|
"test:typescript": "tsc --noEmit",
|
|
53
49
|
"test:jest": "jest --detectOpenHandles",
|
|
54
|
-
"
|
|
50
|
+
"fix": "npm run fix:biome",
|
|
51
|
+
"fix:biome": "biome check --apply .",
|
|
55
52
|
"build": "npm run build:setup && npm run build:copy && npm run build:typescript && npm run build:check && npm run build:jest",
|
|
56
53
|
"build:setup": "rm -rf ./dist && mkdir -p ./dist",
|
|
57
54
|
"build:copy": "cp package.json dist/package.json && cp LICENSE.md dist/LICENSE.md && cp README.md dist/README.md && cp .npmignore dist/.npmignore",
|
|
58
|
-
"build:typescript": "tsc
|
|
55
|
+
"build:typescript": "tsc",
|
|
59
56
|
"build:check": "node ./dist/index.js",
|
|
60
57
|
"build:jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest.config.build.cjs"
|
|
61
58
|
},
|
|
62
59
|
"devDependencies": {
|
|
60
|
+
"@biomejs/biome": "^1.7.3",
|
|
63
61
|
"@google-cloud/firestore": "^7.3.0",
|
|
64
62
|
"@types/jest": "^29.4.0",
|
|
65
63
|
"@types/react": "^18.0.27",
|
|
66
64
|
"@types/react-dom": "^18.0.10",
|
|
67
|
-
"
|
|
68
|
-
"@typescript-eslint/parser": "^7.1.0",
|
|
69
|
-
"esbuild": "^0.20.1",
|
|
65
|
+
"esbuild": "^0.21.3",
|
|
70
66
|
"esbuild-jest": "^0.5.0",
|
|
71
|
-
"eslint": "^8.33.0",
|
|
72
|
-
"eslint-config-prettier": "^9.0.0",
|
|
73
|
-
"eslint-import-resolver-typescript": "^3.5.5",
|
|
74
|
-
"eslint-plugin-import": "^2.27.5",
|
|
75
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
76
67
|
"firebase": "^10.3.1",
|
|
77
68
|
"jest": "^29.4.1",
|
|
78
69
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
79
|
-
"prettier": "^3.0.3",
|
|
80
70
|
"react": "^18.1.0",
|
|
81
71
|
"react-dom": "^18.1.0",
|
|
82
72
|
"typescript": "^5.0.2"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
2
|
/**
|
|
3
3
|
* Create a cache context that can be provided to React elements and allows them to call `useCache()`
|
|
4
4
|
* - Cache is a `Map` indexed by strings that can be used to store any value.
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
export declare function createCacheContext<T>(): {
|
|
7
7
|
/** Wrap around a set of elements to provide the cache to them. */
|
|
8
8
|
readonly CacheContext: ({ children }: {
|
|
9
|
-
children:
|
|
10
|
-
}) =>
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}) => ReactElement;
|
|
11
11
|
/** Use the current cache map in a component. */
|
|
12
12
|
readonly useCache: () => Map<string, T>;
|
|
13
13
|
};
|
|
@@ -14,6 +14,7 @@ export function createCacheContext() {
|
|
|
14
14
|
return cache;
|
|
15
15
|
},
|
|
16
16
|
CacheContext({ children }) {
|
|
17
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: This is the most efficient way to do this.
|
|
17
18
|
const cache = (useRef().current ||= new Map());
|
|
18
19
|
return createElement(context.Provider, { children, value: cache });
|
|
19
20
|
},
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { ItemStore } from "../db/ItemStore.js";
|
|
2
3
|
import type { AbstractProvider } from "../db/Provider.js";
|
|
4
|
+
import { QueryStore } from "../db/QueryStore.js";
|
|
3
5
|
import type { DataKey, Database } from "../util/data.js";
|
|
4
6
|
import type { ItemQuery } from "../util/item.js";
|
|
5
7
|
import type { Optional } from "../util/optional.js";
|
|
6
|
-
import { ItemStore } from "../db/ItemStore.js";
|
|
7
|
-
import { QueryStore } from "../db/QueryStore.js";
|
|
8
8
|
export interface DataContext<T extends Database> {
|
|
9
9
|
/** Get an `ItemStore` for the specified collection item in the current `DataProvider` context and subscribe to any changes in it. */
|
|
10
10
|
useItem<K extends DataKey<T>>(this: void, collection: K, id: string): ItemStore<T, K>;
|
|
@@ -13,10 +13,12 @@ export interface DataContext<T extends Database> {
|
|
|
13
13
|
useQuery<K extends DataKey<T>>(this: void, collection: K, query: ItemQuery<T[K]>): QueryStore<T, K>;
|
|
14
14
|
useQuery<K extends DataKey<T>>(this: void, collection: Optional<K>, query: Optional<ItemQuery<T[K]>>): QueryStore<T, K> | undefined;
|
|
15
15
|
readonly DataContext: ({ children }: {
|
|
16
|
-
children:
|
|
17
|
-
}) =>
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}) => ReactElement;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Create a data context
|
|
20
|
+
* Create a data context
|
|
21
|
+
* - Allows React elements to call `useItem()` and `useQuery()` to access items/queries in a database provider.
|
|
22
|
+
* - If the database has a `CacheProvider` in its chain then in-memory data will be used in the returned stores.
|
|
21
23
|
*/
|
|
22
24
|
export declare function createDataContext<T extends Database>(provider: AbstractProvider<T>): DataContext<T>;
|
|
@@ -6,10 +6,13 @@ import { getOptionalSource } from "../util/source.js";
|
|
|
6
6
|
import { createCacheContext } from "./createCacheContext.js";
|
|
7
7
|
import { useStore } from "./useStore.js";
|
|
8
8
|
/**
|
|
9
|
-
* Create a data context
|
|
9
|
+
* Create a data context
|
|
10
|
+
* - Allows React elements to call `useItem()` and `useQuery()` to access items/queries in a database provider.
|
|
11
|
+
* - If the database has a `CacheProvider` in its chain then in-memory data will be used in the returned stores.
|
|
10
12
|
*/
|
|
11
13
|
export function createDataContext(provider) {
|
|
12
|
-
|
|
14
|
+
// biome-ignore lint/suspicious/noExplicitAny: The outer function enforces the type.
|
|
15
|
+
const { CacheContext, useCache } = createCacheContext();
|
|
13
16
|
// If this provider is backed by an in-memory cache, pass it to the `ItemStore` and `QueryStore` instances we create.
|
|
14
17
|
const memory = getOptionalSource(CacheProvider, provider)?.memory;
|
|
15
18
|
return {
|
package/react/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export * from "./createCacheContext.js";
|
|
2
2
|
export * from "./createDataContext.js";
|
|
3
|
-
export * from "./useFocus.js";
|
|
4
3
|
export * from "./useInstance.js";
|
|
5
4
|
export * from "./useLazy.js";
|
|
6
5
|
export * from "./useReduce.js";
|
|
7
6
|
export * from "./useSequence.js";
|
|
8
7
|
export * from "./useStore.js";
|
|
9
|
-
export * from "./useMount.js";
|