ajv-validator / ajv-validator/ajv-formats
strict mode: unknown keyword: "format"
- 主要語言
- TypeScript
- 星號
- 228
- 分支
- 42
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hello, I'm using ajv@8.8.2 and ajv-formats@2.1.1 in an AWS Lambda (Node.js 14) and I'm getting this error:
```bash
{
"errorType": "Error",
"errorMessage": "strict mode: unknown keyword: \"format\"",
"stack": [
"Error: strict mode: unknown keyword: \"format\"",
" at null.Gq (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/util.ts:211:28)",
" at null.$q (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/util.ts:27:22)",
" at null.Wfe (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/util.ts:17:3)",
" at Object.code (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/vocabularies/jtd/metadata.ts:11:9)",
" at null.UN (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/validate/index.ts:523:9)",
" at null. (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/validate/index.ts:265:9)",
" at Nq.code (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/codegen/index.ts:525:33)",
" at Nq.block (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/codegen/index.ts:680:20)",
" at null.RN (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/validate/index.ts:262:7)",
" at null.v (/node_modules/.pnpm/ajv@8.8.2/node_modules/ajv/lib/compile/validate/index.ts:248:7)"
]
}
```
Here is the function:
```ts
import {
CognitoIdentityProviderClient,
AdminCreateUserCommand,
AdminAddUserToGroupCommand,
} from "@aws-sdk/client-cognito-identity-provider";
import { AppSyncResolverEvent } from "aws-lambda";
import Ajv, { JTDDataType } from "ajv/dist/jtd";
import format from "ajv/dist/vocabularies/format/format";
import addFormats from "ajv-formats";
import { transformUser } from "./user";
import { groupNames } from "./group";
// validation
const ajv = new Ajv();
ajv.addKeyword(format);
addFormats(ajv, ["email"]);
const schema = {
properties: {
email: { type: "string", metadata: { format: "email" } },
family_name: { type: "string" },
given_name: { type: "string" },
groups: {
elements: { enum: groupNames },
},
username: { type: "string" },
},
} as const;
const validate = ajv.compile(schema);
// params
interface CreateUserGqlArgs {
input: JTDDataType;
}
interface CreateUserParams {
cognitoClient: CognitoIdentityProviderClient;
event: AppSyncResolverEvent;
userPoolId: string;
}
export async function createUser(props: CreateUserParams): Promise {
const { cognitoClient, event, userPoolId } = props;
if (!validate(event.arguments.input)) {
throw new Error(validate.errors?.toString());
}
const { username, groups, ...inputUserAttributes } = event.arguments.input;
const userAttributes = Object.entries(inputUserAttributes).map(([k, v]) => ({
Name: k,
Value: v,
}));
const res = await cognitoClient.send(
new AdminCreateUserCommand({
UserPoolId: userPoolId,
Username: username,
UserAttributes: userAttributes,
})
);
await Promise.all(
groups.map((g) =>
cognitoClient.send(
new AdminAddUserToGroupCommand({
GroupName: g,
Username: username,
UserPoolId: userPoolId,
})
)
)
);
if (!res.User) throw new Error("Error while creating user");
const user = transformUser(res.User);
return user;
}
```
Does anyone know what's going on? Thank you!
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。