removed js sdk dto helpers

This commit is contained in:
Gani Georgiev
2023-08-14 21:20:49 +03:00
parent cbf1215bb1
commit 5960dc5f2d
94 changed files with 1226 additions and 1213 deletions
+6 -7
View File
@@ -1,4 +1,4 @@
import PocketBase, { LocalAuthStore, Admin, isTokenExpired } from "pocketbase";
import PocketBase, { LocalAuthStore, isTokenExpired } from "pocketbase";
// ---
import CommonHelper from "@/utils/CommonHelper";
import { replace } from "svelte-spa-router";
@@ -8,7 +8,6 @@ import { setErrors } from "@/stores/errors";
import { setAdmin } from "@/stores/admin";
import { protectedFilesCollectionsCache } from "@/stores/collections";
const adminFileTokenKey = "pb_admin_file_token";
/**
@@ -107,7 +106,7 @@ class AppAuthStore extends LocalAuthStore {
save(token, model) {
super.save(token, model);
if (model instanceof Admin) {
if (model && !model.collectionId) { // not an auth record
setAdmin(model);
}
}
@@ -122,13 +121,13 @@ class AppAuthStore extends LocalAuthStore {
}
}
const client = new PocketBase(
const pb = new PocketBase(
import.meta.env.PB_BACKEND_URL,
new AppAuthStore("pb_admin_auth")
);
if (client.authStore.model instanceof Admin) {
setAdmin(client.authStore.model);
if (pb.authStore.model && !pb.authStore.model.collectionId) { // not an auth record
setAdmin(pb.authStore.model);
}
export default client;
export default pb;
+50 -5
View File
@@ -944,25 +944,28 @@ export default class CommonHelper {
static dummyCollectionRecord(collection) {
const fields = collection?.schema || [];
const isAuth = collection?.type === "auth";
const isView = collection?.type === "view";
const dummy = {
"id": "RECORD_ID",
"collectionId": collection?.id,
"collectionName": collection?.name,
};
if (collection?.isAuth) {
if (isAuth) {
dummy["username"] = "username123";
dummy["verified"] = false;
dummy["emailVisibility"] = true;
dummy["email"] = "test@example.com";
}
const hasCreated = !collection?.$isView || CommonHelper.extractColumnsFromQuery(collection?.options?.query).includes("created");
const hasCreated = !isView || CommonHelper.extractColumnsFromQuery(collection?.options?.query).includes("created");
if (hasCreated) {
dummy["created"] = "2022-01-01 01:00:00.123Z";
}
const hasUpdated = !collection?.$isView || CommonHelper.extractColumnsFromQuery(collection?.options?.query).includes("updated");
const hasUpdated = !isView || CommonHelper.extractColumnsFromQuery(collection?.options?.query).includes("updated");
if (hasUpdated) {
dummy["updated"] = "2022-01-01 23:59:59.456Z";
}
@@ -1542,11 +1545,11 @@ export default class CommonHelper {
let result = [prefix + "id"];
if (collection.$isView) {
if (collection.type === "view") {
for (let col of CommonHelper.extractColumnsFromQuery(collection.options.query)) {
CommonHelper.pushUnique(result, prefix + col);
}
} else if (collection.$isAuth) {
} else if (collection.type === "auth") {
result.push(prefix + "username");
result.push(prefix + "email");
result.push(prefix + "emailVisibility");
@@ -1800,4 +1803,46 @@ export default class CommonHelper {
return fallbackFields.map((f) => `${f}~${searchTerm}`).join("||");
}
/**
* Iniitialize a new blank Collection POJO and merge it with the provided data (if any).
*
* @param {Object} [data]
* @return {Object}
*/
static initCollection(data) {
return Object.assign({
id: '',
created: '',
updated: '',
name: '',
type: 'base',
system: false,
listRule: null,
viewRule: null,
createRule: null,
updateRule: null,
deleteRule: null,
schema: [],
indexes: [],
options: {},
}, data);
}
/**
* Iniitialize a new blank SchemaField POJO and merge it with the provided data (if any).
*
* @param {Object} [data]
* @return {Object}
*/
static initSchemaField(data) {
return Object.assign({
id: '',
name: '',
type: 'text',
system: false,
required: false,
options: {},
}, data);
}
}