shelving 1.91.2 → 1.92.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.
Files changed (98) hide show
  1. package/db/Change.d.ts +19 -20
  2. package/db/Change.js +22 -21
  3. package/db/CollectionReference.d.ts +103 -0
  4. package/db/CollectionReference.js +127 -0
  5. package/db/Database.d.ts +21 -23
  6. package/db/Database.js +18 -18
  7. package/db/{Item.d.ts → ItemReference.d.ts} +13 -14
  8. package/db/{Item.js → ItemReference.js} +14 -17
  9. package/db/ItemState.d.ts +3 -3
  10. package/db/{Query.d.ts → QueryReference.d.ts} +25 -33
  11. package/db/QueryReference.js +101 -0
  12. package/db/QueryState.d.ts +10 -10
  13. package/db/QueryState.js +20 -18
  14. package/db/index.d.ts +3 -3
  15. package/db/index.js +3 -3
  16. package/firestore/client/FirestoreClientProvider.d.ts +13 -13
  17. package/firestore/client/FirestoreClientProvider.js +55 -84
  18. package/firestore/lite/FirestoreLiteProvider.d.ts +11 -11
  19. package/firestore/lite/FirestoreLiteProvider.js +52 -83
  20. package/firestore/server/FirestoreServerProvider.d.ts +13 -13
  21. package/firestore/server/FirestoreServerProvider.js +51 -84
  22. package/index.d.ts +0 -2
  23. package/index.js +0 -2
  24. package/package.json +1 -3
  25. package/provider/CacheProvider.d.ts +7 -7
  26. package/provider/CacheProvider.js +14 -14
  27. package/provider/DebugProvider.d.ts +11 -11
  28. package/provider/DebugProvider.js +28 -29
  29. package/provider/MemoryProvider.d.ts +17 -17
  30. package/provider/MemoryProvider.js +41 -43
  31. package/provider/Provider.d.ts +15 -15
  32. package/provider/ThroughProvider.d.ts +12 -12
  33. package/provider/ThroughProvider.js +20 -20
  34. package/provider/ValidationProvider.d.ts +11 -11
  35. package/provider/ValidationProvider.js +16 -12
  36. package/react/useData.d.ts +5 -5
  37. package/react/useData.js +2 -2
  38. package/state/DataState.d.ts +4 -8
  39. package/state/DataState.js +6 -16
  40. package/state/DictionaryState.d.ts +4 -6
  41. package/state/DictionaryState.js +4 -9
  42. package/test/basics.d.ts +1 -1
  43. package/test/people.d.ts +1 -1
  44. package/test/util.d.ts +1 -1
  45. package/test/util.js +1 -1
  46. package/util/data.d.ts +2 -2
  47. package/util/equal.js +5 -5
  48. package/util/hydrate.d.ts +13 -26
  49. package/util/hydrate.js +44 -60
  50. package/util/index.d.ts +2 -0
  51. package/util/index.js +2 -0
  52. package/util/iterate.d.ts +2 -0
  53. package/util/match.d.ts +2 -10
  54. package/util/match.js +4 -8
  55. package/util/query.d.ts +83 -0
  56. package/util/query.js +129 -0
  57. package/util/sort.d.ts +8 -15
  58. package/util/sort.js +15 -19
  59. package/util/transform.d.ts +26 -45
  60. package/util/transform.js +24 -29
  61. package/util/update.d.ts +22 -0
  62. package/util/update.js +42 -0
  63. package/util/validate.js +2 -2
  64. package/constraint/Constraint.d.ts +0 -7
  65. package/constraint/Constraint.js +0 -3
  66. package/constraint/Constraints.d.ts +0 -20
  67. package/constraint/Constraints.js +0 -34
  68. package/constraint/Filter.d.ts +0 -34
  69. package/constraint/Filter.js +0 -89
  70. package/constraint/Filters.d.ts +0 -27
  71. package/constraint/Filters.js +0 -41
  72. package/constraint/Sort.d.ts +0 -18
  73. package/constraint/Sort.js +0 -33
  74. package/constraint/Sorts.d.ts +0 -26
  75. package/constraint/Sorts.js +0 -47
  76. package/constraint/Statement.d.ts +0 -45
  77. package/constraint/Statement.js +0 -79
  78. package/constraint/index.d.ts +0 -7
  79. package/constraint/index.js +0 -7
  80. package/db/Collection.d.ts +0 -64
  81. package/db/Collection.js +0 -83
  82. package/db/Query.js +0 -94
  83. package/update/ArrayUpdate.d.ts +0 -17
  84. package/update/ArrayUpdate.js +0 -31
  85. package/update/DataUpdate.d.ts +0 -37
  86. package/update/DataUpdate.js +0 -44
  87. package/update/Delete.d.ts +0 -10
  88. package/update/Delete.js +0 -12
  89. package/update/DictionaryUpdate.d.ts +0 -31
  90. package/update/DictionaryUpdate.js +0 -62
  91. package/update/Increment.d.ts +0 -18
  92. package/update/Increment.js +0 -22
  93. package/update/Update.d.ts +0 -8
  94. package/update/Update.js +0 -6
  95. package/update/hydrations.d.ts +0 -3
  96. package/update/hydrations.js +0 -13
  97. package/update/index.d.ts +0 -7
  98. package/update/index.js +0 -7
@@ -1,34 +0,0 @@
1
- import { omitArrayItems, withArrayItems } from "../util/array.js";
2
- import { cloneObjectWith } from "../util/object.js";
3
- import { Constraint } from "./Constraint.js";
4
- /** Type of Rule that is powered by several sub-constraints (e.g. `Filters` and `Sorts` and `Query` itself extend this). */
5
- export class Constraints extends Constraint {
6
- /** Get the first constraint. */
7
- get first() {
8
- return this._constraints[0];
9
- }
10
- /** Get the last constraint. */
11
- get last() {
12
- return this._constraints[this._constraints.length - 1];
13
- }
14
- /** Get the number of constraints. */
15
- get size() {
16
- return this._constraints.length;
17
- }
18
- constructor(...constraints) {
19
- super();
20
- this._constraints = constraints;
21
- }
22
- /** Clone this set of constraints but add additional constraints. */
23
- with(...constraints) {
24
- return cloneObjectWith(this, "_constraints", withArrayItems(this._constraints, ...constraints));
25
- }
26
- /** Clone this set of constraints but remove specific constraints. */
27
- omit(...constraints) {
28
- return cloneObjectWith(this, "_constraints", omitArrayItems(this._constraints, ...constraints));
29
- }
30
- /** Iterate over the constraints. */
31
- [Symbol.iterator]() {
32
- return this._constraints.values();
33
- }
34
- }
@@ -1,34 +0,0 @@
1
- import type { ImmutableArray } from "../util/array.js";
2
- import type { Data, FlatDataKey } from "../util/data.js";
3
- import type { Matchable } from "../util/match.js";
4
- import { Constraint } from "./Constraint.js";
5
- /** Possible operator references. */
6
- export type FilterOperator = "IS" | "NOT" | "IN" | "OUT" | "CONTAINS" | "LT" | "LTE" | "GT" | "GTE";
7
- /** Format that allows multiple filters to be specified as a plain object. */
8
- export type FilterProps<T extends Data> = {
9
- [K in FlatDataKey<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
10
- } & {
11
- [K in FlatDataKey<T> as `${K}<` | `${K}<=` | `${K}>` | `${K}>=`]?: T[K];
12
- } & {
13
- [K in FlatDataKey<T> as `${K}[]`]?: Required<T>[K] extends ImmutableArray<infer X> ? X : never;
14
- };
15
- /** 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` */
16
- export type FilterKey<T extends Data> = keyof FilterProps<T>;
17
- /**
18
- * Filter: filters a list of data.
19
- *
20
- * @param key The name of a property that might exist on data in the collection.
21
- * @param operator FilterOperator, e.g. `IS` or `CONTAINS`
22
- * @param value Value the specified property should be matched against.
23
- */
24
- export declare class Filter<T extends Data = Data> extends Constraint<T> implements Matchable<[T]> {
25
- readonly keys: readonly [string, ...string[]];
26
- readonly operator: FilterOperator;
27
- readonly value: unknown;
28
- get key(): string;
29
- get filterKey(): string;
30
- constructor(filterKey: FilterKey<T>, value: unknown);
31
- match(item: T): boolean;
32
- transform(items: Iterable<T>): Iterable<T>;
33
- toString(): string;
34
- }
@@ -1,89 +0,0 @@
1
- import { isArray } from "../util/array.js";
2
- import { isArrayWith, isEqual, isEqualGreater, isEqualLess, isGreater, isInArray, isLess, notEqual, notInArray } from "../util/equal.js";
3
- import { filterItems } from "../util/match.js";
4
- import { getProp } from "../util/object.js";
5
- import { splitString } from "../util/string.js";
6
- import { Constraint } from "./Constraint.js";
7
- /** Map `FilterOperator` to its corresponding `Match` function. */
8
- const MATCHERS = {
9
- IS: isEqual,
10
- NOT: notEqual,
11
- IN: isInArray,
12
- OUT: notInArray,
13
- CONTAINS: isArrayWith,
14
- LT: isLess,
15
- LTE: isEqualLess,
16
- GT: isGreater,
17
- GTE: isEqualGreater,
18
- };
19
- /**
20
- * Filter: filters a list of data.
21
- *
22
- * @param key The name of a property that might exist on data in the collection.
23
- * @param operator FilterOperator, e.g. `IS` or `CONTAINS`
24
- * @param value Value the specified property should be matched against.
25
- */
26
- export class Filter extends Constraint {
27
- get key() {
28
- return this.keys.join(".");
29
- }
30
- get filterKey() {
31
- const { operator, key } = this;
32
- return operator === "IS" || operator === "IN"
33
- ? key
34
- : operator === "NOT" || operator === "OUT"
35
- ? `!${key}`
36
- : operator === "CONTAINS"
37
- ? `${key}[]`
38
- : operator === "LT"
39
- ? `${key}<`
40
- : operator === "LTE"
41
- ? `${key}<=`
42
- : operator === "GT"
43
- ? `${key}>`
44
- : operator === "GTE"
45
- ? `${key}>=`
46
- : operator; // Never.
47
- }
48
- constructor(filterKey, value) {
49
- super();
50
- if (filterKey.startsWith("!")) {
51
- this.keys = splitString(filterKey.slice(1), ".");
52
- this.operator = isArray(value) ? "OUT" : "NOT";
53
- }
54
- else if (filterKey.endsWith("[]")) {
55
- this.keys = splitString(filterKey.slice(0, -2), ".");
56
- this.operator = "CONTAINS";
57
- }
58
- else if (filterKey.endsWith(">")) {
59
- this.keys = splitString(filterKey.slice(0, -1), ".");
60
- this.operator = "GT";
61
- }
62
- else if (filterKey.endsWith(">=")) {
63
- this.keys = splitString(filterKey.slice(0, -2), ".");
64
- this.operator = "GTE";
65
- }
66
- else if (filterKey.endsWith("<")) {
67
- this.keys = splitString(filterKey.slice(0, -1), ".");
68
- this.operator = "LT";
69
- }
70
- else if (filterKey.endsWith("<=")) {
71
- this.keys = splitString(filterKey.slice(0, -2), ".");
72
- this.operator = "LTE";
73
- }
74
- else {
75
- this.keys = splitString(filterKey, ".");
76
- this.operator = isArray(value) ? "IN" : "IS";
77
- }
78
- this.value = value;
79
- }
80
- match(item) {
81
- return MATCHERS[this.operator](getProp(item, ...this.keys), this.value);
82
- }
83
- transform(items) {
84
- return filterItems(items, this);
85
- }
86
- toString() {
87
- return `"${this.filterKey}":${JSON.stringify(this.value)}`;
88
- }
89
- }
@@ -1,27 +0,0 @@
1
- import type { FilterProps } from "./Filter.js";
2
- import type { Data } from "../util/data.js";
3
- import type { Matchable } from "../util/match.js";
4
- import { Constraints } from "./Constraints.js";
5
- import { Filter } from "./Filter.js";
6
- /** A possible set of filters. */
7
- export type PossibleFilters<T extends Data> = Filters<T> | FilterProps<T>;
8
- /** Turn `FilterProps` into a list of `Filter` instances. */
9
- export declare function getFilters<T extends Data>(filters: PossibleFilters<T>): Iterable<Filter<T>>;
10
- /** An object that is filterable. */
11
- export interface Filterable<T extends Data> extends Matchable<[T]> {
12
- /** Add a filter to this filterable. */
13
- filter(filters: PossibleFilters<T>): this;
14
- /** Return a new instance of this class with no filters specified. */
15
- unfiltered: this;
16
- /** Match an item against the filters specified for this object. */
17
- match(item: T): boolean;
18
- }
19
- /** A set of filters. */
20
- export declare class Filters<T extends Data = Data> extends Constraints<T, Filter<T>> implements Filterable<T> {
21
- static from<X extends Data = Data>(filters: PossibleFilters<X>): Filters<X>;
22
- filter(filters: PossibleFilters<T>): this;
23
- get unfiltered(): this;
24
- match(item: T): boolean;
25
- transform(items: Iterable<T>): Iterable<T>;
26
- toString(): string;
27
- }
@@ -1,41 +0,0 @@
1
- import { clearArray } from "../util/array.js";
2
- import { getDataProps } from "../util/data.js";
3
- import { filterItems } from "../util/match.js";
4
- import { cloneObjectWith } from "../util/object.js";
5
- import { Constraints } from "./Constraints.js";
6
- import { Filter } from "./Filter.js";
7
- /** Turn `FilterProps` into a list of `Filter` instances. */
8
- export function* getFilters(filters) {
9
- if (filters instanceof Filters)
10
- yield* filters;
11
- else
12
- for (const [key, value] of getDataProps(filters))
13
- yield new Filter(key, value);
14
- }
15
- /** A set of filters. */
16
- export class Filters extends Constraints {
17
- static from(filters) {
18
- return filters instanceof Filters ? filters : new Filters(...getFilters(filters));
19
- }
20
- // Implement `Filterable`
21
- filter(filters) {
22
- return this.with(...getFilters(filters));
23
- }
24
- get unfiltered() {
25
- return cloneObjectWith(this, "_constraints", clearArray(this._constraints));
26
- }
27
- match(item) {
28
- for (const rule of this._constraints)
29
- if (!rule.match(item))
30
- return false;
31
- return true;
32
- }
33
- // Implement `Rule`
34
- transform(items) {
35
- return this._constraints.length ? filterItems(items, this) : items;
36
- }
37
- // Stringify as object syntax.
38
- toString() {
39
- return this._constraints.length ? `"filters":{${this._constraints.map(String).join(",")}}` : "";
40
- }
41
- }
@@ -1,18 +0,0 @@
1
- import type { Data, FlatDataKey } from "../util/data.js";
2
- import type { Rankable } from "../util/sort.js";
3
- import { Constraint } from "./Constraint.js";
4
- /** 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. */
5
- export type SortKey<T extends Data> = FlatDataKey<T> | `${FlatDataKey<T>}` | `!${FlatDataKey<T>}`;
6
- /** Possible operator references. */
7
- export type SortDirection = "ASC" | "DESC";
8
- /** Sort a list of values. */
9
- export declare class Sort<T extends Data = Data> extends Constraint<T> implements Rankable<T> {
10
- readonly keys: readonly [string, ...string[]];
11
- readonly direction: SortDirection;
12
- get key(): string;
13
- get sortKey(): string;
14
- constructor(sortKey: SortKey<T>);
15
- rank(left: T, right: T): number;
16
- transform(items: Iterable<T>): Iterable<T>;
17
- toString(): string;
18
- }
@@ -1,33 +0,0 @@
1
- import { getProp } from "../util/object.js";
2
- import { rank, rankAsc, rankDesc, sortItems } from "../util/sort.js";
3
- import { splitString } from "../util/string.js";
4
- import { Constraint } from "./Constraint.js";
5
- /** Sort a list of values. */
6
- export class Sort extends Constraint {
7
- get key() {
8
- return this.keys.join(".");
9
- }
10
- get sortKey() {
11
- return `"${this.direction === "DESC" ? "!" : ""}${this.key}"`;
12
- }
13
- constructor(sortKey) {
14
- super();
15
- if (sortKey.startsWith("!")) {
16
- this.keys = splitString(sortKey.slice(1), ".");
17
- this.direction = "DESC";
18
- }
19
- else {
20
- this.keys = splitString(sortKey, ".");
21
- this.direction = "ASC";
22
- }
23
- }
24
- rank(left, right) {
25
- return rank(getProp(left, ...this.keys), this.direction === "ASC" ? rankAsc : rankDesc, getProp(right, ...this.keys));
26
- }
27
- transform(items) {
28
- return sortItems(items, this);
29
- }
30
- toString() {
31
- return this.sortKey;
32
- }
33
- }
@@ -1,26 +0,0 @@
1
- import type { SortKey } from "./Sort.js";
2
- import type { ImmutableArray } from "../util/array.js";
3
- import type { Data } from "../util/data.js";
4
- import type { Rankable } from "../util/sort.js";
5
- import { Constraints } from "./Constraints.js";
6
- import { Sort } from "./Sort.js";
7
- /** A possible set of sorts. */
8
- export type PossibleSorts<T extends Data> = Sorts<T> | SortKey<T> | Iterable<SortKey<T>> | ImmutableArray<SortKey<T>>;
9
- /** Turn `SortList` into array of list of `Sort` instances. */
10
- export declare function getSorts<T extends Data>(sorts: PossibleSorts<T>): Iterable<Sort<T>>;
11
- /** An object that is sortable. */
12
- export interface Sortable<T extends Data> extends Rankable<T> {
13
- /** Add one or more sorts to this sortable. */
14
- sort(sorts: PossibleSorts<T>): this;
15
- /** Return a new instance of this class with no sorts specified. */
16
- unsorted: this;
17
- }
18
- /** A set of sorts. */
19
- export declare class Sorts<T extends Data = Data> extends Constraints<T, Sort<T>> implements Sortable<T> {
20
- static from<X extends Data>(sorts: PossibleSorts<X>): Sorts<X>;
21
- sort(sorts: PossibleSorts<T>): this;
22
- get unsorted(): this;
23
- rank(left: T, right: T): number;
24
- transform(items: Iterable<T>): Iterable<T>;
25
- toString(): string;
26
- }
@@ -1,47 +0,0 @@
1
- import { clearArray } from "../util/array.js";
2
- import { cloneObjectWith } from "../util/object.js";
3
- import { sortItems } from "../util/sort.js";
4
- import { Constraints } from "./Constraints.js";
5
- import { Sort } from "./Sort.js";
6
- /** Turn `SortList` into array of list of `Sort` instances. */
7
- export function* getSorts(sorts) {
8
- if (sorts instanceof Sorts) {
9
- yield* sorts;
10
- }
11
- else if (typeof sorts === "string") {
12
- yield new Sort(sorts);
13
- }
14
- else {
15
- for (const sort of sorts)
16
- yield new Sort(sort);
17
- }
18
- }
19
- /** A set of sorts. */
20
- export class Sorts extends Constraints {
21
- static from(sorts) {
22
- return sorts instanceof Sorts ? sorts : new Sorts(...getSorts(sorts));
23
- }
24
- // Implement `Sortable`
25
- sort(sorts) {
26
- return this.with(...getSorts(sorts));
27
- }
28
- get unsorted() {
29
- return cloneObjectWith(this, "_constraints", clearArray(this._constraints));
30
- }
31
- rank(left, right) {
32
- for (const rule of this._constraints) {
33
- const l = rule.rank(left, right);
34
- if (l !== 0)
35
- return l;
36
- }
37
- return 0;
38
- }
39
- // Implement `Rule`
40
- transform(items) {
41
- return this._constraints.length ? sortItems(items, this) : items;
42
- }
43
- // Stringify as array syntax.
44
- toString() {
45
- return this._constraints.length ? `"sorts":[${this._constraints.map(String).join(",")}]` : "";
46
- }
47
- }
@@ -1,45 +0,0 @@
1
- import type { Filterable, PossibleFilters } from "./Filters.js";
2
- import type { PossibleSorts, Sortable } from "./Sorts.js";
3
- import type { Data } from "../util/data.js";
4
- import { Constraint } from "./Constraint.js";
5
- import { Filters } from "./Filters.js";
6
- import { Sorts } from "./Sorts.js";
7
- /** Interface that combines Filterable, Sortable, Sliceable. */
8
- export interface Queryable<T extends Data> extends Filterable<T>, Sortable<T> {
9
- /**
10
- * Return a new instance of this class with an after offset defined.
11
- * - Offset are based on the sort orders the collection's query uses.
12
- * - Every key used for sorting (e.g. `date, title` must be defined in `item`
13
- *
14
- * @throws AssertionError if this query currently has no sort orders.
15
- * @throws AssertionError if the input `item` did not contain a sorted value.
16
- */
17
- after(item: T): this;
18
- /** Return a new instance of this class with a before offset defined. */
19
- before(item: T): this;
20
- /** The maximum number of items allowed by the limit. */
21
- readonly limit: number | null;
22
- /** Return a new instance of this class with no limit specified. */
23
- readonly unlimited: this;
24
- /** Return a new instance of this class with a limit set. */
25
- max(max: number | null): this;
26
- }
27
- /** Allows filtering, sorting, and limiting on a set of results. */
28
- export declare class Statement<T extends Data = Data> extends Constraint<T> implements Queryable<T> {
29
- readonly filters: Filters<T>;
30
- readonly sorts: Sorts<T>;
31
- readonly limit: number | null;
32
- constructor(filters?: PossibleFilters<T>, sorts?: PossibleSorts<T>, limit?: number | null);
33
- filter(filters: PossibleFilters<T>): this;
34
- get unfiltered(): this;
35
- match(item: T): boolean;
36
- sort(sorts: PossibleSorts<T>): this;
37
- get unsorted(): this;
38
- rank(left: T, right: T): number;
39
- after(item: T): this;
40
- before(item: T): this;
41
- get unlimited(): this;
42
- max(limit: number | null): this;
43
- transform(items: Iterable<T>): Iterable<T>;
44
- toString(): string;
45
- }
@@ -1,79 +0,0 @@
1
- import { limitArray } from "../util/array.js";
2
- import { assert } from "../util/assert.js";
3
- import { cloneObjectWith, getProp } from "../util/object.js";
4
- import { Constraint } from "./Constraint.js";
5
- import { Filter } from "./Filter.js";
6
- import { Filters } from "./Filters.js";
7
- import { Sorts } from "./Sorts.js";
8
- // Instances to save resources for the default case (empty query).
9
- const EMPTY_FILTERS = new Filters(); // eslint-disable-line @typescript-eslint/no-explicit-any
10
- const EMPTY_SORTS = new Sorts(); // eslint-disable-line @typescript-eslint/no-explicit-any
11
- /** Allows filtering, sorting, and limiting on a set of results. */
12
- export class Statement extends Constraint {
13
- constructor(filters = EMPTY_FILTERS, sorts = EMPTY_SORTS, limit = null) {
14
- super();
15
- this.filters = Filters.from(filters);
16
- this.sorts = Sorts.from(sorts);
17
- this.limit = limit;
18
- }
19
- // Implement `Filterable`
20
- filter(filters) {
21
- return cloneObjectWith(this, "filters", this.filters.filter(filters));
22
- }
23
- get unfiltered() {
24
- return cloneObjectWith(this, "filters", this.filters.unfiltered);
25
- }
26
- match(item) {
27
- return this.filters.match(item);
28
- }
29
- // Implement `Sortable`
30
- sort(sorts) {
31
- return cloneObjectWith(this, "sorts", this.sorts.sort(sorts));
32
- }
33
- get unsorted() {
34
- return cloneObjectWith(this, "sorts", this.sorts.unsorted);
35
- }
36
- rank(left, right) {
37
- return this.sorts.rank(left, right);
38
- }
39
- // Implement `Queryable`
40
- after(item) {
41
- return cloneObjectWith(this, "filters", this.filters.with(..._getAfterFilters(this.sorts, item)));
42
- }
43
- before(item) {
44
- return cloneObjectWith(this, "filters", this.filters.with(..._getBeforeFilters(this.sorts, item)));
45
- }
46
- get unlimited() {
47
- return this.max(null);
48
- }
49
- max(limit) {
50
- return cloneObjectWith(this, "limit", limit);
51
- }
52
- // Implement `Rule`
53
- transform(items) {
54
- const sorted = this.sorts.transform(this.filters.transform(items));
55
- return typeof this.limit === "number" ? limitArray(sorted, this.limit) : sorted;
56
- }
57
- // Implement toString()
58
- toString() {
59
- return [this.filters.toString(), this.sorts.toString(), typeof this.limit === "number" ? `"limit":${this.limit}` : null].filter(Boolean).join(",");
60
- }
61
- }
62
- function* _getAfterFilters(sorts, item) {
63
- const lastSort = sorts.last;
64
- assert(lastSort);
65
- for (const sort of sorts) {
66
- const { key, keys, direction } = sort;
67
- const filterKey = (direction === "ASC" ? (sort === lastSort ? `${key}>` : `${key}>=`) : sort === lastSort ? `${key}<` : `${key}<=`);
68
- yield new Filter(filterKey, getProp(item, ...keys));
69
- }
70
- }
71
- function* _getBeforeFilters(sorts, item) {
72
- const lastSort = sorts.last;
73
- assert(lastSort);
74
- for (const sort of sorts) {
75
- const { key, keys, direction } = sort;
76
- const filterKey = (direction === "ASC" ? (sort === lastSort ? `${key}<` : `${key}<=`) : sort === lastSort ? `${key}>` : `${key}>=`);
77
- yield new Filter(filterKey, getProp(item, ...keys));
78
- }
79
- }
@@ -1,7 +0,0 @@
1
- export * from "./Constraint.js";
2
- export * from "./Constraints.js";
3
- export * from "./Filter.js";
4
- export * from "./Filters.js";
5
- export * from "./Sort.js";
6
- export * from "./Sorts.js";
7
- export * from "./Statement.js";
@@ -1,7 +0,0 @@
1
- export * from "./Constraint.js";
2
- export * from "./Constraints.js";
3
- export * from "./Filter.js";
4
- export * from "./Filters.js";
5
- export * from "./Sort.js";
6
- export * from "./Sorts.js";
7
- export * from "./Statement.js";
@@ -1,64 +0,0 @@
1
- import type { AddChange, DeleteChange, SetChange, UpdateChange } from "./Change.js";
2
- import type { ItemData, ItemValue } from "./Item.js";
3
- import type { PossibleFilters } from "../constraint/Filters.js";
4
- import type { PossibleSorts } from "../constraint/Sorts.js";
5
- import type { AsyncProvider, Provider } from "../provider/Provider.js";
6
- import type { Updates } from "../update/DataUpdate.js";
7
- import type { Data } from "../util/data.js";
8
- import { AsyncItem, Item } from "./Item.js";
9
- import { AsyncQuery, Query } from "./Query.js";
10
- /** Reference to a collection in a synchronous or asynchronous provider. */
11
- declare abstract class BaseCollection<T extends Data = Data> {
12
- abstract readonly provider: Provider | AsyncProvider;
13
- abstract readonly collection: string;
14
- /** Create a query on this item's collection. */
15
- abstract query(filters?: PossibleFilters<ItemData<T>>, sorts?: PossibleSorts<ItemData<T>>, limit?: number | null): Query<T> | AsyncQuery<T>;
16
- /** Create a query on this item's collection. */
17
- abstract item(id: string): Item<T> | AsyncItem<T>;
18
- /** Get an item from this collection. */
19
- abstract get(id: string): ItemValue<T> | Promise<ItemValue<T>>;
20
- /** Add an item to this collection. */
21
- abstract add(data: T): string | Promise<string>;
22
- /** Set a document in this collection. */
23
- abstract set(id: string, data: T): void | Promise<void>;
24
- /** Update a document in this collection. */
25
- abstract update(id: string, updates: Updates<T>): void | Promise<void>;
26
- /** Delete a document in this collection. */
27
- abstract delete(id: string): void | Promise<void>;
28
- /** Get an add change for this collection. */
29
- getAdd(data: T): AddChange<T>;
30
- /** Get a set change for this collection. */
31
- getSet(id: string, data: T): SetChange<T>;
32
- /** Get an update change for this collection. */
33
- getUpdate(id: string, updates: Updates<T>): UpdateChange<T>;
34
- /** Get a delete change for this collection. */
35
- getDelete(id: string): DeleteChange;
36
- toString(): string;
37
- }
38
- /** Reference to a collection in a synchronous provider. */
39
- export declare class Collection<T extends Data = Data> extends BaseCollection<T> {
40
- readonly provider: Provider;
41
- readonly collection: string;
42
- constructor(provider: Provider, collection: string);
43
- query(filters?: PossibleFilters<ItemData<T>>, sorts?: PossibleSorts<ItemData<T>>, limit?: number | null): Query<T>;
44
- item(id: string): Item<T>;
45
- get(id: string): ItemValue<T>;
46
- add(data: T): string;
47
- set(id: string, data: T): void;
48
- update(id: string, updates: Updates<T>): void;
49
- delete(id: string): void;
50
- }
51
- /** Reference to a collection in an asynchronous provider. */
52
- export declare class AsyncCollection<T extends Data = Data> extends BaseCollection<T> {
53
- readonly provider: AsyncProvider;
54
- readonly collection: string;
55
- constructor(provider: AsyncProvider, collection: string);
56
- query(filters?: PossibleFilters<ItemData<T>>, sorts?: PossibleSorts<ItemData<T>>, limit?: number | null): AsyncQuery<T>;
57
- item(id: string): AsyncItem<T>;
58
- get(id: string): Promise<ItemValue<T>>;
59
- add(data: T): Promise<string>;
60
- set(id: string, data: T): Promise<void>;
61
- update(id: string, updates: Updates<T>): Promise<void>;
62
- delete(id: string): Promise<void>;
63
- }
64
- export {};
package/db/Collection.js DELETED
@@ -1,83 +0,0 @@
1
- import { AsyncItem, Item } from "./Item.js";
2
- import { AsyncQuery, Query } from "./Query.js";
3
- /** Reference to a collection in a synchronous or asynchronous provider. */
4
- class BaseCollection {
5
- /** Get an add change for this collection. */
6
- getAdd(data) {
7
- return { action: "ADD", collection: this.collection, data };
8
- }
9
- /** Get a set change for this collection. */
10
- getSet(id, data) {
11
- return { action: "SET", collection: this.collection, id, data };
12
- }
13
- /** Get an update change for this collection. */
14
- getUpdate(id, updates) {
15
- return { action: "UPDATE", collection: this.collection, id, updates };
16
- }
17
- /** Get a delete change for this collection. */
18
- getDelete(id) {
19
- return { action: "DELETE", collection: this.collection, id };
20
- }
21
- // Implement toString()
22
- toString() {
23
- return this.collection;
24
- }
25
- }
26
- /** Reference to a collection in a synchronous provider. */
27
- export class Collection extends BaseCollection {
28
- constructor(provider, collection) {
29
- super();
30
- this.provider = provider;
31
- this.collection = collection;
32
- }
33
- query(filters, sorts, limit) {
34
- return new Query(this.provider, this.collection, filters, sorts, limit);
35
- }
36
- item(id) {
37
- return new Item(this.provider, this.collection, id);
38
- }
39
- get(id) {
40
- return this.provider.getItem(this.collection, id);
41
- }
42
- add(data) {
43
- return this.provider.addItem(this.collection, data);
44
- }
45
- set(id, data) {
46
- return this.provider.setItem(this.collection, id, data);
47
- }
48
- update(id, updates) {
49
- return this.provider.updateItem(this.collection, id, updates);
50
- }
51
- delete(id) {
52
- return this.provider.deleteItem(this.collection, id);
53
- }
54
- }
55
- /** Reference to a collection in an asynchronous provider. */
56
- export class AsyncCollection extends BaseCollection {
57
- constructor(provider, collection) {
58
- super();
59
- this.provider = provider;
60
- this.collection = collection;
61
- }
62
- query(filters, sorts, limit) {
63
- return new AsyncQuery(this.provider, this.collection, filters, sorts, limit);
64
- }
65
- item(id) {
66
- return new AsyncItem(this.provider, this.collection, id);
67
- }
68
- get(id) {
69
- return this.provider.getItem(this.collection, id);
70
- }
71
- add(data) {
72
- return this.provider.addItem(this.collection, data);
73
- }
74
- set(id, data) {
75
- return this.provider.setItem(this.collection, id, data);
76
- }
77
- update(id, updates) {
78
- return this.provider.updateItem(this.collection, id, updates);
79
- }
80
- delete(id) {
81
- return this.provider.deleteItem(this.collection, id);
82
- }
83
- }