shelving 1.157.0 → 1.157.2
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/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +1 -1
- package/schema/NullableSchema.d.ts +4 -4
- package/schema/OptionalSchema.d.ts +8 -1
- package/schema/OptionalSchema.js +3 -0
- package/schema/StringSchema.d.ts +1 -4
- package/schema/StringSchema.js +1 -4
- package/iterate/AbstractIterator.d.ts +0 -7
- package/iterate/AbstractIterator.js +0 -15
- package/iterate/InspectIterator.d.ts +0 -31
- package/iterate/InspectIterator.js +0 -75
- package/iterate/ThroughIterator.d.ts +0 -9
- package/iterate/ThroughIterator.js +0 -19
- package/iterate/index.d.ts +0 -3
- package/iterate/index.js +0 -3
package/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export * from "./api/index.js";
|
|
|
7
7
|
export * from "./db/index.js";
|
|
8
8
|
export * from "./error/index.js";
|
|
9
9
|
export * from "./feedback/index.js";
|
|
10
|
-
export * from "./iterate/index.js";
|
|
11
10
|
export * from "./markup/index.js";
|
|
12
11
|
export * from "./schema/index.js";
|
|
13
12
|
export * from "./sequence/index.js";
|
package/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export * from "./feedback/index.js";
|
|
|
10
10
|
// export * from "./firestore/client/index.js"; // Not exported.
|
|
11
11
|
// export * from "./firestore/lite/index.js"; // Not exported.
|
|
12
12
|
// export * from "./firestore/server/index.js"; // Not exported.
|
|
13
|
-
export * from "./iterate/index.js";
|
|
14
13
|
export * from "./markup/index.js";
|
|
15
14
|
// export * from "./react/index.js"; // Not exported.
|
|
16
15
|
export * from "./schema/index.js";
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Schema
|
|
2
|
-
import { ThroughSchema } from "./ThroughSchema.js";
|
|
1
|
+
import type { Schema } from "./Schema.js";
|
|
2
|
+
import { ThroughSchema, type ThroughSchemaOptions } from "./ThroughSchema.js";
|
|
3
3
|
/** Allowed options for `NullableSchema` */
|
|
4
|
-
export interface NullableSchemaOptions<T> extends
|
|
5
|
-
|
|
4
|
+
export interface NullableSchemaOptions<T> extends ThroughSchemaOptions<T | null> {
|
|
5
|
+
/** Default value (defaults to `null`). */
|
|
6
6
|
readonly value?: T | null;
|
|
7
7
|
}
|
|
8
8
|
/** Validate a value of a specific type or `null`. */
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { Schema } from "./Schema.js";
|
|
2
|
-
import { ThroughSchema } from "./ThroughSchema.js";
|
|
2
|
+
import { ThroughSchema, type ThroughSchemaOptions } from "./ThroughSchema.js";
|
|
3
|
+
export interface OptionalSchemaOptions<T> extends ThroughSchemaOptions<T | undefined> {
|
|
4
|
+
/** Default value for an `OptionalSchema` can always `undefined` */
|
|
5
|
+
readonly value?: undefined;
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* Validate a property in an optional way, i.e. it can be the value, or `undefined`
|
|
5
9
|
* - If the prop is `undefined`, then `undefined` is returned.
|
|
6
10
|
* - When used with `validateData()` this means the prop can be silently skipped.
|
|
7
11
|
*/
|
|
8
12
|
export declare class OptionalSchema<T> extends ThroughSchema<T | undefined> {
|
|
13
|
+
/** Default value for an `OptionalSchema` is always `undefined` (default value is only used when a value is `undefined`, so otherwise `undefined` could never be returned as a value). */
|
|
14
|
+
readonly value: undefined;
|
|
15
|
+
constructor(options: OptionalSchemaOptions<T>);
|
|
9
16
|
validate(unsafeValue: unknown): T | undefined;
|
|
10
17
|
}
|
|
11
18
|
/** Make a property of a set of data optional, i.e. it can be the value or `undefined` */
|
package/schema/OptionalSchema.js
CHANGED
|
@@ -5,6 +5,9 @@ import { ThroughSchema } from "./ThroughSchema.js";
|
|
|
5
5
|
* - When used with `validateData()` this means the prop can be silently skipped.
|
|
6
6
|
*/
|
|
7
7
|
export class OptionalSchema extends ThroughSchema {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super({ ...options, value: undefined });
|
|
10
|
+
}
|
|
8
11
|
validate(unsafeValue) {
|
|
9
12
|
if (unsafeValue === undefined)
|
|
10
13
|
return undefined;
|
package/schema/StringSchema.d.ts
CHANGED
|
@@ -43,10 +43,7 @@ export declare class StringSchema extends Schema<string> {
|
|
|
43
43
|
/** Valid string, e.g. `Hello there!` */
|
|
44
44
|
export declare const STRING: StringSchema;
|
|
45
45
|
/** Valid string, `Hello there!`, with more than one character. */
|
|
46
|
-
export declare const REQUIRED_STRING: StringSchema;
|
|
47
|
-
export declare const TEXT: StringSchema;
|
|
48
|
-
/** Valid text, `Hello there!`, with more than one character. */
|
|
49
|
-
export declare const REQUIRED_TEXT: StringSchema;
|
|
46
|
+
export declare const REQUIRED_STRING: StringSchema;
|
|
50
47
|
/** Title string, e.g. `Title of something` */
|
|
51
48
|
export declare const TITLE: StringSchema;
|
|
52
49
|
/** Optional name string, e.g. `Title of something` or `null` */
|
package/schema/StringSchema.js
CHANGED
|
@@ -59,10 +59,7 @@ export class StringSchema extends Schema {
|
|
|
59
59
|
/** Valid string, e.g. `Hello there!` */
|
|
60
60
|
export const STRING = new StringSchema({});
|
|
61
61
|
/** Valid string, `Hello there!`, with more than one character. */
|
|
62
|
-
export const REQUIRED_STRING = new StringSchema({ min: 1 });
|
|
63
|
-
export const TEXT = new StringSchema({ title: "Text" });
|
|
64
|
-
/** Valid text, `Hello there!`, with more than one character. */
|
|
65
|
-
export const REQUIRED_TEXT = new StringSchema({ min: 1 });
|
|
62
|
+
export const REQUIRED_STRING = new StringSchema({ min: 1 });
|
|
66
63
|
/** Title string, e.g. `Title of something` */
|
|
67
64
|
export const TITLE = new StringSchema({ title: "Title", min: 1, max: 100 });
|
|
68
65
|
/** Optional name string, e.g. `Title of something` or `null` */
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** Abstract generator designed to be extended that implements the full generator protocol. */
|
|
2
|
-
export declare abstract class AbstractIterator<T, R, N> implements Iterator<T, R, N>, Iterable<T, R, N> {
|
|
3
|
-
abstract next(value: N): IteratorResult<T, R>;
|
|
4
|
-
throw(thrown: unknown): IteratorResult<T, R>;
|
|
5
|
-
return(value: R): IteratorResult<T, R>;
|
|
6
|
-
[Symbol.iterator](): Iterator<T, R, N>;
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** Abstract generator designed to be extended that implements the full generator protocol. */
|
|
2
|
-
export class AbstractIterator {
|
|
3
|
-
throw(thrown) {
|
|
4
|
-
// Default behaviour for a generator is to throw the error back out of the iterator and not continue.
|
|
5
|
-
throw thrown;
|
|
6
|
-
}
|
|
7
|
-
return(value) {
|
|
8
|
-
// Default behaviour for a generator is to return `done: true` and the input value.
|
|
9
|
-
return { done: true, value };
|
|
10
|
-
}
|
|
11
|
-
// Implement `Iterable`
|
|
12
|
-
[Symbol.iterator]() {
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ThroughIterator } from "./ThroughIterator.js";
|
|
2
|
-
/**
|
|
3
|
-
* Iterable that inspects a source iterable as it iterates.
|
|
4
|
-
* - Stores: first/last yielded value, returned value, whether iteration is done, the number of items that were iterated.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* const watch = new InspectIterator(iterable);
|
|
8
|
-
* for (const next of capture) console.log("YIELDED", next);
|
|
9
|
-
* console.log("FIRST", watch.first);
|
|
10
|
-
* console.log("RETURNED", watch.returned);
|
|
11
|
-
*/
|
|
12
|
-
export declare class InspectIterator<T, R, N> extends ThroughIterator<T, R, N> implements Iterator<T, R, N>, Iterable<T, R, N> {
|
|
13
|
-
/** Get the number of results received by this iterator so far. */
|
|
14
|
-
readonly count = 0;
|
|
15
|
-
/** Is the iteration done? */
|
|
16
|
-
readonly done: boolean;
|
|
17
|
-
/** The first yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
18
|
-
get first(): T;
|
|
19
|
-
private _first;
|
|
20
|
-
/** The last yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
21
|
-
get last(): T;
|
|
22
|
-
private _last;
|
|
23
|
-
/** The returned value (throws if the iteration is not done, i.e. `this.done === false`). */
|
|
24
|
-
get returned(): R;
|
|
25
|
-
private _returned;
|
|
26
|
-
next(value: N): IteratorResult<T, R>;
|
|
27
|
-
throw(thrown: unknown): IteratorResult<T, R>;
|
|
28
|
-
return(value: R): IteratorResult<T, R>;
|
|
29
|
-
/** Capture a result. */
|
|
30
|
-
private _inspect;
|
|
31
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { UnexpectedError } from "../error/UnexpectedError.js";
|
|
2
|
-
import { getGetter } from "../util/class.js";
|
|
3
|
-
import { ThroughIterator } from "./ThroughIterator.js";
|
|
4
|
-
/** Used when the sequence hasn't inspected anything yet. */
|
|
5
|
-
const _NOVALUE = Symbol("shelving/InspectGenerator.NOVALUE");
|
|
6
|
-
/**
|
|
7
|
-
* Iterable that inspects a source iterable as it iterates.
|
|
8
|
-
* - Stores: first/last yielded value, returned value, whether iteration is done, the number of items that were iterated.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const watch = new InspectIterator(iterable);
|
|
12
|
-
* for (const next of capture) console.log("YIELDED", next);
|
|
13
|
-
* console.log("FIRST", watch.first);
|
|
14
|
-
* console.log("RETURNED", watch.returned);
|
|
15
|
-
*/
|
|
16
|
-
export class InspectIterator extends ThroughIterator {
|
|
17
|
-
/** Get the number of results received by this iterator so far. */
|
|
18
|
-
count = 0;
|
|
19
|
-
/** Is the iteration done? */
|
|
20
|
-
done = false;
|
|
21
|
-
/** The first yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
22
|
-
get first() {
|
|
23
|
-
if (this._first === _NOVALUE)
|
|
24
|
-
throw new UnexpectedError("Iteration not started", {
|
|
25
|
-
iterator: this,
|
|
26
|
-
caller: getGetter(this, "first"),
|
|
27
|
-
});
|
|
28
|
-
return this._first;
|
|
29
|
-
}
|
|
30
|
-
_first = _NOVALUE;
|
|
31
|
-
/** The last yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
|
|
32
|
-
get last() {
|
|
33
|
-
if (this._last === _NOVALUE)
|
|
34
|
-
throw new UnexpectedError("Iteration not started", {
|
|
35
|
-
iterator: this,
|
|
36
|
-
caller: getGetter(this, "last"),
|
|
37
|
-
});
|
|
38
|
-
return this._last;
|
|
39
|
-
}
|
|
40
|
-
_last = _NOVALUE;
|
|
41
|
-
/** The returned value (throws if the iteration is not done, i.e. `this.done === false`). */
|
|
42
|
-
get returned() {
|
|
43
|
-
if (this._returned === _NOVALUE)
|
|
44
|
-
throw new UnexpectedError("Iteration not done", {
|
|
45
|
-
iterator: this,
|
|
46
|
-
caller: getGetter(this, "returned"),
|
|
47
|
-
});
|
|
48
|
-
return this._returned;
|
|
49
|
-
}
|
|
50
|
-
_returned = _NOVALUE;
|
|
51
|
-
// Override to watch returned values.
|
|
52
|
-
next(value) {
|
|
53
|
-
return this._inspect(this.next(value));
|
|
54
|
-
}
|
|
55
|
-
throw(thrown) {
|
|
56
|
-
return this._inspect(this.throw(thrown));
|
|
57
|
-
}
|
|
58
|
-
return(value) {
|
|
59
|
-
return this._inspect(this.return(value));
|
|
60
|
-
}
|
|
61
|
-
/** Capture a result. */
|
|
62
|
-
_inspect(result) {
|
|
63
|
-
if (!result.done) {
|
|
64
|
-
if (this.first === undefined)
|
|
65
|
-
this._first = result.value;
|
|
66
|
-
this._last = result.value;
|
|
67
|
-
this.count++;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
this._returned = result.value;
|
|
71
|
-
this.done = true;
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AbstractIterator } from "./AbstractIterator.js";
|
|
2
|
-
/** Iterable that pulls values from a source iterable. */
|
|
3
|
-
export declare class ThroughIterator<T, R, N> extends AbstractIterator<T, R, N> implements Iterator<T, R, N>, Iterable<T, R, N> {
|
|
4
|
-
private readonly _source;
|
|
5
|
-
constructor(iterator: Iterator<T, R, N>);
|
|
6
|
-
next(value: N): IteratorResult<T, R>;
|
|
7
|
-
throw(thrown: unknown): IteratorResult<T, R>;
|
|
8
|
-
return(value: R): IteratorResult<T, R>;
|
|
9
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { AbstractIterator } from "./AbstractIterator.js";
|
|
2
|
-
/** Iterable that pulls values from a source iterable. */
|
|
3
|
-
export class ThroughIterator extends AbstractIterator {
|
|
4
|
-
_source;
|
|
5
|
-
constructor(iterator) {
|
|
6
|
-
super();
|
|
7
|
-
this._source = iterator;
|
|
8
|
-
}
|
|
9
|
-
// Implement `AbstractIterator`
|
|
10
|
-
next(value) {
|
|
11
|
-
return this._source.next(value);
|
|
12
|
-
}
|
|
13
|
-
throw(thrown) {
|
|
14
|
-
return this._source.throw ? this._source.throw(thrown) : super.throw(thrown);
|
|
15
|
-
}
|
|
16
|
-
return(value) {
|
|
17
|
-
return this._source.return ? this._source.return(value) : super.return(value);
|
|
18
|
-
}
|
|
19
|
-
}
|
package/iterate/index.d.ts
DELETED
package/iterate/index.js
DELETED