shelving 1.44.1 → 1.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db/Database.d.ts +17 -6
- package/db/Database.js +15 -4
- package/package.json +1 -1
- package/react/useDocument.d.ts +3 -3
- package/react/useQuery.d.ts +9 -9
- package/react/useQuery.js +2 -2
- package/util/units.d.ts +1 -1
- package/util/units.js +14 -13
package/db/Database.d.ts
CHANGED
|
@@ -69,14 +69,14 @@ export declare class DatabaseQuery<T extends Data = Data> extends Query<T> imple
|
|
|
69
69
|
* @return Entry in `[id, data]` format for the first document.
|
|
70
70
|
* @throws RequiredError if there were no results for this query.
|
|
71
71
|
*/
|
|
72
|
-
get result():
|
|
72
|
+
get result(): DocumentResult<T> | PromiseLike<DocumentResult<T>>;
|
|
73
73
|
/**
|
|
74
74
|
* Get an entry for the first document matched by this query.
|
|
75
75
|
*
|
|
76
76
|
* @return Entry in `[id, data]` format for the first document.
|
|
77
77
|
* @throws RequiredError if there were no results for this query.
|
|
78
78
|
*/
|
|
79
|
-
get data():
|
|
79
|
+
get data(): DocumentData<T> | PromiseLike<DocumentData<T>>;
|
|
80
80
|
/**
|
|
81
81
|
* Subscribe to all matching documents.
|
|
82
82
|
* - `next()` is called once with the initial results, and again any time the results change.
|
|
@@ -111,7 +111,9 @@ export declare class DatabaseQuery<T extends Data = Data> extends Query<T> imple
|
|
|
111
111
|
toString(): string;
|
|
112
112
|
}
|
|
113
113
|
/** Get the data for a document from a result for that document. */
|
|
114
|
-
export declare function getQueryData<T extends Data>(entries: Entries<T>, ref: DatabaseQuery<T>):
|
|
114
|
+
export declare function getQueryData<T extends Data>(entries: Entries<T>, ref: DatabaseQuery<T>): DocumentData<T>;
|
|
115
|
+
/** Get the data for a document from a result for that document. */
|
|
116
|
+
export declare function getQueryResult<T extends Data>(entries: Entries<T>, ref: DatabaseQuery<T>): DocumentResult<T>;
|
|
115
117
|
/** A document reference within a specific database. */
|
|
116
118
|
export declare class DatabaseDocument<T extends Data = Data> implements Observable<Result<T>>, Validatable<T> {
|
|
117
119
|
readonly db: Database;
|
|
@@ -132,7 +134,7 @@ export declare class DatabaseDocument<T extends Data = Data> implements Observab
|
|
|
132
134
|
* Get the result of this document.
|
|
133
135
|
* @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
|
|
134
136
|
*/
|
|
135
|
-
get result():
|
|
137
|
+
get result(): DocumentResult<T> | PromiseLike<DocumentResult<T>>;
|
|
136
138
|
/**
|
|
137
139
|
* Get the data of this document.
|
|
138
140
|
* - Useful for destructuring, e.g. `{ name, title } = await documentThatMustExist.asyncData`
|
|
@@ -140,7 +142,7 @@ export declare class DatabaseDocument<T extends Data = Data> implements Observab
|
|
|
140
142
|
* @return Document's data (possibly promised).
|
|
141
143
|
* @throws RequiredError if the document's result was undefined.
|
|
142
144
|
*/
|
|
143
|
-
get data(): T | PromiseLike<T
|
|
145
|
+
get data(): DocumentData<T> | PromiseLike<DocumentData<T>>;
|
|
144
146
|
/**
|
|
145
147
|
* Subscribe to the result of this document (indefinitely).
|
|
146
148
|
* - `next()` is called once with the initial result, and again any time the result changes.
|
|
@@ -159,5 +161,14 @@ export declare class DatabaseDocument<T extends Data = Data> implements Observab
|
|
|
159
161
|
validate(unsafeData: Data): T;
|
|
160
162
|
toString(): string;
|
|
161
163
|
}
|
|
164
|
+
/** Database data embeds the corresponding `Document` instance and string ID into the data. */
|
|
165
|
+
export declare type DocumentData<T extends Data> = T & {
|
|
166
|
+
_id: string;
|
|
167
|
+
_doc: DatabaseDocument<T>;
|
|
168
|
+
};
|
|
169
|
+
/** Get the data for a document from a result for that document. */
|
|
170
|
+
export declare function getDocumentData<T extends Data>(result: Result<T>, ref: DatabaseDocument<T>): DocumentData<T>;
|
|
171
|
+
/** Database result embeds the corresponding `Document` instance and string ID into the result. */
|
|
172
|
+
export declare type DocumentResult<T extends Data> = DocumentData<T> | null;
|
|
162
173
|
/** Get the data for a document from a result for that document. */
|
|
163
|
-
export declare function
|
|
174
|
+
export declare function getDocumentResult<T extends Data>(result: Result<T>, ref: DatabaseDocument<T>): DocumentResult<T>;
|
package/db/Database.js
CHANGED
|
@@ -93,7 +93,7 @@ export class DatabaseQuery extends Query {
|
|
|
93
93
|
* @throws RequiredError if there were no results for this query.
|
|
94
94
|
*/
|
|
95
95
|
get result() {
|
|
96
|
-
return callAsync(
|
|
96
|
+
return callAsync(getQueryResult, this.db.provider.getQuery(this.max(1)), this);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Get an entry for the first document matched by this query.
|
|
@@ -170,7 +170,14 @@ export class DatabaseQuery extends Query {
|
|
|
170
170
|
export function getQueryData(entries, ref) {
|
|
171
171
|
const first = getFirstItem(entries);
|
|
172
172
|
if (first)
|
|
173
|
-
return first;
|
|
173
|
+
return getDocumentData(first[1], ref.doc(first[0]));
|
|
174
|
+
throw new QueryRequiredError(ref);
|
|
175
|
+
}
|
|
176
|
+
/** Get the data for a document from a result for that document. */
|
|
177
|
+
export function getQueryResult(entries, ref) {
|
|
178
|
+
const first = getFirstItem(entries);
|
|
179
|
+
if (first)
|
|
180
|
+
return getDocumentData(first[1], ref.doc(first[0]));
|
|
174
181
|
throw new QueryRequiredError(ref);
|
|
175
182
|
}
|
|
176
183
|
/** A document reference within a specific database. */
|
|
@@ -201,7 +208,7 @@ export class DatabaseDocument {
|
|
|
201
208
|
* @return Document's data, or `undefined` if the document doesn't exist (possibly promised).
|
|
202
209
|
*/
|
|
203
210
|
get result() {
|
|
204
|
-
return this.db.provider.get(this);
|
|
211
|
+
return callAsync(getDocumentResult, this.db.provider.get(this), this);
|
|
205
212
|
}
|
|
206
213
|
/**
|
|
207
214
|
* Get the data of this document.
|
|
@@ -252,6 +259,10 @@ export class DatabaseDocument {
|
|
|
252
259
|
/** Get the data for a document from a result for that document. */
|
|
253
260
|
export function getDocumentData(result, ref) {
|
|
254
261
|
if (result)
|
|
255
|
-
return result;
|
|
262
|
+
return { ...result, _id: ref.id, _doc: ref };
|
|
256
263
|
throw new DocumentRequiredError(ref);
|
|
257
264
|
}
|
|
265
|
+
/** Get the data for a document from a result for that document. */
|
|
266
|
+
export function getDocumentResult(result, ref) {
|
|
267
|
+
return result ? getDocumentData(result, ref) : null;
|
|
268
|
+
}
|
package/package.json
CHANGED
package/react/useDocument.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseDocument, Result, Data } from "../index.js";
|
|
1
|
+
import { DatabaseDocument, Result, Data, DocumentData } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Use the cached result of a document in a React component (or a `Promise` to indicate the result is still loading).
|
|
4
4
|
* - Requires database to use `CacheProvider` and will error if this does not exist.
|
|
@@ -33,8 +33,8 @@ export declare function useAsyncDocument<T extends Data>(ref: DatabaseDocument<T
|
|
|
33
33
|
export declare function useDocument<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): Result<T>;
|
|
34
34
|
export declare function useDocument<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): Result<T> | undefined;
|
|
35
35
|
/** Use the data of a document or `undefined` if the query has no matching results (or a promise indicating the result is loading). */
|
|
36
|
-
export declare function useAsyncDocumentData<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): T | PromiseLike<T
|
|
37
|
-
export declare function useAsyncDocumentData<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): T | PromiseLike<T
|
|
36
|
+
export declare function useAsyncDocumentData<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): DocumentData<T> | PromiseLike<DocumentData<T>>;
|
|
37
|
+
export declare function useAsyncDocumentData<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): DocumentData<T> | PromiseLike<DocumentData<T>> | undefined;
|
|
38
38
|
/** Use the data of a document or `undefined` if the query has no matching results. */
|
|
39
39
|
export declare function useDocumentData<T extends Data>(ref: DatabaseDocument<T>, maxAge?: number | true): T;
|
|
40
40
|
export declare function useDocumentData<T extends Data>(ref: DatabaseDocument<T> | undefined, maxAge?: number | true): T | undefined;
|
package/react/useQuery.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Results, DatabaseQuery, Data,
|
|
1
|
+
import { Results, DatabaseQuery, Data, DocumentResult, DocumentData } from "../index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Use the cached result of a document in a React component (or a `Promise` to indicate the result is still loading).
|
|
4
4
|
* - Requires database to use `CacheProvider` and will error if this does not exist.
|
|
@@ -34,14 +34,14 @@ export declare function useAsyncQuery<T extends Data>(ref: DatabaseQuery<T> | un
|
|
|
34
34
|
export declare function useQuery<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): Results<T>;
|
|
35
35
|
export declare function useQuery<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): Results<T> | undefined;
|
|
36
36
|
/** Use the first result of a query or `undefined` if the query has no matching results (or a promise indicating the result is loading). */
|
|
37
|
-
export declare function useAsyncQueryResult<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true):
|
|
38
|
-
export declare function useAsyncQueryResult<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true):
|
|
37
|
+
export declare function useAsyncQueryResult<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): DocumentResult<T> | undefined | PromiseLike<DocumentResult<T> | undefined>;
|
|
38
|
+
export declare function useAsyncQueryResult<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): DocumentResult<T> | undefined | PromiseLike<DocumentResult<T> | undefined>;
|
|
39
39
|
/** Use the first result of a query or `undefined` if the query has no matching results */
|
|
40
|
-
export declare function useQueryResult<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true):
|
|
41
|
-
export declare function useQueryResult<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true):
|
|
40
|
+
export declare function useQueryResult<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): DocumentResult<T>;
|
|
41
|
+
export declare function useQueryResult<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): DocumentResult<T> | undefined;
|
|
42
42
|
/** Use the first result of a query (or a promise indicating the result is loading). */
|
|
43
|
-
export declare function useAsyncQueryData<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true):
|
|
44
|
-
export declare function useAsyncQueryData<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true):
|
|
43
|
+
export declare function useAsyncQueryData<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): DocumentData<T> | PromiseLike<DocumentData<T>>;
|
|
44
|
+
export declare function useAsyncQueryData<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): DocumentData<T> | PromiseLike<DocumentData<T>> | undefined;
|
|
45
45
|
/** Use the first result of a query. */
|
|
46
|
-
export declare function useQueryData<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true):
|
|
47
|
-
export declare function useQueryData<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true):
|
|
46
|
+
export declare function useQueryData<T extends Data>(ref: DatabaseQuery<T>, maxAge?: number | true): DocumentData<T>;
|
|
47
|
+
export declare function useQueryData<T extends Data>(ref: DatabaseQuery<T> | undefined, maxAge?: number | true): DocumentData<T> | undefined;
|
package/react/useQuery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import { CacheProvider, NOERROR, findSourceProvider, NOVALUE, getMap, callAsync, getQueryData, throwAsync,
|
|
2
|
+
import { CacheProvider, NOERROR, findSourceProvider, NOVALUE, getMap, callAsync, getQueryData, throwAsync, ResultsObserver, getQueryResult, } from "../index.js";
|
|
3
3
|
import { usePureEffect } from "./usePureEffect.js";
|
|
4
4
|
import { usePureMemo } from "./usePureMemo.js";
|
|
5
5
|
import { usePureState } from "./usePureState.js";
|
|
@@ -60,7 +60,7 @@ export function useQuery(ref, maxAge) {
|
|
|
60
60
|
}
|
|
61
61
|
export function useAsyncQueryResult(ref, maxAge) {
|
|
62
62
|
const results = useAsyncQuery(ref ? ref.max(1) : undefined, maxAge);
|
|
63
|
-
return ref && results ? callAsync(
|
|
63
|
+
return ref && results ? callAsync(getQueryResult, results, ref) : undefined;
|
|
64
64
|
}
|
|
65
65
|
export function useQueryResult(ref, maxAge) {
|
|
66
66
|
return throwAsync(useAsyncQueryResult(ref, maxAge));
|
package/util/units.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare type UnitData = {
|
|
|
14
14
|
/** Valid system of measurement reference. */
|
|
15
15
|
export declare type UnitType = "percentage" | "angle" | "temperature" | "length" | "speed" | "pace" | "mass" | "time" | "volume";
|
|
16
16
|
/** Valid unit of measurement reference (correspond to units allowed in `Intl.NumberFormat`, but not all). */
|
|
17
|
-
export declare type UnitReference = "percent" | "degree" | "millimeter" | "centimeter" | "meter" | "kilometer" | "mile" | "yard" | "foot" | "inch" | "liter" | "milliliter" | "gallon" | "fluid-ounce" | "gram" | "kilogram" | "pound" | "stone" | "ounce" | "millisecond" | "second" | "minute" | "day" | "hour" | "week" | "month" | "year";
|
|
17
|
+
export declare type UnitReference = "percent" | "degree" | "millimeter" | "centimeter" | "meter" | "kilometer" | "mile" | "yard" | "foot" | "inch" | "liter" | "milliliter" | "gallon" | "fluid-ounce" | "milligram" | "gram" | "kilogram" | "pound" | "stone" | "ounce" | "millisecond" | "second" | "minute" | "day" | "hour" | "week" | "month" | "year";
|
|
18
18
|
/** List of units. */
|
|
19
19
|
export declare const UNITS: {
|
|
20
20
|
[K in UnitReference]: UnitData;
|
package/util/units.js
CHANGED
|
@@ -6,23 +6,24 @@ import { NNBSP } from "./string.js";
|
|
|
6
6
|
export const UNITS = {
|
|
7
7
|
"percent": { type: "percentage", base: 1, suffix: "%" },
|
|
8
8
|
"degree": { type: "angle", base: 1, suffix: "deg" },
|
|
9
|
-
"millimeter": { type: "length", base:
|
|
10
|
-
"centimeter": { type: "length", base:
|
|
11
|
-
"meter": { type: "length", base:
|
|
12
|
-
"kilometer": { type: "length", base:
|
|
13
|
-
"inch": { type: "length", base:
|
|
14
|
-
"foot": { type: "length", base:
|
|
15
|
-
"yard": { type: "length", base:
|
|
16
|
-
"mile": { type: "length", base:
|
|
9
|
+
"millimeter": { type: "length", base: 1, suffix: "mm" },
|
|
10
|
+
"centimeter": { type: "length", base: 10, suffix: "cm" },
|
|
11
|
+
"meter": { type: "length", base: 1000, centimeter: 100, millimeter: 1000, suffix: "m" },
|
|
12
|
+
"kilometer": { type: "length", base: 1000000, centimeter: 100000, millimeter: 1000000, suffix: "km" },
|
|
13
|
+
"inch": { type: "length", base: 25.4, suffix: "in" },
|
|
14
|
+
"foot": { type: "length", base: 304.8, inch: 12, suffix: "ft", plural: "feet" },
|
|
15
|
+
"yard": { type: "length", base: 914.4, inch: 36, foot: 3, suffix: "yd" },
|
|
16
|
+
"mile": { type: "length", base: 1609344, yard: 1760, foot: 5280, inch: 63360, suffix: "mi" },
|
|
17
17
|
"milliliter": { type: "volume", base: 1, suffix: "ml" },
|
|
18
18
|
"liter": { type: "volume", base: 1000, suffix: "l" },
|
|
19
19
|
"fluid-ounce": { type: "volume", base: 29.5735295625, gallon: 128, suffix: `fl${NNBSP}oz` },
|
|
20
20
|
"gallon": { type: "volume", base: 3785.411784, suffix: "gal" },
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
21
|
+
"milligram": { type: "mass", base: 1, suffix: "mg" },
|
|
22
|
+
"gram": { type: "mass", base: 1000, suffix: "g" },
|
|
23
|
+
"kilogram": { type: "mass", base: 1000000, suffix: "kg" },
|
|
24
|
+
"ounce": { type: "mass", base: 28349.523125, pound: 0.0625, suffix: "oz" },
|
|
25
|
+
"pound": { type: "mass", base: 453592.37, ounce: 16, suffix: "lb" },
|
|
26
|
+
"stone": { type: "mass", base: 6350293.18, pound: 14, ounce: 224, suffix: "st", plural: "stone" },
|
|
26
27
|
"millisecond": { type: "time", base: 1, suffix: "ms" },
|
|
27
28
|
"second": { type: "time", base: SECOND, suffix: "s" },
|
|
28
29
|
"minute": { type: "time", base: MINUTE, suffix: "m" },
|