103 lines
1.9 KiB
TypeScript
103 lines
1.9 KiB
TypeScript
/**
|
|
* All the Pocketbase types supported by this tool.
|
|
*/
|
|
export const POCKETBASE_TYPE = {
|
|
BOOL: "bool",
|
|
NUMBER: "number",
|
|
PLAIN_TEXT: "text",
|
|
EMAIL: "email",
|
|
JSON: "json",
|
|
DATETIME: "date",
|
|
URL: "url",
|
|
} as const;
|
|
|
|
type ObjectValues<T> = T[keyof T];
|
|
|
|
/**
|
|
* Supported Pocketbase data types.
|
|
*/
|
|
export type PocketbaseType = ObjectValues<typeof POCKETBASE_TYPE>;
|
|
|
|
/**
|
|
* A row type schema for column value parsing.
|
|
*/
|
|
export type PocketbaseRowSchema = {
|
|
[key: string]: PocketbaseType;
|
|
};
|
|
|
|
/**
|
|
* PocketBase system fields with autogenerated values that cannot be overriden (`base` collection type).
|
|
*/
|
|
export const POCKETBASE_SYSFIELD = [
|
|
"id",
|
|
"created",
|
|
"updated",
|
|
];
|
|
|
|
export interface SchemaField {
|
|
hidden: boolean;
|
|
id?: string;
|
|
name: string;
|
|
presentable: boolean;
|
|
required: boolean;
|
|
system: boolean;
|
|
type: PocketbaseType;
|
|
};
|
|
|
|
export interface BoolField extends SchemaField {
|
|
type: "bool";
|
|
};
|
|
|
|
export interface NumberField extends SchemaField {
|
|
max?: number;
|
|
min?: number;
|
|
onlyInt: boolean;
|
|
type: "number";
|
|
};
|
|
|
|
export interface TextField extends SchemaField {
|
|
autogeneratePattern: string;
|
|
max?: number;
|
|
min?: number;
|
|
pattern: string;
|
|
primaryKey: boolean;
|
|
type: "text";
|
|
};
|
|
|
|
export interface EmailField extends SchemaField {
|
|
exceptDomains?: string[];
|
|
onlyDomains?: string[];
|
|
type: "email";
|
|
};
|
|
|
|
export interface DateField extends SchemaField {
|
|
max: string;
|
|
min: string;
|
|
type: "date";
|
|
}
|
|
|
|
export interface JsonField extends SchemaField {
|
|
maxSize: number;
|
|
type: "json";
|
|
}
|
|
|
|
export interface UrlField extends SchemaField {
|
|
exceptDomains?: string[];
|
|
onlyDomains?: string[];
|
|
type: "url";
|
|
}
|
|
|
|
export interface Collection {
|
|
id?: string;
|
|
name: string;
|
|
type: string;
|
|
system: boolean;
|
|
fields: SchemaField[];
|
|
indexes: string[];
|
|
listRule: string | null;
|
|
viewRule: string | null;
|
|
createRule: string | null;
|
|
updateRule: string | null;
|
|
deleteRule: string | null;
|
|
};
|