shelving 1.20.0 → 1.21.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 (52) hide show
  1. package/db/Change.d.ts +16 -18
  2. package/db/Change.js +7 -13
  3. package/db/Database.d.ts +39 -47
  4. package/db/Database.js +25 -24
  5. package/db/Pagination.d.ts +7 -7
  6. package/db/errors.d.ts +12 -12
  7. package/firestore/client/FirestoreClientProvider.d.ts +9 -9
  8. package/firestore/lite/FirestoreLiteProvider.d.ts +7 -7
  9. package/firestore/server/FirestoreServerProvider.d.ts +9 -9
  10. package/package.json +8 -8
  11. package/provider/BatchProvider.d.ts +7 -7
  12. package/provider/CacheProvider.d.ts +14 -14
  13. package/provider/MemoryProvider.d.ts +10 -10
  14. package/provider/MemoryProvider.js +1 -1
  15. package/provider/Provider.d.ts +22 -22
  16. package/provider/ThroughProvider.d.ts +13 -13
  17. package/provider/ValidationProvider.d.ts +10 -10
  18. package/react/useDocument.d.ts +5 -5
  19. package/react/useDocument.js +3 -3
  20. package/react/useDocumentData.d.ts +5 -5
  21. package/react/usePagination.d.ts +2 -2
  22. package/react/useQuery.d.ts +5 -5
  23. package/react/useQuery.js +3 -3
  24. package/schema/ColorSchema.d.ts +4 -3
  25. package/schema/ColorSchema.js +5 -4
  26. package/schema/DataSchema.d.ts +2 -2
  27. package/schema/DataSchema.js +2 -2
  28. package/schema/DateSchema.d.ts +2 -2
  29. package/schema/DateSchema.js +3 -3
  30. package/schema/EmailSchema.d.ts +4 -3
  31. package/schema/EmailSchema.js +5 -4
  32. package/schema/KeySchema.d.ts +2 -2
  33. package/schema/KeySchema.js +3 -3
  34. package/schema/{UrlSchema.d.ts → LinkSchema.d.ts} +6 -5
  35. package/schema/{UrlSchema.js → LinkSchema.js} +7 -6
  36. package/schema/MapSchema.d.ts +0 -1
  37. package/schema/MapSchema.js +0 -3
  38. package/schema/NumberSchema.d.ts +1 -1
  39. package/schema/NumberSchema.js +2 -2
  40. package/schema/{NullableSchema.d.ts → OptionalSchema.d.ts} +3 -3
  41. package/schema/{NullableSchema.js → OptionalSchema.js} +4 -4
  42. package/schema/PhoneSchema.d.ts +4 -3
  43. package/schema/PhoneSchema.js +5 -4
  44. package/schema/SlugSchema.d.ts +18 -0
  45. package/schema/SlugSchema.js +25 -0
  46. package/schema/StringSchema.d.ts +4 -2
  47. package/schema/ThroughSchema.d.ts +1 -1
  48. package/schema/ThroughSchema.js +2 -2
  49. package/schema/index.d.ts +3 -2
  50. package/schema/index.js +3 -2
  51. package/util/entry.d.ts +5 -0
  52. package/util/validate.d.ts +4 -2
package/db/Change.d.ts CHANGED
@@ -1,36 +1,34 @@
1
1
  import { Transforms, Transform } from "../transform/index.js";
2
- import { Datas, ImmutableArray, Key } from "../util/index.js";
3
- import type { Database, DatabaseDocument } from "./Database.js";
2
+ import { ImmutableArray, Data } from "../util/index.js";
3
+ import type { Database, DataDocument } from "./Database.js";
4
4
  /** A single change that can be made to a database. */
5
- export declare abstract class Change<T extends Datas> {
5
+ export declare abstract class Change {
6
6
  /** Apply this change to a database. */
7
- abstract apply(db: Database<T>): void | PromiseLike<void>;
7
+ abstract apply(db: Database): void | PromiseLike<void>;
8
8
  }
9
9
  /** A change that writes a document in a database. */
10
- export declare class Write<C extends Key<D>, D extends Datas> extends Change<D> {
11
- static on<Y extends Key<X>, X extends Datas>({ collection, id }: DatabaseDocument<Y, X>, value: X[Y] | Transform<X[Y]> | undefined): Write<Y, X>;
12
- readonly collection: C;
10
+ export declare class Write<T extends Data> extends Change {
11
+ readonly collection: string;
13
12
  readonly id: string;
14
- readonly value: D[C] | Transform<D[C]> | undefined;
15
- constructor(collection: C, id: string, value: D[C] | Transform<D[C]> | undefined);
16
- apply(db: Database<D>): void | PromiseLike<void>;
13
+ readonly value: Data | Transform<Data> | undefined;
14
+ constructor({ collection, id }: DataDocument<T>, value: T | Transform<T> | undefined);
15
+ apply(db: Database): void | PromiseLike<void>;
17
16
  }
18
17
  /**
19
18
  * Set of writes that can be applied to documents in a database.
20
19
  * - Sets of changes are predictable and repeatable, so unpredictable operations like `create()` and query operations are not supported.
21
20
  * - Every change must be applied to a specific database document in a specific collection.
22
21
  */
23
- export declare class Writes<D extends Datas> extends Change<D> {
24
- static on<X extends Datas>(db: Database<X>, ...changes: ImmutableArray<Change<X>>): Writes<X>;
25
- readonly changes: ImmutableArray<Change<D>>;
26
- constructor(...changes: ImmutableArray<Change<D>>);
22
+ export declare class Writes extends Change {
23
+ readonly changes: ImmutableArray<Change>;
24
+ constructor(...changes: Change[]);
27
25
  /** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
28
- set<C extends Key<D>>({ collection, id }: DatabaseDocument<C, D>, data: D[C]): this;
26
+ set<T extends Data>(ref: DataDocument<T>, data: T): this;
29
27
  /** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
30
- delete<C extends Key<D>>({ collection, id }: DatabaseDocument<C, D>): this;
28
+ delete<T extends Data>(ref: DataDocument<T>): this;
31
29
  /** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
32
- update<C extends Key<D>>({ collection, id }: DatabaseDocument<C, D>, transforms: Transforms<D[C]> | Transform<D[C]>): this;
33
- apply(db: Database<D>): Promise<void> | undefined;
30
+ update<T extends Data>(ref: DataDocument<T>, transforms: Transforms<T> | Transform<T>): this;
31
+ apply(db: Database): Promise<void> | undefined;
34
32
  }
35
33
  /** Set of hydrations for all change classes. */
36
34
  export declare const CHANGE_HYDRATIONS: {
package/db/Change.js CHANGED
@@ -5,15 +5,12 @@ export class Change {
5
5
  }
6
6
  /** A change that writes a document in a database. */
7
7
  export class Write extends Change {
8
- constructor(collection, id, value) {
8
+ constructor({ collection, id }, value) {
9
9
  super();
10
10
  this.collection = collection;
11
11
  this.id = id;
12
12
  this.value = value;
13
13
  }
14
- static on({ collection, id }, value) {
15
- return new Write(collection, id, value);
16
- }
17
14
  apply(db) {
18
15
  return db.doc(this.collection, this.id).write(this.value);
19
16
  }
@@ -28,23 +25,20 @@ export class Writes extends Change {
28
25
  super();
29
26
  this.changes = changes;
30
27
  }
31
- static on(db, ...changes) {
32
- return new Writes(...changes);
33
- }
34
28
  /** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
35
- set({ collection, id }, data) {
36
- return { __proto__: Object.getPrototypeOf(this), ...this, changes: [...this.changes, new Write(collection, id, data)] };
29
+ set(ref, data) {
30
+ return { __proto__: Object.getPrototypeOf(this), ...this, changes: [...this.changes, new Write(ref, data)] };
37
31
  }
38
32
  /** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
39
- delete({ collection, id }) {
40
- return { __proto__: Object.getPrototypeOf(this), ...this, changes: [...this.changes, new Write(collection, id, undefined)] };
33
+ delete(ref) {
34
+ return { __proto__: Object.getPrototypeOf(this), ...this, changes: [...this.changes, new Write(ref, undefined)] };
41
35
  }
42
36
  /** Return a new `Changes` instance with an additional `Write` instance in its changes list. */
43
- update({ collection, id }, transforms) {
37
+ update(ref, transforms) {
44
38
  return {
45
39
  __proto__: Object.getPrototypeOf(this),
46
40
  ...this,
47
- changes: [...this.changes, new Write(collection, id, transforms instanceof Transform ? transforms : new DataTransform(transforms))],
41
+ changes: [...this.changes, new Write(ref, transforms instanceof Transform ? transforms : new DataTransform(transforms))],
48
42
  };
49
43
  }
50
44
  apply(db) {
package/db/Database.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Dispatcher, Entry, Observable, Observer, Result, Unsubscriber, Datas, ResultsMap, Validatable, Validator, Validators, Key, Data, Results } from "../util/index.js";
1
+ import { Dispatcher, Entry, Observable, Observer, Result, Unsubscriber, ResultsMap, Validatable, Validator, Key, Data, Results, Datas, Validators, ValidatorType } from "../util/index.js";
2
2
  import { Transform, Transforms } from "../transform/index.js";
3
3
  import type { Provider } from "../provider/Provider.js";
4
4
  import { Filters, Sorts, Query } from "../query/index.js";
@@ -9,23 +9,23 @@ import { Filters, Sorts, Query } from "../query/index.js";
9
9
  * @param collections Set of loci describing collections at the root level of the database.
10
10
  * @param provider Provider that allows data to be read/written.
11
11
  */
12
- export declare class Database<D extends Datas> {
13
- readonly validators: Validators<D>;
14
- readonly provider: Provider<D>;
15
- constructor(validators: Validators<D>, provider: Provider<D>);
12
+ export declare class Database<V extends Validators<Datas> = Validators<Datas>> {
13
+ readonly validators: V;
14
+ readonly provider: Provider;
15
+ constructor(validators: V, provider: Provider);
16
16
  /** Create a query on a collection in this model. */
17
- query<C extends Key<D>>(collection: C, filters?: Filters<D[C]>, sorts?: Sorts<D[C]>, limit?: number | null): DatabaseQuery<C, D>;
17
+ query<K extends Key<V>>(collection: K, filters?: Filters<ValidatorType<V[K]>>, sorts?: Sorts<ValidatorType<V[K]>>, limit?: number | null): DataQuery<ValidatorType<V[K]>>;
18
18
  /** Reference a document in a collection in this model. */
19
- doc<C extends Key<D>>(collection: C, id: string): DatabaseDocument<C, D>;
19
+ doc<K extends Key<V>>(collection: K, id: string): DataDocument<ValidatorType<V[K]>>;
20
20
  }
21
21
  /** A documents reference within a specific database. */
22
- export declare class DatabaseQuery<C extends Key<D>, D extends Datas> extends Query<D[C]> implements Observable<Results<D[C]>>, Validatable<Results<D[C]>>, Iterable<Entry<D[C]>> {
23
- readonly db: Database<D>;
24
- readonly validator: Validator<D[C]>;
25
- readonly collection: C;
26
- constructor(db: Database<D>, collection: C, filters?: Filters<D[C]>, sorts?: Sorts<D[C]>, limit?: number | null);
22
+ export declare class DataQuery<T extends Data = Data> extends Query<T> implements Observable<Results<T>>, Validatable<Results<T>>, Iterable<Entry<T>> {
23
+ readonly provider: Provider;
24
+ readonly validator: Validator<T>;
25
+ readonly collection: string;
26
+ constructor(provider: Provider, validator: Validator<T>, collection: string, filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null);
27
27
  /** Reference a document in this query's collection. */
28
- doc(id: string): DatabaseDocument<C, D>;
28
+ doc(id: string): DataDocument<T>;
29
29
  /**
30
30
  * Create a new document with a random ID.
31
31
  * - Created document is guaranteed to have a unique ID.
@@ -33,17 +33,17 @@ export declare class DatabaseQuery<C extends Key<D>, D extends Datas> extends Qu
33
33
  * @param data Complete data to set the document to.
34
34
  * @return String ID for the created document (possibly promised).
35
35
  */
36
- add(data: D[C]): string | PromiseLike<string>;
36
+ add(data: T): string | PromiseLike<string>;
37
37
  /**
38
38
  * Get an iterable that yields the results of this entry.
39
39
  * @return Map containing the results.
40
40
  */
41
- get results(): Results<D[C]> | PromiseLike<Results<D[C]>>;
41
+ get results(): Results<T> | PromiseLike<Results<T>>;
42
42
  /**
43
43
  * Get an iterable that yields the results of this entry.
44
44
  * @return Map containing the results.
45
45
  */
46
- get resultsMap(): ResultsMap<D[C]> | PromiseLike<ResultsMap<D[C]>>;
46
+ get resultsMap(): ResultsMap<T> | PromiseLike<ResultsMap<T>>;
47
47
  /**
48
48
  * Count the number of results of this set of documents.
49
49
  * @return Number of documents in the collection (possibly promised).
@@ -53,7 +53,7 @@ export declare class DatabaseQuery<C extends Key<D>, D extends Datas> extends Qu
53
53
  * Get an entry for the first document matching this query.
54
54
  * @return Entry in `[id, data]` format for the first document, or `undefined` if there are no matching documents (possibly promised).
55
55
  */
56
- get first(): Entry<D[C]> | undefined | PromiseLike<Entry<D[C]> | undefined>;
56
+ get first(): Entry<T> | undefined | PromiseLike<Entry<T> | undefined>;
57
57
  /**
58
58
  * Subscribe to all matching documents.
59
59
  * - `next()` is called once with the initial results, and again any time the results change.
@@ -65,7 +65,7 @@ export declare class DatabaseQuery<C extends Key<D>, D extends Datas> extends Qu
65
65
  *
66
66
  * @return Function that ends the subscription.
67
67
  */
68
- subscribe(next: Observer<Results<D[C]>> | Dispatcher<Results<D[C]>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
68
+ subscribe(next: Observer<Results<T>> | Dispatcher<Results<T>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
69
69
  /**
70
70
  * Subscribe to all matching documents.
71
71
  * - `next()` is called once with the initial results, and again any time the results change.
@@ -77,14 +77,14 @@ export declare class DatabaseQuery<C extends Key<D>, D extends Datas> extends Qu
77
77
  *
78
78
  * @return Function that ends the subscription.
79
79
  */
80
- subscribeMap(next: Observer<ResultsMap<D[C]>> | Dispatcher<ResultsMap<D[C]>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
80
+ subscribeMap(next: Observer<ResultsMap<T>> | Dispatcher<ResultsMap<T>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
81
81
  /**
82
82
  * Set all matching documents to the same exact value.
83
83
  *
84
84
  * @param data Complete data to set the document to.
85
85
  * @return Nothing (possibly promised).
86
86
  */
87
- set(data: D[C]): void | PromiseLike<void>;
87
+ set(data: T): void | PromiseLike<void>;
88
88
  /**
89
89
  * Update all matching documents with the same partial value.
90
90
  *
@@ -93,7 +93,7 @@ export declare class DatabaseQuery<C extends Key<D>, D extends Datas> extends Qu
93
93
  *
94
94
  * @return Nothing (possibly promised).
95
95
  */
96
- update(transform: Transform<D[C]> | Transforms<D[C]>): void | PromiseLike<void>;
96
+ update(transform: Transform<T> | Transforms<T>): void | PromiseLike<void>;
97
97
  /**
98
98
  * Delete all matching documents.
99
99
  * @return Nothing (possibly promised).
@@ -103,24 +103,24 @@ export declare class DatabaseQuery<C extends Key<D>, D extends Datas> extends Qu
103
103
  * Combine `set()`, `update()`, `delete()` into a single method.
104
104
  * @return Nothing (possibly promised).
105
105
  */
106
- write(value: Result<D[C]> | Transform<D[C]>): void | PromiseLike<void>;
106
+ write(value: Result<T> | Transform<T>): void | PromiseLike<void>;
107
107
  /** Iterate over the resuls (will throw `Promise` if the results are asynchronous). */
108
- [Symbol.iterator](): Iterator<Entry<D[C]>, void>;
108
+ [Symbol.iterator](): Iterator<Entry<T>, void>;
109
109
  /** Validate a set of results for this query reference. */
110
- validate(unsafeEntries: Results): Results<D[C]>;
110
+ validate(unsafeEntries: Results): Results<T>;
111
111
  toString(): string;
112
112
  }
113
113
  /** A document reference within a specific database. */
114
- export declare class DatabaseDocument<C extends Key<D>, D extends Datas> implements Observable<Result<D[C]>>, Validatable<D[C]> {
115
- readonly db: Database<D>;
116
- readonly validator: Validator<D[C]>;
117
- readonly collection: C;
114
+ export declare class DataDocument<T extends Data = Data> implements Observable<Result<T>>, Validatable<T> {
115
+ readonly provider: Provider;
116
+ readonly validator: Validator<T>;
117
+ readonly collection: string;
118
118
  readonly id: string;
119
- constructor(db: Database<D>, collection: C, id: string);
119
+ constructor(provider: Provider, validator: Validator<T>, collection: string, id: string);
120
120
  /** Create a query on this document's collection. */
121
- query(filters?: Filters<D[C]>, sorts?: Sorts<D[C]>, limit?: number | null): DatabaseQuery<C, D>;
121
+ query(filters?: Filters<T>, sorts?: Sorts<T>, limit?: number | null): DataQuery<T>;
122
122
  /** Get an 'optional' reference to this document (uses a `ModelQuery` with an `id` filter). */
123
- get optional(): DatabaseQuery<C, D>;
123
+ get optional(): DataQuery<T>;
124
124
  /**
125
125
  * Does this document exist?
126
126
  *
@@ -132,7 +132,7 @@ export declare class DatabaseDocument<C extends Key<D>, D extends Datas> impleme
132
132
  *
133
133
  * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
134
134
  */
135
- get result(): Result<D[C]> | PromiseLike<Result<D[C]>>;
135
+ get result(): Result<T> | PromiseLike<Result<T>>;
136
136
  /**
137
137
  * Get the data of this document.
138
138
  * - Useful for destructuring, e.g. `{ name, title } = await documentThatMustExist.asyncData`
@@ -140,7 +140,7 @@ export declare class DatabaseDocument<C extends Key<D>, D extends Datas> impleme
140
140
  * @return Document's data (possibly promised).
141
141
  * @throws RequiredError if the document's result was undefined.
142
142
  */
143
- get data(): D[C] | PromiseLike<D[C]>;
143
+ get data(): T | PromiseLike<T>;
144
144
  /**
145
145
  * Subscribe to the result of this document (indefinitely).
146
146
  * - `next()` is called once with the initial result, and again any time the result changes.
@@ -152,7 +152,7 @@ export declare class DatabaseDocument<C extends Key<D>, D extends Datas> impleme
152
152
  *
153
153
  * @return Function that ends the subscription.
154
154
  */
155
- subscribe(next: Observer<Result<D[C]>> | Dispatcher<Result<D[C]>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
155
+ subscribe(next: Observer<Result<T>> | Dispatcher<Result<T>>, error?: Dispatcher<Error | unknown>, complete?: Dispatcher<void>): Unsubscriber;
156
156
  /**
157
157
  * Set the complete data of this document.
158
158
  *
@@ -160,7 +160,7 @@ export declare class DatabaseDocument<C extends Key<D>, D extends Datas> impleme
160
160
  *
161
161
  * @return Nothing (possibly promised).
162
162
  */
163
- set(data: D[C]): void | PromiseLike<void>;
163
+ set(data: T): void | PromiseLike<void>;
164
164
  /**
165
165
  * Update this document with partial data.
166
166
  * - If the document exists, merge the partial data into it.
@@ -172,7 +172,7 @@ export declare class DatabaseDocument<C extends Key<D>, D extends Datas> impleme
172
172
  * @return Nothing (possibly promised).
173
173
  * @throws Error If the document does not exist (ideally a `RequiredError` but may be provider-specific).
174
174
  */
175
- update(transforms: Transform<D[C]> | Transforms<D[C]>): void | PromiseLike<void>;
175
+ update(transforms: Transform<T> | Transforms<T>): void | PromiseLike<void>;
176
176
  /**
177
177
  * Delete this document.
178
178
  * - Will not throw an error if the document doesn't exist.
@@ -183,18 +183,10 @@ export declare class DatabaseDocument<C extends Key<D>, D extends Datas> impleme
183
183
  /**
184
184
  * Combine `set()`, `update()`, `delete()` into a single method.
185
185
  */
186
- write(value: Result<D[C]> | Transform<D[C]>): void | PromiseLike<void>;
186
+ write(value: Result<T> | Transform<T>): void | PromiseLike<void>;
187
187
  /** Validate data for this query reference. */
188
- validate(unsafeData: Data): D[C];
188
+ validate(unsafeData: Data): T;
189
189
  toString(): string;
190
190
  }
191
191
  /** Get the data for a document from a result for that document. */
192
- export declare function getDocumentData<C extends Key<D>, D extends Datas>(result: Result<D[C]>, ref: DatabaseDocument<C, D>): D[C];
193
- /** Database query with a collection name. */
194
- export declare type CollectionQuery<C extends string, T extends Data> = DatabaseQuery<C, {
195
- [K in C]: T;
196
- }>;
197
- /** Database document with a collection name. */
198
- export declare type CollectionDocument<C extends string, T extends Data> = DatabaseDocument<C, {
199
- [K in C]: T;
200
- }>;
192
+ export declare function getDocumentData<T extends Data>(result: Result<T>, ref: DataDocument<T>): T;
package/db/Database.js CHANGED
@@ -10,6 +10,7 @@ import { DocumentRequiredError, DocumentValidationError, QueryValidationError }
10
10
  * @param collections Set of loci describing collections at the root level of the database.
11
11
  * @param provider Provider that allows data to be read/written.
12
12
  */
13
+ // Note: typing this with `Validators` rather than raw `Datas` works better for inference — type for props in each collection tends to get lost.
13
14
  export class Database {
14
15
  constructor(validators, provider) {
15
16
  this.validators = validators;
@@ -17,24 +18,24 @@ export class Database {
17
18
  }
18
19
  /** Create a query on a collection in this model. */
19
20
  query(collection, filters, sorts, limit) {
20
- return new DatabaseQuery(this, collection, filters, sorts, limit);
21
+ return new DataQuery(this.provider, this.validators[collection], collection, filters, sorts, limit);
21
22
  }
22
23
  /** Reference a document in a collection in this model. */
23
24
  doc(collection, id) {
24
- return new DatabaseDocument(this, collection, id);
25
+ return new DataDocument(this.provider, this.validators[collection], collection, id);
25
26
  }
26
27
  }
27
28
  /** A documents reference within a specific database. */
28
- export class DatabaseQuery extends Query {
29
- constructor(db, collection, filters, sorts, limit) {
29
+ export class DataQuery extends Query {
30
+ constructor(provider, validator, collection, filters, sorts, limit) {
30
31
  super(filters, sorts, limit);
31
- this.db = db;
32
- this.validator = db.validators[collection];
32
+ this.provider = provider;
33
+ this.validator = validator;
33
34
  this.collection = collection;
34
35
  }
35
36
  /** Reference a document in this query's collection. */
36
37
  doc(id) {
37
- return new DatabaseDocument(this.db, this.collection, id);
38
+ return new DataDocument(this.provider, this.validator, this.collection, id);
38
39
  }
39
40
  /**
40
41
  * Create a new document with a random ID.
@@ -44,21 +45,21 @@ export class DatabaseQuery extends Query {
44
45
  * @return String ID for the created document (possibly promised).
45
46
  */
46
47
  add(data) {
47
- return this.db.provider.add(this, data);
48
+ return this.provider.add(this, data);
48
49
  }
49
50
  /**
50
51
  * Get an iterable that yields the results of this entry.
51
52
  * @return Map containing the results.
52
53
  */
53
54
  get results() {
54
- return this.db.provider.getQuery(this);
55
+ return this.provider.getQuery(this);
55
56
  }
56
57
  /**
57
58
  * Get an iterable that yields the results of this entry.
58
59
  * @return Map containing the results.
59
60
  */
60
61
  get resultsMap() {
61
- return callAsync(toMap, this.db.provider.getQuery(this));
62
+ return callAsync(toMap, this.provider.getQuery(this));
62
63
  }
63
64
  /**
64
65
  * Count the number of results of this set of documents.
@@ -86,7 +87,7 @@ export class DatabaseQuery extends Query {
86
87
  * @return Function that ends the subscription.
87
88
  */
88
89
  subscribe(next, error, complete) {
89
- return this.db.provider.subscribeQuery(this, createObserver(next, error, complete));
90
+ return this.provider.subscribeQuery(this, createObserver(next, error, complete));
90
91
  }
91
92
  /**
92
93
  * Subscribe to all matching documents.
@@ -100,7 +101,7 @@ export class DatabaseQuery extends Query {
100
101
  * @return Function that ends the subscription.
101
102
  */
102
103
  subscribeMap(next, error, complete) {
103
- return this.db.provider.subscribeQuery(this, new DeriveObserver(toMap, createObserver(next, error, complete)));
104
+ return this.provider.subscribeQuery(this, new DeriveObserver(toMap, createObserver(next, error, complete)));
104
105
  }
105
106
  /**
106
107
  * Set all matching documents to the same exact value.
@@ -134,7 +135,7 @@ export class DatabaseQuery extends Query {
134
135
  * @return Nothing (possibly promised).
135
136
  */
136
137
  write(value) {
137
- return this.db.provider.writeQuery(this, value);
138
+ return this.provider.writeQuery(this, value);
138
139
  }
139
140
  /** Iterate over the resuls (will throw `Promise` if the results are asynchronous). */
140
141
  [Symbol.iterator]() {
@@ -164,20 +165,20 @@ export class DatabaseQuery extends Query {
164
165
  }
165
166
  }
166
167
  /** A document reference within a specific database. */
167
- export class DatabaseDocument {
168
- constructor(db, collection, id) {
169
- this.db = db;
170
- this.validator = db.validators[collection];
168
+ export class DataDocument {
169
+ constructor(provider, validator, collection, id) {
170
+ this.provider = provider;
171
+ this.validator = validator;
171
172
  this.collection = collection;
172
173
  this.id = id;
173
174
  }
174
175
  /** Create a query on this document's collection. */
175
176
  query(filters, sorts, limit) {
176
- return new DatabaseQuery(this.db, this.collection, filters, sorts, limit);
177
+ return new DataQuery(this.provider, this.validator, this.collection, filters, sorts, limit);
177
178
  }
178
179
  /** Get an 'optional' reference to this document (uses a `ModelQuery` with an `id` filter). */
179
180
  get optional() {
180
- return new DatabaseQuery(this.db, this.collection, new Filters(new EqualFilter("id", this.id)));
181
+ return new DataQuery(this.provider, this.validator, this.collection, new Filters(new EqualFilter("id", this.id)));
181
182
  }
182
183
  /**
183
184
  * Does this document exist?
@@ -185,7 +186,7 @@ export class DatabaseDocument {
185
186
  * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
186
187
  */
187
188
  get exists() {
188
- return callAsync(Boolean, this.db.provider.get(this));
189
+ return callAsync(Boolean, this.provider.get(this));
189
190
  }
190
191
  /**
191
192
  * Get the result of this document.
@@ -193,7 +194,7 @@ export class DatabaseDocument {
193
194
  * @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
194
195
  */
195
196
  get result() {
196
- return this.db.provider.get(this);
197
+ return this.provider.get(this);
197
198
  }
198
199
  /**
199
200
  * Get the data of this document.
@@ -203,7 +204,7 @@ export class DatabaseDocument {
203
204
  * @throws RequiredError if the document's result was undefined.
204
205
  */
205
206
  get data() {
206
- return callAsync(getDocumentData, this.db.provider.get(this), this);
207
+ return callAsync(getDocumentData, this.provider.get(this), this);
207
208
  }
208
209
  /**
209
210
  * Subscribe to the result of this document (indefinitely).
@@ -217,7 +218,7 @@ export class DatabaseDocument {
217
218
  * @return Function that ends the subscription.
218
219
  */
219
220
  subscribe(next, error, complete) {
220
- return this.db.provider.subscribe(this, createObserver(next, error, complete));
221
+ return this.provider.subscribe(this, createObserver(next, error, complete));
221
222
  }
222
223
  /**
223
224
  * Set the complete data of this document.
@@ -256,7 +257,7 @@ export class DatabaseDocument {
256
257
  * Combine `set()`, `update()`, `delete()` into a single method.
257
258
  */
258
259
  write(value) {
259
- return this.db.provider.write(this, value);
260
+ return this.provider.write(this, value);
260
261
  }
261
262
  /** Validate data for this query reference. */
262
263
  validate(unsafeData) {
@@ -1,19 +1,19 @@
1
- import { Datas, Key, ResultsMap, Entry, Results } from "../util/index.js";
1
+ import { ResultsMap, Entry, Results, Data } from "../util/index.js";
2
2
  import { State } from "../stream/index.js";
3
- import { DatabaseQuery } from "./Database.js";
3
+ import { DataQuery } from "./Database.js";
4
4
  /**
5
5
  * State that wraps a `Documents` reference to enable pagination.
6
6
  * - If you pass in initial values, it will use that as the first page.
7
7
  * - If you don't pass in initial values, it will autoload the first page.
8
8
  */
9
- export declare class Pagination<C extends Key<D>, D extends Datas> extends State<ResultsMap<D[C]>> implements Iterable<Entry<D[C]>> {
10
- readonly ref: DatabaseQuery<C, D>;
9
+ export declare class Pagination<T extends Data> extends State<ResultsMap<T>> implements Iterable<Entry<T>> {
10
+ readonly ref: DataQuery<T>;
11
11
  readonly limit: number;
12
12
  readonly startLoading: boolean;
13
13
  readonly startDone: boolean;
14
14
  readonly endLoading: boolean;
15
15
  readonly endDone: boolean;
16
- constructor(ref: DatabaseQuery<C, D>);
16
+ constructor(ref: DataQuery<T>);
17
17
  /**
18
18
  * Load more results before the start.
19
19
  * - Promise that needs to be handled.
@@ -28,7 +28,7 @@ export declare class Pagination<C extends Key<D>, D extends Datas> extends State
28
28
  * Merge more results into this pagination.
29
29
  * @return The change in the number of results.
30
30
  */
31
- merge(more: Results<D[C]>): void;
31
+ merge(more: Results<T>): void;
32
32
  /** Iterate over the entries of the values currently in the pagination. */
33
- [Symbol.iterator](): Iterator<Entry<D[C]>>;
33
+ [Symbol.iterator](): Iterator<Entry<T>>;
34
34
  }
package/db/errors.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import type { Datas, Key } from "../util/index.js";
1
+ import type { Data } from "../util/index.js";
2
2
  import { RequiredError, ValidationError } from "../error/index.js";
3
- import { Feedback } from "../feedback/index.js";
4
- import type { DatabaseDocument, DatabaseQuery } from "./Database.js";
3
+ import type { Feedback } from "../feedback/index.js";
4
+ import type { DataDocument, DataQuery } from "./Database.js";
5
5
  /** Thrown if a document doesn't exist. */
6
- export declare class DocumentRequiredError<D extends Datas, C extends Key<D>> extends RequiredError {
7
- ref: DatabaseDocument<C, D>;
8
- constructor(ref: DatabaseDocument<C, D>);
6
+ export declare class DocumentRequiredError<T extends Data> extends RequiredError {
7
+ ref: DataDocument<T>;
8
+ constructor(ref: DataDocument<T>);
9
9
  }
10
10
  /** Thrown if a document can't validate. */
11
- export declare class DocumentValidationError<D extends Datas, C extends Key<D>> extends ValidationError {
12
- ref: DatabaseDocument<C, D>;
13
- constructor(ref: DatabaseDocument<C, D>, feedback: Feedback);
11
+ export declare class DocumentValidationError<T extends Data> extends ValidationError {
12
+ ref: DataDocument<T>;
13
+ constructor(ref: DataDocument<T>, feedback: Feedback);
14
14
  }
15
15
  /** Thrown if a query can't validate a set of results. */
16
- export declare class QueryValidationError<D extends Datas, C extends Key<D>> extends ValidationError {
17
- ref: DatabaseQuery<C, D>;
18
- constructor(ref: DatabaseQuery<C, D>, feedback: Feedback);
16
+ export declare class QueryValidationError<T extends Data> extends ValidationError {
17
+ ref: DataQuery<T>;
18
+ constructor(ref: DataQuery<T>, feedback: Feedback);
19
19
  }
@@ -1,19 +1,19 @@
1
1
  import type { Firestore } from "firebase/firestore";
2
- import { Results, Provider, DatabaseDocument, DatabaseQuery, Result, Observer, Transform, AsynchronousProvider, Datas, Key } from "../../index.js";
2
+ import { Results, Provider, DataDocument, DataQuery, Result, Observer, Transform, AsynchronousProvider, Data } from "../../index.js";
3
3
  /**
4
4
  * Firestore client database provider.
5
5
  * - Works with the Firebase JS SDK.
6
6
  * - Supports offline mode.
7
7
  * - Supports realtime subscriptions.
8
8
  */
9
- export declare class FirestoreClientProvider<D extends Datas> extends Provider<D> implements AsynchronousProvider<D> {
9
+ export declare class FirestoreClientProvider extends Provider implements AsynchronousProvider {
10
10
  readonly firestore: Firestore;
11
11
  constructor(firestore: Firestore);
12
- get<C extends Key<D>>(ref: DatabaseDocument<C, D>): Promise<Result<D[C]>>;
13
- subscribe<C extends Key<D>>(ref: DatabaseDocument<C, D>, observer: Observer<Result<D[C]>>): () => void;
14
- add<C extends Key<D>>(ref: DatabaseQuery<C, D>, data: D[C]): Promise<string>;
15
- write<C extends Key<D>>(ref: DatabaseDocument<C, D>, value: D[C] | Transform<D[C]> | undefined): Promise<void>;
16
- getQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>): Promise<Results<D[C]>>;
17
- subscribeQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>, observer: Observer<Results<D[C]>>): () => void;
18
- writeQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>, value: D[C] | Transform<D[C]> | undefined): Promise<void>;
12
+ get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
13
+ subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>): () => void;
14
+ add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
15
+ write<T extends Data>(ref: DataDocument<T>, value: T | Transform<T> | undefined): Promise<void>;
16
+ getQuery<T extends Data>(ref: DataQuery<T>): Promise<Results<T>>;
17
+ subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>): () => void;
18
+ writeQuery<T extends Data>(ref: DataQuery<T>, value: T | Transform<T> | undefined): Promise<void>;
19
19
  }
@@ -1,19 +1,19 @@
1
1
  import type { Firestore } from "firebase/firestore/lite";
2
- import { Provider, DatabaseDocument, DatabaseQuery, Result, Transform, AsynchronousProvider, Datas, Key, Results } from "../../index.js";
2
+ import { Provider, DataDocument, DataQuery, Result, Transform, AsynchronousProvider, Data, Results } from "../../index.js";
3
3
  /**
4
4
  * Firestore Lite client database provider.
5
5
  * - Works with the Firebase JS SDK.
6
6
  * - Does not support offline mode.
7
7
  * - Does not support realtime subscriptions.
8
8
  */
9
- export declare class FirestoreClientProvider<D extends Datas> extends Provider<D> implements AsynchronousProvider<D> {
9
+ export declare class FirestoreClientProvider extends Provider implements AsynchronousProvider {
10
10
  readonly firestore: Firestore;
11
11
  constructor(firestore: Firestore);
12
- get<C extends Key<D>>(ref: DatabaseDocument<C, D>): Promise<Result<D[C]>>;
12
+ get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
13
13
  subscribe(): () => void;
14
- add<C extends Key<D>>(ref: DatabaseQuery<C, D>, data: D[C]): Promise<string>;
15
- write<C extends Key<D>>(ref: DatabaseDocument<C, D>, value: D[C] | Transform<D[C]> | undefined): Promise<void>;
16
- getQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>): Promise<Results<D[C]>>;
14
+ add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
15
+ write<T extends Data>(ref: DataDocument<T>, value: T | Transform<T> | undefined): Promise<void>;
16
+ getQuery<T extends Data>(ref: DataQuery<T>): Promise<Results<T>>;
17
17
  subscribeQuery(): () => void;
18
- writeQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>, value: D[C] | Transform<D[C]> | undefined): Promise<void>;
18
+ writeQuery<T extends Data>(ref: DataQuery<T>, value: T | Transform<T> | undefined): Promise<void>;
19
19
  }
@@ -1,17 +1,17 @@
1
1
  import { Firestore } from "@google-cloud/firestore";
2
- import { Provider, DatabaseDocument, DatabaseQuery, Observer, Result, Transform, AsynchronousProvider, Datas, Key, Entry, Results } from "../../index.js";
2
+ import { Provider, DataDocument, DataQuery, Observer, Result, Transform, Data, AsynchronousProvider, Entry, Results } from "../../index.js";
3
3
  /**
4
4
  * Firestore server database provider.
5
5
  * - Works with the Firebase Admin SDK for Node.JS
6
6
  */
7
- export declare class FirestoreServerProvider<D extends Datas> extends Provider<D> implements AsynchronousProvider<D> {
7
+ export declare class FirestoreServerProvider extends Provider implements AsynchronousProvider {
8
8
  readonly firestore: Firestore;
9
9
  constructor(firestore?: Firestore);
10
- get<C extends Key<D>>(ref: DatabaseDocument<C, D>): Promise<Result<D[C]>>;
11
- subscribe<C extends Key<D>>(ref: DatabaseDocument<C, D>, observer: Observer<Result<D[C]>>): () => void;
12
- add<C extends Key<D>>(ref: DatabaseQuery<C, D>, data: D[C]): Promise<string>;
13
- write<C extends Key<D>>(ref: DatabaseDocument<C, D>, value: D[C] | Transform<D[C]> | undefined): Promise<void>;
14
- getQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>): Promise<Iterable<Entry<D[C]>>>;
15
- subscribeQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>, observer: Observer<Results<D[C]>>): () => void;
16
- writeQuery<C extends Key<D>>(ref: DatabaseQuery<C, D>, value: D[C] | Transform<D[C]> | undefined): Promise<void>;
10
+ get<T extends Data>(ref: DataDocument<T>): Promise<Result<T>>;
11
+ subscribe<T extends Data>(ref: DataDocument<T>, observer: Observer<Result<T>>): () => void;
12
+ add<T extends Data>(ref: DataQuery<T>, data: T): Promise<string>;
13
+ write<T extends Data>(ref: DataDocument<T>, value: T | Transform<T> | undefined): Promise<void>;
14
+ getQuery<T extends Data>(ref: DataQuery<T>): Promise<Iterable<Entry<T>>>;
15
+ subscribeQuery<T extends Data>(ref: DataQuery<T>, observer: Observer<Results<T>>): () => void;
16
+ writeQuery<T extends Data>(ref: DataQuery<T>, value: T | Transform<T> | undefined): Promise<void>;
17
17
  }