shelving 1.86.2 → 1.86.4
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/constraint/FilterConstraint.d.ts +3 -3
- package/constraint/FilterConstraint.js +10 -9
- package/constraint/FilterConstraints.d.ts +4 -4
- package/constraint/QueryConstraints.d.ts +3 -3
- package/constraint/SortConstraint.d.ts +3 -3
- package/constraint/SortConstraint.js +12 -11
- package/constraint/SortConstraints.d.ts +4 -4
- package/db/Collection.d.ts +2 -2
- package/db/Database.d.ts +2 -2
- package/db/Query.d.ts +2 -2
- package/firestore/client/FirestoreClientProvider.js +2 -3
- package/firestore/lite/FirestoreLiteProvider.js +3 -2
- package/firestore/server/FirestoreServerProvider.js +6 -7
- package/markup/regexp.d.ts +1 -1
- package/markup/regexp.js +2 -2
- package/markup/rule.d.ts +12 -18
- package/markup/rule.js +15 -24
- package/markup/rules.d.ts +0 -9
- package/markup/rules.js +4 -4
- package/package.json +1 -1
- package/react/useQuery.js +5 -3
- package/state/State.d.ts +5 -2
- package/state/State.js +12 -3
- package/util/class.d.ts +2 -3
- package/util/class.js +1 -0
- package/util/hydrate.d.ts +1 -1
- package/util/regexp.d.ts +13 -10
- package/util/regexp.js +3 -2
|
@@ -16,7 +16,7 @@ export type FilterProps<T extends Data> = {
|
|
|
16
16
|
[K in DataKey<T> as `${K}<` | `${K}<=` | `${K}>` | `${K}>=`]?: T[K];
|
|
17
17
|
};
|
|
18
18
|
/** List of filters in a flexible format. */
|
|
19
|
-
export type FilterList<T extends Data> =
|
|
19
|
+
export type FilterList<T extends Data> = FilterProps<T> | FilterConstraint<T> | Iterable<Nullish<FilterProps<T> | FilterConstraint<T>>>;
|
|
20
20
|
/**
|
|
21
21
|
* Filter: filters a list of data.
|
|
22
22
|
*
|
|
@@ -34,5 +34,5 @@ export declare class FilterConstraint<T extends Data = Data> implements Constrai
|
|
|
34
34
|
transform(items: Iterable<T>): Iterable<T>;
|
|
35
35
|
toString(): string;
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
export declare function getFilters<T extends Data>(
|
|
37
|
+
/** Turn `FilterList` into a list of `FilterConstraint` instances. */
|
|
38
|
+
export declare function getFilters<T extends Data>(list: FilterList<T> | FilterList<T>[]): Iterable<FilterConstraint<T>>;
|
|
@@ -79,17 +79,18 @@ export class FilterConstraint {
|
|
|
79
79
|
return `"${this.filterKey}":${JSON.stringify(this.value)}`;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
/**
|
|
83
|
-
export function* getFilters(
|
|
84
|
-
if (
|
|
85
|
-
yield
|
|
82
|
+
/** Turn `FilterList` into a list of `FilterConstraint` instances. */
|
|
83
|
+
export function* getFilters(list) {
|
|
84
|
+
if (list instanceof FilterConstraint) {
|
|
85
|
+
yield list;
|
|
86
86
|
}
|
|
87
|
-
else if (isIterable(
|
|
88
|
-
for (const filter of
|
|
89
|
-
|
|
87
|
+
else if (isIterable(list)) {
|
|
88
|
+
for (const filter of list)
|
|
89
|
+
if (filter)
|
|
90
|
+
yield* getFilters(filter);
|
|
90
91
|
}
|
|
91
|
-
else
|
|
92
|
-
for (const [key, value] of Object.entries(
|
|
92
|
+
else {
|
|
93
|
+
for (const [key, value] of Object.entries(list))
|
|
93
94
|
yield new FilterConstraint(key, value);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
@@ -8,14 +8,14 @@ import { Constraints } from "./Constraints.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export interface Filterable<T extends Data> extends Matchable<[T]> {
|
|
10
10
|
/** Add a filter to this filterable. */
|
|
11
|
-
filter(...filters: FilterList<
|
|
11
|
+
filter(...filters: FilterList<T>[]): this;
|
|
12
12
|
/** Match an item against the filters specified for this object. */
|
|
13
13
|
match(item: T): boolean;
|
|
14
14
|
}
|
|
15
15
|
/** A set of filters. */
|
|
16
|
-
export declare class FilterConstraints<T extends Data = Data> extends Constraints<T, FilterConstraint<
|
|
17
|
-
constructor(...filters: FilterList<
|
|
18
|
-
filter(...filters: FilterList<
|
|
16
|
+
export declare class FilterConstraints<T extends Data = Data> extends Constraints<T, FilterConstraint<T>> implements Filterable<T> {
|
|
17
|
+
constructor(...filters: FilterList<T>[]);
|
|
18
|
+
filter(...filters: FilterList<T>[]): this;
|
|
19
19
|
match(item: T): boolean;
|
|
20
20
|
transform(items: Iterable<T>): Iterable<T>;
|
|
21
21
|
toString(): string;
|
|
@@ -31,11 +31,11 @@ export declare class QueryConstraints<T extends Data = Data> extends Constraint<
|
|
|
31
31
|
readonly filters: FilterConstraints<T>;
|
|
32
32
|
readonly sorts: SortConstraints<T>;
|
|
33
33
|
readonly limit: number | null;
|
|
34
|
-
constructor(filters?: FilterList<
|
|
35
|
-
filter(...filters: FilterList<
|
|
34
|
+
constructor(filters?: FilterList<T> | FilterConstraints<T>, sorts?: SortList<T> | SortConstraints<T>, limit?: number | null);
|
|
35
|
+
filter(...filters: FilterList<T>[]): this;
|
|
36
36
|
get unfilter(): this;
|
|
37
37
|
match(item: T): boolean;
|
|
38
|
-
sort(...sorts: SortList<
|
|
38
|
+
sort(...sorts: SortList<T>[]): this;
|
|
39
39
|
get unsort(): this;
|
|
40
40
|
rank(left: T, right: T): number;
|
|
41
41
|
after(item: T): this;
|
|
@@ -10,7 +10,7 @@ export type SortKeys<T extends Data> = SortKey<T> | ImmutableArray<SortKey<T>>;
|
|
|
10
10
|
/** Possible operator references. */
|
|
11
11
|
export type SortDirection = "ASC" | "DESC";
|
|
12
12
|
/** List of sorts in a flexible format. */
|
|
13
|
-
export type SortList<T extends Data> =
|
|
13
|
+
export type SortList<T extends Data> = SortKey<T> | SortConstraint<T> | Iterable<Nullish<SortKey<T> | SortConstraint<T>>>;
|
|
14
14
|
/** Sort a list of values. */
|
|
15
15
|
export declare class SortConstraint<T extends Data = Data> implements Constraint<T>, Rankable<T> {
|
|
16
16
|
readonly key: string;
|
|
@@ -21,5 +21,5 @@ export declare class SortConstraint<T extends Data = Data> implements Constraint
|
|
|
21
21
|
transform(items: Iterable<T>): Iterable<T>;
|
|
22
22
|
toString(): string;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
export declare function getSorts<T extends Data>(
|
|
24
|
+
/** Turn `SortList` into array of list of `SortConstraint` instances. */
|
|
25
|
+
export declare function getSorts<T extends Data>(list: SortList<T> | SortList<T>[]): Iterable<SortConstraint<T>>;
|
|
@@ -24,16 +24,17 @@ export class SortConstraint {
|
|
|
24
24
|
return this.sortKey;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
export function* getSorts(
|
|
29
|
-
if (typeof
|
|
30
|
-
yield new SortConstraint(
|
|
31
|
-
}
|
|
32
|
-
else if (
|
|
33
|
-
yield
|
|
34
|
-
}
|
|
35
|
-
else
|
|
36
|
-
for (const sort of
|
|
37
|
-
|
|
27
|
+
/** Turn `SortList` into array of list of `SortConstraint` instances. */
|
|
28
|
+
export function* getSorts(list) {
|
|
29
|
+
if (typeof list === "string") {
|
|
30
|
+
yield new SortConstraint(list);
|
|
31
|
+
}
|
|
32
|
+
else if (list instanceof SortConstraint) {
|
|
33
|
+
yield list;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
for (const sort of list)
|
|
37
|
+
if (sort)
|
|
38
|
+
yield* getSorts(sort);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -8,12 +8,12 @@ import { SortConstraint, SortList } from "./SortConstraint.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export interface Sortable<T extends Data> extends Rankable<T> {
|
|
10
10
|
/** Add one or more sorts to this sortable. */
|
|
11
|
-
sort(...keys: SortList<
|
|
11
|
+
sort(...keys: SortList<T>[]): this;
|
|
12
12
|
}
|
|
13
13
|
/** A set of sorts. */
|
|
14
|
-
export declare class SortConstraints<T extends Data = Data> extends Constraints<T, SortConstraint<
|
|
15
|
-
constructor(...sorts: SortList<
|
|
16
|
-
sort(...sorts: SortList<
|
|
14
|
+
export declare class SortConstraints<T extends Data = Data> extends Constraints<T, SortConstraint<T>> implements Sortable<T> {
|
|
15
|
+
constructor(...sorts: SortList<T>[]);
|
|
16
|
+
sort(...sorts: SortList<T>[]): this;
|
|
17
17
|
rank(left: T, right: T): number;
|
|
18
18
|
transform(items: Iterable<T>): Iterable<T>;
|
|
19
19
|
toString(): string;
|
package/db/Collection.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare class Collection<T extends Datas = Datas, K extends DataKey<T> =
|
|
|
43
43
|
readonly db: Database<T>;
|
|
44
44
|
readonly collection: K;
|
|
45
45
|
constructor(db: Database<T>, collection: K);
|
|
46
|
-
query(filters?: FilterList<
|
|
46
|
+
query(filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T, K>;
|
|
47
47
|
item(id: string): Item<T, K>;
|
|
48
48
|
change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
|
|
49
49
|
get(id: string): ItemValue<T[K]>;
|
|
@@ -57,7 +57,7 @@ export declare class AsyncCollection<T extends Datas = Datas, K extends DataKey<
|
|
|
57
57
|
readonly db: AsyncDatabase<T>;
|
|
58
58
|
readonly collection: K;
|
|
59
59
|
constructor(db: AsyncDatabase<T>, collection: K);
|
|
60
|
-
query(filters?: FilterList<
|
|
60
|
+
query(filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<T, K>;
|
|
61
61
|
item(id: string): AsyncItem<T, K>;
|
|
62
62
|
change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
|
|
63
63
|
get(id: string): Promise<ItemValue<T[K]>>;
|
package/db/Database.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare class Database<T extends Datas = Datas> extends BaseDatabase<T> {
|
|
|
45
45
|
readonly provider: Provider<T>;
|
|
46
46
|
constructor(provider: Provider<T>);
|
|
47
47
|
collection<K extends DataKey<T>>(collection: K): Collection<T, K>;
|
|
48
|
-
query<K extends DataKey<T>>(collection: K, filters?: FilterList<
|
|
48
|
+
query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T, K>;
|
|
49
49
|
item<K extends DataKey<T>>(collection: K, id: string): Item<T, K>;
|
|
50
50
|
change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T>;
|
|
51
51
|
get<K extends DataKey<T>>(collection: K, id: string): ItemValue<T[K]>;
|
|
@@ -59,7 +59,7 @@ export declare class AsyncDatabase<T extends Datas = Datas> extends BaseDatabase
|
|
|
59
59
|
readonly provider: AsyncProvider<T>;
|
|
60
60
|
constructor(provider: AsyncProvider<T>);
|
|
61
61
|
collection<K extends DataKey<T>>(collection: K): AsyncCollection<T, K>;
|
|
62
|
-
query<K extends DataKey<T>>(collection: K, filters?: FilterList<
|
|
62
|
+
query<K extends DataKey<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<T, K>;
|
|
63
63
|
item<K extends DataKey<T>>(collection: K, id: string): AsyncItem<T, K>;
|
|
64
64
|
change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): Promise<ItemChanges<T>>;
|
|
65
65
|
get<K extends DataKey<T>>(collection: K, id: string): Promise<ItemValue<T[K]>>;
|
package/db/Query.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends DataKey<T> =
|
|
|
73
73
|
export declare class Query<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseQuery<T, K> {
|
|
74
74
|
readonly db: Database<T>;
|
|
75
75
|
readonly collection: K;
|
|
76
|
-
constructor(db: Database<T>, collection: K, filters?: FilterList<
|
|
76
|
+
constructor(db: Database<T>, collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null);
|
|
77
77
|
get value(): ItemArray<T[K]>;
|
|
78
78
|
get count(): number;
|
|
79
79
|
get exists(): boolean;
|
|
@@ -89,7 +89,7 @@ export declare class Query<T extends Datas = Datas, K extends DataKey<T> = DataK
|
|
|
89
89
|
export declare class AsyncQuery<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> extends BaseQuery<T, K> {
|
|
90
90
|
readonly db: AsyncDatabase<T>;
|
|
91
91
|
readonly collection: K;
|
|
92
|
-
constructor(db: AsyncDatabase<T>, collection: K, filters?: FilterList<
|
|
92
|
+
constructor(db: AsyncDatabase<T>, collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null);
|
|
93
93
|
get value(): Promise<ItemArray<T[K]>>;
|
|
94
94
|
get count(): Promise<number>;
|
|
95
95
|
get exists(): Promise<boolean>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { orderBy as firestoreOrderBy, where as firestoreWhere, limit as firestoreLimit, increment as firestoreIncrement, arrayUnion as firestoreArrayUnion, arrayRemove as firestoreArrayRemove, deleteField as firestoreDeleteField, collection as firestoreCollection, doc as firestoreDocument, query as firestoreQuery, onSnapshot, addDoc, setDoc, updateDoc, deleteDoc, getDoc, getDocs, } from "firebase/firestore";
|
|
1
|
+
import { documentId as firestoreDocumentId, orderBy as firestoreOrderBy, where as firestoreWhere, limit as firestoreLimit, increment as firestoreIncrement, arrayUnion as firestoreArrayUnion, arrayRemove as firestoreArrayRemove, deleteField as firestoreDeleteField, collection as firestoreCollection, doc as firestoreDocument, query as firestoreQuery, onSnapshot, addDoc, setDoc, updateDoc, deleteDoc, getDoc, getDocs, } from "firebase/firestore";
|
|
2
2
|
import { LazyDeferredSequence } from "../../sequence/LazyDeferredSequence.js";
|
|
3
3
|
import { ArrayUpdate, DataUpdate, Increment, DictionaryUpdate, Delete, Update } from "../../update/index.js";
|
|
4
4
|
// Constants.
|
|
5
|
-
|
|
6
|
-
const ID = "__id__"; // Internal way Firestore Queries can reference the ID of the current document.
|
|
5
|
+
const ID = firestoreDocumentId();
|
|
7
6
|
// Map `Filter.types` to `WhereFilterOp`
|
|
8
7
|
const OPERATORS = {
|
|
9
8
|
IS: "==",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { orderBy as firestoreOrderBy, where as firestoreWhere, limit as firestoreLimit, increment as firestoreIncrement, arrayUnion as firestoreArrayUnion, arrayRemove as firestoreArrayRemove, deleteField as firestoreDeleteField, collection as firestoreCollection, doc as firestoreDocument, query as firestoreQuery, setDoc, addDoc, updateDoc, deleteDoc, getDoc, getDocs, } from "firebase/firestore/lite";
|
|
1
|
+
import { documentId as firestoreDocumentId, orderBy as firestoreOrderBy, where as firestoreWhere, limit as firestoreLimit, increment as firestoreIncrement, arrayUnion as firestoreArrayUnion, arrayRemove as firestoreArrayRemove, deleteField as firestoreDeleteField, collection as firestoreCollection, doc as firestoreDocument, query as firestoreQuery, setDoc, addDoc, updateDoc, deleteDoc, getDoc, getDocs, } from "firebase/firestore/lite";
|
|
2
2
|
import { UnsupportedError } from "../../error/UnsupportedError.js";
|
|
3
3
|
import { ArrayUpdate, DataUpdate, Increment, DictionaryUpdate, Delete, Update } from "../../update/index.js";
|
|
4
4
|
// Constants.
|
|
5
5
|
// const ID = "__name__"; // DH: `__name__` is the entire path of the document. `__id__` is just ID.
|
|
6
|
-
const ID = "__id__"; // Internal way Firestore Queries can reference the ID of the current document.
|
|
6
|
+
// const ID = "__id__"; // Internal way Firestore Queries can reference the ID of the current document.
|
|
7
|
+
const ID = firestoreDocumentId();
|
|
7
8
|
// Map `Filter.types` to `WhereFilterOp`
|
|
8
9
|
const OPERATORS = {
|
|
9
10
|
IS: "==",
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Firestore, FieldValue
|
|
1
|
+
import { Firestore, FieldValue, FieldPath } from "@google-cloud/firestore";
|
|
2
2
|
import { LazyDeferredSequence } from "../../sequence/LazyDeferredSequence.js";
|
|
3
3
|
import { ArrayUpdate, DataUpdate, Increment, DictionaryUpdate, Delete, Update } from "../../update/index.js";
|
|
4
4
|
// Constants.
|
|
5
|
-
|
|
6
|
-
const ID = "__id__"; // Internal way Firestore Queries can reference the ID of the current document.
|
|
5
|
+
const ID = FieldPath.documentId();
|
|
7
6
|
// Map `Filter.types` to `WhereFilterOp`
|
|
8
7
|
const OPERATORS = {
|
|
9
8
|
IS: "==",
|
|
@@ -53,11 +52,11 @@ function* _getFieldValues(updates, prefix = "") {
|
|
|
53
52
|
else if (update instanceof ArrayUpdate) {
|
|
54
53
|
if (update.adds.length) {
|
|
55
54
|
yield `${prefix}${key}`;
|
|
56
|
-
yield
|
|
55
|
+
yield FieldValue.arrayUnion(...update.adds);
|
|
57
56
|
}
|
|
58
57
|
if (update.deletes.length) {
|
|
59
58
|
yield `${prefix}${key}`;
|
|
60
|
-
yield
|
|
59
|
+
yield FieldValue.arrayRemove(...update.deletes);
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
else {
|
|
@@ -65,9 +64,9 @@ function* _getFieldValues(updates, prefix = "") {
|
|
|
65
64
|
if (!(update instanceof Update))
|
|
66
65
|
yield update;
|
|
67
66
|
else if (update instanceof Delete)
|
|
68
|
-
yield
|
|
67
|
+
yield FieldValue.delete();
|
|
69
68
|
else if (update instanceof Increment)
|
|
70
|
-
yield
|
|
69
|
+
yield FieldValue.increment(update.amount);
|
|
71
70
|
else
|
|
72
71
|
yield update.transform();
|
|
73
72
|
}
|
package/markup/regexp.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare function getLineRegExp(content?: PossibleRegExp, end?: PossibleRe
|
|
|
41
41
|
* - If we could use a negative lookbehind for the start of the word we wouldn't need to create a function that offsets the start.
|
|
42
42
|
*/
|
|
43
43
|
export declare class WordRegExp extends RegExp {
|
|
44
|
-
constructor(pattern: string);
|
|
44
|
+
constructor(pattern: string, flags?: string);
|
|
45
45
|
exec(input: string): RegExpExecArray | null;
|
|
46
46
|
test(input: string): boolean;
|
|
47
47
|
}
|
package/markup/regexp.js
CHANGED
|
@@ -26,8 +26,8 @@ export function getLineRegExp(content = LINE_REGEXP, end = LINE_END_REGEXP, star
|
|
|
26
26
|
* - If we could use a negative lookbehind for the start of the word we wouldn't need to create a function that offsets the start.
|
|
27
27
|
*/
|
|
28
28
|
export class WordRegExp extends RegExp {
|
|
29
|
-
constructor(pattern) {
|
|
30
|
-
super(`(?<lookbehind>^|[^\\p{L}\\p{N}])${pattern}(?![\\p{L}\\p{N}])
|
|
29
|
+
constructor(pattern, flags) {
|
|
30
|
+
super(`(?<lookbehind>^|[^\\p{L}\\p{N}])${pattern}(?![\\p{L}\\p{N}])`, flags);
|
|
31
31
|
}
|
|
32
32
|
exec(input) {
|
|
33
33
|
var _a;
|
package/markup/rule.d.ts
CHANGED
|
@@ -36,35 +36,33 @@ export declare abstract class MarkupRule {
|
|
|
36
36
|
abstract render(props: Data | undefined, options: MarkupOptions): JSXElement;
|
|
37
37
|
}
|
|
38
38
|
export declare class RegExpMarkupRule extends MarkupRule {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
constructor(
|
|
42
|
-
|
|
39
|
+
readonly regexp: RegExp;
|
|
40
|
+
readonly render: (props: Data, options: MarkupOptions) => JSXElement;
|
|
41
|
+
constructor(regexp: RegExp, //
|
|
42
|
+
render: (props: Data, options: MarkupOptions) => JSXElement, contexts: ImmutableArray<string>, subcontext?: string | null, priority?: number);
|
|
43
43
|
match(input: string): MarkupRuleMatch | null;
|
|
44
|
-
render(props: Data, options: MarkupOptions): JSXElement;
|
|
45
44
|
}
|
|
46
45
|
export declare class NamedRegExpMarkupRule<T extends NamedRegExpData> extends MarkupRule {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
|
|
46
|
+
readonly regexp: NamedRegExp<T>;
|
|
47
|
+
readonly render: (props: T, options: MarkupOptions) => JSXElement;
|
|
48
|
+
constructor(regexp: NamedRegExp<T>, //
|
|
49
|
+
render: (props: T, options: MarkupOptions) => JSXElement, contexts: ImmutableArray<string>, subcontext?: string | null, priority?: number);
|
|
51
50
|
match(input: string): NamedRegExpArray<T> | null;
|
|
52
|
-
render(props: T, options: MarkupOptions): JSXElement;
|
|
53
51
|
}
|
|
54
52
|
export declare class LinkRegExpMarkupRule extends MarkupRule {
|
|
55
|
-
readonly
|
|
53
|
+
readonly regexp: NamedRegExp<{
|
|
56
54
|
title?: string;
|
|
57
55
|
href: string;
|
|
58
56
|
}>;
|
|
59
|
-
readonly
|
|
57
|
+
readonly render: (props: {
|
|
60
58
|
title: string;
|
|
61
59
|
href: string;
|
|
62
60
|
}, options: MarkupOptions) => JSXElement;
|
|
63
|
-
constructor(
|
|
61
|
+
constructor(regexp: NamedRegExp<{
|
|
64
62
|
title?: string;
|
|
65
63
|
href: string;
|
|
66
64
|
}>, //
|
|
67
|
-
|
|
65
|
+
render: (props: {
|
|
68
66
|
title: string;
|
|
69
67
|
href: string;
|
|
70
68
|
}, options: MarkupOptions) => JSXElement, contexts: ImmutableArray<string>, subcontext?: string | null, priority?: number);
|
|
@@ -72,9 +70,5 @@ export declare class LinkRegExpMarkupRule extends MarkupRule {
|
|
|
72
70
|
title: string;
|
|
73
71
|
href: string;
|
|
74
72
|
}> | null;
|
|
75
|
-
render(props: {
|
|
76
|
-
title: string;
|
|
77
|
-
href: string;
|
|
78
|
-
}, options: MarkupOptions): JSXElement<import("../util/jsx.js").JSXProps>;
|
|
79
73
|
}
|
|
80
74
|
export type MarkupRules = MarkupRule[];
|
package/markup/rule.js
CHANGED
|
@@ -8,45 +8,39 @@ export class MarkupRule {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export class RegExpMarkupRule extends MarkupRule {
|
|
11
|
-
constructor(
|
|
12
|
-
|
|
11
|
+
constructor(regexp, //
|
|
12
|
+
render, contexts, subcontext, priority) {
|
|
13
13
|
super(contexts, subcontext, priority);
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
14
|
+
this.regexp = regexp;
|
|
15
|
+
this.render = render;
|
|
16
16
|
}
|
|
17
17
|
match(input) {
|
|
18
|
-
return this.
|
|
19
|
-
}
|
|
20
|
-
render(props, options) {
|
|
21
|
-
return this._render(props, options);
|
|
18
|
+
return this.regexp.exec(input);
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
export class NamedRegExpMarkupRule extends MarkupRule {
|
|
25
|
-
constructor(
|
|
26
|
-
|
|
22
|
+
constructor(regexp, //
|
|
23
|
+
render, contexts, subcontext, priority) {
|
|
27
24
|
super(contexts, subcontext, priority);
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
25
|
+
this.regexp = regexp;
|
|
26
|
+
this.render = render;
|
|
30
27
|
}
|
|
31
28
|
match(input) {
|
|
32
|
-
return this.
|
|
33
|
-
}
|
|
34
|
-
render(props, options) {
|
|
35
|
-
return this._render(props, options);
|
|
29
|
+
return this.regexp.exec(input);
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
32
|
export class LinkRegExpMarkupRule extends MarkupRule {
|
|
39
|
-
constructor(
|
|
40
|
-
|
|
33
|
+
constructor(regexp, //
|
|
34
|
+
render, contexts, subcontext, priority) {
|
|
41
35
|
super(contexts, subcontext, priority);
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
36
|
+
this.regexp = regexp;
|
|
37
|
+
this.render = render;
|
|
44
38
|
}
|
|
45
39
|
// Validates that the link is a valid URL (using `getOptionalURL()` to resolve relative links relative to `options.url`).
|
|
46
40
|
// Validates that the link's URL scheme is in the `options.schemes` whitelist (defaults to `http` and `https`).
|
|
47
41
|
// Generates a default title for the link using `formatURL()` (e.g. `shax.com/my/dir`).
|
|
48
42
|
match(input, { schemes, url: base }) {
|
|
49
|
-
const match = this.
|
|
43
|
+
const match = this.regexp.exec(input);
|
|
50
44
|
if (match) {
|
|
51
45
|
const { 0: first, index, groups } = match;
|
|
52
46
|
const { href, title } = groups;
|
|
@@ -57,7 +51,4 @@ export class LinkRegExpMarkupRule extends MarkupRule {
|
|
|
57
51
|
}
|
|
58
52
|
return null;
|
|
59
53
|
}
|
|
60
|
-
render(props, options) {
|
|
61
|
-
return this._render(props, options);
|
|
62
|
-
}
|
|
63
54
|
}
|
package/markup/rules.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { JSXElement } from "../util/jsx.js";
|
|
2
|
-
import { NamedRegExp } from "../util/regexp.js";
|
|
3
2
|
import type { MarkupOptions } from "./options.js";
|
|
4
3
|
import { LinkRegExpMarkupRule, MarkupRules, NamedRegExpMarkupRule, RegExpMarkupRule } from "./rule.js";
|
|
5
4
|
/**
|
|
@@ -60,10 +59,6 @@ export declare function renderLinkRule({ href, title }: {
|
|
|
60
59
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
61
60
|
* - For security only schemes that appear in `options.schemes` will match (defaults to `http:` and `https:`).
|
|
62
61
|
*/
|
|
63
|
-
export declare const URL_REGEXP: NamedRegExp<{
|
|
64
|
-
title?: string;
|
|
65
|
-
href: string;
|
|
66
|
-
}>;
|
|
67
62
|
export declare const URL_RULE: LinkRegExpMarkupRule;
|
|
68
63
|
/**
|
|
69
64
|
* Markdown-style link.
|
|
@@ -73,10 +68,6 @@ export declare const URL_RULE: LinkRegExpMarkupRule;
|
|
|
73
68
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
74
69
|
* - For security only `http://` or `https://` links will work (if invalid the unparsed text will be returned).
|
|
75
70
|
*/
|
|
76
|
-
export declare const LINK_REGEXP: NamedRegExp<{
|
|
77
|
-
title: string;
|
|
78
|
-
href: string;
|
|
79
|
-
}>;
|
|
80
71
|
export declare const LINK_RULE: LinkRegExpMarkupRule;
|
|
81
72
|
/**
|
|
82
73
|
* Inline code.
|
package/markup/rules.js
CHANGED
|
@@ -150,8 +150,8 @@ export function renderLinkRule({ href, title }, { rel }) {
|
|
|
150
150
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
151
151
|
* - For security only schemes that appear in `options.schemes` will match (defaults to `http:` and `https:`).
|
|
152
152
|
*/
|
|
153
|
-
export const
|
|
154
|
-
|
|
153
|
+
export const URL_RULE = new LinkRegExpMarkupRule(getRegExp(/(?<href>[a-z]+:[-$_@.&!*,=;/#?:%a-zA-Z0-9]+)(?: +(?:\((?<title>[^)]*?)\)))?/), //
|
|
154
|
+
renderLinkRule, ["inline", "list"], "link");
|
|
155
155
|
/**
|
|
156
156
|
* Markdown-style link.
|
|
157
157
|
* - Link in standard Markdown format, e.g. `[Google Maps](http://google.com/maps)`
|
|
@@ -160,8 +160,8 @@ export const URL_RULE = new LinkRegExpMarkupRule(URL_REGEXP, renderLinkRule, ["i
|
|
|
160
160
|
* - If link is not valid (using `new URL(url)` then unparsed text will be returned.
|
|
161
161
|
* - For security only `http://` or `https://` links will work (if invalid the unparsed text will be returned).
|
|
162
162
|
*/
|
|
163
|
-
export const
|
|
164
|
-
|
|
163
|
+
export const LINK_RULE = new LinkRegExpMarkupRule(getRegExp(/\[(?<title>[^\]]*?)\]\((?<href>[^)]*?)\)/), //
|
|
164
|
+
renderLinkRule, ["inline", "list"], "link");
|
|
165
165
|
/**
|
|
166
166
|
* Inline code.
|
|
167
167
|
* - Text surrounded by one or more "`" backtick tilde characters.
|
package/package.json
CHANGED
package/react/useQuery.js
CHANGED
|
@@ -70,7 +70,7 @@ export class QueryState extends State {
|
|
|
70
70
|
this.busy.set(true);
|
|
71
71
|
try {
|
|
72
72
|
const items = await this.ref.value;
|
|
73
|
-
this._hasMore = items.length
|
|
73
|
+
this._hasMore = items.length >= this.limit; // If the query returned {limit} or more items, we can assume there are more items waiting to be queried.
|
|
74
74
|
this.set(items);
|
|
75
75
|
}
|
|
76
76
|
catch (thrown) {
|
|
@@ -92,9 +92,11 @@ export class QueryState extends State {
|
|
|
92
92
|
async _loadMore() {
|
|
93
93
|
this.busy.set(true);
|
|
94
94
|
try {
|
|
95
|
-
const
|
|
95
|
+
const last = this.lastValue;
|
|
96
|
+
const query = last ? this.ref.after(last) : this.ref;
|
|
97
|
+
const items = await query.value;
|
|
96
98
|
this.set([...this.value, ...items]);
|
|
97
|
-
this._hasMore = items.length
|
|
99
|
+
this._hasMore = items.length >= this.limit; // If the query returned {limit} or more items, we can assume there are more items waiting to be queried.
|
|
98
100
|
}
|
|
99
101
|
catch (thrown) {
|
|
100
102
|
this.next.reject(thrown);
|
package/state/State.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Validatable } from "../util/validate.js";
|
|
1
2
|
import { Dispatch, Handler, Stop } from "../util/function.js";
|
|
2
3
|
import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
3
4
|
/** Any `State` instance. */
|
|
@@ -12,7 +13,7 @@ export type AnyState = State<any>;
|
|
|
12
13
|
* - To set the state to be loading, use the `State.NOVALUE` constant or a `Promise` value.
|
|
13
14
|
* - To set the state to an explicit value, use that value or another `State` instance with a value.
|
|
14
15
|
* */
|
|
15
|
-
export declare class State<T> implements AsyncIterable<T> {
|
|
16
|
+
export declare class State<T> implements AsyncIterable<T>, Validatable<T> {
|
|
16
17
|
/** The `NOVALUE` symbol indicates no value has been received by a `State` instance. */
|
|
17
18
|
static readonly NOVALUE: unique symbol;
|
|
18
19
|
/** Deferred sequence this state uses to issue values as they change. */
|
|
@@ -30,7 +31,7 @@ export declare class State<T> implements AsyncIterable<T> {
|
|
|
30
31
|
/** Is there a current value, or is it still loading. */
|
|
31
32
|
get loading(): boolean;
|
|
32
33
|
/** Set the value of the state. */
|
|
33
|
-
set(
|
|
34
|
+
set(next: T): void;
|
|
34
35
|
/** Set the value of the state as values are pulled from a sequence. */
|
|
35
36
|
through(sequence: AsyncIterable<T>): AsyncIterable<T>;
|
|
36
37
|
/** Pull values from a source sequence until the returned stop function is called. */
|
|
@@ -38,6 +39,8 @@ export declare class State<T> implements AsyncIterable<T> {
|
|
|
38
39
|
/** Push values to another state or callback to this state until the returned stop function is called. */
|
|
39
40
|
to(target: Dispatch<[T]>, onError?: Handler): Stop;
|
|
40
41
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
42
|
+
/** Validate data set on this state. */
|
|
43
|
+
validate(value: T): T;
|
|
41
44
|
}
|
|
42
45
|
/** Is an unknown value a `State` instance. */
|
|
43
46
|
export declare const isState: <T extends AnyState>(v: unknown) => v is T;
|
package/state/State.js
CHANGED
|
@@ -28,8 +28,12 @@ export class State {
|
|
|
28
28
|
}
|
|
29
29
|
/** State is initiated with an initial state. */
|
|
30
30
|
constructor(initial = State.NOVALUE, next = new DeferredSequence()) {
|
|
31
|
-
this._value =
|
|
32
|
-
this._time =
|
|
31
|
+
this._value = State.NOVALUE;
|
|
32
|
+
this._time = null;
|
|
33
|
+
if (initial !== State.NOVALUE) {
|
|
34
|
+
this._value = this.validate(initial);
|
|
35
|
+
this._time = Date.now();
|
|
36
|
+
}
|
|
33
37
|
this.next = next;
|
|
34
38
|
}
|
|
35
39
|
/** Is there a current value, or is it still loading. */
|
|
@@ -37,7 +41,8 @@ export class State {
|
|
|
37
41
|
return this._value === State.NOVALUE;
|
|
38
42
|
}
|
|
39
43
|
/** Set the value of the state. */
|
|
40
|
-
set(
|
|
44
|
+
set(next) {
|
|
45
|
+
const value = this.validate(next);
|
|
41
46
|
if (value !== this._value) {
|
|
42
47
|
this._value = value;
|
|
43
48
|
this._time = Date.now();
|
|
@@ -67,6 +72,10 @@ export class State {
|
|
|
67
72
|
yield this.value;
|
|
68
73
|
yield* this.next;
|
|
69
74
|
}
|
|
75
|
+
/** Validate data set on this state. */
|
|
76
|
+
validate(value) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
70
79
|
}
|
|
71
80
|
/** The `NOVALUE` symbol indicates no value has been received by a `State` instance. */
|
|
72
81
|
State.NOVALUE = Symbol("shelving/State.NOVALUE");
|
package/util/class.d.ts
CHANGED
|
@@ -4,9 +4,8 @@ export type Constructor<T, A extends Arguments> = new (...args: A) => T;
|
|
|
4
4
|
/** Any function arguments (designed for use with `extends Arguments` guards). */
|
|
5
5
|
export type AnyConstructor = new (...args: any) => any;
|
|
6
6
|
/** Class prototype that can be used with `instanceof` (string name, as per `Function`, and a prototype field matching the object). */
|
|
7
|
-
export type Class<T =
|
|
8
|
-
|
|
9
|
-
};
|
|
7
|
+
export type Class<T> = new (...args: any) => T;
|
|
8
|
+
export declare const abc: Class<String>;
|
|
10
9
|
/** Is a given value a class constructor? */
|
|
11
10
|
export declare const isConstructor: <T extends AnyConstructor>(v: unknown) => v is T;
|
|
12
11
|
/** Is a value an instance of a class? */
|
package/util/class.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { AssertionError } from "../error/AssertionError.js";
|
|
3
3
|
import { assertFunction } from "./function.js";
|
|
4
4
|
import { debug } from "./debug.js";
|
|
5
|
+
export const abc = String;
|
|
5
6
|
/** Is a given value a class constructor? */
|
|
6
7
|
export const isConstructor = (v) => typeof v === "function" && v.toString().startsWith("class");
|
|
7
8
|
/** Is a value an instance of a class? */
|
package/util/hydrate.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Transformable } from "./transform.js";
|
|
|
5
5
|
* A set of hydrations describes a set of string keys and the class constructor to be dehydrated and rehydrated.
|
|
6
6
|
* - We can't use `class.name` because we don't know that the name of the class will survive minification.
|
|
7
7
|
*/
|
|
8
|
-
export type Hydrations = ImmutableDictionary<Class
|
|
8
|
+
export type Hydrations = ImmutableDictionary<Class<unknown>>;
|
|
9
9
|
/**
|
|
10
10
|
* Deeply dehydrate a class instance based on a set of `Hydrations`
|
|
11
11
|
* - Dehydration allows you to pass class instances from a server back to a client.
|
package/util/regexp.d.ts
CHANGED
|
@@ -6,16 +6,6 @@ export declare const ALWAYS_REGEXP: RegExp;
|
|
|
6
6
|
export declare const NEVER_REGEXP: RegExp;
|
|
7
7
|
/** Things that can be convert to a regular expression. */
|
|
8
8
|
export type PossibleRegExp = string | RegExp;
|
|
9
|
-
/** Is an unknown value a `RegExp` instance? */
|
|
10
|
-
export declare const isRegExp: <T extends RegExp>(v: unknown) => v is T;
|
|
11
|
-
/** Assert that an unknown value is a `RegExp` instance. */
|
|
12
|
-
export declare function assertRegExp<T extends RegExp>(v: T | unknown): asserts v is T;
|
|
13
|
-
/** Convert a string to a regular expression that matches that string. */
|
|
14
|
-
export declare const getRegExp: (pattern: PossibleRegExp, flags?: string) => RegExp;
|
|
15
|
-
/** Convert a regular expression to its string source. */
|
|
16
|
-
export declare const getRegExpSource: (regexp: PossibleRegExp) => string;
|
|
17
|
-
/** Escape special characters in a string regular expression. */
|
|
18
|
-
export declare const escapeRegExp: (pattern: string) => string;
|
|
19
9
|
/** Set of named match groups from a regular expression. */
|
|
20
10
|
export type NamedRegExpData = {
|
|
21
11
|
[named: string]: string;
|
|
@@ -28,6 +18,19 @@ export interface NamedRegExpArray<T extends NamedRegExpData = NamedRegExpData> e
|
|
|
28
18
|
export interface NamedRegExp<T extends NamedRegExpData = NamedRegExpData> extends RegExp {
|
|
29
19
|
exec(input: string): NamedRegExpArray<T> | null;
|
|
30
20
|
}
|
|
21
|
+
/** Is an unknown value a `RegExp` instance? */
|
|
22
|
+
export declare const isRegExp: <T extends RegExp>(v: unknown) => v is T;
|
|
23
|
+
/** Assert that an unknown value is a `RegExp` instance. */
|
|
24
|
+
export declare function assertRegExp<T extends RegExp>(v: T | unknown): asserts v is T;
|
|
25
|
+
/** Convert a string to a regular expression that matches that string. */
|
|
26
|
+
export declare function getRegExp<T extends string>(pattern: `(?<${T}>${string})`, flags?: string): NamedRegExp<{
|
|
27
|
+
[K in T]: string;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function getRegExp(pattern: PossibleRegExp, flags?: string): RegExp;
|
|
30
|
+
/** Convert a regular expression to its string source. */
|
|
31
|
+
export declare const getRegExpSource: (regexp: PossibleRegExp) => string;
|
|
32
|
+
/** Escape special characters in a string regular expression. */
|
|
33
|
+
export declare const escapeRegExp: (pattern: string) => string;
|
|
31
34
|
/** Create regular expression that matches any of a list of other expressions. */
|
|
32
35
|
export declare function getAnyRegExp(patterns: Iterable<PossibleRegExp> & NotString, flags?: string): RegExp;
|
|
33
36
|
/** Create regular expression that matches all of a list of other expressions. */
|
package/util/regexp.js
CHANGED
|
@@ -11,8 +11,9 @@ export function assertRegExp(v) {
|
|
|
11
11
|
if (!(v instanceof RegExp))
|
|
12
12
|
throw new AssertionError("Must be regular expression", v);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export function getRegExp(pattern, flags) {
|
|
15
|
+
return typeof pattern === "string" ? new RegExp(pattern, flags) : pattern;
|
|
16
|
+
}
|
|
16
17
|
/** Convert a regular expression to its string source. */
|
|
17
18
|
export const getRegExpSource = (regexp) => (typeof regexp === "string" ? regexp : regexp.source);
|
|
18
19
|
/** Escape special characters in a string regular expression. */
|