-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve record handling #25
Labels
bug
Something isn't working
Comments
You could try making a RecordId Custom schema for zod i have been using this one i found export const ZRecordIdInstanceOf = z.instanceof(RecordId);
export function recordId<Table extends string = string>(table?: Table) {
return z.custom<RecordId<`${Table}`>>(
val => {
const instanceOfCheck = ZRecordIdInstanceOf.safeParse(val);
const tableCheck = table ? val?.tb === table : true;
return instanceOfCheck.success && tableCheck;
},
val => {
let msgArray: string[] = [];
const instanceOfCheck = ZRecordIdInstanceOf.safeParse(val);
if (!instanceOfCheck.success) msgArray.push(`Must be a RecordId class`);
const tableCheck = table ? val?.tb === table : true;
if (!tableCheck) msgArray.push(`RecordId must be of type '${table}', not '${val?.tb}'`);
return { message: msgArray.join("; ") };
}
);
} its from the SurrealDb discord link to message by Chris Rudman |
Thx @CiskaLV ! This looks good. |
sebastianwessel
added a commit
that referenced
this issue
Jul 9, 2024
sebastianwessel
added a commit
that referenced
this issue
Jul 9, 2024
feat: Improve record handling #25
Version 2.4.0 has been released, adopting this approach. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improve handling of record links
The text was updated successfully, but these errors were encountered: