@sot1986/appsync-precognition 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,311 @@
1
1
  # appsync-precognition
2
2
 
3
- Lean validation library for Appsync JS runtime, implementing Precognition protocol.
3
+ Lean validation library for AppSync JS runtime, implementing Precognition protocol for real-time form validation.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Basic Usage](#basic-usage)
9
+ - [Simple Validation](#simple-validation)
10
+ - [Precognitive Validation (Real-time)](#precognitive-validation-real-time)
11
+ - [Validation Rules](#validation-rules)
12
+ - [Basic Rules](#basic-rules)
13
+ - [Type Rules](#type-rules)
14
+ - [String Validation](#string-validation)
15
+ - [Date/Time Validation](#datetime-validation)
16
+ - [Numeric Validation](#numeric-validation)
17
+ - [Size Constraints](#size-constraints)
18
+ - [Pattern Matching](#pattern-matching)
19
+ - [Date Comparisons](#date-comparisons)
20
+ - [Nested Object Validation](#nested-object-validation)
21
+ - [Array Validation](#array-validation)
22
+ - [Custom Error Messages](#custom-error-messages)
23
+ - [Custom Attribute Names](#custom-attribute-names)
24
+ - [Validation Options](#validation-options)
25
+ - [Precognitive Validation Features](#precognitive-validation-features)
26
+ - [Client Integration](#client-integration)
27
+ - [Internationalization](#internationalization)
28
+ - [Error Handling](#error-handling)
29
+ - [Advanced Usage](#advanced-usage)
30
+ - [Assert Validated Data](#assert-validated-data)
31
+ - [Check Localization](#check-localization)
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm install appsync-precognition
37
+ ```
38
+
39
+ ## Basic Usage
40
+
41
+ ### Simple Validation
42
+ Any valid object can be validated, using simplified validation rules.
43
+
44
+ ```javascript
45
+ import { validate } from 'appsync-precognition'
46
+
47
+ export function request(ctx) {
48
+ const validatedArgs = validate({
49
+ name: 'Marco',
50
+ age: 15,
51
+ email: 'marco@email.it',
52
+ }, {
53
+ name: ['required', ['min', 3]],
54
+ age: ['required', ['min', 18]],
55
+ email: ['required', 'email'],
56
+ phone: ['sometimes', 'phone']
57
+ })
58
+
59
+ return {
60
+ operation: 'PutItem',
61
+ key: util.dynamodb.toMapValues({ id: util.autoId() }),
62
+ attributeValues: util.dynamodb.toMapValues(validatedArgs)
63
+ }
64
+ }
65
+ ```
66
+ This validation will throw an Error of type `ValidationError`.
67
+
68
+ ```typescript
69
+ util.error(
70
+ 'age min value is 18',
71
+ 'ValidationError',
72
+ null,
73
+ {
74
+ path: 'age',
75
+ value: 15
76
+ }
77
+ )
78
+ ```
79
+
80
+ ### Precognitive Validation (Real-time)
81
+ If your frontend application supports precognitive validation like [Nuxt precognition](https://nuxt.com/modules/precognition), everything will be handled automatically.
82
+
83
+ ```javascript
84
+ import { precognitiveValidation } from 'appsync-precognition'
85
+
86
+ export function request(ctx) {
87
+ const validatedArgs = precognitiveValidation(ctx, {
88
+ name: ['required', ['min', 3]],
89
+ age: ['required', ['min', 18]],
90
+ email: ['required', 'email'],
91
+ phone: ['nullable', 'phone']
92
+ })
93
+
94
+ return {
95
+ operation: 'PutItem',
96
+ key: util.dynamodb.toMapValues({ id: util.autoId() }),
97
+ attributeValues: util.dynamodb.toMapValues(validatedArgs)
98
+ }
99
+ }
100
+ ```
101
+ 1. Module checks for precognition headers and/or keys.
102
+ 2. Validates the request payload accordingly
103
+ 3. In case of success and precognitive requests, it will immediately return with `{ data: null, errors: undefined }`
104
+
105
+ ## Validation Rules
106
+
107
+ ### Basic Rules
108
+ - `required` - Field must have a value
109
+ - `nullable` - Field can be null but validates if present
110
+ - `sometimes` - Field is optional but validates if present
111
+
112
+ ### Type Rules
113
+ - `string` - Must be a string
114
+ - `number` - Must be a number
115
+ - `boolean` - Must be a boolean
116
+ - `array` - Must be an array
117
+ - `object` - Must be an object
118
+
119
+ ### String Validation
120
+ - `email` - Valid email format
121
+ - `phone` - Valid phone number (+123...)
122
+ - `url` - Valid URL format
123
+ - `uuid` - Valid UUID format
124
+ - `ulid` - Valid ULID format
125
+
126
+ ### Date/Time Validation
127
+ - `date` - Valid date (YYYY-MM-DD)
128
+ - `time` - Valid time (HH:MM:SS)
129
+ - `datetime` - Valid ISO datetime
130
+
131
+ ### Numeric Validation
132
+ - `integer` - Valid integer
133
+ - `numeric` - Valid number format
134
+
135
+ ### Size Constraints
136
+ - `['min', number]` - Minimum value/length
137
+ - `['max', number]` - Maximum value/length
138
+ - `['between', min, max]` - Between values (inclusive)
139
+ - `['bigger', number]` - Strictly greater than
140
+ - `['lower', number]` - Strictly less than
141
+ - `['within', min, max]` - Strictly between values
142
+
143
+ ### Pattern Matching
144
+ - `['regex', pattern]` - Match regex pattern
145
+ - `['in', ...values]` - Value must be in list
146
+ - `['notIn', ...values]` - Value must not be in list
147
+
148
+ ### Date Comparisons
149
+ - `['before', date]` - Before specified date
150
+ - `['after', date]` - After specified date
151
+ - `['beforeOrEqual', date]` - Before or equal to date
152
+ - `['afterOrEqual', date]` - After or equal to date
153
+
154
+ ## Nested Object Validation
155
+
156
+ ```javascript
157
+ const validatedArgs = validate(ctx.args, {
158
+ 'user.name': ['required', ['min', 3]],
159
+ 'user.email': ['required', 'email'],
160
+ 'address.street': ['required'],
161
+ 'address.zipCode': ['required', ['between', 5, 10]]
162
+ })
163
+ ```
164
+
165
+ ## Array Validation
166
+
167
+ To simplify error rules definition, the shortcut `*` is supported.
168
+
169
+ ```javascript
170
+ const validatedArgs = validate(ctx.args, {
171
+ 'hobbies': ['required', 'array', ['min', 1]],
172
+ 'hobbies.*': ['required', 'string', ['max', 50]], // Validates each array item
173
+ 'tags': ['sometimes', 'array'],
174
+ 'tags.*.value': ['string']
175
+ })
176
+ ```
177
+
178
+ ## Custom Error Messages
179
+
180
+ ```javascript
181
+ const validatedArgs = validate(ctx.args, {
182
+ email: [{ rule: 'email', msg: 'Please enter a valid email address' }],
183
+ age: [{ rule: ['min', 18], msg: 'You must be at least 18 years old' }]
184
+ })
185
+ ```
186
+
187
+ ## Custom Attribute Names
188
+ Attribute names can be customized by adding a third parameter to the `validate` function.
189
+
190
+ ```javascript
191
+ const validatedArgs = validate(ctx.args, {
192
+ 'email': ['required', 'email'],
193
+ 'phone': ['required', 'phone'],
194
+ 'hobbies.*': ['required', ['min', 2]] // each hobbies should have at least 2 chars
195
+ }, {
196
+ attributes: {
197
+ ':email': 'Email Address',
198
+ ':phone': 'Phone Number',
199
+ ':hobbies.*': 'Hobby' // 'Hobby must have at least 2 characters'
200
+ }
201
+ })
202
+ ```
203
+
204
+ ## Validation Options
205
+
206
+ ```javascript
207
+ const validatedArgs = validate(ctx.args, rules, {
208
+ trim: true, // Trim string values (default: true)
209
+ allowEmptyString: false, // Allow empty strings (default: false)
210
+ errors: {
211
+ required: ':attr is mandatory',
212
+ email: ':attr must be a valid email'
213
+ },
214
+ attributes: {
215
+ ':email': 'Email Address'
216
+ }
217
+ })
218
+ ```
219
+
220
+ ## Precognitive Validation Features
221
+
222
+ The `precognitiveValidation` function automatically handles:
223
+ - **Full validation** when `precognition` header is not present
224
+ - **Selective validation** when `precognition-validate-only` header specifies fields
225
+ - **Early return** for precognitive requests with proper headers
226
+ - **Response headers** for client-side precognition handling
227
+
228
+ ### Client Integration
229
+
230
+ Your frontend should send these headers for precognitive validation:
231
+ ```json
232
+ {
233
+ "Precognition": "true",
234
+ "Precognition-Validate-Only": "email,name"
235
+ }
236
+ ```
237
+
238
+ In addition, these headers must be enabled in the CORS policy of AppSync.
239
+
240
+ ## Internationalization
241
+
242
+ ```javascript
243
+ import { localize } from 'appsync-precognition/i18n'
244
+
245
+ export function request(ctx) {
246
+ // Set up localization based on Accept-Language header
247
+ localize(ctx, {
248
+ errors: {
249
+ en: { required: ':attr is required' },
250
+ es: { required: ':attr es requerido' },
251
+ it: { required: 'il campo :attr è obbligatorio' }
252
+ },
253
+ attributes: {
254
+ en: { ':name': 'Name', ':email': 'Email' },
255
+ es: { ':name': 'Nombre', ':email': 'Correo' },
256
+ it: { ':name': 'Nome', ':email': 'Email' }
257
+ }
258
+ }) // locale details will be added in stash object
259
+
260
+ const validatedArgs = precognitiveValidation(ctx, {
261
+ name: ['required'],
262
+ email: ['required', 'email']
263
+ })
264
+
265
+ return { /* your operation */ }
266
+ }
267
+ ```
268
+ If needed, it can be useful to split the localization and validation in separate resolvers of the same pipeline.
269
+
270
+ ## Error Handling
271
+
272
+ Validation errors are thrown as AppSync errors with detailed information:
273
+
274
+ ```javascript
275
+ // When validation fails, the error contains:
276
+ // - message: Human-readable error message
277
+ // - errorType: 'ValidationError'
278
+ // - errorInfo: { path: 'field.name', value: invalidValue }
279
+ ```
280
+
281
+ ## Advanced Usage
282
+
283
+ ### Assert Validated Data
284
+
285
+ ```javascript
286
+ import { assertValidated } from 'appsync-precognition'
287
+
288
+ export function request(ctx) {
289
+ precognitiveValidation(ctx, rules)
290
+ return { /* operation */ }
291
+ }
292
+
293
+ export function response(ctx) {
294
+ assertValidated(ctx) // Ensures validation was performed
295
+ return ctx.stash.__validated
296
+ }
297
+ ```
298
+
299
+ ### Check Localization
300
+
301
+ ```javascript
302
+ import { assertLocalized, isLocalized } from 'appsync-precognition'
303
+
304
+ export function request(ctx) {
305
+ if (isLocalized(ctx, 'es')) {
306
+ // Handle Spanish localization
307
+ }
308
+
309
+ assertLocalized(ctx) // Throws if not localized
310
+ }
311
+ ```
package/dist/index.d.ts CHANGED
@@ -23,4 +23,4 @@ declare function assertValidated<T extends object>(ctx: Ctx<T>): asserts ctx is
23
23
  declare function isLocalized<T extends object, TLocale extends string>(ctx: Ctx<T>, locale?: TLocale): ctx is LocalizedCtx<T, TLocale>;
24
24
  declare function assertLocalized<T extends object, TLocale extends string>(ctx: Ctx<T>, locale?: TLocale): asserts ctx is LocalizedCtx<T, TLocale>;
25
25
  //#endregion
26
- export { assertLocalized, assertValidated, formatAttributeName, isLocalized, precognitiveValidation, validate };
26
+ export { type CustomFullRule, type FullRule, type LocalizedCtx, type Rule, type ValidationErrors, assertLocalized, assertValidated, formatAttributeName, isLocalized, precognitiveValidation, validate };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["result: ParsedRule<T>","error: { msg?: string, errorType?: string, data?: any, errorInfo?: any }","errors: ValidationErrors","result: ParsedRule<T>","rules.parse"],"sources":["../src/rules.ts","../src/index.ts"],"sourcesContent":["import type { CustomFullRule, FullRule, ParsedRule, ParseOptions } from './types'\nimport { util } from '@aws-appsync/utils'\nimport { date, datetime, email, integer, isArray, numeric, phone, time, ulid, url, uuid } from './utils'\n\nexport function parse<T>(\n opt: ParseOptions<T>,\n rule: FullRule | CustomFullRule,\n): ParsedRule<T> {\n const [n, ...p] = typeof rule === 'string'\n ? [rule, undefined]\n : isArray(rule)\n ? [rule[0], ...rule.slice(1)]\n : typeof rule.rule === 'string'\n ? [rule.rule, undefined]\n : [rule.rule[0], ...rule.rule.slice(1)]\n\n switch (n) {\n case 'required':\n return requiredRule(opt)\n case 'nullable':\n return nullableRule(opt)\n case 'sometimes':\n return sometimesRule(opt)\n case 'min':\n case 'bigger':\n return betweenRule(opt, (p[0]! as number), undefined, n === 'bigger')\n case 'max':\n case 'lower':\n return betweenRule(opt, undefined, (p[0] as number), n === 'lower')\n case 'between':\n case 'within':\n return betweenRule(opt, (p[0] as number), p[1] as number, n === 'within')\n case 'regex':\n return regexRule(opt, ...p as string[])\n case 'in':\n return inRule(opt, ...p)\n case 'notIn':\n return notInRule(opt, ...p)\n case 'before':\n case 'beforeOrEqual':\n return beforeRule(opt, p[0] as string, n === 'before')\n case 'after':\n case 'afterOrEqual':\n return afterRule(opt, p[0] as string, n === 'after')\n case 'email':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.email }, email)\n case 'phone':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.phone }, phone)\n case 'url':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.url }, url)\n case 'uuid':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.uuid }, uuid)\n case 'ulid':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.ulid }, ulid)\n case 'integer':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.integer }, integer)\n case 'date':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.date }, date)\n case 'time':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.time }, time)\n case 'datetime':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.datetime }, datetime)\n case 'numeric':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.numeric }, numeric)\n default:\n return typeRule(opt, n)\n }\n}\n\nfunction betweenRule<T>(\n { value, msg, errors }: ParseOptions<T>,\n minV: number = -Infinity,\n maxV: number = Infinity,\n strict = false,\n): ParsedRule<T> {\n const [min, max] = [maxV === Infinity, minV === -Infinity]\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? min\n ? strict\n ? errors.biggerNumber\n : errors.minNumber\n : max\n ? strict\n ? errors.lowerNumber\n : errors.maxNumber\n : strict\n ? errors.withinNumber\n : errors.betweenNumber,\n value,\n params: {\n ':min': `${minV}`,\n ':max': `${maxV}`,\n },\n }\n if (typeof value === 'number')\n result.check = strict ? value > minV && value < maxV : value >= minV && value <= maxV\n\n if (typeof value === 'string') {\n result.check = value.length >= minV && value.length <= maxV\n result.msg = msg ?? min\n ? errors.minString\n : max\n ? errors.maxString\n : errors.betweenString\n }\n if (isArray(value)) {\n result.check = value.length >= minV && value.length <= maxV\n result.msg = msg ?? min\n ? errors.minArray\n : max\n ? errors.maxArray\n : errors.betweenArray\n }\n return result\n}\n\nfunction regexRule<T>({ value, msg, errors }: ParseOptions<T>, ...p: string[]): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? (p.length === 1 ? errors.regex : errors.regex_patterns),\n value,\n params: p.length === 1\n ? { ':pattern': p[0]! }\n : { ':patterns': p.join(', ') },\n }\n if (typeof value === 'string')\n result.check = p.some(pt => util.matches(pt, value))\n\n if (typeof value === 'number')\n result.check = p.some(pt => util.matches(pt, `${value}`))\n\n return result\n}\n\nfunction inRule<T>({ value, msg, errors }: ParseOptions<T>, ...p: unknown[]): ParsedRule<T> {\n return {\n check: p.includes(value),\n msg: msg ?? errors.in,\n value,\n params: { ':in': p.join(', ') },\n }\n}\n\nfunction notInRule<T>({ value, msg, errors }: ParseOptions<T>, ...p: unknown[]): ParsedRule<T> {\n return {\n check: !p.includes(value),\n msg: msg ?? errors.notIn,\n value,\n params: { ':notIn': p.join(', ') },\n }\n}\n\nexport function requiredRule<T>({ value, msg, errors }: ParseOptions<T>): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: true,\n msg: msg ?? errors.required,\n value,\n skipNext: true,\n }\n if (typeof value === 'string')\n result.check = value.length > 0\n if (isArray(value))\n result.check = value.length > 0\n if (typeof value === 'number')\n result.check = true\n if (typeof value === 'boolean')\n result.check = true\n if (typeof value === 'object' && !result.value) {\n result.check = false\n }\n if (typeof value === 'undefined')\n result.check = false\n result.skipNext = !result.check\n return result\n}\n\nfunction nullableRule<T>({ value, msg, errors }: ParseOptions<T>): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: true,\n msg: msg ?? errors.nullable,\n value,\n skipNext: typeof value === 'undefined' || value === null,\n }\n return result\n}\n\nfunction sometimesRule<T>({ value, msg, errors }: ParseOptions<T>): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: true,\n msg: msg ?? errors.sometimes,\n value,\n }\n if (typeof value === 'undefined') {\n result.skipNext = true\n return result\n }\n if (typeof value === 'object' && !result.value) {\n result.check = false\n result.skipNext = true\n return result\n }\n return requiredRule({ value, msg, errors })\n}\n\nfunction typeRule<T>({ value, msg, errors }: ParseOptions<T>, type: 'boolean' | 'object' | 'array' | 'number' | 'string'): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? errors.type,\n value,\n params: { ':type': type },\n }\n switch (type) {\n case 'array':\n result.check = isArray(value)\n break\n case 'object':\n result.check = typeof value === 'object' && !!value && !isArray(value) && Object.keys(value).length > 0\n break\n case 'boolean':\n result.check = typeof value === 'boolean'\n break\n case 'number':\n result.check = typeof value === 'number'\n break\n default:\n result.check = typeof value === 'string'\n }\n return result\n}\n\nfunction beforeRule<T>({ value, msg, errors }: ParseOptions<T>, start: string, strict = false): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? errors.before,\n value,\n params: strict\n ? { ':before': start }\n : { ':beforeOrEqual': start },\n }\n const startValue = util.time.parseISO8601ToEpochMilliSeconds(start)\n const numDate = typeof value === 'string'\n ? util.time.parseISO8601ToEpochMilliSeconds(value)\n : value\n if (typeof numDate === 'number')\n result.check = strict ? numDate < startValue : numDate <= startValue\n return result\n}\n\nfunction afterRule<T>({ value, msg, errors }: ParseOptions<T>, p: string, strict = false): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? strict ? errors.after : errors.afterOrEqual,\n value,\n params: strict\n ? { ':after': p }\n : { ':afterOrEqual': p },\n }\n const e = util.time.parseISO8601ToEpochMilliSeconds(p)\n const numDate = typeof value === 'string'\n ? util.time.parseISO8601ToEpochMilliSeconds(value)\n : value\n if (typeof numDate === 'number')\n result.check = strict ? numDate > e : numDate >= e\n\n return result\n}\n","import type { Ctx, CustomFullRule, DefinedRecord, FullRule, LocalizedCtx, NestedKeyOf, ParsedRule, Rule, ValidationErrors } from './types'\nimport { runtime, util } from '@aws-appsync/utils'\nimport * as rules from './rules'\nimport { baseErrors, cleanString, getHeader, getNestedValue, isArray, parseErrorMessage, setNestedValue } from './utils'\n\nfunction isRule<T>(rule: FullRule | CustomFullRule | Omit<Rule<T>, 'value'>): rule is Omit<Rule<T>, 'value'> {\n return typeof rule === 'object' && !!rule && Object.hasOwn(rule, 'check')\n}\n\nfunction isCustomFullRule<T>(rule: FullRule | CustomFullRule | Omit<Rule<T>, 'value'>): rule is CustomFullRule {\n return typeof rule === 'object' && !!rule && Object.hasOwn(rule, 'rule')\n}\n\nexport function validate<T extends object>(\n obj: Partial<T>,\n checks: Partial<Record<NestedKeyOf<T>, (FullRule | CustomFullRule | Omit<Rule<T>, 'value'>)[]>>,\n options?: {\n trim?: boolean\n allowEmptyString?: boolean\n errors?: DefinedRecord<Partial<ValidationErrors>>\n attributes?: DefinedRecord<Partial<Record<`:${NestedKeyOf<T>}`, string>>>\n },\n): T {\n let error: { msg?: string, errorType?: string, data?: any, errorInfo?: any } = {}\n const errors: ValidationErrors = { ...baseErrors, ...options?.errors }\n\n sanitizeNestedArray(obj, checks)\n if (options?.attributes)\n sanitizeNestedArray(obj, options.attributes)\n\n Object.keys(checks).forEach((path) => {\n let value = getNestedValue(obj, path as NestedKeyOf<T>)\n if (typeof value === 'string') {\n value = cleanString(value, options)\n setNestedValue(obj, path as NestedKeyOf<T>, value)\n }\n\n let skip = false\n checks[path as NestedKeyOf<T>]?.forEach((rule) => {\n if (skip)\n return\n\n const result: ParsedRule<T> = isRule(rule)\n ? { ...rule, value, msg: rule.msg ?? errors.invalid }\n : isCustomFullRule(rule)\n ? rules.parse<T>({ value, msg: rule.msg, errors }, rule.rule)\n : rules.parse<T>({ value, errors }, rule)\n\n skip = !!result.skipNext || !result.check\n\n if (result.check)\n return\n\n if (error.msg)\n util.appendError(error.msg, error.errorType, error.data, error.errorInfo)\n\n result.params = result.params ?? {}\n\n if (util.matches(':attr', result.msg))\n result.params[':attr'] = options?.attributes?.[`:${path}`] ?? formatAttributeName(path as NestedKeyOf<T>)\n\n error = {\n msg: parseErrorMessage(result.msg, result.params),\n errorType: 'ValidationError',\n data: null,\n errorInfo: { path, value },\n }\n })\n })\n\n if (!error.msg) {\n return obj as T\n }\n\n util.error(error.msg, error.errorType, error.data, error.errorInfo)\n}\n\nfunction sanitizeNestedArray<T extends object>(\n obj: T,\n nested: object,\n): void {\n Object.keys(nested).forEach((path) => {\n const keys = path.split('.')\n keys.forEach((k, idx) => {\n if (k !== '*' || idx === 0)\n return\n const parentPath = keys.slice(0, idx).join('.')\n const parentValue = parentPath.startsWith(':')\n ? getNestedValue(obj, parentPath.replace(':', '') as NestedKeyOf<T>)\n : getNestedValue(obj, parentPath as NestedKeyOf<T>)\n if (!isArray(parentValue))\n return\n\n parentValue.forEach((_, i) => {\n const idxPath = [...keys]\n idxPath[idx] = `${i}`\n nested[idxPath.join('.') as keyof typeof nested] = nested[path as keyof typeof nested]\n })\n delete nested[path as keyof typeof nested]\n })\n })\n}\n\nexport function precognitiveValidation<\n T extends object,\n>(\n ctx: Ctx<T>,\n checks: Partial<Record<NestedKeyOf<T>, (FullRule | CustomFullRule | Rule<T>)[]>>,\n options?: {\n trim?: boolean\n allowEmptyString?: boolean\n skipTo?: 'END' | 'NEXT'\n errors?: DefinedRecord<Partial<ValidationErrors>>\n attributes?: DefinedRecord<Partial<Record<`:${NestedKeyOf<T>}`, string>>>\n },\n): T {\n const { errors, attributes } = (isLocalized(ctx)\n ? {\n errors: {\n ...ctx.stash.__i18n.errors,\n ...options?.errors,\n },\n attributes: {\n ...ctx.stash.__i18n.attributes,\n ...options?.attributes,\n },\n }\n : { errors: options?.errors, attributes: options?.attributes }) as {\n errors: DefinedRecord<Partial<ValidationErrors>>\n attributes: DefinedRecord<Partial<Record<`:${NestedKeyOf<T>}`, string>>>\n }\n if (getHeader('precognition', ctx) !== 'true')\n return ctx.stash.__validated = validate<T>(ctx.args, checks, { ...options, errors, attributes })\n\n const validationKeys = getHeader('Precognition-Validate-Only', ctx)?.split(',').map(key => key.trim())\n util.http.addResponseHeader('Precognition', 'true')\n\n if (!validationKeys) {\n ctx.stash.__validated = validate(ctx.args, checks, { ...options, errors, attributes })\n util.http.addResponseHeader('Precognition-Success', 'true')\n runtime.earlyReturn(null)\n }\n\n util.http.addResponseHeader('Precognition-Validate-Only', validationKeys.join(','))\n const precognitionChecks = {} as Partial<typeof checks>\n validationKeys.forEach((key) => {\n precognitionChecks[key as NestedKeyOf<T>] = checks[key as NestedKeyOf<T>]\n })\n\n ctx.stash.__validated = validate(ctx.args, precognitionChecks, { ...options, errors, attributes })\n util.http.addResponseHeader('Precognition-Success', 'true')\n runtime.earlyReturn(null, { skipTo: options?.skipTo ?? 'END' })\n return ctx.stash.__validated\n}\n\nexport function formatAttributeName(path: string): string {\n return path.split('.').reduce((acc, part) => {\n if (util.matches('^\\\\d+$', part)) {\n return acc\n }\n let words = ''\n part.split('').forEach((char, idx) => {\n if (idx !== 0 && util.matches('[A-Z]', char)) {\n words += ' '\n }\n words += char.toLowerCase()\n })\n return acc ? `${acc} ${words}` : words\n }, '')\n}\n\nexport function assertValidated<T extends object>(\n ctx: Ctx<T>,\n): asserts ctx is Ctx<T> & {\n stash: { __validated: T }\n} {\n if (Object.hasOwn(ctx.stash, '__validated'))\n return\n util.error('Context arguements have not been validated')\n}\n\nexport function isLocalized<T extends object, TLocale extends string>(\n ctx: Ctx<T>,\n locale?: TLocale,\n): ctx is LocalizedCtx<T, TLocale> {\n if (Object.hasOwn(ctx.stash, '__i18n') && typeof ctx.stash?.__i18n.locale === 'string') {\n return locale\n ? ctx.stash.__i18n.locale === locale\n : true\n }\n return false\n}\n\nexport function assertLocalized<T extends object, TLocale extends string>(\n ctx: Ctx<T>,\n locale?: TLocale,\n): asserts ctx is LocalizedCtx<T, TLocale> {\n if (isLocalized(ctx, locale))\n return\n util.error('Context arguements have not been localized')\n}\n"],"mappings":"2NAIA,SAAgB,MACd,EACA,EACe,CACf,KAAM,CAAC,EAAG,GAAG,GAAK,OAAO,IAAS,SAC9B,CAAC,EAAM,IAAA,GAAU,CACjB,QAAQ,EAAK,CACX,CAAC,EAAK,GAAI,GAAG,EAAK,MAAM,EAAE,CAAC,CAC3B,OAAO,EAAK,OAAS,SACnB,CAAC,EAAK,KAAM,IAAA,GAAU,CACtB,CAAC,EAAK,KAAK,GAAI,GAAG,EAAK,KAAK,MAAM,EAAE,CAAC,CAE7C,OAAQ,EAAR,CACE,IAAK,WACH,OAAO,aAAa,EAAI,CAC1B,IAAK,WACH,OAAO,aAAa,EAAI,CAC1B,IAAK,YACH,OAAO,cAAc,EAAI,CAC3B,IAAK,MACL,IAAK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,CACF,OAAO,EAAM,GAAG,EAAI,GAAG,IAAU,GAChC,GAAG,CAGR,SAAgB,gBACd,EAGA,CACA,GAAI,OAAO,OAAO,EAAI,MAAO,cAAc,CACzC,OACF,KAAK,MAAM,6CAA6C,CAG1D,SAAgB,YACd,EACA,EACiC,CACjC,GAAI,OAAO,OAAO,EAAI,MAAO,SAAS,EAAI,OAAO,EAAI,OAAO,OAAO,SAAW,SAC5E,OAAO,EACH,EAAI,MAAM,OAAO,SAAW,EAC5B,KAEN,MAAO,OAGT,SAAgB,gBACd,EACA,EACyC,CACzC,GAAI,YAAY,EAAK,EAAO,CAC1B,OACF,KAAK,MAAM,6CAA6C"}
1
+ {"version":3,"file":"index.js","names":["result: ParsedRule<T>","error: { msg?: string, errorType?: string, data?: any, errorInfo?: any }","errors: ValidationErrors","result: ParsedRule<T>","rules.parse"],"sources":["../src/rules.ts","../src/index.ts"],"sourcesContent":["import type { CustomFullRule, FullRule, ParsedRule, ParseOptions } from './types'\nimport { util } from '@aws-appsync/utils'\nimport { date, datetime, email, integer, isArray, numeric, phone, time, ulid, url, uuid } from './utils'\n\nexport function parse<T>(\n opt: ParseOptions<T>,\n rule: FullRule | CustomFullRule,\n): ParsedRule<T> {\n const [n, ...p] = typeof rule === 'string'\n ? [rule, undefined]\n : isArray(rule)\n ? [rule[0], ...rule.slice(1)]\n : typeof rule.rule === 'string'\n ? [rule.rule, undefined]\n : [rule.rule[0], ...rule.rule.slice(1)]\n\n switch (n) {\n case 'required':\n return requiredRule(opt)\n case 'nullable':\n return nullableRule(opt)\n case 'sometimes':\n return sometimesRule(opt)\n case 'min':\n case 'bigger':\n return betweenRule(opt, (p[0]! as number), undefined, n === 'bigger')\n case 'max':\n case 'lower':\n return betweenRule(opt, undefined, (p[0] as number), n === 'lower')\n case 'between':\n case 'within':\n return betweenRule(opt, (p[0] as number), p[1] as number, n === 'within')\n case 'regex':\n return regexRule(opt, ...p as string[])\n case 'in':\n return inRule(opt, ...p)\n case 'notIn':\n return notInRule(opt, ...p)\n case 'before':\n case 'beforeOrEqual':\n return beforeRule(opt, p[0] as string, n === 'before')\n case 'after':\n case 'afterOrEqual':\n return afterRule(opt, p[0] as string, n === 'after')\n case 'email':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.email }, email)\n case 'phone':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.phone }, phone)\n case 'url':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.url }, url)\n case 'uuid':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.uuid }, uuid)\n case 'ulid':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.ulid }, ulid)\n case 'integer':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.integer }, integer)\n case 'date':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.date }, date)\n case 'time':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.time }, time)\n case 'datetime':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.datetime }, datetime)\n case 'numeric':\n return regexRule({ ...opt, msg: opt.msg ?? opt.errors.numeric }, numeric)\n default:\n return typeRule(opt, n)\n }\n}\n\nfunction betweenRule<T>(\n { value, msg, errors }: ParseOptions<T>,\n minV: number = -Infinity,\n maxV: number = Infinity,\n strict = false,\n): ParsedRule<T> {\n const [min, max] = [maxV === Infinity, minV === -Infinity]\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? min\n ? strict\n ? errors.biggerNumber\n : errors.minNumber\n : max\n ? strict\n ? errors.lowerNumber\n : errors.maxNumber\n : strict\n ? errors.withinNumber\n : errors.betweenNumber,\n value,\n params: {\n ':min': `${minV}`,\n ':max': `${maxV}`,\n },\n }\n if (typeof value === 'number')\n result.check = strict ? value > minV && value < maxV : value >= minV && value <= maxV\n\n if (typeof value === 'string') {\n result.check = value.length >= minV && value.length <= maxV\n result.msg = msg ?? min\n ? errors.minString\n : max\n ? errors.maxString\n : errors.betweenString\n }\n if (isArray(value)) {\n result.check = value.length >= minV && value.length <= maxV\n result.msg = msg ?? min\n ? errors.minArray\n : max\n ? errors.maxArray\n : errors.betweenArray\n }\n return result\n}\n\nfunction regexRule<T>({ value, msg, errors }: ParseOptions<T>, ...p: string[]): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? (p.length === 1 ? errors.regex : errors.regex_patterns),\n value,\n params: p.length === 1\n ? { ':pattern': p[0]! }\n : { ':patterns': p.join(', ') },\n }\n if (typeof value === 'string')\n result.check = p.some(pt => util.matches(pt, value))\n\n if (typeof value === 'number')\n result.check = p.some(pt => util.matches(pt, `${value}`))\n\n return result\n}\n\nfunction inRule<T>({ value, msg, errors }: ParseOptions<T>, ...p: unknown[]): ParsedRule<T> {\n return {\n check: p.includes(value),\n msg: msg ?? errors.in,\n value,\n params: { ':in': p.join(', ') },\n }\n}\n\nfunction notInRule<T>({ value, msg, errors }: ParseOptions<T>, ...p: unknown[]): ParsedRule<T> {\n return {\n check: !p.includes(value),\n msg: msg ?? errors.notIn,\n value,\n params: { ':notIn': p.join(', ') },\n }\n}\n\nexport function requiredRule<T>({ value, msg, errors }: ParseOptions<T>): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: true,\n msg: msg ?? errors.required,\n value,\n skipNext: true,\n }\n if (typeof value === 'string')\n result.check = value.length > 0\n if (isArray(value))\n result.check = value.length > 0\n if (typeof value === 'number')\n result.check = true\n if (typeof value === 'boolean')\n result.check = true\n if (typeof value === 'object' && !result.value) {\n result.check = false\n }\n if (typeof value === 'undefined')\n result.check = false\n result.skipNext = !result.check\n return result\n}\n\nfunction nullableRule<T>({ value, msg, errors }: ParseOptions<T>): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: true,\n msg: msg ?? errors.nullable,\n value,\n skipNext: typeof value === 'undefined' || value === null,\n }\n return result\n}\n\nfunction sometimesRule<T>({ value, msg, errors }: ParseOptions<T>): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: true,\n msg: msg ?? errors.sometimes,\n value,\n }\n if (typeof value === 'undefined') {\n result.skipNext = true\n return result\n }\n if (typeof value === 'object' && !result.value) {\n result.check = false\n result.skipNext = true\n return result\n }\n return requiredRule({ value, msg, errors })\n}\n\nfunction typeRule<T>({ value, msg, errors }: ParseOptions<T>, type: 'boolean' | 'object' | 'array' | 'number' | 'string'): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? errors.type,\n value,\n params: { ':type': type },\n }\n switch (type) {\n case 'array':\n result.check = isArray(value)\n break\n case 'object':\n result.check = typeof value === 'object' && !!value && !isArray(value) && Object.keys(value).length > 0\n break\n case 'boolean':\n result.check = typeof value === 'boolean'\n break\n case 'number':\n result.check = typeof value === 'number'\n break\n default:\n result.check = typeof value === 'string'\n }\n return result\n}\n\nfunction beforeRule<T>({ value, msg, errors }: ParseOptions<T>, start: string, strict = false): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? errors.before,\n value,\n params: strict\n ? { ':before': start }\n : { ':beforeOrEqual': start },\n }\n const startValue = util.time.parseISO8601ToEpochMilliSeconds(start)\n const numDate = typeof value === 'string'\n ? util.time.parseISO8601ToEpochMilliSeconds(value)\n : value\n if (typeof numDate === 'number')\n result.check = strict ? numDate < startValue : numDate <= startValue\n return result\n}\n\nfunction afterRule<T>({ value, msg, errors }: ParseOptions<T>, p: string, strict = false): ParsedRule<T> {\n const result: ParsedRule<T> = {\n check: false,\n msg: msg ?? strict ? errors.after : errors.afterOrEqual,\n value,\n params: strict\n ? { ':after': p }\n : { ':afterOrEqual': p },\n }\n const e = util.time.parseISO8601ToEpochMilliSeconds(p)\n const numDate = typeof value === 'string'\n ? util.time.parseISO8601ToEpochMilliSeconds(value)\n : value\n if (typeof numDate === 'number')\n result.check = strict ? numDate > e : numDate >= e\n\n return result\n}\n","import type { Ctx, CustomFullRule, DefinedRecord, FullRule, LocalizedCtx, NestedKeyOf, ParsedRule, Rule, ValidationErrors } from './types'\nimport { runtime, util } from '@aws-appsync/utils'\nimport * as rules from './rules'\nimport { baseErrors, cleanString, getHeader, getNestedValue, isArray, parseErrorMessage, setNestedValue } from './utils'\n\nfunction isRule<T>(rule: FullRule | CustomFullRule | Omit<Rule<T>, 'value'>): rule is Omit<Rule<T>, 'value'> {\n return typeof rule === 'object' && !!rule && Object.hasOwn(rule, 'check')\n}\n\nfunction isCustomFullRule<T>(rule: FullRule | CustomFullRule | Omit<Rule<T>, 'value'>): rule is CustomFullRule {\n return typeof rule === 'object' && !!rule && Object.hasOwn(rule, 'rule')\n}\n\nexport function validate<T extends object>(\n obj: Partial<T>,\n checks: Partial<Record<NestedKeyOf<T>, (FullRule | CustomFullRule | Omit<Rule<T>, 'value'>)[]>>,\n options?: {\n trim?: boolean\n allowEmptyString?: boolean\n errors?: DefinedRecord<Partial<ValidationErrors>>\n attributes?: DefinedRecord<Partial<Record<`:${NestedKeyOf<T>}`, string>>>\n },\n): T {\n let error: { msg?: string, errorType?: string, data?: any, errorInfo?: any } = {}\n const errors: ValidationErrors = { ...baseErrors, ...options?.errors }\n\n sanitizeNestedArray(obj, checks)\n if (options?.attributes)\n sanitizeNestedArray(obj, options.attributes)\n\n Object.keys(checks).forEach((path) => {\n let value = getNestedValue(obj, path as NestedKeyOf<T>)\n if (typeof value === 'string') {\n value = cleanString(value, options)\n setNestedValue(obj, path as NestedKeyOf<T>, value)\n }\n\n let skip = false\n checks[path as NestedKeyOf<T>]?.forEach((rule) => {\n if (skip)\n return\n\n const result: ParsedRule<T> = isRule(rule)\n ? { ...rule, value, msg: rule.msg ?? errors.invalid }\n : isCustomFullRule(rule)\n ? rules.parse<T>({ value, msg: rule.msg, errors }, rule.rule)\n : rules.parse<T>({ value, errors }, rule)\n\n skip = !!result.skipNext || !result.check\n\n if (result.check)\n return\n\n if (error.msg)\n util.appendError(error.msg, error.errorType, error.data, error.errorInfo)\n\n result.params = result.params ?? {}\n\n if (util.matches(':attr', result.msg))\n result.params[':attr'] = options?.attributes?.[`:${path}`] ?? formatAttributeName(path as NestedKeyOf<T>)\n\n error = {\n msg: parseErrorMessage(result.msg, result.params),\n errorType: 'ValidationError',\n data: null,\n errorInfo: { path, value },\n }\n })\n })\n\n if (!error.msg) {\n return obj as T\n }\n\n util.error(error.msg, error.errorType, error.data, error.errorInfo)\n}\n\nfunction sanitizeNestedArray<T extends object>(\n obj: T,\n nested: object,\n): void {\n Object.keys(nested).forEach((path) => {\n const keys = path.split('.')\n keys.forEach((k, idx) => {\n if (k !== '*' || idx === 0)\n return\n const parentPath = keys.slice(0, idx).join('.')\n const parentValue = parentPath.startsWith(':')\n ? getNestedValue(obj, parentPath.replace(':', '') as NestedKeyOf<T>)\n : getNestedValue(obj, parentPath as NestedKeyOf<T>)\n if (!isArray(parentValue))\n return\n\n parentValue.forEach((_, i) => {\n const idxPath = [...keys]\n idxPath[idx] = `${i}`\n nested[idxPath.join('.') as keyof typeof nested] = nested[path as keyof typeof nested]\n })\n delete nested[path as keyof typeof nested]\n })\n })\n}\n\nexport function precognitiveValidation<\n T extends object,\n>(\n ctx: Ctx<T>,\n checks: Partial<Record<NestedKeyOf<T>, (FullRule | CustomFullRule | Rule<T>)[]>>,\n options?: {\n trim?: boolean\n allowEmptyString?: boolean\n skipTo?: 'END' | 'NEXT'\n errors?: DefinedRecord<Partial<ValidationErrors>>\n attributes?: DefinedRecord<Partial<Record<`:${NestedKeyOf<T>}`, string>>>\n },\n): T {\n const { errors, attributes } = (isLocalized(ctx)\n ? {\n errors: {\n ...ctx.stash.__i18n.errors,\n ...options?.errors,\n },\n attributes: {\n ...ctx.stash.__i18n.attributes,\n ...options?.attributes,\n },\n }\n : { errors: options?.errors, attributes: options?.attributes }) as {\n errors: DefinedRecord<Partial<ValidationErrors>>\n attributes: DefinedRecord<Partial<Record<`:${NestedKeyOf<T>}`, string>>>\n }\n if (getHeader('precognition', ctx) !== 'true')\n return ctx.stash.__validated = validate<T>(ctx.args, checks, { ...options, errors, attributes })\n\n const validationKeys = getHeader('Precognition-Validate-Only', ctx)?.split(',').map(key => key.trim())\n util.http.addResponseHeader('Precognition', 'true')\n\n if (!validationKeys) {\n ctx.stash.__validated = validate(ctx.args, checks, { ...options, errors, attributes })\n util.http.addResponseHeader('Precognition-Success', 'true')\n runtime.earlyReturn(null)\n }\n\n util.http.addResponseHeader('Precognition-Validate-Only', validationKeys.join(','))\n const precognitionChecks = {} as Partial<typeof checks>\n validationKeys.forEach((key) => {\n precognitionChecks[key as NestedKeyOf<T>] = checks[key as NestedKeyOf<T>]\n })\n\n ctx.stash.__validated = validate(ctx.args, precognitionChecks, { ...options, errors, attributes })\n util.http.addResponseHeader('Precognition-Success', 'true')\n runtime.earlyReturn(null, { skipTo: options?.skipTo ?? 'END' })\n return ctx.stash.__validated\n}\n\nexport function formatAttributeName(path: string): string {\n return path.split('.').reduce((acc, part) => {\n if (util.matches('^\\\\d+$', part)) {\n return acc\n }\n let words = ''\n part.split('').forEach((char, idx) => {\n if (idx !== 0 && util.matches('[A-Z]', char)) {\n words += ' '\n }\n words += char.toLowerCase()\n })\n return acc ? `${acc} ${words}` : words\n }, '')\n}\n\nexport function assertValidated<T extends object>(\n ctx: Ctx<T>,\n): asserts ctx is Ctx<T> & {\n stash: { __validated: T }\n} {\n if (Object.hasOwn(ctx.stash, '__validated'))\n return\n util.error('Context arguements have not been validated')\n}\n\nexport function isLocalized<T extends object, TLocale extends string>(\n ctx: Ctx<T>,\n locale?: TLocale,\n): ctx is LocalizedCtx<T, TLocale> {\n if (Object.hasOwn(ctx.stash, '__i18n') && typeof ctx.stash?.__i18n.locale === 'string') {\n return locale\n ? ctx.stash.__i18n.locale === locale\n : true\n }\n return false\n}\n\nexport function assertLocalized<T extends object, TLocale extends string>(\n ctx: Ctx<T>,\n locale?: TLocale,\n): asserts ctx is LocalizedCtx<T, TLocale> {\n if (isLocalized(ctx, locale))\n return\n util.error('Context arguements have not been localized')\n}\n\nexport type { CustomFullRule, FullRule, LocalizedCtx, Rule, ValidationErrors } from './types'\n"],"mappings":"2NAIA,SAAgB,MACd,EACA,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AC,CAClG,KAAK,KAAK,kBAAkB,uBAAwB,OAAO,CAC3D,QAAQ,YAAY,KAAM,CAAE,OAAQ,GAAS,QAAU,MAAO,CAAC,CAC/D,OAAO,EAAI,MAAM,YAGnB,SAAgB,oBAAoB,EAAsB,CACxD,OAAO,EAAK,MAAM,IAAI,CAAC,QAAQ,EAAK,IAAS,CAC3C,GAAI,KAAK,QAAQ,SAAU,EAAK,CAC9B,OAAO,EAET,IAAI,EAAQ,GACZ,EAAK,MAAM,GAAG,CAAC,SAAS,EAAM,IAAQ,CACpC,GAAI,IAAQ,GAAK,KAAK,QAAQ,QAAS,EAAK,CAC1C,GAAS,IAEX,GAAS,EAAK,aAAa,EAC3B,CACF,OAAO,EAAM,GAAG,EAAI,GAAG,IAAU,GAChC,GAAG,CAGR,SAAgB,gBACd,EAGA,CACA,GAAI,OAAO,OAAO,EAAI,MAAO,cAAc,CACzC,OACF,KAAK,MAAM,6CAA6C,CAG1D,SAAgB,YACd,EACA,EACiC,CACjC,GAAI,OAAO,OAAO,EAAI,MAAO,SAAS,EAAI,OAAO,EAAI,OAAO,OAAO,SAAW,SAC5E,OAAO,EACH,EAAI,MAAM,OAAO,SAAW,EAC5B,KAEN,MAAO,OAGT,SAAgB,gBACd,EACA,EACyC,CACzC,GAAI,YAAY,EAAK,EAAO,CAC1B,OACF,KAAK,MAAM,6CAA6C"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sot1986/appsync-precognition",
3
3
  "type": "module",
4
- "version": "0.5.2",
4
+ "version": "0.5.4",
5
5
  "description": "JavaScript resolver validation utilities for AWS AppSync",
6
6
  "author": "sot1986",
7
7
  "license": "MIT",