shelving 1.86.0 → 1.86.1
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.d.ts +2 -2
- package/constraint/Constraints.js +4 -4
- package/constraint/FilterConstraint.d.ts +4 -4
- package/constraint/FilterConstraint.js +17 -17
- package/constraint/SortConstraint.d.ts +4 -4
- package/constraint/SortConstraint.js +3 -3
- package/db/Change.d.ts +4 -4
- package/db/Item.d.ts +4 -4
- package/markup/options.d.ts +1 -1
- package/markup/regexp.d.ts +2 -2
- package/markup/rules.d.ts +2 -2
- package/package.json +13 -13
- package/react/useItem.js +8 -8
- package/react/useQuery.js +28 -28
- package/schema/AllowSchema.d.ts +4 -4
- package/schema/AllowSchema.js +3 -3
- package/schema/ArraySchema.d.ts +1 -1
- package/schema/BooleanSchema.d.ts +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/LinkSchema.d.ts +1 -1
- package/schema/NumberSchema.d.ts +1 -1
- package/schema/Schema.d.ts +1 -1
- package/schema/StringSchema.d.ts +3 -3
- package/schema/ThroughSchema.d.ts +1 -1
- package/schema/TimeSchema.d.ts +1 -1
- package/state/State.d.ts +1 -1
- package/state/State.js +6 -6
- package/test/basics.d.ts +2 -2
- package/test/index.d.ts +1 -1
- package/test/people.d.ts +2 -2
- package/update/ArrayUpdate.js +5 -5
- package/update/DataUpdate.d.ts +1 -1
- package/update/DataUpdate.js +4 -4
- package/update/DictionaryUpdate.d.ts +1 -1
- package/update/DictionaryUpdate.js +4 -4
- package/util/array.d.ts +4 -4
- package/util/async.js +8 -8
- package/util/class.d.ts +3 -3
- package/util/color.d.ts +2 -2
- package/util/color.js +6 -6
- package/util/data.d.ts +7 -7
- package/util/date.d.ts +3 -3
- package/util/dictionary.d.ts +5 -5
- package/util/duration.d.ts +17 -0
- package/util/duration.js +52 -0
- package/util/entry.d.ts +3 -3
- package/util/function.d.ts +8 -8
- package/util/hydrate.d.ts +2 -2
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
- package/util/iterate.d.ts +1 -1
- package/util/jsx.d.ts +3 -3
- package/util/lazy.d.ts +1 -1
- package/util/map.d.ts +15 -19
- package/util/map.js +11 -13
- package/util/match.d.ts +2 -2
- package/util/merge.d.ts +1 -1
- package/util/null.d.ts +1 -1
- package/util/number.d.ts +4 -2
- package/util/number.js +8 -6
- package/util/object.d.ts +11 -11
- package/util/regexp.d.ts +2 -2
- package/util/set.d.ts +4 -4
- package/util/sort.d.ts +2 -2
- package/util/string.d.ts +1 -1
- package/util/template.d.ts +2 -2
- package/util/time.d.ts +2 -2
- package/util/time.js +3 -3
- package/util/transform.d.ts +5 -5
- package/util/units.d.ts +39 -50
- package/util/units.js +36 -74
- package/util/url.d.ts +2 -2
- package/util/validate.d.ts +5 -5
package/api/Resource.d.ts
CHANGED
|
@@ -27,9 +27,9 @@ export declare class Resource<P = unknown, R = void> implements Validatable<R> {
|
|
|
27
27
|
validate(unsafeResult: unknown): R;
|
|
28
28
|
}
|
|
29
29
|
/** Extract the payload type from a `Resource`. */
|
|
30
|
-
export
|
|
30
|
+
export type PayloadType<X extends Resource> = X extends Resource<infer Y, unknown> ? Y : never;
|
|
31
31
|
/** Extract the result type from a `Resource`. */
|
|
32
|
-
export
|
|
32
|
+
export type ResourceType<X extends Resource> = X extends Resource<unknown, infer Y> ? Y : never;
|
|
33
33
|
/**
|
|
34
34
|
* Shortcut to create a new `Resource` (consistent with `Schema` shortcuts.
|
|
35
35
|
* - Sets `undefined` as the default type for payload and result.
|
|
@@ -2,10 +2,6 @@ import { withArrayItems, omitArrayItems } from "../util/array.js";
|
|
|
2
2
|
import { Constraint } from "./Constraint.js";
|
|
3
3
|
/** Type of Rule that is powered by several sub-constraints (e.g. `Filters` and `Sorts` and `Query` itself extend this). */
|
|
4
4
|
export class Constraints extends Constraint {
|
|
5
|
-
constructor(...constraints) {
|
|
6
|
-
super();
|
|
7
|
-
this._constraints = constraints;
|
|
8
|
-
}
|
|
9
5
|
/** Get the first constraint. */
|
|
10
6
|
get first() {
|
|
11
7
|
return this._constraints[0];
|
|
@@ -18,6 +14,10 @@ export class Constraints extends Constraint {
|
|
|
18
14
|
get size() {
|
|
19
15
|
return this._constraints.length;
|
|
20
16
|
}
|
|
17
|
+
constructor(...constraints) {
|
|
18
|
+
super();
|
|
19
|
+
this._constraints = constraints;
|
|
20
|
+
}
|
|
21
21
|
/** Clone this set of constraints but add additional constraints. */
|
|
22
22
|
with(...constraints) {
|
|
23
23
|
const _constraints = withArrayItems(this._constraints, ...constraints);
|
|
@@ -4,11 +4,11 @@ import { ImmutableArray } from "../util/array.js";
|
|
|
4
4
|
import { Matchable } from "../util/match.js";
|
|
5
5
|
import type { Constraint } from "./Constraint.js";
|
|
6
6
|
/** Possible operator references. */
|
|
7
|
-
export
|
|
7
|
+
export type FilterOperator = "IS" | "NOT" | "IN" | "OUT" | "CONTAINS" | "LT" | "LTE" | "GT" | "GTE";
|
|
8
8
|
/** Format that allows filters to be specified as a string, e.g. `!name` means `name is not` and `age>` means `age is more than` and `tags[]` means `tags array contains` */
|
|
9
|
-
export
|
|
9
|
+
export type FilterKey<T extends Data> = DataKey<T> | `${DataKey<T>}` | `!${DataKey<T>}` | `${DataKey<T>}[]` | `${DataKey<T>}<` | `${DataKey<T>}<=` | `${DataKey<T>}>` | `${DataKey<T>}>=`;
|
|
10
10
|
/** Format that allows multiple filters to be specified as a plain object. */
|
|
11
|
-
export
|
|
11
|
+
export type FilterProps<T extends Data> = {
|
|
12
12
|
[K in DataKey<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
|
|
13
13
|
} & {
|
|
14
14
|
[K in DataKey<T> as `${K}[]`]?: Required<T>[K] extends ImmutableArray<infer X> ? X : never;
|
|
@@ -16,7 +16,7 @@ export declare 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
|
|
19
|
+
export type FilterList<T extends Data> = Nullish<FilterProps<T> | FilterConstraint<T>> | Iterable<FilterList<T>>;
|
|
20
20
|
/**
|
|
21
21
|
* Filter: filters a list of data.
|
|
22
22
|
*
|
|
@@ -21,6 +21,23 @@ const MATCHERS = {
|
|
|
21
21
|
* @param value Value the specified property should be matched against.
|
|
22
22
|
*/
|
|
23
23
|
export class FilterConstraint {
|
|
24
|
+
get filterKey() {
|
|
25
|
+
const { operator, key } = this;
|
|
26
|
+
if (operator === "NOT" || operator === "OUT")
|
|
27
|
+
return `!${key}`;
|
|
28
|
+
else if (operator === "CONTAINS")
|
|
29
|
+
return `${key}[]`;
|
|
30
|
+
else if (operator === "LT")
|
|
31
|
+
return `${key}<`;
|
|
32
|
+
else if (operator === "LTE")
|
|
33
|
+
return `${key}<=`;
|
|
34
|
+
else if (operator === "GT")
|
|
35
|
+
return `${key}>`;
|
|
36
|
+
else if (operator === "GTE")
|
|
37
|
+
return `${key}>=`;
|
|
38
|
+
else
|
|
39
|
+
return key;
|
|
40
|
+
}
|
|
24
41
|
constructor(filterKey, value) {
|
|
25
42
|
if (filterKey.startsWith("!")) {
|
|
26
43
|
this.key = filterKey.slice(1);
|
|
@@ -52,23 +69,6 @@ export class FilterConstraint {
|
|
|
52
69
|
}
|
|
53
70
|
this.value = value;
|
|
54
71
|
}
|
|
55
|
-
get filterKey() {
|
|
56
|
-
const { operator, key } = this;
|
|
57
|
-
if (operator === "NOT" || operator === "OUT")
|
|
58
|
-
return `!${key}`;
|
|
59
|
-
else if (operator === "CONTAINS")
|
|
60
|
-
return `${key}[]`;
|
|
61
|
-
else if (operator === "LT")
|
|
62
|
-
return `${key}<`;
|
|
63
|
-
else if (operator === "LTE")
|
|
64
|
-
return `${key}<=`;
|
|
65
|
-
else if (operator === "GT")
|
|
66
|
-
return `${key}>`;
|
|
67
|
-
else if (operator === "GTE")
|
|
68
|
-
return `${key}>=`;
|
|
69
|
-
else
|
|
70
|
-
return key;
|
|
71
|
-
}
|
|
72
72
|
match(item) {
|
|
73
73
|
return MATCHERS[this.operator](item[this.key], this.value);
|
|
74
74
|
}
|
|
@@ -4,13 +4,13 @@ import type { Nullish } from "../util/null.js";
|
|
|
4
4
|
import { Rankable } from "../util/sort.js";
|
|
5
5
|
import type { Constraint } from "./Constraint.js";
|
|
6
6
|
/** Format that allows sorts to be set as a plain string, e.g. `name` sorts by name in ascending order and `!date` sorts by date in descending order. */
|
|
7
|
-
export
|
|
7
|
+
export type SortKey<T extends Data> = DataKey<T> | `${DataKey<T>}` | `!${DataKey<T>}`;
|
|
8
8
|
/** One or more sort keys. */
|
|
9
|
-
export
|
|
9
|
+
export type SortKeys<T extends Data> = SortKey<T> | ImmutableArray<SortKey<T>>;
|
|
10
10
|
/** Possible operator references. */
|
|
11
|
-
export
|
|
11
|
+
export type SortDirection = "ASC" | "DESC";
|
|
12
12
|
/** List of sorts in a flexible format. */
|
|
13
|
-
export
|
|
13
|
+
export type SortList<T extends Data> = Nullish<SortKeys<T> | SortConstraint<T> | Iterable<SortList<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;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { rank, rankAsc, rankDesc, sortItems } from "../util/sort.js";
|
|
2
2
|
/** Sort a list of values. */
|
|
3
3
|
export class SortConstraint {
|
|
4
|
+
get sortKey() {
|
|
5
|
+
return `"${this.direction === "DESC" ? "!" : ""}${this.key}"`;
|
|
6
|
+
}
|
|
4
7
|
constructor(sortKey) {
|
|
5
8
|
if (sortKey.startsWith("!")) {
|
|
6
9
|
this.key = sortKey.slice(1);
|
|
@@ -11,9 +14,6 @@ export class SortConstraint {
|
|
|
11
14
|
this.direction = "ASC";
|
|
12
15
|
}
|
|
13
16
|
}
|
|
14
|
-
get sortKey() {
|
|
15
|
-
return `"${this.direction === "DESC" ? "!" : ""}${this.key}"`;
|
|
16
|
-
}
|
|
17
17
|
rank(left, right) {
|
|
18
18
|
return rank(left[this.key], this.direction === "ASC" ? rankAsc : rankDesc, right[this.key]);
|
|
19
19
|
}
|
package/db/Change.d.ts
CHANGED
|
@@ -33,13 +33,13 @@ export interface DeleteChange<T extends Datas, K extends DataKey<T> = DataKey<T>
|
|
|
33
33
|
readonly id: string;
|
|
34
34
|
}
|
|
35
35
|
/** Set, update, or delete change on an item. */
|
|
36
|
-
export
|
|
36
|
+
export type ItemChange<T extends Datas, K extends DataKey<T> = DataKey<T>> = SetChange<T, K> | UpdateChange<T, K> | DeleteChange<T, K>;
|
|
37
37
|
/** Array of item changes. */
|
|
38
|
-
export
|
|
38
|
+
export type ItemChanges<T extends Datas, K extends DataKey<T> = DataKey<T>> = ImmutableArray<ItemChange<T, K>>;
|
|
39
39
|
/** Write change on an item. */
|
|
40
|
-
export
|
|
40
|
+
export type WriteChange<T extends Datas, K extends DataKey<T> = DataKey<T>> = ItemChange<T, K> | AddChange<T, K>;
|
|
41
41
|
/** Array of write changes. */
|
|
42
|
-
export
|
|
42
|
+
export type WriteChanges<T extends Datas, K extends DataKey<T> = DataKey<T>> = ImmutableArray<WriteChange<T, K>>;
|
|
43
43
|
/** Apply a set of changes to a synchronous provider. */
|
|
44
44
|
export declare function changeProvider<T extends Datas, K extends DataKey<T>>(provider: Provider<T>, ...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
|
|
45
45
|
/** Apply a set of changes to an asynchronous provider. */
|
package/db/Item.d.ts
CHANGED
|
@@ -7,15 +7,15 @@ import type { DeleteChange, SetChange, UpdateChange } from "./Change.js";
|
|
|
7
7
|
import type { AsyncQuery, Query } from "./Query.js";
|
|
8
8
|
import type { AsyncDatabase, Database } from "./Database.js";
|
|
9
9
|
/** Item data with a string ID that uniquely identifies it. */
|
|
10
|
-
export
|
|
10
|
+
export type ItemData<T extends Data = Data> = T & {
|
|
11
11
|
id: string;
|
|
12
12
|
};
|
|
13
13
|
/** Entity or `null` to indicate the item doesn't exist. */
|
|
14
|
-
export
|
|
14
|
+
export type ItemValue<T extends Data = Data> = ItemData<T> | null;
|
|
15
15
|
/** An array of item data. */
|
|
16
|
-
export
|
|
16
|
+
export type ItemArray<T extends Data = Data> = ImmutableArray<ItemData<T>>;
|
|
17
17
|
/** A set of query constraints for item data. */
|
|
18
|
-
export
|
|
18
|
+
export type ItemConstraints<T extends Data = Data> = QueryConstraints<ItemData<T>>;
|
|
19
19
|
/** Reference to an item in a synchronous or asynchronous database. */
|
|
20
20
|
declare abstract class BaseItem<T extends Datas = Datas, K extends DataKey<T> = DataKey<T>> implements AsyncIterable<ItemValue<T[K]>> {
|
|
21
21
|
abstract readonly db: Database<T> | AsyncDatabase<T>;
|
package/markup/options.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MarkupRules } from "./rules.js";
|
|
2
2
|
/** The current parsing options (represents the current state of the parsing). */
|
|
3
|
-
export
|
|
3
|
+
export type MarkupOptions = {
|
|
4
4
|
/** The active list of parsing rules. */
|
|
5
5
|
readonly rules: MarkupRules;
|
|
6
6
|
/** The initial context to start parsing in (rules may render their children with a different context). */
|
package/markup/regexp.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import type { Data } from "../util/data.js";
|
|
|
2
2
|
import { NamedRegExp, NamedRegExpData, PossibleRegExp } from "../util/regexp.js";
|
|
3
3
|
import type { MarkupOptions } from "./options.js";
|
|
4
4
|
/** Subset of `NamedRegExpArray<T>` that are the only things we're required return from a `MarkupMatcher` function. */
|
|
5
|
-
export
|
|
5
|
+
export type MarkupMatch<T extends Data | undefined = Data | undefined> = {
|
|
6
6
|
0: string;
|
|
7
7
|
index: number;
|
|
8
8
|
groups: T;
|
|
9
9
|
};
|
|
10
10
|
/** Function that matches a string and returns a `MarkupMatch` or `null` or `void` */
|
|
11
|
-
export
|
|
11
|
+
export type MarkupMatcher<T extends Data | undefined = Data | undefined> = (input: string, options: MarkupOptions) => MarkupMatch<T> | null | void;
|
|
12
12
|
export declare const LINE_REGEXP: RegExp;
|
|
13
13
|
export declare const LINE_START_REGEXP: RegExp;
|
|
14
14
|
export declare const LINE_END_REGEXP: RegExp;
|
package/markup/rules.d.ts
CHANGED
|
@@ -34,9 +34,9 @@ export interface MarkupRule<T extends Data | undefined = Data | undefined> {
|
|
|
34
34
|
readonly priority?: number;
|
|
35
35
|
}
|
|
36
36
|
/** Any markup rule. */
|
|
37
|
-
export
|
|
37
|
+
export type AnyMarkupRule = MarkupRule<any>;
|
|
38
38
|
/** A set of markup rules (as an object or array). */
|
|
39
|
-
export
|
|
39
|
+
export type MarkupRules = AnyMarkupRule[];
|
|
40
40
|
/**
|
|
41
41
|
* Headings are single line only (don't allow multiline).
|
|
42
42
|
* - 1-6 hashes then 1+ spaces, then the title.
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.86.
|
|
14
|
+
"version": "1.86.1",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -64,26 +64,26 @@
|
|
|
64
64
|
"build:jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config=jest.config.build.cjs"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@google-cloud/firestore": "^6.4.
|
|
68
|
-
"@types/jest": "^29.2.
|
|
69
|
-
"@types/react": "^18.0.
|
|
70
|
-
"@types/react-dom": "^18.0.
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
72
|
-
"@typescript-eslint/parser": "^5.
|
|
67
|
+
"@google-cloud/firestore": "^6.4.1",
|
|
68
|
+
"@types/jest": "^29.2.3",
|
|
69
|
+
"@types/react": "^18.0.25",
|
|
70
|
+
"@types/react-dom": "^18.0.9",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
|
72
|
+
"@typescript-eslint/parser": "^5.44.0",
|
|
73
73
|
"dpdm": "^3.9.0",
|
|
74
|
-
"esbuild": "^0.15.
|
|
74
|
+
"esbuild": "^0.15.14",
|
|
75
75
|
"esbuild-jest": "^0.5.0",
|
|
76
|
-
"eslint": "^8.
|
|
76
|
+
"eslint": "^8.28.0",
|
|
77
77
|
"eslint-config-prettier": "^8.5.0",
|
|
78
78
|
"eslint-plugin-import": "^2.26.0",
|
|
79
79
|
"eslint-plugin-prettier": "^4.0.0",
|
|
80
|
-
"firebase": "^9.
|
|
81
|
-
"jest": "^29.
|
|
80
|
+
"firebase": "^9.14.0",
|
|
81
|
+
"jest": "^29.3.1",
|
|
82
82
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
83
|
-
"prettier": "^2.
|
|
83
|
+
"prettier": "^2.8.0",
|
|
84
84
|
"react": "^18.1.0",
|
|
85
85
|
"react-dom": "^18.1.0",
|
|
86
|
-
"typescript": "^4.
|
|
86
|
+
"typescript": "^4.9.3"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@google-cloud/firestore": ">=4.0.0",
|
package/react/useItem.js
CHANGED
|
@@ -9,6 +9,14 @@ import { useState } from "./useState.js";
|
|
|
9
9
|
import { useCache } from "./useCache.js";
|
|
10
10
|
/** Hold the current state of a item. */
|
|
11
11
|
export class ItemState extends State {
|
|
12
|
+
/** Get the data of the item (throws `RequiredError` if item doesn't exist). */
|
|
13
|
+
get data() {
|
|
14
|
+
return getData(this.value);
|
|
15
|
+
}
|
|
16
|
+
/** Does the item exist (i.e. its value isn't `null`)? */
|
|
17
|
+
get exists() {
|
|
18
|
+
return !!this.value;
|
|
19
|
+
}
|
|
12
20
|
constructor(ref) {
|
|
13
21
|
var _a;
|
|
14
22
|
const { db, collection, id } = ref;
|
|
@@ -28,14 +36,6 @@ export class ItemState extends State {
|
|
|
28
36
|
if (this.loading)
|
|
29
37
|
this.refresh();
|
|
30
38
|
}
|
|
31
|
-
/** Get the data of the item (throws `RequiredError` if item doesn't exist). */
|
|
32
|
-
get data() {
|
|
33
|
-
return getData(this.value);
|
|
34
|
-
}
|
|
35
|
-
/** Does the item exist (i.e. its value isn't `null`)? */
|
|
36
|
-
get exists() {
|
|
37
|
-
return !!this.value;
|
|
38
|
-
}
|
|
39
39
|
async _refresh() {
|
|
40
40
|
this.busy.set(true);
|
|
41
41
|
try {
|
package/react/useQuery.js
CHANGED
|
@@ -9,6 +9,34 @@ import { useState } from "./useState.js";
|
|
|
9
9
|
import { useCache } from "./useCache.js";
|
|
10
10
|
/** Hold the current state of a query. */
|
|
11
11
|
export class QueryState extends State {
|
|
12
|
+
/** Can more items be loaded after the current result. */
|
|
13
|
+
get hasMore() {
|
|
14
|
+
return this._hasMore;
|
|
15
|
+
}
|
|
16
|
+
/** Get the first document matched by this query or `null` if this query has no items. */
|
|
17
|
+
get firstValue() {
|
|
18
|
+
return getOptionalFirstItem(this.value);
|
|
19
|
+
}
|
|
20
|
+
/** Get the first document matched by this query. */
|
|
21
|
+
get firstData() {
|
|
22
|
+
return getFirstItem(this.value);
|
|
23
|
+
}
|
|
24
|
+
/** Get the last document matched by this query or `null` if this query has no items. */
|
|
25
|
+
get lastValue() {
|
|
26
|
+
return getOptionalLastItem(this.value);
|
|
27
|
+
}
|
|
28
|
+
/** Get the last document matched by this query. */
|
|
29
|
+
get lastData() {
|
|
30
|
+
return getLastItem(this.value);
|
|
31
|
+
}
|
|
32
|
+
/** Does the document have at least one result. */
|
|
33
|
+
get exists() {
|
|
34
|
+
return !!this.value.length;
|
|
35
|
+
}
|
|
36
|
+
/** Get the number of items matching this query. */
|
|
37
|
+
get count() {
|
|
38
|
+
return this.value.length;
|
|
39
|
+
}
|
|
12
40
|
constructor(ref) {
|
|
13
41
|
var _a;
|
|
14
42
|
const { db, collection, limit } = ref;
|
|
@@ -38,34 +66,6 @@ export class QueryState extends State {
|
|
|
38
66
|
if (this.loading)
|
|
39
67
|
this.refresh();
|
|
40
68
|
}
|
|
41
|
-
/** Can more items be loaded after the current result. */
|
|
42
|
-
get hasMore() {
|
|
43
|
-
return this._hasMore;
|
|
44
|
-
}
|
|
45
|
-
/** Get the first document matched by this query or `null` if this query has no items. */
|
|
46
|
-
get firstValue() {
|
|
47
|
-
return getOptionalFirstItem(this.value);
|
|
48
|
-
}
|
|
49
|
-
/** Get the first document matched by this query. */
|
|
50
|
-
get firstData() {
|
|
51
|
-
return getFirstItem(this.value);
|
|
52
|
-
}
|
|
53
|
-
/** Get the last document matched by this query or `null` if this query has no items. */
|
|
54
|
-
get lastValue() {
|
|
55
|
-
return getOptionalLastItem(this.value);
|
|
56
|
-
}
|
|
57
|
-
/** Get the last document matched by this query. */
|
|
58
|
-
get lastData() {
|
|
59
|
-
return getLastItem(this.value);
|
|
60
|
-
}
|
|
61
|
-
/** Does the document have at least one result. */
|
|
62
|
-
get exists() {
|
|
63
|
-
return !!this.value.length;
|
|
64
|
-
}
|
|
65
|
-
/** Get the number of items matching this query. */
|
|
66
|
-
get count() {
|
|
67
|
-
return this.value.length;
|
|
68
|
-
}
|
|
69
69
|
async _refresh() {
|
|
70
70
|
this.busy.set(true);
|
|
71
71
|
try {
|
package/schema/AllowSchema.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { Entry } from "../util/entry.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ImmutableMap, PossibleMap, PossibleStringMap } from "../util/map.js";
|
|
3
3
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `AllowSchama` */
|
|
5
|
-
export
|
|
5
|
+
export type AllowSchemaOptions<K, T> = Omit<SchemaOptions, "value"> & {
|
|
6
6
|
allow: PossibleMap<K, T>;
|
|
7
7
|
};
|
|
8
8
|
/** Define a valid value from an allowed set of values. */
|
|
9
9
|
export declare class AllowSchema<K, T> extends Schema<K> implements Iterable<Entry<K, T>> {
|
|
10
10
|
readonly value: K;
|
|
11
|
-
readonly allow:
|
|
11
|
+
readonly allow: ImmutableMap<K, T>;
|
|
12
12
|
constructor({ allow, ...options }: AllowSchemaOptions<K, T>);
|
|
13
13
|
validate(value?: unknown): K;
|
|
14
14
|
/** Iterate over the the allowed options in `[key, value]` format. */
|
|
15
15
|
[Symbol.iterator](): Iterator<Entry<K, T>>;
|
|
16
16
|
}
|
|
17
17
|
/** Allowed options for `AllowStringSchama` */
|
|
18
|
-
export
|
|
18
|
+
export type AllowStringSchemaOptions<K extends string, T> = Omit<SchemaOptions, "value"> & {
|
|
19
19
|
allow: PossibleStringMap<K, T>;
|
|
20
20
|
};
|
|
21
21
|
/** Define a valid string value from an allowed set of string values. */
|
package/schema/AllowSchema.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getString } from "../util/string.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getMap, isMapKey } from "../util/map.js";
|
|
3
3
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
4
4
|
import { getFirstItem } from "../util/array.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
@@ -7,7 +7,7 @@ import { Schema } from "./Schema.js";
|
|
|
7
7
|
export class AllowSchema extends Schema {
|
|
8
8
|
constructor({ allow, ...options }) {
|
|
9
9
|
super(options);
|
|
10
|
-
this.allow =
|
|
10
|
+
this.allow = getMap(allow);
|
|
11
11
|
this.value = getFirstItem(this.allow.keys());
|
|
12
12
|
}
|
|
13
13
|
validate(value = this.value) {
|
|
@@ -23,7 +23,7 @@ export class AllowSchema extends Schema {
|
|
|
23
23
|
/** Define a valid string value from an allowed set of string values. */
|
|
24
24
|
export class AllowStringSchema extends AllowSchema {
|
|
25
25
|
constructor({ allow, ...options }) {
|
|
26
|
-
super({ allow:
|
|
26
|
+
super({ allow: getMap(allow), ...options });
|
|
27
27
|
}
|
|
28
28
|
validator(value = this.value) {
|
|
29
29
|
return super.validate(getString(value));
|
package/schema/ArraySchema.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ImmutableArray } from "../util/array.js";
|
|
|
2
2
|
import { Validator } from "../util/validate.js";
|
|
3
3
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `ArraySchema` */
|
|
5
|
-
export
|
|
5
|
+
export type ArraySchemaOptions<T> = SchemaOptions & {
|
|
6
6
|
readonly value?: ImmutableArray;
|
|
7
7
|
readonly items: Validator<T>;
|
|
8
8
|
readonly min?: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** Allowed options for `BooleanSchema` */
|
|
3
|
-
export
|
|
3
|
+
export type BooleanSchemaOptions = SchemaOptions & {
|
|
4
4
|
readonly value?: boolean;
|
|
5
5
|
};
|
|
6
6
|
/** Define a valid boolean. */
|
package/schema/DataSchema.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Validators } from "../util/validate.js";
|
|
|
3
3
|
import { OptionalSchema } from "./OptionalSchema.js";
|
|
4
4
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
5
5
|
/** Allowed options for `DataSchema` */
|
|
6
|
-
export
|
|
6
|
+
export type DataSchemaOptions<T extends Data> = SchemaOptions & {
|
|
7
7
|
readonly props: Validators<T>;
|
|
8
8
|
readonly value?: Partial<T>;
|
|
9
9
|
};
|
|
@@ -15,7 +15,7 @@ export declare class DataSchema<T extends Data> extends Schema<T> {
|
|
|
15
15
|
validate(unsafeValue?: unknown): T;
|
|
16
16
|
}
|
|
17
17
|
/** Set of named data schemas. */
|
|
18
|
-
export
|
|
18
|
+
export type DataSchemas<T extends Datas> = {
|
|
19
19
|
[K in keyof T]: DataSchema<T[K]>;
|
|
20
20
|
};
|
|
21
21
|
/** Valid data object with specifed properties. */
|
package/schema/DateSchema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PossibleDate } from "../util/date.js";
|
|
2
2
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
3
3
|
/** Allowed options for `DateSchema` */
|
|
4
|
-
export
|
|
4
|
+
export type DateSchemaOptions = SchemaOptions & {
|
|
5
5
|
readonly value?: PossibleDate;
|
|
6
6
|
readonly min?: PossibleDate | null;
|
|
7
7
|
readonly max?: PossibleDate | null;
|
|
@@ -2,7 +2,7 @@ import { ImmutableDictionary } from "../util/dictionary.js";
|
|
|
2
2
|
import { Validator } from "../util/validate.js";
|
|
3
3
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `DictionarySchema` */
|
|
5
|
-
export
|
|
5
|
+
export type DictionarySchemaOptions<T> = SchemaOptions & {
|
|
6
6
|
readonly items: Validator<T>;
|
|
7
7
|
readonly value?: ImmutableDictionary;
|
|
8
8
|
readonly min?: number | null;
|
package/schema/LinkSchema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StringSchema, StringSchemaOptions } from "./StringSchema.js";
|
|
2
2
|
/** Allowed options for `LinkSchema` */
|
|
3
|
-
export
|
|
3
|
+
export type LinkSchemaOptions = StringSchemaOptions & {
|
|
4
4
|
readonly schemes?: string[];
|
|
5
5
|
readonly hosts?: string[] | null;
|
|
6
6
|
};
|
package/schema/NumberSchema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** Allowed options for `NumberSchema` */
|
|
3
|
-
export
|
|
3
|
+
export type NumberSchemaOptions = SchemaOptions & {
|
|
4
4
|
readonly value?: number | null;
|
|
5
5
|
readonly min?: number | null;
|
|
6
6
|
readonly max?: number | null;
|
package/schema/Schema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Validatable } from "../util/validate.js";
|
|
2
2
|
/** Options allowed by a `Schema` instance. */
|
|
3
|
-
export
|
|
3
|
+
export type SchemaOptions = {
|
|
4
4
|
/** Title of the schema, e.g. for using as the title of a corresponding field. */
|
|
5
5
|
readonly title?: string | null;
|
|
6
6
|
/** Description of the schema, e.g. for using as a description in a corresponding field. */
|
package/schema/StringSchema.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
2
2
|
/** `type=""` prop for HTML `<input />` tags that are relevant for strings. */
|
|
3
|
-
export
|
|
3
|
+
export type HtmlInputType = "text" | "password" | "color" | "date" | "email" | "number" | "tel" | "search" | "url";
|
|
4
4
|
/** Function that sanitizes a string. */
|
|
5
|
-
export
|
|
5
|
+
export type Sanitizer = (str: string) => string;
|
|
6
6
|
/** Options for `StringSchema` */
|
|
7
|
-
export
|
|
7
|
+
export type StringSchemaOptions = SchemaOptions & {
|
|
8
8
|
readonly value?: string;
|
|
9
9
|
readonly type?: HtmlInputType;
|
|
10
10
|
readonly min?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Sourceable } from "../util/source.js";
|
|
2
2
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
3
3
|
/** Allowed options for `ThroughSchama` */
|
|
4
|
-
export
|
|
4
|
+
export type ThroughSchemaOptions<T> = SchemaOptions & {
|
|
5
5
|
source: Schema<T>;
|
|
6
6
|
};
|
|
7
7
|
/** Schema that passes through to a source schema. */
|
package/schema/TimeSchema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PossibleTime, Time } from "../util/time.js";
|
|
2
2
|
import { Schema, SchemaOptions } from "./Schema.js";
|
|
3
3
|
/** Allowed options for `TimeSchama` */
|
|
4
|
-
export
|
|
4
|
+
export type TimeSchemaOptions = SchemaOptions & {
|
|
5
5
|
readonly value?: PossibleTime;
|
|
6
6
|
readonly min?: PossibleTime | null;
|
|
7
7
|
readonly max?: PossibleTime | null;
|
package/state/State.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dispatch, Handler, Stop } from "../util/function.js";
|
|
2
2
|
import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
3
3
|
/** Any `State` instance. */
|
|
4
|
-
export
|
|
4
|
+
export type AnyState = State<any>;
|
|
5
5
|
/**
|
|
6
6
|
* Stream that retains its most recent value
|
|
7
7
|
* - Current value can be read at `state.value` and `state.data`
|
package/state/State.js
CHANGED
|
@@ -11,12 +11,6 @@ import { DeferredSequence } from "../sequence/DeferredSequence.js";
|
|
|
11
11
|
* - To set the state to an explicit value, use that value or another `State` instance with a value.
|
|
12
12
|
* */
|
|
13
13
|
export class State {
|
|
14
|
-
/** State is initiated with an initial state. */
|
|
15
|
-
constructor(initial = State.NOVALUE, next = new DeferredSequence()) {
|
|
16
|
-
this._value = initial;
|
|
17
|
-
this._time = initial !== State.NOVALUE ? Date.now() : null;
|
|
18
|
-
this.next = next;
|
|
19
|
-
}
|
|
20
14
|
/** Most recently dispatched value (or throw `Promise` that resolves to the next value). */
|
|
21
15
|
get value() {
|
|
22
16
|
if (this._value === State.NOVALUE)
|
|
@@ -32,6 +26,12 @@ export class State {
|
|
|
32
26
|
const time = this.time;
|
|
33
27
|
return time !== null ? Date.now() - time : Infinity;
|
|
34
28
|
}
|
|
29
|
+
/** State is initiated with an initial state. */
|
|
30
|
+
constructor(initial = State.NOVALUE, next = new DeferredSequence()) {
|
|
31
|
+
this._value = initial;
|
|
32
|
+
this._time = initial !== State.NOVALUE ? Date.now() : null;
|
|
33
|
+
this.next = next;
|
|
34
|
+
}
|
|
35
35
|
/** Is there a current value, or is it still loading. */
|
|
36
36
|
get loading() {
|
|
37
37
|
return this._value === State.NOVALUE;
|
package/test/basics.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export declare const BASIC_SCHEMA: import("../schema/DataSchema.js").DataSchema<
|
|
|
6
6
|
group: "a" | "b" | "c";
|
|
7
7
|
tags: import("../index.js").ImmutableArray<string>;
|
|
8
8
|
}>;
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type BasicData = ValidatorType<typeof BASIC_SCHEMA>;
|
|
10
|
+
export type BasicItemData = ItemData<BasicData>;
|
|
11
11
|
export declare const basic1: BasicItemData;
|
|
12
12
|
export declare const basic2: BasicItemData;
|
|
13
13
|
export declare const basic3: BasicItemData;
|
package/test/index.d.ts
CHANGED
package/test/people.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare const PERSON_SCHEMA: import("../schema/DataSchema.js").DataSchema
|
|
|
7
7
|
};
|
|
8
8
|
birthday: string | null;
|
|
9
9
|
}>;
|
|
10
|
-
export
|
|
11
|
-
export
|
|
10
|
+
export type PersonData = ValidatorType<typeof PERSON_SCHEMA>;
|
|
11
|
+
export type PersonItemData = ItemData<PersonData>;
|
|
12
12
|
export declare const person1: PersonItemData;
|
|
13
13
|
export declare const person2: PersonItemData;
|
|
14
14
|
export declare const person3: PersonItemData;
|