shelving 1.76.0 → 1.77.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.
@@ -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 ReadonlyArray<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
@@ -3,33 +3,34 @@ import type { ImmutableArray } from "../util/array.js";
3
3
  import type { Provider, AsyncProvider } from "../provider/Provider.js";
4
4
  import { DataUpdate } from "../update/DataUpdate.js";
5
5
  import { Nullish } from "../util/null.js";
6
+ import { DeepIterable } from "../util/iterate.js";
6
7
  import type { ItemConstraints, ItemData } from "./Item.js";
7
- export interface Change<T extends Datas, K extends Key<T>> {
8
+ export interface Change<T extends Datas> {
8
9
  readonly action: string;
9
- readonly collection: K;
10
+ readonly collection: Key<T>;
10
11
  }
11
12
  /** Add on an item. */
12
- export interface AddChange<T extends Datas, K extends Key<T>> extends Change<T, K> {
13
+ export interface AddChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
13
14
  readonly action: "ADD";
14
15
  readonly collection: K;
15
16
  readonly data: T[K];
16
17
  }
17
18
  /** Set on an item. */
18
- export interface SetChange<T extends Datas, K extends Key<T>> extends Change<T, K> {
19
+ export interface SetChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
19
20
  readonly action: "SET";
20
21
  readonly collection: K;
21
22
  readonly id: string;
22
23
  readonly data: T[K];
23
24
  }
24
25
  /** Update change on an item. */
25
- export interface UpdateChange<T extends Datas, K extends Key<T>> extends Change<T, K> {
26
+ export interface UpdateChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
26
27
  readonly action: "UPDATE";
27
28
  readonly collection: K;
28
29
  readonly id: string;
29
30
  readonly update: DataUpdate<T[K]>;
30
31
  }
31
32
  /** Delete change on an item. */
32
- export interface DeleteChange<T extends Datas, K extends Key<T>> extends Change<T, K> {
33
+ export interface DeleteChange<T extends Datas, K extends Key<T> = Key<T>> extends Change<T> {
33
34
  readonly action: "DELETE";
34
35
  readonly collection: K;
35
36
  readonly id: string;
@@ -43,7 +44,7 @@ export declare type WriteChange<T extends Datas, K extends Key<T> = Key<T>> = It
43
44
  /** Array of write changes. */
44
45
  export declare type WriteChanges<T extends Datas, K extends Key<T> = Key<T>> = ImmutableArray<WriteChange<T, K>>;
45
46
  /** Apply a set of changes to a synchronous provider. */
46
- export declare function changeProvider<T extends Datas, K extends Key<T> = Key<T>>(provider: Provider<T>, changes: ImmutableArray<Nullish<WriteChange<T, K>>>): ItemChanges<T, K>;
47
+ export declare function changeProvider<T extends Datas, K extends Key<T>>(provider: Provider<T>, ...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
47
48
  /** Apply a set of changes to an asynchronous provider. */
48
- export declare function changeAsyncProvider<T extends Datas, K extends Key<T>>(provider: AsyncProvider<T>, changes: ImmutableArray<Nullish<WriteChange<T, K>>>): Promise<ItemChanges<T, K>>;
49
+ export declare function changeAsyncProvider<T extends Datas, K extends Key<T>>(provider: AsyncProvider<T>, ...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
49
50
  export declare function _getItemConstraint<T extends Data>(id: string): ItemConstraints<ItemData<T>>;
package/db/Change.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { QueryConstraints } from "../constraint/QueryConstraints.js";
2
2
  import { FilterConstraint } from "../constraint/FilterConstraint.js";
3
3
  import { notNullish } from "../util/null.js";
4
+ import { flattenDeepIterable } from "../util/iterate.js";
4
5
  /** Apply a set of changes to a synchronous provider. */
5
- export function changeProvider(provider, changes) {
6
- return changes.filter(notNullish).map(_changeItem, provider);
6
+ export function changeProvider(provider, ...changes) {
7
+ return Array.from(flattenDeepIterable(changes)).filter(notNullish).map(_changeItem, provider);
7
8
  }
8
9
  function _changeItem(change) {
9
10
  const { action, collection } = change;
@@ -18,8 +19,8 @@ function _changeItem(change) {
18
19
  return change;
19
20
  }
20
21
  /** Apply a set of changes to an asynchronous provider. */
21
- export function changeAsyncProvider(provider, changes) {
22
- return Promise.all(changes.filter(notNullish).map(_changeAsyncItem, provider));
22
+ export function changeAsyncProvider(provider, ...changes) {
23
+ return Promise.all(Array.from(flattenDeepIterable(changes)).filter(notNullish).map(_changeAsyncItem, provider));
23
24
  }
24
25
  async function _changeAsyncItem(change) {
25
26
  const { collection, action } = change;
@@ -2,22 +2,23 @@ import type { Datas, Key } from "../util/data.js";
2
2
  import type { Nullish } from "../util/null.js";
3
3
  import type { FilterList } from "../constraint/FilterConstraint.js";
4
4
  import type { SortList } from "../constraint/SortConstraint.js";
5
- import type { ItemData, AsyncItem, Item } from "./Item.js";
5
+ import type { DeepIterable } from "../util/iterate.js";
6
6
  import type { AsyncDatabase, Database } from "./Database.js";
7
- import type { AsyncQuery, Query } from "./Query.js";
8
- import type { AddChange, ItemChanges, WriteChange } from "./Change.js";
7
+ import { ItemData, AsyncItem, Item } from "./Item.js";
8
+ import { AsyncQuery, Query } from "./Query.js";
9
+ import { AddChange, ItemChanges, WriteChange } from "./Change.js";
9
10
  /** Reference to a collection in a synchronous or asynchronous provider. */
10
11
  declare abstract class BaseCollection<T extends Datas = Datas, K extends Key<T> = Key<T>> {
11
12
  abstract readonly db: Database<T> | AsyncDatabase<T>;
12
13
  abstract readonly collection: K;
13
14
  /** Create a query on this item's collection. */
14
- 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>;
15
16
  /** Create a query on this item's collection. */
16
17
  abstract item(id: string): Item<T, K> | AsyncItem<T, K>;
17
18
  /** Add an item to this collection. */
18
19
  abstract add(data: T[K]): string | Promise<string>;
19
20
  /** Run a set of changes on this database. */
20
- abstract change(...changes: Nullish<WriteChange<T, K>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
21
+ abstract change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
21
22
  /** Get an add change for this collection. */
22
23
  getAdd(data: T[K]): AddChange<T, K>;
23
24
  toString(): K;
@@ -27,19 +28,19 @@ export declare class Collection<T extends Datas = Datas, K extends Key<T> = Key<
27
28
  readonly db: Database<T>;
28
29
  readonly collection: K;
29
30
  constructor(db: Database<T>, collection: K);
30
- 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>;
31
32
  item(id: string): Item<T, K>;
32
33
  add(data: T[K]): string;
33
- change(...changes: Nullish<WriteChange<T, K>>[]): ItemChanges<T, K>;
34
+ change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
34
35
  }
35
36
  /** Reference to a collection in an asynchronous provider. */
36
37
  export declare class AsyncCollection<T extends Datas = Datas, K extends Key<T> = Key<T>> extends BaseCollection<T, K> {
37
38
  readonly db: AsyncDatabase<T>;
38
39
  readonly collection: K;
39
40
  constructor(db: AsyncDatabase<T>, collection: K);
40
- 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>;
41
42
  item(id: string): AsyncItem<T, K>;
42
43
  add(data: T[K]): Promise<string>;
43
- change(...changes: Nullish<WriteChange<T, K>>[]): Promise<ItemChanges<T, K>>;
44
+ change(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
44
45
  }
45
46
  export {};
package/db/Collection.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { AsyncItem, Item } from "./Item.js";
2
+ import { AsyncQuery, Query } from "./Query.js";
3
+ import { changeAsyncProvider, changeProvider } from "./Change.js";
1
4
  /** Reference to a collection in a synchronous or asynchronous provider. */
2
5
  class BaseCollection {
3
6
  /** Get an add change for this collection. */
@@ -17,16 +20,16 @@ export class Collection extends BaseCollection {
17
20
  this.collection = collection;
18
21
  }
19
22
  query(filters, sorts, limit) {
20
- return this.db.query(this.collection, filters, sorts, limit);
23
+ return new Query(this.db, this.collection, filters, sorts, limit);
21
24
  }
22
25
  item(id) {
23
- return this.db.item(this.collection, id);
26
+ return new Item(this.db, this.collection, id);
24
27
  }
25
28
  add(data) {
26
29
  return this.db.provider.addItem(this.collection, data);
27
30
  }
28
31
  change(...changes) {
29
- return this.db.change(...changes);
32
+ return changeProvider(this.db.provider, changes);
30
33
  }
31
34
  }
32
35
  /** Reference to a collection in an asynchronous provider. */
@@ -37,15 +40,15 @@ export class AsyncCollection extends BaseCollection {
37
40
  this.collection = collection;
38
41
  }
39
42
  query(filters, sorts, limit) {
40
- return this.db.query(this.collection, filters, sorts, limit);
43
+ return new AsyncQuery(this.db, this.collection, filters, sorts, limit);
41
44
  }
42
45
  item(id) {
43
- return this.db.item(this.collection, id);
46
+ return new AsyncItem(this.db, this.collection, id);
44
47
  }
45
48
  add(data) {
46
49
  return this.db.provider.addItem(this.collection, data);
47
50
  }
48
51
  change(...changes) {
49
- return this.db.change(...changes);
52
+ return changeAsyncProvider(this.db.provider, changes);
50
53
  }
51
54
  }
package/db/Database.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { FilterList } from "../constraint/FilterConstraint.js";
4
4
  import type { SortList } from "../constraint/SortConstraint.js";
5
5
  import type { ItemData } from "../db/Item.js";
6
6
  import type { Nullish } from "../util/null.js";
7
+ import { DeepIterable } from "../util/iterate.js";
7
8
  import { Item, AsyncItem } from "./Item.js";
8
9
  import { Query, AsyncQuery } from "./Query.js";
9
10
  import { Collection, AsyncCollection } from "./Collection.js";
@@ -14,28 +15,28 @@ declare abstract class BaseDatabase<T extends Datas> {
14
15
  /** Create a query on a collection in this database. */
15
16
  abstract collection<K extends Key<T>>(collection: K): Collection<T, K> | AsyncCollection<T, K>;
16
17
  /** Create a query on a collection in this database. */
17
- abstract query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<T, K> | AsyncQuery<T, 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>;
18
19
  /** Reference an item in a collection in this database. */
19
20
  abstract item<K extends Key<T>>(collection: K, id: string): Item<T, K> | AsyncItem<T, K>;
20
21
  /** Run a set of changes on this database. */
21
- abstract change<K extends Key<T>>(...changes: Nullish<WriteChange<T, K>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
22
+ abstract change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K> | Promise<ItemChanges<T, K>>;
22
23
  }
23
24
  /** Database with a synchronous provider. */
24
25
  export declare class Database<T extends Datas = Datas> implements BaseDatabase<T> {
25
26
  readonly provider: Provider<T>;
26
27
  constructor(provider: Provider<T>);
27
28
  collection<K extends Key<T>>(collection: K): Collection<T, K>;
28
- query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): Query<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>;
29
30
  item<K extends Key<T>>(collection: K, id: string): Item<T, K>;
30
- change<K extends Key<T>>(...changes: Nullish<WriteChange<T, K>>[]): ItemChanges<T, K>;
31
+ change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): ItemChanges<T, K>;
31
32
  }
32
33
  /** Database with a synchronous provider. */
33
34
  export declare class AsyncDatabase<T extends Datas = Datas> implements BaseDatabase<T> {
34
35
  readonly provider: AsyncProvider<T>;
35
36
  constructor(provider: AsyncProvider<T>);
36
37
  collection<K extends Key<T>>(collection: K): AsyncCollection<T, K>;
37
- query<K extends Key<T>>(collection: K, filters?: FilterList<ItemData<T[K]>>, sorts?: SortList<ItemData<T[K]>>, limit?: number | null): AsyncQuery<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>;
38
39
  item<K extends Key<T>>(collection: K, id: string): AsyncItem<T, K>;
39
- change<K extends Key<T>>(...changes: Nullish<WriteChange<T, K>>[]): Promise<ItemChanges<T, K>>;
40
+ change<K extends Key<T>>(...changes: DeepIterable<Nullish<WriteChange<T, K>>>[]): Promise<ItemChanges<T, K>>;
40
41
  }
41
42
  export {};
package/db/Query.d.ts CHANGED
@@ -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;
@@ -96,7 +96,7 @@ export declare class Query<T extends Datas = Datas, K extends Key<T> = Key<T>> e
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>;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.76.0",
14
+ "version": "1.77.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -1,10 +1,10 @@
1
1
  import type { Unsubscribe } from "../observe/Observable.js";
2
- import { Key, Datas } from "../util/data.js";
2
+ import { Datas, Key } from "../util/data.js";
3
3
  import { ItemValue, ItemData, AsyncItem, Item } from "../db/Item.js";
4
4
  import { State } from "../state/State.js";
5
5
  import { BooleanState } from "../state/BooleanState.js";
6
6
  /** Hold the current state of a item. */
7
- export declare class ItemState<T extends Datas, K extends Key<T>> extends State<ItemValue<T[K]>> {
7
+ export declare class ItemState<T extends Datas, K extends Key<T> = Key<T>> extends State<ItemValue<T[K]>> {
8
8
  readonly ref: Item<T, K> | AsyncItem<T, K>;
9
9
  readonly busy: BooleanState;
10
10
  /** Get the data of the item (throws `RequiredError` if item doesn't exist). */
@@ -1,11 +1,11 @@
1
1
  import type { Unsubscribe } from "../observe/Observable.js";
2
- import type { Key, Datas } from "../util/data.js";
2
+ import type { Datas, Key } from "../util/data.js";
3
3
  import type { ItemArray, ItemValue, ItemData } from "../db/Item.js";
4
4
  import { AsyncQuery, Query } from "../db/Query.js";
5
5
  import { State } from "../state/State.js";
6
6
  import { BooleanState } from "../state/BooleanState.js";
7
7
  /** Hold the current state of a query. */
8
- export declare class QueryState<T extends Datas, K extends Key<T>> extends State<ItemArray<T[K]>> {
8
+ export declare class QueryState<T extends Datas, K extends Key<T> = Key<T>> extends State<ItemArray<T[K]>> {
9
9
  readonly ref: Query<T, K> | AsyncQuery<T, K>;
10
10
  readonly busy: BooleanState;
11
11
  readonly limit: number;
package/util/iterate.d.ts CHANGED
@@ -20,6 +20,10 @@ export declare const isAsyncIterable: <T extends AsyncIterable<unknown>>(value:
20
20
  * - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.
21
21
  */
22
22
  export declare function countItems(items: Iterable<unknown>): number;
23
+ /** An iterable possibly containing multiple other iterables. */
24
+ export declare type DeepIterable<T> = T | Iterable<DeepIterable<T>>;
25
+ /** Flatten one or more iterables. */
26
+ export declare function flattenDeepIterable<T>(items: DeepIterable<T>): Iterable<T>;
23
27
  /**
24
28
  * Does an iterable have one or more items.
25
29
  * - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.
package/util/iterate.js CHANGED
@@ -31,6 +31,14 @@ function _countItems(items) {
31
31
  count++;
32
32
  return count;
33
33
  }
34
+ /** Flatten one or more iterables. */
35
+ export function* flattenDeepIterable(items) {
36
+ if (isIterable(items))
37
+ for (const item of items)
38
+ yield* flattenDeepIterable(item);
39
+ else
40
+ yield items;
41
+ }
34
42
  /**
35
43
  * Does an iterable have one or more items.
36
44
  * - Checks `items.size` or `items.length` first, or consumes the iterable and counts its iterations.