@monorise/core 3.0.1 → 3.0.3

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 (206) hide show
  1. package/dist/index.d.ts +4759 -27
  2. package/dist/index.js +7940 -31
  3. package/dist/index.js.map +1 -1
  4. package/package.json +4 -4
  5. package/dist/configs/service.config.d.ts +0 -5
  6. package/dist/configs/service.config.d.ts.map +0 -1
  7. package/dist/configs/service.config.js +0 -5
  8. package/dist/configs/service.config.js.map +0 -1
  9. package/dist/constants/table.d.ts +0 -3
  10. package/dist/constants/table.d.ts.map +0 -1
  11. package/dist/constants/table.js +0 -3
  12. package/dist/constants/table.js.map +0 -1
  13. package/dist/controllers/entity/create-entity.controller.d.ts +0 -7
  14. package/dist/controllers/entity/create-entity.controller.d.ts.map +0 -1
  15. package/dist/controllers/entity/create-entity.controller.js +0 -64
  16. package/dist/controllers/entity/create-entity.controller.js.map +0 -1
  17. package/dist/controllers/entity/delete-entity.controller.d.ts +0 -7
  18. package/dist/controllers/entity/delete-entity.controller.d.ts.map +0 -1
  19. package/dist/controllers/entity/delete-entity.controller.js +0 -38
  20. package/dist/controllers/entity/delete-entity.controller.js.map +0 -1
  21. package/dist/controllers/entity/get-entity-by-unique-field-value.controller.d.ts +0 -7
  22. package/dist/controllers/entity/get-entity-by-unique-field-value.controller.d.ts.map +0 -1
  23. package/dist/controllers/entity/get-entity-by-unique-field-value.controller.js +0 -36
  24. package/dist/controllers/entity/get-entity-by-unique-field-value.controller.js.map +0 -1
  25. package/dist/controllers/entity/get-entity.controller.d.ts +0 -7
  26. package/dist/controllers/entity/get-entity.controller.d.ts.map +0 -1
  27. package/dist/controllers/entity/get-entity.controller.js +0 -37
  28. package/dist/controllers/entity/get-entity.controller.js.map +0 -1
  29. package/dist/controllers/entity/list-entities.controller.d.ts +0 -7
  30. package/dist/controllers/entity/list-entities.controller.d.ts.map +0 -1
  31. package/dist/controllers/entity/list-entities.controller.js +0 -61
  32. package/dist/controllers/entity/list-entities.controller.js.map +0 -1
  33. package/dist/controllers/entity/update-entity.controller.d.ts +0 -7
  34. package/dist/controllers/entity/update-entity.controller.d.ts.map +0 -1
  35. package/dist/controllers/entity/update-entity.controller.js +0 -62
  36. package/dist/controllers/entity/update-entity.controller.js.map +0 -1
  37. package/dist/controllers/entity/upsert-entity.controller.d.ts +0 -11
  38. package/dist/controllers/entity/upsert-entity.controller.d.ts.map +0 -1
  39. package/dist/controllers/entity/upsert-entity.controller.js +0 -84
  40. package/dist/controllers/entity/upsert-entity.controller.js.map +0 -1
  41. package/dist/controllers/mutual/create-mutual.controller.d.ts +0 -7
  42. package/dist/controllers/mutual/create-mutual.controller.d.ts.map +0 -1
  43. package/dist/controllers/mutual/create-mutual.controller.js +0 -60
  44. package/dist/controllers/mutual/create-mutual.controller.js.map +0 -1
  45. package/dist/controllers/mutual/delete-mutual.controller.d.ts +0 -7
  46. package/dist/controllers/mutual/delete-mutual.controller.d.ts.map +0 -1
  47. package/dist/controllers/mutual/delete-mutual.controller.js +0 -40
  48. package/dist/controllers/mutual/delete-mutual.controller.js.map +0 -1
  49. package/dist/controllers/mutual/get-mutual.controller.d.ts +0 -7
  50. package/dist/controllers/mutual/get-mutual.controller.d.ts.map +0 -1
  51. package/dist/controllers/mutual/get-mutual.controller.js +0 -36
  52. package/dist/controllers/mutual/get-mutual.controller.js.map +0 -1
  53. package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts +0 -7
  54. package/dist/controllers/mutual/list-entities-by-entity.controller.d.ts.map +0 -1
  55. package/dist/controllers/mutual/list-entities-by-entity.controller.js +0 -72
  56. package/dist/controllers/mutual/list-entities-by-entity.controller.js.map +0 -1
  57. package/dist/controllers/mutual/update-mutual.controller.d.ts +0 -7
  58. package/dist/controllers/mutual/update-mutual.controller.d.ts.map +0 -1
  59. package/dist/controllers/mutual/update-mutual.controller.js +0 -54
  60. package/dist/controllers/mutual/update-mutual.controller.js.map +0 -1
  61. package/dist/controllers/setupRoutes.d.ts +0 -4
  62. package/dist/controllers/setupRoutes.d.ts.map +0 -1
  63. package/dist/controllers/setupRoutes.js +0 -32
  64. package/dist/controllers/setupRoutes.js.map +0 -1
  65. package/dist/controllers/tag/list-tags.controller.d.ts +0 -7
  66. package/dist/controllers/tag/list-tags.controller.d.ts.map +0 -1
  67. package/dist/controllers/tag/list-tags.controller.js +0 -57
  68. package/dist/controllers/tag/list-tags.controller.js.map +0 -1
  69. package/dist/data/DbUtils.d.ts +0 -7
  70. package/dist/data/DbUtils.d.ts.map +0 -1
  71. package/dist/data/DbUtils.js +0 -34
  72. package/dist/data/DbUtils.js.map +0 -1
  73. package/dist/data/Entity.d.ts +0 -77
  74. package/dist/data/Entity.d.ts.map +0 -1
  75. package/dist/data/Entity.js +0 -504
  76. package/dist/data/Entity.js.map +0 -1
  77. package/dist/data/EventUtils.d.ts +0 -15
  78. package/dist/data/EventUtils.d.ts.map +0 -1
  79. package/dist/data/EventUtils.js +0 -43
  80. package/dist/data/EventUtils.js.map +0 -1
  81. package/dist/data/FileObject.d.ts +0 -62
  82. package/dist/data/FileObject.d.ts.map +0 -1
  83. package/dist/data/FileObject.js +0 -13
  84. package/dist/data/FileObject.js.map +0 -1
  85. package/dist/data/Mutual.d.ts +0 -93
  86. package/dist/data/Mutual.d.ts.map +0 -1
  87. package/dist/data/Mutual.js +0 -440
  88. package/dist/data/Mutual.js.map +0 -1
  89. package/dist/data/ProjectionExpression.d.ts +0 -6
  90. package/dist/data/ProjectionExpression.d.ts.map +0 -1
  91. package/dist/data/ProjectionExpression.js +0 -5
  92. package/dist/data/ProjectionExpression.js.map +0 -1
  93. package/dist/data/Tag.d.ts +0 -77
  94. package/dist/data/Tag.d.ts.map +0 -1
  95. package/dist/data/Tag.js +0 -329
  96. package/dist/data/Tag.js.map +0 -1
  97. package/dist/data/abstract/Item.base.d.ts +0 -11
  98. package/dist/data/abstract/Item.base.d.ts.map +0 -1
  99. package/dist/data/abstract/Item.base.js +0 -9
  100. package/dist/data/abstract/Item.base.js.map +0 -1
  101. package/dist/data/abstract/Repository.base.d.ts +0 -11
  102. package/dist/data/abstract/Repository.base.d.ts.map +0 -1
  103. package/dist/data/abstract/Repository.base.js +0 -51
  104. package/dist/data/abstract/Repository.base.js.map +0 -1
  105. package/dist/errors/api-error.d.ts +0 -23
  106. package/dist/errors/api-error.d.ts.map +0 -1
  107. package/dist/errors/api-error.js +0 -26
  108. package/dist/errors/api-error.js.map +0 -1
  109. package/dist/errors/extendable-error.d.ts +0 -18
  110. package/dist/errors/extendable-error.d.ts.map +0 -1
  111. package/dist/errors/extendable-error.js +0 -15
  112. package/dist/errors/extendable-error.js.map +0 -1
  113. package/dist/errors/standard-error.d.ts +0 -33
  114. package/dist/errors/standard-error.d.ts.map +0 -1
  115. package/dist/errors/standard-error.js +0 -39
  116. package/dist/errors/standard-error.js.map +0 -1
  117. package/dist/handles/app.d.ts +0 -16
  118. package/dist/handles/app.d.ts.map +0 -1
  119. package/dist/handles/app.js +0 -31
  120. package/dist/handles/app.js.map +0 -1
  121. package/dist/helpers/dependencies.d.ts +0 -8
  122. package/dist/helpers/dependencies.d.ts.map +0 -1
  123. package/dist/helpers/dependencies.js +0 -10
  124. package/dist/helpers/dependencies.js.map +0 -1
  125. package/dist/helpers/event.d.ts +0 -22
  126. package/dist/helpers/event.d.ts.map +0 -1
  127. package/dist/helpers/event.js +0 -48
  128. package/dist/helpers/event.js.map +0 -1
  129. package/dist/helpers/fromLastKeyQuery.d.ts +0 -3
  130. package/dist/helpers/fromLastKeyQuery.d.ts.map +0 -1
  131. package/dist/helpers/fromLastKeyQuery.js +0 -7
  132. package/dist/helpers/fromLastKeyQuery.js.map +0 -1
  133. package/dist/helpers/sleep.d.ts +0 -2
  134. package/dist/helpers/sleep.d.ts.map +0 -1
  135. package/dist/helpers/sleep.js +0 -2
  136. package/dist/helpers/sleep.js.map +0 -1
  137. package/dist/helpers/toLastKeyResponse.d.ts +0 -3
  138. package/dist/helpers/toLastKeyResponse.d.ts.map +0 -1
  139. package/dist/helpers/toLastKeyResponse.js +0 -7
  140. package/dist/helpers/toLastKeyResponse.js.map +0 -1
  141. package/dist/index.d.ts.map +0 -1
  142. package/dist/middlewares/api-key-auth.d.ts +0 -3
  143. package/dist/middlewares/api-key-auth.d.ts.map +0 -1
  144. package/dist/middlewares/api-key-auth.js +0 -32
  145. package/dist/middlewares/api-key-auth.js.map +0 -1
  146. package/dist/middlewares/entity-type-check.d.ts +0 -3
  147. package/dist/middlewares/entity-type-check.d.ts.map +0 -1
  148. package/dist/middlewares/entity-type-check.js +0 -22
  149. package/dist/middlewares/entity-type-check.js.map +0 -1
  150. package/dist/middlewares/general-error-handler.d.ts +0 -7
  151. package/dist/middlewares/general-error-handler.d.ts.map +0 -1
  152. package/dist/middlewares/general-error-handler.js +0 -40
  153. package/dist/middlewares/general-error-handler.js.map +0 -1
  154. package/dist/middlewares/mutual-type-check.d.ts +0 -3
  155. package/dist/middlewares/mutual-type-check.d.ts.map +0 -1
  156. package/dist/middlewares/mutual-type-check.js +0 -23
  157. package/dist/middlewares/mutual-type-check.js.map +0 -1
  158. package/dist/processors/create-entity-processor.d.ts +0 -6
  159. package/dist/processors/create-entity-processor.d.ts.map +0 -1
  160. package/dist/processors/create-entity-processor.js +0 -44
  161. package/dist/processors/create-entity-processor.js.map +0 -1
  162. package/dist/processors/mutual-processor.d.ts +0 -16
  163. package/dist/processors/mutual-processor.d.ts.map +0 -1
  164. package/dist/processors/mutual-processor.js +0 -142
  165. package/dist/processors/mutual-processor.js.map +0 -1
  166. package/dist/processors/prejoin-processor.d.ts +0 -13
  167. package/dist/processors/prejoin-processor.d.ts.map +0 -1
  168. package/dist/processors/prejoin-processor.js +0 -161
  169. package/dist/processors/prejoin-processor.js.map +0 -1
  170. package/dist/processors/replication-processor.d.ts +0 -9
  171. package/dist/processors/replication-processor.d.ts.map +0 -1
  172. package/dist/processors/replication-processor.js +0 -180
  173. package/dist/processors/replication-processor.js.map +0 -1
  174. package/dist/processors/tag-processor.d.ts +0 -12
  175. package/dist/processors/tag-processor.d.ts.map +0 -1
  176. package/dist/processors/tag-processor.js +0 -118
  177. package/dist/processors/tag-processor.js.map +0 -1
  178. package/dist/services/DependencyContainer.d.ts +0 -67
  179. package/dist/services/DependencyContainer.d.ts.map +0 -1
  180. package/dist/services/DependencyContainer.js +0 -121
  181. package/dist/services/DependencyContainer.js.map +0 -1
  182. package/dist/services/entity-service-lifecycle.d.ts +0 -12
  183. package/dist/services/entity-service-lifecycle.d.ts.map +0 -1
  184. package/dist/services/entity-service-lifecycle.js +0 -41
  185. package/dist/services/entity-service-lifecycle.js.map +0 -1
  186. package/dist/services/entity.service.d.ts +0 -34
  187. package/dist/services/entity.service.d.ts.map +0 -1
  188. package/dist/services/entity.service.js +0 -120
  189. package/dist/services/entity.service.js.map +0 -1
  190. package/dist/services/mutual.service.d.ts +0 -64
  191. package/dist/services/mutual.service.d.ts.map +0 -1
  192. package/dist/services/mutual.service.js +0 -141
  193. package/dist/services/mutual.service.js.map +0 -1
  194. package/dist/tsconfig.tsbuildinfo +0 -1
  195. package/dist/types/entity.type.d.ts +0 -20
  196. package/dist/types/entity.type.d.ts.map +0 -1
  197. package/dist/types/entity.type.js +0 -2
  198. package/dist/types/entity.type.js.map +0 -1
  199. package/dist/types/event.d.ts +0 -73
  200. package/dist/types/event.d.ts.map +0 -1
  201. package/dist/types/event.js +0 -74
  202. package/dist/types/event.js.map +0 -1
  203. package/dist/vitest.config.d.ts +0 -3
  204. package/dist/vitest.config.d.ts.map +0 -1
  205. package/dist/vitest.config.js +0 -10
  206. package/dist/vitest.config.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,35 +1,4767 @@
1
- import type { Entity as EntityType, createEntityConfig } from '@monorise/base';
2
- import { setupCommonRoutes } from './controllers/setupRoutes';
3
- import { Entity, EntityRepository } from './data/Entity';
4
- import { Mutual, MutualRepository } from './data/Mutual';
5
- import { PROJECTION_EXPRESSION } from './data/ProjectionExpression';
6
- import { TagRepository } from './data/Tag';
7
- import { StandardError, StandardErrorCode } from './errors/standard-error';
8
- import { appHandler } from './handles/app';
9
- import { handler as createEntityProcessor } from './processors/create-entity-processor';
10
- import { handler as mutualProcessor } from './processors/mutual-processor';
11
- import { handler as prejoinProcessor } from './processors/prejoin-processor';
12
- import { handler as replicationProcessor } from './processors/replication-processor';
13
- import { handler as tagProcessor } from './processors/tag-processor';
14
- import { DependencyContainer } from './services/DependencyContainer';
15
- import { EntityService } from './services/entity.service';
16
- import { MutualService } from './services/mutual.service';
1
+ import { Entity as Entity$2, EntitySchemaMap, createEntityConfig } from '@monorise/base';
2
+ import * as hono from 'hono';
3
+ import { Hono } from 'hono';
4
+ import { DynamoDB, TransactWriteItemsInput, AttributeValue, TransactWriteItem, UpdateItemCommandInput } from '@aws-sdk/client-dynamodb';
5
+ import * as hono_utils_http_status from 'hono/utils/http-status';
6
+ import * as hono_utils_types from 'hono/utils/types';
7
+ import { createFactory } from 'hono/factory';
8
+ import httpStatus4 from 'http-status';
9
+ import { unmarshall, marshall } from '@aws-sdk/util-dynamodb';
10
+ import { EventBridgeClient } from '@aws-sdk/client-eventbridge';
11
+ import * as hono_aws_lambda from 'hono/aws-lambda';
12
+ import { SQSEvent, SQSBatchItemFailure, DynamoDBBatchItemFailure } from 'aws-lambda';
13
+ import { _Record } from '@aws-sdk/client-dynamodb-streams';
14
+
15
+ type EventDetail = {
16
+ Source: string;
17
+ DetailType: string;
18
+ };
19
+
20
+ type PublishEventProps$1<T> = {
21
+ payload: T;
22
+ event: EventDetail;
23
+ };
24
+ declare function publishEvent<T extends Record<string, any>>({ payload, event, }: PublishEventProps$1<T>): Promise<void>;
25
+
26
+ declare class DbUtils {
27
+ private ddbClient;
28
+ constructor(ddbClient: DynamoDB);
29
+ executeTransactWrite(params: TransactWriteItemsInput): Promise<void>;
30
+ }
31
+
32
+ type ProjectionExpressionValues = (typeof PROJECTION_EXPRESSION)[keyof typeof PROJECTION_EXPRESSION];
33
+ declare const PROJECTION_EXPRESSION: {
34
+ readonly NO_DATA: "byEntityType, byEntityId, entityType, entityId, mutualId";
35
+ readonly MUTUAL_DATA_ONLY: "byEntityType, byEntityId, entityType, entityId, mutualId, mutualData";
36
+ };
37
+
38
+ declare abstract class Item$1 {
39
+ abstract get pk(): string;
40
+ abstract get sk(): string;
41
+ abstract get createdAt(): string | undefined;
42
+ abstract get updatedAt(): string | undefined;
43
+ keys(): Record<string, AttributeValue>;
44
+ abstract toItem(): Record<string, AttributeValue>;
45
+ abstract toJSON(): Record<string, unknown>;
46
+ }
47
+
48
+ declare abstract class Repository {
49
+ toUpdate(parsedUpdateData: Record<string, unknown>, opts?: {
50
+ maxLevel?: number;
51
+ }): {
52
+ UpdateExpression: string;
53
+ ExpressionAttributeNames: Record<string, string>;
54
+ ExpressionAttributeValues: Record<string, AttributeValue>;
55
+ };
56
+ }
57
+
58
+ declare class Entity$1<T extends Entity$2> extends Item$1 {
59
+ entityType: T;
60
+ entityId?: string | undefined;
61
+ data: Partial<EntitySchemaMap[T]>;
62
+ private _createdAt?;
63
+ private _updatedAt?;
64
+ fullId: string;
65
+ constructor(entityType: T, entityId?: string | undefined, data?: Partial<EntitySchemaMap[T]>, _createdAt?: Date | undefined, _updatedAt?: Date | undefined);
66
+ static fromItem<T extends Entity$2>(item?: Record<string, AttributeValue>): Entity$1<T>;
67
+ get pk(): string;
68
+ get sk(): string;
69
+ get listActionKey(): string;
70
+ get emailKeys(): Record<string, AttributeValue>;
71
+ get createdAt(): string | undefined;
72
+ get updatedAt(): string | undefined;
73
+ toItem(): Record<string, AttributeValue>;
74
+ toJSON(): Record<string, unknown>;
75
+ }
76
+ declare class EntityRepository extends Repository {
77
+ private EntityConfig;
78
+ private readonly TABLE_NAME;
79
+ private readonly dynamodbClient;
80
+ private readonly EmailAuthEnabledEntities;
81
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, TABLE_NAME: string, dynamodbClient: DynamoDB, EmailAuthEnabledEntities: Entity$2[]);
82
+ listEntities<T extends Entity$2>({ entityType, limit, // if this is not set, it will return all items
83
+ between, options, }: {
84
+ entityType: T;
85
+ limit?: number;
86
+ between?: {
87
+ start: string;
88
+ end: string;
89
+ };
90
+ options?: {
91
+ lastKey?: string;
92
+ ProjectionExpression?: ProjectionExpressionValues | (string & {});
93
+ };
94
+ }): Promise<{
95
+ items: Entity$1<T>[];
96
+ totalCount?: number;
97
+ lastKey?: string;
98
+ }>;
99
+ getEntity<T extends Entity$2>(entityType: T, entityId: string): Promise<Entity$1<T>>;
100
+ getEntityByEmail<T extends Entity$2>(entityType: T, email: string): Promise<Entity$1<T>>;
101
+ getEmailAvailability<T extends Entity$2>(entityType: T, email: string): Promise<void>;
102
+ getEntityByUniqueField<T extends Entity$2>(entityType: T, fieldName: string, value: string): Promise<Entity$1<T>>;
103
+ getUniqueFieldValueAvailability<T extends Entity$2>(entityType: T, fieldName: string, value: string): Promise<void>;
104
+ createEntityTransactItems<T extends Entity$2>(entity: Entity$1<T>, opts: {
105
+ mutualId?: string;
106
+ uniqueFieldValues?: Record<string, string>;
107
+ }): TransactWriteItem[];
108
+ createEntity<T extends Entity$2>(entityType: T, entityPayload: EntitySchemaMap[T], entityId?: string, opts?: {
109
+ createAndUpdateDatetime?: Date;
110
+ mutualId?: string;
111
+ }): Promise<Entity$1<T>>;
112
+ upsertEntity<T extends Entity$2>(entityType: T, entityId: string, payload: Partial<EntitySchemaMap[T]>): Promise<Entity$1<T>>;
113
+ updateEntityTransactItems<T extends Entity$2>(entity: Entity$1<T>, updateParams: UpdateItemCommandInput, previousUniqueFieldValues: Record<string, string>, previousEntity: Entity$1<T>): TransactWriteItem[];
114
+ updateEntity<T extends Entity$2>(entityType: T, entityId: string, toUpdate: {
115
+ data: Partial<EntitySchemaMap[T]>;
116
+ updatedAt?: string;
117
+ }, opts?: {
118
+ ConditionExpression?: string;
119
+ ExpressionAttributeNames?: Record<string, string>;
120
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
121
+ }): Promise<Entity$1<T>>;
122
+ deleteEntity<T extends Entity$2>(entityType: T, entityId: string): Promise<void>;
123
+ queryEntities<T extends Entity$2>(entityType: T, query: string): Promise<{
124
+ items: Entity$1<T>[];
125
+ totalCount?: number;
126
+ filteredCount?: number;
127
+ }>;
128
+ }
129
+
130
+ type PublishEventProps<T extends Entity$2> = {
131
+ entity: Entity$1<T>;
132
+ mutualPayload: Record<string, any>;
133
+ };
134
+ declare class EventUtils {
135
+ EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
136
+ private publishEvent;
137
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, publishEvent: typeof publishEvent);
138
+ publishCreateMutualsEvent: <T extends Entity$2>({ entity, mutualPayload, }: PublishEventProps<T>) => Promise<void>;
139
+ }
140
+
141
+ declare class Mutual<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>> {
142
+ byEntityType: B;
143
+ byEntityId: string;
144
+ byData: Partial<EntitySchemaMap[B]> | Record<string, any>;
145
+ entityType: T;
146
+ entityId: string;
147
+ data: Partial<EntitySchemaMap[T]> | Record<string, any>;
148
+ mutualData: M;
149
+ mutualId?: string | undefined;
150
+ private _createdAt?;
151
+ private _updatedAt?;
152
+ private _mutualUpdatedAt?;
153
+ private _expiresAt?;
154
+ constructor(byEntityType: B, byEntityId: string, byData: Partial<EntitySchemaMap[B]> | Record<string, any>, entityType: T, entityId: string, data: Partial<EntitySchemaMap[T]> | Record<string, any>, mutualData: M, mutualId?: string | undefined, _createdAt?: Date | undefined, _updatedAt?: Date | undefined, _mutualUpdatedAt?: Date | undefined, _expiresAt?: Date | undefined);
155
+ static fromItem<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>(item?: Record<string, AttributeValue>): Mutual<B, T, M>;
156
+ mainKeys(): Record<string, AttributeValue>;
157
+ subKeys(): Record<string, AttributeValue>;
158
+ get byFullEntityId(): string;
159
+ get fullEntityId(): string;
160
+ get listEntitySK(): string;
161
+ get mainPk(): string;
162
+ get mainSk(): string;
163
+ get createdAt(): string | undefined;
164
+ get updatedAt(): string | undefined;
165
+ get mutualUpdatedAt(): string | undefined;
166
+ get expiresAt(): string | undefined;
167
+ toItem(): Record<string, AttributeValue>;
168
+ toReversedItem(): Record<string, AttributeValue>;
169
+ toJSON(): Record<string, unknown>;
170
+ }
171
+ declare class MutualRepository extends Repository {
172
+ private readonly TABLE_NAME;
173
+ private readonly dynamodbClient;
174
+ private readonly ddbUtils;
175
+ constructor(TABLE_NAME: string, dynamodbClient: DynamoDB, ddbUtils: DbUtils);
176
+ listEntitiesByEntity<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, opts?: {
177
+ lastKey?: string;
178
+ ProjectionExpression?: ProjectionExpressionValues | (string & {});
179
+ limit?: number;
180
+ }): Promise<{
181
+ items: Mutual<B, T, M>[];
182
+ lastKey?: string;
183
+ }>;
184
+ getMutual<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, entityId: string, opts?: {
185
+ isFromMetadata?: boolean;
186
+ ProjectionExpression?: string;
187
+ }): Promise<Mutual<B, T, M>>;
188
+ checkMutualExist<B extends Entity$2, T extends Entity$2>(byEntityType: B, byEntityId: string, entityType: T, entityId: string): Promise<void>;
189
+ createMutualTransactItems<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>(mutual: Mutual<B, T, M>, opts?: {
190
+ ConditionExpression?: string;
191
+ ExpressionAttributeNames?: Record<string, string>;
192
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
193
+ }): TransactWriteItem[];
194
+ createMutual<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, byData: EntitySchemaMap[B] | Record<string, any>, entityType: T, entityId: string, data: EntitySchemaMap[T] | Record<string, any>, mutualData?: M, opts?: {
195
+ ConditionExpression?: string;
196
+ ExpressionAttributeNames?: Record<string, string>;
197
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
198
+ createAndUpdateDatetime?: Date;
199
+ }): Promise<Mutual<B, T, M>>;
200
+ updateMutual<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, entityId: string, toUpdate: {
201
+ mutualData: Record<string, unknown>;
202
+ mutualUpdatedAt?: string;
203
+ updatedAt?: string;
204
+ }, opts?: {
205
+ ConditionExpression?: string;
206
+ ExpressionAttributeNames?: Record<string, string>;
207
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
208
+ returnUpdatedValue?: boolean;
209
+ maxObjectUpdateLevel?: number;
210
+ }): Promise<Mutual<B, T, M> | undefined>;
211
+ deleteMutual<B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>(byEntityType: B, byEntityId: string, entityType: T, entityId: string, opts?: {
212
+ ConditionExpression?: string;
213
+ ExpressionAttributeNames?: Record<string, string>;
214
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
215
+ }): Promise<Mutual<B, T, M>>;
216
+ createMutualLock<B extends Entity$2, T extends Entity$2>({ byEntityType, byEntityId, entityType, version, }: {
217
+ byEntityType: B;
218
+ byEntityId: string;
219
+ entityType: T;
220
+ version: string;
221
+ }): Promise<void>;
222
+ deleteMutualLock<B extends Entity$2, T extends Entity$2>({ byEntityType, byEntityId, entityType, }: {
223
+ byEntityType: B;
224
+ byEntityId: string;
225
+ entityType: T;
226
+ }): Promise<void>;
227
+ }
228
+
229
+ declare class TaggedEntity<T extends Entity$2> extends Entity$1<T> {
230
+ tagName: string;
231
+ group?: string;
232
+ sortValue?: string;
233
+ constructor({ tagName, group, sortValue, entityType, entityId, data, createdAt, updatedAt, }: {
234
+ tagName: string;
235
+ group?: string;
236
+ sortValue?: string;
237
+ entityType: T;
238
+ entityId: string;
239
+ data?: Partial<EntitySchemaMap[T]>;
240
+ createdAt?: Date;
241
+ updatedAt?: Date;
242
+ });
243
+ static fromItem<T extends Entity$2>(item?: Record<string, AttributeValue>): TaggedEntity<T>;
244
+ get pk(): string;
245
+ get sk(): string;
246
+ reversedKeys(): Record<string, AttributeValue>;
247
+ replicationKeys(): Record<string, AttributeValue>;
248
+ toItem(): Record<string, AttributeValue>;
249
+ toJSON(): Record<string, unknown>;
250
+ }
251
+ declare class TagRepository extends Repository {
252
+ private readonly TABLE_NAME;
253
+ private readonly dynamodbClient;
254
+ constructor(TABLE_NAME: string, dynamodbClient: DynamoDB);
255
+ getExistingTags<T extends Entity$2>({ entityType, entityId, tagName, }: {
256
+ entityType: T;
257
+ entityId: string;
258
+ tagName: string;
259
+ }): Promise<TaggedEntity<T>[]>;
260
+ deleteTag({ tagName, group, sortValue, entityType, entityId, }: {
261
+ tagName: string;
262
+ group?: string;
263
+ sortValue?: string;
264
+ entityType: Entity$2;
265
+ entityId: string;
266
+ }): Promise<void>;
267
+ createTag<T extends Entity$2>({ tagName, group, sortValue, entity, }: {
268
+ tagName: string;
269
+ group?: string;
270
+ sortValue?: string;
271
+ entity: Entity$1<T>;
272
+ }): Promise<TaggedEntity<T>>;
273
+ listTags<T extends Entity$2>({ entityType, tagName, limit, // if this is not set, it will return all items
274
+ query, group, start, end, options, }: {
275
+ entityType: T;
276
+ tagName: string;
277
+ limit?: number;
278
+ start?: string;
279
+ end?: string;
280
+ query?: string;
281
+ group?: string;
282
+ options?: {
283
+ lastKey?: string;
284
+ ProjectionExpression?: ProjectionExpressionValues;
285
+ };
286
+ }): Promise<{
287
+ items: Entity$1<T>[];
288
+ totalCount?: number;
289
+ lastKey?: string;
290
+ }>;
291
+ createLock({ entityType, entityId, }: {
292
+ entityType: Entity$2;
293
+ entityId: string;
294
+ }): Promise<void>;
295
+ deleteLock({ entityType, entityId, }: {
296
+ entityType: Entity$2;
297
+ entityId: string;
298
+ }): Promise<void>;
299
+ }
300
+
301
+ var __defProp = Object.defineProperty;
302
+ var __defProps = Object.defineProperties;
303
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
304
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
305
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
306
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
307
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
308
+ var __spreadValues = (a, b) => {
309
+ for (var prop in b || (b = {}))
310
+ if (__hasOwnProp.call(b, prop))
311
+ __defNormalProp(a, prop, b[prop]);
312
+ if (__getOwnPropSymbols)
313
+ for (var prop of __getOwnPropSymbols(b)) {
314
+ if (__propIsEnum.call(b, prop))
315
+ __defNormalProp(a, prop, b[prop]);
316
+ }
317
+ return a;
318
+ };
319
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
320
+ var __export = (target, all) => {
321
+ for (var name in all)
322
+ __defProp(target, name, { get: all[name], enumerable: true });
323
+ };
324
+ var __async = (__this, __arguments, generator) => {
325
+ return new Promise((resolve, reject) => {
326
+ var fulfilled = (value) => {
327
+ try {
328
+ step(generator.next(value));
329
+ } catch (e) {
330
+ reject(e);
331
+ }
332
+ };
333
+ var rejected = (value) => {
334
+ try {
335
+ step(generator.throw(value));
336
+ } catch (e) {
337
+ reject(e);
338
+ }
339
+ };
340
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
341
+ step((generator = generator.apply(__this, __arguments)).next());
342
+ });
343
+ };
344
+
345
+ // errors/standard-error.ts
346
+ var StandardError$1 = class StandardError extends Error {
347
+ constructor(errorCode, message, lastError, context) {
348
+ super(message);
349
+ Object.setPrototypeOf(this, new.target.prototype);
350
+ this.name = this.constructor.name;
351
+ this.code = errorCode;
352
+ this.lastError = lastError;
353
+ this.context = JSON.stringify(context, null, 2);
354
+ }
355
+ toJSON() {
356
+ return {
357
+ code: this.code,
358
+ message: this.message
359
+ };
360
+ }
361
+ };
362
+ var StandardErrorCode$1 = {
363
+ ENTITY_IS_UNDEFINED: "ENTITY_IS_UNDEFINED"};
364
+
365
+ // data/abstract/Item.base.ts
366
+ var Item = class {
367
+ keys() {
368
+ return {
369
+ PK: { S: this.pk },
370
+ SK: { S: this.sk }
371
+ };
372
+ }
373
+ };
374
+
375
+ // data/Entity.ts
376
+ var Entity = class _Entity extends Item {
377
+ constructor(entityType, entityId, data = {}, _createdAt, _updatedAt) {
378
+ super();
379
+ this.entityType = entityType;
380
+ this.entityId = entityId;
381
+ this.data = data;
382
+ this._createdAt = _createdAt;
383
+ this._updatedAt = _updatedAt;
384
+ this.fullId = this.pk;
385
+ }
386
+ static fromItem(item) {
387
+ if (!item)
388
+ throw new StandardError$1(
389
+ StandardErrorCode$1.ENTITY_IS_UNDEFINED,
390
+ "Entity item empty"
391
+ );
392
+ const parsedItem = unmarshall(item);
393
+ return new _Entity(
394
+ parsedItem.entityType,
395
+ parsedItem.entityId,
396
+ parsedItem.data,
397
+ parsedItem.createdAt ? new Date(parsedItem.createdAt) : void 0,
398
+ parsedItem.updatedAt ? new Date(parsedItem.updatedAt) : void 0
399
+ );
400
+ }
401
+ get pk() {
402
+ return `${this.entityType}#${this.entityId}`;
403
+ }
404
+ get sk() {
405
+ return "#METADATA#";
406
+ }
407
+ get listActionKey() {
408
+ return `LIST#${this.entityType}`;
409
+ }
410
+ get emailKeys() {
411
+ return {
412
+ PK: {
413
+ S: `EMAIL#${this.data.email}`
414
+ },
415
+ SK: {
416
+ S: `${this.entityType}#${this.entityId}`
417
+ }
418
+ };
419
+ }
420
+ get createdAt() {
421
+ var _a;
422
+ return (_a = this._createdAt) == null ? void 0 : _a.toISOString();
423
+ }
424
+ get updatedAt() {
425
+ var _a;
426
+ return (_a = this._updatedAt) == null ? void 0 : _a.toISOString();
427
+ }
428
+ toItem() {
429
+ return __spreadValues(__spreadValues({}, marshall(this.toJSON(), { removeUndefinedValues: true })), this.keys());
430
+ }
431
+ toJSON() {
432
+ return {
433
+ entityType: this.entityType,
434
+ entityId: this.entityId,
435
+ data: this.data,
436
+ createdAt: this.createdAt,
437
+ updatedAt: this.updatedAt
438
+ };
439
+ }
440
+ };
441
+ var factory = createFactory();
442
+ var API_KEYS = process.env.API_KEYS ? JSON.parse(process.env.API_KEYS) : [];
443
+ factory.createMiddleware((c, next) => __async(null, null, function* () {
444
+ const xApiKey = c.req.header("x-api-key");
445
+ if (c.req.url.match(/^\/core\/public\//)) {
446
+ return yield next();
447
+ }
448
+ if (!xApiKey || Array.isArray(xApiKey) || !API_KEYS.includes(xApiKey)) {
449
+ c.status(httpStatus4.UNAUTHORIZED);
450
+ return c.json({
451
+ status: httpStatus4.UNAUTHORIZED,
452
+ message: httpStatus4["401_MESSAGE"]
453
+ });
454
+ }
455
+ return yield next();
456
+ }));
457
+
458
+ // configs/service.config.ts
459
+ process.env.CORE_TABLE || "";
460
+ process.env.CORE_EVENT_BUS || "";
461
+
462
+ // helpers/event.ts
463
+ new EventBridgeClient();
464
+
465
+ // middlewares/general-error-handler.ts
466
+ createFactory();
467
+
468
+ // ../../node_modules/zod/dist/esm/v3/external.js
469
+ var external_exports = {};
470
+ __export(external_exports, {
471
+ BRAND: () => BRAND,
472
+ DIRTY: () => DIRTY,
473
+ EMPTY_PATH: () => EMPTY_PATH,
474
+ INVALID: () => INVALID,
475
+ NEVER: () => NEVER,
476
+ OK: () => OK,
477
+ ParseStatus: () => ParseStatus,
478
+ Schema: () => ZodType,
479
+ ZodAny: () => ZodAny,
480
+ ZodArray: () => ZodArray,
481
+ ZodBigInt: () => ZodBigInt,
482
+ ZodBoolean: () => ZodBoolean,
483
+ ZodBranded: () => ZodBranded,
484
+ ZodCatch: () => ZodCatch,
485
+ ZodDate: () => ZodDate,
486
+ ZodDefault: () => ZodDefault,
487
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
488
+ ZodEffects: () => ZodEffects,
489
+ ZodEnum: () => ZodEnum,
490
+ ZodError: () => ZodError,
491
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
492
+ ZodFunction: () => ZodFunction,
493
+ ZodIntersection: () => ZodIntersection,
494
+ ZodIssueCode: () => ZodIssueCode,
495
+ ZodLazy: () => ZodLazy,
496
+ ZodLiteral: () => ZodLiteral,
497
+ ZodMap: () => ZodMap,
498
+ ZodNaN: () => ZodNaN,
499
+ ZodNativeEnum: () => ZodNativeEnum,
500
+ ZodNever: () => ZodNever,
501
+ ZodNull: () => ZodNull,
502
+ ZodNullable: () => ZodNullable,
503
+ ZodNumber: () => ZodNumber,
504
+ ZodObject: () => ZodObject,
505
+ ZodOptional: () => ZodOptional,
506
+ ZodParsedType: () => ZodParsedType,
507
+ ZodPipeline: () => ZodPipeline,
508
+ ZodPromise: () => ZodPromise,
509
+ ZodReadonly: () => ZodReadonly,
510
+ ZodRecord: () => ZodRecord,
511
+ ZodSchema: () => ZodType,
512
+ ZodSet: () => ZodSet,
513
+ ZodString: () => ZodString,
514
+ ZodSymbol: () => ZodSymbol,
515
+ ZodTransformer: () => ZodEffects,
516
+ ZodTuple: () => ZodTuple,
517
+ ZodType: () => ZodType,
518
+ ZodUndefined: () => ZodUndefined,
519
+ ZodUnion: () => ZodUnion,
520
+ ZodUnknown: () => ZodUnknown,
521
+ ZodVoid: () => ZodVoid,
522
+ addIssueToContext: () => addIssueToContext,
523
+ any: () => anyType,
524
+ array: () => arrayType,
525
+ bigint: () => bigIntType,
526
+ boolean: () => booleanType,
527
+ coerce: () => coerce,
528
+ custom: () => custom,
529
+ date: () => dateType,
530
+ datetimeRegex: () => datetimeRegex,
531
+ defaultErrorMap: () => en_default,
532
+ discriminatedUnion: () => discriminatedUnionType,
533
+ effect: () => effectsType,
534
+ enum: () => enumType,
535
+ function: () => functionType,
536
+ getErrorMap: () => getErrorMap,
537
+ getParsedType: () => getParsedType,
538
+ instanceof: () => instanceOfType,
539
+ intersection: () => intersectionType,
540
+ isAborted: () => isAborted,
541
+ isAsync: () => isAsync,
542
+ isDirty: () => isDirty,
543
+ isValid: () => isValid,
544
+ late: () => late,
545
+ lazy: () => lazyType,
546
+ literal: () => literalType,
547
+ makeIssue: () => makeIssue,
548
+ map: () => mapType,
549
+ nan: () => nanType,
550
+ nativeEnum: () => nativeEnumType,
551
+ never: () => neverType,
552
+ null: () => nullType,
553
+ nullable: () => nullableType,
554
+ number: () => numberType,
555
+ object: () => objectType,
556
+ objectUtil: () => objectUtil,
557
+ oboolean: () => oboolean,
558
+ onumber: () => onumber,
559
+ optional: () => optionalType,
560
+ ostring: () => ostring,
561
+ pipeline: () => pipelineType,
562
+ preprocess: () => preprocessType,
563
+ promise: () => promiseType,
564
+ quotelessJson: () => quotelessJson,
565
+ record: () => recordType,
566
+ set: () => setType,
567
+ setErrorMap: () => setErrorMap,
568
+ strictObject: () => strictObjectType,
569
+ string: () => stringType,
570
+ symbol: () => symbolType,
571
+ transformer: () => effectsType,
572
+ tuple: () => tupleType,
573
+ undefined: () => undefinedType,
574
+ union: () => unionType,
575
+ unknown: () => unknownType,
576
+ util: () => util,
577
+ void: () => voidType
578
+ });
579
+
580
+ // ../../node_modules/zod/dist/esm/v3/helpers/util.js
581
+ var util;
582
+ (function(util2) {
583
+ util2.assertEqual = (_) => {
584
+ };
585
+ function assertIs(_arg) {
586
+ }
587
+ util2.assertIs = assertIs;
588
+ function assertNever(_x) {
589
+ throw new Error();
590
+ }
591
+ util2.assertNever = assertNever;
592
+ util2.arrayToEnum = (items) => {
593
+ const obj = {};
594
+ for (const item of items) {
595
+ obj[item] = item;
596
+ }
597
+ return obj;
598
+ };
599
+ util2.getValidEnumValues = (obj) => {
600
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
601
+ const filtered = {};
602
+ for (const k of validKeys) {
603
+ filtered[k] = obj[k];
604
+ }
605
+ return util2.objectValues(filtered);
606
+ };
607
+ util2.objectValues = (obj) => {
608
+ return util2.objectKeys(obj).map(function(e) {
609
+ return obj[e];
610
+ });
611
+ };
612
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
613
+ const keys = [];
614
+ for (const key in object) {
615
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
616
+ keys.push(key);
617
+ }
618
+ }
619
+ return keys;
620
+ };
621
+ util2.find = (arr, checker) => {
622
+ for (const item of arr) {
623
+ if (checker(item))
624
+ return item;
625
+ }
626
+ return void 0;
627
+ };
628
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
629
+ function joinValues(array, separator = " | ") {
630
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
631
+ }
632
+ util2.joinValues = joinValues;
633
+ util2.jsonStringifyReplacer = (_, value) => {
634
+ if (typeof value === "bigint") {
635
+ return value.toString();
636
+ }
637
+ return value;
638
+ };
639
+ })(util || (util = {}));
640
+ var objectUtil;
641
+ (function(objectUtil2) {
642
+ objectUtil2.mergeShapes = (first, second) => {
643
+ return __spreadValues(__spreadValues({}, first), second);
644
+ };
645
+ })(objectUtil || (objectUtil = {}));
646
+ var ZodParsedType = util.arrayToEnum([
647
+ "string",
648
+ "nan",
649
+ "number",
650
+ "integer",
651
+ "float",
652
+ "boolean",
653
+ "date",
654
+ "bigint",
655
+ "symbol",
656
+ "function",
657
+ "undefined",
658
+ "null",
659
+ "array",
660
+ "object",
661
+ "unknown",
662
+ "promise",
663
+ "void",
664
+ "never",
665
+ "map",
666
+ "set"
667
+ ]);
668
+ var getParsedType = (data) => {
669
+ const t = typeof data;
670
+ switch (t) {
671
+ case "undefined":
672
+ return ZodParsedType.undefined;
673
+ case "string":
674
+ return ZodParsedType.string;
675
+ case "number":
676
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
677
+ case "boolean":
678
+ return ZodParsedType.boolean;
679
+ case "function":
680
+ return ZodParsedType.function;
681
+ case "bigint":
682
+ return ZodParsedType.bigint;
683
+ case "symbol":
684
+ return ZodParsedType.symbol;
685
+ case "object":
686
+ if (Array.isArray(data)) {
687
+ return ZodParsedType.array;
688
+ }
689
+ if (data === null) {
690
+ return ZodParsedType.null;
691
+ }
692
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
693
+ return ZodParsedType.promise;
694
+ }
695
+ if (typeof Map !== "undefined" && data instanceof Map) {
696
+ return ZodParsedType.map;
697
+ }
698
+ if (typeof Set !== "undefined" && data instanceof Set) {
699
+ return ZodParsedType.set;
700
+ }
701
+ if (typeof Date !== "undefined" && data instanceof Date) {
702
+ return ZodParsedType.date;
703
+ }
704
+ return ZodParsedType.object;
705
+ default:
706
+ return ZodParsedType.unknown;
707
+ }
708
+ };
709
+
710
+ // ../../node_modules/zod/dist/esm/v3/ZodError.js
711
+ var ZodIssueCode = util.arrayToEnum([
712
+ "invalid_type",
713
+ "invalid_literal",
714
+ "custom",
715
+ "invalid_union",
716
+ "invalid_union_discriminator",
717
+ "invalid_enum_value",
718
+ "unrecognized_keys",
719
+ "invalid_arguments",
720
+ "invalid_return_type",
721
+ "invalid_date",
722
+ "invalid_string",
723
+ "too_small",
724
+ "too_big",
725
+ "invalid_intersection_types",
726
+ "not_multiple_of",
727
+ "not_finite"
728
+ ]);
729
+ var quotelessJson = (obj) => {
730
+ const json = JSON.stringify(obj, null, 2);
731
+ return json.replace(/"([^"]+)":/g, "$1:");
732
+ };
733
+ var ZodError = class _ZodError extends Error {
734
+ get errors() {
735
+ return this.issues;
736
+ }
737
+ constructor(issues) {
738
+ super();
739
+ this.issues = [];
740
+ this.addIssue = (sub) => {
741
+ this.issues = [...this.issues, sub];
742
+ };
743
+ this.addIssues = (subs = []) => {
744
+ this.issues = [...this.issues, ...subs];
745
+ };
746
+ const actualProto = new.target.prototype;
747
+ if (Object.setPrototypeOf) {
748
+ Object.setPrototypeOf(this, actualProto);
749
+ } else {
750
+ this.__proto__ = actualProto;
751
+ }
752
+ this.name = "ZodError";
753
+ this.issues = issues;
754
+ }
755
+ format(_mapper) {
756
+ const mapper = _mapper || function(issue) {
757
+ return issue.message;
758
+ };
759
+ const fieldErrors = { _errors: [] };
760
+ const processError = (error) => {
761
+ for (const issue of error.issues) {
762
+ if (issue.code === "invalid_union") {
763
+ issue.unionErrors.map(processError);
764
+ } else if (issue.code === "invalid_return_type") {
765
+ processError(issue.returnTypeError);
766
+ } else if (issue.code === "invalid_arguments") {
767
+ processError(issue.argumentsError);
768
+ } else if (issue.path.length === 0) {
769
+ fieldErrors._errors.push(mapper(issue));
770
+ } else {
771
+ let curr = fieldErrors;
772
+ let i = 0;
773
+ while (i < issue.path.length) {
774
+ const el = issue.path[i];
775
+ const terminal = i === issue.path.length - 1;
776
+ if (!terminal) {
777
+ curr[el] = curr[el] || { _errors: [] };
778
+ } else {
779
+ curr[el] = curr[el] || { _errors: [] };
780
+ curr[el]._errors.push(mapper(issue));
781
+ }
782
+ curr = curr[el];
783
+ i++;
784
+ }
785
+ }
786
+ }
787
+ };
788
+ processError(this);
789
+ return fieldErrors;
790
+ }
791
+ static assert(value) {
792
+ if (!(value instanceof _ZodError)) {
793
+ throw new Error(`Not a ZodError: ${value}`);
794
+ }
795
+ }
796
+ toString() {
797
+ return this.message;
798
+ }
799
+ get message() {
800
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
801
+ }
802
+ get isEmpty() {
803
+ return this.issues.length === 0;
804
+ }
805
+ flatten(mapper = (issue) => issue.message) {
806
+ const fieldErrors = {};
807
+ const formErrors = [];
808
+ for (const sub of this.issues) {
809
+ if (sub.path.length > 0) {
810
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
811
+ fieldErrors[sub.path[0]].push(mapper(sub));
812
+ } else {
813
+ formErrors.push(mapper(sub));
814
+ }
815
+ }
816
+ return { formErrors, fieldErrors };
817
+ }
818
+ get formErrors() {
819
+ return this.flatten();
820
+ }
821
+ };
822
+ ZodError.create = (issues) => {
823
+ const error = new ZodError(issues);
824
+ return error;
825
+ };
826
+
827
+ // ../../node_modules/zod/dist/esm/v3/locales/en.js
828
+ var errorMap = (issue, _ctx) => {
829
+ let message;
830
+ switch (issue.code) {
831
+ case ZodIssueCode.invalid_type:
832
+ if (issue.received === ZodParsedType.undefined) {
833
+ message = "Required";
834
+ } else {
835
+ message = `Expected ${issue.expected}, received ${issue.received}`;
836
+ }
837
+ break;
838
+ case ZodIssueCode.invalid_literal:
839
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
840
+ break;
841
+ case ZodIssueCode.unrecognized_keys:
842
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
843
+ break;
844
+ case ZodIssueCode.invalid_union:
845
+ message = `Invalid input`;
846
+ break;
847
+ case ZodIssueCode.invalid_union_discriminator:
848
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
849
+ break;
850
+ case ZodIssueCode.invalid_enum_value:
851
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
852
+ break;
853
+ case ZodIssueCode.invalid_arguments:
854
+ message = `Invalid function arguments`;
855
+ break;
856
+ case ZodIssueCode.invalid_return_type:
857
+ message = `Invalid function return type`;
858
+ break;
859
+ case ZodIssueCode.invalid_date:
860
+ message = `Invalid date`;
861
+ break;
862
+ case ZodIssueCode.invalid_string:
863
+ if (typeof issue.validation === "object") {
864
+ if ("includes" in issue.validation) {
865
+ message = `Invalid input: must include "${issue.validation.includes}"`;
866
+ if (typeof issue.validation.position === "number") {
867
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
868
+ }
869
+ } else if ("startsWith" in issue.validation) {
870
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
871
+ } else if ("endsWith" in issue.validation) {
872
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
873
+ } else {
874
+ util.assertNever(issue.validation);
875
+ }
876
+ } else if (issue.validation !== "regex") {
877
+ message = `Invalid ${issue.validation}`;
878
+ } else {
879
+ message = "Invalid";
880
+ }
881
+ break;
882
+ case ZodIssueCode.too_small:
883
+ if (issue.type === "array")
884
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
885
+ else if (issue.type === "string")
886
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
887
+ else if (issue.type === "number")
888
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
889
+ else if (issue.type === "date")
890
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
891
+ else
892
+ message = "Invalid input";
893
+ break;
894
+ case ZodIssueCode.too_big:
895
+ if (issue.type === "array")
896
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
897
+ else if (issue.type === "string")
898
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
899
+ else if (issue.type === "number")
900
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
901
+ else if (issue.type === "bigint")
902
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
903
+ else if (issue.type === "date")
904
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
905
+ else
906
+ message = "Invalid input";
907
+ break;
908
+ case ZodIssueCode.custom:
909
+ message = `Invalid input`;
910
+ break;
911
+ case ZodIssueCode.invalid_intersection_types:
912
+ message = `Intersection results could not be merged`;
913
+ break;
914
+ case ZodIssueCode.not_multiple_of:
915
+ message = `Number must be a multiple of ${issue.multipleOf}`;
916
+ break;
917
+ case ZodIssueCode.not_finite:
918
+ message = "Number must be finite";
919
+ break;
920
+ default:
921
+ message = _ctx.defaultError;
922
+ util.assertNever(issue);
923
+ }
924
+ return { message };
925
+ };
926
+ var en_default = errorMap;
927
+
928
+ // ../../node_modules/zod/dist/esm/v3/errors.js
929
+ var overrideErrorMap = en_default;
930
+ function setErrorMap(map) {
931
+ overrideErrorMap = map;
932
+ }
933
+ function getErrorMap() {
934
+ return overrideErrorMap;
935
+ }
936
+
937
+ // ../../node_modules/zod/dist/esm/v3/helpers/parseUtil.js
938
+ var makeIssue = (params) => {
939
+ const { data, path, errorMaps, issueData } = params;
940
+ const fullPath = [...path, ...issueData.path || []];
941
+ const fullIssue = __spreadProps(__spreadValues({}, issueData), {
942
+ path: fullPath
943
+ });
944
+ if (issueData.message !== void 0) {
945
+ return __spreadProps(__spreadValues({}, issueData), {
946
+ path: fullPath,
947
+ message: issueData.message
948
+ });
949
+ }
950
+ let errorMessage = "";
951
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
952
+ for (const map of maps) {
953
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
954
+ }
955
+ return __spreadProps(__spreadValues({}, issueData), {
956
+ path: fullPath,
957
+ message: errorMessage
958
+ });
959
+ };
960
+ var EMPTY_PATH = [];
961
+ function addIssueToContext(ctx, issueData) {
962
+ const overrideMap = getErrorMap();
963
+ const issue = makeIssue({
964
+ issueData,
965
+ data: ctx.data,
966
+ path: ctx.path,
967
+ errorMaps: [
968
+ ctx.common.contextualErrorMap,
969
+ // contextual error map is first priority
970
+ ctx.schemaErrorMap,
971
+ // then schema-bound map if available
972
+ overrideMap,
973
+ // then global override map
974
+ overrideMap === en_default ? void 0 : en_default
975
+ // then global default map
976
+ ].filter((x) => !!x)
977
+ });
978
+ ctx.common.issues.push(issue);
979
+ }
980
+ var ParseStatus = class _ParseStatus {
981
+ constructor() {
982
+ this.value = "valid";
983
+ }
984
+ dirty() {
985
+ if (this.value === "valid")
986
+ this.value = "dirty";
987
+ }
988
+ abort() {
989
+ if (this.value !== "aborted")
990
+ this.value = "aborted";
991
+ }
992
+ static mergeArray(status, results) {
993
+ const arrayValue = [];
994
+ for (const s of results) {
995
+ if (s.status === "aborted")
996
+ return INVALID;
997
+ if (s.status === "dirty")
998
+ status.dirty();
999
+ arrayValue.push(s.value);
1000
+ }
1001
+ return { status: status.value, value: arrayValue };
1002
+ }
1003
+ static mergeObjectAsync(status, pairs) {
1004
+ return __async(this, null, function* () {
1005
+ const syncPairs = [];
1006
+ for (const pair of pairs) {
1007
+ const key = yield pair.key;
1008
+ const value = yield pair.value;
1009
+ syncPairs.push({
1010
+ key,
1011
+ value
1012
+ });
1013
+ }
1014
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
1015
+ });
1016
+ }
1017
+ static mergeObjectSync(status, pairs) {
1018
+ const finalObject = {};
1019
+ for (const pair of pairs) {
1020
+ const { key, value } = pair;
1021
+ if (key.status === "aborted")
1022
+ return INVALID;
1023
+ if (value.status === "aborted")
1024
+ return INVALID;
1025
+ if (key.status === "dirty")
1026
+ status.dirty();
1027
+ if (value.status === "dirty")
1028
+ status.dirty();
1029
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
1030
+ finalObject[key.value] = value.value;
1031
+ }
1032
+ }
1033
+ return { status: status.value, value: finalObject };
1034
+ }
1035
+ };
1036
+ var INVALID = Object.freeze({
1037
+ status: "aborted"
1038
+ });
1039
+ var DIRTY = (value) => ({ status: "dirty", value });
1040
+ var OK = (value) => ({ status: "valid", value });
1041
+ var isAborted = (x) => x.status === "aborted";
1042
+ var isDirty = (x) => x.status === "dirty";
1043
+ var isValid = (x) => x.status === "valid";
1044
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1045
+
1046
+ // ../../node_modules/zod/dist/esm/v3/helpers/errorUtil.js
1047
+ var errorUtil;
1048
+ (function(errorUtil2) {
1049
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1050
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
1051
+ })(errorUtil || (errorUtil = {}));
1052
+
1053
+ // ../../node_modules/zod/dist/esm/v3/types.js
1054
+ var ParseInputLazyPath = class {
1055
+ constructor(parent, value, path, key) {
1056
+ this._cachedPath = [];
1057
+ this.parent = parent;
1058
+ this.data = value;
1059
+ this._path = path;
1060
+ this._key = key;
1061
+ }
1062
+ get path() {
1063
+ if (!this._cachedPath.length) {
1064
+ if (Array.isArray(this._key)) {
1065
+ this._cachedPath.push(...this._path, ...this._key);
1066
+ } else {
1067
+ this._cachedPath.push(...this._path, this._key);
1068
+ }
1069
+ }
1070
+ return this._cachedPath;
1071
+ }
1072
+ };
1073
+ var handleResult = (ctx, result) => {
1074
+ if (isValid(result)) {
1075
+ return { success: true, data: result.value };
1076
+ } else {
1077
+ if (!ctx.common.issues.length) {
1078
+ throw new Error("Validation failed but no issues detected.");
1079
+ }
1080
+ return {
1081
+ success: false,
1082
+ get error() {
1083
+ if (this._error)
1084
+ return this._error;
1085
+ const error = new ZodError(ctx.common.issues);
1086
+ this._error = error;
1087
+ return this._error;
1088
+ }
1089
+ };
1090
+ }
1091
+ };
1092
+ function processCreateParams(params) {
1093
+ if (!params)
1094
+ return {};
1095
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
1096
+ if (errorMap2 && (invalid_type_error || required_error)) {
1097
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
1098
+ }
1099
+ if (errorMap2)
1100
+ return { errorMap: errorMap2, description };
1101
+ const customMap = (iss, ctx) => {
1102
+ var _a, _b;
1103
+ const { message } = params;
1104
+ if (iss.code === "invalid_enum_value") {
1105
+ return { message: message != null ? message : ctx.defaultError };
1106
+ }
1107
+ if (typeof ctx.data === "undefined") {
1108
+ return { message: (_a = message != null ? message : required_error) != null ? _a : ctx.defaultError };
1109
+ }
1110
+ if (iss.code !== "invalid_type")
1111
+ return { message: ctx.defaultError };
1112
+ return { message: (_b = message != null ? message : invalid_type_error) != null ? _b : ctx.defaultError };
1113
+ };
1114
+ return { errorMap: customMap, description };
1115
+ }
1116
+ var ZodType = class {
1117
+ get description() {
1118
+ return this._def.description;
1119
+ }
1120
+ _getType(input) {
1121
+ return getParsedType(input.data);
1122
+ }
1123
+ _getOrReturnCtx(input, ctx) {
1124
+ return ctx || {
1125
+ common: input.parent.common,
1126
+ data: input.data,
1127
+ parsedType: getParsedType(input.data),
1128
+ schemaErrorMap: this._def.errorMap,
1129
+ path: input.path,
1130
+ parent: input.parent
1131
+ };
1132
+ }
1133
+ _processInputParams(input) {
1134
+ return {
1135
+ status: new ParseStatus(),
1136
+ ctx: {
1137
+ common: input.parent.common,
1138
+ data: input.data,
1139
+ parsedType: getParsedType(input.data),
1140
+ schemaErrorMap: this._def.errorMap,
1141
+ path: input.path,
1142
+ parent: input.parent
1143
+ }
1144
+ };
1145
+ }
1146
+ _parseSync(input) {
1147
+ const result = this._parse(input);
1148
+ if (isAsync(result)) {
1149
+ throw new Error("Synchronous parse encountered promise.");
1150
+ }
1151
+ return result;
1152
+ }
1153
+ _parseAsync(input) {
1154
+ const result = this._parse(input);
1155
+ return Promise.resolve(result);
1156
+ }
1157
+ parse(data, params) {
1158
+ const result = this.safeParse(data, params);
1159
+ if (result.success)
1160
+ return result.data;
1161
+ throw result.error;
1162
+ }
1163
+ safeParse(data, params) {
1164
+ var _a;
1165
+ const ctx = {
1166
+ common: {
1167
+ issues: [],
1168
+ async: (_a = params == null ? void 0 : params.async) != null ? _a : false,
1169
+ contextualErrorMap: params == null ? void 0 : params.errorMap
1170
+ },
1171
+ path: (params == null ? void 0 : params.path) || [],
1172
+ schemaErrorMap: this._def.errorMap,
1173
+ parent: null,
1174
+ data,
1175
+ parsedType: getParsedType(data)
1176
+ };
1177
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
1178
+ return handleResult(ctx, result);
1179
+ }
1180
+ "~validate"(data) {
1181
+ var _a, _b;
1182
+ const ctx = {
1183
+ common: {
1184
+ issues: [],
1185
+ async: !!this["~standard"].async
1186
+ },
1187
+ path: [],
1188
+ schemaErrorMap: this._def.errorMap,
1189
+ parent: null,
1190
+ data,
1191
+ parsedType: getParsedType(data)
1192
+ };
1193
+ if (!this["~standard"].async) {
1194
+ try {
1195
+ const result = this._parseSync({ data, path: [], parent: ctx });
1196
+ return isValid(result) ? {
1197
+ value: result.value
1198
+ } : {
1199
+ issues: ctx.common.issues
1200
+ };
1201
+ } catch (err) {
1202
+ if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
1203
+ this["~standard"].async = true;
1204
+ }
1205
+ ctx.common = {
1206
+ issues: [],
1207
+ async: true
1208
+ };
1209
+ }
1210
+ }
1211
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
1212
+ value: result.value
1213
+ } : {
1214
+ issues: ctx.common.issues
1215
+ });
1216
+ }
1217
+ parseAsync(data, params) {
1218
+ return __async(this, null, function* () {
1219
+ const result = yield this.safeParseAsync(data, params);
1220
+ if (result.success)
1221
+ return result.data;
1222
+ throw result.error;
1223
+ });
1224
+ }
1225
+ safeParseAsync(data, params) {
1226
+ return __async(this, null, function* () {
1227
+ const ctx = {
1228
+ common: {
1229
+ issues: [],
1230
+ contextualErrorMap: params == null ? void 0 : params.errorMap,
1231
+ async: true
1232
+ },
1233
+ path: (params == null ? void 0 : params.path) || [],
1234
+ schemaErrorMap: this._def.errorMap,
1235
+ parent: null,
1236
+ data,
1237
+ parsedType: getParsedType(data)
1238
+ };
1239
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
1240
+ const result = yield isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult);
1241
+ return handleResult(ctx, result);
1242
+ });
1243
+ }
1244
+ refine(check, message) {
1245
+ const getIssueProperties = (val) => {
1246
+ if (typeof message === "string" || typeof message === "undefined") {
1247
+ return { message };
1248
+ } else if (typeof message === "function") {
1249
+ return message(val);
1250
+ } else {
1251
+ return message;
1252
+ }
1253
+ };
1254
+ return this._refinement((val, ctx) => {
1255
+ const result = check(val);
1256
+ const setError = () => ctx.addIssue(__spreadValues({
1257
+ code: ZodIssueCode.custom
1258
+ }, getIssueProperties(val)));
1259
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
1260
+ return result.then((data) => {
1261
+ if (!data) {
1262
+ setError();
1263
+ return false;
1264
+ } else {
1265
+ return true;
1266
+ }
1267
+ });
1268
+ }
1269
+ if (!result) {
1270
+ setError();
1271
+ return false;
1272
+ } else {
1273
+ return true;
1274
+ }
1275
+ });
1276
+ }
1277
+ refinement(check, refinementData) {
1278
+ return this._refinement((val, ctx) => {
1279
+ if (!check(val)) {
1280
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
1281
+ return false;
1282
+ } else {
1283
+ return true;
1284
+ }
1285
+ });
1286
+ }
1287
+ _refinement(refinement) {
1288
+ return new ZodEffects({
1289
+ schema: this,
1290
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1291
+ effect: { type: "refinement", refinement }
1292
+ });
1293
+ }
1294
+ superRefine(refinement) {
1295
+ return this._refinement(refinement);
1296
+ }
1297
+ constructor(def) {
1298
+ this.spa = this.safeParseAsync;
1299
+ this._def = def;
1300
+ this.parse = this.parse.bind(this);
1301
+ this.safeParse = this.safeParse.bind(this);
1302
+ this.parseAsync = this.parseAsync.bind(this);
1303
+ this.safeParseAsync = this.safeParseAsync.bind(this);
1304
+ this.spa = this.spa.bind(this);
1305
+ this.refine = this.refine.bind(this);
1306
+ this.refinement = this.refinement.bind(this);
1307
+ this.superRefine = this.superRefine.bind(this);
1308
+ this.optional = this.optional.bind(this);
1309
+ this.nullable = this.nullable.bind(this);
1310
+ this.nullish = this.nullish.bind(this);
1311
+ this.array = this.array.bind(this);
1312
+ this.promise = this.promise.bind(this);
1313
+ this.or = this.or.bind(this);
1314
+ this.and = this.and.bind(this);
1315
+ this.transform = this.transform.bind(this);
1316
+ this.brand = this.brand.bind(this);
1317
+ this.default = this.default.bind(this);
1318
+ this.catch = this.catch.bind(this);
1319
+ this.describe = this.describe.bind(this);
1320
+ this.pipe = this.pipe.bind(this);
1321
+ this.readonly = this.readonly.bind(this);
1322
+ this.isNullable = this.isNullable.bind(this);
1323
+ this.isOptional = this.isOptional.bind(this);
1324
+ this["~standard"] = {
1325
+ version: 1,
1326
+ vendor: "zod",
1327
+ validate: (data) => this["~validate"](data)
1328
+ };
1329
+ }
1330
+ optional() {
1331
+ return ZodOptional.create(this, this._def);
1332
+ }
1333
+ nullable() {
1334
+ return ZodNullable.create(this, this._def);
1335
+ }
1336
+ nullish() {
1337
+ return this.nullable().optional();
1338
+ }
1339
+ array() {
1340
+ return ZodArray.create(this);
1341
+ }
1342
+ promise() {
1343
+ return ZodPromise.create(this, this._def);
1344
+ }
1345
+ or(option) {
1346
+ return ZodUnion.create([this, option], this._def);
1347
+ }
1348
+ and(incoming) {
1349
+ return ZodIntersection.create(this, incoming, this._def);
1350
+ }
1351
+ transform(transform) {
1352
+ return new ZodEffects(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
1353
+ schema: this,
1354
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1355
+ effect: { type: "transform", transform }
1356
+ }));
1357
+ }
1358
+ default(def) {
1359
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
1360
+ return new ZodDefault(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
1361
+ innerType: this,
1362
+ defaultValue: defaultValueFunc,
1363
+ typeName: ZodFirstPartyTypeKind.ZodDefault
1364
+ }));
1365
+ }
1366
+ brand() {
1367
+ return new ZodBranded(__spreadValues({
1368
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
1369
+ type: this
1370
+ }, processCreateParams(this._def)));
1371
+ }
1372
+ catch(def) {
1373
+ const catchValueFunc = typeof def === "function" ? def : () => def;
1374
+ return new ZodCatch(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
1375
+ innerType: this,
1376
+ catchValue: catchValueFunc,
1377
+ typeName: ZodFirstPartyTypeKind.ZodCatch
1378
+ }));
1379
+ }
1380
+ describe(description) {
1381
+ const This = this.constructor;
1382
+ return new This(__spreadProps(__spreadValues({}, this._def), {
1383
+ description
1384
+ }));
1385
+ }
1386
+ pipe(target) {
1387
+ return ZodPipeline.create(this, target);
1388
+ }
1389
+ readonly() {
1390
+ return ZodReadonly.create(this);
1391
+ }
1392
+ isOptional() {
1393
+ return this.safeParse(void 0).success;
1394
+ }
1395
+ isNullable() {
1396
+ return this.safeParse(null).success;
1397
+ }
1398
+ };
1399
+ var cuidRegex = /^c[^\s-]{8,}$/i;
1400
+ var cuid2Regex = /^[0-9a-z]+$/;
1401
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
1402
+ var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
1403
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
1404
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
1405
+ var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
1406
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1407
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1408
+ var emojiRegex;
1409
+ var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
1410
+ var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
1411
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
1412
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
1413
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
1414
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
1415
+ var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
1416
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
1417
+ function timeRegexSource(args) {
1418
+ let secondsRegexSource = `[0-5]\\d`;
1419
+ if (args.precision) {
1420
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
1421
+ } else if (args.precision == null) {
1422
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
1423
+ }
1424
+ const secondsQuantifier = args.precision ? "+" : "?";
1425
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
1426
+ }
1427
+ function timeRegex(args) {
1428
+ return new RegExp(`^${timeRegexSource(args)}$`);
1429
+ }
1430
+ function datetimeRegex(args) {
1431
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
1432
+ const opts = [];
1433
+ opts.push(args.local ? `Z?` : `Z`);
1434
+ if (args.offset)
1435
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
1436
+ regex = `${regex}(${opts.join("|")})`;
1437
+ return new RegExp(`^${regex}$`);
1438
+ }
1439
+ function isValidIP(ip, version) {
1440
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
1441
+ return true;
1442
+ }
1443
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
1444
+ return true;
1445
+ }
1446
+ return false;
1447
+ }
1448
+ function isValidJWT(jwt, alg) {
1449
+ if (!jwtRegex.test(jwt))
1450
+ return false;
1451
+ try {
1452
+ const [header] = jwt.split(".");
1453
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
1454
+ const decoded = JSON.parse(atob(base64));
1455
+ if (typeof decoded !== "object" || decoded === null)
1456
+ return false;
1457
+ if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
1458
+ return false;
1459
+ if (!decoded.alg)
1460
+ return false;
1461
+ if (alg && decoded.alg !== alg)
1462
+ return false;
1463
+ return true;
1464
+ } catch (e) {
1465
+ return false;
1466
+ }
1467
+ }
1468
+ function isValidCidr(ip, version) {
1469
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
1470
+ return true;
1471
+ }
1472
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
1473
+ return true;
1474
+ }
1475
+ return false;
1476
+ }
1477
+ var ZodString = class _ZodString extends ZodType {
1478
+ _parse(input) {
1479
+ if (this._def.coerce) {
1480
+ input.data = String(input.data);
1481
+ }
1482
+ const parsedType = this._getType(input);
1483
+ if (parsedType !== ZodParsedType.string) {
1484
+ const ctx2 = this._getOrReturnCtx(input);
1485
+ addIssueToContext(ctx2, {
1486
+ code: ZodIssueCode.invalid_type,
1487
+ expected: ZodParsedType.string,
1488
+ received: ctx2.parsedType
1489
+ });
1490
+ return INVALID;
1491
+ }
1492
+ const status = new ParseStatus();
1493
+ let ctx = void 0;
1494
+ for (const check of this._def.checks) {
1495
+ if (check.kind === "min") {
1496
+ if (input.data.length < check.value) {
1497
+ ctx = this._getOrReturnCtx(input, ctx);
1498
+ addIssueToContext(ctx, {
1499
+ code: ZodIssueCode.too_small,
1500
+ minimum: check.value,
1501
+ type: "string",
1502
+ inclusive: true,
1503
+ exact: false,
1504
+ message: check.message
1505
+ });
1506
+ status.dirty();
1507
+ }
1508
+ } else if (check.kind === "max") {
1509
+ if (input.data.length > check.value) {
1510
+ ctx = this._getOrReturnCtx(input, ctx);
1511
+ addIssueToContext(ctx, {
1512
+ code: ZodIssueCode.too_big,
1513
+ maximum: check.value,
1514
+ type: "string",
1515
+ inclusive: true,
1516
+ exact: false,
1517
+ message: check.message
1518
+ });
1519
+ status.dirty();
1520
+ }
1521
+ } else if (check.kind === "length") {
1522
+ const tooBig = input.data.length > check.value;
1523
+ const tooSmall = input.data.length < check.value;
1524
+ if (tooBig || tooSmall) {
1525
+ ctx = this._getOrReturnCtx(input, ctx);
1526
+ if (tooBig) {
1527
+ addIssueToContext(ctx, {
1528
+ code: ZodIssueCode.too_big,
1529
+ maximum: check.value,
1530
+ type: "string",
1531
+ inclusive: true,
1532
+ exact: true,
1533
+ message: check.message
1534
+ });
1535
+ } else if (tooSmall) {
1536
+ addIssueToContext(ctx, {
1537
+ code: ZodIssueCode.too_small,
1538
+ minimum: check.value,
1539
+ type: "string",
1540
+ inclusive: true,
1541
+ exact: true,
1542
+ message: check.message
1543
+ });
1544
+ }
1545
+ status.dirty();
1546
+ }
1547
+ } else if (check.kind === "email") {
1548
+ if (!emailRegex.test(input.data)) {
1549
+ ctx = this._getOrReturnCtx(input, ctx);
1550
+ addIssueToContext(ctx, {
1551
+ validation: "email",
1552
+ code: ZodIssueCode.invalid_string,
1553
+ message: check.message
1554
+ });
1555
+ status.dirty();
1556
+ }
1557
+ } else if (check.kind === "emoji") {
1558
+ if (!emojiRegex) {
1559
+ emojiRegex = new RegExp(_emojiRegex, "u");
1560
+ }
1561
+ if (!emojiRegex.test(input.data)) {
1562
+ ctx = this._getOrReturnCtx(input, ctx);
1563
+ addIssueToContext(ctx, {
1564
+ validation: "emoji",
1565
+ code: ZodIssueCode.invalid_string,
1566
+ message: check.message
1567
+ });
1568
+ status.dirty();
1569
+ }
1570
+ } else if (check.kind === "uuid") {
1571
+ if (!uuidRegex.test(input.data)) {
1572
+ ctx = this._getOrReturnCtx(input, ctx);
1573
+ addIssueToContext(ctx, {
1574
+ validation: "uuid",
1575
+ code: ZodIssueCode.invalid_string,
1576
+ message: check.message
1577
+ });
1578
+ status.dirty();
1579
+ }
1580
+ } else if (check.kind === "nanoid") {
1581
+ if (!nanoidRegex.test(input.data)) {
1582
+ ctx = this._getOrReturnCtx(input, ctx);
1583
+ addIssueToContext(ctx, {
1584
+ validation: "nanoid",
1585
+ code: ZodIssueCode.invalid_string,
1586
+ message: check.message
1587
+ });
1588
+ status.dirty();
1589
+ }
1590
+ } else if (check.kind === "cuid") {
1591
+ if (!cuidRegex.test(input.data)) {
1592
+ ctx = this._getOrReturnCtx(input, ctx);
1593
+ addIssueToContext(ctx, {
1594
+ validation: "cuid",
1595
+ code: ZodIssueCode.invalid_string,
1596
+ message: check.message
1597
+ });
1598
+ status.dirty();
1599
+ }
1600
+ } else if (check.kind === "cuid2") {
1601
+ if (!cuid2Regex.test(input.data)) {
1602
+ ctx = this._getOrReturnCtx(input, ctx);
1603
+ addIssueToContext(ctx, {
1604
+ validation: "cuid2",
1605
+ code: ZodIssueCode.invalid_string,
1606
+ message: check.message
1607
+ });
1608
+ status.dirty();
1609
+ }
1610
+ } else if (check.kind === "ulid") {
1611
+ if (!ulidRegex.test(input.data)) {
1612
+ ctx = this._getOrReturnCtx(input, ctx);
1613
+ addIssueToContext(ctx, {
1614
+ validation: "ulid",
1615
+ code: ZodIssueCode.invalid_string,
1616
+ message: check.message
1617
+ });
1618
+ status.dirty();
1619
+ }
1620
+ } else if (check.kind === "url") {
1621
+ try {
1622
+ new URL(input.data);
1623
+ } catch (e) {
1624
+ ctx = this._getOrReturnCtx(input, ctx);
1625
+ addIssueToContext(ctx, {
1626
+ validation: "url",
1627
+ code: ZodIssueCode.invalid_string,
1628
+ message: check.message
1629
+ });
1630
+ status.dirty();
1631
+ }
1632
+ } else if (check.kind === "regex") {
1633
+ check.regex.lastIndex = 0;
1634
+ const testResult = check.regex.test(input.data);
1635
+ if (!testResult) {
1636
+ ctx = this._getOrReturnCtx(input, ctx);
1637
+ addIssueToContext(ctx, {
1638
+ validation: "regex",
1639
+ code: ZodIssueCode.invalid_string,
1640
+ message: check.message
1641
+ });
1642
+ status.dirty();
1643
+ }
1644
+ } else if (check.kind === "trim") {
1645
+ input.data = input.data.trim();
1646
+ } else if (check.kind === "includes") {
1647
+ if (!input.data.includes(check.value, check.position)) {
1648
+ ctx = this._getOrReturnCtx(input, ctx);
1649
+ addIssueToContext(ctx, {
1650
+ code: ZodIssueCode.invalid_string,
1651
+ validation: { includes: check.value, position: check.position },
1652
+ message: check.message
1653
+ });
1654
+ status.dirty();
1655
+ }
1656
+ } else if (check.kind === "toLowerCase") {
1657
+ input.data = input.data.toLowerCase();
1658
+ } else if (check.kind === "toUpperCase") {
1659
+ input.data = input.data.toUpperCase();
1660
+ } else if (check.kind === "startsWith") {
1661
+ if (!input.data.startsWith(check.value)) {
1662
+ ctx = this._getOrReturnCtx(input, ctx);
1663
+ addIssueToContext(ctx, {
1664
+ code: ZodIssueCode.invalid_string,
1665
+ validation: { startsWith: check.value },
1666
+ message: check.message
1667
+ });
1668
+ status.dirty();
1669
+ }
1670
+ } else if (check.kind === "endsWith") {
1671
+ if (!input.data.endsWith(check.value)) {
1672
+ ctx = this._getOrReturnCtx(input, ctx);
1673
+ addIssueToContext(ctx, {
1674
+ code: ZodIssueCode.invalid_string,
1675
+ validation: { endsWith: check.value },
1676
+ message: check.message
1677
+ });
1678
+ status.dirty();
1679
+ }
1680
+ } else if (check.kind === "datetime") {
1681
+ const regex = datetimeRegex(check);
1682
+ if (!regex.test(input.data)) {
1683
+ ctx = this._getOrReturnCtx(input, ctx);
1684
+ addIssueToContext(ctx, {
1685
+ code: ZodIssueCode.invalid_string,
1686
+ validation: "datetime",
1687
+ message: check.message
1688
+ });
1689
+ status.dirty();
1690
+ }
1691
+ } else if (check.kind === "date") {
1692
+ const regex = dateRegex;
1693
+ if (!regex.test(input.data)) {
1694
+ ctx = this._getOrReturnCtx(input, ctx);
1695
+ addIssueToContext(ctx, {
1696
+ code: ZodIssueCode.invalid_string,
1697
+ validation: "date",
1698
+ message: check.message
1699
+ });
1700
+ status.dirty();
1701
+ }
1702
+ } else if (check.kind === "time") {
1703
+ const regex = timeRegex(check);
1704
+ if (!regex.test(input.data)) {
1705
+ ctx = this._getOrReturnCtx(input, ctx);
1706
+ addIssueToContext(ctx, {
1707
+ code: ZodIssueCode.invalid_string,
1708
+ validation: "time",
1709
+ message: check.message
1710
+ });
1711
+ status.dirty();
1712
+ }
1713
+ } else if (check.kind === "duration") {
1714
+ if (!durationRegex.test(input.data)) {
1715
+ ctx = this._getOrReturnCtx(input, ctx);
1716
+ addIssueToContext(ctx, {
1717
+ validation: "duration",
1718
+ code: ZodIssueCode.invalid_string,
1719
+ message: check.message
1720
+ });
1721
+ status.dirty();
1722
+ }
1723
+ } else if (check.kind === "ip") {
1724
+ if (!isValidIP(input.data, check.version)) {
1725
+ ctx = this._getOrReturnCtx(input, ctx);
1726
+ addIssueToContext(ctx, {
1727
+ validation: "ip",
1728
+ code: ZodIssueCode.invalid_string,
1729
+ message: check.message
1730
+ });
1731
+ status.dirty();
1732
+ }
1733
+ } else if (check.kind === "jwt") {
1734
+ if (!isValidJWT(input.data, check.alg)) {
1735
+ ctx = this._getOrReturnCtx(input, ctx);
1736
+ addIssueToContext(ctx, {
1737
+ validation: "jwt",
1738
+ code: ZodIssueCode.invalid_string,
1739
+ message: check.message
1740
+ });
1741
+ status.dirty();
1742
+ }
1743
+ } else if (check.kind === "cidr") {
1744
+ if (!isValidCidr(input.data, check.version)) {
1745
+ ctx = this._getOrReturnCtx(input, ctx);
1746
+ addIssueToContext(ctx, {
1747
+ validation: "cidr",
1748
+ code: ZodIssueCode.invalid_string,
1749
+ message: check.message
1750
+ });
1751
+ status.dirty();
1752
+ }
1753
+ } else if (check.kind === "base64") {
1754
+ if (!base64Regex.test(input.data)) {
1755
+ ctx = this._getOrReturnCtx(input, ctx);
1756
+ addIssueToContext(ctx, {
1757
+ validation: "base64",
1758
+ code: ZodIssueCode.invalid_string,
1759
+ message: check.message
1760
+ });
1761
+ status.dirty();
1762
+ }
1763
+ } else if (check.kind === "base64url") {
1764
+ if (!base64urlRegex.test(input.data)) {
1765
+ ctx = this._getOrReturnCtx(input, ctx);
1766
+ addIssueToContext(ctx, {
1767
+ validation: "base64url",
1768
+ code: ZodIssueCode.invalid_string,
1769
+ message: check.message
1770
+ });
1771
+ status.dirty();
1772
+ }
1773
+ } else {
1774
+ util.assertNever(check);
1775
+ }
1776
+ }
1777
+ return { status: status.value, value: input.data };
1778
+ }
1779
+ _regex(regex, validation, message) {
1780
+ return this.refinement((data) => regex.test(data), __spreadValues({
1781
+ validation,
1782
+ code: ZodIssueCode.invalid_string
1783
+ }, errorUtil.errToObj(message)));
1784
+ }
1785
+ _addCheck(check) {
1786
+ return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1787
+ checks: [...this._def.checks, check]
1788
+ }));
1789
+ }
1790
+ email(message) {
1791
+ return this._addCheck(__spreadValues({ kind: "email" }, errorUtil.errToObj(message)));
1792
+ }
1793
+ url(message) {
1794
+ return this._addCheck(__spreadValues({ kind: "url" }, errorUtil.errToObj(message)));
1795
+ }
1796
+ emoji(message) {
1797
+ return this._addCheck(__spreadValues({ kind: "emoji" }, errorUtil.errToObj(message)));
1798
+ }
1799
+ uuid(message) {
1800
+ return this._addCheck(__spreadValues({ kind: "uuid" }, errorUtil.errToObj(message)));
1801
+ }
1802
+ nanoid(message) {
1803
+ return this._addCheck(__spreadValues({ kind: "nanoid" }, errorUtil.errToObj(message)));
1804
+ }
1805
+ cuid(message) {
1806
+ return this._addCheck(__spreadValues({ kind: "cuid" }, errorUtil.errToObj(message)));
1807
+ }
1808
+ cuid2(message) {
1809
+ return this._addCheck(__spreadValues({ kind: "cuid2" }, errorUtil.errToObj(message)));
1810
+ }
1811
+ ulid(message) {
1812
+ return this._addCheck(__spreadValues({ kind: "ulid" }, errorUtil.errToObj(message)));
1813
+ }
1814
+ base64(message) {
1815
+ return this._addCheck(__spreadValues({ kind: "base64" }, errorUtil.errToObj(message)));
1816
+ }
1817
+ base64url(message) {
1818
+ return this._addCheck(__spreadValues({
1819
+ kind: "base64url"
1820
+ }, errorUtil.errToObj(message)));
1821
+ }
1822
+ jwt(options) {
1823
+ return this._addCheck(__spreadValues({ kind: "jwt" }, errorUtil.errToObj(options)));
1824
+ }
1825
+ ip(options) {
1826
+ return this._addCheck(__spreadValues({ kind: "ip" }, errorUtil.errToObj(options)));
1827
+ }
1828
+ cidr(options) {
1829
+ return this._addCheck(__spreadValues({ kind: "cidr" }, errorUtil.errToObj(options)));
1830
+ }
1831
+ datetime(options) {
1832
+ var _a, _b;
1833
+ if (typeof options === "string") {
1834
+ return this._addCheck({
1835
+ kind: "datetime",
1836
+ precision: null,
1837
+ offset: false,
1838
+ local: false,
1839
+ message: options
1840
+ });
1841
+ }
1842
+ return this._addCheck(__spreadValues({
1843
+ kind: "datetime",
1844
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
1845
+ offset: (_a = options == null ? void 0 : options.offset) != null ? _a : false,
1846
+ local: (_b = options == null ? void 0 : options.local) != null ? _b : false
1847
+ }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1848
+ }
1849
+ date(message) {
1850
+ return this._addCheck({ kind: "date", message });
1851
+ }
1852
+ time(options) {
1853
+ if (typeof options === "string") {
1854
+ return this._addCheck({
1855
+ kind: "time",
1856
+ precision: null,
1857
+ message: options
1858
+ });
1859
+ }
1860
+ return this._addCheck(__spreadValues({
1861
+ kind: "time",
1862
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision
1863
+ }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1864
+ }
1865
+ duration(message) {
1866
+ return this._addCheck(__spreadValues({ kind: "duration" }, errorUtil.errToObj(message)));
1867
+ }
1868
+ regex(regex, message) {
1869
+ return this._addCheck(__spreadValues({
1870
+ kind: "regex",
1871
+ regex
1872
+ }, errorUtil.errToObj(message)));
1873
+ }
1874
+ includes(value, options) {
1875
+ return this._addCheck(__spreadValues({
1876
+ kind: "includes",
1877
+ value,
1878
+ position: options == null ? void 0 : options.position
1879
+ }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1880
+ }
1881
+ startsWith(value, message) {
1882
+ return this._addCheck(__spreadValues({
1883
+ kind: "startsWith",
1884
+ value
1885
+ }, errorUtil.errToObj(message)));
1886
+ }
1887
+ endsWith(value, message) {
1888
+ return this._addCheck(__spreadValues({
1889
+ kind: "endsWith",
1890
+ value
1891
+ }, errorUtil.errToObj(message)));
1892
+ }
1893
+ min(minLength, message) {
1894
+ return this._addCheck(__spreadValues({
1895
+ kind: "min",
1896
+ value: minLength
1897
+ }, errorUtil.errToObj(message)));
1898
+ }
1899
+ max(maxLength, message) {
1900
+ return this._addCheck(__spreadValues({
1901
+ kind: "max",
1902
+ value: maxLength
1903
+ }, errorUtil.errToObj(message)));
1904
+ }
1905
+ length(len, message) {
1906
+ return this._addCheck(__spreadValues({
1907
+ kind: "length",
1908
+ value: len
1909
+ }, errorUtil.errToObj(message)));
1910
+ }
1911
+ /**
1912
+ * Equivalent to `.min(1)`
1913
+ */
1914
+ nonempty(message) {
1915
+ return this.min(1, errorUtil.errToObj(message));
1916
+ }
1917
+ trim() {
1918
+ return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1919
+ checks: [...this._def.checks, { kind: "trim" }]
1920
+ }));
1921
+ }
1922
+ toLowerCase() {
1923
+ return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1924
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1925
+ }));
1926
+ }
1927
+ toUpperCase() {
1928
+ return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1929
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1930
+ }));
1931
+ }
1932
+ get isDatetime() {
1933
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1934
+ }
1935
+ get isDate() {
1936
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1937
+ }
1938
+ get isTime() {
1939
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1940
+ }
1941
+ get isDuration() {
1942
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1943
+ }
1944
+ get isEmail() {
1945
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1946
+ }
1947
+ get isURL() {
1948
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1949
+ }
1950
+ get isEmoji() {
1951
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1952
+ }
1953
+ get isUUID() {
1954
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1955
+ }
1956
+ get isNANOID() {
1957
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1958
+ }
1959
+ get isCUID() {
1960
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1961
+ }
1962
+ get isCUID2() {
1963
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1964
+ }
1965
+ get isULID() {
1966
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1967
+ }
1968
+ get isIP() {
1969
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1970
+ }
1971
+ get isCIDR() {
1972
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1973
+ }
1974
+ get isBase64() {
1975
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1976
+ }
1977
+ get isBase64url() {
1978
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1979
+ }
1980
+ get minLength() {
1981
+ let min = null;
1982
+ for (const ch of this._def.checks) {
1983
+ if (ch.kind === "min") {
1984
+ if (min === null || ch.value > min)
1985
+ min = ch.value;
1986
+ }
1987
+ }
1988
+ return min;
1989
+ }
1990
+ get maxLength() {
1991
+ let max = null;
1992
+ for (const ch of this._def.checks) {
1993
+ if (ch.kind === "max") {
1994
+ if (max === null || ch.value < max)
1995
+ max = ch.value;
1996
+ }
1997
+ }
1998
+ return max;
1999
+ }
2000
+ };
2001
+ ZodString.create = (params) => {
2002
+ var _a;
2003
+ return new ZodString(__spreadValues({
2004
+ checks: [],
2005
+ typeName: ZodFirstPartyTypeKind.ZodString,
2006
+ coerce: (_a = params == null ? void 0 : params.coerce) != null ? _a : false
2007
+ }, processCreateParams(params)));
2008
+ };
2009
+ function floatSafeRemainder(val, step) {
2010
+ const valDecCount = (val.toString().split(".")[1] || "").length;
2011
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
2012
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
2013
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
2014
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
2015
+ return valInt % stepInt / 10 ** decCount;
2016
+ }
2017
+ var ZodNumber = class _ZodNumber extends ZodType {
2018
+ constructor() {
2019
+ super(...arguments);
2020
+ this.min = this.gte;
2021
+ this.max = this.lte;
2022
+ this.step = this.multipleOf;
2023
+ }
2024
+ _parse(input) {
2025
+ if (this._def.coerce) {
2026
+ input.data = Number(input.data);
2027
+ }
2028
+ const parsedType = this._getType(input);
2029
+ if (parsedType !== ZodParsedType.number) {
2030
+ const ctx2 = this._getOrReturnCtx(input);
2031
+ addIssueToContext(ctx2, {
2032
+ code: ZodIssueCode.invalid_type,
2033
+ expected: ZodParsedType.number,
2034
+ received: ctx2.parsedType
2035
+ });
2036
+ return INVALID;
2037
+ }
2038
+ let ctx = void 0;
2039
+ const status = new ParseStatus();
2040
+ for (const check of this._def.checks) {
2041
+ if (check.kind === "int") {
2042
+ if (!util.isInteger(input.data)) {
2043
+ ctx = this._getOrReturnCtx(input, ctx);
2044
+ addIssueToContext(ctx, {
2045
+ code: ZodIssueCode.invalid_type,
2046
+ expected: "integer",
2047
+ received: "float",
2048
+ message: check.message
2049
+ });
2050
+ status.dirty();
2051
+ }
2052
+ } else if (check.kind === "min") {
2053
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2054
+ if (tooSmall) {
2055
+ ctx = this._getOrReturnCtx(input, ctx);
2056
+ addIssueToContext(ctx, {
2057
+ code: ZodIssueCode.too_small,
2058
+ minimum: check.value,
2059
+ type: "number",
2060
+ inclusive: check.inclusive,
2061
+ exact: false,
2062
+ message: check.message
2063
+ });
2064
+ status.dirty();
2065
+ }
2066
+ } else if (check.kind === "max") {
2067
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2068
+ if (tooBig) {
2069
+ ctx = this._getOrReturnCtx(input, ctx);
2070
+ addIssueToContext(ctx, {
2071
+ code: ZodIssueCode.too_big,
2072
+ maximum: check.value,
2073
+ type: "number",
2074
+ inclusive: check.inclusive,
2075
+ exact: false,
2076
+ message: check.message
2077
+ });
2078
+ status.dirty();
2079
+ }
2080
+ } else if (check.kind === "multipleOf") {
2081
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
2082
+ ctx = this._getOrReturnCtx(input, ctx);
2083
+ addIssueToContext(ctx, {
2084
+ code: ZodIssueCode.not_multiple_of,
2085
+ multipleOf: check.value,
2086
+ message: check.message
2087
+ });
2088
+ status.dirty();
2089
+ }
2090
+ } else if (check.kind === "finite") {
2091
+ if (!Number.isFinite(input.data)) {
2092
+ ctx = this._getOrReturnCtx(input, ctx);
2093
+ addIssueToContext(ctx, {
2094
+ code: ZodIssueCode.not_finite,
2095
+ message: check.message
2096
+ });
2097
+ status.dirty();
2098
+ }
2099
+ } else {
2100
+ util.assertNever(check);
2101
+ }
2102
+ }
2103
+ return { status: status.value, value: input.data };
2104
+ }
2105
+ gte(value, message) {
2106
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2107
+ }
2108
+ gt(value, message) {
2109
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2110
+ }
2111
+ lte(value, message) {
2112
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2113
+ }
2114
+ lt(value, message) {
2115
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2116
+ }
2117
+ setLimit(kind, value, inclusive, message) {
2118
+ return new _ZodNumber(__spreadProps(__spreadValues({}, this._def), {
2119
+ checks: [
2120
+ ...this._def.checks,
2121
+ {
2122
+ kind,
2123
+ value,
2124
+ inclusive,
2125
+ message: errorUtil.toString(message)
2126
+ }
2127
+ ]
2128
+ }));
2129
+ }
2130
+ _addCheck(check) {
2131
+ return new _ZodNumber(__spreadProps(__spreadValues({}, this._def), {
2132
+ checks: [...this._def.checks, check]
2133
+ }));
2134
+ }
2135
+ int(message) {
2136
+ return this._addCheck({
2137
+ kind: "int",
2138
+ message: errorUtil.toString(message)
2139
+ });
2140
+ }
2141
+ positive(message) {
2142
+ return this._addCheck({
2143
+ kind: "min",
2144
+ value: 0,
2145
+ inclusive: false,
2146
+ message: errorUtil.toString(message)
2147
+ });
2148
+ }
2149
+ negative(message) {
2150
+ return this._addCheck({
2151
+ kind: "max",
2152
+ value: 0,
2153
+ inclusive: false,
2154
+ message: errorUtil.toString(message)
2155
+ });
2156
+ }
2157
+ nonpositive(message) {
2158
+ return this._addCheck({
2159
+ kind: "max",
2160
+ value: 0,
2161
+ inclusive: true,
2162
+ message: errorUtil.toString(message)
2163
+ });
2164
+ }
2165
+ nonnegative(message) {
2166
+ return this._addCheck({
2167
+ kind: "min",
2168
+ value: 0,
2169
+ inclusive: true,
2170
+ message: errorUtil.toString(message)
2171
+ });
2172
+ }
2173
+ multipleOf(value, message) {
2174
+ return this._addCheck({
2175
+ kind: "multipleOf",
2176
+ value,
2177
+ message: errorUtil.toString(message)
2178
+ });
2179
+ }
2180
+ finite(message) {
2181
+ return this._addCheck({
2182
+ kind: "finite",
2183
+ message: errorUtil.toString(message)
2184
+ });
2185
+ }
2186
+ safe(message) {
2187
+ return this._addCheck({
2188
+ kind: "min",
2189
+ inclusive: true,
2190
+ value: Number.MIN_SAFE_INTEGER,
2191
+ message: errorUtil.toString(message)
2192
+ })._addCheck({
2193
+ kind: "max",
2194
+ inclusive: true,
2195
+ value: Number.MAX_SAFE_INTEGER,
2196
+ message: errorUtil.toString(message)
2197
+ });
2198
+ }
2199
+ get minValue() {
2200
+ let min = null;
2201
+ for (const ch of this._def.checks) {
2202
+ if (ch.kind === "min") {
2203
+ if (min === null || ch.value > min)
2204
+ min = ch.value;
2205
+ }
2206
+ }
2207
+ return min;
2208
+ }
2209
+ get maxValue() {
2210
+ let max = null;
2211
+ for (const ch of this._def.checks) {
2212
+ if (ch.kind === "max") {
2213
+ if (max === null || ch.value < max)
2214
+ max = ch.value;
2215
+ }
2216
+ }
2217
+ return max;
2218
+ }
2219
+ get isInt() {
2220
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
2221
+ }
2222
+ get isFinite() {
2223
+ let max = null;
2224
+ let min = null;
2225
+ for (const ch of this._def.checks) {
2226
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
2227
+ return true;
2228
+ } else if (ch.kind === "min") {
2229
+ if (min === null || ch.value > min)
2230
+ min = ch.value;
2231
+ } else if (ch.kind === "max") {
2232
+ if (max === null || ch.value < max)
2233
+ max = ch.value;
2234
+ }
2235
+ }
2236
+ return Number.isFinite(min) && Number.isFinite(max);
2237
+ }
2238
+ };
2239
+ ZodNumber.create = (params) => {
2240
+ return new ZodNumber(__spreadValues({
2241
+ checks: [],
2242
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
2243
+ coerce: (params == null ? void 0 : params.coerce) || false
2244
+ }, processCreateParams(params)));
2245
+ };
2246
+ var ZodBigInt = class _ZodBigInt extends ZodType {
2247
+ constructor() {
2248
+ super(...arguments);
2249
+ this.min = this.gte;
2250
+ this.max = this.lte;
2251
+ }
2252
+ _parse(input) {
2253
+ if (this._def.coerce) {
2254
+ try {
2255
+ input.data = BigInt(input.data);
2256
+ } catch (e) {
2257
+ return this._getInvalidInput(input);
2258
+ }
2259
+ }
2260
+ const parsedType = this._getType(input);
2261
+ if (parsedType !== ZodParsedType.bigint) {
2262
+ return this._getInvalidInput(input);
2263
+ }
2264
+ let ctx = void 0;
2265
+ const status = new ParseStatus();
2266
+ for (const check of this._def.checks) {
2267
+ if (check.kind === "min") {
2268
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2269
+ if (tooSmall) {
2270
+ ctx = this._getOrReturnCtx(input, ctx);
2271
+ addIssueToContext(ctx, {
2272
+ code: ZodIssueCode.too_small,
2273
+ type: "bigint",
2274
+ minimum: check.value,
2275
+ inclusive: check.inclusive,
2276
+ message: check.message
2277
+ });
2278
+ status.dirty();
2279
+ }
2280
+ } else if (check.kind === "max") {
2281
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2282
+ if (tooBig) {
2283
+ ctx = this._getOrReturnCtx(input, ctx);
2284
+ addIssueToContext(ctx, {
2285
+ code: ZodIssueCode.too_big,
2286
+ type: "bigint",
2287
+ maximum: check.value,
2288
+ inclusive: check.inclusive,
2289
+ message: check.message
2290
+ });
2291
+ status.dirty();
2292
+ }
2293
+ } else if (check.kind === "multipleOf") {
2294
+ if (input.data % check.value !== BigInt(0)) {
2295
+ ctx = this._getOrReturnCtx(input, ctx);
2296
+ addIssueToContext(ctx, {
2297
+ code: ZodIssueCode.not_multiple_of,
2298
+ multipleOf: check.value,
2299
+ message: check.message
2300
+ });
2301
+ status.dirty();
2302
+ }
2303
+ } else {
2304
+ util.assertNever(check);
2305
+ }
2306
+ }
2307
+ return { status: status.value, value: input.data };
2308
+ }
2309
+ _getInvalidInput(input) {
2310
+ const ctx = this._getOrReturnCtx(input);
2311
+ addIssueToContext(ctx, {
2312
+ code: ZodIssueCode.invalid_type,
2313
+ expected: ZodParsedType.bigint,
2314
+ received: ctx.parsedType
2315
+ });
2316
+ return INVALID;
2317
+ }
2318
+ gte(value, message) {
2319
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2320
+ }
2321
+ gt(value, message) {
2322
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2323
+ }
2324
+ lte(value, message) {
2325
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2326
+ }
2327
+ lt(value, message) {
2328
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2329
+ }
2330
+ setLimit(kind, value, inclusive, message) {
2331
+ return new _ZodBigInt(__spreadProps(__spreadValues({}, this._def), {
2332
+ checks: [
2333
+ ...this._def.checks,
2334
+ {
2335
+ kind,
2336
+ value,
2337
+ inclusive,
2338
+ message: errorUtil.toString(message)
2339
+ }
2340
+ ]
2341
+ }));
2342
+ }
2343
+ _addCheck(check) {
2344
+ return new _ZodBigInt(__spreadProps(__spreadValues({}, this._def), {
2345
+ checks: [...this._def.checks, check]
2346
+ }));
2347
+ }
2348
+ positive(message) {
2349
+ return this._addCheck({
2350
+ kind: "min",
2351
+ value: BigInt(0),
2352
+ inclusive: false,
2353
+ message: errorUtil.toString(message)
2354
+ });
2355
+ }
2356
+ negative(message) {
2357
+ return this._addCheck({
2358
+ kind: "max",
2359
+ value: BigInt(0),
2360
+ inclusive: false,
2361
+ message: errorUtil.toString(message)
2362
+ });
2363
+ }
2364
+ nonpositive(message) {
2365
+ return this._addCheck({
2366
+ kind: "max",
2367
+ value: BigInt(0),
2368
+ inclusive: true,
2369
+ message: errorUtil.toString(message)
2370
+ });
2371
+ }
2372
+ nonnegative(message) {
2373
+ return this._addCheck({
2374
+ kind: "min",
2375
+ value: BigInt(0),
2376
+ inclusive: true,
2377
+ message: errorUtil.toString(message)
2378
+ });
2379
+ }
2380
+ multipleOf(value, message) {
2381
+ return this._addCheck({
2382
+ kind: "multipleOf",
2383
+ value,
2384
+ message: errorUtil.toString(message)
2385
+ });
2386
+ }
2387
+ get minValue() {
2388
+ let min = null;
2389
+ for (const ch of this._def.checks) {
2390
+ if (ch.kind === "min") {
2391
+ if (min === null || ch.value > min)
2392
+ min = ch.value;
2393
+ }
2394
+ }
2395
+ return min;
2396
+ }
2397
+ get maxValue() {
2398
+ let max = null;
2399
+ for (const ch of this._def.checks) {
2400
+ if (ch.kind === "max") {
2401
+ if (max === null || ch.value < max)
2402
+ max = ch.value;
2403
+ }
2404
+ }
2405
+ return max;
2406
+ }
2407
+ };
2408
+ ZodBigInt.create = (params) => {
2409
+ var _a;
2410
+ return new ZodBigInt(__spreadValues({
2411
+ checks: [],
2412
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
2413
+ coerce: (_a = params == null ? void 0 : params.coerce) != null ? _a : false
2414
+ }, processCreateParams(params)));
2415
+ };
2416
+ var ZodBoolean = class extends ZodType {
2417
+ _parse(input) {
2418
+ if (this._def.coerce) {
2419
+ input.data = Boolean(input.data);
2420
+ }
2421
+ const parsedType = this._getType(input);
2422
+ if (parsedType !== ZodParsedType.boolean) {
2423
+ const ctx = this._getOrReturnCtx(input);
2424
+ addIssueToContext(ctx, {
2425
+ code: ZodIssueCode.invalid_type,
2426
+ expected: ZodParsedType.boolean,
2427
+ received: ctx.parsedType
2428
+ });
2429
+ return INVALID;
2430
+ }
2431
+ return OK(input.data);
2432
+ }
2433
+ };
2434
+ ZodBoolean.create = (params) => {
2435
+ return new ZodBoolean(__spreadValues({
2436
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
2437
+ coerce: (params == null ? void 0 : params.coerce) || false
2438
+ }, processCreateParams(params)));
2439
+ };
2440
+ var ZodDate = class _ZodDate extends ZodType {
2441
+ _parse(input) {
2442
+ if (this._def.coerce) {
2443
+ input.data = new Date(input.data);
2444
+ }
2445
+ const parsedType = this._getType(input);
2446
+ if (parsedType !== ZodParsedType.date) {
2447
+ const ctx2 = this._getOrReturnCtx(input);
2448
+ addIssueToContext(ctx2, {
2449
+ code: ZodIssueCode.invalid_type,
2450
+ expected: ZodParsedType.date,
2451
+ received: ctx2.parsedType
2452
+ });
2453
+ return INVALID;
2454
+ }
2455
+ if (Number.isNaN(input.data.getTime())) {
2456
+ const ctx2 = this._getOrReturnCtx(input);
2457
+ addIssueToContext(ctx2, {
2458
+ code: ZodIssueCode.invalid_date
2459
+ });
2460
+ return INVALID;
2461
+ }
2462
+ const status = new ParseStatus();
2463
+ let ctx = void 0;
2464
+ for (const check of this._def.checks) {
2465
+ if (check.kind === "min") {
2466
+ if (input.data.getTime() < check.value) {
2467
+ ctx = this._getOrReturnCtx(input, ctx);
2468
+ addIssueToContext(ctx, {
2469
+ code: ZodIssueCode.too_small,
2470
+ message: check.message,
2471
+ inclusive: true,
2472
+ exact: false,
2473
+ minimum: check.value,
2474
+ type: "date"
2475
+ });
2476
+ status.dirty();
2477
+ }
2478
+ } else if (check.kind === "max") {
2479
+ if (input.data.getTime() > check.value) {
2480
+ ctx = this._getOrReturnCtx(input, ctx);
2481
+ addIssueToContext(ctx, {
2482
+ code: ZodIssueCode.too_big,
2483
+ message: check.message,
2484
+ inclusive: true,
2485
+ exact: false,
2486
+ maximum: check.value,
2487
+ type: "date"
2488
+ });
2489
+ status.dirty();
2490
+ }
2491
+ } else {
2492
+ util.assertNever(check);
2493
+ }
2494
+ }
2495
+ return {
2496
+ status: status.value,
2497
+ value: new Date(input.data.getTime())
2498
+ };
2499
+ }
2500
+ _addCheck(check) {
2501
+ return new _ZodDate(__spreadProps(__spreadValues({}, this._def), {
2502
+ checks: [...this._def.checks, check]
2503
+ }));
2504
+ }
2505
+ min(minDate, message) {
2506
+ return this._addCheck({
2507
+ kind: "min",
2508
+ value: minDate.getTime(),
2509
+ message: errorUtil.toString(message)
2510
+ });
2511
+ }
2512
+ max(maxDate, message) {
2513
+ return this._addCheck({
2514
+ kind: "max",
2515
+ value: maxDate.getTime(),
2516
+ message: errorUtil.toString(message)
2517
+ });
2518
+ }
2519
+ get minDate() {
2520
+ let min = null;
2521
+ for (const ch of this._def.checks) {
2522
+ if (ch.kind === "min") {
2523
+ if (min === null || ch.value > min)
2524
+ min = ch.value;
2525
+ }
2526
+ }
2527
+ return min != null ? new Date(min) : null;
2528
+ }
2529
+ get maxDate() {
2530
+ let max = null;
2531
+ for (const ch of this._def.checks) {
2532
+ if (ch.kind === "max") {
2533
+ if (max === null || ch.value < max)
2534
+ max = ch.value;
2535
+ }
2536
+ }
2537
+ return max != null ? new Date(max) : null;
2538
+ }
2539
+ };
2540
+ ZodDate.create = (params) => {
2541
+ return new ZodDate(__spreadValues({
2542
+ checks: [],
2543
+ coerce: (params == null ? void 0 : params.coerce) || false,
2544
+ typeName: ZodFirstPartyTypeKind.ZodDate
2545
+ }, processCreateParams(params)));
2546
+ };
2547
+ var ZodSymbol = class extends ZodType {
2548
+ _parse(input) {
2549
+ const parsedType = this._getType(input);
2550
+ if (parsedType !== ZodParsedType.symbol) {
2551
+ const ctx = this._getOrReturnCtx(input);
2552
+ addIssueToContext(ctx, {
2553
+ code: ZodIssueCode.invalid_type,
2554
+ expected: ZodParsedType.symbol,
2555
+ received: ctx.parsedType
2556
+ });
2557
+ return INVALID;
2558
+ }
2559
+ return OK(input.data);
2560
+ }
2561
+ };
2562
+ ZodSymbol.create = (params) => {
2563
+ return new ZodSymbol(__spreadValues({
2564
+ typeName: ZodFirstPartyTypeKind.ZodSymbol
2565
+ }, processCreateParams(params)));
2566
+ };
2567
+ var ZodUndefined = class extends ZodType {
2568
+ _parse(input) {
2569
+ const parsedType = this._getType(input);
2570
+ if (parsedType !== ZodParsedType.undefined) {
2571
+ const ctx = this._getOrReturnCtx(input);
2572
+ addIssueToContext(ctx, {
2573
+ code: ZodIssueCode.invalid_type,
2574
+ expected: ZodParsedType.undefined,
2575
+ received: ctx.parsedType
2576
+ });
2577
+ return INVALID;
2578
+ }
2579
+ return OK(input.data);
2580
+ }
2581
+ };
2582
+ ZodUndefined.create = (params) => {
2583
+ return new ZodUndefined(__spreadValues({
2584
+ typeName: ZodFirstPartyTypeKind.ZodUndefined
2585
+ }, processCreateParams(params)));
2586
+ };
2587
+ var ZodNull = class extends ZodType {
2588
+ _parse(input) {
2589
+ const parsedType = this._getType(input);
2590
+ if (parsedType !== ZodParsedType.null) {
2591
+ const ctx = this._getOrReturnCtx(input);
2592
+ addIssueToContext(ctx, {
2593
+ code: ZodIssueCode.invalid_type,
2594
+ expected: ZodParsedType.null,
2595
+ received: ctx.parsedType
2596
+ });
2597
+ return INVALID;
2598
+ }
2599
+ return OK(input.data);
2600
+ }
2601
+ };
2602
+ ZodNull.create = (params) => {
2603
+ return new ZodNull(__spreadValues({
2604
+ typeName: ZodFirstPartyTypeKind.ZodNull
2605
+ }, processCreateParams(params)));
2606
+ };
2607
+ var ZodAny = class extends ZodType {
2608
+ constructor() {
2609
+ super(...arguments);
2610
+ this._any = true;
2611
+ }
2612
+ _parse(input) {
2613
+ return OK(input.data);
2614
+ }
2615
+ };
2616
+ ZodAny.create = (params) => {
2617
+ return new ZodAny(__spreadValues({
2618
+ typeName: ZodFirstPartyTypeKind.ZodAny
2619
+ }, processCreateParams(params)));
2620
+ };
2621
+ var ZodUnknown = class extends ZodType {
2622
+ constructor() {
2623
+ super(...arguments);
2624
+ this._unknown = true;
2625
+ }
2626
+ _parse(input) {
2627
+ return OK(input.data);
2628
+ }
2629
+ };
2630
+ ZodUnknown.create = (params) => {
2631
+ return new ZodUnknown(__spreadValues({
2632
+ typeName: ZodFirstPartyTypeKind.ZodUnknown
2633
+ }, processCreateParams(params)));
2634
+ };
2635
+ var ZodNever = class extends ZodType {
2636
+ _parse(input) {
2637
+ const ctx = this._getOrReturnCtx(input);
2638
+ addIssueToContext(ctx, {
2639
+ code: ZodIssueCode.invalid_type,
2640
+ expected: ZodParsedType.never,
2641
+ received: ctx.parsedType
2642
+ });
2643
+ return INVALID;
2644
+ }
2645
+ };
2646
+ ZodNever.create = (params) => {
2647
+ return new ZodNever(__spreadValues({
2648
+ typeName: ZodFirstPartyTypeKind.ZodNever
2649
+ }, processCreateParams(params)));
2650
+ };
2651
+ var ZodVoid = class extends ZodType {
2652
+ _parse(input) {
2653
+ const parsedType = this._getType(input);
2654
+ if (parsedType !== ZodParsedType.undefined) {
2655
+ const ctx = this._getOrReturnCtx(input);
2656
+ addIssueToContext(ctx, {
2657
+ code: ZodIssueCode.invalid_type,
2658
+ expected: ZodParsedType.void,
2659
+ received: ctx.parsedType
2660
+ });
2661
+ return INVALID;
2662
+ }
2663
+ return OK(input.data);
2664
+ }
2665
+ };
2666
+ ZodVoid.create = (params) => {
2667
+ return new ZodVoid(__spreadValues({
2668
+ typeName: ZodFirstPartyTypeKind.ZodVoid
2669
+ }, processCreateParams(params)));
2670
+ };
2671
+ var ZodArray = class _ZodArray extends ZodType {
2672
+ _parse(input) {
2673
+ const { ctx, status } = this._processInputParams(input);
2674
+ const def = this._def;
2675
+ if (ctx.parsedType !== ZodParsedType.array) {
2676
+ addIssueToContext(ctx, {
2677
+ code: ZodIssueCode.invalid_type,
2678
+ expected: ZodParsedType.array,
2679
+ received: ctx.parsedType
2680
+ });
2681
+ return INVALID;
2682
+ }
2683
+ if (def.exactLength !== null) {
2684
+ const tooBig = ctx.data.length > def.exactLength.value;
2685
+ const tooSmall = ctx.data.length < def.exactLength.value;
2686
+ if (tooBig || tooSmall) {
2687
+ addIssueToContext(ctx, {
2688
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2689
+ minimum: tooSmall ? def.exactLength.value : void 0,
2690
+ maximum: tooBig ? def.exactLength.value : void 0,
2691
+ type: "array",
2692
+ inclusive: true,
2693
+ exact: true,
2694
+ message: def.exactLength.message
2695
+ });
2696
+ status.dirty();
2697
+ }
2698
+ }
2699
+ if (def.minLength !== null) {
2700
+ if (ctx.data.length < def.minLength.value) {
2701
+ addIssueToContext(ctx, {
2702
+ code: ZodIssueCode.too_small,
2703
+ minimum: def.minLength.value,
2704
+ type: "array",
2705
+ inclusive: true,
2706
+ exact: false,
2707
+ message: def.minLength.message
2708
+ });
2709
+ status.dirty();
2710
+ }
2711
+ }
2712
+ if (def.maxLength !== null) {
2713
+ if (ctx.data.length > def.maxLength.value) {
2714
+ addIssueToContext(ctx, {
2715
+ code: ZodIssueCode.too_big,
2716
+ maximum: def.maxLength.value,
2717
+ type: "array",
2718
+ inclusive: true,
2719
+ exact: false,
2720
+ message: def.maxLength.message
2721
+ });
2722
+ status.dirty();
2723
+ }
2724
+ }
2725
+ if (ctx.common.async) {
2726
+ return Promise.all([...ctx.data].map((item, i) => {
2727
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2728
+ })).then((result2) => {
2729
+ return ParseStatus.mergeArray(status, result2);
2730
+ });
2731
+ }
2732
+ const result = [...ctx.data].map((item, i) => {
2733
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2734
+ });
2735
+ return ParseStatus.mergeArray(status, result);
2736
+ }
2737
+ get element() {
2738
+ return this._def.type;
2739
+ }
2740
+ min(minLength, message) {
2741
+ return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2742
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2743
+ }));
2744
+ }
2745
+ max(maxLength, message) {
2746
+ return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2747
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2748
+ }));
2749
+ }
2750
+ length(len, message) {
2751
+ return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2752
+ exactLength: { value: len, message: errorUtil.toString(message) }
2753
+ }));
2754
+ }
2755
+ nonempty(message) {
2756
+ return this.min(1, message);
2757
+ }
2758
+ };
2759
+ ZodArray.create = (schema, params) => {
2760
+ return new ZodArray(__spreadValues({
2761
+ type: schema,
2762
+ minLength: null,
2763
+ maxLength: null,
2764
+ exactLength: null,
2765
+ typeName: ZodFirstPartyTypeKind.ZodArray
2766
+ }, processCreateParams(params)));
2767
+ };
2768
+ function deepPartialify(schema) {
2769
+ if (schema instanceof ZodObject) {
2770
+ const newShape = {};
2771
+ for (const key in schema.shape) {
2772
+ const fieldSchema = schema.shape[key];
2773
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2774
+ }
2775
+ return new ZodObject(__spreadProps(__spreadValues({}, schema._def), {
2776
+ shape: () => newShape
2777
+ }));
2778
+ } else if (schema instanceof ZodArray) {
2779
+ return new ZodArray(__spreadProps(__spreadValues({}, schema._def), {
2780
+ type: deepPartialify(schema.element)
2781
+ }));
2782
+ } else if (schema instanceof ZodOptional) {
2783
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2784
+ } else if (schema instanceof ZodNullable) {
2785
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2786
+ } else if (schema instanceof ZodTuple) {
2787
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2788
+ } else {
2789
+ return schema;
2790
+ }
2791
+ }
2792
+ var ZodObject = class _ZodObject extends ZodType {
2793
+ constructor() {
2794
+ super(...arguments);
2795
+ this._cached = null;
2796
+ this.nonstrict = this.passthrough;
2797
+ this.augment = this.extend;
2798
+ }
2799
+ _getCached() {
2800
+ if (this._cached !== null)
2801
+ return this._cached;
2802
+ const shape = this._def.shape();
2803
+ const keys = util.objectKeys(shape);
2804
+ this._cached = { shape, keys };
2805
+ return this._cached;
2806
+ }
2807
+ _parse(input) {
2808
+ const parsedType = this._getType(input);
2809
+ if (parsedType !== ZodParsedType.object) {
2810
+ const ctx2 = this._getOrReturnCtx(input);
2811
+ addIssueToContext(ctx2, {
2812
+ code: ZodIssueCode.invalid_type,
2813
+ expected: ZodParsedType.object,
2814
+ received: ctx2.parsedType
2815
+ });
2816
+ return INVALID;
2817
+ }
2818
+ const { status, ctx } = this._processInputParams(input);
2819
+ const { shape, keys: shapeKeys } = this._getCached();
2820
+ const extraKeys = [];
2821
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2822
+ for (const key in ctx.data) {
2823
+ if (!shapeKeys.includes(key)) {
2824
+ extraKeys.push(key);
2825
+ }
2826
+ }
2827
+ }
2828
+ const pairs = [];
2829
+ for (const key of shapeKeys) {
2830
+ const keyValidator = shape[key];
2831
+ const value = ctx.data[key];
2832
+ pairs.push({
2833
+ key: { status: "valid", value: key },
2834
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2835
+ alwaysSet: key in ctx.data
2836
+ });
2837
+ }
2838
+ if (this._def.catchall instanceof ZodNever) {
2839
+ const unknownKeys = this._def.unknownKeys;
2840
+ if (unknownKeys === "passthrough") {
2841
+ for (const key of extraKeys) {
2842
+ pairs.push({
2843
+ key: { status: "valid", value: key },
2844
+ value: { status: "valid", value: ctx.data[key] }
2845
+ });
2846
+ }
2847
+ } else if (unknownKeys === "strict") {
2848
+ if (extraKeys.length > 0) {
2849
+ addIssueToContext(ctx, {
2850
+ code: ZodIssueCode.unrecognized_keys,
2851
+ keys: extraKeys
2852
+ });
2853
+ status.dirty();
2854
+ }
2855
+ } else if (unknownKeys === "strip") ; else {
2856
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2857
+ }
2858
+ } else {
2859
+ const catchall = this._def.catchall;
2860
+ for (const key of extraKeys) {
2861
+ const value = ctx.data[key];
2862
+ pairs.push({
2863
+ key: { status: "valid", value: key },
2864
+ value: catchall._parse(
2865
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
2866
+ //, ctx.child(key), value, getParsedType(value)
2867
+ ),
2868
+ alwaysSet: key in ctx.data
2869
+ });
2870
+ }
2871
+ }
2872
+ if (ctx.common.async) {
2873
+ return Promise.resolve().then(() => __async(this, null, function* () {
2874
+ const syncPairs = [];
2875
+ for (const pair of pairs) {
2876
+ const key = yield pair.key;
2877
+ const value = yield pair.value;
2878
+ syncPairs.push({
2879
+ key,
2880
+ value,
2881
+ alwaysSet: pair.alwaysSet
2882
+ });
2883
+ }
2884
+ return syncPairs;
2885
+ })).then((syncPairs) => {
2886
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2887
+ });
2888
+ } else {
2889
+ return ParseStatus.mergeObjectSync(status, pairs);
2890
+ }
2891
+ }
2892
+ get shape() {
2893
+ return this._def.shape();
2894
+ }
2895
+ strict(message) {
2896
+ errorUtil.errToObj;
2897
+ return new _ZodObject(__spreadValues(__spreadProps(__spreadValues({}, this._def), {
2898
+ unknownKeys: "strict"
2899
+ }), message !== void 0 ? {
2900
+ errorMap: (issue, ctx) => {
2901
+ var _a, _b, _c, _d;
2902
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) != null ? _c : ctx.defaultError;
2903
+ if (issue.code === "unrecognized_keys")
2904
+ return {
2905
+ message: (_d = errorUtil.errToObj(message).message) != null ? _d : defaultError
2906
+ };
2907
+ return {
2908
+ message: defaultError
2909
+ };
2910
+ }
2911
+ } : {}));
2912
+ }
2913
+ strip() {
2914
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2915
+ unknownKeys: "strip"
2916
+ }));
2917
+ }
2918
+ passthrough() {
2919
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2920
+ unknownKeys: "passthrough"
2921
+ }));
2922
+ }
2923
+ // const AugmentFactory =
2924
+ // <Def extends ZodObjectDef>(def: Def) =>
2925
+ // <Augmentation extends ZodRawShape>(
2926
+ // augmentation: Augmentation
2927
+ // ): ZodObject<
2928
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2929
+ // Def["unknownKeys"],
2930
+ // Def["catchall"]
2931
+ // > => {
2932
+ // return new ZodObject({
2933
+ // ...def,
2934
+ // shape: () => ({
2935
+ // ...def.shape(),
2936
+ // ...augmentation,
2937
+ // }),
2938
+ // }) as any;
2939
+ // };
2940
+ extend(augmentation) {
2941
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2942
+ shape: () => __spreadValues(__spreadValues({}, this._def.shape()), augmentation)
2943
+ }));
2944
+ }
2945
+ /**
2946
+ * Prior to zod@1.0.12 there was a bug in the
2947
+ * inferred type of merged objects. Please
2948
+ * upgrade if you are experiencing issues.
2949
+ */
2950
+ merge(merging) {
2951
+ const merged = new _ZodObject({
2952
+ unknownKeys: merging._def.unknownKeys,
2953
+ catchall: merging._def.catchall,
2954
+ shape: () => __spreadValues(__spreadValues({}, this._def.shape()), merging._def.shape()),
2955
+ typeName: ZodFirstPartyTypeKind.ZodObject
2956
+ });
2957
+ return merged;
2958
+ }
2959
+ // merge<
2960
+ // Incoming extends AnyZodObject,
2961
+ // Augmentation extends Incoming["shape"],
2962
+ // NewOutput extends {
2963
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2964
+ // ? Augmentation[k]["_output"]
2965
+ // : k extends keyof Output
2966
+ // ? Output[k]
2967
+ // : never;
2968
+ // },
2969
+ // NewInput extends {
2970
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2971
+ // ? Augmentation[k]["_input"]
2972
+ // : k extends keyof Input
2973
+ // ? Input[k]
2974
+ // : never;
2975
+ // }
2976
+ // >(
2977
+ // merging: Incoming
2978
+ // ): ZodObject<
2979
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2980
+ // Incoming["_def"]["unknownKeys"],
2981
+ // Incoming["_def"]["catchall"],
2982
+ // NewOutput,
2983
+ // NewInput
2984
+ // > {
2985
+ // const merged: any = new ZodObject({
2986
+ // unknownKeys: merging._def.unknownKeys,
2987
+ // catchall: merging._def.catchall,
2988
+ // shape: () =>
2989
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2990
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2991
+ // }) as any;
2992
+ // return merged;
2993
+ // }
2994
+ setKey(key, schema) {
2995
+ return this.augment({ [key]: schema });
2996
+ }
2997
+ // merge<Incoming extends AnyZodObject>(
2998
+ // merging: Incoming
2999
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
3000
+ // ZodObject<
3001
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3002
+ // Incoming["_def"]["unknownKeys"],
3003
+ // Incoming["_def"]["catchall"]
3004
+ // > {
3005
+ // // const mergedShape = objectUtil.mergeShapes(
3006
+ // // this._def.shape(),
3007
+ // // merging._def.shape()
3008
+ // // );
3009
+ // const merged: any = new ZodObject({
3010
+ // unknownKeys: merging._def.unknownKeys,
3011
+ // catchall: merging._def.catchall,
3012
+ // shape: () =>
3013
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3014
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3015
+ // }) as any;
3016
+ // return merged;
3017
+ // }
3018
+ catchall(index) {
3019
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
3020
+ catchall: index
3021
+ }));
3022
+ }
3023
+ pick(mask) {
3024
+ const shape = {};
3025
+ for (const key of util.objectKeys(mask)) {
3026
+ if (mask[key] && this.shape[key]) {
3027
+ shape[key] = this.shape[key];
3028
+ }
3029
+ }
3030
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
3031
+ shape: () => shape
3032
+ }));
3033
+ }
3034
+ omit(mask) {
3035
+ const shape = {};
3036
+ for (const key of util.objectKeys(this.shape)) {
3037
+ if (!mask[key]) {
3038
+ shape[key] = this.shape[key];
3039
+ }
3040
+ }
3041
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
3042
+ shape: () => shape
3043
+ }));
3044
+ }
3045
+ /**
3046
+ * @deprecated
3047
+ */
3048
+ deepPartial() {
3049
+ return deepPartialify(this);
3050
+ }
3051
+ partial(mask) {
3052
+ const newShape = {};
3053
+ for (const key of util.objectKeys(this.shape)) {
3054
+ const fieldSchema = this.shape[key];
3055
+ if (mask && !mask[key]) {
3056
+ newShape[key] = fieldSchema;
3057
+ } else {
3058
+ newShape[key] = fieldSchema.optional();
3059
+ }
3060
+ }
3061
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
3062
+ shape: () => newShape
3063
+ }));
3064
+ }
3065
+ required(mask) {
3066
+ const newShape = {};
3067
+ for (const key of util.objectKeys(this.shape)) {
3068
+ if (mask && !mask[key]) {
3069
+ newShape[key] = this.shape[key];
3070
+ } else {
3071
+ const fieldSchema = this.shape[key];
3072
+ let newField = fieldSchema;
3073
+ while (newField instanceof ZodOptional) {
3074
+ newField = newField._def.innerType;
3075
+ }
3076
+ newShape[key] = newField;
3077
+ }
3078
+ }
3079
+ return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
3080
+ shape: () => newShape
3081
+ }));
3082
+ }
3083
+ keyof() {
3084
+ return createZodEnum(util.objectKeys(this.shape));
3085
+ }
3086
+ };
3087
+ ZodObject.create = (shape, params) => {
3088
+ return new ZodObject(__spreadValues({
3089
+ shape: () => shape,
3090
+ unknownKeys: "strip",
3091
+ catchall: ZodNever.create(),
3092
+ typeName: ZodFirstPartyTypeKind.ZodObject
3093
+ }, processCreateParams(params)));
3094
+ };
3095
+ ZodObject.strictCreate = (shape, params) => {
3096
+ return new ZodObject(__spreadValues({
3097
+ shape: () => shape,
3098
+ unknownKeys: "strict",
3099
+ catchall: ZodNever.create(),
3100
+ typeName: ZodFirstPartyTypeKind.ZodObject
3101
+ }, processCreateParams(params)));
3102
+ };
3103
+ ZodObject.lazycreate = (shape, params) => {
3104
+ return new ZodObject(__spreadValues({
3105
+ shape,
3106
+ unknownKeys: "strip",
3107
+ catchall: ZodNever.create(),
3108
+ typeName: ZodFirstPartyTypeKind.ZodObject
3109
+ }, processCreateParams(params)));
3110
+ };
3111
+ var ZodUnion = class extends ZodType {
3112
+ _parse(input) {
3113
+ const { ctx } = this._processInputParams(input);
3114
+ const options = this._def.options;
3115
+ function handleResults(results) {
3116
+ for (const result of results) {
3117
+ if (result.result.status === "valid") {
3118
+ return result.result;
3119
+ }
3120
+ }
3121
+ for (const result of results) {
3122
+ if (result.result.status === "dirty") {
3123
+ ctx.common.issues.push(...result.ctx.common.issues);
3124
+ return result.result;
3125
+ }
3126
+ }
3127
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
3128
+ addIssueToContext(ctx, {
3129
+ code: ZodIssueCode.invalid_union,
3130
+ unionErrors
3131
+ });
3132
+ return INVALID;
3133
+ }
3134
+ if (ctx.common.async) {
3135
+ return Promise.all(options.map((option) => __async(this, null, function* () {
3136
+ const childCtx = __spreadProps(__spreadValues({}, ctx), {
3137
+ common: __spreadProps(__spreadValues({}, ctx.common), {
3138
+ issues: []
3139
+ }),
3140
+ parent: null
3141
+ });
3142
+ return {
3143
+ result: yield option._parseAsync({
3144
+ data: ctx.data,
3145
+ path: ctx.path,
3146
+ parent: childCtx
3147
+ }),
3148
+ ctx: childCtx
3149
+ };
3150
+ }))).then(handleResults);
3151
+ } else {
3152
+ let dirty = void 0;
3153
+ const issues = [];
3154
+ for (const option of options) {
3155
+ const childCtx = __spreadProps(__spreadValues({}, ctx), {
3156
+ common: __spreadProps(__spreadValues({}, ctx.common), {
3157
+ issues: []
3158
+ }),
3159
+ parent: null
3160
+ });
3161
+ const result = option._parseSync({
3162
+ data: ctx.data,
3163
+ path: ctx.path,
3164
+ parent: childCtx
3165
+ });
3166
+ if (result.status === "valid") {
3167
+ return result;
3168
+ } else if (result.status === "dirty" && !dirty) {
3169
+ dirty = { result, ctx: childCtx };
3170
+ }
3171
+ if (childCtx.common.issues.length) {
3172
+ issues.push(childCtx.common.issues);
3173
+ }
3174
+ }
3175
+ if (dirty) {
3176
+ ctx.common.issues.push(...dirty.ctx.common.issues);
3177
+ return dirty.result;
3178
+ }
3179
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
3180
+ addIssueToContext(ctx, {
3181
+ code: ZodIssueCode.invalid_union,
3182
+ unionErrors
3183
+ });
3184
+ return INVALID;
3185
+ }
3186
+ }
3187
+ get options() {
3188
+ return this._def.options;
3189
+ }
3190
+ };
3191
+ ZodUnion.create = (types, params) => {
3192
+ return new ZodUnion(__spreadValues({
3193
+ options: types,
3194
+ typeName: ZodFirstPartyTypeKind.ZodUnion
3195
+ }, processCreateParams(params)));
3196
+ };
3197
+ var getDiscriminator = (type) => {
3198
+ if (type instanceof ZodLazy) {
3199
+ return getDiscriminator(type.schema);
3200
+ } else if (type instanceof ZodEffects) {
3201
+ return getDiscriminator(type.innerType());
3202
+ } else if (type instanceof ZodLiteral) {
3203
+ return [type.value];
3204
+ } else if (type instanceof ZodEnum) {
3205
+ return type.options;
3206
+ } else if (type instanceof ZodNativeEnum) {
3207
+ return util.objectValues(type.enum);
3208
+ } else if (type instanceof ZodDefault) {
3209
+ return getDiscriminator(type._def.innerType);
3210
+ } else if (type instanceof ZodUndefined) {
3211
+ return [void 0];
3212
+ } else if (type instanceof ZodNull) {
3213
+ return [null];
3214
+ } else if (type instanceof ZodOptional) {
3215
+ return [void 0, ...getDiscriminator(type.unwrap())];
3216
+ } else if (type instanceof ZodNullable) {
3217
+ return [null, ...getDiscriminator(type.unwrap())];
3218
+ } else if (type instanceof ZodBranded) {
3219
+ return getDiscriminator(type.unwrap());
3220
+ } else if (type instanceof ZodReadonly) {
3221
+ return getDiscriminator(type.unwrap());
3222
+ } else if (type instanceof ZodCatch) {
3223
+ return getDiscriminator(type._def.innerType);
3224
+ } else {
3225
+ return [];
3226
+ }
3227
+ };
3228
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
3229
+ _parse(input) {
3230
+ const { ctx } = this._processInputParams(input);
3231
+ if (ctx.parsedType !== ZodParsedType.object) {
3232
+ addIssueToContext(ctx, {
3233
+ code: ZodIssueCode.invalid_type,
3234
+ expected: ZodParsedType.object,
3235
+ received: ctx.parsedType
3236
+ });
3237
+ return INVALID;
3238
+ }
3239
+ const discriminator = this.discriminator;
3240
+ const discriminatorValue = ctx.data[discriminator];
3241
+ const option = this.optionsMap.get(discriminatorValue);
3242
+ if (!option) {
3243
+ addIssueToContext(ctx, {
3244
+ code: ZodIssueCode.invalid_union_discriminator,
3245
+ options: Array.from(this.optionsMap.keys()),
3246
+ path: [discriminator]
3247
+ });
3248
+ return INVALID;
3249
+ }
3250
+ if (ctx.common.async) {
3251
+ return option._parseAsync({
3252
+ data: ctx.data,
3253
+ path: ctx.path,
3254
+ parent: ctx
3255
+ });
3256
+ } else {
3257
+ return option._parseSync({
3258
+ data: ctx.data,
3259
+ path: ctx.path,
3260
+ parent: ctx
3261
+ });
3262
+ }
3263
+ }
3264
+ get discriminator() {
3265
+ return this._def.discriminator;
3266
+ }
3267
+ get options() {
3268
+ return this._def.options;
3269
+ }
3270
+ get optionsMap() {
3271
+ return this._def.optionsMap;
3272
+ }
3273
+ /**
3274
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3275
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3276
+ * have a different value for each object in the union.
3277
+ * @param discriminator the name of the discriminator property
3278
+ * @param types an array of object schemas
3279
+ * @param params
3280
+ */
3281
+ static create(discriminator, options, params) {
3282
+ const optionsMap = /* @__PURE__ */ new Map();
3283
+ for (const type of options) {
3284
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3285
+ if (!discriminatorValues.length) {
3286
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3287
+ }
3288
+ for (const value of discriminatorValues) {
3289
+ if (optionsMap.has(value)) {
3290
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3291
+ }
3292
+ optionsMap.set(value, type);
3293
+ }
3294
+ }
3295
+ return new _ZodDiscriminatedUnion(__spreadValues({
3296
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3297
+ discriminator,
3298
+ options,
3299
+ optionsMap
3300
+ }, processCreateParams(params)));
3301
+ }
3302
+ };
3303
+ function mergeValues(a, b) {
3304
+ const aType = getParsedType(a);
3305
+ const bType = getParsedType(b);
3306
+ if (a === b) {
3307
+ return { valid: true, data: a };
3308
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3309
+ const bKeys = util.objectKeys(b);
3310
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
3311
+ const newObj = __spreadValues(__spreadValues({}, a), b);
3312
+ for (const key of sharedKeys) {
3313
+ const sharedValue = mergeValues(a[key], b[key]);
3314
+ if (!sharedValue.valid) {
3315
+ return { valid: false };
3316
+ }
3317
+ newObj[key] = sharedValue.data;
3318
+ }
3319
+ return { valid: true, data: newObj };
3320
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
3321
+ if (a.length !== b.length) {
3322
+ return { valid: false };
3323
+ }
3324
+ const newArray = [];
3325
+ for (let index = 0; index < a.length; index++) {
3326
+ const itemA = a[index];
3327
+ const itemB = b[index];
3328
+ const sharedValue = mergeValues(itemA, itemB);
3329
+ if (!sharedValue.valid) {
3330
+ return { valid: false };
3331
+ }
3332
+ newArray.push(sharedValue.data);
3333
+ }
3334
+ return { valid: true, data: newArray };
3335
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
3336
+ return { valid: true, data: a };
3337
+ } else {
3338
+ return { valid: false };
3339
+ }
3340
+ }
3341
+ var ZodIntersection = class extends ZodType {
3342
+ _parse(input) {
3343
+ const { status, ctx } = this._processInputParams(input);
3344
+ const handleParsed = (parsedLeft, parsedRight) => {
3345
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
3346
+ return INVALID;
3347
+ }
3348
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
3349
+ if (!merged.valid) {
3350
+ addIssueToContext(ctx, {
3351
+ code: ZodIssueCode.invalid_intersection_types
3352
+ });
3353
+ return INVALID;
3354
+ }
3355
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
3356
+ status.dirty();
3357
+ }
3358
+ return { status: status.value, value: merged.data };
3359
+ };
3360
+ if (ctx.common.async) {
3361
+ return Promise.all([
3362
+ this._def.left._parseAsync({
3363
+ data: ctx.data,
3364
+ path: ctx.path,
3365
+ parent: ctx
3366
+ }),
3367
+ this._def.right._parseAsync({
3368
+ data: ctx.data,
3369
+ path: ctx.path,
3370
+ parent: ctx
3371
+ })
3372
+ ]).then(([left, right]) => handleParsed(left, right));
3373
+ } else {
3374
+ return handleParsed(this._def.left._parseSync({
3375
+ data: ctx.data,
3376
+ path: ctx.path,
3377
+ parent: ctx
3378
+ }), this._def.right._parseSync({
3379
+ data: ctx.data,
3380
+ path: ctx.path,
3381
+ parent: ctx
3382
+ }));
3383
+ }
3384
+ }
3385
+ };
3386
+ ZodIntersection.create = (left, right, params) => {
3387
+ return new ZodIntersection(__spreadValues({
3388
+ left,
3389
+ right,
3390
+ typeName: ZodFirstPartyTypeKind.ZodIntersection
3391
+ }, processCreateParams(params)));
3392
+ };
3393
+ var ZodTuple = class _ZodTuple extends ZodType {
3394
+ _parse(input) {
3395
+ const { status, ctx } = this._processInputParams(input);
3396
+ if (ctx.parsedType !== ZodParsedType.array) {
3397
+ addIssueToContext(ctx, {
3398
+ code: ZodIssueCode.invalid_type,
3399
+ expected: ZodParsedType.array,
3400
+ received: ctx.parsedType
3401
+ });
3402
+ return INVALID;
3403
+ }
3404
+ if (ctx.data.length < this._def.items.length) {
3405
+ addIssueToContext(ctx, {
3406
+ code: ZodIssueCode.too_small,
3407
+ minimum: this._def.items.length,
3408
+ inclusive: true,
3409
+ exact: false,
3410
+ type: "array"
3411
+ });
3412
+ return INVALID;
3413
+ }
3414
+ const rest = this._def.rest;
3415
+ if (!rest && ctx.data.length > this._def.items.length) {
3416
+ addIssueToContext(ctx, {
3417
+ code: ZodIssueCode.too_big,
3418
+ maximum: this._def.items.length,
3419
+ inclusive: true,
3420
+ exact: false,
3421
+ type: "array"
3422
+ });
3423
+ status.dirty();
3424
+ }
3425
+ const items = [...ctx.data].map((item, itemIndex) => {
3426
+ const schema = this._def.items[itemIndex] || this._def.rest;
3427
+ if (!schema)
3428
+ return null;
3429
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
3430
+ }).filter((x) => !!x);
3431
+ if (ctx.common.async) {
3432
+ return Promise.all(items).then((results) => {
3433
+ return ParseStatus.mergeArray(status, results);
3434
+ });
3435
+ } else {
3436
+ return ParseStatus.mergeArray(status, items);
3437
+ }
3438
+ }
3439
+ get items() {
3440
+ return this._def.items;
3441
+ }
3442
+ rest(rest) {
3443
+ return new _ZodTuple(__spreadProps(__spreadValues({}, this._def), {
3444
+ rest
3445
+ }));
3446
+ }
3447
+ };
3448
+ ZodTuple.create = (schemas, params) => {
3449
+ if (!Array.isArray(schemas)) {
3450
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3451
+ }
3452
+ return new ZodTuple(__spreadValues({
3453
+ items: schemas,
3454
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
3455
+ rest: null
3456
+ }, processCreateParams(params)));
3457
+ };
3458
+ var ZodRecord = class _ZodRecord extends ZodType {
3459
+ get keySchema() {
3460
+ return this._def.keyType;
3461
+ }
3462
+ get valueSchema() {
3463
+ return this._def.valueType;
3464
+ }
3465
+ _parse(input) {
3466
+ const { status, ctx } = this._processInputParams(input);
3467
+ if (ctx.parsedType !== ZodParsedType.object) {
3468
+ addIssueToContext(ctx, {
3469
+ code: ZodIssueCode.invalid_type,
3470
+ expected: ZodParsedType.object,
3471
+ received: ctx.parsedType
3472
+ });
3473
+ return INVALID;
3474
+ }
3475
+ const pairs = [];
3476
+ const keyType = this._def.keyType;
3477
+ const valueType = this._def.valueType;
3478
+ for (const key in ctx.data) {
3479
+ pairs.push({
3480
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3481
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3482
+ alwaysSet: key in ctx.data
3483
+ });
3484
+ }
3485
+ if (ctx.common.async) {
3486
+ return ParseStatus.mergeObjectAsync(status, pairs);
3487
+ } else {
3488
+ return ParseStatus.mergeObjectSync(status, pairs);
3489
+ }
3490
+ }
3491
+ get element() {
3492
+ return this._def.valueType;
3493
+ }
3494
+ static create(first, second, third) {
3495
+ if (second instanceof ZodType) {
3496
+ return new _ZodRecord(__spreadValues({
3497
+ keyType: first,
3498
+ valueType: second,
3499
+ typeName: ZodFirstPartyTypeKind.ZodRecord
3500
+ }, processCreateParams(third)));
3501
+ }
3502
+ return new _ZodRecord(__spreadValues({
3503
+ keyType: ZodString.create(),
3504
+ valueType: first,
3505
+ typeName: ZodFirstPartyTypeKind.ZodRecord
3506
+ }, processCreateParams(second)));
3507
+ }
3508
+ };
3509
+ var ZodMap = class extends ZodType {
3510
+ get keySchema() {
3511
+ return this._def.keyType;
3512
+ }
3513
+ get valueSchema() {
3514
+ return this._def.valueType;
3515
+ }
3516
+ _parse(input) {
3517
+ const { status, ctx } = this._processInputParams(input);
3518
+ if (ctx.parsedType !== ZodParsedType.map) {
3519
+ addIssueToContext(ctx, {
3520
+ code: ZodIssueCode.invalid_type,
3521
+ expected: ZodParsedType.map,
3522
+ received: ctx.parsedType
3523
+ });
3524
+ return INVALID;
3525
+ }
3526
+ const keyType = this._def.keyType;
3527
+ const valueType = this._def.valueType;
3528
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
3529
+ return {
3530
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
3531
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
3532
+ };
3533
+ });
3534
+ if (ctx.common.async) {
3535
+ const finalMap = /* @__PURE__ */ new Map();
3536
+ return Promise.resolve().then(() => __async(this, null, function* () {
3537
+ for (const pair of pairs) {
3538
+ const key = yield pair.key;
3539
+ const value = yield pair.value;
3540
+ if (key.status === "aborted" || value.status === "aborted") {
3541
+ return INVALID;
3542
+ }
3543
+ if (key.status === "dirty" || value.status === "dirty") {
3544
+ status.dirty();
3545
+ }
3546
+ finalMap.set(key.value, value.value);
3547
+ }
3548
+ return { status: status.value, value: finalMap };
3549
+ }));
3550
+ } else {
3551
+ const finalMap = /* @__PURE__ */ new Map();
3552
+ for (const pair of pairs) {
3553
+ const key = pair.key;
3554
+ const value = pair.value;
3555
+ if (key.status === "aborted" || value.status === "aborted") {
3556
+ return INVALID;
3557
+ }
3558
+ if (key.status === "dirty" || value.status === "dirty") {
3559
+ status.dirty();
3560
+ }
3561
+ finalMap.set(key.value, value.value);
3562
+ }
3563
+ return { status: status.value, value: finalMap };
3564
+ }
3565
+ }
3566
+ };
3567
+ ZodMap.create = (keyType, valueType, params) => {
3568
+ return new ZodMap(__spreadValues({
3569
+ valueType,
3570
+ keyType,
3571
+ typeName: ZodFirstPartyTypeKind.ZodMap
3572
+ }, processCreateParams(params)));
3573
+ };
3574
+ var ZodSet = class _ZodSet extends ZodType {
3575
+ _parse(input) {
3576
+ const { status, ctx } = this._processInputParams(input);
3577
+ if (ctx.parsedType !== ZodParsedType.set) {
3578
+ addIssueToContext(ctx, {
3579
+ code: ZodIssueCode.invalid_type,
3580
+ expected: ZodParsedType.set,
3581
+ received: ctx.parsedType
3582
+ });
3583
+ return INVALID;
3584
+ }
3585
+ const def = this._def;
3586
+ if (def.minSize !== null) {
3587
+ if (ctx.data.size < def.minSize.value) {
3588
+ addIssueToContext(ctx, {
3589
+ code: ZodIssueCode.too_small,
3590
+ minimum: def.minSize.value,
3591
+ type: "set",
3592
+ inclusive: true,
3593
+ exact: false,
3594
+ message: def.minSize.message
3595
+ });
3596
+ status.dirty();
3597
+ }
3598
+ }
3599
+ if (def.maxSize !== null) {
3600
+ if (ctx.data.size > def.maxSize.value) {
3601
+ addIssueToContext(ctx, {
3602
+ code: ZodIssueCode.too_big,
3603
+ maximum: def.maxSize.value,
3604
+ type: "set",
3605
+ inclusive: true,
3606
+ exact: false,
3607
+ message: def.maxSize.message
3608
+ });
3609
+ status.dirty();
3610
+ }
3611
+ }
3612
+ const valueType = this._def.valueType;
3613
+ function finalizeSet(elements2) {
3614
+ const parsedSet = /* @__PURE__ */ new Set();
3615
+ for (const element of elements2) {
3616
+ if (element.status === "aborted")
3617
+ return INVALID;
3618
+ if (element.status === "dirty")
3619
+ status.dirty();
3620
+ parsedSet.add(element.value);
3621
+ }
3622
+ return { status: status.value, value: parsedSet };
3623
+ }
3624
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3625
+ if (ctx.common.async) {
3626
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
3627
+ } else {
3628
+ return finalizeSet(elements);
3629
+ }
3630
+ }
3631
+ min(minSize, message) {
3632
+ return new _ZodSet(__spreadProps(__spreadValues({}, this._def), {
3633
+ minSize: { value: minSize, message: errorUtil.toString(message) }
3634
+ }));
3635
+ }
3636
+ max(maxSize, message) {
3637
+ return new _ZodSet(__spreadProps(__spreadValues({}, this._def), {
3638
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3639
+ }));
3640
+ }
3641
+ size(size, message) {
3642
+ return this.min(size, message).max(size, message);
3643
+ }
3644
+ nonempty(message) {
3645
+ return this.min(1, message);
3646
+ }
3647
+ };
3648
+ ZodSet.create = (valueType, params) => {
3649
+ return new ZodSet(__spreadValues({
3650
+ valueType,
3651
+ minSize: null,
3652
+ maxSize: null,
3653
+ typeName: ZodFirstPartyTypeKind.ZodSet
3654
+ }, processCreateParams(params)));
3655
+ };
3656
+ var ZodFunction = class _ZodFunction extends ZodType {
3657
+ constructor() {
3658
+ super(...arguments);
3659
+ this.validate = this.implement;
3660
+ }
3661
+ _parse(input) {
3662
+ const { ctx } = this._processInputParams(input);
3663
+ if (ctx.parsedType !== ZodParsedType.function) {
3664
+ addIssueToContext(ctx, {
3665
+ code: ZodIssueCode.invalid_type,
3666
+ expected: ZodParsedType.function,
3667
+ received: ctx.parsedType
3668
+ });
3669
+ return INVALID;
3670
+ }
3671
+ function makeArgsIssue(args, error) {
3672
+ return makeIssue({
3673
+ data: args,
3674
+ path: ctx.path,
3675
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3676
+ issueData: {
3677
+ code: ZodIssueCode.invalid_arguments,
3678
+ argumentsError: error
3679
+ }
3680
+ });
3681
+ }
3682
+ function makeReturnsIssue(returns, error) {
3683
+ return makeIssue({
3684
+ data: returns,
3685
+ path: ctx.path,
3686
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3687
+ issueData: {
3688
+ code: ZodIssueCode.invalid_return_type,
3689
+ returnTypeError: error
3690
+ }
3691
+ });
3692
+ }
3693
+ const params = { errorMap: ctx.common.contextualErrorMap };
3694
+ const fn = ctx.data;
3695
+ if (this._def.returns instanceof ZodPromise) {
3696
+ const me = this;
3697
+ return OK(function(...args) {
3698
+ return __async(this, null, function* () {
3699
+ const error = new ZodError([]);
3700
+ const parsedArgs = yield me._def.args.parseAsync(args, params).catch((e) => {
3701
+ error.addIssue(makeArgsIssue(args, e));
3702
+ throw error;
3703
+ });
3704
+ const result = yield Reflect.apply(fn, this, parsedArgs);
3705
+ const parsedReturns = yield me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3706
+ error.addIssue(makeReturnsIssue(result, e));
3707
+ throw error;
3708
+ });
3709
+ return parsedReturns;
3710
+ });
3711
+ });
3712
+ } else {
3713
+ const me = this;
3714
+ return OK(function(...args) {
3715
+ const parsedArgs = me._def.args.safeParse(args, params);
3716
+ if (!parsedArgs.success) {
3717
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3718
+ }
3719
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3720
+ const parsedReturns = me._def.returns.safeParse(result, params);
3721
+ if (!parsedReturns.success) {
3722
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3723
+ }
3724
+ return parsedReturns.data;
3725
+ });
3726
+ }
3727
+ }
3728
+ parameters() {
3729
+ return this._def.args;
3730
+ }
3731
+ returnType() {
3732
+ return this._def.returns;
3733
+ }
3734
+ args(...items) {
3735
+ return new _ZodFunction(__spreadProps(__spreadValues({}, this._def), {
3736
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3737
+ }));
3738
+ }
3739
+ returns(returnType) {
3740
+ return new _ZodFunction(__spreadProps(__spreadValues({}, this._def), {
3741
+ returns: returnType
3742
+ }));
3743
+ }
3744
+ implement(func) {
3745
+ const validatedFunc = this.parse(func);
3746
+ return validatedFunc;
3747
+ }
3748
+ strictImplement(func) {
3749
+ const validatedFunc = this.parse(func);
3750
+ return validatedFunc;
3751
+ }
3752
+ static create(args, returns, params) {
3753
+ return new _ZodFunction(__spreadValues({
3754
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3755
+ returns: returns || ZodUnknown.create(),
3756
+ typeName: ZodFirstPartyTypeKind.ZodFunction
3757
+ }, processCreateParams(params)));
3758
+ }
3759
+ };
3760
+ var ZodLazy = class extends ZodType {
3761
+ get schema() {
3762
+ return this._def.getter();
3763
+ }
3764
+ _parse(input) {
3765
+ const { ctx } = this._processInputParams(input);
3766
+ const lazySchema = this._def.getter();
3767
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3768
+ }
3769
+ };
3770
+ ZodLazy.create = (getter, params) => {
3771
+ return new ZodLazy(__spreadValues({
3772
+ getter,
3773
+ typeName: ZodFirstPartyTypeKind.ZodLazy
3774
+ }, processCreateParams(params)));
3775
+ };
3776
+ var ZodLiteral = class extends ZodType {
3777
+ _parse(input) {
3778
+ if (input.data !== this._def.value) {
3779
+ const ctx = this._getOrReturnCtx(input);
3780
+ addIssueToContext(ctx, {
3781
+ received: ctx.data,
3782
+ code: ZodIssueCode.invalid_literal,
3783
+ expected: this._def.value
3784
+ });
3785
+ return INVALID;
3786
+ }
3787
+ return { status: "valid", value: input.data };
3788
+ }
3789
+ get value() {
3790
+ return this._def.value;
3791
+ }
3792
+ };
3793
+ ZodLiteral.create = (value, params) => {
3794
+ return new ZodLiteral(__spreadValues({
3795
+ value,
3796
+ typeName: ZodFirstPartyTypeKind.ZodLiteral
3797
+ }, processCreateParams(params)));
3798
+ };
3799
+ function createZodEnum(values, params) {
3800
+ return new ZodEnum(__spreadValues({
3801
+ values,
3802
+ typeName: ZodFirstPartyTypeKind.ZodEnum
3803
+ }, processCreateParams(params)));
3804
+ }
3805
+ var ZodEnum = class _ZodEnum extends ZodType {
3806
+ _parse(input) {
3807
+ if (typeof input.data !== "string") {
3808
+ const ctx = this._getOrReturnCtx(input);
3809
+ const expectedValues = this._def.values;
3810
+ addIssueToContext(ctx, {
3811
+ expected: util.joinValues(expectedValues),
3812
+ received: ctx.parsedType,
3813
+ code: ZodIssueCode.invalid_type
3814
+ });
3815
+ return INVALID;
3816
+ }
3817
+ if (!this._cache) {
3818
+ this._cache = new Set(this._def.values);
3819
+ }
3820
+ if (!this._cache.has(input.data)) {
3821
+ const ctx = this._getOrReturnCtx(input);
3822
+ const expectedValues = this._def.values;
3823
+ addIssueToContext(ctx, {
3824
+ received: ctx.data,
3825
+ code: ZodIssueCode.invalid_enum_value,
3826
+ options: expectedValues
3827
+ });
3828
+ return INVALID;
3829
+ }
3830
+ return OK(input.data);
3831
+ }
3832
+ get options() {
3833
+ return this._def.values;
3834
+ }
3835
+ get enum() {
3836
+ const enumValues = {};
3837
+ for (const val of this._def.values) {
3838
+ enumValues[val] = val;
3839
+ }
3840
+ return enumValues;
3841
+ }
3842
+ get Values() {
3843
+ const enumValues = {};
3844
+ for (const val of this._def.values) {
3845
+ enumValues[val] = val;
3846
+ }
3847
+ return enumValues;
3848
+ }
3849
+ get Enum() {
3850
+ const enumValues = {};
3851
+ for (const val of this._def.values) {
3852
+ enumValues[val] = val;
3853
+ }
3854
+ return enumValues;
3855
+ }
3856
+ extract(values, newDef = this._def) {
3857
+ return _ZodEnum.create(values, __spreadValues(__spreadValues({}, this._def), newDef));
3858
+ }
3859
+ exclude(values, newDef = this._def) {
3860
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), __spreadValues(__spreadValues({}, this._def), newDef));
3861
+ }
3862
+ };
3863
+ ZodEnum.create = createZodEnum;
3864
+ var ZodNativeEnum = class extends ZodType {
3865
+ _parse(input) {
3866
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3867
+ const ctx = this._getOrReturnCtx(input);
3868
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3869
+ const expectedValues = util.objectValues(nativeEnumValues);
3870
+ addIssueToContext(ctx, {
3871
+ expected: util.joinValues(expectedValues),
3872
+ received: ctx.parsedType,
3873
+ code: ZodIssueCode.invalid_type
3874
+ });
3875
+ return INVALID;
3876
+ }
3877
+ if (!this._cache) {
3878
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
3879
+ }
3880
+ if (!this._cache.has(input.data)) {
3881
+ const expectedValues = util.objectValues(nativeEnumValues);
3882
+ addIssueToContext(ctx, {
3883
+ received: ctx.data,
3884
+ code: ZodIssueCode.invalid_enum_value,
3885
+ options: expectedValues
3886
+ });
3887
+ return INVALID;
3888
+ }
3889
+ return OK(input.data);
3890
+ }
3891
+ get enum() {
3892
+ return this._def.values;
3893
+ }
3894
+ };
3895
+ ZodNativeEnum.create = (values, params) => {
3896
+ return new ZodNativeEnum(__spreadValues({
3897
+ values,
3898
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum
3899
+ }, processCreateParams(params)));
3900
+ };
3901
+ var ZodPromise = class extends ZodType {
3902
+ unwrap() {
3903
+ return this._def.type;
3904
+ }
3905
+ _parse(input) {
3906
+ const { ctx } = this._processInputParams(input);
3907
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3908
+ addIssueToContext(ctx, {
3909
+ code: ZodIssueCode.invalid_type,
3910
+ expected: ZodParsedType.promise,
3911
+ received: ctx.parsedType
3912
+ });
3913
+ return INVALID;
3914
+ }
3915
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3916
+ return OK(promisified.then((data) => {
3917
+ return this._def.type.parseAsync(data, {
3918
+ path: ctx.path,
3919
+ errorMap: ctx.common.contextualErrorMap
3920
+ });
3921
+ }));
3922
+ }
3923
+ };
3924
+ ZodPromise.create = (schema, params) => {
3925
+ return new ZodPromise(__spreadValues({
3926
+ type: schema,
3927
+ typeName: ZodFirstPartyTypeKind.ZodPromise
3928
+ }, processCreateParams(params)));
3929
+ };
3930
+ var ZodEffects = class extends ZodType {
3931
+ innerType() {
3932
+ return this._def.schema;
3933
+ }
3934
+ sourceType() {
3935
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3936
+ }
3937
+ _parse(input) {
3938
+ const { status, ctx } = this._processInputParams(input);
3939
+ const effect = this._def.effect || null;
3940
+ const checkCtx = {
3941
+ addIssue: (arg) => {
3942
+ addIssueToContext(ctx, arg);
3943
+ if (arg.fatal) {
3944
+ status.abort();
3945
+ } else {
3946
+ status.dirty();
3947
+ }
3948
+ },
3949
+ get path() {
3950
+ return ctx.path;
3951
+ }
3952
+ };
3953
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3954
+ if (effect.type === "preprocess") {
3955
+ const processed = effect.transform(ctx.data, checkCtx);
3956
+ if (ctx.common.async) {
3957
+ return Promise.resolve(processed).then((processed2) => __async(this, null, function* () {
3958
+ if (status.value === "aborted")
3959
+ return INVALID;
3960
+ const result = yield this._def.schema._parseAsync({
3961
+ data: processed2,
3962
+ path: ctx.path,
3963
+ parent: ctx
3964
+ });
3965
+ if (result.status === "aborted")
3966
+ return INVALID;
3967
+ if (result.status === "dirty")
3968
+ return DIRTY(result.value);
3969
+ if (status.value === "dirty")
3970
+ return DIRTY(result.value);
3971
+ return result;
3972
+ }));
3973
+ } else {
3974
+ if (status.value === "aborted")
3975
+ return INVALID;
3976
+ const result = this._def.schema._parseSync({
3977
+ data: processed,
3978
+ path: ctx.path,
3979
+ parent: ctx
3980
+ });
3981
+ if (result.status === "aborted")
3982
+ return INVALID;
3983
+ if (result.status === "dirty")
3984
+ return DIRTY(result.value);
3985
+ if (status.value === "dirty")
3986
+ return DIRTY(result.value);
3987
+ return result;
3988
+ }
3989
+ }
3990
+ if (effect.type === "refinement") {
3991
+ const executeRefinement = (acc) => {
3992
+ const result = effect.refinement(acc, checkCtx);
3993
+ if (ctx.common.async) {
3994
+ return Promise.resolve(result);
3995
+ }
3996
+ if (result instanceof Promise) {
3997
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3998
+ }
3999
+ return acc;
4000
+ };
4001
+ if (ctx.common.async === false) {
4002
+ const inner = this._def.schema._parseSync({
4003
+ data: ctx.data,
4004
+ path: ctx.path,
4005
+ parent: ctx
4006
+ });
4007
+ if (inner.status === "aborted")
4008
+ return INVALID;
4009
+ if (inner.status === "dirty")
4010
+ status.dirty();
4011
+ executeRefinement(inner.value);
4012
+ return { status: status.value, value: inner.value };
4013
+ } else {
4014
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
4015
+ if (inner.status === "aborted")
4016
+ return INVALID;
4017
+ if (inner.status === "dirty")
4018
+ status.dirty();
4019
+ return executeRefinement(inner.value).then(() => {
4020
+ return { status: status.value, value: inner.value };
4021
+ });
4022
+ });
4023
+ }
4024
+ }
4025
+ if (effect.type === "transform") {
4026
+ if (ctx.common.async === false) {
4027
+ const base = this._def.schema._parseSync({
4028
+ data: ctx.data,
4029
+ path: ctx.path,
4030
+ parent: ctx
4031
+ });
4032
+ if (!isValid(base))
4033
+ return INVALID;
4034
+ const result = effect.transform(base.value, checkCtx);
4035
+ if (result instanceof Promise) {
4036
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
4037
+ }
4038
+ return { status: status.value, value: result };
4039
+ } else {
4040
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4041
+ if (!isValid(base))
4042
+ return INVALID;
4043
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
4044
+ status: status.value,
4045
+ value: result
4046
+ }));
4047
+ });
4048
+ }
4049
+ }
4050
+ util.assertNever(effect);
4051
+ }
4052
+ };
4053
+ ZodEffects.create = (schema, effect, params) => {
4054
+ return new ZodEffects(__spreadValues({
4055
+ schema,
4056
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
4057
+ effect
4058
+ }, processCreateParams(params)));
4059
+ };
4060
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
4061
+ return new ZodEffects(__spreadValues({
4062
+ schema,
4063
+ effect: { type: "preprocess", transform: preprocess },
4064
+ typeName: ZodFirstPartyTypeKind.ZodEffects
4065
+ }, processCreateParams(params)));
4066
+ };
4067
+ var ZodOptional = class extends ZodType {
4068
+ _parse(input) {
4069
+ const parsedType = this._getType(input);
4070
+ if (parsedType === ZodParsedType.undefined) {
4071
+ return OK(void 0);
4072
+ }
4073
+ return this._def.innerType._parse(input);
4074
+ }
4075
+ unwrap() {
4076
+ return this._def.innerType;
4077
+ }
4078
+ };
4079
+ ZodOptional.create = (type, params) => {
4080
+ return new ZodOptional(__spreadValues({
4081
+ innerType: type,
4082
+ typeName: ZodFirstPartyTypeKind.ZodOptional
4083
+ }, processCreateParams(params)));
4084
+ };
4085
+ var ZodNullable = class extends ZodType {
4086
+ _parse(input) {
4087
+ const parsedType = this._getType(input);
4088
+ if (parsedType === ZodParsedType.null) {
4089
+ return OK(null);
4090
+ }
4091
+ return this._def.innerType._parse(input);
4092
+ }
4093
+ unwrap() {
4094
+ return this._def.innerType;
4095
+ }
4096
+ };
4097
+ ZodNullable.create = (type, params) => {
4098
+ return new ZodNullable(__spreadValues({
4099
+ innerType: type,
4100
+ typeName: ZodFirstPartyTypeKind.ZodNullable
4101
+ }, processCreateParams(params)));
4102
+ };
4103
+ var ZodDefault = class extends ZodType {
4104
+ _parse(input) {
4105
+ const { ctx } = this._processInputParams(input);
4106
+ let data = ctx.data;
4107
+ if (ctx.parsedType === ZodParsedType.undefined) {
4108
+ data = this._def.defaultValue();
4109
+ }
4110
+ return this._def.innerType._parse({
4111
+ data,
4112
+ path: ctx.path,
4113
+ parent: ctx
4114
+ });
4115
+ }
4116
+ removeDefault() {
4117
+ return this._def.innerType;
4118
+ }
4119
+ };
4120
+ ZodDefault.create = (type, params) => {
4121
+ return new ZodDefault(__spreadValues({
4122
+ innerType: type,
4123
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
4124
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default
4125
+ }, processCreateParams(params)));
4126
+ };
4127
+ var ZodCatch = class extends ZodType {
4128
+ _parse(input) {
4129
+ const { ctx } = this._processInputParams(input);
4130
+ const newCtx = __spreadProps(__spreadValues({}, ctx), {
4131
+ common: __spreadProps(__spreadValues({}, ctx.common), {
4132
+ issues: []
4133
+ })
4134
+ });
4135
+ const result = this._def.innerType._parse({
4136
+ data: newCtx.data,
4137
+ path: newCtx.path,
4138
+ parent: __spreadValues({}, newCtx)
4139
+ });
4140
+ if (isAsync(result)) {
4141
+ return result.then((result2) => {
4142
+ return {
4143
+ status: "valid",
4144
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
4145
+ get error() {
4146
+ return new ZodError(newCtx.common.issues);
4147
+ },
4148
+ input: newCtx.data
4149
+ })
4150
+ };
4151
+ });
4152
+ } else {
4153
+ return {
4154
+ status: "valid",
4155
+ value: result.status === "valid" ? result.value : this._def.catchValue({
4156
+ get error() {
4157
+ return new ZodError(newCtx.common.issues);
4158
+ },
4159
+ input: newCtx.data
4160
+ })
4161
+ };
4162
+ }
4163
+ }
4164
+ removeCatch() {
4165
+ return this._def.innerType;
4166
+ }
4167
+ };
4168
+ ZodCatch.create = (type, params) => {
4169
+ return new ZodCatch(__spreadValues({
4170
+ innerType: type,
4171
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
4172
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch
4173
+ }, processCreateParams(params)));
4174
+ };
4175
+ var ZodNaN = class extends ZodType {
4176
+ _parse(input) {
4177
+ const parsedType = this._getType(input);
4178
+ if (parsedType !== ZodParsedType.nan) {
4179
+ const ctx = this._getOrReturnCtx(input);
4180
+ addIssueToContext(ctx, {
4181
+ code: ZodIssueCode.invalid_type,
4182
+ expected: ZodParsedType.nan,
4183
+ received: ctx.parsedType
4184
+ });
4185
+ return INVALID;
4186
+ }
4187
+ return { status: "valid", value: input.data };
4188
+ }
4189
+ };
4190
+ ZodNaN.create = (params) => {
4191
+ return new ZodNaN(__spreadValues({
4192
+ typeName: ZodFirstPartyTypeKind.ZodNaN
4193
+ }, processCreateParams(params)));
4194
+ };
4195
+ var BRAND = /* @__PURE__ */ Symbol("zod_brand");
4196
+ var ZodBranded = class extends ZodType {
4197
+ _parse(input) {
4198
+ const { ctx } = this._processInputParams(input);
4199
+ const data = ctx.data;
4200
+ return this._def.type._parse({
4201
+ data,
4202
+ path: ctx.path,
4203
+ parent: ctx
4204
+ });
4205
+ }
4206
+ unwrap() {
4207
+ return this._def.type;
4208
+ }
4209
+ };
4210
+ var ZodPipeline = class _ZodPipeline extends ZodType {
4211
+ _parse(input) {
4212
+ const { status, ctx } = this._processInputParams(input);
4213
+ if (ctx.common.async) {
4214
+ const handleAsync = () => __async(this, null, function* () {
4215
+ const inResult = yield this._def.in._parseAsync({
4216
+ data: ctx.data,
4217
+ path: ctx.path,
4218
+ parent: ctx
4219
+ });
4220
+ if (inResult.status === "aborted")
4221
+ return INVALID;
4222
+ if (inResult.status === "dirty") {
4223
+ status.dirty();
4224
+ return DIRTY(inResult.value);
4225
+ } else {
4226
+ return this._def.out._parseAsync({
4227
+ data: inResult.value,
4228
+ path: ctx.path,
4229
+ parent: ctx
4230
+ });
4231
+ }
4232
+ });
4233
+ return handleAsync();
4234
+ } else {
4235
+ const inResult = this._def.in._parseSync({
4236
+ data: ctx.data,
4237
+ path: ctx.path,
4238
+ parent: ctx
4239
+ });
4240
+ if (inResult.status === "aborted")
4241
+ return INVALID;
4242
+ if (inResult.status === "dirty") {
4243
+ status.dirty();
4244
+ return {
4245
+ status: "dirty",
4246
+ value: inResult.value
4247
+ };
4248
+ } else {
4249
+ return this._def.out._parseSync({
4250
+ data: inResult.value,
4251
+ path: ctx.path,
4252
+ parent: ctx
4253
+ });
4254
+ }
4255
+ }
4256
+ }
4257
+ static create(a, b) {
4258
+ return new _ZodPipeline({
4259
+ in: a,
4260
+ out: b,
4261
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
4262
+ });
4263
+ }
4264
+ };
4265
+ var ZodReadonly = class extends ZodType {
4266
+ _parse(input) {
4267
+ const result = this._def.innerType._parse(input);
4268
+ const freeze = (data) => {
4269
+ if (isValid(data)) {
4270
+ data.value = Object.freeze(data.value);
4271
+ }
4272
+ return data;
4273
+ };
4274
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
4275
+ }
4276
+ unwrap() {
4277
+ return this._def.innerType;
4278
+ }
4279
+ };
4280
+ ZodReadonly.create = (type, params) => {
4281
+ return new ZodReadonly(__spreadValues({
4282
+ innerType: type,
4283
+ typeName: ZodFirstPartyTypeKind.ZodReadonly
4284
+ }, processCreateParams(params)));
4285
+ };
4286
+ function cleanParams(params, data) {
4287
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
4288
+ const p2 = typeof p === "string" ? { message: p } : p;
4289
+ return p2;
4290
+ }
4291
+ function custom(check, _params = {}, fatal) {
4292
+ if (check)
4293
+ return ZodAny.create().superRefine((data, ctx) => {
4294
+ var _a, _b;
4295
+ const r = check(data);
4296
+ if (r instanceof Promise) {
4297
+ return r.then((r2) => {
4298
+ var _a2, _b2;
4299
+ if (!r2) {
4300
+ const params = cleanParams(_params, data);
4301
+ const _fatal = (_b2 = (_a2 = params.fatal) != null ? _a2 : fatal) != null ? _b2 : true;
4302
+ ctx.addIssue(__spreadProps(__spreadValues({ code: "custom" }, params), { fatal: _fatal }));
4303
+ }
4304
+ });
4305
+ }
4306
+ if (!r) {
4307
+ const params = cleanParams(_params, data);
4308
+ const _fatal = (_b = (_a = params.fatal) != null ? _a : fatal) != null ? _b : true;
4309
+ ctx.addIssue(__spreadProps(__spreadValues({ code: "custom" }, params), { fatal: _fatal }));
4310
+ }
4311
+ return;
4312
+ });
4313
+ return ZodAny.create();
4314
+ }
4315
+ var late = {
4316
+ object: ZodObject.lazycreate
4317
+ };
4318
+ var ZodFirstPartyTypeKind;
4319
+ (function(ZodFirstPartyTypeKind2) {
4320
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
4321
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
4322
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
4323
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
4324
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
4325
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
4326
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
4327
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
4328
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
4329
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
4330
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
4331
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
4332
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
4333
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
4334
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
4335
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
4336
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4337
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
4338
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
4339
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
4340
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
4341
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
4342
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
4343
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
4344
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
4345
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
4346
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
4347
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
4348
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
4349
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
4350
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
4351
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
4352
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4353
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4354
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4355
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
4356
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4357
+ var instanceOfType = (cls, params = {
4358
+ message: `Input not instance of ${cls.name}`
4359
+ }) => custom((data) => data instanceof cls, params);
4360
+ var stringType = ZodString.create;
4361
+ var numberType = ZodNumber.create;
4362
+ var nanType = ZodNaN.create;
4363
+ var bigIntType = ZodBigInt.create;
4364
+ var booleanType = ZodBoolean.create;
4365
+ var dateType = ZodDate.create;
4366
+ var symbolType = ZodSymbol.create;
4367
+ var undefinedType = ZodUndefined.create;
4368
+ var nullType = ZodNull.create;
4369
+ var anyType = ZodAny.create;
4370
+ var unknownType = ZodUnknown.create;
4371
+ var neverType = ZodNever.create;
4372
+ var voidType = ZodVoid.create;
4373
+ var arrayType = ZodArray.create;
4374
+ var objectType = ZodObject.create;
4375
+ var strictObjectType = ZodObject.strictCreate;
4376
+ var unionType = ZodUnion.create;
4377
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
4378
+ var intersectionType = ZodIntersection.create;
4379
+ var tupleType = ZodTuple.create;
4380
+ var recordType = ZodRecord.create;
4381
+ var mapType = ZodMap.create;
4382
+ var setType = ZodSet.create;
4383
+ var functionType = ZodFunction.create;
4384
+ var lazyType = ZodLazy.create;
4385
+ var literalType = ZodLiteral.create;
4386
+ var enumType = ZodEnum.create;
4387
+ var nativeEnumType = ZodNativeEnum.create;
4388
+ var promiseType = ZodPromise.create;
4389
+ var effectsType = ZodEffects.create;
4390
+ var optionalType = ZodOptional.create;
4391
+ var nullableType = ZodNullable.create;
4392
+ var preprocessType = ZodEffects.createWithPreprocess;
4393
+ var pipelineType = ZodPipeline.create;
4394
+ var ostring = () => stringType().optional();
4395
+ var onumber = () => numberType().optional();
4396
+ var oboolean = () => booleanType().optional();
4397
+ var coerce = {
4398
+ string: ((arg) => ZodString.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
4399
+ number: ((arg) => ZodNumber.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
4400
+ boolean: ((arg) => ZodBoolean.create(__spreadProps(__spreadValues({}, arg), {
4401
+ coerce: true
4402
+ }))),
4403
+ bigint: ((arg) => ZodBigInt.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
4404
+ date: ((arg) => ZodDate.create(__spreadProps(__spreadValues({}, arg), { coerce: true })))
4405
+ };
4406
+ var NEVER = INVALID;
4407
+
4408
+ // controllers/entity/list-entities.controller.ts
4409
+ external_exports.object({
4410
+ limit: external_exports.string().optional(),
4411
+ lastKey: external_exports.string().optional(),
4412
+ query: external_exports.string().trim().optional(),
4413
+ start: external_exports.string().optional(),
4414
+ end: external_exports.string().optional()
4415
+ });
4416
+ external_exports.object({
4417
+ group: external_exports.string().optional(),
4418
+ query: external_exports.string().optional(),
4419
+ start: external_exports.string().optional(),
4420
+ end: external_exports.string().optional(),
4421
+ limit: external_exports.string().optional(),
4422
+ lastKey: external_exports.string().optional()
4423
+ });
4424
+
4425
+ declare class EntityServiceLifeCycle {
4426
+ private EntityConfig;
4427
+ private publishEvent;
4428
+ private eventUtils;
4429
+ constructor(EntityConfig: any, publishEvent: typeof publishEvent, eventUtils: EventUtils);
4430
+ afterCreateEntityHook<T extends Entity$2>(entity: Entity$1<T>, entityPayload?: Record<string, unknown>, accountId?: string | string[]): Promise<void>;
4431
+ }
4432
+
4433
+ declare class EntityService {
4434
+ private EntityConfig;
4435
+ private EmailAuthEnabledEntities;
4436
+ private entityRepository;
4437
+ private publishEvent;
4438
+ private entityServiceLifeCycle;
4439
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, EmailAuthEnabledEntities: Entity$2[], entityRepository: EntityRepository, publishEvent: typeof publishEvent, entityServiceLifeCycle: EntityServiceLifeCycle);
4440
+ createEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, options, }: {
4441
+ entityType: T;
4442
+ entityPayload: EntitySchemaMap[T] | Record<string, any>;
4443
+ entityId?: string;
4444
+ accountId?: string | string[];
4445
+ options?: {
4446
+ createAndUpdateDatetime?: string;
4447
+ mutualId?: string;
4448
+ };
4449
+ }) => Promise<Entity<T>>;
4450
+ updateEntity: <T extends Entity$2>({ entityType, entityId, entityPayload, accountId, }: {
4451
+ entityType: T;
4452
+ entityId: string;
4453
+ entityPayload: Partial<EntitySchemaMap[T]>;
4454
+ accountId?: string | string[];
4455
+ }) => Promise<Entity<T>>;
4456
+ deleteEntity: <T extends Entity$2>({ entityType, entityId, accountId, }: {
4457
+ entityType: T;
4458
+ entityId: string;
4459
+ accountId?: string | string[];
4460
+ }) => Promise<void>;
4461
+ }
4462
+
4463
+ declare class CreateEntityController {
4464
+ private entityService;
4465
+ constructor(entityService: EntityService);
4466
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4467
+ [x: string]: hono_utils_types.JSONValue;
4468
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4469
+ }
4470
+
4471
+ declare class DeleteEntityController {
4472
+ private readonly entityService;
4473
+ constructor(entityService: EntityService);
4474
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4475
+ message: string;
4476
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4477
+ }
4478
+
4479
+ declare class GetEntityByUniqueFieldValueController {
4480
+ private entityRepository;
4481
+ constructor(entityRepository: EntityRepository);
4482
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4483
+ [x: string]: hono_utils_types.JSONValue;
4484
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4485
+ }
4486
+
4487
+ declare class GetEntityController {
4488
+ private entityRepository;
4489
+ constructor(entityRepository: EntityRepository);
4490
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4491
+ [x: string]: hono_utils_types.JSONValue;
4492
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4493
+ }
4494
+
4495
+ declare class ListEntitiesController {
4496
+ private entityRepository;
4497
+ constructor(entityRepository: EntityRepository);
4498
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4499
+ data: {
4500
+ [x: string]: hono_utils_types.JSONValue;
4501
+ }[];
4502
+ totalCount: number | undefined;
4503
+ filteredCount: number | undefined;
4504
+ lastKey: string | undefined;
4505
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4506
+ }
4507
+
4508
+ declare class UpdateEntityController {
4509
+ private entityService;
4510
+ constructor(entityService: EntityService);
4511
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4512
+ [x: string]: hono_utils_types.JSONValue;
4513
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4514
+ }
4515
+
4516
+ declare class UpsertEntityController {
4517
+ private EntityConfig;
4518
+ private entityRepository;
4519
+ private publishEvent;
4520
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, entityRepository: EntityRepository, publishEvent: typeof publishEvent);
4521
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4522
+ [x: string]: hono_utils_types.JSONValue;
4523
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4524
+ }
4525
+
4526
+ declare class MutualService {
4527
+ private entityRepository;
4528
+ private mutualRepository;
4529
+ private publishEvent;
4530
+ private ddbUtils;
4531
+ private entityServiceLifeCycle;
4532
+ constructor(entityRepository: EntityRepository, mutualRepository: MutualRepository, publishEvent: typeof publishEvent, ddbUtils: DbUtils, entityServiceLifeCycle: EntityServiceLifeCycle);
4533
+ createMutual: <B extends Entity$2, T extends Entity$2, A extends Entity$2>({ byEntityType, byEntityId, entityType, entityId, mutualPayload, accountId, options, }: {
4534
+ byEntityType: B;
4535
+ byEntityId: string;
4536
+ entityType: T;
4537
+ entityId: string;
4538
+ mutualPayload?: Record<string, unknown>;
4539
+ accountId?: string | string[];
4540
+ options?: {
4541
+ asEntity?: A;
4542
+ ensureEntityStrongConsistentWrite?: boolean;
4543
+ mutualId?: string;
4544
+ skipMutualCreation?: boolean;
4545
+ createAndUpdateDatetime?: Date;
4546
+ ConditionExpression?: string;
4547
+ ExpressionAttributeNames?: Record<string, string>;
4548
+ ExpressionAttributeValues?: Record<string, AttributeValue>;
4549
+ };
4550
+ }) => Promise<{
4551
+ mutual: Mutual<B, T, Record<string, any>>;
4552
+ eventPayload: {
4553
+ byEntityType: B;
4554
+ byEntityId: string;
4555
+ entityType: T;
4556
+ entityId: string;
4557
+ parsedMutualPayload: Record<string, any>;
4558
+ accountId: string | string[] | undefined;
4559
+ publishedAt: string;
4560
+ };
4561
+ }>;
4562
+ updateMutual: <B extends Entity$2, T extends Entity$2, M extends Record<string, unknown>>({ byEntityType, byEntityId, entityType, entityId, mutualPayload, accountId, options, }: {
4563
+ byEntityType: B;
4564
+ byEntityId: string;
4565
+ entityType: T;
4566
+ entityId: string;
4567
+ mutualPayload: M;
4568
+ accountId?: string | string[];
4569
+ options?: {
4570
+ maxObjectUpdateLevel?: number;
4571
+ returnUpdatedValue?: boolean;
4572
+ };
4573
+ }) => Promise<Mutual<B, T, Record<string, unknown>> | undefined>;
4574
+ deleteMutual: ({ byEntityType, byEntityId, entityType, entityId, accountId, }: {
4575
+ byEntityType: Entity$2;
4576
+ byEntityId: string;
4577
+ entityType: Entity$2;
4578
+ entityId: string;
4579
+ accountId?: string | string[];
4580
+ }) => Promise<Mutual<Entity$2, Entity$2, Record<string, unknown>>>;
4581
+ }
4582
+
4583
+ declare class CreateMutualController {
4584
+ private mutualService;
4585
+ constructor(mutualService: MutualService);
4586
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4587
+ [x: string]: hono_utils_types.JSONValue;
4588
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4589
+ }
4590
+
4591
+ declare class DeleteMutualController {
4592
+ private mutualService;
4593
+ constructor(mutualService: MutualService);
4594
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4595
+ [x: string]: hono_utils_types.JSONValue;
4596
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4597
+ }
4598
+
4599
+ declare class GetMutualController {
4600
+ private associateRepository;
4601
+ constructor(associateRepository: MutualRepository);
4602
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4603
+ [x: string]: hono_utils_types.JSONValue;
4604
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4605
+ }
4606
+
4607
+ declare class ListEntitiesByEntityController {
4608
+ private associateRepository;
4609
+ constructor(associateRepository: MutualRepository);
4610
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4611
+ entities: {
4612
+ [x: string]: hono_utils_types.JSONValue;
4613
+ }[];
4614
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4615
+ }
4616
+
4617
+ declare class UpdateMutualController {
4618
+ private mutualService;
4619
+ constructor(mutualService: MutualService);
4620
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4621
+ [x: string]: hono_utils_types.JSONValue;
4622
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4623
+ }
4624
+
4625
+ declare class ListTagsController {
4626
+ private tagRepository;
4627
+ constructor(tagRepository: TagRepository);
4628
+ controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4629
+ entities: {
4630
+ [x: string]: hono_utils_types.JSONValue;
4631
+ }[];
4632
+ totalCount: number | undefined;
4633
+ lastKey: string | undefined;
4634
+ }, hono_utils_http_status.ContentfulStatusCode, "json">>;
4635
+ }
4636
+
4637
+ declare class DependencyContainer {
4638
+ config: {
4639
+ EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
4640
+ AllowedEntityTypes: Entity$2[];
4641
+ EmailAuthEnabledEntities: Entity$2[];
4642
+ tableName?: string;
4643
+ };
4644
+ private _instanceCache;
4645
+ private _publishEvent;
4646
+ private _tableName;
4647
+ constructor(config: {
4648
+ EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
4649
+ AllowedEntityTypes: Entity$2[];
4650
+ EmailAuthEnabledEntities: Entity$2[];
4651
+ tableName?: string;
4652
+ });
4653
+ createCachedInstance<T extends new (...args: any[]) => any>(ClassRef: T, ...args: ConstructorParameters<T>): InstanceType<T>;
4654
+ get coreTable(): string;
4655
+ get publishEvent(): typeof publishEvent;
4656
+ get dynamodbClient(): DynamoDB;
4657
+ get dbUtils(): DbUtils;
4658
+ get eventUtils(): EventUtils;
4659
+ get entityRepository(): EntityRepository;
4660
+ get mutualRepository(): MutualRepository;
4661
+ get entityServiceLifeCycle(): EntityServiceLifeCycle;
4662
+ get entityService(): EntityService;
4663
+ get mutualService(): MutualService;
4664
+ get tagRepository(): TagRepository;
4665
+ get getEntityController(): GetEntityController;
4666
+ get getEntityByUniqueFieldController(): GetEntityByUniqueFieldValueController;
4667
+ get listEntitiesController(): ListEntitiesController;
4668
+ get createEntityController(): CreateEntityController;
4669
+ get upsertEntityController(): UpsertEntityController;
4670
+ get updateEntityController(): UpdateEntityController;
4671
+ get deleteEntityController(): DeleteEntityController;
4672
+ get listEntitiesByEntityController(): ListEntitiesByEntityController;
4673
+ get getMutualController(): GetMutualController;
4674
+ get createMutualController(): CreateMutualController;
4675
+ get updateMutualController(): UpdateMutualController;
4676
+ get deleteMutualController(): DeleteMutualController;
4677
+ get listTagsController(): ListTagsController;
4678
+ }
4679
+
4680
+ declare const setupCommonRoutes: (container: DependencyContainer) => Hono;
4681
+
4682
+ declare class StandardError extends Error {
4683
+ code: string;
4684
+ lastError?: object | null;
4685
+ context?: string | null;
4686
+ constructor(errorCode: string, message: string, lastError?: any, context?: object | string | null);
4687
+ toJSON(): {
4688
+ code: string;
4689
+ message: string;
4690
+ };
4691
+ }
4692
+ declare const StandardErrorCode: {
4693
+ readonly CONDITIONAL_CHECK_FAILED: "CONDITIONAL_CHECK_FAILED";
4694
+ readonly EMAIL_EXISTS: "EMAIL_EXISTS";
4695
+ readonly ENTITY_ID_IS_UNDEFINED: "ENTITY_ID_IS_UNDEFINED";
4696
+ readonly ENTITY_IS_UNDEFINED: "ENTITY_IS_UNDEFINED";
4697
+ readonly ENTITY_NOT_FOUND: "ENTITY_NOT_FOUND";
4698
+ readonly INVALID_ENTITY_TYPE: "INVALID_ENTITY_TYPE";
4699
+ readonly INVALID_MUTUAL: "INVALID_MUTUAL";
4700
+ readonly INVALID_QUERY: "INVALID_QUERY";
4701
+ readonly INVALID_UNIQUE_VALUE_TYPE: "INVALID_UNIQUE_VALUE_TYPE";
4702
+ readonly MUTUAL_EXISTS: "MUTUAL_EXISTS";
4703
+ readonly MUTUAL_IS_UNDEFINED: "MUTUAL_IS_UNDEFINED";
4704
+ readonly MUTUAL_LOCK_CONFLICT: "MUTUAL_LOCK_CONFLICT";
4705
+ readonly MUTUAL_NOT_FOUND: "MUTUAL_NOT_FOUND";
4706
+ readonly MUTUAL_PROCESSOR_ERROR: "MUTUAL_PROCESSOR_ERROR";
4707
+ readonly REPLICATION_ERROR: "REPLICATION_ERROR";
4708
+ readonly RETRYABLE_MUTUAL_LOCK_CONFLICT: "RETRYABLE_MUTUAL_LOCK_CONFLICT";
4709
+ readonly TAG_IS_UNDEFINED: "TAG_IS_UNDEFINED";
4710
+ readonly TRANSACTION_FAILED: "TRANSACTION_FAILED";
4711
+ readonly UNIQUE_VALUE_EXISTS: "UNIQUE_VALUE_EXISTS";
4712
+ };
4713
+ type StandardErrorCode = typeof StandardErrorCode[keyof typeof StandardErrorCode];
4714
+
4715
+ type AppHandleArgs = {
4716
+ routes?: (container: DependencyContainer) => Hono | Hono;
4717
+ };
4718
+ declare const appHandler: (container: DependencyContainer) => ({ routes }: AppHandleArgs) => <L extends hono_aws_lambda.LambdaEvent>(event: L, lambdaContext?: hono_aws_lambda.LambdaContext) => Promise<hono_aws_lambda.APIGatewayProxyResult & (L extends {
4719
+ multiValueHeaders: Record<string, string[]>;
4720
+ } ? {
4721
+ headers?: undefined;
4722
+ multiValueHeaders: Record<string, string[]>;
4723
+ } : {
4724
+ headers: Record<string, string>;
4725
+ multiValueHeaders?: undefined;
4726
+ })>;
4727
+
4728
+ declare const handler$4: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
4729
+ batchItemFailures: SQSBatchItemFailure[];
4730
+ }>;
4731
+
4732
+ declare const handler$3: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
4733
+ batchItemFailures: SQSBatchItemFailure[];
4734
+ }>;
4735
+
4736
+ declare const handler$2: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
4737
+ batchItemFailures: SQSBatchItemFailure[];
4738
+ }>;
4739
+
4740
+ declare const handler$1: (container: DependencyContainer) => (event: {
4741
+ Records: _Record[];
4742
+ }) => Promise<{
4743
+ batchItemFailures: DynamoDBBatchItemFailure[];
4744
+ }>;
4745
+
4746
+ declare const handler: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
4747
+ batchItemFailures: SQSBatchItemFailure[];
4748
+ }>;
4749
+
17
4750
  declare class CoreFactory {
18
4751
  private config;
19
4752
  setupCommonRoutes: ReturnType<typeof setupCommonRoutes>;
20
- mutualProcessor: ReturnType<typeof mutualProcessor>;
21
- replicationProcessor: ReturnType<typeof replicationProcessor>;
22
- createEntityProcessor: ReturnType<typeof createEntityProcessor>;
23
- prejoinProcessor: ReturnType<typeof prejoinProcessor>;
24
- tagProcessor: ReturnType<typeof tagProcessor>;
4753
+ mutualProcessor: ReturnType<typeof handler$3>;
4754
+ replicationProcessor: ReturnType<typeof handler$1>;
4755
+ createEntityProcessor: ReturnType<typeof handler$4>;
4756
+ prejoinProcessor: ReturnType<typeof handler$2>;
4757
+ tagProcessor: ReturnType<typeof handler>;
25
4758
  appHandler: ReturnType<typeof appHandler>;
26
4759
  dependencyContainer: DependencyContainer;
27
4760
  constructor(config: {
28
- EntityConfig: Record<EntityType, ReturnType<typeof createEntityConfig>>;
29
- AllowedEntityTypes: EntityType[];
30
- EmailAuthEnabledEntities: EntityType[];
4761
+ EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>;
4762
+ AllowedEntityTypes: Entity$2[];
4763
+ EmailAuthEnabledEntities: Entity$2[];
31
4764
  });
32
4765
  }
33
- export { setupCommonRoutes, Entity, EntityRepository, EntityService, Mutual, MutualService, MutualRepository, TagRepository, PROJECTION_EXPRESSION, createEntityProcessor, mutualProcessor, prejoinProcessor, replicationProcessor, tagProcessor, appHandler, DependencyContainer, StandardError, StandardErrorCode, };
34
- export default CoreFactory;
35
- //# sourceMappingURL=index.d.ts.map
4766
+
4767
+ export { DependencyContainer, Entity$1 as Entity, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, appHandler, handler$4 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, setupCommonRoutes, handler as tagProcessor };