pema 0.13.0 → 0.14.1

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.
@@ -3,11 +3,8 @@ import coerce from "#coerce/bigint";
3
3
  import CoerceKey from "#CoerceKey";
4
4
  import NumericType from "#NumericType";
5
5
  import type Storable from "#Storable";
6
- export default class BigUintType<T extends BigUintDataType = "u64", L extends boolean | undefined = undefined, G extends boolean = false> extends NumericType<T, bigint, "BigUintType", L, G> implements Storable<T> {
6
+ export default class BigUintType<T extends BigUintDataType = "u64", L extends boolean | undefined = undefined> extends NumericType<T, bigint, "BigUintType", L> implements Storable<T> {
7
7
  [CoerceKey]: typeof coerce;
8
- sequence(): BigUintType<T, L, true>;
9
- default<S extends bigint>(value: (() => S) | S): import("./DefaultType.js").default<this, S>;
10
- optional(): import("./OptionalType.js").default<this>;
11
8
  get name(): string;
12
9
  }
13
10
  //# sourceMappingURL=BigUintType.d.ts.map
@@ -3,21 +3,6 @@ import CoerceKey from "#CoerceKey";
3
3
  import NumericType from "#NumericType";
4
4
  export default class BigUintType extends NumericType {
5
5
  [CoerceKey] = coerce;
6
- sequence() {
7
- return this.with({ sequence: true });
8
- }
9
- default(value) {
10
- if (this.generated === "sequence") {
11
- throw new TypeError("a sequence cannot also have a default value");
12
- }
13
- return super.default(value);
14
- }
15
- optional() {
16
- if (this.generated === "sequence") {
17
- throw new TypeError("a sequence cannot be optional in stored output");
18
- }
19
- return super.optional();
20
- }
21
6
  get name() {
22
7
  return "bigint";
23
8
  }
@@ -8,24 +8,21 @@ import type Validator from "#Validator";
8
8
  import type { Dict } from "@rcompat/type";
9
9
  type Next<T> = {
10
10
  options?: ParseOptions;
11
- sequence?: boolean;
12
11
  validators?: Validator<T>[];
13
12
  };
14
- export default abstract class NumericType<Key extends DataKey, T extends bigint | number, Name extends string, M extends Mode = undefined, G extends boolean = false> extends PrimitiveType<T, Name> implements Storable<Key> {
13
+ export default abstract class NumericType<Key extends DataKey, T extends bigint | number, Name extends string, M extends Mode = undefined> extends PrimitiveType<T, Name> implements Storable<Key> {
15
14
  #private;
16
15
  [Loose]: M;
17
- constructor(datatype: Key, mode?: M, validators?: Validator<T>[], options?: ParseOptions, sequence?: G);
16
+ constructor(datatype: Key, mode?: M, validators?: Validator<T>[], options?: ParseOptions);
18
17
  with(next: Next<T>): this;
19
18
  values(anyof: Dict<T>): this;
20
19
  range(from: T, to: T): this;
21
20
  min(from: T): this;
22
21
  max(to: T): this;
23
22
  get datatype(): Key;
24
- get generated(): G extends true ? "sequence" : undefined;
25
23
  toJSON(): {
26
24
  type: "number" | "bigint";
27
25
  datatype: Key;
28
- sequence?: true | undefined;
29
26
  };
30
27
  }
31
28
  export {};
@@ -6,17 +6,15 @@ import range from "#validator/range";
6
6
  import values from "#validator/values";
7
7
  export default class NumericType extends PrimitiveType {
8
8
  #datatype;
9
- #sequence;
10
9
  [Loose];
11
- constructor(datatype, mode = undefined, validators = [], options = {}, sequence = false) {
10
+ constructor(datatype, mode = undefined, validators = [], options = {}) {
12
11
  super(validators, options);
13
12
  this.#datatype = datatype;
14
- this.#sequence = sequence;
15
13
  this[Loose] = mode;
16
14
  }
17
15
  with(next) {
18
16
  const Constructor = this.constructor;
19
- return new Constructor(this.#datatype, this[Loose], [...this.validators, ...next.validators ?? []], { ...this.options, ...next.options ?? {} }, (next.sequence ?? this.#sequence));
17
+ return new Constructor(this.#datatype, this[Loose], [...this.validators, ...next.validators ?? []], { ...this.options, ...next.options ?? {} });
20
18
  }
21
19
  values(anyof) {
22
20
  return this.with({ validators: [values(anyof)] });
@@ -33,14 +31,10 @@ export default class NumericType extends PrimitiveType {
33
31
  get datatype() {
34
32
  return this.#datatype;
35
33
  }
36
- get generated() {
37
- return (this.#sequence ? "sequence" : undefined);
38
- }
39
34
  toJSON() {
40
35
  return {
41
36
  type: this.name,
42
37
  datatype: this.#datatype,
43
- ...this.#sequence ? { sequence: true } : {},
44
38
  };
45
39
  }
46
40
  }
@@ -22,7 +22,6 @@ export default class RecordType<Key extends RecordTypeKey, Value extends Parsed<
22
22
  } | {
23
23
  type: "number" | "bigint";
24
24
  datatype: "f64";
25
- sequence?: true | undefined;
26
25
  } | {
27
26
  type: "symbol";
28
27
  };
@@ -31,11 +31,9 @@ type PrimitiveSerialized = ({
31
31
  };
32
32
  type NumberSerialized = {
33
33
  type: "number";
34
- sequence?: true;
35
34
  } & DT;
36
35
  type BigIntSerialized = {
37
36
  type: "bigint";
38
- sequence?: true;
39
37
  } & DT;
40
38
  type StructuralSerialized = {
41
39
  type: "newable";
@@ -5,7 +5,7 @@ import PartialType from "#PartialType";
5
5
  import type StoreSchema from "#StoreSchema";
6
6
  export default class StoreType<S extends StoreSchema> extends ObjectType<S> {
7
7
  #private;
8
- constructor(properties: S, pk?: string | null, sequences?: readonly string[]);
8
+ constructor(properties: S, pk?: string | null);
9
9
  get name(): string;
10
10
  parse(u: unknown, options?: ParseOptions): Infer<this>;
11
11
  partial(): PartialType<any, undefined>;
@@ -6,11 +6,9 @@ import resolve from "#resolve";
6
6
  import is from "@rcompat/is";
7
7
  export default class StoreType extends ObjectType {
8
8
  #pk;
9
- #sequences;
10
- constructor(properties, pk = null, sequences = []) {
9
+ constructor(properties, pk = null) {
11
10
  super(properties);
12
11
  this.#pk = pk;
13
- this.#sequences = new Set(sequences);
14
12
  }
15
13
  get name() {
16
14
  return "store";
@@ -23,7 +21,7 @@ export default class StoreType extends ObjectType {
23
21
  const input = x ?? {};
24
22
  const out = {};
25
23
  for (const k in this.properties) {
26
- const generated = k === this.#pk || this.#sequences.has(k);
24
+ const generated = k === this.#pk;
27
25
  if (generated && !(k in input))
28
26
  continue;
29
27
  const parsed = this.properties[k].parse(input[k], next(k, $options));
@@ -4,11 +4,8 @@ import NumericType from "#NumericType";
4
4
  import type ParseOptions from "#ParseOptions";
5
5
  import type Storable from "#Storable";
6
6
  import type UintDataType from "#UintDataType";
7
- export default class UintType<T extends UintDataType, L extends boolean | undefined = undefined, G extends boolean = false> extends NumericType<T, number, "UintType", L, G> implements Storable<T> {
7
+ export default class UintType<T extends UintDataType, L extends boolean | undefined = undefined> extends NumericType<T, number, "UintType", L> implements Storable<T> {
8
8
  [CoerceKey]: typeof coerce;
9
- sequence(): UintType<T, L, true>;
10
- default<S extends number>(value: (() => S) | S): import("./DefaultType.js").default<this, S>;
11
- optional(): import("./OptionalType.js").default<this>;
12
9
  get name(): string;
13
10
  /**
14
11
  * Value is a non-privileged port number (1000 - 65535).
@@ -5,21 +5,6 @@ import integer from "#validator/integer";
5
5
  import port from "#validator/port";
6
6
  export default class UintType extends NumericType {
7
7
  [CoerceKey] = coerce;
8
- sequence() {
9
- return this.with({ sequence: true });
10
- }
11
- default(value) {
12
- if (this.generated === "sequence") {
13
- throw new TypeError("a sequence cannot also have a default value");
14
- }
15
- return super.default(value);
16
- }
17
- optional() {
18
- if (this.generated === "sequence") {
19
- throw new TypeError("a sequence cannot be optional in stored output");
20
- }
21
- return super.optional();
22
- }
23
8
  get name() {
24
9
  return "number";
25
10
  }
@@ -27,7 +27,6 @@ export type { default as PartialType } from "#PartialType";
27
27
  export type { default as PureType } from "#PureType";
28
28
  export type { default as RecordType } from "#RecordType";
29
29
  export type { default as Schema } from "#Schema";
30
- export type { default as Sequence } from "#Sequence";
31
30
  export type { default as Serialized } from "#Serialized";
32
31
  export type { default as Storable } from "#Storable";
33
32
  export type { default as StoreId } from "#StoreId";
@@ -56,7 +55,7 @@ declare namespace schema {
56
55
  export { async_schema as async };
57
56
  export var _b: import("./BigIntType.js").default<"i64", undefined>;
58
57
  export { _b as bigint };
59
- export var _c: import("./BigUintType.js").default<"u64", undefined, false>;
58
+ export var _c: import("./BigUintType.js").default<"u64", undefined>;
60
59
  export { _c as biguint };
61
60
  export var _d: import("#BlobType").default;
62
61
  export { _d as blob };
@@ -122,17 +121,17 @@ declare namespace schema {
122
121
  export { _6 as symbol };
123
122
  export var _7: <const T extends Schema[]>(...items: T) => import("#TupleType").default<{ [K in keyof T]: NormalizeSchema<T[K]>; }>;
124
123
  export { _7 as tuple };
125
- export var _8: import("./BigUintType.js").default<"u128", undefined, false>;
124
+ export var _8: import("./BigUintType.js").default<"u128", undefined>;
126
125
  export { _8 as u128 };
127
- export var _9: import("#UintType").default<"u16", undefined, false>;
126
+ export var _9: import("#UintType").default<"u16", undefined>;
128
127
  export { _9 as u16 };
129
- export var _10: import("#UintType").default<"u32", undefined, false>;
128
+ export var _10: import("#UintType").default<"u32", undefined>;
130
129
  export { _10 as u32 };
131
- export var _11: import("./BigUintType.js").default<"u64", undefined, false>;
130
+ export var _11: import("./BigUintType.js").default<"u64", undefined>;
132
131
  export { _11 as u64 };
133
- export var _12: import("#UintType").default<"u8", undefined, false>;
132
+ export var _12: import("#UintType").default<"u8", undefined>;
134
133
  export { _12 as u8 };
135
- export var _13: import("#UintType").default<"u32", undefined, false>;
134
+ export var _13: import("#UintType").default<"u32", undefined>;
136
135
  export { _13 as uint };
137
136
  export var _14: import("#UndefinedType").default;
138
137
  export { _14 as undefined };
@@ -155,7 +154,7 @@ declare namespace schema {
155
154
  declare const loose: (<const S extends Schema>(s: S) => NormalizeSchema<S>) & {
156
155
  array: <const S extends Schema>(of: S) => import("#ArrayType").default<NormalizeSchema<S>, true>;
157
156
  bigint: import("./BigIntType.js").default<"i64", true>;
158
- biguint: import("./BigUintType.js").default<"u64", true, false>;
157
+ biguint: import("./BigUintType.js").default<"u64", true>;
159
158
  blob: import("#BlobType").default;
160
159
  boolean: import("#BooleanType").default<true>;
161
160
  constructor: <const C extends import("@rcompat/type").AbstractNewable>(c: C) => import("#ConstructorType").default<C>;
@@ -191,12 +190,12 @@ declare const loose: (<const S extends Schema>(s: S) => NormalizeSchema<S>) & {
191
190
  string: import("#StringType").default;
192
191
  symbol: import("./SymbolType.js").default;
193
192
  tuple: <const T extends Schema[]>(...items: T) => import("#TupleType").default<{ [K in keyof T]: NormalizeSchema<T[K]>; }, true>;
194
- u128: import("./BigUintType.js").default<"u128", true, false>;
195
- u16: import("#UintType").default<"u16", true, false>;
196
- u32: import("#UintType").default<"u32", true, false>;
197
- u64: import("./BigUintType.js").default<"u64", true, false>;
198
- u8: import("#UintType").default<"u8", true, false>;
199
- uint: import("#UintType").default<"u32", true, false>;
193
+ u128: import("./BigUintType.js").default<"u128", true>;
194
+ u16: import("#UintType").default<"u16", true>;
195
+ u32: import("#UintType").default<"u32", true>;
196
+ u64: import("./BigUintType.js").default<"u64", true>;
197
+ u8: import("#UintType").default<"u8", true>;
198
+ uint: import("#UintType").default<"u32", true>;
200
199
  undefined: import("#UndefinedType").default;
201
200
  union: {
202
201
  (): import("#UnionType").default<[], true>;
@@ -209,7 +208,7 @@ declare const loose: (<const S extends Schema>(s: S) => NormalizeSchema<S>) & {
209
208
  declare const strict: (<const S extends Schema>(s: S) => NormalizeSchema<S>) & {
210
209
  array: <const S extends Schema>(of: S) => import("#ArrayType").default<NormalizeSchema<S>, false>;
211
210
  bigint: import("./BigIntType.js").default<"i64", false>;
212
- biguint: import("./BigUintType.js").default<"u64", false, false>;
211
+ biguint: import("./BigUintType.js").default<"u64", false>;
213
212
  blob: import("#BlobType").default;
214
213
  boolean: import("#BooleanType").default<false>;
215
214
  constructor: <const C extends import("@rcompat/type").AbstractNewable>(c: C) => import("#ConstructorType").default<C>;
@@ -245,12 +244,12 @@ declare const strict: (<const S extends Schema>(s: S) => NormalizeSchema<S>) & {
245
244
  string: import("#StringType").default;
246
245
  symbol: import("./SymbolType.js").default;
247
246
  tuple: <const T extends Schema[]>(...items: T) => import("#TupleType").default<{ [K in keyof T]: NormalizeSchema<T[K]>; }, false>;
248
- u128: import("./BigUintType.js").default<"u128", false, false>;
249
- u16: import("#UintType").default<"u16", false, false>;
250
- u32: import("#UintType").default<"u32", false, false>;
251
- u64: import("./BigUintType.js").default<"u64", false, false>;
252
- u8: import("#UintType").default<"u8", false, false>;
253
- uint: import("#UintType").default<"u32", false, false>;
247
+ u128: import("./BigUintType.js").default<"u128", false>;
248
+ u16: import("#UintType").default<"u16", false>;
249
+ u32: import("#UintType").default<"u32", false>;
250
+ u64: import("./BigUintType.js").default<"u64", false>;
251
+ u8: import("#UintType").default<"u8", false>;
252
+ uint: import("#UintType").default<"u32", false>;
254
253
  undefined: import("#UndefinedType").default;
255
254
  union: {
256
255
  (): import("#UnionType").default<[], false>;
@@ -15,6 +15,38 @@ declare const errors: {
15
15
  enum_invalid_key: (key: string) => import("@rcompat/error").CodeError<"enum_invalid_key">;
16
16
  };
17
17
  export type Code = keyof typeof errors;
18
- export declare const Code: { [K in Code]: K; };
19
- export default errors;
18
+ declare const schema_errors: {
19
+ unique_subtype_not_primitive: (subtype: string) => import("@rcompat/error").CodeError<"unique_subtype_not_primitive">;
20
+ min_negative: (limit: number) => import("@rcompat/error").CodeError<"min_negative">;
21
+ max_negative: (limit: number) => import("@rcompat/error").CodeError<"max_negative">;
22
+ length_not_finite: (from: number, to: number) => import("@rcompat/error").CodeError<"length_not_finite">;
23
+ length_not_positive: (from: number, to: number) => import("@rcompat/error").CodeError<"length_not_positive">;
24
+ length_not_integer: (from: number, to: number) => import("@rcompat/error").CodeError<"length_not_integer">;
25
+ length_from_exceeds_to: (from: number, to: number) => import("@rcompat/error").CodeError<"length_from_exceeds_to">;
26
+ min_limit_not_finite: (limit: number) => import("@rcompat/error").CodeError<"min_limit_not_finite">;
27
+ min_limit_not_integer: (limit: number) => import("@rcompat/error").CodeError<"min_limit_not_integer">;
28
+ max_limit_not_finite: (limit: number) => import("@rcompat/error").CodeError<"max_limit_not_finite">;
29
+ max_limit_not_integer: (limit: number) => import("@rcompat/error").CodeError<"max_limit_not_integer">;
30
+ extend_key_collision: (key: string) => import("@rcompat/error").CodeError<"extend_key_collision">;
31
+ union_at_least_two_members: () => import("@rcompat/error").CodeError<"union_at_least_two_members">;
32
+ enum_invalid_key: (key: string) => import("@rcompat/error").CodeError<"enum_invalid_key">;
33
+ } & {
34
+ Code: {
35
+ enum_invalid_key: "enum_invalid_key";
36
+ extend_key_collision: "extend_key_collision";
37
+ length_from_exceeds_to: "length_from_exceeds_to";
38
+ length_not_finite: "length_not_finite";
39
+ length_not_integer: "length_not_integer";
40
+ length_not_positive: "length_not_positive";
41
+ max_limit_not_finite: "max_limit_not_finite";
42
+ max_limit_not_integer: "max_limit_not_integer";
43
+ max_negative: "max_negative";
44
+ min_limit_not_finite: "min_limit_not_finite";
45
+ min_limit_not_integer: "min_limit_not_integer";
46
+ min_negative: "min_negative";
47
+ union_at_least_two_members: "union_at_least_two_members";
48
+ unique_subtype_not_primitive: "unique_subtype_not_primitive";
49
+ };
50
+ };
51
+ export default schema_errors;
20
52
  //# sourceMappingURL=schema-errors.d.ts.map
@@ -16,6 +16,7 @@ const errors = error.coded({
16
16
  union_at_least_two_members: () => t `union type must have at least two members`,
17
17
  enum_invalid_key: (key) => t `enum: key ${key} must be SCREAMING_SNAKE_CASE`,
18
18
  });
19
- export const Code = Object.fromEntries(Object.keys(errors).map(k => [k, k]));
20
- export default errors;
19
+ const Code = Object.fromEntries(Object.keys(errors).map(k => [k, k]));
20
+ const schema_errors = Object.assign(errors, { Code });
21
+ export default schema_errors;
21
22
  //# sourceMappingURL=schema-errors.js.map
@@ -1,8 +1,8 @@
1
1
  import BigUintType from "#BigUintType";
2
2
  declare const u128: {
3
- vanilla: BigUintType<"u128", undefined, false>;
4
- loose: BigUintType<"u128", true, false>;
5
- strict: BigUintType<"u128", false, false>;
3
+ vanilla: BigUintType<"u128", undefined>;
4
+ loose: BigUintType<"u128", true>;
5
+ strict: BigUintType<"u128", false>;
6
6
  };
7
7
  export default u128;
8
8
  //# sourceMappingURL=u128.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import UintType from "#UintType";
2
2
  declare const u16: {
3
- vanilla: UintType<"u16", undefined, false>;
4
- loose: UintType<"u16", true, false>;
5
- strict: UintType<"u16", false, false>;
3
+ vanilla: UintType<"u16", undefined>;
4
+ loose: UintType<"u16", true>;
5
+ strict: UintType<"u16", false>;
6
6
  };
7
7
  export default u16;
8
8
  //# sourceMappingURL=u16.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import UintType from "#UintType";
2
2
  declare const u32: {
3
- vanilla: UintType<"u32", undefined, false>;
4
- loose: UintType<"u32", true, false>;
5
- strict: UintType<"u32", false, false>;
3
+ vanilla: UintType<"u32", undefined>;
4
+ loose: UintType<"u32", true>;
5
+ strict: UintType<"u32", false>;
6
6
  };
7
7
  export default u32;
8
8
  //# sourceMappingURL=u32.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import BigUintType from "#BigUintType";
2
2
  declare const u64: {
3
- vanilla: BigUintType<"u64", undefined, false>;
4
- loose: BigUintType<"u64", true, false>;
5
- strict: BigUintType<"u64", false, false>;
3
+ vanilla: BigUintType<"u64", undefined>;
4
+ loose: BigUintType<"u64", true>;
5
+ strict: BigUintType<"u64", false>;
6
6
  };
7
7
  export default u64;
8
8
  //# sourceMappingURL=u64.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import UintType from "#UintType";
2
2
  declare const u8: {
3
- vanilla: UintType<"u8", undefined, false>;
4
- loose: UintType<"u8", true, false>;
5
- strict: UintType<"u8", false, false>;
3
+ vanilla: UintType<"u8", undefined>;
4
+ loose: UintType<"u8", true>;
5
+ strict: UintType<"u8", false>;
6
6
  };
7
7
  export default u8;
8
8
  //# sourceMappingURL=u8.d.ts.map
@@ -1,5 +1,7 @@
1
1
  import regex from "#validator/regex";
2
- const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u;
2
+ // Choose the first dot after the domain's first character. Keeping dots out
3
+ // of the preceding repetition avoids quadratic backtracking on hostile input.
4
+ const re = /^[^\s@]+@[^\s@][^\s@.]*\.[^\s@]+$/u;
3
5
  export default function email(options) {
4
6
  return regex(re, options ?? (x => `"${x}" is not a valid email`));
5
7
  }
@@ -1,2 +1,3 @@
1
- export { default } from "#ParseError";
1
+ import ParseError from "#ParseError";
2
+ export default ParseError;
2
3
  //# sourceMappingURL=ParseError.d.ts.map
@@ -1,2 +1,3 @@
1
- export { default } from "#ParseError";
1
+ import ParseError from "#ParseError";
2
+ export default ParseError;
2
3
  //# sourceMappingURL=ParseError.js.map
@@ -1,3 +1,4 @@
1
1
  export type { default as Serialized } from "#Serialized";
2
- export { default } from "#StoreType";
2
+ import StoreType from "#StoreType";
3
+ export default StoreType;
3
4
  //# sourceMappingURL=StoreType.d.ts.map
@@ -1,2 +1,3 @@
1
- export { default } from "#StoreType";
1
+ import StoreType from "#StoreType";
2
+ export default StoreType;
2
3
  //# sourceMappingURL=StoreType.js.map
@@ -1,3 +1,4 @@
1
1
  export type * from "#index";
2
- export { default } from "#index";
2
+ import pema from "#index";
3
+ export default pema;
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,3 @@
1
- export { default } from "#index";
1
+ import pema from "#index";
2
+ export default pema;
2
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -48,5 +48,5 @@
48
48
  "test": "proby"
49
49
  },
50
50
  "type": "module",
51
- "version": "0.13.0"
51
+ "version": "0.14.1"
52
52
  }
@@ -1,5 +0,0 @@
1
- type Sequence = {
2
- readonly generated: "sequence";
3
- };
4
- export type { Sequence as default };
5
- //# sourceMappingURL=Sequence.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Sequence.js.map