@redmix/api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -0
  3. package/dist/auth/index.d.ts +51 -0
  4. package/dist/auth/index.d.ts.map +1 -0
  5. package/dist/auth/index.js +129 -0
  6. package/dist/auth/parseJWT.d.ts +6 -0
  7. package/dist/auth/parseJWT.d.ts.map +1 -0
  8. package/dist/auth/parseJWT.js +57 -0
  9. package/dist/auth/verifiers/base64Sha1Verifier.d.ts +19 -0
  10. package/dist/auth/verifiers/base64Sha1Verifier.d.ts.map +1 -0
  11. package/dist/auth/verifiers/base64Sha1Verifier.js +77 -0
  12. package/dist/auth/verifiers/base64Sha256Verifier.d.ts +19 -0
  13. package/dist/auth/verifiers/base64Sha256Verifier.d.ts.map +1 -0
  14. package/dist/auth/verifiers/base64Sha256Verifier.js +77 -0
  15. package/dist/auth/verifiers/common.d.ts +104 -0
  16. package/dist/auth/verifiers/common.d.ts.map +1 -0
  17. package/dist/auth/verifiers/common.js +99 -0
  18. package/dist/auth/verifiers/index.d.ts +8 -0
  19. package/dist/auth/verifiers/index.d.ts.map +1 -0
  20. package/dist/auth/verifiers/index.js +38 -0
  21. package/dist/auth/verifiers/jwtVerifier.d.ts +26 -0
  22. package/dist/auth/verifiers/jwtVerifier.d.ts.map +1 -0
  23. package/dist/auth/verifiers/jwtVerifier.js +86 -0
  24. package/dist/auth/verifiers/secretKeyVerifier.d.ts +14 -0
  25. package/dist/auth/verifiers/secretKeyVerifier.d.ts.map +1 -0
  26. package/dist/auth/verifiers/secretKeyVerifier.js +40 -0
  27. package/dist/auth/verifiers/sha1Verifier.d.ts +25 -0
  28. package/dist/auth/verifiers/sha1Verifier.d.ts.map +1 -0
  29. package/dist/auth/verifiers/sha1Verifier.js +85 -0
  30. package/dist/auth/verifiers/sha256Verifier.d.ts +25 -0
  31. package/dist/auth/verifiers/sha256Verifier.d.ts.map +1 -0
  32. package/dist/auth/verifiers/sha256Verifier.js +85 -0
  33. package/dist/auth/verifiers/skipVerifier.d.ts +13 -0
  34. package/dist/auth/verifiers/skipVerifier.d.ts.map +1 -0
  35. package/dist/auth/verifiers/skipVerifier.js +37 -0
  36. package/dist/auth/verifiers/timestampSchemeVerifier.d.ts +16 -0
  37. package/dist/auth/verifiers/timestampSchemeVerifier.d.ts.map +1 -0
  38. package/dist/auth/verifiers/timestampSchemeVerifier.js +81 -0
  39. package/dist/bins/redwood.d.ts +3 -0
  40. package/dist/bins/redwood.d.ts.map +1 -0
  41. package/dist/bins/redwood.js +33 -0
  42. package/dist/bins/rwfw.d.ts +3 -0
  43. package/dist/bins/rwfw.d.ts.map +1 -0
  44. package/dist/bins/rwfw.js +33 -0
  45. package/dist/bins/tsc.d.ts +3 -0
  46. package/dist/bins/tsc.d.ts.map +1 -0
  47. package/dist/bins/tsc.js +30 -0
  48. package/dist/cache/clients/BaseClient.d.ts +11 -0
  49. package/dist/cache/clients/BaseClient.d.ts.map +1 -0
  50. package/dist/cache/clients/BaseClient.js +27 -0
  51. package/dist/cache/clients/InMemoryClient.d.ts +31 -0
  52. package/dist/cache/clients/InMemoryClient.d.ts.map +1 -0
  53. package/dist/cache/clients/InMemoryClient.js +100 -0
  54. package/dist/cache/clients/MemcachedClient.d.ts +16 -0
  55. package/dist/cache/clients/MemcachedClient.d.ts.map +1 -0
  56. package/dist/cache/clients/MemcachedClient.js +75 -0
  57. package/dist/cache/clients/RedisClient.d.ts +20 -0
  58. package/dist/cache/clients/RedisClient.d.ts.map +1 -0
  59. package/dist/cache/clients/RedisClient.js +79 -0
  60. package/dist/cache/errors.d.ts +4 -0
  61. package/dist/cache/errors.d.ts.map +1 -0
  62. package/dist/cache/errors.js +33 -0
  63. package/dist/cache/index.d.ts +35 -0
  64. package/dist/cache/index.d.ts.map +1 -0
  65. package/dist/cache/index.js +171 -0
  66. package/dist/cors.d.ts +16 -0
  67. package/dist/cors.d.ts.map +1 -0
  68. package/dist/cors.js +93 -0
  69. package/dist/errors.d.ts +5 -0
  70. package/dist/errors.d.ts.map +1 -0
  71. package/dist/errors.js +38 -0
  72. package/dist/event.d.ts +3 -0
  73. package/dist/event.d.ts.map +1 -0
  74. package/dist/event.js +34 -0
  75. package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts +4 -0
  76. package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.d.ts.map +1 -0
  77. package/dist/functions/fixtures/apiGatewayProxyEvent.fixture.js +72 -0
  78. package/dist/index.d.ts +11 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +49 -0
  81. package/dist/logger/index.d.ts +179 -0
  82. package/dist/logger/index.d.ts.map +1 -0
  83. package/dist/logger/index.js +195 -0
  84. package/dist/transforms.d.ts +35 -0
  85. package/dist/transforms.d.ts.map +1 -0
  86. package/dist/transforms.js +98 -0
  87. package/dist/types.d.ts +25 -0
  88. package/dist/types.d.ts.map +1 -0
  89. package/dist/types.js +16 -0
  90. package/dist/validations/errors.d.ts +101 -0
  91. package/dist/validations/errors.d.ts.map +1 -0
  92. package/dist/validations/errors.js +298 -0
  93. package/dist/validations/validations.d.ts +222 -0
  94. package/dist/validations/validations.d.ts.map +1 -0
  95. package/dist/validations/validations.js +351 -0
  96. package/dist/webhooks/index.d.ts +76 -0
  97. package/dist/webhooks/index.d.ts.map +1 -0
  98. package/dist/webhooks/index.js +107 -0
  99. package/package.json +95 -0
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var errors_exports = {};
30
+ __export(errors_exports, {
31
+ AbsenceValidationError: () => AbsenceValidationError,
32
+ AcceptanceValidationError: () => AcceptanceValidationError,
33
+ BetweenLengthValidationError: () => BetweenLengthValidationError,
34
+ CustomValidationError: () => CustomValidationError,
35
+ EmailValidationError: () => EmailValidationError,
36
+ EqualLengthValidationError: () => EqualLengthValidationError,
37
+ EqualNumericalityValidationError: () => EqualNumericalityValidationError,
38
+ EvenNumericalityValidationError: () => EvenNumericalityValidationError,
39
+ ExclusionValidationError: () => ExclusionValidationError,
40
+ FormatValidationError: () => FormatValidationError,
41
+ GreaterThanNumericalityValidationError: () => GreaterThanNumericalityValidationError,
42
+ GreaterThanOrEqualNumericalityValidationError: () => GreaterThanOrEqualNumericalityValidationError,
43
+ InclusionValidationError: () => InclusionValidationError,
44
+ IntegerNumericalityValidationError: () => IntegerNumericalityValidationError,
45
+ LessThanNumericalityValidationError: () => LessThanNumericalityValidationError,
46
+ LessThanOrEqualNumericalityValidationError: () => LessThanOrEqualNumericalityValidationError,
47
+ MaxLengthValidationError: () => MaxLengthValidationError,
48
+ MinLengthValidationError: () => MinLengthValidationError,
49
+ NegativeNumericalityValidationError: () => NegativeNumericalityValidationError,
50
+ OddNumericalityValidationError: () => OddNumericalityValidationError,
51
+ OtherThanNumericalityValidationError: () => OtherThanNumericalityValidationError,
52
+ PositiveNumericalityValidationError: () => PositiveNumericalityValidationError,
53
+ PresenceValidationError: () => PresenceValidationError,
54
+ ServiceValidationError: () => ServiceValidationError,
55
+ TypeNumericalityValidationError: () => TypeNumericalityValidationError,
56
+ UniquenessValidationError: () => UniquenessValidationError
57
+ });
58
+ module.exports = __toCommonJS(errors_exports);
59
+ var import_humanize_string = __toESM(require("humanize-string"));
60
+ var import_title_case = require("title-case");
61
+ var import_errors = require("../errors");
62
+ class ServiceValidationError extends import_errors.RedwoodError {
63
+ constructor(message, substitutions = {}) {
64
+ let errorMessage = message;
65
+ let extensions = {};
66
+ for (const [key, value] of Object.entries(substitutions)) {
67
+ errorMessage = errorMessage.replaceAll(
68
+ `\${${key}}`,
69
+ (0, import_title_case.titleCase)((0, import_humanize_string.default)(String(value)))
70
+ );
71
+ extensions = {
72
+ code: "BAD_USER_INPUT",
73
+ properties: {
74
+ messages: {
75
+ [String(value)]: [errorMessage]
76
+ }
77
+ }
78
+ };
79
+ }
80
+ super(errorMessage, extensions);
81
+ this.name = "ServiceValidationError";
82
+ Object.setPrototypeOf(this, ServiceValidationError.prototype);
83
+ }
84
+ }
85
+ class AbsenceValidationError extends ServiceValidationError {
86
+ constructor(name, message = "${name} is not absent", substitutions = {}) {
87
+ super(message, Object.assign(substitutions, { name }));
88
+ this.name = "AbsenceValidationError";
89
+ Object.setPrototypeOf(this, AbsenceValidationError.prototype);
90
+ }
91
+ }
92
+ class AcceptanceValidationError extends ServiceValidationError {
93
+ constructor(name, message = "${name} must be accepted", substitutions = {}) {
94
+ super(message, Object.assign(substitutions, { name }));
95
+ this.name = "AcceptanceValidationError";
96
+ Object.setPrototypeOf(this, AcceptanceValidationError.prototype);
97
+ }
98
+ }
99
+ class EmailValidationError extends ServiceValidationError {
100
+ constructor(name, message = "${name} must be formatted like an email address", substitutions = {}) {
101
+ super(message, Object.assign(substitutions, { name }));
102
+ this.name = "EmailValidationError";
103
+ Object.setPrototypeOf(this, EmailValidationError.prototype);
104
+ }
105
+ }
106
+ class ExclusionValidationError extends ServiceValidationError {
107
+ constructor(name, message = "${name} is reserved", substitutions = {}) {
108
+ super(message, Object.assign(substitutions, { name }));
109
+ this.name = "ExclusionValidationError";
110
+ Object.setPrototypeOf(this, ExclusionValidationError.prototype);
111
+ }
112
+ }
113
+ class FormatValidationError extends ServiceValidationError {
114
+ constructor(name, message = "${name} is not formatted correctly", substitutions = {}) {
115
+ super(message, Object.assign(substitutions, { name }));
116
+ this.name = "FormatValidationError";
117
+ Object.setPrototypeOf(this, FormatValidationError.prototype);
118
+ }
119
+ }
120
+ class InclusionValidationError extends ServiceValidationError {
121
+ constructor(name, message = "${name} is reserved", substitutions = {}) {
122
+ super(message, Object.assign(substitutions, { name }));
123
+ this.name = "InclusionValidationError";
124
+ Object.setPrototypeOf(this, InclusionValidationError.prototype);
125
+ }
126
+ }
127
+ class MinLengthValidationError extends ServiceValidationError {
128
+ constructor(name, message = "${name} must have at least ${min} characters", substitutions = {}) {
129
+ super(message, Object.assign(substitutions, { name }));
130
+ this.name = "MinLengthValidationError";
131
+ Object.setPrototypeOf(this, MinLengthValidationError.prototype);
132
+ }
133
+ }
134
+ class MaxLengthValidationError extends ServiceValidationError {
135
+ constructor(name, message = "${name} must have no more than ${max} characters", substitutions = {}) {
136
+ super(message, Object.assign(substitutions, { name }));
137
+ this.name = "MaxLengthValidationError";
138
+ Object.setPrototypeOf(this, MaxLengthValidationError.prototype);
139
+ }
140
+ }
141
+ class EqualLengthValidationError extends ServiceValidationError {
142
+ constructor(name, message = "${name} must have exactly ${equal} characters", substitutions = {}) {
143
+ super(message, Object.assign(substitutions, { name }));
144
+ this.name = "EqualLengthValidationError";
145
+ Object.setPrototypeOf(this, EqualLengthValidationError.prototype);
146
+ }
147
+ }
148
+ class BetweenLengthValidationError extends ServiceValidationError {
149
+ constructor(name, message = "${name} must be between ${min} and ${max} characters", substitutions = {}) {
150
+ super(message, Object.assign(substitutions, { name }));
151
+ this.name = "BetweenLengthValidationError";
152
+ Object.setPrototypeOf(this, BetweenLengthValidationError.prototype);
153
+ }
154
+ }
155
+ class PresenceValidationError extends ServiceValidationError {
156
+ constructor(name, message = "${name} must be present", substitutions = {}) {
157
+ super(message, Object.assign(substitutions, { name }));
158
+ this.name = "PresenceValidationError";
159
+ Object.setPrototypeOf(this, PresenceValidationError.prototype);
160
+ }
161
+ }
162
+ class TypeNumericalityValidationError extends ServiceValidationError {
163
+ constructor(name, message = "${name} must by a number", substitutions = {}) {
164
+ super(message, Object.assign(substitutions, { name }));
165
+ this.name = "TypeNumericalityValidationError";
166
+ Object.setPrototypeOf(this, TypeNumericalityValidationError.prototype);
167
+ }
168
+ }
169
+ class IntegerNumericalityValidationError extends ServiceValidationError {
170
+ constructor(name, message = "${name} must be an integer", substitutions = {}) {
171
+ super(message, Object.assign(substitutions, { name }));
172
+ this.name = "IntegerNumericalityValidationError";
173
+ Object.setPrototypeOf(this, IntegerNumericalityValidationError.prototype);
174
+ }
175
+ }
176
+ class LessThanNumericalityValidationError extends ServiceValidationError {
177
+ constructor(name, message = "${name} must be less than ${lessThan}", substitutions = {}) {
178
+ super(message, Object.assign(substitutions, { name }));
179
+ this.name = "LessThanNumericalityValidationError";
180
+ Object.setPrototypeOf(this, LessThanNumericalityValidationError.prototype);
181
+ }
182
+ }
183
+ class LessThanOrEqualNumericalityValidationError extends ServiceValidationError {
184
+ constructor(name, message = "${name} must be less than or equal to ${lessThanOrEqual}", substitutions = {}) {
185
+ super(message, Object.assign(substitutions, { name }));
186
+ this.name = "LessThanOrEqualNumericalityValidationError";
187
+ Object.setPrototypeOf(
188
+ this,
189
+ LessThanOrEqualNumericalityValidationError.prototype
190
+ );
191
+ }
192
+ }
193
+ class GreaterThanNumericalityValidationError extends ServiceValidationError {
194
+ constructor(name, message = "${name} must be greater than ${greaterThan}", substitutions = {}) {
195
+ super(message, Object.assign(substitutions, { name }));
196
+ this.name = "GreaterThanNumericalityValidationError";
197
+ Object.setPrototypeOf(
198
+ this,
199
+ GreaterThanNumericalityValidationError.prototype
200
+ );
201
+ }
202
+ }
203
+ class GreaterThanOrEqualNumericalityValidationError extends ServiceValidationError {
204
+ constructor(name, message = "${name} must be greater than or equal to ${greaterThanOrEqual}", substitutions = {}) {
205
+ super(message, Object.assign(substitutions, { name }));
206
+ this.name = "GreaterThanOrEqualNumericalityValidationError";
207
+ Object.setPrototypeOf(
208
+ this,
209
+ GreaterThanOrEqualNumericalityValidationError.prototype
210
+ );
211
+ }
212
+ }
213
+ class EqualNumericalityValidationError extends ServiceValidationError {
214
+ constructor(name, message = "${name} must equal ${equal}", substitutions = {}) {
215
+ super(message, Object.assign(substitutions, { name }));
216
+ this.name = "EqualNumericalityValidationError";
217
+ Object.setPrototypeOf(this, EqualNumericalityValidationError.prototype);
218
+ }
219
+ }
220
+ class OtherThanNumericalityValidationError extends ServiceValidationError {
221
+ constructor(name, message = "${name} must not equal ${otherThan}", substitutions = {}) {
222
+ super(message, Object.assign(substitutions, { name }));
223
+ this.name = "OtherThanNumericalityValidationError";
224
+ Object.setPrototypeOf(this, OtherThanNumericalityValidationError.prototype);
225
+ }
226
+ }
227
+ class EvenNumericalityValidationError extends ServiceValidationError {
228
+ constructor(name, message = "${name} must be even", substitutions = {}) {
229
+ super(message, Object.assign(substitutions, { name }));
230
+ this.name = "EvenNumericalityValidationError";
231
+ Object.setPrototypeOf(this, EvenNumericalityValidationError.prototype);
232
+ }
233
+ }
234
+ class OddNumericalityValidationError extends ServiceValidationError {
235
+ constructor(name, message = "${name} must be odd", substitutions = {}) {
236
+ super(message, Object.assign(substitutions, { name }));
237
+ this.name = "OddNumericalityValidationError";
238
+ Object.setPrototypeOf(this, OddNumericalityValidationError.prototype);
239
+ }
240
+ }
241
+ class PositiveNumericalityValidationError extends ServiceValidationError {
242
+ constructor(name, message = "${name} must be positive", substitutions = {}) {
243
+ super(message, Object.assign(substitutions, { name }));
244
+ this.name = "PositiveNumericalityValidationError";
245
+ Object.setPrototypeOf(this, PositiveNumericalityValidationError.prototype);
246
+ }
247
+ }
248
+ class NegativeNumericalityValidationError extends ServiceValidationError {
249
+ constructor(name, message = "${name} must be negative", substitutions = {}) {
250
+ super(message, Object.assign(substitutions, { name }));
251
+ this.name = "NegativeNumericalityValidationError";
252
+ Object.setPrototypeOf(this, NegativeNumericalityValidationError.prototype);
253
+ }
254
+ }
255
+ class CustomValidationError extends ServiceValidationError {
256
+ constructor(name, message = "", substitutions = {}) {
257
+ super(message, Object.assign(substitutions, { name }));
258
+ this.name = "CustomValidationError";
259
+ Object.setPrototypeOf(this, CustomValidationError.prototype);
260
+ }
261
+ }
262
+ class UniquenessValidationError extends ServiceValidationError {
263
+ constructor(name, message, substitutions = {}) {
264
+ const errorMessage = message ? message : `${name} must be unique`;
265
+ super(errorMessage, Object.assign(substitutions, { name }));
266
+ this.name = "UniquenessValidationError";
267
+ Object.setPrototypeOf(this, UniquenessValidationError.prototype);
268
+ }
269
+ }
270
+ // Annotate the CommonJS export names for ESM import in node:
271
+ 0 && (module.exports = {
272
+ AbsenceValidationError,
273
+ AcceptanceValidationError,
274
+ BetweenLengthValidationError,
275
+ CustomValidationError,
276
+ EmailValidationError,
277
+ EqualLengthValidationError,
278
+ EqualNumericalityValidationError,
279
+ EvenNumericalityValidationError,
280
+ ExclusionValidationError,
281
+ FormatValidationError,
282
+ GreaterThanNumericalityValidationError,
283
+ GreaterThanOrEqualNumericalityValidationError,
284
+ InclusionValidationError,
285
+ IntegerNumericalityValidationError,
286
+ LessThanNumericalityValidationError,
287
+ LessThanOrEqualNumericalityValidationError,
288
+ MaxLengthValidationError,
289
+ MinLengthValidationError,
290
+ NegativeNumericalityValidationError,
291
+ OddNumericalityValidationError,
292
+ OtherThanNumericalityValidationError,
293
+ PositiveNumericalityValidationError,
294
+ PresenceValidationError,
295
+ ServiceValidationError,
296
+ TypeNumericalityValidationError,
297
+ UniquenessValidationError
298
+ });
@@ -0,0 +1,222 @@
1
+ import { PrismaClient } from '@prisma/client';
2
+ type WithOptionalMessage<T = Record<string, unknown>> = T & {
3
+ /**
4
+ * A message to be shown if the validation fails.
5
+ */
6
+ message?: string;
7
+ };
8
+ type WithRequiredMessage<T = Record<string, unknown>> = Required<WithOptionalMessage> & T;
9
+ interface AbsenceValidatorOptions extends WithOptionalMessage {
10
+ /**
11
+ * Will count an empty string as being absent (that is, null, undefined and "" will pass this validation)
12
+ */
13
+ allowEmptyString?: boolean;
14
+ }
15
+ interface AcceptanceValidatorOptions extends WithOptionalMessage {
16
+ /**
17
+ * An array of values that, if any match, will pass the validation.
18
+ */
19
+ in?: unknown[];
20
+ }
21
+ type EmailValidatorOptions = WithOptionalMessage;
22
+ interface ExclusionValidatorOptions extends WithOptionalMessage {
23
+ /**
24
+ * The list of values that cannot be used.
25
+ */
26
+ in?: unknown[];
27
+ caseSensitive?: boolean;
28
+ }
29
+ interface FormatValidatorOptions extends WithOptionalMessage {
30
+ /**
31
+ * The regular expression to use.
32
+ */
33
+ pattern?: RegExp;
34
+ }
35
+ interface InclusionValidatorOptions extends WithOptionalMessage {
36
+ /**
37
+ * The list of values that can be used.
38
+ */
39
+ in?: unknown[];
40
+ caseSensitive?: boolean;
41
+ }
42
+ interface LengthValidatorOptions extends WithOptionalMessage {
43
+ /**
44
+ * Must be at least this number of characters long.
45
+ */
46
+ min?: number;
47
+ /**
48
+ * Must be no more than this number of characters long.
49
+ */
50
+ max?: number;
51
+ /**
52
+ * Must be exactly this number of characters long.
53
+ */
54
+ equal?: number;
55
+ /**
56
+ * Convenience syntax for defining min and max as an array
57
+ *
58
+ * @example
59
+ * validate(input.title, 'Title', {
60
+ * length: { between: [2, 255] }
61
+ * })
62
+ */
63
+ between?: number[];
64
+ }
65
+ interface NumericalityValidatorOptions extends WithOptionalMessage {
66
+ /**
67
+ * The number must be an integer.
68
+ */
69
+ integer?: boolean;
70
+ /**
71
+ * The number must be less than the given value.
72
+ */
73
+ lessThan?: number;
74
+ /**
75
+ * The number must be less than or equal to the given value.
76
+ */
77
+ lessThanOrEqual?: number;
78
+ /**
79
+ * The number must be greater than the given value.
80
+ */
81
+ greaterThan?: number;
82
+ /**
83
+ * The number must be greater than or equal to the given number.
84
+ */
85
+ greaterThanOrEqual?: number;
86
+ /**
87
+ * The number must be equal to the given number.
88
+ */
89
+ equal?: number;
90
+ /**
91
+ * The number must not be equal to the given number.
92
+ */
93
+ otherThan?: number;
94
+ /**
95
+ * The number must be even.
96
+ */
97
+ even?: boolean;
98
+ /**
99
+ * The number must be odd.
100
+ */
101
+ odd?: boolean;
102
+ /**
103
+ * The number must be positive.
104
+ */
105
+ positive?: boolean;
106
+ /**
107
+ * The number must be negative.
108
+ */
109
+ negative?: boolean;
110
+ }
111
+ interface PresenceValidatorOptions extends WithOptionalMessage {
112
+ /**
113
+ * Whether or not to allow null to be considered present.
114
+ *
115
+ * @default false
116
+ */
117
+ allowNull?: boolean;
118
+ /**
119
+ * Whether or not to allow undefined to be considered present.
120
+ *
121
+ * @default false
122
+ */
123
+ allowUndefined?: boolean;
124
+ /**
125
+ * Whether or not to allow an empty string "" to be considered present.
126
+ *
127
+ * @default false
128
+ */
129
+ allowEmptyString?: boolean;
130
+ }
131
+ interface CustomValidatorOptions extends WithOptionalMessage {
132
+ /**
133
+ * A function which should either throw or return nothing
134
+ */
135
+ with: () => void;
136
+ }
137
+ interface UniquenessValidatorOptions extends WithOptionalMessage {
138
+ db?: PrismaClient;
139
+ }
140
+ interface ValidationRecipe {
141
+ /**
142
+ * Requires that a field NOT be present, meaning it must be `null` or `undefined`.
143
+ *
144
+ * Opposite of the [`presence`](https://redwoodjs.com/docs/services.html#presence) validator.
145
+ */
146
+ absence?: boolean | AbsenceValidatorOptions;
147
+ /**
148
+ * Requires that the passed value be `true`, or within an array of allowed values that will be considered "true".
149
+ */
150
+ acceptance?: boolean | AcceptanceValidatorOptions;
151
+ /**
152
+ * Requires that the value be formatted like an email address by comparing against a regular expression.
153
+ * The regex is extremely lax: `/^[^@\s]+@[^.\s]+\.[^\s]+$/`
154
+ *
155
+ * This says that the value:
156
+ *
157
+ * * Must start with one or more characters that aren't a whitespace or literal @
158
+ * * Followed by a @
159
+ * * Followed by one or more characters that aren't a whitespace or literal .
160
+ * * Followed by a .
161
+ * * Ending with one or more characters that aren't whitespace
162
+ *
163
+ * Since the official email regex is around 6,300 characters long, we though this one was good enough.
164
+ * If you have a different, preferred email validation regular expression, use the format validation.
165
+ */
166
+ email?: boolean | EmailValidatorOptions;
167
+ /**
168
+ * Requires that the given value not equal to any in a list of given values.
169
+ *
170
+ * Opposite of the [inclusion](https://redwoodjs.com/docs/services.html#inclusion) validation.
171
+ */
172
+ exclusion?: unknown[] | ExclusionValidatorOptions;
173
+ /**
174
+ * Requires that the value match a given regular expression.
175
+ */
176
+ format?: RegExp | FormatValidatorOptions;
177
+ /**
178
+ * Requires that the given value is equal to one in a list of given values.
179
+ *
180
+ * Opposite of the [exclusion](https://redwoodjs.com/docs/services.html#exclusion) validation.
181
+ */
182
+ inclusion?: unknown[] | InclusionValidatorOptions;
183
+ /**
184
+ * Requires that the value meet one or more of a number of string length validations.
185
+ */
186
+ length?: LengthValidatorOptions;
187
+ /**
188
+ * The awesomely-named Numericality Validation requires that the value passed meet one or more criteria that are all number related.
189
+ */
190
+ numericality?: boolean | NumericalityValidatorOptions;
191
+ /**
192
+ * Requires that a field be present, meaning it must not be null or undefined.
193
+ *
194
+ * Opposite of the [absence](https://redwoodjs.com/docs/services.html#absence) validator.
195
+ */
196
+ presence?: boolean | PresenceValidatorOptions;
197
+ /**
198
+ * Run a custom validation function which should either throw or return nothing.
199
+ * If the function throws an error, the error message will be used as the validation error associated with the field.
200
+ */
201
+ custom?: CustomValidatorOptions;
202
+ }
203
+ interface ValidationWithMessagesRecipe extends ValidationRecipe {
204
+ absence?: WithRequiredMessage<AbsenceValidatorOptions>;
205
+ acceptance?: WithRequiredMessage<AcceptanceValidatorOptions>;
206
+ email?: WithRequiredMessage<EmailValidatorOptions>;
207
+ exclusion?: WithRequiredMessage<ExclusionValidatorOptions>;
208
+ format?: WithRequiredMessage<FormatValidatorOptions>;
209
+ inclusion?: WithRequiredMessage<InclusionValidatorOptions>;
210
+ length?: WithRequiredMessage<LengthValidatorOptions>;
211
+ numericality?: WithRequiredMessage<NumericalityValidatorOptions>;
212
+ presence?: WithRequiredMessage<PresenceValidatorOptions>;
213
+ custom?: WithRequiredMessage<CustomValidatorOptions>;
214
+ }
215
+ export declare function validate(value: unknown, labelOrRecipe: ValidationWithMessagesRecipe, recipe?: never): void;
216
+ export declare function validate(value: unknown, labelOrRecipe: string, recipe: ValidationRecipe): void;
217
+ export declare const validateWithSync: (func: () => void) => void;
218
+ export declare const validateWith: (func: () => Promise<any>) => Promise<void>;
219
+ export declare function validateUniqueness(model: string, fields: Record<string, unknown>, optionsOrCallback: (tx: PrismaClient) => Promise<any>, callback: never): Promise<any>;
220
+ export declare function validateUniqueness(model: string, fields: Record<string, unknown>, optionsOrCallback: UniquenessValidatorOptions, callback?: (tx: PrismaClient) => Promise<any>): Promise<any>;
221
+ export {};
222
+ //# sourceMappingURL=validations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validations.d.ts","sourceRoot":"","sources":["../../src/validations/validations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAK7C,KAAK,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;IAC1D;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AACD,KAAK,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAClD,QAAQ,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;AAEnC,UAAU,uBAAwB,SAAQ,mBAAmB;IAC3D;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