shelving 1.150.15 → 1.152.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/db/CacheProvider.d.ts +18 -17
- package/db/Change.d.ts +20 -19
- package/db/ChangesProvider.d.ts +22 -21
- package/db/DebugProvider.d.ts +28 -27
- package/db/ItemStore.d.ts +10 -10
- package/db/MemoryProvider.d.ts +47 -44
- package/db/MemoryProvider.js +9 -4
- package/db/Provider.d.ts +50 -49
- package/db/QueryStore.d.ts +11 -10
- package/db/ThroughProvider.d.ts +38 -37
- package/db/ValidationProvider.d.ts +33 -29
- package/db/ValidationProvider.js +24 -22
- package/firestore/client/FirestoreClientProvider.d.ts +11 -10
- package/firestore/lite/FirestoreLiteProvider.d.ts +11 -10
- package/firestore/server/FirestoreServerProvider.d.ts +11 -10
- package/package.json +1 -1
- package/react/createDataContext.d.ts +8 -7
- package/schema/ColorSchema.d.ts +3 -3
- package/schema/ColorSchema.js +3 -4
- package/schema/DataSchema.d.ts +3 -3
- package/schema/DataSchema.js +2 -3
- package/schema/EmailSchema.d.ts +2 -2
- package/schema/EmailSchema.js +3 -4
- package/schema/EntitySchema.js +2 -2
- package/schema/LinkSchema.d.ts +2 -2
- package/schema/LinkSchema.js +3 -3
- package/schema/PhoneSchema.d.ts +2 -2
- package/schema/PhoneSchema.js +3 -4
- package/schema/SlugSchema.js +1 -1
- package/schema/StringSchema.d.ts +25 -4
- package/schema/StringSchema.js +33 -3
- package/schema/index.d.ts +0 -1
- package/schema/index.js +0 -1
- package/test/basics.d.ts +11 -10
- package/test/people.d.ts +7 -6
- package/test/util.d.ts +3 -3
- package/test/util.js +3 -3
- package/util/array.d.ts +2 -2
- package/util/array.js +3 -3
- package/util/error.d.ts +1 -1
- package/util/item.d.ts +15 -16
- package/util/item.js +9 -8
- package/util/query.d.ts +3 -0
- package/util/random.d.ts +1 -1
- package/util/set.d.ts +3 -3
- package/schema/TextSchema.d.ts +0 -40
- package/schema/TextSchema.js +0 -47
package/util/item.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
/** Get the
|
|
2
|
-
export function
|
|
1
|
+
/** Get the identifier from an item object. */
|
|
2
|
+
export function getIdentifier({ id }) {
|
|
3
3
|
return id;
|
|
4
4
|
}
|
|
5
|
-
/** Get the
|
|
6
|
-
export function*
|
|
5
|
+
/** Get the identifiers from an iterable set item objects. */
|
|
6
|
+
export function* getIdentifiers(entities) {
|
|
7
7
|
for (const { id } of entities)
|
|
8
8
|
yield id;
|
|
9
9
|
}
|
|
10
|
+
/** Does a data object or data item object. */
|
|
11
|
+
export function hasIdentifier(item, id) {
|
|
12
|
+
return item.id === id;
|
|
13
|
+
}
|
|
10
14
|
/** Merge an ID into a set of data to make an `ItemData` */
|
|
11
15
|
export function getItem(id, data) {
|
|
12
|
-
return data
|
|
13
|
-
}
|
|
14
|
-
export function getItemQuery(id) {
|
|
15
|
-
return { id, $limit: 1 };
|
|
16
|
+
return hasIdentifier(data, id) ? data : { ...data, id };
|
|
16
17
|
}
|
package/util/query.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ImmutableArray } from "./array.js";
|
|
2
2
|
import type { Data, LeafData, LeafKey } from "./data.js";
|
|
3
|
+
import type { Item } from "./item.js";
|
|
3
4
|
/** Query that can be applied to a list of data objects. */
|
|
4
5
|
export type Query<T extends Data> = {
|
|
5
6
|
readonly [K in LeafKey<T> as `${K}` | `!${K}`]?: LeafData<T>[K] | ImmutableArray<LeafData<T>[K]> | undefined;
|
|
@@ -11,6 +12,8 @@ export type Query<T extends Data> = {
|
|
|
11
12
|
readonly $order?: `${LeafKey<T>}` | `!${LeafKey<T>}` | undefined | ImmutableArray<`${LeafKey<T>}` | `!${LeafKey<T>}` | undefined>;
|
|
12
13
|
readonly $limit?: number | undefined;
|
|
13
14
|
};
|
|
15
|
+
/** A set of query constraints for item data. */
|
|
16
|
+
export type ItemQuery<I extends string | number, T extends Data> = Query<Item<I, T>>;
|
|
14
17
|
/** A single filter that can be applied to a list of data objects. */
|
|
15
18
|
export type Filter = {
|
|
16
19
|
key: string;
|
package/util/random.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ export declare function getRandomKey(length?: number): string;
|
|
|
13
13
|
/** Get a random character from a string. */
|
|
14
14
|
export declare function getRandomCharacter(str: string): string;
|
|
15
15
|
/** Get a random item from an array or random character from a string string. */
|
|
16
|
-
export declare function getRandomItem<T>(arr: ImmutableArray<T>): T;
|
|
16
|
+
export declare function getRandomItem<I, T>(arr: ImmutableArray<T>): T;
|
package/util/set.d.ts
CHANGED
|
@@ -16,11 +16,11 @@ export declare function getSet<T>(value: PossibleSet<T>): ImmutableSet;
|
|
|
16
16
|
/** Apply a limit to a set. */
|
|
17
17
|
export declare function limitSet<T>(set: ImmutableSet<T>, limit: number): ImmutableSet<T>;
|
|
18
18
|
/** Is an unknown value an item in a set? */
|
|
19
|
-
export declare function isSetItem<T>(set: ImmutableSet<T>, item: unknown): item is T;
|
|
19
|
+
export declare function isSetItem<I, T>(set: ImmutableSet<T>, item: unknown): item is T;
|
|
20
20
|
/** Assert that an unknown value is an item in a set. */
|
|
21
|
-
export declare function assertSetItem<T>(set: ImmutableSet<T>, item: unknown, caller?: AnyCaller): asserts item is T;
|
|
21
|
+
export declare function assertSetItem<I, T>(set: ImmutableSet<T>, item: unknown, caller?: AnyCaller): asserts item is T;
|
|
22
22
|
/** Add an item to a set (by reference) and return the set item. */
|
|
23
|
-
export declare function addSetItem<T>(set: MutableSet<T>, item: T): T;
|
|
23
|
+
export declare function addSetItem<I, T>(set: MutableSet<T>, item: T): T;
|
|
24
24
|
/** Add multiple items to a set (by reference). */
|
|
25
25
|
export declare function addSetItems<T>(set: MutableSet<T>, ...items: T[]): void;
|
|
26
26
|
/** Remove multiple items from a set (by reference). */
|
package/schema/TextSchema.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { type Sanitizer, StringSchema, type StringSchemaOptions } from "./StringSchema.js";
|
|
2
|
-
/** `type=""` prop for HTML `<input />` tags that are relevant for strings. */
|
|
3
|
-
export type TextSchemaType = "text" | "password" | "color" | "date" | "email" | "number" | "tel" | "search" | "url";
|
|
4
|
-
/** Options for `TextSchema` */
|
|
5
|
-
export interface TextSchemaOptions extends StringSchemaOptions {
|
|
6
|
-
readonly type?: TextSchemaType | undefined;
|
|
7
|
-
readonly match?: RegExp | undefined;
|
|
8
|
-
readonly multiline?: boolean | undefined;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Schema that defines a valid text string.
|
|
12
|
-
*
|
|
13
|
-
* Ensures value is string and optionally enforces min/max length, whether to trim whitespace, and regex match format.
|
|
14
|
-
* Doesn't allow `null` to mean no value — empty string is the equivalent for StringSchema (because it means we'll never accidentally get `"null"` by converting the `null` to string).
|
|
15
|
-
*
|
|
16
|
-
* Defaults to a single line text string (newlines are stripped). Use `multiline=true` to allow newlines.
|
|
17
|
-
*/
|
|
18
|
-
export declare class TextSchema extends StringSchema {
|
|
19
|
-
readonly type: TextSchemaType;
|
|
20
|
-
readonly match: RegExp | undefined;
|
|
21
|
-
readonly sanitizer: Sanitizer | undefined;
|
|
22
|
-
readonly multiline: boolean;
|
|
23
|
-
constructor({ type, match, multiline, ...options }: TextSchemaOptions);
|
|
24
|
-
validate(unsafeValue?: unknown): string;
|
|
25
|
-
sanitize(str: string): string;
|
|
26
|
-
}
|
|
27
|
-
/** Valid text, e.g. `Hello there!` */
|
|
28
|
-
export declare const TEXT: TextSchema;
|
|
29
|
-
/** Valid text, `Hello there!`, with more than one character. */
|
|
30
|
-
export declare const REQUIRED_TEXT: TextSchema;
|
|
31
|
-
/** Title string, e.g. `Title of something` */
|
|
32
|
-
export declare const TITLE: TextSchema;
|
|
33
|
-
/** Optional name string, e.g. `Title of something` or `null` */
|
|
34
|
-
export declare const NULLABLE_TITLE: import("./NullableSchema.js").NullableSchema<string>;
|
|
35
|
-
/** Name string, e.g. `Name of Something` */
|
|
36
|
-
export declare const NAME: TextSchema;
|
|
37
|
-
/** Optional name string, e.g. `Name of Something` or `null` */
|
|
38
|
-
export declare const NULLABLE_NAME: import("./NullableSchema.js").NullableSchema<string>;
|
|
39
|
-
/** Password string. */
|
|
40
|
-
export declare const PASSWORD: TextSchema;
|
package/schema/TextSchema.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
|
-
import { sanitizeMultilineText, sanitizeText } from "../util/string.js";
|
|
3
|
-
import { NULLABLE } from "./NullableSchema.js";
|
|
4
|
-
import { StringSchema } from "./StringSchema.js";
|
|
5
|
-
/**
|
|
6
|
-
* Schema that defines a valid text string.
|
|
7
|
-
*
|
|
8
|
-
* Ensures value is string and optionally enforces min/max length, whether to trim whitespace, and regex match format.
|
|
9
|
-
* Doesn't allow `null` to mean no value — empty string is the equivalent for StringSchema (because it means we'll never accidentally get `"null"` by converting the `null` to string).
|
|
10
|
-
*
|
|
11
|
-
* Defaults to a single line text string (newlines are stripped). Use `multiline=true` to allow newlines.
|
|
12
|
-
*/
|
|
13
|
-
export class TextSchema extends StringSchema {
|
|
14
|
-
type;
|
|
15
|
-
match;
|
|
16
|
-
sanitizer;
|
|
17
|
-
multiline;
|
|
18
|
-
constructor({ type = "text", match, multiline = false, ...options }) {
|
|
19
|
-
super(options);
|
|
20
|
-
this.type = type;
|
|
21
|
-
this.match = match;
|
|
22
|
-
this.multiline = multiline;
|
|
23
|
-
}
|
|
24
|
-
validate(unsafeValue = this.value) {
|
|
25
|
-
const str = super.validate(unsafeValue);
|
|
26
|
-
if (this.match && !this.match.test(str))
|
|
27
|
-
throw new ValueFeedback(str ? "Invalid format" : "Required", str);
|
|
28
|
-
return str;
|
|
29
|
-
}
|
|
30
|
-
sanitize(str) {
|
|
31
|
-
return this.multiline ? sanitizeMultilineText(str) : sanitizeText(str);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/** Valid text, e.g. `Hello there!` */
|
|
35
|
-
export const TEXT = new TextSchema({ title: "Text" });
|
|
36
|
-
/** Valid text, `Hello there!`, with more than one character. */
|
|
37
|
-
export const REQUIRED_TEXT = new TextSchema({ min: 1 });
|
|
38
|
-
/** Title string, e.g. `Title of something` */
|
|
39
|
-
export const TITLE = new TextSchema({ title: "Title", min: 1, max: 100 });
|
|
40
|
-
/** Optional name string, e.g. `Title of something` or `null` */
|
|
41
|
-
export const NULLABLE_TITLE = NULLABLE(TITLE);
|
|
42
|
-
/** Name string, e.g. `Name of Something` */
|
|
43
|
-
export const NAME = new TextSchema({ title: "Name", min: 1, max: 100 });
|
|
44
|
-
/** Optional name string, e.g. `Name of Something` or `null` */
|
|
45
|
-
export const NULLABLE_NAME = NULLABLE(NAME);
|
|
46
|
-
/** Password string. */
|
|
47
|
-
export const PASSWORD = new TextSchema({ title: "Password", min: 6, type: "password" });
|