shelving 1.146.0 → 1.147.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.
- package/package.json +1 -1
- package/schema/PartialSchema.d.ts +18 -0
- package/schema/PartialSchema.js +17 -0
- package/schema/StringSchema.js +1 -1
- package/schema/index.d.ts +1 -0
- package/schema/index.js +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Data } from "../util/data.js";
|
|
2
|
+
import type { DataSchema } from "./DataSchema.js";
|
|
3
|
+
import type { SchemaOptions } from "./Schema.js";
|
|
4
|
+
import { ThroughSchema } from "./ThroughSchema.js";
|
|
5
|
+
/** Allowed options for `PartialSchema` */
|
|
6
|
+
export interface PartialSchemaOptions<T extends Data> extends SchemaOptions {
|
|
7
|
+
readonly source: DataSchema<T>;
|
|
8
|
+
readonly value?: Partial<T> | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Validate a partial value for a given `DataSchema` source. */
|
|
11
|
+
export declare class PartialSchema<T extends Data> extends ThroughSchema<Partial<T>> {
|
|
12
|
+
readonly source: DataSchema<T>;
|
|
13
|
+
readonly value: Partial<T>;
|
|
14
|
+
constructor({ value, ...options }: PartialSchemaOptions<T>);
|
|
15
|
+
validate(unsafeValue?: unknown): Partial<T>;
|
|
16
|
+
}
|
|
17
|
+
/** Create a new partial schema from a `DataSchema` source. */
|
|
18
|
+
export declare const PARTIAL: <T extends Data>(source: DataSchema<T>) => PartialSchema<T>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
|
+
import { isData } from "../util/data.js";
|
|
3
|
+
import { validateData } from "../util/validate.js";
|
|
4
|
+
import { ThroughSchema } from "./ThroughSchema.js";
|
|
5
|
+
/** Validate a partial value for a given `DataSchema` source. */
|
|
6
|
+
export class PartialSchema extends ThroughSchema {
|
|
7
|
+
constructor({ value = {}, ...options }) {
|
|
8
|
+
super({ value, ...options });
|
|
9
|
+
}
|
|
10
|
+
validate(unsafeValue = this.value) {
|
|
11
|
+
if (!isData(unsafeValue))
|
|
12
|
+
throw new ValueFeedback("Must be object", unsafeValue);
|
|
13
|
+
return validateData(unsafeValue, this.source.props, true);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Create a new partial schema from a `DataSchema` source. */
|
|
17
|
+
export const PARTIAL = (source) => new PartialSchema({ source });
|
package/schema/StringSchema.js
CHANGED
|
@@ -29,7 +29,7 @@ export class StringSchema extends Schema {
|
|
|
29
29
|
throw new ValueFeedback("Must be string", unsafeValue);
|
|
30
30
|
const saneString = this.sanitize(possibleString);
|
|
31
31
|
if (saneString.length < this.min)
|
|
32
|
-
throw new ValueFeedback(saneString ? `Minimum ${this.min} characters` : "Required", saneString);
|
|
32
|
+
throw new ValueFeedback(saneString.length ? `Minimum ${this.min} characters` : "Required", saneString);
|
|
33
33
|
if (saneString.length > this.max)
|
|
34
34
|
throw new ValueFeedback(`Maximum ${this.max} characters`, saneString);
|
|
35
35
|
return saneString;
|
package/schema/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./Schema.js";
|
|
|
2
2
|
export * from "./ThroughSchema.js";
|
|
3
3
|
export * from "./OptionalSchema.js";
|
|
4
4
|
export * from "./RequiredSchema.js";
|
|
5
|
+
export * from "./PartialSchema.js";
|
|
5
6
|
export * from "./AllowSchema.js";
|
|
6
7
|
export * from "./ArraySchema.js";
|
|
7
8
|
export * from "./BooleanSchema.js";
|
package/schema/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./Schema.js";
|
|
|
3
3
|
export * from "./ThroughSchema.js";
|
|
4
4
|
export * from "./OptionalSchema.js";
|
|
5
5
|
export * from "./RequiredSchema.js";
|
|
6
|
+
export * from "./PartialSchema.js";
|
|
6
7
|
// Field schemas.
|
|
7
8
|
export * from "./AllowSchema.js";
|
|
8
9
|
export * from "./ArraySchema.js";
|