test
This commit is contained in:
parent
75015c7044
commit
ee03cd6160
|
@ -1,3 +1,6 @@
|
||||||
|
import { packedNoteSchema } from "@/models/repositories/note";
|
||||||
|
import { packedNotificationSchema } from "@/models/repositories/notification";
|
||||||
|
|
||||||
export type Schema = {
|
export type Schema = {
|
||||||
type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any';
|
type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any';
|
||||||
nullable: boolean;
|
nullable: boolean;
|
||||||
|
@ -43,11 +46,19 @@ type NullOrUndefined<p extends Schema, T> =
|
||||||
? (T | undefined)
|
? (T | undefined)
|
||||||
: T;
|
: T;
|
||||||
|
|
||||||
|
export const refs = {
|
||||||
|
Note: packedNoteSchema,
|
||||||
|
Notification: packedNotificationSchema,
|
||||||
|
};
|
||||||
|
|
||||||
export type SchemaType<p extends Schema> =
|
export type SchemaType<p extends Schema> =
|
||||||
p['type'] extends 'number' ? NullOrUndefined<p, number> :
|
p['type'] extends 'number' ? NullOrUndefined<p, number> :
|
||||||
p['type'] extends 'string' ? NullOrUndefined<p, string> :
|
p['type'] extends 'string' ? NullOrUndefined<p, string> :
|
||||||
p['type'] extends 'boolean' ? NullOrUndefined<p, boolean> :
|
p['type'] extends 'boolean' ? NullOrUndefined<p, boolean> :
|
||||||
p['type'] extends 'array' ? NullOrUndefined<p, MyType<NonNullable<p['items']>>[]> :
|
p['type'] extends 'array' ? NullOrUndefined<p, MyType<NonNullable<p['items']>>[]> :
|
||||||
p['type'] extends 'object' ? NullOrUndefined<p, ObjType<NonNullable<p['properties']>>> :
|
p['type'] extends 'object' ?
|
||||||
|
( p['ref'] extends keyof typeof refs ?
|
||||||
|
NullOrUndefined<p, SchemaType<typeof refs[p['ref']]>> :
|
||||||
|
NullOrUndefined<p, ObjType<NonNullable<p['properties']>>> ) :
|
||||||
p['type'] extends 'any' ? NullOrUndefined<p, any> :
|
p['type'] extends 'any' ? NullOrUndefined<p, any> :
|
||||||
any;
|
any;
|
||||||
|
|
|
@ -56,7 +56,7 @@ export const packedBlockingSchema = {
|
||||||
blockee: {
|
blockee: {
|
||||||
type: 'object' as const,
|
type: 'object' as const,
|
||||||
optional: false as const, nullable: false as const,
|
optional: false as const, nullable: false as const,
|
||||||
ref: 'User',
|
ref: 'User' as const,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -145,6 +145,19 @@ export const packedNotificationSchema = {
|
||||||
format: 'id',
|
format: 'id',
|
||||||
},
|
},
|
||||||
note: {
|
note: {
|
||||||
|
type: 'object' as const,
|
||||||
|
ref: 'Note' as const,
|
||||||
|
optional: true as const, nullable: true as const,
|
||||||
|
},
|
||||||
|
reaction: {
|
||||||
|
type: 'string' as const,
|
||||||
|
optional: true as const, nullable: true as const,
|
||||||
|
},
|
||||||
|
choice: {
|
||||||
|
type: 'number' as const,
|
||||||
|
optional: true as const, nullable: true as const,
|
||||||
|
},
|
||||||
|
invitation: {
|
||||||
type: 'object' as const,
|
type: 'object' as const,
|
||||||
ref: 'Note',
|
ref: 'Note',
|
||||||
optional: true as const, nullable: true as const,
|
optional: true as const, nullable: true as const,
|
||||||
|
|
Loading…
Reference in New Issue