pocketbase-import/types/pocketbase.ts
michal-kapala df56216609 update to v0.23.1
+ package version bump to 0.22.0
+ support for PB v0.23.1 collections
2024-11-26 17:39:41 +01:00

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;
};