shelving 1.29.0 → 1.30.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 CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.29.0",
14
+ "version": "1.30.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -63,20 +63,20 @@
63
63
  "@types/jest": "^27.0.3",
64
64
  "@types/react": "^17.0.37",
65
65
  "@types/react-dom": "^17.0.11",
66
- "@typescript-eslint/eslint-plugin": "^5.5.0",
67
- "@typescript-eslint/parser": "^5.5.0",
68
- "eslint": "^8.4.0",
66
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
67
+ "@typescript-eslint/parser": "^5.6.0",
68
+ "eslint": "^8.4.1",
69
69
  "eslint-config-prettier": "^8.3.0",
70
70
  "eslint-plugin-import": "^2.25.3",
71
71
  "eslint-plugin-prettier": "^4.0.0",
72
- "firebase": "^9.6.0",
73
- "jest": "^27.4.3",
72
+ "firebase": "^9.6.1",
73
+ "jest": "^27.4.4",
74
74
  "jest-ts-webcompat-resolver": "^1.0.0",
75
75
  "prettier": "^2.5.1",
76
76
  "react": "^17.0.2",
77
77
  "react-dom": "^17.0.2",
78
- "ts-jest": "^27.0.7",
79
- "typescript": "^4.5.2"
78
+ "ts-jest": "^27.1.1",
79
+ "typescript": "^4.5.3"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "@google-cloud/firestore": ">=4.0.0",
@@ -1,6 +1,8 @@
1
1
  import { Schema } from "./Schema.js";
2
2
  /** `type=""` prop for HTML `<input />` tags that are relevant for strings. */
3
3
  export declare type HtmlInputType = "text" | "password" | "color" | "date" | "email" | "number" | "tel" | "search" | "url";
4
+ /** Function that sanitizes a string. */
5
+ export declare type Sanitizer = (str: string) => string;
4
6
  /**
5
7
  * Schema that defines a valid string.
6
8
  *
@@ -27,14 +29,16 @@ export declare class StringSchema extends Schema<string> {
27
29
  readonly min: number;
28
30
  readonly max: number | null;
29
31
  readonly match: RegExp | null;
32
+ readonly sanitizer: Sanitizer | null;
30
33
  readonly multiline: boolean;
31
34
  readonly trim: boolean;
32
- constructor({ value, type, min, max, match, multiline, trim, ...rest }: ConstructorParameters<typeof Schema>[0] & {
35
+ constructor({ value, type, min, max, match, sanitizer, multiline, trim, ...rest }: ConstructorParameters<typeof Schema>[0] & {
33
36
  readonly value?: string;
34
37
  readonly type?: HtmlInputType;
35
38
  readonly min?: number;
36
39
  readonly max?: number | null;
37
40
  readonly match?: RegExp | null;
41
+ readonly sanitizer?: Sanitizer | null;
38
42
  readonly multiline?: boolean;
39
43
  readonly trim?: boolean;
40
44
  });
@@ -22,13 +22,14 @@ import { Schema } from "./Schema.js";
22
22
  * schema.validate('j'); // Throws 'Minimum 3 chaacters'
23
23
  */
24
24
  export class StringSchema extends Schema {
25
- constructor({ value = "", type = "text", min = 0, max = null, match = null, multiline = false, trim = true, ...rest }) {
25
+ constructor({ value = "", type = "text", min = 0, max = null, match = null, sanitizer = null, multiline = false, trim = true, ...rest }) {
26
26
  super(rest);
27
27
  this.type = type;
28
28
  this.value = value;
29
29
  this.min = min;
30
30
  this.max = max;
31
31
  this.match = match;
32
+ this.sanitizer = sanitizer;
32
33
  this.multiline = multiline;
33
34
  this.trim = trim;
34
35
  }
@@ -51,7 +52,11 @@ export class StringSchema extends Schema {
51
52
  * - Applies `options.sanitizer` too (if it's set).
52
53
  */
53
54
  sanitize(uncleanString) {
54
- return this.multiline ? sanitizeLines(uncleanString, this.trim) : sanitizeString(uncleanString, this.trim);
55
+ return this.sanitizer
56
+ ? this.sanitizer(uncleanString)
57
+ : this.multiline
58
+ ? sanitizeLines(uncleanString, this.trim)
59
+ : sanitizeString(uncleanString, this.trim);
55
60
  }
56
61
  }
57
62
  /** Valid string, e.g. `Hello there!` */
package/stream/State.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Transformer, LOADING, ObserverType, NOERROR, Observer } from "../util/index.js";
2
- import { Stream } from "./Stream.js";
2
+ import { AnyStream, Stream } from "./Stream.js";
3
3
  /** Any state (useful for `extends AnySubscribable` clauses). */
4
4
  export declare type AnyState = State<any>;
5
5
  /**
@@ -14,8 +14,11 @@ export declare type AnyState = State<any>;
14
14
  * */
15
15
  export interface State<T> {
16
16
  to(): State<T>;
17
+ to<O extends AnyStream>(target: O): O;
17
18
  derive<TT>(transformer: Transformer<T, TT>): State<TT>;
19
+ derive<O extends AnyStream>(transformer: Transformer<T, ObserverType<O>>, target: O): O;
18
20
  deriveAsync<TT>(transformer: Transformer<T, PromiseLike<TT>>): State<TT>;
21
+ deriveAsync<O extends AnyStream>(transformer: Transformer<T, Promise<ObserverType<O>>>, target: O): O;
19
22
  }
20
23
  export declare class State<T> extends Stream<T> {
21
24
  static [Symbol.species]: typeof State;
package/util/data.d.ts CHANGED
@@ -134,3 +134,11 @@ export declare type DeepMutable<T extends Data> = {
134
134
  export declare type DeepReadonly<T extends Data> = {
135
135
  +readonly [K in keyof T]: T[K] extends Data ? DeepReadonly<T[K]> : T[K];
136
136
  };
137
+ /** Pick only the properties of an object that match a type. */
138
+ export declare type PickProps<T, TT> = Pick<T, {
139
+ [K in keyof T]: T[K] extends TT ? K : never;
140
+ }[keyof T]>;
141
+ /** Omit the properties of an object that match a type. */
142
+ export declare type OmitProps<T, TT> = Omit<T, {
143
+ [K in keyof T]: T[K] extends TT ? K : never;
144
+ }[keyof T]>;