shelving 1.47.1 → 1.48.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/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
- _id: string;
167
- _doc: DatabaseDocument<T>;
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, _id: ref.id, _doc: ref };
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/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.47.1",
14
+ "version": "1.48.1",
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.0",
67
- "@typescript-eslint/parser": "^5.9.0",
68
- "eslint": "^8.6.0",
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.2",
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.2",
78
+ "ts-jest": "^27.1.3",
79
79
  "typescript": "^4.5.4"
80
80
  },
81
81
  "peerDependencies": {
@@ -9,8 +9,8 @@ export declare class Filters<T extends Data> extends Rules<T, Filter<T>> impleme
9
9
  filter(props: FilterProps<T>): this;
10
10
  filter(key: "id" | "!id" | "id>" | "id>=" | "id<" | "id<=", value: string): this;
11
11
  filter(key: "id" | "!id", value: ImmutableArray<string>): this;
12
- filter<K extends Key<T>>(key: K | `!${K}` | `${K}>` | `${K}>=` | `${K}<` | `${K}<=`, value: T[K]): this;
13
- filter<K extends Key<T>>(key: K | `!${K}`, value: ImmutableArray<string>): this;
12
+ filter<K extends Key<T>>(key: `${K}` | `!${K}` | `${K}>` | `${K}>=` | `${K}<` | `${K}<=`, value: T[K]): this;
13
+ filter<K extends Key<T>>(key: `${K}` | `!${K}`, value: ImmutableArray<string>): this;
14
14
  filter<K extends Key<T>>(key: `${K}[]`, value: T[K] extends ImmutableArray ? ArrayType<T[K]> : never): this;
15
15
  match(entry: Entry<T>): boolean;
16
16
  transform(iterable: Entries<T>): Entries<T>;
package/query/Query.d.ts CHANGED
@@ -14,8 +14,8 @@ export declare class Query<T extends Data> extends Rule<T> implements Queryable<
14
14
  filter(props: FilterProps<T>): this;
15
15
  filter(key: "id" | "!id" | "id>" | "id>=" | "id<" | "id<=", value: string): this;
16
16
  filter(key: "id" | "!id", value: ImmutableArray<string>): this;
17
- filter<K extends Key<T>>(key: K | `!${K}` | `${K}>` | `${K}>=` | `${K}<` | `${K}<=`, value: T[K]): this;
18
- filter<K extends Key<T>>(key: K | `!${K}`, value: ImmutableArray<T[K]>): this;
17
+ filter<K extends Key<T>>(key: `${K}` | `!${K}` | `${K}>` | `${K}>=` | `${K}<` | `${K}<=`, value: T[K]): this;
18
+ filter<K extends Key<T>>(key: `${K}` | `!${K}`, value: ImmutableArray<T[K]>): this;
19
19
  filter<K extends Key<T>>(key: `${K}[]`, value: T[K] extends ImmutableArray ? ArrayType<T[K]> : never): this;
20
20
  get unfilter(): this;
21
21
  match(entry: Entry<T>): boolean;
package/query/types.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { Data, Key, Matchable, Entry, Rankable, ImmutableArray, ArrayType }
2
2
  /** Possible operator references. */
3
3
  export declare type FilterOperator = "IS" | "NOT" | "IN" | "OUT" | "CONTAINS" | "LT" | "LTE" | "GT" | "GTE";
4
4
  /** 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` */
5
- export declare type FilterKey<T extends Data> = "id" | "!id" | "id>" | "id>=" | "id<" | "id<=" | Key<T> | `!${Key<T>}` | `${Key<T>}[]` | `${Key<T>}<` | `${Key<T>}<=` | `${Key<T>}>` | `${Key<T>}>=`;
5
+ export declare type FilterKey<T extends Data> = "id" | "!id" | "id>" | "id>=" | "id<" | "id<=" | Key<T> | `${Key<T>}` | `!${Key<T>}` | `${Key<T>}[]` | `${Key<T>}<` | `${Key<T>}<=` | `${Key<T>}>` | `${Key<T>}>=`;
6
6
  /** Format that allows multiple filters to be specified as a plain object. */
7
7
  export declare type FilterProps<T extends Data> = {
8
8
  "id"?: string | ImmutableArray<string>;
@@ -12,7 +12,7 @@ export declare type FilterProps<T extends Data> = {
12
12
  "id<"?: string;
13
13
  "id<="?: string;
14
14
  } & {
15
- [K in Key<T> as K | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
15
+ [K in Key<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
16
16
  } & {
17
17
  [K in Key<T> as `${K}[]`]?: T[K] extends ImmutableArray ? ArrayType<T[K]> : never;
18
18
  } & {
@@ -27,14 +27,14 @@ export interface Filterable<T extends Data> extends Matchable<Entry<T>, void> {
27
27
  filter(props: FilterProps<T>): this;
28
28
  filter(key: "id" | "!id" | "id>" | "id>=" | "id<" | "id<=", value: string): this;
29
29
  filter(key: "id" | "!id", value: ImmutableArray<string>): this;
30
- filter<K extends Key<T>>(key: K | `!${K}` | `${K}>` | `${K}>=` | `${K}<` | `${K}<=`, value: T[K]): this;
31
- filter<K extends Key<T>>(key: K | `!${K}`, value: ImmutableArray<string>): this;
30
+ filter<K extends Key<T>>(key: `${K}` | `!${K}` | `${K}>` | `${K}>=` | `${K}<` | `${K}<=`, value: T[K]): this;
31
+ filter<K extends Key<T>>(key: `${K}` | `!${K}`, value: ImmutableArray<string>): this;
32
32
  filter<K extends Key<T>>(key: `${K}[]`, value: T[K] extends ImmutableArray ? ArrayType<T[K]> : never): this;
33
33
  /** Match an entry against the filters specified for this object. */
34
34
  match(entry: Entry<T>): boolean;
35
35
  }
36
36
  /** 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. */
37
- export declare type SortKey<T extends Data> = "id" | "!id" | Key<T> | `!${Key<T>}`;
37
+ export declare type SortKey<T extends Data> = "id" | "!id" | Key<T> | `${Key<T>}` | `!${Key<T>}`;
38
38
  /** One or more sort keys. */
39
39
  export declare type SortKeys<T extends Data> = SortKey<T> | ImmutableArray<SortKey<T>>;
40
40
  /** Possible operator references. */
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 rankEntryKeyAsc: ([l]: Entry<unknown>, [r]: Entry<unknown>) => number;
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 rankEntryKeyDesc: ([l]: Entry<unknown>, [r]: Entry<unknown>) => number;
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 rankEntryValueAsc: ([, l]: Entry<unknown>, [, r]: Entry<unknown>) => number;
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 rankEntryValueDesc: ([, l]: Entry<unknown>, [, r]: Entry<unknown>) => number;
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 rankEntryKeyAsc = ([l], [r]) => rankAsc(l, r);
78
+ export const rankKeyAsc = ([l], [r]) => rankAsc(l, r);
79
79
  /** Rank the keys of two entries in descending order. */
80
- export const rankEntryKeyDesc = ([l], [r]) => rankDesc(l, r);
80
+ export const rankKeyDesc = ([l], [r]) => rankDesc(l, r);
81
81
  /** Rank the values of two entries in ascending order. */
82
- export const rankEntryValueAsc = ([, l], [, r]) => rankAsc(l, r);
82
+ export const rankValueAsc = ([, l], [, r]) => rankAsc(l, r);
83
83
  /** Rank the values of two entries in descending order. */
84
- export const rankEntryValueDesc = ([, l], [, r]) => rankDesc(l, r);
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 = rankEntryKeyAsc) {
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 = rankEntryKeyAsc) {
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 = rankEntryKeyAsc) {
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
  }