-
-
-
-
-
+
-
Diplomas para Assinar
-
{{ deplomasStore.diplomasParaAssinartCount }} Documentos
+
Eventos para Aprovação
+
{{eventoaprovacaostore.countMd + eventoaprovacaostore.countPr}} Documentos
+
+
+
-
-
-
-
-
+
+
+
+
+
-
Diplomas por Assinar
-
{{ deplomasStore.diplomasParaAssinartCount }} Documentos
+
Despachos
+
{{despachoStore.count}} Documentos
+
+
+
+
+
+
+
+
+
+
+
+
+
Pedidos de Parecer
+
Pedidos de Parecer solicitados por mim
+
{{pedidosstore.countparecer}} Documentos
+
+
+
+
+
+
+
+
+
+
+
+
+
Pedidos de Deferimento
+
{{pedidosstore.countdeferimento}} Documentos
+
+
+
+
+
+
+
+
+
+
+
+
Pendentes
+
Meus Pendentes
+
{{pendentesstore.count}} Documentos
+
+
+
+
diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts
index 364e8fdab..d4f93829a 100644
--- a/src/app/services/chat/message.service.ts
+++ b/src/app/services/chat/message.service.ts
@@ -480,7 +480,7 @@ export class MessageService {
return SessionStore.user.ChatData.data.userId == this.u._id
}
- private getChatObj() {
+ getChatObj() {
return {
channels: this.channels,
mentions: this.mentions,
diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts
index d603a9858..0ed0aea47 100644
--- a/src/app/services/chat/room.service.ts
+++ b/src/app/services/chat/room.service.ts
@@ -125,7 +125,7 @@ export class RoomService {
this.hasLoadHistory = false
this.subscribeAttempt = false
}
- })
+ });
}
@@ -174,11 +174,7 @@ export class RoomService {
this.calDateDuration();
- (async () => {
- await this.restoreMessageFromDB()
- await this.loadHistory({})
- })()
-
+
if(this.customFields?.countDownDate) {
this.countDownDate(this.customFields.countDownDate);
}
@@ -327,7 +323,7 @@ export class RoomService {
if(!found) {
ChatMessage.origin = 'stream'
- const message = await this.prepareCreate({message: ChatMessage, save: true});
+ const message = await this.prepareCreate({message: ChatMessage, save: false});
this.registerSendMessage(message)
message.from = 'stream'
@@ -348,7 +344,10 @@ export class RoomService {
}
if(this.hasLoadHistory == true) {
+ this.messages.push(message)
await message.addMessageDB()
+ } else {
+ this.messagesBeforeOfflineAPI.push(message)
}
if(this.chatOpen == false) {
@@ -503,7 +502,6 @@ export class RoomService {
if(previousLastMessage) {
this.lastMessage = previousLastMessage;
- // console.log("last message"+ previousLastMessage)
this.calDateDuration(previousLastMessage._updatedAt)
this.sortRoomList()
}
@@ -736,12 +734,11 @@ export class RoomService {
setTimeout(() => {
this.scrollDown()
}, 50)
-
}
}
// runs onces only
-
+ loadHistoryCount = 0
async loadHistory({limit = 1000, forceUpdate = false }) {
if(forceUpdate == false) {
@@ -752,33 +749,37 @@ export class RoomService {
this.hasLoadHistory = true
+ await this.restoreMessageFromDB()
const chatHistory: chatHistory = await this.RochetChatConnectorService.loadHistory(this.id, limit)
if(chatHistory?.result?.messages) {
- const messagesId = this.messages.map((message)=> message._id)
const users = this.getUsersByStatus('online')
for(let message of chatHistory.result.messages.reverse()) {
- if (!messagesId.includes(message._id)) {
- message.origin = 'history'
- message.from = 'History'
- const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});
- if(messagesToSave != null) {
- messagesToSave.received = users.map((user) => user._id)
- messagesToSave.addMessageDB()
-
- // console.log('add history', message)
- } else {
- // console.log('exit')
- }
- } else {
- // console.log('exit')
+ message.origin = 'history'
+ message.from = 'History'
+ const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});
+ if(messagesToSave != null) {
+
+ messagesToSave.received = users.map((user) => user._id)
+ messagesToSave.addMessageDB()
}
+
}
+ for( const message of this.messagesBeforeOfflineAPI) {
+ const messagesToSave = await this.prepareMessageCreateIfNotExist({message: message});
+ if(messagesToSave != null) {
+
+ messagesToSave.received = users.map((user) => user._id)
+ messagesToSave.addMessageDB()
+ }
+ }
+ this.messagesBeforeOfflineAPI = []
+
setTimeout(() => {
this.scrollDown()
}, 50)
@@ -824,8 +825,10 @@ export class RoomService {
wewMessage.setData(message)
wewMessage.loadHistory = this.hasLoadHistory
- this.messages.push(wewMessage)
-
+ if(save) {
+ this.messages.push(wewMessage)
+ }
+
return wewMessage
}
@@ -842,17 +845,17 @@ export class RoomService {
private findMessageBy_id (id) {
for( let m of this.messages) {
- if(m._id == id) {
+ if(m?._id == id) {
return true
}
}
-
+
return false
}
private findMessageBy_localReference (localReference) {
for( let m of this.messages) {
- if(m.localReference == localReference) {
+ if(m?.localReference == localReference) {
return true
}
}
@@ -893,7 +896,7 @@ export class RoomService {
async prepareMessageCreateIfNotExist({message}) {
message = this.fix_updatedAt(message)
- let found = await this.findMessageBy_id(message._id) || this.findMessageBy_localReference(message.localReference)
+ let found = await this.findMessageBy_id(message._id) || await this.findMessageBy_localReference(message.localReference)
// || await this.findMessageInDBByData({_id:message._id, localReference:message.localReference })
if (!found) {
diff --git a/src/plugin/src/connection/indexedDb/connector.d.ts b/src/plugin/src/connection/indexedDb/connector.d.ts
index b2659d0db..1fb933e57 100644
--- a/src/plugin/src/connection/indexedDb/connector.d.ts
+++ b/src/plugin/src/connection/indexedDb/connector.d.ts
@@ -1,7 +1,7 @@
import { DatabaseSchema } from '../../models/register-modal.interface.js';
export declare class IndexedDBConnection {
constructor();
- connect(config: DatabaseSchema): Promise
;
- migrate(config: DatabaseSchema): Promise;
+ static connect(config: DatabaseSchema): Promise;
+ static migrate(config: DatabaseSchema): Promise;
private runMigrations;
}
diff --git a/src/plugin/src/connection/indexedDb/connector.js b/src/plugin/src/connection/indexedDb/connector.js
index 9db8b0b0d..abc57da00 100644
--- a/src/plugin/src/connection/indexedDb/connector.js
+++ b/src/plugin/src/connection/indexedDb/connector.js
@@ -13,8 +13,13 @@ export class IndexedDBConnection {
reject(e.target.error.name);
};
request.onupgradeneeded = async (e) => {
- throw ('need to migrate first');
+ console.log('need to migrate first');
+ await this.migrate(config);
+ return await this.connect(config);
};
+ // request.onblocked = async (e: any) => {
+ // reject(e.target.error.name);
+ // }
}
else {
reject("IDBDatabase not supported inside webworker");
diff --git a/src/plugin/src/connection/indexedDb/indexedb.d.ts b/src/plugin/src/connection/indexedDb/indexedb.d.ts
index 3e9bd7a25..f8e32357a 100644
--- a/src/plugin/src/connection/indexedDb/indexedb.d.ts
+++ b/src/plugin/src/connection/indexedDb/indexedb.d.ts
@@ -11,7 +11,7 @@ declare class _indexedDB {
getOneByIndex: (keyPath: string, value: string | number) => Promise;
getManyByIndex: (keyPath: string, value: string | number) => Promise;
getAll: () => Promise;
- add: (value: Object, key?: any) => Promise;
+ add: (value: Object, key?: any) => Promise;
update: (value: any, key?: any) => Promise;
deleteByID: (id: any) => Promise;
deleteAll: () => Promise;
diff --git a/src/plugin/src/connection/indexedDb/indexedb.js b/src/plugin/src/connection/indexedDb/indexedb.js
index db3270c46..010e45a94 100644
--- a/src/plugin/src/connection/indexedDb/indexedb.js
+++ b/src/plugin/src/connection/indexedDb/indexedb.js
@@ -77,6 +77,13 @@ class _indexedDB {
var _a, _b;
(_b = (_a = tx) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a);
resolve(e.target.result);
+ db.transaction;
+ };
+ request.onerror = (e) => {
+ let data = {
+ error: e.target['error']
+ };
+ resolve(data);
};
})
.catch(reject);
@@ -94,11 +101,6 @@ class _indexedDB {
(_b = (_a = tx) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a);
resolve(e.target.result);
};
-
- request.onerror = (e) => {
- console.log(value, key)
- console.log(e)
- }
})
.catch(reject);
});
@@ -152,6 +154,7 @@ class _indexedDB {
request.onsuccess = e => {
cursorCallback(e);
resolve();
+ // db.close();
};
})
.catch(reject);
@@ -278,7 +281,6 @@ class _indexedDB {
delete: async (methods) => {
if (methods[methods.length - 1].methodName == 'delete' &&
methods[methods.length - 1].arguments == null) {
-
const customMethods = Object.create(methods);
customMethods[methods.length - 1].methodName = 'execute';
const result = await this.requestHandler(TableSchema, config, queryId).select(customMethods);
@@ -293,15 +295,11 @@ class _indexedDB {
}
else if (methods[methods.length - 1].methodName == 'delete' &&
typeof methods[methods.length - 1].arguments == 'object') {
-
const IdInObject = methods[methods.length - 1].arguments;
const idValue = IdInObject[TableSchema.id.keyPath];
-
- const result = await this.getActions(TableSchema.name, config).deleteByID(idValue)
- console.log('delete7', IdInObject,idValue, result.type == 'success', result.type)
return {
queryId: queryId,
- value: result.type == 'success'
+ value: await this.getActions(TableSchema.name, config).deleteByID(idValue)
};
}
else if (methods[methods.length - 1].methodName == 'delete' &&
@@ -310,8 +308,6 @@ class _indexedDB {
queryId: queryId,
value: await this.getActions(TableSchema.name, config).deleteAll()
};
- } else {
- console.log('delete else')
}
},
insert: async (methods) => {
@@ -319,19 +315,19 @@ class _indexedDB {
const rows = methods[0].arguments;
for (let insert of rows) {
const id = await this.getActions(TableSchema.name, config).add(insert);
- createdObjKeys.push(id);
+ insert[TableSchema.id.keyPath] = id;
}
// return first element
if (rows.length == 1) {
return {
queryId: queryId,
- value: await this.getActions(TableSchema.name, config).getByID(createdObjKeys[0])
+ value: rows[0]
};
}
else {
return {
queryId: queryId,
- value: createdObjKeys
+ value: rows
};
}
}
diff --git a/src/plugin/src/connection/intreface.d.ts b/src/plugin/src/connection/intreface.d.ts
index b836048a4..5d31fbfcc 100644
--- a/src/plugin/src/connection/intreface.d.ts
+++ b/src/plugin/src/connection/intreface.d.ts
@@ -1,2 +1,2 @@
export declare type actionParam = 'insert' | 'update' | 'delete' | 'select';
-export declare type dbType = 'indexedDB';
+export declare type dbType = 'indexedDB' | 'localStorage';
diff --git a/src/plugin/src/connection/worker.js b/src/plugin/src/connection/worker.js
index 83bea5d75..174c12cc3 100644
--- a/src/plugin/src/connection/worker.js
+++ b/src/plugin/src/connection/worker.js
@@ -1,17 +1,26 @@
import { indexedDB } from './indexedDb/indexedb.js';
onmessage = async (oEvent) => {
const { TableSchema, DBconfig, queryId, action, arg } = oEvent.data;
- const result = await indexedDB.requestHandler(TableSchema, DBconfig, queryId)[action](arg);
+ indexedDB.requestHandler(TableSchema, DBconfig, queryId)[action](arg).then((result) => {
+ try {
+ postMessage(result);
+ }
+ catch (error) {
+ postMessage({
+ queryId: result.queryId,
+ value: undefined
+ });
+ }
+ }).catch((result)=> {
+ try {
+ postMessage(result);
+ }
+ catch (error) {
+ postMessage({
+ queryId: result.queryId,
+ value: undefined
+ });
+ }
+ })
- console.log('return response', result)
- try {
-
- postMessage(result);
- }
- catch (error) {
- postMessage({
- queryId: result.queryId,
- value: undefined
- });
- }
};
diff --git a/src/plugin/src/index.d.ts b/src/plugin/src/index.d.ts
index f378d0fe3..da23bc5ac 100644
--- a/src/plugin/src/index.d.ts
+++ b/src/plugin/src/index.d.ts
@@ -1,6 +1,7 @@
import { Model } from './models/model.js';
+import { LocalStorage } from './models/model.js';
import { ModelReader } from './models/model.reader.js';
-import { registerModel } from './models/register-model.js';
+import { registerModel, migrate } from './models/register-model.js';
export declare const models: {
Value(arg: any): {};
CharField(data?: import("./models/field/interface.js").CharFieldParams): import("./models/field/allFields.js").CharField;
@@ -21,7 +22,8 @@ export declare const models: {
};
};
Model: typeof Model;
+ LocalStorage: typeof LocalStorage;
read: typeof ModelReader.read;
+ migrate: typeof migrate;
register: typeof registerModel.register;
- migrate: typeof registerModel.register;
};
diff --git a/src/plugin/src/index.js b/src/plugin/src/index.js
index 04ce4b13e..0db38b57f 100644
--- a/src/plugin/src/index.js
+++ b/src/plugin/src/index.js
@@ -1,8 +1,10 @@
import { Model } from './models/model.js';
+import { LocalStorage } from './models/model.js';
import * as Fields from './models/field/fields.js';
import { ModelReader } from './models/model.reader.js';
-import { registerModel } from './models/register-model.js';
-export const models = Object.assign(Object.assign({ Model, read: ModelReader.read, register: registerModel.register, migrate: registerModel.register }, Fields), { Value(arg) {
+import { registerModel, migrate } from './models/register-model.js';
+export const models = Object.assign(Object.assign({ Model,
+ LocalStorage, read: ModelReader.read, migrate: migrate, register: registerModel.register }, Fields), { Value(arg) {
if (arg == 'null') {
return {};
}
diff --git a/src/plugin/src/models/model.d.ts b/src/plugin/src/models/model.d.ts
index 73f32f0b7..1574ec608 100644
--- a/src/plugin/src/models/model.d.ts
+++ b/src/plugin/src/models/model.d.ts
@@ -1,5 +1,5 @@
import { getParams } from './model.interface.js';
-import { DatabaseSchema, TableSchema } from './register-modal.interface.js';
+import { DatabaseSchema, DatabaseSchemaLocalStorage, TableSchema } from './register-modal.interface.js';
import { ModelManager } from './model-manager.js';
export declare class Model extends ModelManager {
constructor(obg?: any);
@@ -47,3 +47,18 @@ export declare class Model extends ModelManager {
all: () => Promise;
};
}
+export declare class LocalStorage {
+ constructor();
+ static save(data?: Object): void;
+ static get(): any;
+ static getModelName(): string;
+ static getDBSchema(): DatabaseSchemaLocalStorage;
+ static getTableSchema(): TableSchema;
+ private static getIgnoreAttributes;
+ static ignoreAttributes(attributesStartWidth?: string[]): void;
+ private static getFields;
+ private static formValidation;
+ static clear(): void;
+ static clearComponent(): void;
+ static clearStorage(): void;
+}
diff --git a/src/plugin/src/models/model.js b/src/plugin/src/models/model.js
index 941b7f573..9ed0a8a30 100644
--- a/src/plugin/src/models/model.js
+++ b/src/plugin/src/models/model.js
@@ -1,7 +1,7 @@
var _a, _b;
import { hashCode, uniqueGenerator } from '../utils.js';
import { ModelManager } from './model-manager.js';
-import { models, modelsConfig } from './register-model.js';
+import { models, modelsConfig, modelsConfigLocalStorage } from './register-model.js';
import { FieldType } from '../sql/query/interface.js';
import * as Fields from './field/allFields.js';
let methods = {} = {};
@@ -134,6 +134,10 @@ export class Model extends (_b = ModelManager) {
delete newInstance[fieldName];
}
}
+ Object.defineProperty(newInstance, TableSchema.id.keyPath, {
+ configurable: false,
+ writable: false
+ });
delete newInstance.obj;
return newInstance;
}
@@ -211,11 +215,16 @@ export class Model extends (_b = ModelManager) {
const queryId = uniqueGenerator();
const createObject = await super.obj(DBconfig, TableSchema).create(_methods, queryId);
if (createObject) {
- const ModelName = this.getModelName();
- let newInstance = new models[ModelName]();
- Object.assign(newInstance, createObject);
- delete newInstance.obj;
- return newInstance;
+ if (typeof createObject[TableSchema.id.keyPath] == 'object') {
+ throw (createObject[TableSchema.id.keyPath].error);
+ }
+ else {
+ const ModelName = this.getModelName();
+ let newInstance = new models[ModelName]();
+ Object.assign(newInstance, createObject);
+ delete newInstance.obj;
+ return newInstance;
+ }
}
else {
}
@@ -303,3 +312,82 @@ Model.object = ({ queryId = uniqueGenerator(), DBconfig, TableSchema, some = nul
}
};
};
+export class LocalStorage {
+ constructor() { }
+ static save(data = {}) {
+ const dataToSave = this.getFields(Object.assign(this, Object.assign({}, data)));
+ const key = this.getTableSchema().id;
+ localStorage.setItem(key.keyPath, JSON.stringify(dataToSave));
+ }
+ static get() {
+ const key = this.getTableSchema().id;
+ const restedData = JSON.parse(localStorage.getItem(key.keyPath));
+ Object.assign(this, Object.assign({}, restedData));
+ return restedData;
+ }
+ static getModelName() {
+ return this.toString().split('(' || /s+/)[0].split(' ' || /s+/)[1];
+ }
+ static getDBSchema() {
+ const modalName = this.getModelName();
+ return modelsConfigLocalStorage[modalName].DatabaseSchema;
+ }
+ static getTableSchema() {
+ const modalName = this.getModelName();
+ return modelsConfigLocalStorage[modalName].TableSchema;
+ }
+ static getIgnoreAttributes() {
+ return false;
+ }
+ static ignoreAttributes(attributesStartWidth = []) {
+ if (!this.getIgnoreAttributes()) {
+ this.getIgnoreAttributes = () => {
+ return attributesStartWidth;
+ };
+ }
+ }
+ static getFields(arg) {
+ const TableSchema = this.getTableSchema();
+ const filteredArgs = {};
+ const fieldsName = TableSchema.fields.map((field) => field.name);
+ const Attributes = this.getIgnoreAttributes();
+ const fieldNameFilter = fieldsName.filter((fieldName) => {
+ if (Attributes) {
+ for (let Attribute of Attributes) {
+ if (fieldName.startsWith(Attribute)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ });
+ for (let fieldName of fieldNameFilter) {
+ if (arg.hasOwnProperty(fieldName)) {
+ filteredArgs[fieldName] = arg[fieldName];
+ }
+ }
+ return filteredArgs;
+ }
+ static formValidation(data) {
+ const TableSchema = this.getTableSchema();
+ for (let field of TableSchema.fields) {
+ const Field = new Fields[field.className](field.fieldAttributes);
+ const FieldValue = data[field.name];
+ if (!Field.valid(FieldValue)) {
+ throw ('invalid insert into ' + TableSchema.name + ', invalid value for field ' + field.name + ' = ' + JSON.stringify(FieldValue));
+ }
+ }
+ return true;
+ }
+ static clear() {
+ this.clearComponent();
+ this.clearStorage();
+ }
+ static clearComponent() {
+ const key = this.getTableSchema().id;
+ }
+ static clearStorage() {
+ const key = this.getTableSchema().id;
+ localStorage.removeItem(key.keyPath);
+ }
+}
diff --git a/src/plugin/src/models/model.reader.d.ts b/src/plugin/src/models/model.reader.d.ts
index bc4188236..8d6d3ce87 100644
--- a/src/plugin/src/models/model.reader.d.ts
+++ b/src/plugin/src/models/model.reader.d.ts
@@ -9,3 +9,13 @@ export declare class ModelReader {
attributes: AttributesMap<"maxLength" | "minLength" | "choices" | "primaryKey" | "unique" | "autoIncrement" | "type" | "model" | "blank" | "default" | "onDelete" | "foreignKey", string[]>;
};
}
+export declare class LocalStorageModelReader {
+ static read(modelClassRepresentation: any): {
+ modelName: string;
+ fields: {
+ [key: string]: any;
+ };
+ attributes: AttributesMap<"maxLength" | "minLength" | "choices" | "primaryKey" | "unique" | "autoIncrement" | "type" | "model" | "blank" | "default" | "onDelete" | "foreignKey", string[]>;
+ fieldTypes: FieldsMap<"CharField" | "JsonField" | "AutoField" | "BigIntegerField" | "DateField" | "IntegerField" | "TextField" | "BooleanField" | "OneToOneField" | "ForeignKey" | "ManyToManyField" | "indexedDBJsonField" | "indexedDBArrayField" | "DateTimeField", string[]>;
+ };
+}
diff --git a/src/plugin/src/models/model.reader.js b/src/plugin/src/models/model.reader.js
index 37e537b3e..397660b36 100644
--- a/src/plugin/src/models/model.reader.js
+++ b/src/plugin/src/models/model.reader.js
@@ -32,3 +32,22 @@ export class ModelReader {
};
}
}
+export class LocalStorageModelReader {
+ static read(modelClassRepresentation) {
+ const classInstance = modelClassRepresentation;
+ const fieldTypes = {};
+ const attributes = {};
+ const modelName = classInstance.getModelName();
+ const fields = {};
+ for (const [fieldName, Field] of Object.entries(classInstance)) {
+ // const type = Field?.fieldName
+ fields[fieldName] = Field || null;
+ }
+ return {
+ modelName,
+ fields,
+ attributes,
+ fieldTypes
+ };
+ }
+}
diff --git a/src/plugin/src/models/register-model.d.ts b/src/plugin/src/models/register-model.d.ts
index c87bd5309..a3d81b004 100644
--- a/src/plugin/src/models/register-model.d.ts
+++ b/src/plugin/src/models/register-model.d.ts
@@ -1,11 +1,11 @@
-import { Model } from './model.js';
-import { DatabaseSchema, TableSchema } from './register-modal.interface.js';
+import { Model, LocalStorage } from './model.js';
+import { DatabaseSchema, DatabaseSchemaLocalStorage, TableSchema, TableSchemaLocalStorage } from './register-modal.interface.js';
import { OneToOneField, ForeignKey, ManyToManyField } from './field/allFields.js';
interface register {
databaseName: string;
version: number;
- type: 'indexedDB';
- models: typeof Model[];
+ type: 'indexedDB' | 'localStorage';
+ models: typeof Model[] | typeof LocalStorage[];
}
export declare const models: {};
export declare const modelsConfig: {
@@ -17,10 +17,21 @@ export declare const modelsConfig: {
};
};
};
+export declare const modelsLocalStorage: {};
+export declare const modelsConfigLocalStorage: {
+ [key: string]: {
+ DatabaseSchema: DatabaseSchemaLocalStorage;
+ TableSchema: TableSchemaLocalStorage;
+ };
+};
+export declare function migrate(register: register): void;
export declare class registerModel {
static register(entries: register): Promise;
static manyToManyRelationShip(foreignKeyField: ManyToManyField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): Model;
}
+export declare class registerLocalStorage {
+ static register(entries: register): Promise;
+}
export declare class ModelEditor {
static addMethodOneToOneField(foreignKeyField: OneToOneField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void;
static addMethodForeignKey(foreignKeyField: ForeignKey, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void;
diff --git a/src/plugin/src/models/register-model.js b/src/plugin/src/models/register-model.js
index 794ff592b..4281870bb 100644
--- a/src/plugin/src/models/register-model.js
+++ b/src/plugin/src/models/register-model.js
@@ -1,5 +1,5 @@
import { Model } from './model.js';
-import { ModelReader } from './model.reader.js';
+import { LocalStorageModelReader, ModelReader } from './model.reader.js';
import { indexedDB } from './../connection/indexedDb/indexedb.js';
import { OneToOneField, ForeignKey, ManyToManyField } from './field/allFields.js';
import { uncapitalize } from '../utils.js';
@@ -7,6 +7,16 @@ import { FieldType } from '../sql/query/interface.js';
import { ModelMigrations } from './mode-migrations.js';
export const models = {};
export const modelsConfig = {};
+export const modelsLocalStorage = {};
+export const modelsConfigLocalStorage = {};
+export function migrate(register) {
+ if (register.type == 'indexedDB') {
+ registerModel.register(register);
+ }
+ else if (register.type == 'localStorage') {
+ registerLocalStorage.register(register);
+ }
+}
export class registerModel {
static async register(entries) {
var _a, _b, _c;
@@ -122,6 +132,65 @@ export class registerModel {
});
}
}
+export class registerLocalStorage {
+ static async register(entries) {
+ const databaseSchema = {
+ databaseName: entries.databaseName,
+ version: entries.version,
+ type: 'localStorage',
+ stores: []
+ };
+ for (const modelClassRepresentations of entries.models) {
+ const ModelName = modelClassRepresentations.getModelName();
+ modelsLocalStorage[ModelName] = modelClassRepresentations;
+ }
+ let index = 0;
+ for (const modelClassRepresentations of entries.models) {
+ const { fields, modelName, attributes, fieldTypes } = LocalStorageModelReader.read(modelClassRepresentations);
+ // const idFieldName = attributes?.primaryKey?.shift()
+ databaseSchema.stores.push({
+ name: modelName,
+ id: {
+ keyPath: modelName,
+ type: FieldType.VARCHAR,
+ autoIncrement: false
+ },
+ attributes: attributes,
+ fields: [],
+ fieldTypes
+ });
+ for (const [fieldName, Field] of Object.entries(fields)) {
+ databaseSchema.stores[index].fields.push({
+ name: fieldName,
+ keyPath: fieldName,
+ options: {
+ unique: false,
+ type: null
+ },
+ className: Field === null || Field === void 0 ? void 0 : Field.fieldName,
+ fieldAttributes: Object.assign({}, Field)
+ });
+ }
+ index++;
+ }
+ for (const modelClassRepresentations of entries.models) {
+ const ModelName = modelClassRepresentations.getModelName();
+ const tableSchema = databaseSchema.stores.find((e) => e.name == ModelName);
+ modelClassRepresentations.getDBSchema = () => {
+ return databaseSchema;
+ };
+ modelClassRepresentations.getTableSchema = () => {
+ return tableSchema;
+ };
+ modelsConfigLocalStorage[ModelName] = {
+ DatabaseSchema: databaseSchema,
+ TableSchema: tableSchema
+ };
+ modelsLocalStorage[ModelName] = modelClassRepresentations;
+ }
+ ModelMigrations.migrationsState(true);
+ }
+}
export class ModelEditor {
static addMethodOneToOneField(foreignKeyField, FieldName, modelName, databaseSchema) {
const foreignKeyFieldModel = foreignKeyField.model;
diff --git a/version/git-version.ts b/version/git-version.ts
index e9c192547..82419de44 100644
--- a/version/git-version.ts
+++ b/version/git-version.ts
@@ -1,12 +1,12 @@
export let versionData = {
- "shortSHA": "b60ff0715",
- "SHA": "b60ff0715956f98df8ef0c989174452c1eeabb9f",
+ "shortSHA": "9b5cb7e0e",
+ "SHA": "9b5cb7e0ef8c40b369a3bcbd0e030dbc55801c75",
"branch": "no_bug_movemente",
"lastCommitAuthor": "'Peter Maquiran'",
- "lastCommitTime": "'Wed Feb 8 10:19:33 2023 +0100'",
- "lastCommitMessage": "add lebal",
- "lastCommitNumber": "4755",
- "change": "",
- "changeStatus": "On branch no_bug_movemente\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/modals/create-process/create-process.page.html\n\tmodified: src/app/modals/create-process/create-process.page.ts\n\tmodified: src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.html\n\tmodified: src/app/pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page.ts\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.ts\n\tmodified: src/app/services/chat/chat-system.service.ts",
+ "lastCommitTime": "'Wed Feb 8 11:06:27 2023 +0100'",
+ "lastCommitMessage": "remove some inputs to pr",
+ "lastCommitNumber": "4756",
+ "change": "diff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts\nindex 4d71e6e21..7ed0f9c1c 100644\n--- a/src/app/models/beast-orm.ts\n+++ b/src/app/models/beast-orm.ts\n@@ -1,4 +1,4 @@\n-import { models } from 'src/plugin/src/'\n+import { models } from 'beast-orm'\n import { environment } from 'src/environments/environment'\n const { ArrayField, JsonField} = models.indexedDB.fields\n \ndiff --git a/src/plugin/src/connection/indexedDb/connector.d.ts b/src/plugin/src/connection/indexedDb/connector.d.ts\nindex b2659d0db..1fb933e57 100644\n--- a/src/plugin/src/connection/indexedDb/connector.d.ts\n+++ b/src/plugin/src/connection/indexedDb/connector.d.ts\n@@ -1,7 +1,7 @@\n import { DatabaseSchema } from '../../models/register-modal.interface.js';\n export declare class IndexedDBConnection {\n constructor();\n- connect(config: DatabaseSchema): Promise;\n- migrate(config: DatabaseSchema): Promise;\n+ static connect(config: DatabaseSchema): Promise;\n+ static migrate(config: DatabaseSchema): Promise;\n private runMigrations;\n }\ndiff --git a/src/plugin/src/connection/indexedDb/connector.js b/src/plugin/src/connection/indexedDb/connector.js\nindex 9db8b0b0d..abc57da00 100644\n--- a/src/plugin/src/connection/indexedDb/connector.js\n+++ b/src/plugin/src/connection/indexedDb/connector.js\n@@ -13,8 +13,13 @@ export class IndexedDBConnection {\n reject(e.target.error.name);\n };\n request.onupgradeneeded = async (e) => {\n- throw ('need to migrate first');\n+ console.log('need to migrate first');\n+ await this.migrate(config);\n+ return await this.connect(config);\n };\n+ // request.onblocked = async (e: any) => {\n+ // reject(e.target.error.name);\n+ // }\n }\n else {\n reject(\"IDBDatabase not supported inside webworker\");\ndiff --git a/src/plugin/src/connection/indexedDb/indexedb.d.ts b/src/plugin/src/connection/indexedDb/indexedb.d.ts\nindex 3e9bd7a25..f8e32357a 100644\n--- a/src/plugin/src/connection/indexedDb/indexedb.d.ts\n+++ b/src/plugin/src/connection/indexedDb/indexedb.d.ts\n@@ -11,7 +11,7 @@ declare class _indexedDB {\n getOneByIndex: (keyPath: string, value: string | number) => Promise;\n getManyByIndex: (keyPath: string, value: string | number) => Promise;\n getAll: () => Promise;\n- add: (value: Object, key?: any) => Promise;\n+ add: (value: Object, key?: any) => Promise;\n update: (value: any, key?: any) => Promise;\n deleteByID: (id: any) => Promise;\n deleteAll: () => Promise;\ndiff --git a/src/plugin/src/connection/indexedDb/indexedb.js b/src/plugin/src/connection/indexedDb/indexedb.js\nindex db3270c46..010e45a94 100644\n--- a/src/plugin/src/connection/indexedDb/indexedb.js\n+++ b/src/plugin/src/connection/indexedDb/indexedb.js\n@@ -77,6 +77,13 @@ class _indexedDB {\n var _a, _b;\n (_b = (_a = tx) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a);\n resolve(e.target.result);\n+ db.transaction;\n+ };\n+ request.onerror = (e) => {\n+ let data = {\n+ error: e.target['error']\n+ };\n+ resolve(data);\n };\n })\n .catch(reject);\n@@ -94,11 +101,6 @@ class _indexedDB {\n (_b = (_a = tx) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a);\n resolve(e.target.result);\n };\n-\n- request.onerror = (e) => {\n- console.log(value, key)\n- console.log(e)\n- }\n })\n .catch(reject);\n });\n@@ -152,6 +154,7 @@ class _indexedDB {\n request.onsuccess = e => {\n cursorCallback(e);\n resolve();\n+ // db.close();\n };\n })\n .catch(reject);\n@@ -278,7 +281,6 @@ class _indexedDB {\n delete: async (methods) => {\n if (methods[methods.length - 1].methodName == 'delete' &&\n methods[methods.length - 1].arguments == null) {\n- \n const customMethods = Object.create(methods);\n customMethods[methods.length - 1].methodName = 'execute';\n const result = await this.requestHandler(TableSchema, config, queryId).select(customMethods);\n@@ -293,15 +295,11 @@ class _indexedDB {\n }\n else if (methods[methods.length - 1].methodName == 'delete' &&\n typeof methods[methods.length - 1].arguments == 'object') {\n- \n const IdInObject = methods[methods.length - 1].arguments;\n const idValue = IdInObject[TableSchema.id.keyPath];\n- \n- const result = await this.getActions(TableSchema.name, config).deleteByID(idValue)\n- console.log('delete7', IdInObject,idValue, result.type == 'success', result.type)\n return {\n queryId: queryId,\n- value: result.type == 'success'\n+ value: await this.getActions(TableSchema.name, config).deleteByID(idValue)\n };\n }\n else if (methods[methods.length - 1].methodName == 'delete' &&\n@@ -310,8 +308,6 @@ class _indexedDB {\n queryId: queryId,\n value: await this.getActions(TableSchema.name, config).deleteAll()\n };\n- } else {\n- console.log('delete else')\n }\n },\n insert: async (methods) => {\n@@ -319,19 +315,19 @@ class _indexedDB {\n const rows = methods[0].arguments;\n for (let insert of rows) {\n const id = await this.getActions(TableSchema.name, config).add(insert);\n- createdObjKeys.push(id);\n+ insert[TableSchema.id.keyPath] = id;\n }\n // return first element\n if (rows.length == 1) {\n return {\n queryId: queryId,\n- value: await this.getActions(TableSchema.name, config).getByID(createdObjKeys[0])\n+ value: rows[0]\n };\n }\n else {\n return {\n queryId: queryId,\n- value: createdObjKeys\n+ value: rows\n };\n }\n }\ndiff --git a/src/plugin/src/connection/intreface.d.ts b/src/plugin/src/connection/intreface.d.ts\nindex b836048a4..5d31fbfcc 100644\n--- a/src/plugin/src/connection/intreface.d.ts\n+++ b/src/plugin/src/connection/intreface.d.ts\n@@ -1,2 +1,2 @@\n export declare type actionParam = 'insert' | 'update' | 'delete' | 'select';\n-export declare type dbType = 'indexedDB';\n+export declare type dbType = 'indexedDB' | 'localStorage';\ndiff --git a/src/plugin/src/connection/worker.js b/src/plugin/src/connection/worker.js\nindex 83bea5d75..174c12cc3 100644\n--- a/src/plugin/src/connection/worker.js\n+++ b/src/plugin/src/connection/worker.js\n@@ -1,17 +1,26 @@\n import { indexedDB } from './indexedDb/indexedb.js';\n onmessage = async (oEvent) => {\n const { TableSchema, DBconfig, queryId, action, arg } = oEvent.data;\n- const result = await indexedDB.requestHandler(TableSchema, DBconfig, queryId)[action](arg);\n+ indexedDB.requestHandler(TableSchema, DBconfig, queryId)[action](arg).then((result) => {\n+ try {\n+ postMessage(result);\n+ }\n+ catch (error) {\n+ postMessage({\n+ queryId: result.queryId,\n+ value: undefined\n+ });\n+ }\n+ }).catch((result)=> {\n+ try {\n+ postMessage(result);\n+ }\n+ catch (error) {\n+ postMessage({\n+ queryId: result.queryId,\n+ value: undefined\n+ });\n+ }\n+ })\n \n- console.log('return response', result)\n- try {\n- \n- postMessage(result);\n- }\n- catch (error) {\n- postMessage({\n- queryId: result.queryId,\n- value: undefined\n- });\n- }\n };\ndiff --git a/src/plugin/src/index.d.ts b/src/plugin/src/index.d.ts\nindex f378d0fe3..da23bc5ac 100644\n--- a/src/plugin/src/index.d.ts\n+++ b/src/plugin/src/index.d.ts\n@@ -1,6 +1,7 @@\n import { Model } from './models/model.js';\n+import { LocalStorage } from './models/model.js';\n import { ModelReader } from './models/model.reader.js';\n-import { registerModel } from './models/register-model.js';\n+import { registerModel, migrate } from './models/register-model.js';\n export declare const models: {\n Value(arg: any): {};\n CharField(data?: import(\"./models/field/interface.js\").CharFieldParams): import(\"./models/field/allFields.js\").CharField;\n@@ -21,7 +22,8 @@ export declare const models: {\n };\n };\n Model: typeof Model;\n+ LocalStorage: typeof LocalStorage;\n read: typeof ModelReader.read;\n+ migrate: typeof migrate;\n register: typeof registerModel.register;\n- migrate: typeof registerModel.register;\n };\ndiff --git a/src/plugin/src/index.js b/src/plugin/src/index.js\nindex 04ce4b13e..0db38b57f 100644\n--- a/src/plugin/src/index.js\n+++ b/src/plugin/src/index.js\n@@ -1,8 +1,10 @@\n import { Model } from './models/model.js';\n+import { LocalStorage } from './models/model.js';\n import * as Fields from './models/field/fields.js';\n import { ModelReader } from './models/model.reader.js';\n-import { registerModel } from './models/register-model.js';\n-export const models = Object.assign(Object.assign({ Model, read: ModelReader.read, register: registerModel.register, migrate: registerModel.register }, Fields), { Value(arg) {\n+import { registerModel, migrate } from './models/register-model.js';\n+export const models = Object.assign(Object.assign({ Model,\n+ LocalStorage, read: ModelReader.read, migrate: migrate, register: registerModel.register }, Fields), { Value(arg) {\n if (arg == 'null') {\n return {};\n }\ndiff --git a/src/plugin/src/models/model.d.ts b/src/plugin/src/models/model.d.ts\nindex 73f32f0b7..1574ec608 100644\n--- a/src/plugin/src/models/model.d.ts\n+++ b/src/plugin/src/models/model.d.ts\n@@ -1,5 +1,5 @@\n import { getParams } from './model.interface.js';\n-import { DatabaseSchema, TableSchema } from './register-modal.interface.js';\n+import { DatabaseSchema, DatabaseSchemaLocalStorage, TableSchema } from './register-modal.interface.js';\n import { ModelManager } from './model-manager.js';\n export declare class Model extends ModelManager {\n constructor(obg?: any);\n@@ -47,3 +47,18 @@ export declare class Model extends ModelManager {\n all: () => Promise;\n };\n }\n+export declare class LocalStorage {\n+ constructor();\n+ static save(data?: Object): void;\n+ static get(): any;\n+ static getModelName(): string;\n+ static getDBSchema(): DatabaseSchemaLocalStorage;\n+ static getTableSchema(): TableSchema;\n+ private static getIgnoreAttributes;\n+ static ignoreAttributes(attributesStartWidth?: string[]): void;\n+ private static getFields;\n+ private static formValidation;\n+ static clear(): void;\n+ static clearComponent(): void;\n+ static clearStorage(): void;\n+}\ndiff --git a/src/plugin/src/models/model.js b/src/plugin/src/models/model.js\nindex 941b7f573..9ed0a8a30 100644\n--- a/src/plugin/src/models/model.js\n+++ b/src/plugin/src/models/model.js\n@@ -1,7 +1,7 @@\n var _a, _b;\n import { hashCode, uniqueGenerator } from '../utils.js';\n import { ModelManager } from './model-manager.js';\n-import { models, modelsConfig } from './register-model.js';\n+import { models, modelsConfig, modelsConfigLocalStorage } from './register-model.js';\n import { FieldType } from '../sql/query/interface.js';\n import * as Fields from './field/allFields.js';\n let methods = {} = {};\n@@ -134,6 +134,10 @@ export class Model extends (_b = ModelManager) {\n delete newInstance[fieldName];\n }\n }\n+ Object.defineProperty(newInstance, TableSchema.id.keyPath, {\n+ configurable: false,\n+ writable: false\n+ });\n delete newInstance.obj;\n return newInstance;\n }\n@@ -211,11 +215,16 @@ export class Model extends (_b = ModelManager) {\n const queryId = uniqueGenerator();\n const createObject = await super.obj(DBconfig, TableSchema).create(_methods, queryId);\n if (createObject) {\n- const ModelName = this.getModelName();\n- let newInstance = new models[ModelName]();\n- Object.assign(newInstance, createObject);\n- delete newInstance.obj;\n- return newInstance;\n+ if (typeof createObject[TableSchema.id.keyPath] == 'object') {\n+ throw (createObject[TableSchema.id.keyPath].error);\n+ }\n+ else {\n+ const ModelName = this.getModelName();\n+ let newInstance = new models[ModelName]();\n+ Object.assign(newInstance, createObject);\n+ delete newInstance.obj;\n+ return newInstance;\n+ }\n }\n else {\n }\n@@ -303,3 +312,82 @@ Model.object = ({ queryId = uniqueGenerator(), DBconfig, TableSchema, some = nul\n }\n };\n };\n+export class LocalStorage {\n+ constructor() { }\n+ static save(data = {}) {\n+ const dataToSave = this.getFields(Object.assign(this, Object.assign({}, data)));\n+ const key = this.getTableSchema().id;\n+ localStorage.setItem(key.keyPath, JSON.stringify(dataToSave));\n+ }\n+ static get() {\n+ const key = this.getTableSchema().id;\n+ const restedData = JSON.parse(localStorage.getItem(key.keyPath));\n+ Object.assign(this, Object.assign({}, restedData));\n+ return restedData;\n+ }\n+ static getModelName() {\n+ return this.toString().split('(' || /s+/)[0].split(' ' || /s+/)[1];\n+ }\n+ static getDBSchema() {\n+ const modalName = this.getModelName();\n+ return modelsConfigLocalStorage[modalName].DatabaseSchema;\n+ }\n+ static getTableSchema() {\n+ const modalName = this.getModelName();\n+ return modelsConfigLocalStorage[modalName].TableSchema;\n+ }\n+ static getIgnoreAttributes() {\n+ return false;\n+ }\n+ static ignoreAttributes(attributesStartWidth = []) {\n+ if (!this.getIgnoreAttributes()) {\n+ this.getIgnoreAttributes = () => {\n+ return attributesStartWidth;\n+ };\n+ }\n+ }\n+ static getFields(arg) {\n+ const TableSchema = this.getTableSchema();\n+ const filteredArgs = {};\n+ const fieldsName = TableSchema.fields.map((field) => field.name);\n+ const Attributes = this.getIgnoreAttributes();\n+ const fieldNameFilter = fieldsName.filter((fieldName) => {\n+ if (Attributes) {\n+ for (let Attribute of Attributes) {\n+ if (fieldName.startsWith(Attribute)) {\n+ return false;\n+ }\n+ }\n+ }\n+ return true;\n+ });\n+ for (let fieldName of fieldNameFilter) {\n+ if (arg.hasOwnProperty(fieldName)) {\n+ filteredArgs[fieldName] = arg[fieldName];\n+ }\n+ }\n+ return filteredArgs;\n+ }\n+ static formValidation(data) {\n+ const TableSchema = this.getTableSchema();\n+ for (let field of TableSchema.fields) {\n+ const Field = new Fields[field.className](field.fieldAttributes);\n+ const FieldValue = data[field.name];\n+ if (!Field.valid(FieldValue)) {\n+ throw ('invalid insert into ' + TableSchema.name + ', invalid value for field ' + field.name + ' = ' + JSON.stringify(FieldValue));\n+ }\n+ }\n+ return true;\n+ }\n+ static clear() {\n+ this.clearComponent();\n+ this.clearStorage();\n+ }\n+ static clearComponent() {\n+ const key = this.getTableSchema().id;\n+ }\n+ static clearStorage() {\n+ const key = this.getTableSchema().id;\n+ localStorage.removeItem(key.keyPath);\n+ }\n+}\ndiff --git a/src/plugin/src/models/model.reader.d.ts b/src/plugin/src/models/model.reader.d.ts\nindex bc4188236..8d6d3ce87 100644\n--- a/src/plugin/src/models/model.reader.d.ts\n+++ b/src/plugin/src/models/model.reader.d.ts\n@@ -9,3 +9,13 @@ export declare class ModelReader {\n attributes: AttributesMap<\"maxLength\" | \"minLength\" | \"choices\" | \"primaryKey\" | \"unique\" | \"autoIncrement\" | \"type\" | \"model\" | \"blank\" | \"default\" | \"onDelete\" | \"foreignKey\", string[]>;\n };\n }\n+export declare class LocalStorageModelReader {\n+ static read(modelClassRepresentation: any): {\n+ modelName: string;\n+ fields: {\n+ [key: string]: any;\n+ };\n+ attributes: AttributesMap<\"maxLength\" | \"minLength\" | \"choices\" | \"primaryKey\" | \"unique\" | \"autoIncrement\" | \"type\" | \"model\" | \"blank\" | \"default\" | \"onDelete\" | \"foreignKey\", string[]>;\n+ fieldTypes: FieldsMap<\"CharField\" | \"JsonField\" | \"AutoField\" | \"BigIntegerField\" | \"DateField\" | \"IntegerField\" | \"TextField\" | \"BooleanField\" | \"OneToOneField\" | \"ForeignKey\" | \"ManyToManyField\" | \"indexedDBJsonField\" | \"indexedDBArrayField\" | \"DateTimeField\", string[]>;\n+ };\n+}\ndiff --git a/src/plugin/src/models/model.reader.js b/src/plugin/src/models/model.reader.js\nindex 37e537b3e..397660b36 100644\n--- a/src/plugin/src/models/model.reader.js\n+++ b/src/plugin/src/models/model.reader.js\n@@ -32,3 +32,22 @@ export class ModelReader {\n };\n }\n }\n+export class LocalStorageModelReader {\n+ static read(modelClassRepresentation) {\n+ const classInstance = modelClassRepresentation;\n+ const fieldTypes = {};\n+ const attributes = {};\n+ const modelName = classInstance.getModelName();\n+ const fields = {};\n+ for (const [fieldName, Field] of Object.entries(classInstance)) {\n+ // const type = Field?.fieldName\n+ fields[fieldName] = Field || null;\n+ }\n+ return {\n+ modelName,\n+ fields,\n+ attributes,\n+ fieldTypes\n+ };\n+ }\n+}\ndiff --git a/src/plugin/src/models/register-model.d.ts b/src/plugin/src/models/register-model.d.ts\nindex c87bd5309..a3d81b004 100644\n--- a/src/plugin/src/models/register-model.d.ts\n+++ b/src/plugin/src/models/register-model.d.ts\n@@ -1,11 +1,11 @@\n-import { Model } from './model.js';\n-import { DatabaseSchema, TableSchema } from './register-modal.interface.js';\n+import { Model, LocalStorage } from './model.js';\n+import { DatabaseSchema, DatabaseSchemaLocalStorage, TableSchema, TableSchemaLocalStorage } from './register-modal.interface.js';\n import { OneToOneField, ForeignKey, ManyToManyField } from './field/allFields.js';\n interface register {\n databaseName: string;\n version: number;\n- type: 'indexedDB';\n- models: typeof Model[];\n+ type: 'indexedDB' | 'localStorage';\n+ models: typeof Model[] | typeof LocalStorage[];\n }\n export declare const models: {};\n export declare const modelsConfig: {\n@@ -17,10 +17,21 @@ export declare const modelsConfig: {\n };\n };\n };\n+export declare const modelsLocalStorage: {};\n+export declare const modelsConfigLocalStorage: {\n+ [key: string]: {\n+ DatabaseSchema: DatabaseSchemaLocalStorage;\n+ TableSchema: TableSchemaLocalStorage;\n+ };\n+};\n+export declare function migrate(register: register): void;\n export declare class registerModel {\n static register(entries: register): Promise;\n static manyToManyRelationShip(foreignKeyField: ManyToManyField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): Model;\n }\n+export declare class registerLocalStorage {\n+ static register(entries: register): Promise;\n+}\n export declare class ModelEditor {\n static addMethodOneToOneField(foreignKeyField: OneToOneField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void;\n static addMethodForeignKey(foreignKeyField: ForeignKey, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void;\ndiff --git a/src/plugin/src/models/register-model.js b/src/plugin/src/models/register-model.js\nindex 794ff592b..4281870bb 100644\n--- a/src/plugin/src/models/register-model.js\n+++ b/src/plugin/src/models/register-model.js\n@@ -1,5 +1,5 @@\n import { Model } from './model.js';\n-import { ModelReader } from './model.reader.js';\n+import { LocalStorageModelReader, ModelReader } from './model.reader.js';\n import { indexedDB } from './../connection/indexedDb/indexedb.js';\n import { OneToOneField, ForeignKey, ManyToManyField } from './field/allFields.js';\n import { uncapitalize } from '../utils.js';\n@@ -7,6 +7,16 @@ import { FieldType } from '../sql/query/interface.js';\n import { ModelMigrations } from './mode-migrations.js';\n export const models = {};\n export const modelsConfig = {};\n+export const modelsLocalStorage = {};\n+export const modelsConfigLocalStorage = {};\n+export function migrate(register) {\n+ if (register.type == 'indexedDB') {\n+ registerModel.register(register);\n+ }\n+ else if (register.type == 'localStorage') {\n+ registerLocalStorage.register(register);\n+ }\n+}\n export class registerModel {\n static async register(entries) {\n var _a, _b, _c;\n@@ -122,6 +132,65 @@ export class registerModel {\n });\n }\n }\n+export class registerLocalStorage {\n+ static async register(entries) {\n+ const databaseSchema = {\n+ databaseName: entries.databaseName,\n+ version: entries.version,\n+ type: 'localStorage',\n+ stores: []\n+ };\n+ for (const modelClassRepresentations of entries.models) {\n+ const ModelName = modelClassRepresentations.getModelName();\n+ modelsLocalStorage[ModelName] = modelClassRepresentations;\n+ }\n+ let index = 0;\n+ for (const modelClassRepresentations of entries.models) {\n+ const { fields, modelName, attributes, fieldTypes } = LocalStorageModelReader.read(modelClassRepresentations);\n+ // const idFieldName = attributes?.primaryKey?.shift()\n+ databaseSchema.stores.push({\n+ name: modelName,\n+ id: {\n+ keyPath: modelName,\n+ type: FieldType.VARCHAR,\n+ autoIncrement: false\n+ },\n+ attributes: attributes,\n+ fields: [],\n+ fieldTypes\n+ });\n+ for (const [fieldName, Field] of Object.entries(fields)) {\n+ databaseSchema.stores[index].fields.push({\n+ name: fieldName,\n+ keyPath: fieldName,\n+ options: {\n+ unique: false,\n+ type: null\n+ },\n+ className: Field === null || Field === void 0 ? void 0 : Field.fieldName,\n+ fieldAttributes: Object.assign({}, Field)\n+ });\n+ }\n+ index++;\n+ }\n+ for (const modelClassRepresentations of entries.models) {\n+ const ModelName = modelClassRepresentations.getModelName();\n+ const tableSchema = databaseSchema.stores.find((e) => e.name == ModelName);\n+ modelClassRepresentations.getDBSchema = () => {\n+ return databaseSchema;\n+ };\n+ modelClassRepresentations.getTableSchema = () => {\n+ return tableSchema;\n+ };\n+ modelsConfigLocalStorage[ModelName] = {\n+ DatabaseSchema: databaseSchema,\n+ TableSchema: tableSchema\n+ };\n+ modelsLocalStorage[ModelName] = modelClassRepresentations;\n+ }\n+ ModelMigrations.migrationsState(true);\n+ }\n+}\n export class ModelEditor {\n static addMethodOneToOneField(foreignKeyField, FieldName, modelName, databaseSchema) {\n const foreignKeyFieldModel = foreignKeyField.model;",
+ "changeStatus": "On branch no_bug_movemente\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/models/beast-orm.ts\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.html\n\tmodified: src/app/services/chat/message.service.ts\n\tmodified: src/app/services/chat/room.service.ts\n\nChanges not staged for commit:\n (use \"git add ...\" to update what will be committed)\n (use \"git restore ...\" to discard changes in working directory)\n\tmodified: src/app/models/beast-orm.ts\n\tmodified: src/plugin/src/connection/indexedDb/connector.d.ts\n\tmodified: src/plugin/src/connection/indexedDb/connector.js\n\tmodified: src/plugin/src/connection/indexedDb/indexedb.d.ts\n\tmodified: src/plugin/src/connection/indexedDb/indexedb.js\n\tmodified: src/plugin/src/connection/intreface.d.ts\n\tmodified: src/plugin/src/connection/worker.js\n\tmodified: src/plugin/src/index.d.ts\n\tmodified: src/plugin/src/index.js\n\tmodified: src/plugin/src/models/model.d.ts\n\tmodified: src/plugin/src/models/model.js\n\tmodified: src/plugin/src/models/model.reader.d.ts\n\tmodified: src/plugin/src/models/model.reader.js\n\tmodified: src/plugin/src/models/register-model.d.ts\n\tmodified: src/plugin/src/models/register-model.js",
"changeAuthor": "peter.maquiran"
}
\ No newline at end of file