Updates snaplet transform script (#3199)

* Update .gitignore

* Fixes local dev env checks

* Update transform.ts
This commit is contained in:
Omar López 2022-06-29 13:03:13 -06:00 committed by GitHub
parent fbc4eb5457
commit 92bfb3e5b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 33 deletions

View File

@ -1,7 +1,7 @@
// This transform config was generated by Snaplet. // This transform config was generated by Snaplet.
// Snaplet found fields that may contain personally identifiable information (PII) // Snaplet found fields that may contain personally identifiable information (PII)
// and used that to populate this file. // and used that to populate this file.
import { copycat } from "@snaplet/copycat"; import { copycat as c } from "@snaplet/copycat";
import type { Transform } from "./structure"; import type { Transform } from "./structure";
@ -11,13 +11,13 @@ function hasStringProp<T extends string>(x: unknown, key: T): x is { [key in T]:
function replaceKeyIfExists<T extends string>(x: object, key: T) { function replaceKeyIfExists<T extends string>(x: object, key: T) {
if (hasStringProp(x, key)) { if (hasStringProp(x, key)) {
return { ...x, [key]: copycat.uuid(x[key]) }; return { ...x, [key]: c.uuid(x[key]) };
} }
return x; return x;
} }
function generateSlug(x: string) { function generateSlug(x: string) {
return copycat.words(x, { max: 3 }).split(" ").join("-"); return c.words(x, { max: 3 }).split(" ").join("-");
} }
function replaceSensitiveKeys(record: object) { function replaceSensitiveKeys(record: object) {
@ -39,57 +39,57 @@ function replaceSensitiveKeys(record: object) {
}; };
} }
const generateUsername = (x: string) => `${c.firstName(x)}-${c.lastName(x)}${c.int(x, { min: 2, max: 99 })}`;
const config: Transform = () => ({ const config: Transform = () => ({
public: { public: {
_user_eventtype: ({ row }) => ({
A: copycat.int(row.A),
B: copycat.int(row.B),
}),
ApiKey: ({ row }) => ({ ApiKey: ({ row }) => ({
note: copycat.sentence(row.note), hashedKey: c.uuid(row.hashedKey),
}), }),
App: ({ row }) => ({ App: ({ row }) => ({
keys: replaceSensitiveKeys(row.keys), keys: replaceSensitiveKeys(row.keys),
}), }),
Attendee: ({ row }) => ({ Attendee: ({ row }) => ({
email: copycat.email(row.email), email: c.email(row.email),
name: copycat.fullName(row.name), name: c.fullName(row.name),
timeZone: copycat.timezone(row.timeZone), timeZone: c.timezone(row.timeZone),
}),
Availability: ({ row }) => ({
// date: copycat.fullName(row.date),
}), }),
Credential: ({ row }) => ({ Credential: ({ row }) => ({
key: typeof row.key === "string" ? copycat.uuid(row.key) : replaceSensitiveKeys(row.key), key: typeof row.key === "string" ? c.uuid(row.key) : replaceSensitiveKeys(row.key),
}), }),
EventType: ({ row }) => ({ EventType: ({ row }) => ({
slug: generateSlug(row.slug), slug: generateSlug(row.slug),
timeZone: copycat.timezone(row.timeZone), timeZone: c.timezone(row.timeZone),
}), eventName: c.words(row.eventName, { max: 3 }),
Feedback: ({ row }) => ({
// date: copycat.dateString(row.date),
}), }),
ResetPasswordRequest: ({ row }) => ({ ResetPasswordRequest: ({ row }) => ({
email: copycat.email(row.email), email: c.email(row.email),
}), }),
Schedule: ({ row }) => ({ Schedule: ({ row }) => ({
timeZone: copycat.timezone(row.timeZone), timeZone: c.timezone(row.timeZone),
}), }),
Team: ({ row }) => ({ Team: ({ row }) => ({
bio: copycat.sentence(row.bio), bio: c.sentence(row.bio),
name: copycat.words(row.name, { max: 2 }), name: c.words(row.name, { max: 2 }),
slug: generateSlug(row.slug), slug: generateSlug(row.slug),
}), }),
users: ({ row }) => ({ users: ({ row }) =>
bio: copycat.sentence(row.bio), row.role !== "ADMIN"
email: copycat.email(row.email), ? {
name: copycat.fullName(row.name), bio: c.sentence(row.bio),
password: copycat.password(row.password), email: c.email(row.email),
timeZone: copycat.timezone(row.timeZone), name: c.fullName(row.name),
username: generateSlug(row.username), password: c.password(row.password),
}), timeZone: c.timezone(row.timeZone),
username: generateUsername(row.username),
}
: row,
VerificationToken: ({ row }) => ({ VerificationToken: ({ row }) => ({
token: copycat.uuid(row.token), token: c.uuid(row.token),
}),
Account: ({ row }) => ({
access_token: c.uuid(row.access_token),
refresh_token: c.uuid(row.refresh_token),
}), }),
}, },
}); });

View File

@ -21,4 +21,3 @@
"type": "riverside_video" "type": "riverside_video"
} }
] ]