update to v0.23.1

+ package version bump to 0.22.0
+ support for PB v0.23.1 collections
This commit is contained in:
michal-kapala 2024-11-26 17:39:41 +01:00
parent ce03fd9991
commit df56216609
6 changed files with 131 additions and 120 deletions

7
csv.ts
View File

@ -64,7 +64,7 @@ async function importCsv() {
const _authResponse = await pb.admins.authWithPassword(adminName, adminPass);
// collection schema object
const schema = createSchema(data, options.id, "csv");
const fields = createSchema(data, options.id, "csv");
const creationDate = new Date().toISOString();
@ -73,14 +73,13 @@ async function importCsv() {
name: collectName,
type: "base",
system: false,
schema,
fields,
indexes: [],
listRule: null,
viewRule: null,
createRule: null,
updateRule: null,
deleteRule: null,
options: {},
};
// show the submitted collection
@ -96,7 +95,7 @@ async function importCsv() {
);
// rows to be sent via PocketBase API
const rows = parseData(data, schema);
const rows = parseData(data, fields);
console.log(`[Import] Importing ${rows.length} rows...`);

View File

@ -3,6 +3,6 @@
"dev": "deno run --watch main.ts"
},
"imports": {
"pocketbase": "npm:pocketbase@^0.21.5"
"pocketbase": "npm:pocketbase@^0.22.0"
}
}

8
deno.lock generated
View File

@ -1,11 +1,11 @@
{
"version": "4",
"specifiers": {
"npm:pocketbase@~0.21.5": "0.21.5"
"npm:pocketbase@0.22": "0.22.0"
},
"npm": {
"pocketbase@0.21.5": {
"integrity": "sha512-bnI/uinnQps+ElSlzxkc4yvwuSFfKcoszDtXH/4QT2FhGq2mJVUvDlxn+rjRXVntUjPfmMG5LEPZ1eGqV6ssog=="
"pocketbase@0.22.0": {
"integrity": "sha512-jhP0Dcf2Z/4q+SNxqpgV+SJWLZeU0rOJA4TKMxwU7X2olFSBr0jhLu+G6Pc+RIQ40IYrC3WMGwbASPrK6rxQOw=="
}
},
"remote": {
@ -33,7 +33,7 @@
},
"workspace": {
"dependencies": [
"npm:pocketbase@~0.21.5"
"npm:pocketbase@0.22"
]
}
}

View File

@ -48,21 +48,20 @@ async function importJson() {
const _authResponse = await pb.admins.authWithPassword(adminName, adminPass);
// collection schema object
const schema = createSchema(data, options.id, "json");
const fields = createSchema(data, options.id, "json");
// the new collection
const collection: Collection = {
name: collectName,
type: "base",
system: false,
schema,
fields,
indexes: [],
listRule: null,
viewRule: null,
createRule: null,
updateRule: null,
deleteRule: null,
options: {},
};
// show the submitted collection

View File

@ -34,32 +34,69 @@ export const POCKETBASE_SYSFIELD = [
"updated",
];
export type Options = {
[key: string]: any;
};
export type SchemaField = {
export interface SchemaField {
hidden: boolean;
id?: string;
name: string;
type: PocketbaseType;
presentable: boolean;
required: boolean;
system: boolean;
presentable: boolean;
unique: boolean;
options: Options;
type: PocketbaseType;
};
export type Collection = {
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;
schema: SchemaField[];
fields: SchemaField[];
indexes: string[];
listRule: string | null;
viewRule: string |null;
createRule: string |null;
updateRule: string |null;
deleteRule: string |null;
options: Options;
viewRule: string | null;
createRule: string | null;
updateRule: string | null;
deleteRule: string | null;
};

View File

@ -4,7 +4,14 @@ import {
POCKETBASE_TYPE,
PocketbaseRowSchema,
PocketbaseType,
SchemaField
SchemaField,
BoolField,
NumberField,
TextField,
EmailField,
JsonField,
DateField,
UrlField
} from "../types/pocketbase.ts";
import { addSchemaField as addCsvSchemaField } from "./csv.ts";
import { addSchemaField as addJsonSchemaField } from "./json.ts";
@ -28,39 +35,19 @@ export function getSchemaType(
"color: red",
);
Deno.exit(-1);
return "text"
return "text";
}
switch (schemaField.type) {
case POCKETBASE_TYPE.BOOL:
return POCKETBASE_TYPE.BOOL;
case POCKETBASE_TYPE.NUMBER:
return POCKETBASE_TYPE.NUMBER;
case POCKETBASE_TYPE.PLAIN_TEXT:
return POCKETBASE_TYPE.PLAIN_TEXT;
case POCKETBASE_TYPE.EMAIL:
return POCKETBASE_TYPE.EMAIL;
case POCKETBASE_TYPE.JSON:
return POCKETBASE_TYPE.JSON;
case POCKETBASE_TYPE.DATETIME:
return POCKETBASE_TYPE.DATETIME;
case POCKETBASE_TYPE.URL:
return POCKETBASE_TYPE.URL;
default:
console.error(
`%cPbTypeError: Unsupported type '${schemaField.type}'`,
"color: red",
);
Deno.exit(-2);
return "text"
if (schemaField.type == null) {
console.error(
`%cSchemaError: Column type missing for '${column}'`,
"color: red",
);
Deno.exit(-1);
return "text";
}
return schemaField.type;
}
/**
@ -76,93 +63,82 @@ export function createSchemaField(
switch (type) {
case POCKETBASE_TYPE.BOOL:
return {
hidden: false,
name,
type,
system: false,
required: false,
presentable: false,
unique: false,
options: {},
};
required: false,
system: false,
type,
} as BoolField;
case POCKETBASE_TYPE.NUMBER:
return {
hidden: false,
max: undefined,
min: undefined,
name,
type,
system: false,
required: false,
onlyInt: false,
presentable: false,
unique: false,
options: {
min: null,
max: null,
noDecimal: false,
},
};
required: false,
system: false,
type,
} as NumberField;
case POCKETBASE_TYPE.PLAIN_TEXT:
return {
autogeneratePattern: "",
hidden: false,
max: 0,
min: 0,
name,
type,
system: false,
required: false,
pattern: "",
presentable: false,
unique: false,
options: {
min: null,
max: null,
pattern: "",
},
};
primaryKey: false,
required: false,
system: false,
type,
} as TextField;
case POCKETBASE_TYPE.EMAIL:
return {
exceptDomains: undefined,
hidden: false,
name,
type,
system: false,
required: false,
onlyDomains: undefined,
presentable: false,
unique: false,
options: {
exceptDomains: null,
onlyDomains: null,
},
};
required: false,
system: false,
type,
} as EmailField;
case POCKETBASE_TYPE.JSON:
return {
hidden: false,
maxSize: 0,
name,
type,
system: false,
required: false,
presentable: false,
unique: false,
options: {
maxSize: 2000000
},
};
required: false,
system: false,
type,
} as JsonField;
case POCKETBASE_TYPE.DATETIME:
return {
hidden: false,
max: "",
min: "",
name,
type,
system: false,
required: false,
presentable: false,
unique: false,
options: {
min: "",
max: "",
},
};
required: false,
system: false,
type,
} as DateField;
case POCKETBASE_TYPE.URL:
return {
hidden: false,
exceptDomains: undefined,
name,
type,
system: false,
required: false,
onlyDomains: undefined,
presentable: false,
unique: false,
options: {
exceptDomains: null,
onlyDomains: null,
},
};
required: false,
system: false,
type,
} as UrlField;
}
}