shelving 1.47.0 → 1.48.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/db/Database.d.ts +2 -2
- package/db/Database.js +1 -1
- package/db/Operation.d.ts +1 -3
- package/db/Operation.js +4 -7
- package/package.json +6 -6
- package/util/date.d.ts +2 -0
- package/util/date.js +2 -0
- package/util/sort.d.ts +4 -4
- package/util/sort.js +7 -7
package/db/Database.d.ts
CHANGED
|
@@ -163,8 +163,8 @@ export declare class DatabaseDocument<T extends Data = Data> implements Observab
|
|
|
163
163
|
}
|
|
164
164
|
/** Database data embeds the corresponding `Document` instance and string ID into the data. */
|
|
165
165
|
export declare type DocumentData<T extends Data> = T & {
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
id: string;
|
|
167
|
+
doc: DatabaseDocument<T>;
|
|
168
168
|
};
|
|
169
169
|
/** Get the data for a document from a result for that document. */
|
|
170
170
|
export declare function getDocumentData<T extends Data>(result: Result<T>, ref: DatabaseDocument<T>): DocumentData<T>;
|
package/db/Database.js
CHANGED
|
@@ -259,7 +259,7 @@ export class DatabaseDocument {
|
|
|
259
259
|
/** Get the data for a document from a result for that document. */
|
|
260
260
|
export function getDocumentData(result, ref) {
|
|
261
261
|
if (result)
|
|
262
|
-
return { ...result,
|
|
262
|
+
return { ...result, id: ref.id, doc: ref };
|
|
263
263
|
throw new DocumentRequiredError(ref);
|
|
264
264
|
}
|
|
265
265
|
/** Get the data for a document from a result for that document. */
|
package/db/Operation.d.ts
CHANGED
|
@@ -8,10 +8,8 @@ export declare abstract class Operation {
|
|
|
8
8
|
}
|
|
9
9
|
/** Represent a list of write operations on a database run in series. */
|
|
10
10
|
export declare class Operations extends Operation {
|
|
11
|
-
/** Return a new write operations list with a set of write operations. */
|
|
12
|
-
static with(...operations: Nullish<Operation>[]): Operations;
|
|
13
11
|
readonly operations: ImmutableArray<Operation>;
|
|
14
|
-
constructor(operations:
|
|
12
|
+
constructor(...operations: Nullish<Operation>[]);
|
|
15
13
|
run(db: Database): Promise<Operations>;
|
|
16
14
|
/** Return a new write operations list with an additional write operation added. */
|
|
17
15
|
with(...operations: Nullish<Operation>[]): {
|
package/db/Operation.js
CHANGED
|
@@ -4,23 +4,20 @@ export class Operation {
|
|
|
4
4
|
}
|
|
5
5
|
/** Represent a list of write operations on a database run in series. */
|
|
6
6
|
export class Operations extends Operation {
|
|
7
|
-
constructor(operations) {
|
|
7
|
+
constructor(...operations) {
|
|
8
8
|
super();
|
|
9
9
|
this.operations = operations.filter(notNullish);
|
|
10
10
|
}
|
|
11
|
-
/** Return a new write operations list with a set of write operations. */
|
|
12
|
-
static with(...operations) {
|
|
13
|
-
return new Operations(operations);
|
|
14
|
-
}
|
|
15
11
|
async run(db) {
|
|
16
|
-
|
|
12
|
+
const ops = await callAsyncSeries(_run, this.operations, db);
|
|
13
|
+
return new Operations(...ops);
|
|
17
14
|
}
|
|
18
15
|
/** Return a new write operations list with an additional write operation added. */
|
|
19
16
|
with(...operations) {
|
|
20
17
|
return { __proto__: Object.getPrototypeOf(this), ...this, operations: [...this.operations, operations] };
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
const
|
|
20
|
+
const _run = (operation, db) => operation.run(db);
|
|
24
21
|
/** Represent a add operation made to a collection in a database. */
|
|
25
22
|
export class AddOperation extends Operation {
|
|
26
23
|
constructor(collection, data) {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.48.0",
|
|
15
15
|
"repository": "https://github.com/dhoulb/shelving",
|
|
16
16
|
"author": "Dave Houlbrooke <dave@shax.com>",
|
|
17
17
|
"license": "0BSD",
|
|
@@ -63,19 +63,19 @@
|
|
|
63
63
|
"@types/jest": "^27.4.0",
|
|
64
64
|
"@types/react": "^17.0.38",
|
|
65
65
|
"@types/react-dom": "^17.0.11",
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^5.9.
|
|
67
|
-
"@typescript-eslint/parser": "^5.9.
|
|
68
|
-
"eslint": "^8.
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
|
67
|
+
"@typescript-eslint/parser": "^5.9.1",
|
|
68
|
+
"eslint": "^8.7.0",
|
|
69
69
|
"eslint-config-prettier": "^8.3.0",
|
|
70
70
|
"eslint-plugin-import": "^2.25.4",
|
|
71
71
|
"eslint-plugin-prettier": "^4.0.0",
|
|
72
|
-
"firebase": "^9.6.
|
|
72
|
+
"firebase": "^9.6.3",
|
|
73
73
|
"jest": "^27.4.7",
|
|
74
74
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
75
75
|
"prettier": "^2.5.1",
|
|
76
76
|
"react": "^17.0.2",
|
|
77
77
|
"react-dom": "^17.0.2",
|
|
78
|
-
"ts-jest": "^27.1.
|
|
78
|
+
"ts-jest": "^27.1.3",
|
|
79
79
|
"typescript": "^4.5.4"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
package/util/date.d.ts
CHANGED
|
@@ -128,3 +128,5 @@ export declare const formatDate: (date: PossibleDate) => string;
|
|
|
128
128
|
export declare const isPast: (target: PossibleDate, current?: PossibleDate | undefined) => boolean;
|
|
129
129
|
/** Is a date in the future? */
|
|
130
130
|
export declare const isFuture: (target: PossibleDate, current?: PossibleDate | undefined) => boolean;
|
|
131
|
+
/** Is a date today (taking into account midnight). */
|
|
132
|
+
export declare const isToday: (target: PossibleDate, current?: PossibleDate | undefined) => boolean;
|
package/util/date.js
CHANGED
|
@@ -217,3 +217,5 @@ const _formatter = new Intl.DateTimeFormat(undefined, {});
|
|
|
217
217
|
export const isPast = (target, current) => getDate(target) < getDate(current);
|
|
218
218
|
/** Is a date in the future? */
|
|
219
219
|
export const isFuture = (target, current) => getDate(target) > getDate(current);
|
|
220
|
+
/** Is a date today (taking into account midnight). */
|
|
221
|
+
export const isToday = (target, current) => getMidnight(target) === getMidnight(current);
|
package/util/sort.d.ts
CHANGED
|
@@ -32,13 +32,13 @@ export declare function rankAsc(left: unknown, right: unknown): number;
|
|
|
32
32
|
/** Rank two values in descending order. */
|
|
33
33
|
export declare const rankDesc: (left: unknown, right: unknown) => number;
|
|
34
34
|
/** Rank the keys of two entries in ascending order. */
|
|
35
|
-
export declare const
|
|
35
|
+
export declare const rankKeyAsc: ([l]: Entry<unknown>, [r]: Entry<unknown>) => number;
|
|
36
36
|
/** Rank the keys of two entries in descending order. */
|
|
37
|
-
export declare const
|
|
37
|
+
export declare const rankKeyDesc: ([l]: Entry<unknown>, [r]: Entry<unknown>) => number;
|
|
38
38
|
/** Rank the values of two entries in ascending order. */
|
|
39
|
-
export declare const
|
|
39
|
+
export declare const rankValueAsc: ([, l]: Entry<unknown>, [, r]: Entry<unknown>) => number;
|
|
40
40
|
/** Rank the values of two entries in descending order. */
|
|
41
|
-
export declare const
|
|
41
|
+
export declare const rankValueDesc: ([, l]: Entry<unknown>, [, r]: Entry<unknown>) => number;
|
|
42
42
|
/** Sort an iterable set of items using a ranker (defaults to sorting in ascending order). */
|
|
43
43
|
export declare function sortItems<T>(input: Iterable<T>, ranker?: Ranker<T>): ImmutableArray<T>;
|
|
44
44
|
/** Sort an array using a ranker (defaults to sorting in ascending order) */
|
package/util/sort.js
CHANGED
|
@@ -75,13 +75,13 @@ export function rankAsc(left, right) {
|
|
|
75
75
|
/** Rank two values in descending order. */
|
|
76
76
|
export const rankDesc = (left, right) => 0 - rankAsc(left, right);
|
|
77
77
|
/** Rank the keys of two entries in ascending order. */
|
|
78
|
-
export const
|
|
78
|
+
export const rankKeyAsc = ([l], [r]) => rankAsc(l, r);
|
|
79
79
|
/** Rank the keys of two entries in descending order. */
|
|
80
|
-
export const
|
|
80
|
+
export const rankKeyDesc = ([l], [r]) => rankDesc(l, r);
|
|
81
81
|
/** Rank the values of two entries in ascending order. */
|
|
82
|
-
export const
|
|
82
|
+
export const rankValueAsc = ([, l], [, r]) => rankAsc(l, r);
|
|
83
83
|
/** Rank the values of two entries in descending order. */
|
|
84
|
-
export const
|
|
84
|
+
export const rankValueDesc = ([, l], [, r]) => rankDesc(l, r);
|
|
85
85
|
/**
|
|
86
86
|
* Quick sort algorithm.
|
|
87
87
|
* DH: We implement our own sorting algorithm so that:
|
|
@@ -144,18 +144,18 @@ export function sortArray(input, ranker = rankAsc) {
|
|
|
144
144
|
* Sort an iterable set of entries (defaults to sorting by key in ascending order).
|
|
145
145
|
* - Always returns an array
|
|
146
146
|
*/
|
|
147
|
-
export function sortEntries(input, ranker =
|
|
147
|
+
export function sortEntries(input, ranker = rankKeyAsc) {
|
|
148
148
|
const array = Array.from(input);
|
|
149
149
|
_quicksort(array, ranker);
|
|
150
150
|
return array;
|
|
151
151
|
}
|
|
152
152
|
/** Sort a map-like object using a ranker (defaults to sorting by key in ascending order). */
|
|
153
|
-
export function sortObject(input, ranker =
|
|
153
|
+
export function sortObject(input, ranker = rankKeyAsc) {
|
|
154
154
|
const array = Object.entries(input);
|
|
155
155
|
return _quicksort(array, ranker) ? Object.fromEntries(array) : input;
|
|
156
156
|
}
|
|
157
157
|
/** Sort a map using a ranker (defaults to sorting by key in ascending order). */
|
|
158
|
-
export function sortMap(input, ranker =
|
|
158
|
+
export function sortMap(input, ranker = rankKeyAsc) {
|
|
159
159
|
const array = Array.from(input);
|
|
160
160
|
return _quicksort(array, ranker) ? new Map(array) : input;
|
|
161
161
|
}
|