shelving 1.76.1 → 1.78.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 (42) hide show
  1. package/constraint/Constraints.d.ts +1 -1
  2. package/constraint/FilterConstraint.d.ts +6 -6
  3. package/constraint/FilterConstraint.js +1 -1
  4. package/constraint/FilterConstraints.d.ts +5 -5
  5. package/constraint/QueryConstraints.d.ts +4 -4
  6. package/constraint/QueryConstraints.js +2 -2
  7. package/constraint/SortConstraint.d.ts +4 -3
  8. package/constraint/SortConstraint.js +2 -3
  9. package/constraint/SortConstraints.d.ts +5 -5
  10. package/db/Change.d.ts +10 -13
  11. package/db/Change.js +2 -2
  12. package/db/Collection.d.ts +3 -3
  13. package/db/Database.d.ts +12 -12
  14. package/db/Item.d.ts +5 -5
  15. package/db/Item.js +3 -5
  16. package/db/Query.d.ts +6 -6
  17. package/db/Query.js +2 -3
  18. package/firestore/client/FirestoreClientProvider.d.ts +3 -3
  19. package/firestore/client/FirestoreClientProvider.js +4 -4
  20. package/firestore/lite/FirestoreLiteProvider.d.ts +3 -3
  21. package/firestore/lite/FirestoreLiteProvider.js +4 -4
  22. package/firestore/server/FirestoreServerProvider.d.ts +3 -3
  23. package/firestore/server/FirestoreServerProvider.js +4 -4
  24. package/package.json +5 -5
  25. package/provider/CacheProvider.d.ts +3 -3
  26. package/provider/CacheProvider.js +6 -6
  27. package/provider/DebugProvider.d.ts +5 -5
  28. package/provider/DebugProvider.js +12 -12
  29. package/provider/MemoryProvider.d.ts +5 -5
  30. package/provider/MemoryProvider.js +9 -8
  31. package/provider/Provider.d.ts +7 -7
  32. package/provider/ThroughProvider.d.ts +5 -5
  33. package/provider/ThroughProvider.js +4 -4
  34. package/provider/ValidationProvider.d.ts +11 -11
  35. package/provider/ValidationProvider.js +29 -28
  36. package/react/useItem.d.ts +7 -7
  37. package/react/useQuery.d.ts +10 -10
  38. package/schema/DataSchema.d.ts +5 -1
  39. package/state/DataState.d.ts +3 -3
  40. package/update/DataUpdate.d.ts +15 -7
  41. package/update/DataUpdate.js +28 -21
  42. package/util/transform.d.ts +3 -3
@@ -2,7 +2,7 @@ import type { Data } from "../util/data.js";
2
2
  import { ImmutableArray } from "../util/array.js";
3
3
  import { Constraint } from "./Constraint.js";
4
4
  /** Type of Rule that is powered by several sub-constraints (e.g. `Filters` and `Sorts` and `Query` itself extend this). */
5
- export declare abstract class Constraints<T extends Data, C extends Constraint<T>> extends Constraint<T> implements Iterable<C> {
5
+ export declare abstract class Constraints<T extends Data, C extends Constraint<Partial<T>>> extends Constraint<T> implements Iterable<C> {
6
6
  protected readonly _constraints: ImmutableArray<C>;
7
7
  /** Get the first constraint. */
8
8
  get first(): C | undefined;
@@ -1,8 +1,8 @@
1
- import { ArrayType, ImmutableArray } from "../util/array.js";
2
- import { Data, Key } from "../util/data.js";
1
+ import type { Data, Key } from "../util/data.js";
2
+ import type { Nullish } from "../util/null.js";
3
+ import { ImmutableArray } from "../util/array.js";
3
4
  import { Matchable } from "../util/match.js";
4
- import { NotString } from "../util/string.js";
5
- import { Constraint } from "./Constraint.js";
5
+ import type { Constraint } from "./Constraint.js";
6
6
  /** Possible operator references. */
7
7
  export declare 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` */
@@ -11,12 +11,12 @@ export declare type FilterKey<T extends Data> = Key<T> | `${Key<T>}` | `!${Key<T
11
11
  export declare type FilterProps<T extends Data> = {
12
12
  [K in Key<T> as `${K}` | `!${K}`]?: T[K] | ImmutableArray<T[K]>;
13
13
  } & {
14
- [K in Key<T> as `${K}[]`]?: T[K] extends ImmutableArray ? ArrayType<T[K]> : never;
14
+ [K in Key<T> as `${K}[]`]?: Required<T>[K] extends ImmutableArray<infer X> ? X : never;
15
15
  } & {
16
16
  [K in Key<T> as `${K}<` | `${K}<=` | `${K}>` | `${K}>=`]?: T[K];
17
17
  };
18
18
  /** List of filters in a flexible format. */
19
- export declare type FilterList<T extends Data> = FilterProps<T> | FilterConstraint<T> | Iterable<FilterList<T> & NotString>;
19
+ export declare 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
  *
@@ -89,7 +89,7 @@ export function* getFilters(filters) {
89
89
  for (const filter of filters)
90
90
  yield* getFilters(filter);
91
91
  }
92
- else {
92
+ else if (filters) {
93
93
  for (const [key, value] of Object.entries(filters))
94
94
  yield new FilterConstraint(key, value);
95
95
  }
@@ -1,6 +1,6 @@
1
1
  import type { Data } from "../util/data.js";
2
2
  import type { Matchable } from "../util/match.js";
3
- import { FilterList, FilterProps, FilterConstraint } from "./FilterConstraint.js";
3
+ import { FilterList, FilterConstraint } from "./FilterConstraint.js";
4
4
  import { Constraints } from "./Constraints.js";
5
5
  /**
6
6
  * Interface to make sure an object implements all matchers.
@@ -8,14 +8,14 @@ import { Constraints } from "./Constraints.js";
8
8
  */
9
9
  export interface Filterable<T extends Data> extends Matchable<T, void> {
10
10
  /** Add a filter to this filterable. */
11
- filter(props: FilterProps<T>): this;
11
+ filter(...filters: FilterList<Partial<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<T>> implements Filterable<T> {
17
- constructor(...filters: FilterList<T>[]);
18
- filter(...filters: FilterList<T>[]): this;
16
+ export declare class FilterConstraints<T extends Data = Data> extends Constraints<T, FilterConstraint<Partial<T>>> implements Filterable<T> {
17
+ constructor(...filters: FilterList<Partial<T>>[]);
18
+ filter(...filters: FilterList<Partial<T>>[]): this;
19
19
  match(item: T): boolean;
20
20
  transform(items: Iterable<T>): Iterable<T>;
21
21
  toString(): string;
@@ -3,7 +3,7 @@ import { Filterable, FilterConstraints } from "./FilterConstraints.js";
3
3
  import { Sortable, SortConstraints } from "./SortConstraints.js";
4
4
  import { Constraint } from "./Constraint.js";
5
5
  import { FilterList } from "./FilterConstraint.js";
6
- import { SortKeys, SortList } from "./SortConstraint.js";
6
+ import { SortList } from "./SortConstraint.js";
7
7
  /** Interface that combines Filterable, Sortable, Sliceable. */
8
8
  export interface Queryable<T extends Data> extends Filterable<T>, Sortable<T> {
9
9
  /**
@@ -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<T>, sorts?: SortList<T>, limit?: number | null);
35
- filter(...filters: FilterList<T>[]): this;
34
+ constructor(filters?: FilterList<Partial<T>>, sorts?: SortList<Partial<T>>, limit?: number | null);
35
+ filter(...filters: FilterList<Partial<T>>[]): this;
36
36
  get unfilter(): this;
37
37
  match(item: T): boolean;
38
- sort(...keys: SortKeys<T>[]): this;
38
+ sort(...sorts: SortList<Partial<T>>[]): this;
39
39
  get unsort(): this;
40
40
  rank(left: T, right: T): number;
41
41
  after(item: T): this;
@@ -37,11 +37,11 @@ export class QueryConstraints extends Constraint {
37
37
  return this.filters.match(item);
38
38
  }
39
39
  // Implement `Sortable`
40
- sort(...keys) {
40
+ sort(...sorts) {
41
41
  return {
42
42
  __proto__: Object.getPrototypeOf(this),
43
43
  ...this,
44
- sorts: this.sorts.sort(...keys),
44
+ sorts: this.sorts.sort(...sorts),
45
45
  };
46
46
  }
47
47
  get unsort() {
@@ -1,7 +1,8 @@
1
1
  import type { ImmutableArray } from "../util/array.js";
2
- import { Data, Key } from "../util/data.js";
2
+ import type { Data, Key } from "../util/data.js";
3
+ import type { Nullish } from "../util/null.js";
3
4
  import { Rankable } from "../util/sort.js";
4
- import { Constraint } from "./Constraint.js";
5
+ import type { Constraint } from "./Constraint.js";
5
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. */
6
7
  export declare type SortKey<T extends Data> = Key<T> | `${Key<T>}` | `!${Key<T>}`;
7
8
  /** One or more sort keys. */
@@ -9,7 +10,7 @@ export declare type SortKeys<T extends Data> = SortKey<T> | ImmutableArray<SortK
9
10
  /** Possible operator references. */
10
11
  export declare type SortDirection = "ASC" | "DESC";
11
12
  /** List of sorts in a flexible format. */
12
- export declare type SortList<T extends Data> = SortKeys<T> | SortConstraint<T> | Iterable<SortList<T>>;
13
+ export declare type SortList<T extends Data> = Nullish<SortKeys<T> | SortConstraint<T> | Iterable<SortList<T>>>;
13
14
  /** Sort a list of values. */
14
15
  export declare class SortConstraint<T extends Data = Data> implements Constraint<T>, Rankable<T> {
15
16
  readonly key: string;
@@ -1,4 +1,3 @@
1
- import { getProp } from "../util/data.js";
2
1
  import { rank, rankAsc, rankDesc, sortItems } from "../util/sort.js";
3
2
  /** Sort a list of values. */
4
3
  export class SortConstraint {
@@ -16,7 +15,7 @@ export class SortConstraint {
16
15
  return `"${this.direction === "DESC" ? "!" : ""}${this.key}"`;
17
16
  }
18
17
  rank(left, right) {
19
- return rank(getProp(left, this.key), this.direction === "ASC" ? rankAsc : rankDesc, getProp(right, this.key));
18
+ return rank(left[this.key], this.direction === "ASC" ? rankAsc : rankDesc, right[this.key]);
20
19
  }
21
20
  transform(items) {
22
21
  return sortItems(items, this);
@@ -33,7 +32,7 @@ export function* getSorts(sorts) {
33
32
  else if (sorts instanceof SortConstraint) {
34
33
  yield sorts;
35
34
  }
36
- else {
35
+ else if (sorts) {
37
36
  for (const sort of sorts)
38
37
  yield* getSorts(sort);
39
38
  }
@@ -1,19 +1,19 @@
1
1
  import type { Data } from "../util/data.js";
2
2
  import { Rankable } from "../util/sort.js";
3
3
  import { Constraints } from "./Constraints.js";
4
- import { SortConstraint, SortKeys, SortList } from "./SortConstraint.js";
4
+ import { SortConstraint, SortList } from "./SortConstraint.js";
5
5
  /**
6
6
  * Interface to make sure an object implements all directions.
7
7
  * - Extends `Rankable` so this object itself can be directly be used with `filterItems()` and `filterEntries()`
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: SortKeys<T>[]): this;
11
+ sort(...keys: SortList<Partial<T>>[]): this;
12
12
  }
13
13
  /** A set of sorts. */
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;
14
+ export declare class SortConstraints<T extends Data = Data> extends Constraints<T, SortConstraint<Partial<T>>> implements Sortable<T> {
15
+ constructor(...sorts: SortList<Partial<T>>[]);
16
+ sort(...sorts: SortList<Partial<T>>[]): this;
17
17
  rank(left: T, right: T): number;
18
18
  transform(items: Iterable<T>): Iterable<T>;
19
19
  toString(): string;
package/db/Change.d.ts CHANGED
@@ -1,38 +1,35 @@
1
- import type { Data, Datas, Key, Value } from "../util/data.js";
1
+ import type { Data, Datas, Key } from "../util/data.js";
2
2
  import type { ImmutableArray } from "../util/array.js";
3
3
  import type { Provider, AsyncProvider } from "../provider/Provider.js";
4
- import { DataUpdate } from "../update/DataUpdate.js";
4
+ import { Updates } from "../update/DataUpdate.js";
5
5
  import { Nullish } from "../util/null.js";
6
6
  import { DeepIterable } from "../util/iterate.js";
7
7
  import type { ItemConstraints, ItemData } from "./Item.js";
8
- export interface Change<T extends Datas> {
8
+ /** Change on a collection. */
9
+ export interface Change<T extends Datas, K extends Key<T> = Key<T>> {
9
10
  readonly action: string;
10
- readonly collection: Key<T>;
11
+ readonly collection: K;
11
12
  }
12
13
  /** Add on an item. */
13
- export interface AddChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
14
+ export interface AddChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
14
15
  readonly action: "ADD";
15
- readonly collection: K;
16
16
  readonly data: T[K];
17
17
  }
18
18
  /** Set on an item. */
19
- export interface SetChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
19
+ export interface SetChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
20
20
  readonly action: "SET";
21
- readonly collection: K;
22
21
  readonly id: string;
23
22
  readonly data: T[K];
24
23
  }
25
24
  /** Update change on an item. */
26
- export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
25
+ export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
27
26
  readonly action: "UPDATE";
28
- readonly collection: K;
29
27
  readonly id: string;
30
- readonly update: DataUpdate<Value<T>>;
28
+ readonly updates: Updates<T[K]>;
31
29
  }
32
30
  /** Delete change on an item. */
33
- export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
31
+ export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T, K> {
34
32
  readonly action: "DELETE";
35
- readonly collection: K;
36
33
  readonly id: string;
37
34
  }
38
35
  /** Set, update, or delete change on an item. */
package/db/Change.js CHANGED
@@ -13,7 +13,7 @@ function _changeItem(change) {
13
13
  else if (action === "SET")
14
14
  this.setItem(collection, change.id, change.data);
15
15
  else if (action === "UPDATE")
16
- this.updateQuery(collection, _getItemConstraint(change.id), change.update);
16
+ this.updateQuery(collection, _getItemConstraint(change.id), change.updates);
17
17
  else if (action === "DELETE")
18
18
  this.deleteItem(collection, change.id);
19
19
  return change;
@@ -29,7 +29,7 @@ async function _changeAsyncItem(change) {
29
29
  else if (action === "SET")
30
30
  await this.setItem(collection, change.id, change.data);
31
31
  else if (action === "UPDATE")
32
- await this.updateQuery(collection, _getItemConstraint(change.id), change.update);
32
+ await this.updateQuery(collection, _getItemConstraint(change.id), change.updates);
33
33
  else if (action === "DELETE")
34
34
  await this.deleteItem(collection, change.id);
35
35
  return change;
@@ -12,7 +12,7 @@ declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T>
12
12
  abstract readonly db: Database<T> | AsyncDatabase<T>;
13
13
  abstract readonly collection: K;
14
14
  /** Create a query on this item's collection. */
15
- abstract query(filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
15
+ abstract query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
16
16
  /** Create a query on this item's collection. */
17
17
  abstract item(id: string): Item<T, K> | AsyncItem<T, K>;
18
18
  /** Add an item to this collection. */
@@ -28,7 +28,7 @@ export declare class Collection<T extends Datas = Datas, K extends Key<T> = Key<
28
28
  readonly db: Database<T>;
29
29
  readonly collection: K;
30
30
  constructor(db: Database<T>, collection: K);
31
- query(filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T, K>;
31
+ query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
32
32
  item(id: string): Item<T, K>;
33
33
  add(data: T[K]): string;
34
34
  change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
@@ -38,7 +38,7 @@ export declare class AsyncCollection<T extends Datas = Datas, K extends Key<T> =
38
38
  readonly db: AsyncDatabase<T>;
39
39
  readonly collection: K;
40
40
  constructor(db: AsyncDatabase<T>, collection: K);
41
- query(filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<T, K>;
41
+ query(filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
42
42
  item(id: string): AsyncItem<T, K>;
43
43
  add(data: T[K]): Promise<string>;
44
44
  change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
package/db/Database.d.ts CHANGED
@@ -13,30 +13,30 @@ import { ItemChanges, WriteChange } from "./Change.js";
13
13
  declare abstract class BaseDatabase<T extends Datas> {
14
14
  abstract readonly provider: Provider<T> | AsyncProvider<T>;
15
15
  /** Create a query on a collection in this database. */
16
- abstract collection<K extends Key<T>>(collection: K): Collection<Pick<T, K>, K> | AsyncCollection<Pick<T, K>, K>;
16
+ abstract collection<K extends Key<T>>(collection: K): Collection<T, K> | AsyncCollection<T, K>;
17
17
  /** Create a query on a collection in this database. */
18
- abstract query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<Pick<T, K>, K> | AsyncQuery<Pick<T, K>, K>;
18
+ abstract query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K> | AsyncQuery<T, K>;
19
19
  /** Reference an item in a collection in this database. */
20
- abstract item<K extends Key<T>>(collection: K, id: string): Item<Pick<T, K>, K> | AsyncItem<Pick<T, K>, K>;
20
+ abstract item<K extends Key<T>>(collection: K, id: string): Item<T, K> | AsyncItem<T, K>;
21
21
  /** Run a set of changes on this database. */
22
- abstract change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<Pick<T, K>, K>>>[]): ItemChanges<Pick<T, K>, K> | Promise<ItemChanges<Pick<T, K>, K>>;
22
+ abstract change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T> | Promise<ItemChanges<T>>;
23
23
  }
24
24
  /** Database with a synchronous provider. */
25
25
  export declare class Database<T extends Datas = Datas> implements BaseDatabase<T> {
26
26
  readonly provider: Provider<T>;
27
27
  constructor(provider: Provider<T>);
28
- collection<K extends Key<T>>(collection: K): Collection<Pick<T, K>, K>;
29
- query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<Pick<T, K>, K>;
30
- item<K extends Key<T>>(collection: K, id: string): Item<Pick<T, K>, K>;
31
- change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<Pick<T, K>, K>>>[]): ItemChanges<Pick<T, K>, K>;
28
+ collection<K extends Key<T>>(collection: K): Collection<T, K>;
29
+ query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): Query<T, K>;
30
+ item<K extends Key<T>>(collection: K, id: string): Item<T, K>;
31
+ change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): ItemChanges<T>;
32
32
  }
33
33
  /** Database with a synchronous provider. */
34
34
  export declare class AsyncDatabase<T extends Datas = Datas> implements BaseDatabase<T> {
35
35
  readonly provider: AsyncProvider<T>;
36
36
  constructor(provider: AsyncProvider<T>);
37
- collection<K extends Key<T>>(collection: K): AsyncCollection<Pick<T, K>, K>;
38
- query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<Pick<T, K>, K>;
39
- item<K extends Key<T>>(collection: K, id: string): AsyncItem<Pick<T, K>, K>;
40
- change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<Pick<T, K>, K>>>[]): Promise<ItemChanges<Pick<T, K>, K>>;
37
+ collection<K extends Key<T>>(collection: K): AsyncCollection<T, K>;
38
+ query<K extends Key<T>>(collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null): AsyncQuery<T, K>;
39
+ item<K extends Key<T>>(collection: K, id: string): AsyncItem<T, K>;
40
+ change(...changes: DeepIterable<Nullish<WriteChange<T>>>[]): Promise<ItemChanges<T>>;
41
41
  }
42
42
  export {};
package/db/Item.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { Dispatch } from "../util/function.js";
3
3
  import type { PartialObserver } from "../observe/Observer.js";
4
4
  import type { ImmutableArray } from "../util/array.js";
5
5
  import type { Observable, Unsubscribe } from "../observe/Observable.js";
6
- import { DataUpdate, PropUpdates } from "../update/DataUpdate.js";
6
+ import { DataUpdate, Updates } from "../update/DataUpdate.js";
7
7
  import type { QueryConstraints } from "../constraint/QueryConstraints.js";
8
8
  import type { AsyncDatabase, Database } from "./Database.js";
9
9
  import type { AsyncQuery, Query } from "./Query.js";
@@ -54,13 +54,13 @@ declare abstract class BaseItem<T extends Datas = Datas, K extends Key<T> = Key<
54
54
  /** Set the complete data of this item. */
55
55
  abstract set(data: T[K]): void | PromiseLike<void>;
56
56
  /** Update this item. */
57
- abstract update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): void | PromiseLike<void>;
57
+ abstract update(updates: DataUpdate<T[K]> | Updates<T[K]>): void | PromiseLike<void>;
58
58
  /** Delete this item. */
59
59
  abstract delete(): void | PromiseLike<void>;
60
60
  /** Get a set change for this item. */
61
61
  getSet(data: T[K]): SetChange<T, K>;
62
62
  /** Get an update change for this item. */
63
- getUpdate(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): UpdateChange<T, K>;
63
+ getUpdate(updates: Updates<T[K]>): UpdateChange<T, K>;
64
64
  /** Get a delete change for this item. */
65
65
  getDelete(): DeleteChange<T, K>;
66
66
  toString(): `${K}/${string}`;
@@ -76,7 +76,7 @@ export declare class Item<T extends Datas = Datas, K extends Key<T> = Key<T>> ex
76
76
  get value(): ItemValue<T[K]>;
77
77
  get data(): ItemData<T[K]>;
78
78
  set(data: T[K]): void;
79
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): void;
79
+ update(updates: Updates<T[K]>): void;
80
80
  delete(): void;
81
81
  }
82
82
  /** Reference to an item in an asynchronous provider. */
@@ -90,7 +90,7 @@ export declare class AsyncItem<T extends Datas = Datas, K extends Key<T> = Key<T
90
90
  get value(): Promise<ItemValue<T[K]>>;
91
91
  get data(): Promise<ItemData<T[K]>>;
92
92
  set(data: T[K]): Promise<void>;
93
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): Promise<void>;
93
+ update(updates: Updates<T[K]>): Promise<void>;
94
94
  delete(): Promise<void>;
95
95
  }
96
96
  /** Get the ID from item data. */
package/db/Item.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { getData } from "../util/data.js";
2
2
  import { FilterConstraint } from "../constraint/FilterConstraint.js";
3
- import { DataUpdate } from "../update/DataUpdate.js";
4
- import { isTransformable } from "../util/transform.js";
5
3
  /** Reference to an item in a synchronous or asynchronous provider. */
6
4
  class BaseItem {
7
5
  /**
@@ -20,7 +18,7 @@ class BaseItem {
20
18
  }
21
19
  /** Get an update change for this item. */
22
20
  getUpdate(updates) {
23
- return { action: "UPDATE", collection: this.collection, id: this.id, update: updates instanceof DataUpdate ? updates : new DataUpdate(updates) };
21
+ return { action: "UPDATE", collection: this.collection, id: this.id, updates };
24
22
  }
25
23
  /** Get a delete change for this item. */
26
24
  getDelete() {
@@ -55,7 +53,7 @@ export class Item extends BaseItem {
55
53
  return this.db.provider.setItem(this.collection, this.id, data);
56
54
  }
57
55
  update(updates) {
58
- return this.db.provider.updateItem(this.collection, this.id, isTransformable(updates) ? updates : new DataUpdate(updates));
56
+ return this.db.provider.updateItem(this.collection, this.id, updates);
59
57
  }
60
58
  delete() {
61
59
  return this.db.provider.deleteItem(this.collection, this.id);
@@ -85,7 +83,7 @@ export class AsyncItem extends BaseItem {
85
83
  return this.db.provider.setItem(this.collection, this.id, data);
86
84
  }
87
85
  update(updates) {
88
- return this.db.provider.updateItem(this.collection, this.id, isTransformable(updates) ? updates : new DataUpdate(updates));
86
+ return this.db.provider.updateItem(this.collection, this.id, updates);
89
87
  }
90
88
  delete() {
91
89
  return this.db.provider.deleteItem(this.collection, this.id);
package/db/Query.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { Dispatch } from "../util/function.js";
2
2
  import type { Key, Datas } from "../util/data.js";
3
+ import type { Updates } from "../update/DataUpdate.js";
3
4
  import type { PartialObserver } from "../observe/Observer.js";
4
5
  import type { Observable, Unsubscribe } from "../observe/Observable.js";
5
6
  import type { FilterList } from "../constraint/FilterConstraint.js";
6
7
  import type { SortList } from "../constraint/SortConstraint.js";
7
8
  import { QueryConstraints } from "../constraint/QueryConstraints.js";
8
- import { DataUpdate, PropUpdates } from "../update/DataUpdate.js";
9
9
  import type { ItemArray, ItemValue, ItemData } from "./Item.js";
10
10
  import type { AsyncDatabase, Database } from "./Database.js";
11
11
  /** Reference to a set of items in a sync or async provider. */
@@ -68,7 +68,7 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends Key<T> = Key
68
68
  * @param updates `Update` instance or set of updates to apply to every matching item.
69
69
  * @return Nothing (possibly promised).
70
70
  */
71
- abstract update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): number | PromiseLike<number>;
71
+ abstract update(updates: Updates<T[K]>): number | PromiseLike<number>;
72
72
  /**
73
73
  * Delete all matching items.
74
74
  * @return Nothing (possibly promised).
@@ -80,7 +80,7 @@ declare abstract class BaseQuery<T extends Datas = Datas, K extends Key<T> = Key
80
80
  export declare class Query<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseQuery<T, K> implements BaseQuery<T, K> {
81
81
  readonly db: Database<T>;
82
82
  readonly collection: K;
83
- constructor(db: Database<T>, collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null);
83
+ constructor(db: Database<T>, collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null);
84
84
  get value(): ItemArray<T[K]>;
85
85
  get count(): number;
86
86
  get exists(): boolean;
@@ -89,14 +89,14 @@ export declare class Query<T extends Datas = Datas, K extends Key<T> = Key<T>> e
89
89
  get lastValue(): ItemValue<T[K]>;
90
90
  get lastData(): ItemData<T[K]>;
91
91
  set(data: T[K]): number;
92
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): number;
92
+ update(updates: Updates<T[K]>): number;
93
93
  delete(): number;
94
94
  }
95
95
  /** Reference to a set of items in a provider. */
96
96
  export declare class AsyncQuery<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseQuery<T, K> implements BaseQuery<T, K> {
97
97
  readonly db: AsyncDatabase<T>;
98
98
  readonly collection: K;
99
- constructor(db: AsyncDatabase<T>, collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null);
99
+ constructor(db: AsyncDatabase<T>, collection: K, filters?: FilterList<Partial<ItemData<T[K]>>>, sorts?: SortList<Partial<ItemData<T[K]>>>, limit?: number | null);
100
100
  get value(): Promise<ItemArray<T[K]>>;
101
101
  get count(): Promise<number>;
102
102
  get exists(): Promise<boolean>;
@@ -105,7 +105,7 @@ export declare class AsyncQuery<T extends Datas = Datas, K extends Key<T> = Key<
105
105
  get lastValue(): Promise<ItemValue<T[K]>>;
106
106
  get lastData(): Promise<ItemData<T[K]>>;
107
107
  set(data: T[K]): Promise<number>;
108
- update(updates: DataUpdate<T[K]> | PropUpdates<T[K]>): PromiseLike<number>;
108
+ update(updates: Updates<T[K]>): PromiseLike<number>;
109
109
  delete(): PromiseLike<number>;
110
110
  }
111
111
  export {};
package/db/Query.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { getFirstItem, getLastItem, getOptionalFirstItem, getOptionalLastItem } from "../util/array.js";
2
2
  import { QueryConstraints } from "../constraint/QueryConstraints.js";
3
3
  import { countItems, hasItems } from "../util/iterate.js";
4
- import { DataUpdate } from "../update/DataUpdate.js";
5
4
  /** Reference to a set of items in a sync or async provider. */
6
5
  class BaseQuery extends QueryConstraints {
7
6
  /**
@@ -51,7 +50,7 @@ export class Query extends BaseQuery {
51
50
  return this.db.provider.setQuery(this.collection, this, data);
52
51
  }
53
52
  update(updates) {
54
- return this.db.provider.updateQuery(this.collection, this, updates instanceof DataUpdate ? updates : new DataUpdate(updates));
53
+ return this.db.provider.updateQuery(this.collection, this, updates);
55
54
  }
56
55
  delete() {
57
56
  return this.db.provider.deleteQuery(this.collection, this);
@@ -89,7 +88,7 @@ export class AsyncQuery extends BaseQuery {
89
88
  return this.db.provider.setQuery(this.collection, this, data);
90
89
  }
91
90
  update(updates) {
92
- return this.db.provider.updateQuery(this.collection, this, updates instanceof DataUpdate ? updates : new DataUpdate(updates));
91
+ return this.db.provider.updateQuery(this.collection, this, updates);
93
92
  }
94
93
  delete() {
95
94
  return this.db.provider.deleteQuery(this.collection, this);
@@ -4,7 +4,7 @@ import type { Unsubscribe } from "../../observe/Observable.js";
4
4
  import type { AsyncProvider } from "../../provider/Provider.js";
5
5
  import type { ItemArray, ItemValue, ItemConstraints } from "../../db/Item.js";
6
6
  import { Observer, PartialObserver } from "../../observe/Observer.js";
7
- import { DataUpdate } from "../../update/DataUpdate.js";
7
+ import { Updates } from "../../update/DataUpdate.js";
8
8
  /**
9
9
  * Firestore client database provider.
10
10
  * - Works with the Firebase JS SDK.
@@ -18,11 +18,11 @@ export declare class FirestoreClientProvider implements AsyncProvider {
18
18
  subscribeItem(collection: string, id: string, observer: PartialObserver<ItemValue>): Unsubscribe;
19
19
  addItem(collection: string, data: Data): Promise<string>;
20
20
  setItem(collection: string, id: string, data: Data): Promise<void>;
21
- updateItem(collection: string, id: string, update: DataUpdate): Promise<void>;
21
+ updateItem(collection: string, id: string, updates: Updates): Promise<void>;
22
22
  deleteItem(collection: string, id: string): Promise<void>;
23
23
  getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
24
24
  subscribeQuery(collection: string, constraints: ItemConstraints, observer: Observer<ItemArray>): Unsubscribe;
25
25
  setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
26
- updateQuery(collection: string, constraints: ItemConstraints, update: DataUpdate): Promise<number>;
26
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
27
27
  deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
28
28
  }
@@ -101,8 +101,8 @@ export class FirestoreClientProvider {
101
101
  async setItem(collection, id, data) {
102
102
  await setDoc(firestoreDocument(this._firestore, collection, id), data);
103
103
  }
104
- async updateItem(collection, id, update) {
105
- await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(update));
104
+ async updateItem(collection, id, updates) {
105
+ await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(Object.entries(updates)));
106
106
  }
107
107
  async deleteItem(collection, id) {
108
108
  await deleteDoc(firestoreDocument(this._firestore, collection, id));
@@ -118,9 +118,9 @@ export class FirestoreClientProvider {
118
118
  await Promise.all(snapshot.docs.map(s => setDoc(s.ref, data)));
119
119
  return snapshot.size;
120
120
  }
121
- async updateQuery(collection, constraints, update) {
121
+ async updateQuery(collection, constraints, updates) {
122
122
  const snapshot = await getDocs(_getQuery(this._firestore, collection, constraints));
123
- const fieldValues = Array.from(_getFieldValues(update));
123
+ const fieldValues = Array.from(_getFieldValues(Object.entries(updates)));
124
124
  await Promise.all(snapshot.docs.map(s => updateDoc(s.ref, ...fieldValues)));
125
125
  return snapshot.size;
126
126
  }
@@ -3,7 +3,7 @@ import type { Data } from "../../util/data.js";
3
3
  import type { Unsubscribe } from "../../observe/Observable.js";
4
4
  import type { AsyncProvider } from "../../provider/Provider.js";
5
5
  import type { ItemArray, ItemValue, ItemConstraints } from "../../db/Item.js";
6
- import { DataUpdate } from "../../update/DataUpdate.js";
6
+ import { Updates } from "../../update/DataUpdate.js";
7
7
  /**
8
8
  * Firestore Lite client database provider.
9
9
  * - Works with the Firebase JS SDK.
@@ -17,11 +17,11 @@ export declare class FirestoreLiteProvider implements AsyncProvider {
17
17
  subscribeItem(): Unsubscribe;
18
18
  addItem(collection: string, data: Data): Promise<string>;
19
19
  setItem(collection: string, id: string, data: Data): Promise<void>;
20
- updateItem(collection: string, id: string, update: DataUpdate): Promise<void>;
20
+ updateItem(collection: string, id: string, updates: Updates): Promise<void>;
21
21
  deleteItem(collection: string, id: string): Promise<void>;
22
22
  getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
23
23
  subscribeQuery(): Unsubscribe;
24
24
  setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
25
- updateQuery(collection: string, constraints: ItemConstraints, update: DataUpdate): Promise<number>;
25
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
26
26
  deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
27
27
  }
@@ -101,8 +101,8 @@ export class FirestoreLiteProvider {
101
101
  async setItem(collection, id, data) {
102
102
  await setDoc(firestoreDocument(this._firestore, collection, id), data);
103
103
  }
104
- async updateItem(collection, id, update) {
105
- await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(update));
104
+ async updateItem(collection, id, updates) {
105
+ await updateDoc(firestoreDocument(this._firestore, collection, id), ..._getFieldValues(Object.entries(updates)));
106
106
  }
107
107
  async deleteItem(collection, id) {
108
108
  await deleteDoc(firestoreDocument(this._firestore, collection, id));
@@ -118,9 +118,9 @@ export class FirestoreLiteProvider {
118
118
  await Promise.all(snapshot.docs.map(s => setDoc(s.ref, data)));
119
119
  return snapshot.size;
120
120
  }
121
- async updateQuery(collection, constraints, update) {
121
+ async updateQuery(collection, constraints, updates) {
122
122
  const snapshot = await getDocs(_getQuery(this._firestore, collection, constraints));
123
- const fieldValues = Array.from(_getFieldValues(update));
123
+ const fieldValues = Array.from(_getFieldValues(Object.entries(updates)));
124
124
  await Promise.all(snapshot.docs.map(s => updateDoc(s.ref, ...fieldValues)));
125
125
  return snapshot.size;
126
126
  }
@@ -3,7 +3,7 @@ import type { Unsubscribe } from "../../observe/Observable.js";
3
3
  import type { AsyncProvider } from "../../provider/Provider.js";
4
4
  import type { ItemArray, ItemValue, ItemConstraints } from "../../db/Item.js";
5
5
  import { Observer } from "../../observe/Observer.js";
6
- import { DataUpdate } from "../../update/DataUpdate.js";
6
+ import { Updates } from "../../update/DataUpdate.js";
7
7
  import { Data } from "../../util/data.js";
8
8
  /**
9
9
  * Firestore server database provider.
@@ -16,11 +16,11 @@ export declare class FirestoreServerProvider implements AsyncProvider {
16
16
  subscribeItem(collection: string, id: string, observer: Observer<ItemValue>): Unsubscribe;
17
17
  addItem(collection: string, data: Data): Promise<string>;
18
18
  setItem(collection: string, id: string, data: Data): Promise<void>;
19
- updateItem(collection: string, id: string, update: DataUpdate): Promise<void>;
19
+ updateItem(collection: string, id: string, updates: Updates): Promise<void>;
20
20
  deleteItem(collection: string, id: string): Promise<void>;
21
21
  getQuery(collection: string, constraints: ItemConstraints): Promise<ItemArray>;
22
22
  subscribeQuery(collection: string, constraints: ItemConstraints, observer: Observer<ItemArray>): Unsubscribe;
23
23
  setQuery(collection: string, constraints: ItemConstraints, data: Data): Promise<number>;
24
- updateQuery(collection: string, constraints: ItemConstraints, update: DataUpdate): Promise<number>;
24
+ updateQuery(collection: string, constraints: ItemConstraints, updates: Updates): Promise<number>;
25
25
  deleteQuery(collection: string, constraints: ItemConstraints): Promise<number>;
26
26
  }