@predictorsdk/client 0.1.1 → 0.1.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.
Files changed (147) hide show
  1. package/README.md +1 -1
  2. package/dist/Client.js +47 -7
  3. package/dist/api/client/requests/GetSportsMatchingMarketsRequest.d.ts +4 -4
  4. package/dist/api/types/ErrorResponse.d.ts +1 -1
  5. package/dist/api/types/PlatformMarket.d.ts +8 -16
  6. package/dist/api/types/PlatformMarket.js +1 -9
  7. package/dist/api/types/PlatformMarketPlatform.d.ts +7 -0
  8. package/dist/api/types/PlatformMarketPlatform.js +7 -0
  9. package/dist/api/types/index.d.ts +1 -0
  10. package/dist/api/types/index.js +1 -0
  11. package/dist/core/auth/BasicAuth.d.ts +2 -2
  12. package/dist/core/auth/BasicAuth.js +6 -1
  13. package/dist/core/index.d.ts +1 -0
  14. package/dist/core/index.js +1 -0
  15. package/dist/core/schemas/Schema.d.ts +88 -0
  16. package/dist/core/schemas/Schema.js +22 -0
  17. package/dist/core/schemas/builders/bigint/bigint.d.ts +2 -0
  18. package/dist/core/schemas/builders/bigint/bigint.js +53 -0
  19. package/dist/core/schemas/builders/bigint/index.d.ts +1 -0
  20. package/dist/core/schemas/builders/bigint/index.js +1 -0
  21. package/dist/core/schemas/builders/date/date.d.ts +2 -0
  22. package/dist/core/schemas/builders/date/date.js +62 -0
  23. package/dist/core/schemas/builders/date/index.d.ts +1 -0
  24. package/dist/core/schemas/builders/date/index.js +1 -0
  25. package/dist/core/schemas/builders/enum/enum.d.ts +2 -0
  26. package/dist/core/schemas/builders/enum/enum.js +35 -0
  27. package/dist/core/schemas/builders/enum/index.d.ts +1 -0
  28. package/dist/core/schemas/builders/enum/index.js +1 -0
  29. package/dist/core/schemas/builders/index.d.ts +14 -0
  30. package/dist/core/schemas/builders/index.js +14 -0
  31. package/dist/core/schemas/builders/lazy/index.d.ts +3 -0
  32. package/dist/core/schemas/builders/lazy/index.js +2 -0
  33. package/dist/core/schemas/builders/lazy/lazy.d.ts +5 -0
  34. package/dist/core/schemas/builders/lazy/lazy.js +22 -0
  35. package/dist/core/schemas/builders/lazy/lazyObject.d.ts +3 -0
  36. package/dist/core/schemas/builders/lazy/lazyObject.js +17 -0
  37. package/dist/core/schemas/builders/list/index.d.ts +1 -0
  38. package/dist/core/schemas/builders/list/index.js +1 -0
  39. package/dist/core/schemas/builders/list/list.d.ts +2 -0
  40. package/dist/core/schemas/builders/list/list.js +49 -0
  41. package/dist/core/schemas/builders/literals/booleanLiteral.d.ts +2 -0
  42. package/dist/core/schemas/builders/literals/booleanLiteral.js +25 -0
  43. package/dist/core/schemas/builders/literals/index.d.ts +2 -0
  44. package/dist/core/schemas/builders/literals/index.js +2 -0
  45. package/dist/core/schemas/builders/literals/stringLiteral.d.ts +2 -0
  46. package/dist/core/schemas/builders/literals/stringLiteral.js +25 -0
  47. package/dist/core/schemas/builders/object/index.d.ts +6 -0
  48. package/dist/core/schemas/builders/object/index.js +3 -0
  49. package/dist/core/schemas/builders/object/object.d.ts +3 -0
  50. package/dist/core/schemas/builders/object/object.js +381 -0
  51. package/dist/core/schemas/builders/object/objectWithoutOptionalProperties.d.ts +6 -0
  52. package/dist/core/schemas/builders/object/objectWithoutOptionalProperties.js +4 -0
  53. package/dist/core/schemas/builders/object/property.d.ts +8 -0
  54. package/dist/core/schemas/builders/object/property.js +11 -0
  55. package/dist/core/schemas/builders/object/types.d.ts +31 -0
  56. package/dist/core/schemas/builders/object/types.js +1 -0
  57. package/dist/core/schemas/builders/object-like/getObjectLikeUtils.d.ts +9 -0
  58. package/dist/core/schemas/builders/object-like/getObjectLikeUtils.js +62 -0
  59. package/dist/core/schemas/builders/object-like/index.d.ts +2 -0
  60. package/dist/core/schemas/builders/object-like/index.js +1 -0
  61. package/dist/core/schemas/builders/object-like/types.d.ts +7 -0
  62. package/dist/core/schemas/builders/object-like/types.js +1 -0
  63. package/dist/core/schemas/builders/primitives/any.d.ts +2 -0
  64. package/dist/core/schemas/builders/primitives/any.js +6 -0
  65. package/dist/core/schemas/builders/primitives/boolean.d.ts +2 -0
  66. package/dist/core/schemas/builders/primitives/boolean.js +22 -0
  67. package/dist/core/schemas/builders/primitives/index.d.ts +6 -0
  68. package/dist/core/schemas/builders/primitives/index.js +6 -0
  69. package/dist/core/schemas/builders/primitives/never.d.ts +2 -0
  70. package/dist/core/schemas/builders/primitives/never.js +11 -0
  71. package/dist/core/schemas/builders/primitives/number.d.ts +2 -0
  72. package/dist/core/schemas/builders/primitives/number.js +22 -0
  73. package/dist/core/schemas/builders/primitives/string.d.ts +2 -0
  74. package/dist/core/schemas/builders/primitives/string.js +22 -0
  75. package/dist/core/schemas/builders/primitives/unknown.d.ts +2 -0
  76. package/dist/core/schemas/builders/primitives/unknown.js +3 -0
  77. package/dist/core/schemas/builders/record/index.d.ts +2 -0
  78. package/dist/core/schemas/builders/record/index.js +1 -0
  79. package/dist/core/schemas/builders/record/record.d.ts +4 -0
  80. package/dist/core/schemas/builders/record/record.js +133 -0
  81. package/dist/core/schemas/builders/record/types.d.ts +6 -0
  82. package/dist/core/schemas/builders/record/types.js +1 -0
  83. package/dist/core/schemas/builders/schema-utils/JsonError.d.ts +5 -0
  84. package/dist/core/schemas/builders/schema-utils/JsonError.js +9 -0
  85. package/dist/core/schemas/builders/schema-utils/ParseError.d.ts +5 -0
  86. package/dist/core/schemas/builders/schema-utils/ParseError.js +9 -0
  87. package/dist/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +21 -0
  88. package/dist/core/schemas/builders/schema-utils/getSchemaUtils.js +150 -0
  89. package/dist/core/schemas/builders/schema-utils/index.d.ts +4 -0
  90. package/dist/core/schemas/builders/schema-utils/index.js +3 -0
  91. package/dist/core/schemas/builders/schema-utils/stringifyValidationErrors.d.ts +2 -0
  92. package/dist/core/schemas/builders/schema-utils/stringifyValidationErrors.js +6 -0
  93. package/dist/core/schemas/builders/set/index.d.ts +1 -0
  94. package/dist/core/schemas/builders/set/index.js +1 -0
  95. package/dist/core/schemas/builders/set/set.d.ts +2 -0
  96. package/dist/core/schemas/builders/set/set.js +42 -0
  97. package/dist/core/schemas/builders/undiscriminated-union/index.d.ts +2 -0
  98. package/dist/core/schemas/builders/undiscriminated-union/index.js +1 -0
  99. package/dist/core/schemas/builders/undiscriminated-union/types.d.ts +4 -0
  100. package/dist/core/schemas/builders/undiscriminated-union/types.js +1 -0
  101. package/dist/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.d.ts +3 -0
  102. package/dist/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +39 -0
  103. package/dist/core/schemas/builders/union/discriminant.d.ts +5 -0
  104. package/dist/core/schemas/builders/union/discriminant.js +6 -0
  105. package/dist/core/schemas/builders/union/index.d.ts +4 -0
  106. package/dist/core/schemas/builders/union/index.js +2 -0
  107. package/dist/core/schemas/builders/union/types.d.ts +13 -0
  108. package/dist/core/schemas/builders/union/types.js +1 -0
  109. package/dist/core/schemas/builders/union/union.d.ts +4 -0
  110. package/dist/core/schemas/builders/union/union.js +127 -0
  111. package/dist/core/schemas/index.d.ts +2 -0
  112. package/dist/core/schemas/index.js +1 -0
  113. package/dist/core/schemas/utils/MaybePromise.d.ts +1 -0
  114. package/dist/core/schemas/utils/MaybePromise.js +1 -0
  115. package/dist/core/schemas/utils/addQuestionMarksToNullableProperties.d.ts +7 -0
  116. package/dist/core/schemas/utils/addQuestionMarksToNullableProperties.js +1 -0
  117. package/dist/core/schemas/utils/createIdentitySchemaCreator.d.ts +2 -0
  118. package/dist/core/schemas/utils/createIdentitySchemaCreator.js +15 -0
  119. package/dist/core/schemas/utils/entries.d.ts +1 -0
  120. package/dist/core/schemas/utils/entries.js +3 -0
  121. package/dist/core/schemas/utils/filterObject.d.ts +1 -0
  122. package/dist/core/schemas/utils/filterObject.js +10 -0
  123. package/dist/core/schemas/utils/getErrorMessageForIncorrectType.d.ts +1 -0
  124. package/dist/core/schemas/utils/getErrorMessageForIncorrectType.js +24 -0
  125. package/dist/core/schemas/utils/isPlainObject.d.ts +1 -0
  126. package/dist/core/schemas/utils/isPlainObject.js +12 -0
  127. package/dist/core/schemas/utils/keys.d.ts +1 -0
  128. package/dist/core/schemas/utils/keys.js +3 -0
  129. package/dist/core/schemas/utils/maybeSkipValidation.d.ts +2 -0
  130. package/dist/core/schemas/utils/maybeSkipValidation.js +28 -0
  131. package/dist/core/schemas/utils/partition.d.ts +1 -0
  132. package/dist/core/schemas/utils/partition.js +12 -0
  133. package/dist/index.d.ts +1 -0
  134. package/dist/index.js +1 -0
  135. package/dist/serialization/index.d.ts +1 -0
  136. package/dist/serialization/index.js +1 -0
  137. package/dist/serialization/types/ErrorResponse.d.ts +10 -0
  138. package/dist/serialization/types/ErrorResponse.js +6 -0
  139. package/dist/serialization/types/PlatformMarket.d.ts +16 -0
  140. package/dist/serialization/types/PlatformMarket.js +12 -0
  141. package/dist/serialization/types/PlatformMarketPlatform.d.ts +7 -0
  142. package/dist/serialization/types/PlatformMarketPlatform.js +3 -0
  143. package/dist/serialization/types/SportsMatchingResponse.d.ts +10 -0
  144. package/dist/serialization/types/SportsMatchingResponse.js +6 -0
  145. package/dist/serialization/types/index.d.ts +4 -0
  146. package/dist/serialization/types/index.js +4 -0
  147. package/package.json +13 -2
@@ -0,0 +1 @@
1
+ export { getObjectLikeUtils, withParsedProperties } from "./getObjectLikeUtils.js";
@@ -0,0 +1,7 @@
1
+ import type { BaseSchema, Schema } from "../../Schema.js";
2
+ export type ObjectLikeSchema<Raw, Parsed> = Schema<Raw, Parsed> & BaseSchema<Raw, Parsed> & ObjectLikeUtils<Raw, Parsed>;
3
+ export interface ObjectLikeUtils<Raw, Parsed> {
4
+ withParsedProperties: <T extends Record<string, any>>(properties: {
5
+ [K in keyof T]: T[K] | ((parsed: Parsed) => T[K]);
6
+ }) => ObjectLikeSchema<Raw, Parsed & T>;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ export declare const any: () => Schema<any, any>;
@@ -0,0 +1,6 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator.js";
3
+ export const any = createIdentitySchemaCreator(SchemaType.ANY, (value) => ({
4
+ ok: true,
5
+ value,
6
+ }));
@@ -0,0 +1,2 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ export declare const boolean: () => Schema<boolean, boolean>;
@@ -0,0 +1,22 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator.js";
3
+ import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.js";
4
+ export const boolean = createIdentitySchemaCreator(SchemaType.BOOLEAN, (value, { breadcrumbsPrefix = [] } = {}) => {
5
+ if (typeof value === "boolean") {
6
+ return {
7
+ ok: true,
8
+ value,
9
+ };
10
+ }
11
+ else {
12
+ return {
13
+ ok: false,
14
+ errors: [
15
+ {
16
+ path: breadcrumbsPrefix,
17
+ message: getErrorMessageForIncorrectType(value, "boolean"),
18
+ },
19
+ ],
20
+ };
21
+ }
22
+ });
@@ -0,0 +1,6 @@
1
+ export { any } from "./any.js";
2
+ export { boolean } from "./boolean.js";
3
+ export { never } from "./never.js";
4
+ export { number } from "./number.js";
5
+ export { string } from "./string.js";
6
+ export { unknown } from "./unknown.js";
@@ -0,0 +1,6 @@
1
+ export { any } from "./any.js";
2
+ export { boolean } from "./boolean.js";
3
+ export { never } from "./never.js";
4
+ export { number } from "./number.js";
5
+ export { string } from "./string.js";
6
+ export { unknown } from "./unknown.js";
@@ -0,0 +1,2 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ export declare const never: () => Schema<never, never>;
@@ -0,0 +1,11 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator.js";
3
+ export const never = createIdentitySchemaCreator(SchemaType.NEVER, (_value, { breadcrumbsPrefix = [] } = {}) => ({
4
+ ok: false,
5
+ errors: [
6
+ {
7
+ path: breadcrumbsPrefix,
8
+ message: "Expected never",
9
+ },
10
+ ],
11
+ }));
@@ -0,0 +1,2 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ export declare const number: () => Schema<number, number>;
@@ -0,0 +1,22 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator.js";
3
+ import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.js";
4
+ export const number = createIdentitySchemaCreator(SchemaType.NUMBER, (value, { breadcrumbsPrefix = [] } = {}) => {
5
+ if (typeof value === "number") {
6
+ return {
7
+ ok: true,
8
+ value,
9
+ };
10
+ }
11
+ else {
12
+ return {
13
+ ok: false,
14
+ errors: [
15
+ {
16
+ path: breadcrumbsPrefix,
17
+ message: getErrorMessageForIncorrectType(value, "number"),
18
+ },
19
+ ],
20
+ };
21
+ }
22
+ });
@@ -0,0 +1,2 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ export declare const string: () => Schema<string, string>;
@@ -0,0 +1,22 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator.js";
3
+ import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.js";
4
+ export const string = createIdentitySchemaCreator(SchemaType.STRING, (value, { breadcrumbsPrefix = [] } = {}) => {
5
+ if (typeof value === "string") {
6
+ return {
7
+ ok: true,
8
+ value,
9
+ };
10
+ }
11
+ else {
12
+ return {
13
+ ok: false,
14
+ errors: [
15
+ {
16
+ path: breadcrumbsPrefix,
17
+ message: getErrorMessageForIncorrectType(value, "string"),
18
+ },
19
+ ],
20
+ };
21
+ }
22
+ });
@@ -0,0 +1,2 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ export declare const unknown: () => Schema<unknown, unknown>;
@@ -0,0 +1,3 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { createIdentitySchemaCreator } from "../../utils/createIdentitySchemaCreator.js";
3
+ export const unknown = createIdentitySchemaCreator(SchemaType.UNKNOWN, (value) => ({ ok: true, value }));
@@ -0,0 +1,2 @@
1
+ export { partialRecord, record } from "./record.js";
2
+ export type { BasePartialRecordSchema, BaseRecordSchema, PartialRecordSchema, RecordSchema } from "./types.js";
@@ -0,0 +1 @@
1
+ export { partialRecord, record } from "./record.js";
@@ -0,0 +1,4 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ import type { PartialRecordSchema, RecordSchema } from "./types.js";
3
+ export declare function record<RawKey extends string | number, RawValue, ParsedValue, ParsedKey extends string | number>(keySchema: Schema<RawKey, ParsedKey>, valueSchema: Schema<RawValue, ParsedValue>): RecordSchema<RawKey, RawValue, ParsedKey, ParsedValue>;
4
+ export declare function partialRecord<RawKey extends string | number, RawValue, ParsedValue, ParsedKey extends string | number>(keySchema: Schema<RawKey, ParsedKey>, valueSchema: Schema<RawValue, ParsedValue>): PartialRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue>;
@@ -0,0 +1,133 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.js";
3
+ import { isPlainObject } from "../../utils/isPlainObject.js";
4
+ import { maybeSkipValidation } from "../../utils/maybeSkipValidation.js";
5
+ import { getSchemaUtils } from "../schema-utils/index.js";
6
+ // eslint-disable-next-line @typescript-eslint/unbound-method
7
+ const _hasOwn = Object.prototype.hasOwnProperty;
8
+ export function record(keySchema, valueSchema) {
9
+ const baseSchema = {
10
+ parse: (raw, opts) => {
11
+ return validateAndTransformRecord({
12
+ value: raw,
13
+ isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
14
+ transformKey: (key) => keySchema.parse(key, {
15
+ ...opts,
16
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`],
17
+ }),
18
+ transformValue: (value, key) => valueSchema.parse(value, {
19
+ ...opts,
20
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`],
21
+ }),
22
+ breadcrumbsPrefix: opts?.breadcrumbsPrefix,
23
+ });
24
+ },
25
+ json: (parsed, opts) => {
26
+ return validateAndTransformRecord({
27
+ value: parsed,
28
+ isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
29
+ transformKey: (key) => keySchema.json(key, {
30
+ ...opts,
31
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`],
32
+ }),
33
+ transformValue: (value, key) => valueSchema.json(value, {
34
+ ...opts,
35
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`],
36
+ }),
37
+ breadcrumbsPrefix: opts?.breadcrumbsPrefix,
38
+ });
39
+ },
40
+ getType: () => SchemaType.RECORD,
41
+ };
42
+ return {
43
+ ...maybeSkipValidation(baseSchema),
44
+ ...getSchemaUtils(baseSchema),
45
+ };
46
+ }
47
+ export function partialRecord(keySchema, valueSchema) {
48
+ const baseSchema = {
49
+ parse: (raw, opts) => {
50
+ return validateAndTransformRecord({
51
+ value: raw,
52
+ isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
53
+ transformKey: (key) => keySchema.parse(key, {
54
+ ...opts,
55
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`],
56
+ }),
57
+ transformValue: (value, key) => valueSchema.parse(value, {
58
+ ...opts,
59
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`],
60
+ }),
61
+ breadcrumbsPrefix: opts?.breadcrumbsPrefix,
62
+ });
63
+ },
64
+ json: (parsed, opts) => {
65
+ return validateAndTransformRecord({
66
+ value: parsed,
67
+ isKeyNumeric: keySchema.getType() === SchemaType.NUMBER,
68
+ transformKey: (key) => keySchema.json(key, {
69
+ ...opts,
70
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key} (key)`],
71
+ }),
72
+ transformValue: (value, key) => valueSchema.json(value, {
73
+ ...opts,
74
+ breadcrumbsPrefix: [...(opts?.breadcrumbsPrefix ?? []), `${key}`],
75
+ }),
76
+ breadcrumbsPrefix: opts?.breadcrumbsPrefix,
77
+ });
78
+ },
79
+ getType: () => SchemaType.RECORD,
80
+ };
81
+ return {
82
+ ...maybeSkipValidation(baseSchema),
83
+ ...getSchemaUtils(baseSchema),
84
+ };
85
+ }
86
+ function validateAndTransformRecord({ value, isKeyNumeric, transformKey, transformValue, breadcrumbsPrefix = [], }) {
87
+ if (!isPlainObject(value)) {
88
+ return {
89
+ ok: false,
90
+ errors: [
91
+ {
92
+ path: breadcrumbsPrefix,
93
+ message: getErrorMessageForIncorrectType(value, "object"),
94
+ },
95
+ ],
96
+ };
97
+ }
98
+ const result = {};
99
+ const errors = [];
100
+ for (const stringKey in value) {
101
+ if (!_hasOwn.call(value, stringKey)) {
102
+ continue;
103
+ }
104
+ const entryValue = value[stringKey];
105
+ if (entryValue === undefined) {
106
+ continue;
107
+ }
108
+ let key = stringKey;
109
+ if (isKeyNumeric) {
110
+ const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
111
+ if (!Number.isNaN(numberKey)) {
112
+ key = numberKey;
113
+ }
114
+ }
115
+ const transformedKey = transformKey(key);
116
+ const transformedValue = transformValue(entryValue, key);
117
+ if (transformedKey.ok && transformedValue.ok) {
118
+ result[transformedKey.value] = transformedValue.value;
119
+ }
120
+ else {
121
+ if (!transformedKey.ok) {
122
+ errors.push(...transformedKey.errors);
123
+ }
124
+ if (!transformedValue.ok) {
125
+ errors.push(...transformedValue.errors);
126
+ }
127
+ }
128
+ }
129
+ if (errors.length === 0) {
130
+ return { ok: true, value: result };
131
+ }
132
+ return { ok: false, errors };
133
+ }
@@ -0,0 +1,6 @@
1
+ import type { BaseSchema } from "../../Schema.js";
2
+ import type { SchemaUtils } from "../schema-utils/index.js";
3
+ export type RecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BaseRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue> & SchemaUtils<Record<RawKey, RawValue>, Record<ParsedKey, ParsedValue>>;
4
+ export type BaseRecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BaseSchema<Record<RawKey, RawValue>, Record<ParsedKey, ParsedValue>>;
5
+ export type PartialRecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BasePartialRecordSchema<RawKey, RawValue, ParsedKey, ParsedValue> & SchemaUtils<Record<RawKey, RawValue>, Partial<Record<ParsedKey, ParsedValue>>>;
6
+ export type BasePartialRecordSchema<RawKey extends string | number, RawValue, ParsedKey extends string | number, ParsedValue> = BaseSchema<Record<RawKey, RawValue>, Partial<Record<ParsedKey, ParsedValue>>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { ValidationError } from "../../Schema.js";
2
+ export declare class JsonError extends Error {
3
+ readonly errors: ValidationError[];
4
+ constructor(errors: ValidationError[]);
5
+ }
@@ -0,0 +1,9 @@
1
+ import { stringifyValidationError } from "./stringifyValidationErrors.js";
2
+ export class JsonError extends Error {
3
+ errors;
4
+ constructor(errors) {
5
+ super(errors.map(stringifyValidationError).join("; "));
6
+ this.errors = errors;
7
+ Object.setPrototypeOf(this, JsonError.prototype);
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ import type { ValidationError } from "../../Schema.js";
2
+ export declare class ParseError extends Error {
3
+ readonly errors: ValidationError[];
4
+ constructor(errors: ValidationError[]);
5
+ }
@@ -0,0 +1,9 @@
1
+ import { stringifyValidationError } from "./stringifyValidationErrors.js";
2
+ export class ParseError extends Error {
3
+ errors;
4
+ constructor(errors) {
5
+ super(errors.map(stringifyValidationError).join("; "));
6
+ this.errors = errors;
7
+ Object.setPrototypeOf(this, ParseError.prototype);
8
+ }
9
+ }
@@ -0,0 +1,21 @@
1
+ import { type BaseSchema, type Schema, type SchemaOptions } from "../../Schema.js";
2
+ export interface SchemaUtils<Raw, Parsed> {
3
+ nullable: () => Schema<Raw | null, Parsed | null>;
4
+ optional: () => Schema<Raw | null | undefined, Parsed | undefined>;
5
+ optionalNullable: () => Schema<Raw | null | undefined, Parsed | null | undefined>;
6
+ transform: <Transformed>(transformer: SchemaTransformer<Parsed, Transformed>) => Schema<Raw, Transformed>;
7
+ parseOrThrow: (raw: unknown, opts?: SchemaOptions) => Parsed;
8
+ jsonOrThrow: (raw: unknown, opts?: SchemaOptions) => Raw;
9
+ }
10
+ export interface SchemaTransformer<Parsed, Transformed> {
11
+ transform: (parsed: Parsed) => Transformed;
12
+ untransform: (transformed: any) => Parsed;
13
+ }
14
+ export declare function getSchemaUtils<Raw, Parsed>(schema: BaseSchema<Raw, Parsed>): SchemaUtils<Raw, Parsed>;
15
+ /**
16
+ * schema utils are defined in one file to resolve issues with circular imports
17
+ */
18
+ export declare function nullable<Raw, Parsed>(schema: BaseSchema<Raw, Parsed>): Schema<Raw | null, Parsed | null>;
19
+ export declare function optional<Raw, Parsed>(schema: BaseSchema<Raw, Parsed>): Schema<Raw | null | undefined, Parsed | undefined>;
20
+ export declare function optionalNullable<Raw, Parsed>(schema: BaseSchema<Raw, Parsed>): Schema<Raw | null | undefined, Parsed | null | undefined>;
21
+ export declare function transform<Raw, Parsed, Transformed>(schema: BaseSchema<Raw, Parsed>, transformer: SchemaTransformer<Parsed, Transformed>): Schema<Raw, Transformed>;
@@ -0,0 +1,150 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { JsonError } from "./JsonError.js";
3
+ import { ParseError } from "./ParseError.js";
4
+ export function getSchemaUtils(schema) {
5
+ return {
6
+ nullable: () => nullable(schema),
7
+ optional: () => optional(schema),
8
+ optionalNullable: () => optionalNullable(schema),
9
+ transform: (transformer) => transform(schema, transformer),
10
+ parseOrThrow: (raw, opts) => {
11
+ const parsed = schema.parse(raw, opts);
12
+ if (parsed.ok) {
13
+ return parsed.value;
14
+ }
15
+ throw new ParseError(parsed.errors);
16
+ },
17
+ jsonOrThrow: (parsed, opts) => {
18
+ const raw = schema.json(parsed, opts);
19
+ if (raw.ok) {
20
+ return raw.value;
21
+ }
22
+ throw new JsonError(raw.errors);
23
+ },
24
+ };
25
+ }
26
+ /**
27
+ * schema utils are defined in one file to resolve issues with circular imports
28
+ */
29
+ export function nullable(schema) {
30
+ const baseSchema = {
31
+ parse: (raw, opts) => {
32
+ if (raw == null) {
33
+ return {
34
+ ok: true,
35
+ value: null,
36
+ };
37
+ }
38
+ return schema.parse(raw, opts);
39
+ },
40
+ json: (parsed, opts) => {
41
+ if (parsed == null) {
42
+ return {
43
+ ok: true,
44
+ value: null,
45
+ };
46
+ }
47
+ return schema.json(parsed, opts);
48
+ },
49
+ getType: () => SchemaType.NULLABLE,
50
+ };
51
+ return {
52
+ ...baseSchema,
53
+ ...getSchemaUtils(baseSchema),
54
+ };
55
+ }
56
+ export function optional(schema) {
57
+ const baseSchema = {
58
+ parse: (raw, opts) => {
59
+ if (raw == null) {
60
+ return {
61
+ ok: true,
62
+ value: undefined,
63
+ };
64
+ }
65
+ return schema.parse(raw, opts);
66
+ },
67
+ json: (parsed, opts) => {
68
+ if (opts?.omitUndefined && parsed === undefined) {
69
+ return {
70
+ ok: true,
71
+ value: undefined,
72
+ };
73
+ }
74
+ if (parsed == null) {
75
+ return {
76
+ ok: true,
77
+ value: null,
78
+ };
79
+ }
80
+ return schema.json(parsed, opts);
81
+ },
82
+ getType: () => SchemaType.OPTIONAL,
83
+ };
84
+ return {
85
+ ...baseSchema,
86
+ ...getSchemaUtils(baseSchema),
87
+ };
88
+ }
89
+ export function optionalNullable(schema) {
90
+ const baseSchema = {
91
+ parse: (raw, opts) => {
92
+ if (raw === undefined) {
93
+ return {
94
+ ok: true,
95
+ value: undefined,
96
+ };
97
+ }
98
+ if (raw === null) {
99
+ return {
100
+ ok: true,
101
+ value: null,
102
+ };
103
+ }
104
+ return schema.parse(raw, opts);
105
+ },
106
+ json: (parsed, opts) => {
107
+ if (parsed === undefined) {
108
+ return {
109
+ ok: true,
110
+ value: undefined,
111
+ };
112
+ }
113
+ if (parsed === null) {
114
+ return {
115
+ ok: true,
116
+ value: null,
117
+ };
118
+ }
119
+ return schema.json(parsed, opts);
120
+ },
121
+ getType: () => SchemaType.OPTIONAL_NULLABLE,
122
+ };
123
+ return {
124
+ ...baseSchema,
125
+ ...getSchemaUtils(baseSchema),
126
+ };
127
+ }
128
+ export function transform(schema, transformer) {
129
+ const baseSchema = {
130
+ parse: (raw, opts) => {
131
+ const parsed = schema.parse(raw, opts);
132
+ if (!parsed.ok) {
133
+ return parsed;
134
+ }
135
+ return {
136
+ ok: true,
137
+ value: transformer.transform(parsed.value),
138
+ };
139
+ },
140
+ json: (transformed, opts) => {
141
+ const parsed = transformer.untransform(transformed);
142
+ return schema.json(parsed, opts);
143
+ },
144
+ getType: () => schema.getType(),
145
+ };
146
+ return {
147
+ ...baseSchema,
148
+ ...getSchemaUtils(baseSchema),
149
+ };
150
+ }
@@ -0,0 +1,4 @@
1
+ export type { SchemaUtils } from "./getSchemaUtils.js";
2
+ export { getSchemaUtils, optional, transform } from "./getSchemaUtils.js";
3
+ export { JsonError } from "./JsonError.js";
4
+ export { ParseError } from "./ParseError.js";
@@ -0,0 +1,3 @@
1
+ export { getSchemaUtils, optional, transform } from "./getSchemaUtils.js";
2
+ export { JsonError } from "./JsonError.js";
3
+ export { ParseError } from "./ParseError.js";
@@ -0,0 +1,2 @@
1
+ import type { ValidationError } from "../../Schema.js";
2
+ export declare function stringifyValidationError(error: ValidationError): string;
@@ -0,0 +1,6 @@
1
+ export function stringifyValidationError(error) {
2
+ if (error.path.length === 0) {
3
+ return error.message;
4
+ }
5
+ return `${error.path.join(" -> ")}: ${error.message}`;
6
+ }
@@ -0,0 +1 @@
1
+ export { set } from "./set.js";
@@ -0,0 +1 @@
1
+ export { set } from "./set.js";
@@ -0,0 +1,2 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ export declare function set<Raw, Parsed>(schema: Schema<Raw, Parsed>): Schema<Raw[], Set<Parsed>>;
@@ -0,0 +1,42 @@
1
+ import { SchemaType } from "../../Schema.js";
2
+ import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.js";
3
+ import { maybeSkipValidation } from "../../utils/maybeSkipValidation.js";
4
+ import { list } from "../list/index.js";
5
+ import { getSchemaUtils } from "../schema-utils/index.js";
6
+ export function set(schema) {
7
+ const listSchema = list(schema);
8
+ const baseSchema = {
9
+ parse: (raw, opts) => {
10
+ const parsedList = listSchema.parse(raw, opts);
11
+ if (parsedList.ok) {
12
+ return {
13
+ ok: true,
14
+ value: new Set(parsedList.value),
15
+ };
16
+ }
17
+ else {
18
+ return parsedList;
19
+ }
20
+ },
21
+ json: (parsed, opts) => {
22
+ if (!(parsed instanceof Set)) {
23
+ return {
24
+ ok: false,
25
+ errors: [
26
+ {
27
+ path: opts?.breadcrumbsPrefix ?? [],
28
+ message: getErrorMessageForIncorrectType(parsed, "Set"),
29
+ },
30
+ ],
31
+ };
32
+ }
33
+ const jsonList = listSchema.json([...parsed], opts);
34
+ return jsonList;
35
+ },
36
+ getType: () => SchemaType.SET,
37
+ };
38
+ return {
39
+ ...maybeSkipValidation(baseSchema),
40
+ ...getSchemaUtils(baseSchema),
41
+ };
42
+ }
@@ -0,0 +1,2 @@
1
+ export type { inferParsedUnidiscriminatedUnionSchema, inferRawUnidiscriminatedUnionSchema, UndiscriminatedUnionSchema, } from "./types.js";
2
+ export { undiscriminatedUnion } from "./undiscriminatedUnion.js";
@@ -0,0 +1 @@
1
+ export { undiscriminatedUnion } from "./undiscriminatedUnion.js";
@@ -0,0 +1,4 @@
1
+ import type { inferParsed, inferRaw, Schema } from "../../Schema.js";
2
+ export type UndiscriminatedUnionSchema<Schemas extends [...Schema[]]> = Schema<inferRawUnidiscriminatedUnionSchema<Schemas>, inferParsedUnidiscriminatedUnionSchema<Schemas>>;
3
+ export type inferRawUnidiscriminatedUnionSchema<Schemas extends [...Schema[]]> = inferRaw<Schemas[number]>;
4
+ export type inferParsedUnidiscriminatedUnionSchema<Schemas extends [...Schema[]]> = inferParsed<Schemas[number]>;
@@ -0,0 +1,3 @@
1
+ import { type Schema } from "../../Schema.js";
2
+ import type { inferParsedUnidiscriminatedUnionSchema, inferRawUnidiscriminatedUnionSchema } from "./types.js";
3
+ export declare function undiscriminatedUnion<Schemas extends [Schema<any, any>, ...Schema<any, any>[]]>(schemas: Schemas): Schema<inferRawUnidiscriminatedUnionSchema<Schemas>, inferParsedUnidiscriminatedUnionSchema<Schemas>>;