shelving 1.68.2 → 1.68.3
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/feedback/Feedback.js +2 -2
- package/firestore/client/FirestoreClientProvider.d.ts +1 -1
- package/firestore/client/FirestoreClientProvider.js +7 -3
- package/firestore/lite/FirestoreLiteProvider.js +6 -2
- package/firestore/server/FirestoreServerProvider.d.ts +1 -1
- package/firestore/server/FirestoreServerProvider.js +7 -3
- package/package.json +1 -1
- package/provider/ThroughProvider.d.ts +4 -2
- package/provider/ThroughProvider.js +11 -3
- package/provider/ValidationProvider.js +2 -3
- package/react/useDocument.js +3 -3
- package/react/useQuery.js +3 -3
- package/schema/AllowSchema.js +4 -4
- package/schema/ArraySchema.js +3 -3
- package/schema/DateSchema.js +4 -4
- package/schema/NumberSchema.js +2 -2
- package/schema/SlugSchema.js +2 -2
- package/schema/ThroughSchema.d.ts +4 -2
- package/schema/ThroughSchema.js +10 -4
- package/update/ArrayUpdate.d.ts +2 -1
- package/update/ArrayUpdate.js +22 -3
- package/update/DataUpdate.d.ts +3 -2
- package/update/DataUpdate.js +42 -2
- package/update/Delete.d.ts +11 -0
- package/update/Delete.js +15 -0
- package/update/Increment.d.ts +5 -5
- package/update/Increment.js +5 -5
- package/update/ObjectUpdate.d.ts +8 -8
- package/update/ObjectUpdate.js +38 -18
- package/update/Update.d.ts +4 -1
- package/update/Update.js +6 -0
- package/update/hydrations.js +3 -1
- package/update/index.d.ts +2 -2
- package/update/index.js +2 -2
- package/util/color.d.ts +6 -2
- package/util/color.js +17 -11
- package/util/constants.d.ts +0 -2
- package/util/constants.js +0 -2
- package/util/data.d.ts +6 -6
- package/util/data.js +3 -3
- package/util/date.d.ts +5 -5
- package/util/date.js +19 -19
- package/util/number.d.ts +3 -3
- package/util/number.js +5 -5
- package/util/search.js +2 -2
- package/util/string.d.ts +4 -4
- package/util/string.js +7 -7
- package/util/transform.js +2 -2
- package/util/validate.d.ts +9 -0
- package/util/validate.js +13 -2
- package/update/util.d.ts +0 -7
- package/update/util.js +0 -44
package/util/validate.js
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { Feedback } from "../feedback/Feedback.js";
|
|
2
2
|
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getProps } from "./data.js";
|
|
4
|
+
import { getArray } from "./array.js";
|
|
4
5
|
/** Validate an unknown value with a validator. */
|
|
5
6
|
export function validate(unsafeValue, validator) {
|
|
6
7
|
return typeof validator === "function" ? validator(unsafeValue) : validator.validate(unsafeValue);
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Validate an array of items.
|
|
11
|
+
*
|
|
12
|
+
* @return Array with valid items.
|
|
13
|
+
* @throw InvalidFeedback if one or more entry values did not validate.
|
|
14
|
+
* - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
|
|
15
|
+
*/
|
|
16
|
+
export function validateArray(unsafeItems, validator) {
|
|
17
|
+
return getArray(validateItems(unsafeItems, validator));
|
|
18
|
+
}
|
|
8
19
|
/**
|
|
9
20
|
* Validate an iterable set of items with a validator.
|
|
10
21
|
*
|
|
@@ -73,7 +84,7 @@ export function validateObject(obj, validator) {
|
|
|
73
84
|
export function* validateProps(unsafeData, validators) {
|
|
74
85
|
let invalid = false;
|
|
75
86
|
const details = {};
|
|
76
|
-
for (const [k, validator] of
|
|
87
|
+
for (const [k, validator] of getProps(validators)) {
|
|
77
88
|
try {
|
|
78
89
|
yield [k, validate(unsafeData[k], validator)];
|
|
79
90
|
}
|
package/update/util.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Data } from "../util/data.js";
|
|
2
|
-
import { Validator } from "../util/validate.js";
|
|
3
|
-
import { DataUpdate } from "./DataUpdate.js";
|
|
4
|
-
import { Update } from "./Update.js";
|
|
5
|
-
/** Validate an update against a validator. */
|
|
6
|
-
export declare function validateUpdate<T extends Data>(unsafeUpdate: DataUpdate<T>, validator: Validator<T>): DataUpdate<T>;
|
|
7
|
-
export declare function validateUpdate<T>(unsafeUpdate: Update<T>, validator: Validator<T>): Update<T>;
|
package/update/util.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Feedback } from "../feedback/Feedback.js";
|
|
2
|
-
import { InvalidFeedback } from "../feedback/InvalidFeedback.js";
|
|
3
|
-
import { DataSchema } from "../schema/DataSchema.js";
|
|
4
|
-
import { toProps } from "../util/data.js";
|
|
5
|
-
import { validate } from "../util/validate.js";
|
|
6
|
-
import { transform } from "../util/transform.js";
|
|
7
|
-
import { DataUpdate } from "./DataUpdate.js";
|
|
8
|
-
import { Update } from "./Update.js";
|
|
9
|
-
export function validateUpdate(unsafeUpdate, validator) {
|
|
10
|
-
if (validator instanceof DataSchema && unsafeUpdate instanceof DataUpdate) {
|
|
11
|
-
const unsafeUpdates = unsafeUpdate.updates;
|
|
12
|
-
const safeUpdates = _validatePropUpdates(unsafeUpdates, validator.props);
|
|
13
|
-
return safeUpdates === unsafeUpdates ? unsafeUpdate : new DataUpdate(safeUpdates);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
validate(transform(undefined, unsafeUpdate), validator);
|
|
17
|
-
return unsafeUpdate;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/** Validate a set of transforms against a set of validators. */
|
|
21
|
-
function _validatePropUpdates(unsafeUpdates, validators) {
|
|
22
|
-
let invalid = false;
|
|
23
|
-
const safeUpdates = {};
|
|
24
|
-
const details = {};
|
|
25
|
-
for (const [k, validator] of toProps(validators)) {
|
|
26
|
-
const unsafeUpdate = unsafeUpdates[k];
|
|
27
|
-
if (unsafeUpdate !== undefined) {
|
|
28
|
-
try {
|
|
29
|
-
safeUpdates[k] = unsafeUpdate instanceof Update ? validateUpdate(unsafeUpdate, validator) : validate(unsafeUpdate, validator);
|
|
30
|
-
}
|
|
31
|
-
catch (thrown) {
|
|
32
|
-
if (thrown instanceof Feedback) {
|
|
33
|
-
invalid = true;
|
|
34
|
-
details[k] = thrown;
|
|
35
|
-
}
|
|
36
|
-
else
|
|
37
|
-
throw thrown;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (invalid)
|
|
42
|
-
throw new InvalidFeedback("Invalid updates", details);
|
|
43
|
-
return safeUpdates;
|
|
44
|
-
}
|