diff --git a/.gitignore b/.gitignore index e8ea8cb22..6797cbad5 100644 --- a/.gitignore +++ b/.gitignore @@ -77,7 +77,9 @@ _www/ www2020 android copy/ report.* -src/plugin/src/ +src/plugin/* +!src/plugin/*.js +!src/plugin/src _node_modules/ migrat/ @@ -88,4 +90,6 @@ src/app/models/beast-orm-pro.ts src/app/pipes/process.service.spec.ts -src/app/pipes/process.service.ts \ No newline at end of file +src/app/pipes/process.service.ts + +/.angular \ No newline at end of file diff --git a/src/app/models/beast-orm-function.ts b/src/app/models/beast-orm-function.ts new file mode 100644 index 000000000..d50e4fddd --- /dev/null +++ b/src/app/models/beast-orm-function.ts @@ -0,0 +1,56 @@ +import { AES, SHA1, enc } from "crypto-js"; +import { environment } from 'src/environments/environment' + + +function prefix() { + return environment.version.lastCommitNumber + environment.id+"-"; +} + +export function GET({key, localStorage, instance}) { + if(environment.storageProduction) { + + try { + const newKey = prefix() + SHA1(key).toString() + const cipherText = localStorage.getItem(newKey) + const bytes = AES.decrypt(cipherText, newKey) + var decryptedData = bytes.toString(enc.Utf8); + const restoredData = JSON.parse(decryptedData) + + Object.assign(instance, restoredData); + + return restoredData + + } catch(error) { + console.log(error) + return {} + } + + } else { + return JSON.parse(localStorage.getItem(prefix() + key)) + } + +} + +export function SAVE({key, localStorage, instance, dataToSave}) { + if(environment.storageProduction) { + const newKey = prefix() + SHA1(key).toString() + const stringifyData = JSON.stringify(dataToSave) + + const cipherText = AES.encrypt(stringifyData, newKey).toString(); + + localStorage.setItem(newKey, cipherText) + + } else { + localStorage.setItem(prefix() + key, dataToSave) + } +} + +export function DELETE({key, localStorage, instance}) { + if(environment.storageProduction) { + const newKey = prefix() + SHA1(key).toString() + localStorage.removeItem(newKey) + + } else { + localStorage.removeItem(prefix() + key) + } +} \ No newline at end of file diff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts index d9cec8e66..cf1d30fb5 100644 --- a/src/app/models/beast-orm.ts +++ b/src/app/models/beast-orm.ts @@ -1,5 +1,6 @@ -import { models } from 'beast-orm' +//import { models } from 'beast-orm' import { environment } from 'src/environments/environment' +import { models } from 'src/plugin/src' const { ArrayField, JsonField} = models.indexedDB.fields export class MessageModel extends models.Model { @@ -80,9 +81,6 @@ models.register({ models: [PublicationModel, ActionModel] }) - - - export class WebtrixUserModel extends models.Model { FullName = models.CharField() Role = models.CharField() @@ -102,4 +100,3 @@ models.register({ version: 14, models: [PublicationModel, ActionModel] }) - diff --git a/src/app/models/envarioment.ts b/src/app/models/envarioment.ts index 889d32a02..760187d8b 100644 --- a/src/app/models/envarioment.ts +++ b/src/app/models/envarioment.ts @@ -20,6 +20,7 @@ export interface Environment { PR: string VP: string dispatchPR: string + storageProduction: boolean } diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 2812ba982..26cfcf967 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -19,7 +19,7 @@ import { Platform } from '@ionic/angular'; import { FirstEnterService } from '../../services/first-enter.service'; import { Storage } from '@ionic/storage'; import { HttpErrorHandle } from 'src/app/services/http-error-handle.service'; -import { DocumentManagementStore } from 'src/app/store/documentManagement'; +import { CPSession } from 'src/app/store/documentManagement'; @Component({ selector: 'app-login', templateUrl: './login.page.html', @@ -39,7 +39,6 @@ export class LoginPage implements OnInit { sessionStore = SessionStore; showPassword = false; passwordIcon = "eye"; - DocumentManagementStore = DocumentManagementStore constructor( private notificatinsservice: NotificationsService, @@ -154,7 +153,7 @@ export class LoginPage implements OnInit { window.localStorage.clear(); await MessageModel.deleteAll(); await DeleteMessageModel.deleteAll(); - this.DocumentManagementStore.clear(); + CPSession.clear(); this.storage.clear(); await this.authService.SetSession(attempt, this.userattempt); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 292c126cf..1be1a7b98 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -19,7 +19,7 @@ import { InitialsService } from './functions/initials.service'; import { PermissionService } from './permission.service'; import { ChatSystemService } from 'src/app/services/chat/chat-system.service'; import { HttpErrorHandle } from 'src/app/services/http-error-handle.service'; -import { DocumentManagementStore } from '../store/documentManagement'; +import { CPSession } from '../store/documentManagement'; @Injectable({ providedIn: 'root' }) @@ -32,8 +32,6 @@ export class AuthService { opts:any; tabIsActive = true - - DocumentManagementStore = DocumentManagementStore constructor( private http: HttpClient, @@ -78,9 +76,6 @@ export class AuthService { async login(user: UserForm, {saveSession = true}): Promise { user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password,user.username )); - // Basic peter.maquiran@equilibrium.co.ao:senha123456 - // console.log(user.BasicAuthKey) - this.headers = this.headers.set('Authorization', user.BasicAuthKey); this.opts = { headers: this.headers, @@ -119,7 +114,8 @@ export class AuthService { if(saveSession) { /* this.SetSession(response, user) */ - this.DocumentManagementStore.setData(response) + console.log('teste', response); + CPSession.save(response) } } catch (error) { diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index c5bc66032..7398111a8 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -882,13 +882,13 @@ export class RoomService { private async findMessageInDBByData({localReference, _id}) { - const a = await MessageModel.filter({localReference: localReference}) + const a = await MessageModel.filter({localReference: localReference}).execute() if(a.length >= 1) { return true } - const c = await MessageModel.filter({_id: _id}) + const c = await MessageModel.filter({_id: _id}).execute() if(c.length >= 1) { return true diff --git a/src/app/services/processes.service.ts b/src/app/services/processes.service.ts index e638aa1f3..5eea4ca98 100644 --- a/src/app/services/processes.service.ts +++ b/src/app/services/processes.service.ts @@ -11,7 +11,7 @@ import { fullTaskList } from '../models/dailyworktask.model'; import { ChangeProfileService } from './change-profile.service'; import { SessionStore } from '../store/session.service'; import { StorageService } from './storage.service'; -import { DocumentManagementStore } from '../store/documentManagement'; +import { CPSession } from '../store/documentManagement'; @Injectable({ providedIn: 'root' }) @@ -21,7 +21,6 @@ export class ProcessesService { loggeduser: LoginUserRespose; headers: HttpHeaders; headers2: HttpHeaders; - documentMangement = DocumentManagementStore; @@ -46,14 +45,10 @@ export class ProcessesService { setHeader() { + console.log('CPSession.AuthorizationJwt', CPSession.AuthorizationJwt); - this.headers = new HttpHeaders(); - this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey); + this.headers2 = this.headers2.set('Authorization',"bearer "+ CPSession.AuthorizationJwt); - this.headers2 = new HttpHeaders(); - this.headers2 = this.headers2.set('Authorization',"Bearer "+ this.documentMangement.session?.AuthorizationJwt - - ); } uploadFile(formData:any){ @@ -137,8 +132,6 @@ export class ProcessesService { GetDraftByID(id:string): Observable { - console.log('Instancia estas instanciar?',this.documentMangement.session?.AuthorizationJwt) - const geturl = environment.apiPCURL + `Documents/${id}`; let params = new HttpParams(); diff --git a/src/app/store/documentManagement.ts b/src/app/store/documentManagement.ts index 8148ab65b..90347baed 100644 --- a/src/app/store/documentManagement.ts +++ b/src/app/store/documentManagement.ts @@ -1,45 +1,31 @@ -import { SHA1 } from 'crypto-js' -import { localstoreService } from './localstore.service' - -class _DocumentManagementStore { - - - session: { - UserId: number, - Email: string, - UserName: string - FullName: string - RoleID: number - RoleDescription: string - OrganicEntityID: number - OrganicEntityName: string - Status: string - Authorization: string - AuthorizationJwt: string - } - - - constructor() { - const restore = localstoreService.get(this.keyName, {}) - this.session = restore.session - } - - get keyName() { - return SHA1("documentManagement").toString() - } - - setData(data) { - this.session = data - localstoreService.set(this.keyName, { - session: this.session - }) - } - - clear() { - delete this.session - localstoreService.delete(this.keyName) - } +import { models } from 'src/plugin/src' +import { DELETE, GET, SAVE } from '../models/beast-orm-function'; +const { rewriteSave, rewriteGet, rewriteDelete } = models.core.localStorage.rewrite +export class CPSession extends models.LocalStorage { + static UserId: number = models.preset() + static Email: string = models.preset() + static UserName: string = models.preset() + static FullName: string = models.preset() + static RoleID: number = models.preset() + static RoleDescription: string = models.preset() + static OrganicEntityID: number = models.preset() + static OrganicEntityName: string = models.preset() + static Status: string = models.preset() + static Authorization: string = models.preset() + static AuthorizationJwt: string = models.preset() } -export const DocumentManagementStore = new _DocumentManagementStore() +// content production +models.migrate({ + databaseName:'content-production', + type: 'localStorage', + version: 1, + models: [CPSession], +}) + + +rewriteGet.connect(GET, [CPSession]) +rewriteSave.connect(SAVE, [CPSession]) +rewriteDelete.connect(DELETE, [CPSession]) +CPSession.get() \ No newline at end of file diff --git a/src/environments/suport/dev.ts b/src/environments/suport/dev.ts index 1351d586b..d6061aec1 100644 --- a/src/environments/suport/dev.ts +++ b/src/environments/suport/dev.ts @@ -23,6 +23,7 @@ export const DevProd: Environment = { PR: 'Titular', VP: '', dispatchPR: 'Despachos Titular', + storageProduction: true }; @@ -48,4 +49,5 @@ export const DevDev: Environment = { PR: 'Titular', VP: '', dispatchPR: 'Despachos Titular', + storageProduction: false, }; \ No newline at end of file diff --git a/src/environments/suport/doneIt.ts b/src/environments/suport/doneIt.ts index ac25d7c56..88bf24fe9 100644 --- a/src/environments/suport/doneIt.ts +++ b/src/environments/suport/doneIt.ts @@ -23,6 +23,7 @@ export const doneITProd: Environment = { PR: 'Titular', VP: '', dispatchPR: 'Despachos Titular', + storageProduction: true }; export const doneITDev: Environment = { @@ -47,4 +48,5 @@ export const doneITDev: Environment = { PR: 'Titular', VP: '', dispatchPR: 'Despachos Titular', + storageProduction: false }; \ No newline at end of file diff --git a/src/environments/suport/oapr.ts b/src/environments/suport/oapr.ts index 470d3eb6b..e68f2dd63 100644 --- a/src/environments/suport/oapr.ts +++ b/src/environments/suport/oapr.ts @@ -23,7 +23,8 @@ export const oaprProd: Environment = { PR: 'PR', VP: '', dispatchPR: 'Despachos Presidênciais', - sentryUrl: 'https://9920cc36f1d740b987426ee8d80cf588@o4504340905525248.ingest.sentry.io/4504340946419712' + sentryUrl: 'https://9920cc36f1d740b987426ee8d80cf588@o4504340905525248.ingest.sentry.io/4504340946419712', + storageProduction: true }; export const oaprDev: Environment = { @@ -48,4 +49,5 @@ export const oaprDev: Environment = { VP: '', dispatchPR: 'Despachos Presidênciais', sentryUrl: 'https://9920cc36f1d740b987426ee8d80cf588@o4504340905525248.ingest.sentry.io/4504340946419712', + storageProduction: false }; \ No newline at end of file diff --git a/src/plugin/src/connection/dbSwtich.d.ts b/src/plugin/src/connection/dbSwtich.d.ts new file mode 100644 index 000000000..0adb66060 --- /dev/null +++ b/src/plugin/src/connection/dbSwtich.d.ts @@ -0,0 +1,6 @@ +import { actionParam, dbType } from './intreface.js'; +export declare class DBSwitch { + private static header; + static requestHandler(TableName: string, DatabaseName: string, dbType: dbType, action: actionParam, arg: any, queryId: any): Promise; + static callBackRequestHandler(TableName: string, DatabaseName: string, dbType: dbType, action: actionParam, arg: any, callback: Function, queryId: string): Promise; +} diff --git a/src/plugin/src/connection/dbSwtich.js b/src/plugin/src/connection/dbSwtich.js new file mode 100644 index 000000000..e7e07b8f0 --- /dev/null +++ b/src/plugin/src/connection/dbSwtich.js @@ -0,0 +1,40 @@ +import { indexedDB } from './indexedDb/indexedb.js'; +import { taskHolder } from './taskHolder.js'; +import { WorkerManager } from './workerManager.js'; +export class DBSwitch { + static header({ TableName, DatabaseName, queryId, action, arg, dbType, callback }) { + return { + params: { TableName, DatabaseName, queryId, action, arg, dbType }, + queryId: queryId, + method: 'execute', + callback: (message) => { + callback(message.value); + } + }; + } + static async requestHandler(TableName, DatabaseName, dbType, action, arg, queryId) { + return new Promise(async (resolve, reject) => { + const header = this.header({ TableName, DatabaseName, queryId, action, arg, dbType, callback: (data) => { + resolve(data); + taskHolder.finish(queryId); + } }); + if (typeof (Worker) !== "undefined" && WorkerManager.webWorkerModuleSupport) { + WorkerManager.register(header); + } + else { + taskHolder.register(header); + indexedDB.requestHandler(TableName, DatabaseName, queryId)[action](arg); + } + }); + } + static async callBackRequestHandler(TableName, DatabaseName, dbType, action, arg, callback, queryId) { + const header = this.header({ TableName, DatabaseName, queryId, action, arg, dbType, callback }); + if (typeof (Worker) !== "undefined" && WorkerManager.webWorkerModuleSupport) { + WorkerManager.register(header); + } + else { + taskHolder.register(header); + indexedDB.requestHandler(TableName, DatabaseName, queryId)[action](arg); + } + } +} diff --git a/src/plugin/src/connection/indexedDb/DatabaseManager.d.ts b/src/plugin/src/connection/indexedDb/DatabaseManager.d.ts new file mode 100644 index 000000000..e6f2c8fae --- /dev/null +++ b/src/plugin/src/connection/indexedDb/DatabaseManager.d.ts @@ -0,0 +1,9 @@ +import { DatabaseSchema } from "../../models/register-modal.interface.js"; +import { Database } from "./database.js"; +export declare class DatabaseManager { + static databases: { + [databaseName: string]: Database; + }; + static prepare(config: DatabaseSchema): Promise; + static getDb(databaseName: any): Database; +} diff --git a/src/plugin/src/connection/indexedDb/DatabaseManager.js b/src/plugin/src/connection/indexedDb/DatabaseManager.js new file mode 100644 index 000000000..0407f4440 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/DatabaseManager.js @@ -0,0 +1,12 @@ +import { Database } from "./database.js"; +// inspire by https://github.com/hc-oss/use-indexeddb +export class DatabaseManager { + static async prepare(config) { + this.databases[config.databaseName] = new Database({ config }); + await this.databases[config.databaseName].migrate(); + } + static getDb(databaseName) { + return this.databases[databaseName]; + } +} +DatabaseManager.databases = {}; diff --git a/src/plugin/src/connection/indexedDb/connect.d.ts b/src/plugin/src/connection/indexedDb/connect.d.ts new file mode 100644 index 000000000..c99508b8b --- /dev/null +++ b/src/plugin/src/connection/indexedDb/connect.d.ts @@ -0,0 +1,6 @@ +import { DatabaseSchema } from "../../models/register-modal.interface.js"; +export declare class IndexedDBConnector { + static connect(config: DatabaseSchema): Promise; + static migrate(config: DatabaseSchema): Promise; + private static runMigrations; +} diff --git a/src/plugin/src/connection/indexedDb/connect.js b/src/plugin/src/connection/indexedDb/connect.js new file mode 100644 index 000000000..413164713 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/connect.js @@ -0,0 +1,61 @@ +// inspire by https://github.com/hc-oss/use-indexeddb +export class IndexedDBConnector { + static connect(config) { + return new Promise((resolve, reject) => { + const idbInstance = indexedDB || self.indexedDB || self.mozIndexedDB || self.webkitIndexedDB || self.msIndexedDB; + if (idbInstance) { + const request = idbInstance.open(config.databaseName, config.version); + request.onsuccess = () => { + resolve(request.result); + }; + request.onerror = (e) => { + reject(e.target.error.name); + }; + request.onupgradeneeded = async (e) => { + 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"); + } + }); + } + static migrate(config) { + return new Promise((resolve, reject) => { + const idbInstance = indexedDB || self.indexedDB || self.mozIndexedDB || self.webkitIndexedDB || self.msIndexedDB; + if (idbInstance) { + const request = idbInstance.open(config.databaseName, config.version); + request.onsuccess = () => { + // request.result.close() + resolve(false); + }; + request.onerror = (e) => { + reject(e.target.error.name); + }; + request.onupgradeneeded = async (e) => { + const db = e.target.result; + await this.runMigrations(db, config); + db.close(); + resolve(true); + }; + } + else { + reject("Failed to connect"); + } + }); + } + static async runMigrations(db, config) { + await config.stores.forEach(async (storeSchema) => { + if (!db.objectStoreNames.contains(storeSchema.name)) { + const ObjectStore = db.createObjectStore(storeSchema.name, storeSchema.id); + storeSchema.fields.forEach(c => { + ObjectStore.createIndex(c.name, c.keyPath, c.options); + }); + } + }); + } +} diff --git a/src/plugin/src/connection/indexedDb/database.d.ts b/src/plugin/src/connection/indexedDb/database.d.ts new file mode 100644 index 000000000..791ba918d --- /dev/null +++ b/src/plugin/src/connection/indexedDb/database.d.ts @@ -0,0 +1,28 @@ +import { DatabaseSchema } from '../../models/register-modal.interface'; +import { ObjectStore } from './objectStore.js'; +export declare class Database { + name: string; + version: string; + objectStore: { + [storeName: string]: ObjectStore; + }; + dbInstance: IDBDatabase; + executingTransaction: { + [key: string]: boolean; + }; + storeUsingDbInstance: { + [key: string]: boolean; + }; + config: DatabaseSchema; + constructor({ config }: { + config: DatabaseSchema; + }); + getDatabaseConnection(): Promise; + getOrCreateTransaction({ TableName, queryId }: { + TableName: any; + queryId: any; + }, mode: any, callback: any): Promise; + getObjectStore(TableName: any): ObjectStore; + transactionFinish: (TableName: any) => void; + migrate(): Promise; +} diff --git a/src/plugin/src/connection/indexedDb/database.js b/src/plugin/src/connection/indexedDb/database.js new file mode 100644 index 000000000..8af2f5e81 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/database.js @@ -0,0 +1,42 @@ +import { ObjectStore } from './objectStore.js'; +import { IndexedDBConnector } from './connect.js'; +export class Database { + constructor({ config }) { + this.name = ''; + this.version = ''; + this.objectStore = {}; + this.executingTransaction = {}; + this.storeUsingDbInstance = {}; + this.transactionFinish = (TableName) => { + delete this.storeUsingDbInstance[TableName]; + delete this.storeUsingDbInstance[TableName]; + if (Object.keys(this.storeUsingDbInstance).length == 0) { + this.dbInstance.close(); + delete this.dbInstance; + } + }; + this.config = config; + this.name = this.config.databaseName; + for (let store of config.stores) { + this.objectStore[store.name] = new ObjectStore({ store }); + this.objectStore[store.name].transactionFinish = this.transactionFinish; + } + } + async getDatabaseConnection() { + if (!this.dbInstance) { + this.dbInstance = await IndexedDBConnector.connect(this.config); + } + return this.dbInstance; + } + async getOrCreateTransaction({ TableName, queryId }, mode, callback) { + const Database = await this.getDatabaseConnection(); + this.storeUsingDbInstance[TableName] = true; + this.objectStore[TableName].getOrCreateTransaction({ Database, queryId }, "readonly", callback); + } + getObjectStore(TableName) { + return this.objectStore[TableName]; + } + async migrate() { + return await IndexedDBConnector.migrate(this.config); + } +} diff --git a/src/plugin/src/connection/indexedDb/indexedb.d.ts b/src/plugin/src/connection/indexedDb/indexedb.d.ts new file mode 100644 index 000000000..c8367e421 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/indexedb.d.ts @@ -0,0 +1,38 @@ +import { DatabaseSchema, TableSchema } from "../../models/register-modal.interface.js"; +import { Method } from "../../models/model.interface.js"; +import { Database } from "./database.js"; +declare class indexedDBInterface { + getActions: (TableName: string, Database: Database, queryId: string) => { + getByID: (id: string | number) => Promise; + getOneByIndex: (keyPath: string, value: string | number) => Promise; + getAll: () => Promise; + add: ({ value, key, add, index }: { + value: any; + key: any; + add: any; + index: any; + }) => Promise; + update: ({ value, key }: { + value: any; + key?: any; + }) => Promise; + deleteByID: (id: any) => Promise; + deleteAll: () => Promise; + }; + requestHandler: (TableName: string, DatabaseName: string, queryId: any, PostMessage?: typeof postMessage) => { + select: (methods: Method[]) => Promise; + update: (methods: Method[]) => Promise; + delete: (methods: Method[]) => Promise; + insert: (methods: Method[]) => Promise; + migrate: ({ DatabaseSchema, TableSchema }: { + DatabaseSchema: DatabaseSchema; + TableSchema: TableSchema; + }) => Promise; + trigger: ({ type, subscribe }: { + type: any; + subscribe: any; + }) => Promise; + }; +} +export declare const indexedDB: indexedDBInterface; +export {}; diff --git a/src/plugin/src/connection/indexedDb/indexedb.js b/src/plugin/src/connection/indexedDb/indexedb.js new file mode 100644 index 000000000..716492ccd --- /dev/null +++ b/src/plugin/src/connection/indexedDb/indexedb.js @@ -0,0 +1,352 @@ +import { SqlObject } from "../../sql/sqlObject/sqlObject.js"; +import { PostMessage as PostMessageWorker } from "./postMessage.js"; +import { DatabaseManager } from "./DatabaseManager.js"; +// inspire by https://github.com/hc-oss/use-indexeddb +class indexedDBInterface { + constructor() { + this.getActions = (TableName, Database, queryId) => { + const DatabaseName = Database.name; + return { + getByID: (id) => { + return new Promise((resolve, reject) => { + Database.getOrCreateTransaction({ TableName, queryId }, 'readonly', (transaction) => { + let objectStore = transaction.objectStore(TableName); + let request = objectStore.get({ id }); + request.onsuccess = async (e) => { + resolve(e.target.result); + }; + }); + }); + }, + getOneByIndex: (keyPath, value) => { + return new Promise((resolve, reject) => { + Database.getOrCreateTransaction({ TableName, queryId }, 'readonly', (transaction) => { + let objectStore = transaction.objectStore(TableName); + let request = objectStore.index({ keyPath, value }); + request.onsuccess = async (e) => { + resolve(e.target.result); + }; + }); + }); + }, + // getManyByIndex:(keyPath: string, value: string | number) => { + // return new Promise((resolve, reject) => { + // this.getConnection(DatabaseName) + // .then(db => { + // this.validateBeforeTransaction(db, TableName, reject); + // let tx = this.createTransaction(db, "readonly", TableName, resolve, reject); + // let objectStore = tx.objectStore(TableName); + // let index = objectStore.index(keyPath); + // let request = index.getAll(value); + // request.onsuccess = (e: any) => { + // resolve(e.target.result); + // }; + // }) + // .catch(reject); + // }); + // }, + getAll: () => { + return new Promise((resolve, reject) => { + Database.getOrCreateTransaction({ TableName, queryId }, 'readonly', (transaction) => { + let objectStore = transaction.objectStore(TableName); + let request = objectStore.getAll(); + request.onsuccess = async (e) => { + resolve(e.target.result); + }; + }); + }); + }, + add: ({ value, key, add, index }) => { + return new Promise((resolve, reject) => { + Database.getOrCreateTransaction({ TableName, queryId }, 'readwrite', (transaction) => { + let objectStore = transaction.objectStore(TableName); + let request = objectStore.add({ value }); + request.onsuccess = async (e) => { + const id = e.target.result; + add(id, index); + resolve(true); + }; + request.onerror = (e) => { + let data = { + error: e.target['error'] + }; + resolve(true); + }; + }); + }); + }, + update: ({ value, key = undefined }) => { + return new Promise((resolve, reject) => { + Database.getOrCreateTransaction({ TableName, queryId }, 'readwrite', (transaction) => { + let objectStore = transaction.objectStore(TableName); + let request = objectStore.put({ value, key }); + request.onsuccess = async (e) => { + resolve(e.target.result); + }; + request.onerror = (e) => { + let data = { + error: e.target['error'] + }; + resolve(data); + }; + }); + }); + }, + deleteByID: (id) => { + return new Promise((resolve, reject) => { + Database.getOrCreateTransaction({ TableName, queryId }, 'readwrite', (transaction) => { + let objectStore = transaction.objectStore(TableName); + let request = objectStore.delete({ id }); + request.onsuccess = async (e) => { + resolve(e.target.result); + }; + request.onerror = (e) => { + let data = { + error: e.target['error'] + }; + resolve(data); + }; + }); + }); + }, + deleteAll: () => { + return new Promise((resolve, reject) => { + Database.getOrCreateTransaction({ TableName, queryId }, 'readwrite', (transaction) => { + let objectStore = transaction.objectStore(TableName); + let request = objectStore.clear(); + request.onsuccess = async (e) => { + resolve(e.target.result); + }; + }); + }); + } + }; + }; + this.requestHandler = (TableName, DatabaseName, queryId, PostMessage = PostMessageWorker) => { + const db = DatabaseManager.getDb(DatabaseName); + return { + select: async (methods) => { + const TableSchema = db.objectStore[TableName].config; + if (methods[0].methodName == 'all') { + PostMessage({ + run: 'callback', + queryId: queryId, + value: await this.getActions(TableName, db, queryId).getAll() + }); + } + else if (methods[0].methodName == 'get') { + const args = methods[0].arguments; + if (Object.keys(args).length == 1) { + const key = Object.keys(args)[0]; + const value = args[key]; + if (TableSchema.id.keyPath == key) { + PostMessage({ + run: 'callback', + queryId: queryId, + value: await this.getActions(TableName, db, queryId).getByID(value) + }); + } + else { + PostMessage({ + run: 'callback', + queryId: queryId, + value: await this.getActions(TableName, db, queryId).getOneByIndex(key, value) + }); + } + } + else if (methods[0].arguments[TableSchema.id.keyPath]) { + PostMessage({ + run: 'callback', + queryId: queryId, + value: await this.getActions(TableSchema.name, db, queryId).getByID(args[TableSchema.id.keyPath]) + }); + } + } + else if (methods[methods.length - 1].methodName == 'execute') { + const sqlObject = new SqlObject(TableSchema, methods); + //await this.getActions(TableSchema.name, config, queryId).openCursor(async(event: any) => { + //var cursor = event.target.result; + //if(cursor) { + const rows = await this.getActions(TableName, db, queryId).getAll(); + for (const row of rows) { + //const row = cursor.value + await sqlObject.runFirstMethod(row); + //cursor.continue(); + } + //} else { + sqlObject.doneRunFirstMethod(); + sqlObject.run(); + PostMessage({ + run: 'callback', + queryId: queryId, + value: sqlObject.firstMethod.rows + }); + //} + //}) + } + else if (methods[methods.length - 1].methodName == 'first') { + return new Promise(async (resolve, reject) => { + PostMessage({ + run: 'callback', + queryId: queryId, + value: (await this.getActions(TableName, db, queryId).getAll())[0] + }); + }); + } + }, + update: async (methods) => { + const TableSchema = db.objectStore[TableName].config; + if (methods[0].methodName == 'save') { + const args = methods[0].arguments; + const idFieldName = TableSchema.id.keyPath; + const idValue = args[idFieldName]; + if (idValue) { + this.getActions(TableSchema.name, db, queryId).update({ value: args }); + } + else { + this.getActions(TableSchema.name, db, queryId).update({ value: args, key: idValue }); + } + db.getOrCreateTransaction({ TableName: TableName, queryId }, 'readwrite', (transaction) => { + PostMessage({ + run: 'callback', + queryId: queryId, + value: true + }); + transaction.done(); + }); + } + else if (methods[0].methodName != 'update' && methods[methods.length - 1].methodName == 'update') { + const argsToUpdate = methods[methods.length - 1].arguments; + const customMethods = Object.create(methods); + customMethods[methods.length - 1].methodName = 'execute'; + await this.requestHandler(TableSchema.name, DatabaseName, queryId, ({ value }) => { + const rows = value; + for (let row of rows) { + const updateRow = Object.assign(row, argsToUpdate); + this.getActions(TableSchema.name, db, queryId).update({ value: updateRow }); + } + db.getOrCreateTransaction({ TableName: TableName, queryId }, 'readwrite', (transaction) => { + PostMessage({ + run: 'callback', + queryId: queryId, + value: true + }); + transaction.done(); + }); + }).select(customMethods); + } + else if (methods[0].methodName == 'update') { + const argsToUpdate = methods[0].arguments; + const idFieldName = TableSchema.id.keyPath; + //await this.getActions(TableSchema.name, config).update(argsToUpdate) + const idValue = argsToUpdate[idFieldName]; + if (idValue) { + this.getActions(TableSchema.name, db, queryId).update({ value: argsToUpdate }); + } + else { + this.getActions(TableSchema.name, db, queryId).update({ value: argsToUpdate, key: idValue }); + } + db.getOrCreateTransaction({ TableName: TableSchema.name, queryId }, 'readwrite', (transaction) => { + PostMessage({ + run: 'callback', + queryId: queryId, + value: true + }); + transaction.done(); + }); + } + }, + delete: async (methods) => { + const TableSchema = db.objectStore[TableName].config; + if (methods[methods.length - 1].methodName == 'delete' && + methods[methods.length - 1].arguments == null) { + const customMethods = Object.create(methods); + customMethods[methods.length - 1].methodName = 'execute'; + await this.requestHandler(TableName, DatabaseName, queryId, ({ value }) => { + const rows = value; + for (let row of rows) { + const id = row[TableSchema.id.keyPath]; + this.getActions(TableSchema.name, db, queryId).deleteByID(id); + } + db.getOrCreateTransaction({ TableName: TableName, queryId }, 'readwrite', (transaction) => { + PostMessage({ + run: 'callback', + queryId: queryId, + value: rows.length + }); + transaction.done(); + }); + }).select(customMethods); + } + 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]; + PostMessage({ + run: 'callback', + queryId: queryId, + value: await this.getActions(TableName, db, queryId).deleteByID(idValue) + }); + } + else if (methods[methods.length - 1].methodName == 'delete' && + methods[methods.length - 1].arguments == '*') { + PostMessage({ + run: 'callback', + queryId: queryId, + value: await this.getActions(TableName, db, queryId).deleteAll() + }); + } + }, + insert: async (methods) => { + const rows = methods[0].arguments; + const add = (id, index) => { + PostMessage({ + run: 'callback', + queryId: queryId, + value: { id, index } + }); + }; + for (let i = 0; i < rows.length; i++) { + const insert = rows[i]; + this.getActions(TableName, db, queryId).add({ value: insert, key: null, index: i, add }); + } + db.getOrCreateTransaction({ TableName: TableName, queryId }, 'readwrite', (transaction) => { + PostMessage({ + run: 'done', + queryId: queryId, + value: true + }); + transaction.done(); + }); + }, + migrate: async ({ DatabaseSchema, TableSchema }) => { + await DatabaseManager.prepare(DatabaseSchema); + PostMessage({ + run: 'callback', + queryId: queryId, + value: true + }); + }, + trigger: async ({ type, subscribe }) => { + const objectStore = db.getObjectStore(TableName); + if (type == 'transactionOnCommit') { + if (subscribe) { + PostMessage(objectStore.transactionOnCommitSubscribe(TableName, DatabaseName, queryId)); + } + else { + PostMessage(objectStore.transactionOnCommitUnSubscribe(TableName, DatabaseName, queryId)); + } + } + else if (type == 'trigger') { + PostMessage({ + run: 'callback', + queryId: queryId, + value: true + }); + } + } + }; + }; + } +} +export const indexedDB = new indexedDBInterface(); diff --git a/src/plugin/src/connection/indexedDb/objectStore.d.ts b/src/plugin/src/connection/indexedDb/objectStore.d.ts new file mode 100644 index 000000000..ee485e308 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/objectStore.d.ts @@ -0,0 +1,61 @@ +import { TableSchema } from "../../models/register-modal.interface.js"; +import { transaction } from './transaction.js'; +export declare class ObjectStore { + transactions: { + callback: Function; + queryId: string; + mode: string; + }[]; + parallelTransactions: { + callback: Function; + queryId: string; + mode: string; + DatabaseName: string; + }[]; + transactionsToCommit: { + callback: Function; + queryId: string; + mode: string; + }[]; + dbInstance: IDBDatabase; + txInstance: { + IDBTransaction: IDBTransaction; + IDBTransactionMode: IDBTransactionMode; + active: boolean; + }; + executingTransaction: boolean; + txInstanceMode: object; + storeCache: { + [store: string]: object[]; + }; + transactionOnCommit: { + [queryId: string]: Object; + }; + name: string; + transactionFinish: (TableName: any) => void; + config: TableSchema; + constructor({ store }: { + store: TableSchema; + }); + transactionTrigger(): Promise; + executeTransaction(): void; + parallelExecuteTransaction(): void; + getOrCreateTransaction({ queryId, Database }: { + queryId: any; + Database: any; + }, mode: IDBTransactionMode, callback: (transaction: transaction) => void): void; + private createTransaction; + private validateBeforeTransaction; + transactionOnCommitSubscribe(TableName: string, DatabaseName: string, SubscriptionName: any): { + run: string; + subscription: boolean; + queryId: any; + value: boolean; + }; + transactionOnCommitUnSubscribe(TableName: any, DatabaseName: string, SubscriptionName: any): { + run: string; + subscription: boolean; + queryId: any; + value: boolean; + }; +} diff --git a/src/plugin/src/connection/indexedDb/objectStore.js b/src/plugin/src/connection/indexedDb/objectStore.js new file mode 100644 index 000000000..9bdd3ab62 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/objectStore.js @@ -0,0 +1,175 @@ +import { transaction } from './transaction.js'; +import { PostMessage } from "./postMessage.js"; +// inspire by https://github.com/hc-oss/use-indexeddb +export class ObjectStore { + constructor({ store }) { + this.transactions = []; + this.parallelTransactions = []; + this.transactionsToCommit = []; + this.executingTransaction = false; + this.txInstanceMode = {}; + this.storeCache = {}; + this.transactionOnCommit = {}; + this.name = ''; + this.transactionFinish = (TableName) => { }; + this.name = store.name; + this.config = store; + } + async transactionTrigger() { + var _a, _b; + if (this.txInstanceMode['readwrite']) { + try { + (_b = (_a = this.txInstance.IDBTransaction) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a); + this.transactionsToCommit = []; + (async () => { + for (let [queryId, value] of Object.entries(this.transactionOnCommit)) { + PostMessage({ + run: 'callback', + queryId: queryId, + value: true + }); + } + })(); + } + catch (error) { + // no commit need + } + } + } + executeTransaction() { + const { mode, callback } = this.transactions[0]; + this.txInstanceMode[mode] = true; + const done = async () => { + const transaction = this.transactions.shift(); + this.transactionsToCommit.push(transaction); + if (this.transactions.length == 0) { + this.executingTransaction = false; + this.transactionTrigger(); + delete this.txInstance; + this.txInstanceMode[mode] = false; + this.transactionFinish(this.name); + } + else { + this.executeTransaction(); + } + }; + const doneButFailed = async () => { + var _a, _b; + this.transactions.shift(); + this.txInstance.active = false; + if (this.transactionsToCommit.length >= 1) { + try { + (_b = (_a = this.txInstance.IDBTransaction) === null || _a === void 0 ? void 0 : _a.commit) === null || _b === void 0 ? void 0 : _b.call(_a); + this.transactionsToCommit = []; + } + catch (error) { } + } + if (this.transactions.length >= 1) { + const tx = this.createTransaction(this.dbInstance, "readwrite", (onerror) => { }, (oncomplete) => { }, (onabort) => { }); + this.txInstance = { + IDBTransaction: tx, + active: true, + IDBTransactionMode: "readwrite" + }; + this.executeTransaction(); + } + else { + this.transactionTrigger(); + } + }; + this.validateBeforeTransaction(this.dbInstance, (data) => { + }); + const transactionInstance = new transaction({ + store: this.name, + done, + doneButFailed, + db: this.dbInstance, + tx: this.txInstance.IDBTransaction + }); + callback(transactionInstance); + } + parallelExecuteTransaction() { + const { mode, callback } = this.parallelTransactions.shift(); + this.txInstanceMode[mode] = true; + const tx = this.createTransaction(this.dbInstance, "readonly", (onerror) => { }, (oncomplete) => { }, (onabort) => { }); + const done = async () => { + if (this.parallelTransactions.length == 0) { + this.txInstanceMode[mode] = false; + } + }; + const doneButFailed = async () => { + if (this.parallelTransactions.length == 0) { + this.txInstanceMode[mode] = false; + } + }; + const transactionInstance = new transaction({ + store: this.name, + done, + doneButFailed, + db: this.dbInstance, + tx: this.txInstance.IDBTransaction + }); + callback(transactionInstance); + } + getOrCreateTransaction({ queryId, Database }, mode, callback) { + //if(mode == 'readonly' && !this.txInstance) { + // this.parallelTransactions.push({DatabaseName, queryId, mode, callback}) + // this.parallelExecuteTransaction(DatabaseName, TableName) + //} else { + this.transactions.push({ queryId, mode, callback }); + //} + if (this.executingTransaction == false) { + this.executingTransaction = true; + const tx = this.createTransaction(Database, "readwrite", (onerror) => { }, (oncomplete) => { }, (onabort) => { }); + this.dbInstance = Database; + if (!this.txInstance) { + this.txInstance = { + IDBTransaction: tx, + active: true, + IDBTransactionMode: "readwrite" + }; + } + this.txInstance.IDBTransaction = tx; + this.txInstance.active = true; + // this.dbInstanceUsing = true + this.executeTransaction(); + } + else { + if (mode == 'readonly') { + } + } + } + createTransaction(db, dbMode, onerror, oncomplete, onabort) { + let tx = db.transaction(this.name, dbMode); + tx.onerror = onerror; + tx.oncomplete = oncomplete; + tx.onabort = onabort; + return tx; + } + validateBeforeTransaction(db, reject) { + if (!db) { + reject("Queried before opening connection"); + } + // if (!this.validateStore(db, storeName)) { + // reject(`Store ${storeName} not found`); + // } + } + transactionOnCommitSubscribe(TableName, DatabaseName, SubscriptionName) { + this.transactionOnCommit[SubscriptionName] = {}; + return { + run: 'callback', + subscription: true, + queryId: SubscriptionName, + value: true + }; + } + transactionOnCommitUnSubscribe(TableName, DatabaseName, SubscriptionName) { + delete this.transactionOnCommit[SubscriptionName]; + return { + run: 'callback', + subscription: false, + queryId: SubscriptionName, + value: true + }; + } +} diff --git a/src/plugin/src/connection/indexedDb/postMessage.d.ts b/src/plugin/src/connection/indexedDb/postMessage.d.ts new file mode 100644 index 000000000..cd314f79d --- /dev/null +++ b/src/plugin/src/connection/indexedDb/postMessage.d.ts @@ -0,0 +1 @@ +export declare let PostMessage: typeof postMessage; diff --git a/src/plugin/src/connection/indexedDb/postMessage.js b/src/plugin/src/connection/indexedDb/postMessage.js new file mode 100644 index 000000000..ad9f84fc9 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/postMessage.js @@ -0,0 +1,17 @@ +var _a; +import { taskHolder } from '../taskHolder.js'; +export let PostMessage; +try { + if (!window || (window === null || window === void 0 ? void 0 : window.document) === undefined) { + // web worker + PostMessage = (_a = (this || {})) === null || _a === void 0 ? void 0 : _a.postMessage; + } + else { + // main thread + PostMessage = taskHolder.onmessage; + } +} +catch (error) { + // web worker + PostMessage = postMessage; +} diff --git a/src/plugin/src/connection/indexedDb/transaction.d.ts b/src/plugin/src/connection/indexedDb/transaction.d.ts new file mode 100644 index 000000000..f36231966 --- /dev/null +++ b/src/plugin/src/connection/indexedDb/transaction.d.ts @@ -0,0 +1,52 @@ +declare class transactionRequest { + type: string; + value: any; + key: any; + result: any; + store: string; + onsuccessFunc: Function; + onerrorFunc: Function; + set onsuccess(func: any); + set onerror(func: any); +} +export declare class transaction { + store: any; + done: Function; + doneButFailed: Function; + tx: IDBTransaction; + trigger: { + beforeInsert: boolean; + afterInsert: boolean; + }; + constructor({ store, done, db, tx, doneButFailed }: { + store: any; + done: any; + db: any; + tx: any; + doneButFailed: any; + }); + request: any[]; + FinishRequest: any[]; + objectStore: (currentStore: any) => { + add: ({ value }: { + value: any; + }) => transactionRequest; + getAll: () => transactionRequest; + put: ({ value, key }: { + value: any; + key?: any; + }) => transactionRequest; + clear: () => transactionRequest; + delete: ({ id }: { + id: any; + }) => transactionRequest; + get: ({ id }: { + id: any; + }) => transactionRequest; + index: ({ keyPath, value }: { + keyPath: any; + value: any; + }) => transactionRequest; + }; +} +export {}; diff --git a/src/plugin/src/connection/indexedDb/transaction.js b/src/plugin/src/connection/indexedDb/transaction.js new file mode 100644 index 000000000..9ebcc771c --- /dev/null +++ b/src/plugin/src/connection/indexedDb/transaction.js @@ -0,0 +1,142 @@ +class transactionRequest { + set onsuccess(func) { + this.onsuccessFunc = func; + } + set onerror(func) { + this.onerrorFunc = func; + } +} +export class transaction { + constructor({ store, done, db, tx, doneButFailed }) { + this.trigger = { + beforeInsert: false, + afterInsert: false, + }; + this.request = []; + this.FinishRequest = []; + this.objectStore = (currentStore) => { + return { + add: ({ value }) => { + const request = new transactionRequest(); + request.type = 'add'; + request.value = value; + this.request.push(request); + let objectStore = this.tx.objectStore(currentStore); + let addGetList = objectStore.add(value); + addGetList.onsuccess = async (e) => { + request === null || request === void 0 ? void 0 : request.onsuccessFunc(e); + this.done(); + }; + addGetList.onerror = async (e) => { + request === null || request === void 0 ? void 0 : request.onerrorFunc(e); + this.doneButFailed(); + }; + return request; + }, + getAll: () => { + const request = new transactionRequest(); + this.request.push(request); + request.type = 'getAll'; + let objectStore = this.tx.objectStore(currentStore); + let getList = objectStore.getAll(); + getList.onsuccess = (e) => { + this.done(); + request === null || request === void 0 ? void 0 : request.onsuccessFunc(e); + }; + getList.onerror = (e) => { + this.doneButFailed(); + request === null || request === void 0 ? void 0 : request.onerrorFunc(e); + }; + return request; + }, + put: ({ value, key = undefined }) => { + const request = new transactionRequest(); + this.request.push(request); + request.type = 'put'; + this.request.push(request); + let objectStore = this.tx.objectStore(currentStore); + let updateRequest = objectStore.put(value, key); + updateRequest.onsuccess = async (e) => { + request === null || request === void 0 ? void 0 : request.onsuccessFunc(e); + this.done(); + }; + updateRequest.onerror = async (e) => { + request === null || request === void 0 ? void 0 : request.onerrorFunc(e); + this.doneButFailed(); + }; + return request; + }, + clear: () => { + const request = new transactionRequest(); + this.request.push(request); + request.type = 'clear'; + let objectStore = this.tx.objectStore(currentStore); + objectStore.clear(); + this.tx.oncomplete = async (e) => { + request === null || request === void 0 ? void 0 : request.onsuccessFunc(e); + this.done(); + }; + this.tx.onerror = async (e) => { + request === null || request === void 0 ? void 0 : request.onerrorFunc(e); + this.doneButFailed(); + }; + return request; + }, + delete: ({ id }) => { + const request = new transactionRequest(); + this.request.push(request); + request.type = 'delete'; + let objectStore = this.tx.objectStore(currentStore); + let deleteRequest = objectStore.delete(id); + deleteRequest.onsuccess = async (e) => { + request === null || request === void 0 ? void 0 : request.onsuccessFunc(e); + this.done(); + }; + deleteRequest.onerror = async (e) => { + request === null || request === void 0 ? void 0 : request.onerrorFunc(e); + this.doneButFailed(); + }; + return request; + }, + get: ({ id }) => { + const request = new transactionRequest(); + this.request.push(request); + request.type = 'get'; + let objectStore = this.tx.objectStore(currentStore); + let getRequest = objectStore.get(id); + getRequest.onsuccess = (e) => { + this.done(); + request === null || request === void 0 ? void 0 : request.onsuccessFunc(e); + }; + getRequest.onerror = (e) => { + this.doneButFailed(); + request === null || request === void 0 ? void 0 : request.onerrorFunc(e); + }; + return request; + }, + index: ({ keyPath, value }) => { + const request = new transactionRequest(); + this.request.push(request); + request.type = 'get'; + let objectStore = this.tx.objectStore(currentStore); + let targe = objectStore.index(keyPath); + let getRequest = targe.get(value); + getRequest.onsuccess = (e) => { + this.done(); + request === null || request === void 0 ? void 0 : request.onsuccessFunc(e); + }; + getRequest.onerror = (e) => { + this.doneButFailed(); + request === null || request === void 0 ? void 0 : request.onerrorFunc(e); + }; + return request; + } + }; + }; + // currentStore = store + this.doneButFailed = doneButFailed; + this.done = done; + // this.db = db + this.tx = tx; + } +} diff --git a/src/plugin/src/connection/indexedDb/triggers/triggers.d.ts b/src/plugin/src/connection/indexedDb/triggers/triggers.d.ts new file mode 100644 index 000000000..bb459e30c --- /dev/null +++ b/src/plugin/src/connection/indexedDb/triggers/triggers.d.ts @@ -0,0 +1,18 @@ +interface Trigger { + callback: Function; + SubscriptionName: string; +} +export declare class triggerSignal { + static beforeInsertExist(Model: any): Trigger; + static beforeInsert(instance: any): Promise; + static AfterInsertExist(Model: any): Trigger; + static AfterInsert(instance: any): Promise; + static AfterDeleteExist(Model: any): Trigger; + static AfterDelete(instance: string, { modelName, databaseName }: any): Promise; + static BeforeDeleteExist(Model: any): Trigger; + static BeforeDelete(instance: string, { modelName, databaseName }: { + modelName: any; + databaseName: any; + }): Promise; +} +export {}; diff --git a/src/plugin/src/connection/indexedDb/triggers/triggers.js b/src/plugin/src/connection/indexedDb/triggers/triggers.js new file mode 100644 index 000000000..40019b83c --- /dev/null +++ b/src/plugin/src/connection/indexedDb/triggers/triggers.js @@ -0,0 +1,51 @@ +let triggerBeforeInsert = {}; +let triggerAfterInsert = {}; +let triggerBeforeDelete = {}; +let triggerAfterDelete = {}; +function setUpSignal() { } +export class triggerSignal { + static beforeInsertExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerBeforeInsert === null || triggerBeforeInsert === void 0 ? void 0 : triggerBeforeInsert[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async beforeInsert(instance) { + const ModelName = instance.getModelName(); + const databaseName = instance.getDBSchema().databaseName; + postMessage({ + queryId: triggerBeforeInsert[databaseName][ModelName].SubscriptionName, + value: instance + }); + } + static AfterInsertExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerAfterInsert === null || triggerAfterInsert === void 0 ? void 0 : triggerAfterInsert[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async AfterInsert(instance) { + const ModelName = instance.getModelName(); + const databaseName = instance.getDBSchema().databaseName; + postMessage({ + queryId: triggerBeforeInsert[databaseName][ModelName].SubscriptionName, + value: instance + }); + } + static AfterDeleteExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerAfterDelete === null || triggerAfterDelete === void 0 ? void 0 : triggerAfterDelete[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async AfterDelete(instance, { modelName, databaseName }) { + } + static BeforeDeleteExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerBeforeDelete === null || triggerBeforeDelete === void 0 ? void 0 : triggerBeforeDelete[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async BeforeDelete(instance, { modelName, databaseName }) { + } +} diff --git a/src/plugin/src/connection/intreface.d.ts b/src/plugin/src/connection/intreface.d.ts new file mode 100644 index 000000000..25f0f8ec3 --- /dev/null +++ b/src/plugin/src/connection/intreface.d.ts @@ -0,0 +1,2 @@ +export declare type actionParam = 'insert' | 'update' | 'delete' | 'select' | 'migrate' | 'trigger'; +export declare type dbType = 'indexedDB' | 'localStorage'; diff --git a/src/plugin/src/connection/intreface.js b/src/plugin/src/connection/intreface.js new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/src/plugin/src/connection/intreface.js @@ -0,0 +1 @@ +export {}; diff --git a/src/plugin/src/connection/localStorage/localStorage.d.ts b/src/plugin/src/connection/localStorage/localStorage.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/connection/localStorage/localStorage.js b/src/plugin/src/connection/localStorage/localStorage.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/connection/memory/db.d.ts b/src/plugin/src/connection/memory/db.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/connection/memory/db.js b/src/plugin/src/connection/memory/db.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/connection/taskHolder.d.ts b/src/plugin/src/connection/taskHolder.d.ts new file mode 100644 index 000000000..ff71128eb --- /dev/null +++ b/src/plugin/src/connection/taskHolder.d.ts @@ -0,0 +1,17 @@ +export interface TaskHolderInterface { + type?: 'response' | 'Register'; + queryId: string; + params: any; + method: 'execute' | 'migrate'; + callback: Function; + done?: Function; +} +declare class _taskHolder { + private tasks; + register(data: TaskHolderInterface): void; + finish(queryId: string): void; + updateFunction(queryId: any, run: any, func: Function): void; + onmessage(data: any): Promise; +} +export declare const taskHolder: _taskHolder; +export {}; diff --git a/src/plugin/src/connection/taskHolder.js b/src/plugin/src/connection/taskHolder.js new file mode 100644 index 000000000..c7ad0ead8 --- /dev/null +++ b/src/plugin/src/connection/taskHolder.js @@ -0,0 +1,24 @@ +class _taskHolder { + constructor() { + this.tasks = {}; + } + register(data) { + this.tasks[data.queryId] = data; + } + finish(queryId) { + try { + delete this.tasks[queryId]; + } + catch (error) { } + } + updateFunction(queryId, run, func) { + this.tasks[queryId][run] = (message) => { + func(message.value); + }; + } + async onmessage(data) { + const value = this.tasks[data.queryId]; + value[data.run](data); + } +} +export const taskHolder = new _taskHolder(); diff --git a/src/plugin/src/connection/worker.d.ts b/src/plugin/src/connection/worker.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/src/plugin/src/connection/worker.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/src/plugin/src/connection/worker.js b/src/plugin/src/connection/worker.js new file mode 100644 index 000000000..763c58e5d --- /dev/null +++ b/src/plugin/src/connection/worker.js @@ -0,0 +1,10 @@ +import { indexedDB } from './indexedDb/indexedb.js'; +onmessage = async (oEvent) => { + const { TableName, DatabaseName, queryId, action, arg } = oEvent.data; + indexedDB.requestHandler(TableName, DatabaseName, queryId)[action](arg).then((result) => { + // console.log('result', result) + // postMessage(result) + }, (error) => { + console.log('error', error); + }); +}; diff --git a/src/plugin/src/connection/workerManager.d.ts b/src/plugin/src/connection/workerManager.d.ts new file mode 100644 index 000000000..ee50df7ed --- /dev/null +++ b/src/plugin/src/connection/workerManager.d.ts @@ -0,0 +1,18 @@ +export interface WsRegister { + type?: 'response' | 'Register'; + queryId: string; + params: any; + method: 'execute' | 'migrate'; + callback: Function; + done?: Function; +} +declare class _WorkerManager { + private myWorker; + webWorkerModuleSupport: boolean; + constructor(); + supportsWorkerType(): boolean; + register(data: WsRegister): string; + private onmessage; +} +export declare const WorkerManager: _WorkerManager; +export {}; diff --git a/src/plugin/src/connection/workerManager.js b/src/plugin/src/connection/workerManager.js new file mode 100644 index 000000000..d4bf5ebd5 --- /dev/null +++ b/src/plugin/src/connection/workerManager.js @@ -0,0 +1,40 @@ +import { taskHolder } from './taskHolder.js'; +class _WorkerManager { + constructor() { + this.webWorkerModuleSupport = false; + this.webWorkerModuleSupport = this.supportsWorkerType(); + if (this.webWorkerModuleSupport) { + this.myWorker = new Worker(new URL('./worker.js', import.meta.url), { type: "module" }); + this.myWorker.onmessage = (oEvent) => { + const data = oEvent.data; + this.onmessage(data); + }; + this.myWorker.onerror = (error) => { + console.log('myWorker', error); + }; + } + } + // https://stackoverflow.com/a/62963963/14115342 + supportsWorkerType() { + var _a; + let supports = false; + const tester = { + get type() { return supports = true; } // it's been called, it's supported + }; + try { + const worker = new Worker('blob://', tester); + } + finally { + return supports && ((_a = (window || {})) === null || _a === void 0 ? void 0 : _a.document); + } + } + register(data) { + this.myWorker.postMessage(data.params); + taskHolder.register(data); + return data.queryId; + } + async onmessage(data) { + taskHolder.onmessage(data); + } +} +export const WorkerManager = new _WorkerManager(); diff --git a/src/plugin/src/index.d.ts b/src/plugin/src/index.d.ts new file mode 100644 index 000000000..145c2e4a0 --- /dev/null +++ b/src/plugin/src/index.d.ts @@ -0,0 +1,49 @@ +import { Model } from './models/model.js'; +import { LocalStorage } from './models/model.js'; +import { ModelReader } from './models/model.reader.js'; +import { registerModel, migrate } from './models/register-model.js'; +export declare const models: { + Value(arg: any): {}; + preset(): any; + core: { + localStorage: { + rewrite: { + rewriteGet: { + connect(callback: (params: import("./models/signal.interface.js").params) => void, models: (typeof LocalStorage)[]): void; + }; + rewriteSave: { + connect(callback: (params: import("./models/signal.interface.js").params) => void, models: (typeof LocalStorage)[]): void; + }; + rewriteDelete: { + connect(callback: (params: import("./models/signal.interface.js").params) => void, models: (typeof LocalStorage)[]): void; + }; + hasRewriteGet(ModalName: string): boolean; + hasRewriteSave(ModalName: string): boolean; + hasRewriteDelete(ModalName: string): boolean; + }; + }; + }; + CharField(data?: import("./models/field/interface.js").CharFieldParams): string; + BooleanField(data?: import("./models/field/interface.js").BooleanFieldParams): boolean; + TextField(data?: import("./models/field/interface.js").TextFieldParams): string; + IntegerField(data?: import("./models/field/interface.js").IntegerFieldParams): number; + DateField(data?: import("./models/field/interface.js").DateFieldParams): Date; + DateTimeField(data?: import("./models/field/interface.js").DateTimeFieldParams): string; + BigIntegerField(data?: import("./models/field/interface.js").BigIntegerFieldParams): number; + AutoField(data?: import("./models/field/interface.js").AutoFieldParams): any; + OneToOneField(data: import("./models/field/interface.js").OneToOneFieldParams): string | number; + ForeignKey(data: import("./models/field/interface.js").ForeignKeyParams): string | number; + ManyToManyField(data?: import("./models/field/interface.js").ManyToManyFieldParams): string | number; + indexedDB: { + fields: { + JsonField: (data?: import("./models/field/interface.js").IndexedDBJsonFieldParams) => Object; + ArrayField: (data?: import("./models/field/interface.js").IndexedDBArrayFieldParams) => any[]; + }; + }; + Model: typeof Model; + LocalStorage: typeof LocalStorage; + read: typeof ModelReader.read; + migrate: typeof migrate; + register: typeof registerModel.register; +}; +export default models; diff --git a/src/plugin/src/index.js b/src/plugin/src/index.js new file mode 100644 index 000000000..2c927c2f0 --- /dev/null +++ b/src/plugin/src/index.js @@ -0,0 +1,19 @@ +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, migrate } from './models/register-model.js'; +import { rewrite } from './models/signal.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 {}; + } + }, + preset() { }, core: { + // signals + localStorage: { + rewrite + } + } }); +export default models; diff --git a/src/plugin/src/models/field/allFields.d.ts b/src/plugin/src/models/field/allFields.d.ts new file mode 100644 index 000000000..8ea37dd46 --- /dev/null +++ b/src/plugin/src/models/field/allFields.d.ts @@ -0,0 +1,140 @@ +import { FieldType } from '../../sql/query/interface.js'; +import { field } from './field.js'; +import { FieldKeys } from './fields.interface.js'; +import { AutoFieldParams, BooleanFieldParams, DateFieldParams, DateTimeFieldParams, ForeignKeyParams, IndexedDBArrayFieldParams, IndexedDBJsonFieldParams, IntegerFieldParams, ManyToManyFieldParams, OneToOneFieldParams } from './interface.js'; +import { BigIntegerFieldParams } from './interface.js'; +import { CharFieldParams } from './interface.js'; +import { TextFieldParams } from './interface.js'; +export declare class AutoField extends field { + fieldName: FieldKeys; + unique: boolean; + autoIncrement: boolean; + primaryKey?: boolean; + type: FieldType; + blank: boolean; + default?: any; + constructor(data?: AutoFieldParams); + valid(value: any): boolean; +} +export declare class BigIntegerField extends field { + fieldName: FieldKeys; + unique?: boolean; + primaryKey?: boolean; + blank?: boolean; + default?: any; + type: FieldType; + constructor(data?: BigIntegerFieldParams); + valid(value: any): boolean; +} +export declare class BooleanField extends field { + fieldName: FieldKeys; + unique?: boolean; + blank?: boolean; + default?: any; + constructor(data?: BooleanFieldParams); + valid(value: any): boolean; +} +export declare class CharField extends field { + fieldName: FieldKeys; + maxLength?: number | undefined; + minLength?: number | undefined; + choices?: any[] | undefined; + primaryKey?: boolean; + blank?: boolean; + default?: any; + unique?: boolean; + type: FieldType; + constructor(data?: CharFieldParams); + valid(value: any): boolean; +} +export declare class DateField extends field { + fieldName: FieldKeys; + type: FieldType; + blank?: boolean; + default?: any; + constructor(data?: DateFieldParams); + valid(value: any): boolean; +} +export declare class DateTimeField extends field { + fieldName: FieldKeys; + type: FieldType; + blank?: boolean; + default?: any; + constructor(data?: DateTimeFieldParams); + valid(value: any): boolean; +} +export declare class indexedDBArrayField extends field { + fieldName: FieldKeys; + type: FieldType; + blank?: boolean; + default?: any; + maxLength?: number; + minLength?: number; + size?: number; + private _field?; + get field(): any; + set field(value: any); + constructor(data?: IndexedDBArrayFieldParams); + valid(value: any): boolean; +} +export declare class indexedDBJsonField extends field { + fieldName: FieldKeys; + type: FieldType; + blank?: boolean; + default?: any; + null?: boolean; + constructor(data?: IndexedDBJsonFieldParams); + valid(value: any): boolean; +} +export declare class TextField extends field { + fieldName: FieldKeys; + maxLength?: number | undefined; + minLength?: number | undefined; + primaryKey?: boolean; + blank?: boolean; + default?: any; + type: FieldType.TEXT; + constructor(data?: TextFieldParams); + valid(value: any): boolean; +} +export declare class IntegerField extends field { + fieldName: FieldKeys; + unique?: boolean; + primaryKey?: boolean; + type: FieldType; + blank?: boolean; + default?: any; + constructor(data?: IntegerFieldParams); + valid(value: any): boolean; +} +export declare class ForeignKey extends field { + fieldName: FieldKeys; + model: any; + foreignKey: boolean; + blank?: boolean; + default?: any; + constructor(data?: ForeignKeyParams); + valid(value: any): boolean; +} +export declare class OneToOneField extends field { + fieldName: FieldKeys; + foreignKey: boolean; + model: any; + blank?: boolean; + default?: any; + onDelete?: any; + constructor(data?: OneToOneFieldParams); + contractor(contractor: any): void; + valid(value: any): boolean; +} +export declare class ManyToManyField extends field { + fieldName: FieldKeys; + model: any; + foreignKey: boolean; + blank?: boolean; + default?: any; + onDelete?: any; + unique?: boolean; + constructor(data?: ManyToManyFieldParams); + valid(value: any): boolean; +} diff --git a/src/plugin/src/models/field/allFields.js b/src/plugin/src/models/field/allFields.js new file mode 100644 index 000000000..10096f3ae --- /dev/null +++ b/src/plugin/src/models/field/allFields.js @@ -0,0 +1,253 @@ +import { FieldType } from '../../sql/query/interface.js'; +import { field } from './field.js'; +export class AutoField extends field { + constructor(data) { + super(); + this.fieldName = 'AutoField'; + this.unique = true; + this.autoIncrement = true; + this.type = FieldType.BIGINT; + this.blank = true; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'bigint' || typeof value == 'number')) { + return false; + } + else if (!((this === null || this === void 0 ? void 0 : this.blank) == undefined && this.isNull(value) == false)) { + return false; + } + return false; + } +} +export class BigIntegerField extends field { + constructor(data) { + super(); + this.fieldName = 'BigIntegerField'; + this.type = FieldType.BIGINT; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'bigint' || typeof value == 'number')) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + else if (!(value === null || value === undefined)) { + return false; + } + } + else if (!this.rules(this, value)) { + return false; + } + return true; + } +} +export class BooleanField extends field { + constructor(data) { + super(); + this.fieldName = 'BooleanField'; + Object.assign(this, data); + } + valid(value) { + if (typeof value != 'boolean') { + return false; + } + return true; + } +} +export class CharField extends field { + constructor(data) { + super(); + this.fieldName = 'CharField'; + this.type = FieldType.DATE; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'string')) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + else if (!(value === null || value === undefined)) { + return false; + } + } + else if (!this.rules(this, value)) { + return false; + } + return true; + } +} +export class DateField extends field { + constructor(data) { + super(); + this.fieldName = 'DateField'; + this.type = FieldType.DATE; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'string')) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + } + else if (!((this === null || this === void 0 ? void 0 : this.blank) == undefined && this.isNull(value) == false)) { + return true; + } + return false; + } +} +export class DateTimeField extends field { + constructor(data) { + super(); + this.fieldName = 'DateTimeField'; + this.type = FieldType.DATE; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'string')) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + } + else if (!((this === null || this === void 0 ? void 0 : this.blank) == undefined && this.isNull(value) == false)) { + return false; + } + return true; + } +} +export class indexedDBArrayField extends field { + constructor(data) { + super(); + this.fieldName = 'indexedDBArrayField'; + this.type = FieldType.ARRAY; + Object.assign(this, data); + } + get field() { + return this._field; + } + set field(value) { + this._field = value; + } + valid(value) { + if (!(Array.isArray(value))) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + } + else if (this.isNull(value) == true) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + } + else if (this.size) { + if (value.length != this.size) { + return false; + } + } + if (this.field) { + for (const e of value) { + if (!this.field.valid(e)) { + return false; + } + } + } + return true; + } +} +export class indexedDBJsonField extends field { + constructor(data) { + super(); + this.fieldName = 'indexedDBJsonField'; + this.type = FieldType.JSON; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'object' && Array.isArray(value) == false)) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + } + else if (this.isNull(value) == true) { + } + return true; + } +} +export class TextField extends field { + constructor(data) { + super(); + this.fieldName = 'TextField'; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'string')) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + else if (!(value === null || value === undefined)) { + return false; + } + } + else if (!this.rules(this, value)) { + return false; + } + return true; + } +} +export class IntegerField extends field { + constructor(data) { + super(); + this.fieldName = 'IntegerField'; + this.type = FieldType.INT; + Object.assign(this, data); + } + valid(value) { + if (!(typeof value == 'number')) { + if ((this === null || this === void 0 ? void 0 : this.blank) != true) { + return false; + } + else if (!(value === null || value === undefined)) { + return false; + } + } + else if (!this.rules(this, value)) { + return false; + } + return true; + } +} +export class ForeignKey extends field { + constructor(data) { + super(); + this.fieldName = 'ForeignKey'; + this.foreignKey = true; + Object.assign(this, data); + } + valid(value) { + return !this.isNull(value); + } +} +export class OneToOneField extends field { + constructor(data) { + super(); + this.fieldName = 'OneToOneField'; + this.foreignKey = true; + Object.assign(this, data); + } + contractor(contractor) { + throw new Error('Method not implemented.'); + } + valid(value) { + return !this.isNull(value); + } +} +export class ManyToManyField extends field { + constructor(data) { + super(); + this.fieldName = 'ManyToManyField'; + this.foreignKey = true; + Object.assign(this, data); + } + valid(value) { + return !this.isNull(value); + } +} diff --git a/src/plugin/src/models/field/field.d.ts b/src/plugin/src/models/field/field.d.ts new file mode 100644 index 000000000..900500008 --- /dev/null +++ b/src/plugin/src/models/field/field.d.ts @@ -0,0 +1,17 @@ +import { FieldKeys } from "./fields.interface"; +export declare class field { + fieldName: FieldKeys; + primaryKey?: any; + maxLength?: number | undefined; + minLength?: number | undefined; + choices?: any[] | undefined; + type: number; + blank?: boolean; + default?: any; + unique?: boolean; + foreignKey?: boolean; + model?: field; + get field(): boolean; + isNull(value: any): boolean; + rules(field: field, value: any): boolean; +} diff --git a/src/plugin/src/models/field/field.js b/src/plugin/src/models/field/field.js new file mode 100644 index 000000000..7d929b90e --- /dev/null +++ b/src/plugin/src/models/field/field.js @@ -0,0 +1,32 @@ +export class field { + get field() { + return true; + } + isNull(value) { + if (value == undefined) { + return true; + } + else if (value == null) { + return true; + } + else if (value == '' && !Array.isArray(value)) { + return true; + } + return false; + } + rules(field, value) { + if (field === null || field === void 0 ? void 0 : field.maxLength) { + if (value.toString().length > field.maxLength) { + return false; + } + } + if (field === null || field === void 0 ? void 0 : field.minLength) { + if (value.toString().length < field.minLength) { + return false; + } + } + if (field === null || field === void 0 ? void 0 : field.foreignKey) { + } + return true; + } +} diff --git a/src/plugin/src/models/field/fields.d.ts b/src/plugin/src/models/field/fields.d.ts new file mode 100644 index 000000000..3c92d0b0c --- /dev/null +++ b/src/plugin/src/models/field/fields.d.ts @@ -0,0 +1,18 @@ +import { AutoFieldParams, BigIntegerFieldParams, BooleanFieldParams, CharFieldParams, DateFieldParams, DateTimeFieldParams, ForeignKeyParams, IndexedDBArrayFieldParams, IndexedDBJsonFieldParams, IntegerFieldParams, ManyToManyFieldParams, OneToOneFieldParams, TextFieldParams } from './interface.js'; +export declare function CharField(data?: CharFieldParams): string; +export declare function BooleanField(data?: BooleanFieldParams): boolean; +export declare function TextField(data?: TextFieldParams): string; +export declare function IntegerField(data?: IntegerFieldParams): number; +export declare function DateField(data?: DateFieldParams): Date; +export declare function DateTimeField(data?: DateTimeFieldParams): string; +export declare function BigIntegerField(data?: BigIntegerFieldParams): number; +export declare function AutoField(data?: AutoFieldParams): any; +export declare const indexedDB: { + fields: { + JsonField: (data?: IndexedDBJsonFieldParams) => Object; + ArrayField: (data?: IndexedDBArrayFieldParams) => any[]; + }; +}; +export declare function OneToOneField(data: OneToOneFieldParams): string | number; +export declare function ForeignKey(data: ForeignKeyParams): string | number; +export declare function ManyToManyField(data?: ManyToManyFieldParams): string | number; diff --git a/src/plugin/src/models/field/fields.interface.d.ts b/src/plugin/src/models/field/fields.interface.d.ts new file mode 100644 index 000000000..f3a80736b --- /dev/null +++ b/src/plugin/src/models/field/fields.interface.d.ts @@ -0,0 +1,10 @@ +export declare const FieldKeysArray: readonly ["CharField", "JsonField", "AutoField", "BigIntegerField", "DateField", "IntegerField", "TextField", "BooleanField", "OneToOneField", "ForeignKey", "ManyToManyField", "indexedDBJsonField", "indexedDBArrayField", "DateTimeField", "DateField", "Unknown"]; +export declare const AttributesArray: readonly ["maxLength", "minLength", "choices", "primaryKey", "unique", "autoIncrement", "type", "choices", "model", "blank", "default", "onDelete", "foreignKey"]; +export declare type FieldKeys = typeof FieldKeysArray[number]; +export declare type FieldsMap = { + [P in K]?: T; +}; +export declare type FieldAttributesKeys = typeof AttributesArray[number]; +export declare type AttributesMap = { + [P in K]?: T; +}; diff --git a/src/plugin/src/models/field/fields.interface.js b/src/plugin/src/models/field/fields.interface.js new file mode 100644 index 000000000..12136a06c --- /dev/null +++ b/src/plugin/src/models/field/fields.interface.js @@ -0,0 +1,34 @@ +export const FieldKeysArray = [ + 'CharField', + 'JsonField', + 'AutoField', + 'BigIntegerField', + 'DateField', + 'IntegerField', + 'TextField', + 'BooleanField', + 'OneToOneField', + 'ForeignKey', + 'ManyToManyField', + 'indexedDBJsonField', + 'indexedDBArrayField', + 'DateTimeField', + 'DateField', + 'Unknown' +]; // TS3.4 syntax +export const AttributesArray = [ + 'maxLength', + 'minLength', + 'choices', + 'primaryKey', + 'unique', + 'autoIncrement', + 'type', + 'choices', + 'model', + 'blank', + 'default', + 'onDelete', + 'foreignKey' +]; // TS3.4 syntax +// https://stackoverflow.com/a/64694571/14115342 diff --git a/src/plugin/src/models/field/fields.js b/src/plugin/src/models/field/fields.js new file mode 100644 index 000000000..76b2c7c33 --- /dev/null +++ b/src/plugin/src/models/field/fields.js @@ -0,0 +1,40 @@ +import * as Fields from './allFields.js'; +export function CharField(data) { + return new Fields.CharField(data); +} +export function BooleanField(data) { + return new Fields.BooleanField(data); +} +export function TextField(data) { + return new Fields.TextField(data); +} +export function IntegerField(data) { + return new Fields.IntegerField(data); +} +export function DateField(data) { + return new Fields.DateField(data); +} +export function DateTimeField(data) { + return new Fields.DateTimeField(data); +} +export function BigIntegerField(data) { + return new Fields.BigIntegerField(data); +} +export function AutoField(data) { + return new Fields.AutoField(data); +} +export const indexedDB = { + fields: { + JsonField: (data) => new Fields.indexedDBJsonField(data), + ArrayField: (data) => new Fields.indexedDBArrayField(data) + } +}; +export function OneToOneField(data) { + return new Fields.OneToOneField(data); +} +export function ForeignKey(data) { + return new Fields.ForeignKey(data); +} +export function ManyToManyField(data) { + return new Fields.ManyToManyField(data); +} diff --git a/src/plugin/src/models/field/interface.d.ts b/src/plugin/src/models/field/interface.d.ts new file mode 100644 index 000000000..a46736b3e --- /dev/null +++ b/src/plugin/src/models/field/interface.d.ts @@ -0,0 +1,97 @@ +import { field } from './field.js'; +export interface CharFieldParams { + maxLength?: number; + minLength?: number; + primaryKey?: boolean; + choices?: any[] | undefined; + unique?: boolean; + blank?: boolean; + default?: any; +} +export interface TextFieldParams { + maxLength?: number; + minLength?: number; + primaryKey?: boolean; + unique?: boolean; + default?: any; + blank?: boolean; +} +export interface IntegerFieldParams { + primaryKey?: boolean; + unique?: boolean; + default?: any; + blank?: boolean; +} +export interface BigIntegerFieldParams { + primaryKey?: boolean; + unique?: boolean; + default?: any; + blank?: boolean; +} +export interface AutoFieldParams { + primaryKey?: boolean; +} +export interface IndexedDBJsonFieldParams { + unique?: boolean; + blank?: boolean; + null?: boolean; + default?: any; +} +export interface IndexedDBArrayFieldParams { + unique?: boolean; + blank?: boolean; + type?: any; + default?: any; + maxLength?: number; + minLength?: number; + field?: field | any; + size?: number; +} +export interface DateTimeFieldParams { + unique?: boolean; + blank?: boolean; + default?: any; +} +export interface DateFieldParams { + unique?: boolean; + blank?: boolean; + default?: any; +} +export interface BooleanFieldParams { + unique?: boolean; + blank?: boolean; + default?: any; +} +export interface ForeignKeyParams { + model: any; + unique?: boolean; + blank?: boolean; + default?: any; + onDelete?: any; + primaryKey?: boolean; +} +export interface OneToOneFieldParams { + model: any; + unique?: boolean; + blank?: boolean; + default?: any; + onDelete?: any; +} +export interface ManyToManyFieldParams { + model: any; + unique?: boolean; + blank?: boolean; + default?: any; + onDelete?: any; +} +export interface PossibleFieldAttributes { + model?: any; + unique?: boolean; + blank?: boolean; + default?: any; + onDelete?: any; + primaryKey?: boolean; + maxLength?: number; + minLength?: number; + choices?: any[] | undefined; +} diff --git a/src/plugin/src/models/field/interface.js b/src/plugin/src/models/field/interface.js new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/src/plugin/src/models/field/interface.js @@ -0,0 +1 @@ +export {}; diff --git a/src/plugin/src/models/mode-migrations.d.ts b/src/plugin/src/models/mode-migrations.d.ts new file mode 100644 index 000000000..9bc40a174 --- /dev/null +++ b/src/plugin/src/models/mode-migrations.d.ts @@ -0,0 +1,13 @@ +export declare class _ModelMigrations { + callback: { + [dbName: string]: Function[]; + }; + migrated: { + [dbName: string]: boolean; + }; + prepare(databaseName: any): void; + migrationsState(databaseName: string, value: boolean): void; + isReady(modelClassRepresentation: any): void; + waitMigration(databaseName: string): Promise; +} +export declare const ModelMigrations: _ModelMigrations; diff --git a/src/plugin/src/models/mode-migrations.js b/src/plugin/src/models/mode-migrations.js new file mode 100644 index 000000000..5541827ae --- /dev/null +++ b/src/plugin/src/models/mode-migrations.js @@ -0,0 +1,37 @@ +export class _ModelMigrations { + constructor() { + this.callback = {}; + this.migrated = {}; + } + prepare(databaseName) { + if (!this.callback[databaseName]) { + this.callback[databaseName] = []; + } + } + migrationsState(databaseName, value) { + this.migrated[databaseName] = value; + this.prepare(databaseName); + if (this.migrated[databaseName]) { + this.callback[databaseName].forEach((callback, index, object) => { + callback(); + }); + } + } + isReady(modelClassRepresentation) { + // const classInstance: typeof models.Model = new modelClassRepresentation() + } + async waitMigration(databaseName) { + return new Promise((resolve, reject) => { + if (!this.migrated[databaseName]) { + this.prepare(databaseName); + this.callback[databaseName].push(() => { + resolve('ready'); + }); + } + else { + resolve('ready'); + } + }); + } +} +export const ModelMigrations = new _ModelMigrations(); diff --git a/src/plugin/src/models/model-from.d.ts b/src/plugin/src/models/model-from.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/models/model-from.js b/src/plugin/src/models/model-from.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/models/model-manager.d.ts b/src/plugin/src/models/model-manager.d.ts new file mode 100644 index 000000000..6244a1e0f --- /dev/null +++ b/src/plugin/src/models/model-manager.d.ts @@ -0,0 +1,16 @@ +import { Methods, Method } from './model.interface.js'; +import { DatabaseSchema, TableSchema } from './register-modal.interface.js'; +export declare class ModelAPIRequest { + constructor(); + static obj: (DatabaseSchema: DatabaseSchema, TableSchema?: TableSchema) => { + create: (args: Method[], queryId: string, callback: any) => Promise; + get: (arg: Method[], queryId: string) => Promise; + save: (arg: Method[], queryId: string) => Promise; + execute: (arg: Methods | Method[], queryId: string) => Promise; + update: (arg: any, queryId: string) => Promise; + delete: (arg: any, queryId: string) => Promise; + all: (arg: any, queryId: string) => Promise; + migrate: (queryId?: string) => Promise; + trigger: (args: any, Subscription: string, callback: Function) => Promise; + }; +} diff --git a/src/plugin/src/models/model-manager.js b/src/plugin/src/models/model-manager.js new file mode 100644 index 000000000..2cd59910c --- /dev/null +++ b/src/plugin/src/models/model-manager.js @@ -0,0 +1,46 @@ +var _a; +import { DBSwitch } from '../connection/dbSwtich.js'; +import { ModelMigrations } from './mode-migrations.js'; +import { uniqueGenerator } from '../utils.js'; +export class ModelAPIRequest { + constructor() { } +} +_a = ModelAPIRequest; +ModelAPIRequest.obj = (DatabaseSchema, TableSchema) => { + return { + create: async (args, queryId, callback) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + return await DBSwitch.callBackRequestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'insert', args, callback, queryId); + }, + get: async (arg, queryId) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + return await DBSwitch.requestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'select', arg, queryId); + }, + save: async (arg, queryId) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + return await DBSwitch.requestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'update', arg, queryId); + }, + execute: async (arg, queryId) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + return await DBSwitch.requestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'select', arg, queryId); + }, + update: async (arg, queryId) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + return await DBSwitch.requestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'update', arg, queryId); + }, + delete: async (arg, queryId) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + return await DBSwitch.requestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'delete', arg, queryId); + }, + all: async (arg, queryId) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + return await DBSwitch.requestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'select', arg, queryId); + }, + migrate: async (queryId = uniqueGenerator()) => { + return await DBSwitch.requestHandler(null, DatabaseSchema.databaseName, DatabaseSchema.type, 'migrate', { DatabaseSchema, TableSchema }, queryId); + }, trigger: async (args, Subscription, callback) => { + await ModelMigrations.waitMigration(DatabaseSchema.databaseName); + DBSwitch.callBackRequestHandler(TableSchema.name, DatabaseSchema.databaseName, DatabaseSchema.type, 'trigger', args, callback, Subscription); + } + }; +}; diff --git a/src/plugin/src/models/model.d.ts b/src/plugin/src/models/model.d.ts new file mode 100644 index 000000000..eda2dfc51 --- /dev/null +++ b/src/plugin/src/models/model.d.ts @@ -0,0 +1,87 @@ +import { getParams } from './model.interface.js'; +import { DatabaseSchema, DatabaseSchemaLocalStorage, TableSchema, TableSchemaLocalStorage } from './register-modal.interface.js'; +export declare class Model { + constructor(); + get(arg: any): Promise; + getModelName(): string; + getDBSchema(): DatabaseSchema; + getTableSchema(): TableSchema; + filter(...arg: any[]): { + filter: (...args: any[]) => void; + execute: () => Promise; + update: (args: any) => Promise; + delete: () => Promise; + all: () => Promise; + }; + getPrimaryKeyValue(): any; + private setDataToInstance; + private static setDataToInstance; + save(): Promise; + delete(): Promise; + static deleteAll(): Promise; + all(): Promise; + getFields(arg: any): {}; + formValidation(data: any): boolean; + Value(args: any): string; + static Value(args: any): string; + static formValidation(data: any): boolean; + static getModelsFields(arg: any): Promise; + static all(): Promise; + static get(arg: getParams): Promise; + static getOrCreate(arg: getParams): Promise; + private static getId; + static getModelName(): string; + static filter(...arg: any[]): { + filter: (...args: any[]) => void; + execute: () => Promise; + update: (args: any) => Promise; + delete: () => Promise; + all: () => Promise; + }; + static getDBSchema(): DatabaseSchema; + static getTableSchema(): TableSchema; + private static getEmptyFields; + private static getFields; + static create(arg: any): Promise; + static getMode(TableSchema: any): any; + private static newInstance; + static createOrFind(getArg: any, defaultCreate: any): Promise; + static updateOrCreate(...args: any[]): Promise; + static update(arg: any): Promise; + static transactionOnCommit(callback: () => void): { + queryId: string; + subscribe: boolean; + unsubscribe: () => Promise; + }; + static ReactiveList(callback: (Model: Model) => void): { + readonly value: any; + readonly subscribe: any; + unsubscribe: () => Promise; + setUpdateUi(func: any): void; + }; + static object: ({ queryId, DBconfig, TableSchema, some }: { + queryId: any; + DBconfig: any; + TableSchema: any; + some?: any; + }) => { + filter: (...args: any[]) => void; + execute: () => Promise; + update: (args: any) => Promise; + delete: () => Promise; + all: () => Promise; + }; +} +export declare class LocalStorage { + constructor(); + static save(data?: Object): void; + static get(): any; + static getModelName(): any; + static getDBSchema(): DatabaseSchemaLocalStorage; + static getTableSchema(): TableSchemaLocalStorage; + private static getFields; + private static formValidation; + static clear(): void; + static clearComponent(): void; + static clearStorage(): void; +} diff --git a/src/plugin/src/models/model.interface.d.ts b/src/plugin/src/models/model.interface.d.ts new file mode 100644 index 000000000..50937339c --- /dev/null +++ b/src/plugin/src/models/model.interface.d.ts @@ -0,0 +1,10 @@ +export declare const MethodNameArray: readonly ["save", "filter", "get", "create", "execute", "update", "delete", "all", "first"]; +export declare type MethodName = typeof MethodNameArray[number]; +export interface Method { + methodName: MethodName; + arguments: any; +} +export declare type Methods = { + [key: string]: Method[]; +}; +export declare type getParams = Object; diff --git a/src/plugin/src/models/model.interface.js b/src/plugin/src/models/model.interface.js new file mode 100644 index 000000000..c1ceba925 --- /dev/null +++ b/src/plugin/src/models/model.interface.js @@ -0,0 +1,11 @@ +export const MethodNameArray = [ + 'save', + 'filter', + 'get', + 'create', + 'execute', + 'update', + 'delete', + 'all', + 'first', +]; // TS3.4 syntax diff --git a/src/plugin/src/models/model.js b/src/plugin/src/models/model.js new file mode 100644 index 000000000..0eebf2b26 --- /dev/null +++ b/src/plugin/src/models/model.js @@ -0,0 +1,518 @@ +var _a; +import { hashCode, uniqueGenerator } from '../utils.js'; +import { ModelAPIRequest } from './model-manager.js'; +import { objModels } from './register-model.js'; +import { FieldType } from '../sql/query/interface.js'; +import * as Fields from './field/allFields.js'; +import { taskHolder } from '../connection/taskHolder.js'; +import { transactionOnCommit } from '../triggers/transaction.js'; +import { ReactiveList } from '../reactive/DynamicList.js'; +import { signalExecutor, rewrite } from './signal.js'; +let methods = {} = {}; +// inspire by https://github.com/brianschardt/browser-orm +export class Model { + constructor() { } + get(arg) { + return Model.get(arg); + } + getModelName() { + return this.constructor.name; + } + getDBSchema() { + return {}; + } + getTableSchema() { + return {}; + } + filter(...arg) { + return Model.filter(arg); + } + getPrimaryKeyValue() { + const TableSchema = this.getTableSchema(); + const idFieldName = TableSchema.id.keyPath; + return this[idFieldName]; + } + setDataToInstance(obj, Fields = {}) { + const tableSchema = this.getTableSchema(); + const fiendsName = tableSchema.fields.map((field) => field.name); + Fields = {}; + for (let name of fiendsName) { + Fields[name] = obj[name]; + } + if (obj[tableSchema.id.keyPath]) { + Fields[tableSchema.id.keyPath] = obj[tableSchema.id.keyPath]; + } + return Fields; + } + static setDataToInstance(obj, Fields = {}) { + const tableSchema = this.getTableSchema(); + const fiendsName = tableSchema.fields.map((field) => field.name); + Fields = {}; + for (let name of fiendsName) { + Fields[name] = obj[name]; + } + if (obj[tableSchema.id.keyPath]) { + Fields[tableSchema.id.keyPath] = obj[tableSchema.id.keyPath]; + } + return Fields; + } + async save() { + const DBconfig = this.getDBSchema(); + const tableSchema = this.getTableSchema(); + const Fields = this.setDataToInstance(this); + const methods = [{ methodName: 'save', arguments: Fields }]; + const queryId = uniqueGenerator(); + await ModelAPIRequest.obj(DBconfig, tableSchema).save(methods, queryId); + taskHolder.finish(queryId); + } + async delete() { + const DBconfig = this.getDBSchema(); + const TableSchema = this.getTableSchema(); + const idFieldName = TableSchema.id.keyPath; + const createArg = {}; + createArg[idFieldName] = this[idFieldName]; + const _methods = [{ methodName: 'delete', arguments: createArg }]; + const queryId = uniqueGenerator(); + await ModelAPIRequest.obj(DBconfig, TableSchema).delete(_methods, queryId); + taskHolder.finish(queryId); + } + static async deleteAll() { + const DBconfig = this.getDBSchema(); + const TableSchema = this.getTableSchema(); + const idFieldName = TableSchema.id.keyPath; + const createArg = {}; + createArg[idFieldName] = this[idFieldName]; + const _methods = [{ methodName: 'delete', arguments: '*' }]; + const queryId = uniqueGenerator(); + await ModelAPIRequest.obj(DBconfig, TableSchema).delete(_methods, queryId); + taskHolder.finish(queryId); + } + async all() { + const DBconfig = this.getDBSchema(); + const TableSchema = this.getTableSchema(); + const queryId = uniqueGenerator(); + const result = await Model.object({ queryId, DBconfig, TableSchema }).all(); + taskHolder.finish(queryId); + return result; + } + getFields(arg) { + return Model.getFields(arg); + } + formValidation(data) { + return Model.formValidation(data); + } + Value(args) { + return Model.Value(args); + } + static Value(args) { + return ''; + } + 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 async getModelsFields(arg) { + var _b; + const newArgs = {}; + const TableSchema = this.getTableSchema(); + if ((_b = TableSchema.id) === null || _b === void 0 ? void 0 : _b.autoIncrement) { + TableSchema.fields.push({ + keyPath: TableSchema.id.keyPath, + name: TableSchema.id.keyPath, + options: { + type: FieldType.INT, + unique: true + } + }); + } + for (const fieldName in TableSchema.fields) { + newArgs[fieldName] = arg[fieldName]; + } + } + static async all() { + const DBconfig = this.getDBSchema(); + const TableSchema = this.getTableSchema(); + const queryId = uniqueGenerator(); + const result = await Model.object({ queryId, DBconfig, TableSchema }).all(); + taskHolder.finish(queryId); + return result; + } + static async get(arg) { + if (Object.values(arg).length >= 2) { + throw ("get only works with one field"); + } + const _methods = [{ methodName: 'get', arguments: arg }]; + const DBconfig = this.getDBSchema(); + const TableSchema = this.getTableSchema(); + const queryId = uniqueGenerator(); + const foundObj = await ModelAPIRequest.obj(DBconfig, TableSchema).get(_methods, queryId); + taskHolder.finish(queryId); + if (!foundObj) { + return false; + } + let newInstance = this.newInstance({ TableSchema, DBconfig, dataToMerge: foundObj }); + return newInstance; + } + static async getOrCreate(arg) { + const object = await this.get(arg); + if (!object) { + return await this.create(arg); + } + else { + return object; + } + } + static getId() { + return hashCode(this.toString()); + } + static getModelName() { + return this.toString().split('(' || /s+/)[0].split(' ' || /s+/)[1]; + } + static filter(...arg) { + const queryId = uniqueGenerator(); + const DBconfig = this.getDBSchema(); + const TableSchema = this.getTableSchema(); + return this.object({ queryId, DBconfig, TableSchema, some: ['filter', arg] }); + } + static getDBSchema() { + return {}; + } + static getTableSchema() { + return {}; + } + static async getEmptyFields() { + const TableSchema = this.getTableSchema(); + const emptyFields = {}; + const fieldsName = TableSchema.fields.map((field) => field.name); + for (let fieldName of fieldsName) { + emptyFields[fieldName] = null; + } + return emptyFields; + } + static getFields(arg) { + const TableSchema = this.getTableSchema(); + const filteredArgs = {}; + const fieldsName = TableSchema.fields.map((field) => field.name); + for (let fieldName of fieldsName) { + if (arg.hasOwnProperty(fieldName)) { + filteredArgs[fieldName] = arg[fieldName]; + } + } + return filteredArgs; + } + static async create(arg) { + return new Promise(async (resolve, reject) => { + if (arg.constructor.name != 'Array') { + arg = [arg]; + } + const emptyFields = await this.getEmptyFields(); + const TableSchema = this.getTableSchema(); + const ModelName = TableSchema.name; + for (let i in arg) { + arg[i] = this.setDataToInstance(this.getFields(arg[i]), emptyFields); + if (!this.formValidation(arg[i])) { + throw ('invalid ' + JSON.stringify(arg[i])); + } + } + for (let i in arg) { + if (TableSchema.attributes.foreignKey) { + for (let field of TableSchema.attributes.foreignKey) { + try { + arg[i][field] = arg[i][field].getPrimaryKeyValue(); + } + catch (error) { } + } + } + } + const _methods = [{ methodName: 'create', arguments: arg }]; + const DBconfig = this.getDBSchema(); + const queryId = uniqueGenerator(); + const result = []; + await ModelAPIRequest.obj(DBconfig, TableSchema).create(_methods, queryId, ({ id, index }) => { + const insert = arg[index]; + insert[TableSchema.id.keyPath] = id; + const instance = this.newInstance({ TableSchema, DBconfig, dataToMerge: insert }); + result.push(instance); + }); + taskHolder.updateFunction(queryId, "done", () => { + if (arg.length == 1) { + resolve(result[0]); + } + else { + resolve(result); + } + taskHolder.finish(queryId); + }); + }); + } + static getMode(TableSchema) { + return objModels[TableSchema.databaseName + TableSchema.name]; + } + static newInstance({ TableSchema, DBconfig, dataToMerge }) { + const model = this.getMode(TableSchema); + let newInstance = new model(); + delete newInstance[TableSchema.id.keyPath]; + if (TableSchema.fieldTypes.ManyToManyField) { + for (let field of TableSchema.fieldTypes.ManyToManyField) { + newInstance[field] = null; + } + } + if (TableSchema.fieldTypes.OneToOneField) { + for (let field of TableSchema.fieldTypes.OneToOneField) { + newInstance[field] = null; + } + } + Object.assign(newInstance, dataToMerge); + if (newInstance[TableSchema.id.keyPath]) { + Object.defineProperty(newInstance, TableSchema.id.keyPath, { + configurable: false, + writable: false + }); + } + delete newInstance.obj; + return newInstance; + } + static async createOrFind(getArg, defaultCreate) { + const result = await this.filter(getArg).execute(); + const TableSchema = this.getTableSchema(); + const DBconfig = this.getDBSchema(); + let instance; + let created; + if (result.length == 1) { + created = false; + instance = await this.newInstance({ TableSchema, DBconfig, dataToMerge: result[0] }); + } + else { + created = true; + instance = await this.create(Object.assign(getArg, defaultCreate)); + } + return [instance, created]; + } + static async updateOrCreate(...args) { + if (args.length == 1) { + if (Array.isArray(args)) { + const TableSchema = this.getTableSchema(); + let created = []; + let updated = []; + const list = args; + const uniqueFields = TableSchema.attributes["unique"].concat(TableSchema.id.keyPath); + for (const object of list) { + const uniqueFieldName = uniqueFields.find((fieldName) => { + if (object[fieldName]) { + return true; + } + return false; + }); + const params = {}; + params[uniqueFieldName] = object[uniqueFieldName]; + try { + const instanceModel = await this.get(params); + updated.push(instanceModel); + } + catch (error) { + const instanceModel = await this.create(params); + created.push(instanceModel); + } + } + return { created, updated }; + } + else { + const TableSchema = this.getTableSchema(); + let instance; + let created = false; + const uniqueFields = TableSchema.attributes["unique"].concat(TableSchema.id.keyPath); + const uniqueFieldName = uniqueFields.find((fieldName) => { + if (args[fieldName]) { + return true; + } + return false; + }); + const params = {}; + params[uniqueFieldName] = args[uniqueFieldName]; + try { + const object = await this.get(params); + instance = object; + await object.save(args); + } + catch (error) { + instance = await this.create(params); + return instance; + } + return { instance, created }; + } + } + else { + let argToFind = args[0]; + let argsToUpdate = args[1]; + let [instance, created] = await this.createOrFind(argToFind, argsToUpdate); + if (!created) { + const params = Object.assign(argToFind, argsToUpdate); + instance = Object.assign(instance, params); + await instance.save(); + } + return instance; + } + } + static async update(arg) { + arg = this.getFields(arg); + const DBconfig = this.getDBSchema(); + const TableSchema = this.getTableSchema(); + const _methods = [{ methodName: 'update', arguments: arg }]; + const queryId = uniqueGenerator(); + const result = await ModelAPIRequest.obj(DBconfig, TableSchema).update(_methods, queryId); + taskHolder.finish(queryId); + return result; + } + static transactionOnCommit(callback) { + return transactionOnCommit.subscribe(this, callback); + } + static ReactiveList(callback) { + return ReactiveList.subscribe(this, callback); + } +} +_a = Model; +Model.object = ({ queryId, DBconfig, TableSchema, some = null }) => { + const ModelName = TableSchema.name; + if (!methods[queryId]) { + methods[queryId] = []; + } + if (some) { + const methodName = some[0]; + const methodArgs = some[1]; + _a.object({ queryId, DBconfig, TableSchema })[methodName](...methodArgs); + } + return { + filter: (...args) => { + methods[queryId].push({ methodName: 'filter', arguments: args }); + _a.object({ DBconfig, TableSchema, queryId }); + }, + execute: async () => { + return new Promise(async (resolve, reject) => { + methods[queryId].push({ methodName: 'execute', arguments: null }); + const _methods = methods[queryId]; + methods[queryId] = []; + const result = await ModelAPIRequest.obj(DBconfig, TableSchema).execute(_methods, queryId); + resolve(result); + for (let i of result) { + result[i] = _a.newInstance({ TableSchema, DBconfig, dataToMerge: result[i] }); + } + }); + }, + update: async (args) => { + methods[queryId].push({ methodName: 'update', arguments: args }); + const _methods = methods[queryId]; + methods[queryId] = []; + return await ModelAPIRequest.obj(DBconfig, TableSchema).update(_methods, queryId); + }, + delete: async () => { + methods[queryId].push({ methodName: 'delete', arguments: null }); + const _methods = methods[queryId]; + methods[queryId] = []; + return await ModelAPIRequest.obj(DBconfig, TableSchema).delete(_methods, queryId); + }, + all: async () => { + return new Promise(async (resolve, reject) => { + methods[queryId].push({ methodName: 'all', arguments: null }); + const _methods = methods[queryId]; + methods[queryId] = []; + const result = await ModelAPIRequest.obj(DBconfig, TableSchema).all(_methods, queryId); + resolve(result); + for (let i of result) { + result[i] = _a.newInstance({ TableSchema, DBconfig, dataToMerge: result[i] }); + } + }); + } + }; +}; +export class LocalStorage { + constructor() { } + static save(data = {}) { + const key = this.getTableSchema().id; + const _data = typeof data == 'object' ? data : {}; + const dataToSave = this.getFields(Object.assign(this, Object.assign({}, _data))); + const hasSignal = rewrite.hasRewriteSave(key.keyPath); + if (hasSignal) { + signalExecutor.rewriteSave(key.keyPath, this, dataToSave); + } + else { + localStorage.setItem(key.keyPath, JSON.stringify(dataToSave)); + } + } + static get() { + const key = this.getTableSchema().id; + const hasSignal = rewrite.hasRewriteGet(key.keyPath); + if (hasSignal) { + signalExecutor.rewriteGet(key.keyPath, this); + } + else { + const restedData = JSON.parse(localStorage.getItem(key.keyPath)); + Object.assign(this, Object.assign({}, restedData)); + return restedData; + } + } + static getModelName() { + return this['$keyName'] || this.toString().split('(' || /s+/)[0].split(' ' || /s+/)[1]; + } + static getDBSchema() { + return; + } + static getTableSchema() { + return; + } + static getFields(arg) { + const TableSchema = this.getTableSchema(); + const DBSchema = this.getDBSchema(); + const ignoreFieldsStartWidth = (DBSchema === null || DBSchema === void 0 ? void 0 : DBSchema.ignoreFieldsStartWidth) || []; + const filteredArgs = {}; + const fieldsName = TableSchema.fields.map((field) => field.name); + const fieldNameFilter = fieldsName.filter((fieldName) => { + for (let Attribute of ignoreFieldsStartWidth) { + 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; + const hasSignal = rewrite.hasRewriteDelete(key.keyPath); + if (hasSignal) { + signalExecutor.rewriteDelete(key.keyPath, this); + } + else { + localStorage.removeItem(key.keyPath); + } + } +} diff --git a/src/plugin/src/models/model.reader.d.ts b/src/plugin/src/models/model.reader.d.ts new file mode 100644 index 000000000..30e35ca03 --- /dev/null +++ b/src/plugin/src/models/model.reader.d.ts @@ -0,0 +1,21 @@ +import { FieldsMap, AttributesMap } from './field/fields.interface.js'; +export declare class ModelReader { + static read(modelClassRepresentation: any): { + modelName: string; + fields: { + [key: string]: any; + }; + fieldTypes: FieldsMap<"CharField" | "JsonField" | "AutoField" | "BigIntegerField" | "DateField" | "IntegerField" | "TextField" | "BooleanField" | "OneToOneField" | "ForeignKey" | "ManyToManyField" | "indexedDBJsonField" | "indexedDBArrayField" | "DateTimeField" | "Unknown", string[]>; + attributes: AttributesMap<"maxLength" | "minLength" | "choices" | "primaryKey" | "unique" | "autoIncrement" | "type" | "model" | "blank" | "default" | "onDelete" | "foreignKey", string[]>; + }; +} +export declare class LocalStorageModelReader { + static read(modelClassRepresentation: any, ignoreFieldsStartWidth: string[]): { + modelName: any; + 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" | "Unknown", string[]>; + }; +} diff --git a/src/plugin/src/models/model.reader.js b/src/plugin/src/models/model.reader.js new file mode 100644 index 000000000..5b6b4b083 --- /dev/null +++ b/src/plugin/src/models/model.reader.js @@ -0,0 +1,84 @@ +import { FieldKeysArray } from './field/fields.interface.js'; +export class ModelReader { + static read(modelClassRepresentation) { + const classInstance = new modelClassRepresentation(); + const modelName = classInstance.getModelName(); + const fieldTypes = {}; + const fields = {}; + const attributes = {}; + for (const [fieldName, Field] of Object.entries(classInstance)) { + const type = Field === null || Field === void 0 ? void 0 : Field.fieldName; + if (FieldKeysArray.includes(type)) { + fields[fieldName] = Field; + if (!fieldTypes[type]) { + fieldTypes[type] = []; + } + fieldTypes[type].push(fieldName); + for (const [FieldProperty, value] of Object.entries(Field)) { + if (typeof value != "function") { + if (!attributes[FieldProperty]) { + attributes[FieldProperty] = []; + } + attributes[FieldProperty].push(fieldName); + } + } + } + else { + fields[fieldName] = Field; + if (!fieldTypes["Unknown"]) { + fieldTypes["Unknown"] = []; + } + fieldTypes["Unknown"].push(fieldName); + } + } + return { + modelName, + fields, + fieldTypes, + attributes, + }; + } +} +export class LocalStorageModelReader { + static read(modelClassRepresentation, ignoreFieldsStartWidth) { + const classInstance = modelClassRepresentation; + const fieldTypes = {}; + const attributes = {}; + const modelName = classInstance.getModelName(); + const fields = {}; + for (const [fieldName, Field] of Object.entries(classInstance)) { + const ignore = ignoreFieldsStartWidth.find(e => fieldName.startsWith(e)); + if (!ignore) { + const type = Field === null || Field === void 0 ? void 0 : Field.fieldName; + if (FieldKeysArray.includes(type)) { + fields[fieldName] = Field; + if (!fieldTypes[type]) { + fieldTypes[type] = []; + } + fieldTypes[type].push(fieldName); + for (const [FieldProperty, value] of Object.entries(Field)) { + if (typeof value != "function") { + if (!attributes[FieldProperty]) { + attributes[FieldProperty] = []; + } + attributes[FieldProperty].push(fieldName); + } + } + } + else { + fields[fieldName] = Field; + if (!fieldTypes["Unknown"]) { + fieldTypes["Unknown"] = []; + } + fieldTypes["Unknown"].push(fieldName); + } + } + } + return { + modelName, + fields, + attributes, + fieldTypes + }; + } +} diff --git a/src/plugin/src/models/register-modal.interface.d.ts b/src/plugin/src/models/register-modal.interface.d.ts new file mode 100644 index 000000000..a46e8c5df --- /dev/null +++ b/src/plugin/src/models/register-modal.interface.d.ts @@ -0,0 +1,52 @@ +import { FieldType } from '../sql/query/interface.js'; +import { FieldsMap, FieldKeys, AttributesMap, FieldAttributesKeys } from './field/fields.interface.js'; +import { PossibleFieldAttributes } from './field/interface.js'; +export interface FieldSchema { + name: string; + keyPath: string; + className?: FieldKeys; + fieldAttributes?: PossibleFieldAttributes; + options?: { + unique?: boolean; + type: FieldType; + }; +} +export interface TableSchema { + databaseName: string; + name: string; + id: { + keyPath: string; + autoIncrement?: boolean; + type: FieldType; + }; + fields: FieldSchema[]; + attributes: AttributesMap; + fieldTypes: FieldsMap; + middle?: boolean; +} +export interface DatabaseSchema { + databaseName: string; + type: 'indexedDB' | 'localStorage'; + version: number; + webWorker?: boolean; + stores?: TableSchema[]; +} +export interface TableSchemaLocalStorage { + name: string; + id: { + keyPath: string; + autoIncrement?: boolean; + type: FieldType; + }; + fields: FieldSchema[]; + attributes: AttributesMap; + fieldTypes: FieldsMap; +} +export interface DatabaseSchemaLocalStorage { + databaseName: string; + type: 'localStorage'; + version: number; + webWorker?: boolean; + stores?: TableSchemaLocalStorage[]; + ignoreFieldsStartWidth?: string[]; +} diff --git a/src/plugin/src/models/register-modal.interface.js b/src/plugin/src/models/register-modal.interface.js new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/src/plugin/src/models/register-modal.interface.js @@ -0,0 +1 @@ +export {}; diff --git a/src/plugin/src/models/register-model.d.ts b/src/plugin/src/models/register-model.d.ts new file mode 100644 index 000000000..8f331c614 --- /dev/null +++ b/src/plugin/src/models/register-model.d.ts @@ -0,0 +1,45 @@ +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' | 'localStorage'; + models: typeof Model[] | typeof LocalStorage[]; + /** + * @description restore values from localStorage for LocalStorage Models + */ + restore?: boolean; + ignoreFieldsStartWidth?: string[]; +} +export declare const objModels: {}; +export declare const modelsConfig: { + [key: string]: { + DatabaseSchema: DatabaseSchema; + TableSchema: TableSchema; + OneToOneField?: { + [key: string]: {}; + }; + }; +}; +export declare function migrate(register: register): void; +export declare class registerModel { + static ModalName(): void; + 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; + static edit(ModelName: any, databaseSchema: any, modelClassRepresentations: any, entries: any): void; + static ModelName(modelClassRepresentations: typeof LocalStorage, DbName: any): string; +} +export declare class ModelEditor { + static setTableSchemaLocalStorage(ModelToEdit: typeof LocalStorage, TableSchema: TableSchemaLocalStorage): void; + static getDBSchemaLocalStorage(ModelToEdit: typeof LocalStorage, DatabaseSchema: DatabaseSchemaLocalStorage): void; + static setTableSchema(ModelToEdit: typeof Model, DbName: any): void; + static getDBSchema(ModelToEdit: typeof Model, DbName: any): void; + static addMethodOneToOneField(foreignKeyField: OneToOneField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void; + static addMethodForeignKey(foreignKeyField: ForeignKey, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): void; + static addMethodManyToManyField(foreignKeyField: ManyToManyField, FieldName: string, modelName: string, databaseSchema: DatabaseSchema): Promise; +} +export {}; diff --git a/src/plugin/src/models/register-model.js b/src/plugin/src/models/register-model.js new file mode 100644 index 000000000..1e3e54d6c --- /dev/null +++ b/src/plugin/src/models/register-model.js @@ -0,0 +1,448 @@ +import { Model } from './model.js'; +import { LocalStorageModelReader, ModelReader } from './model.reader.js'; +import { OneToOneField, ForeignKey, ManyToManyField } from './field/allFields.js'; +import { hashCode, uncapitalize, uniqueGenerator } from '../utils.js'; +import { FieldType } from '../sql/query/interface.js'; +import { ModelMigrations } from './mode-migrations.js'; +import { ModelAPIRequest } from './model-manager.js'; +import { transactionOnCommit } from '../triggers/transaction.js'; +import { DatabaseManagerSchema } from './schema/databae-manager-schema.js'; +const models = {}; +export const objModels = {}; +export const modelsConfig = {}; +const modelsLocalStorage = {}; +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 ModalName() { } + static async register(entries) { + var _a, _b, _c, _d; + const databaseSchema = { + databaseName: entries.databaseName || uniqueGenerator(), + version: entries.version, + type: entries.type, + stores: [] + }; + let index = 0; + for (const modelClassRepresentations of entries.models) { + const ModelName = modelClassRepresentations.getModelName(); + models[ModelName] = modelClassRepresentations; + const { fields, modelName, attributes, fieldTypes } = ModelReader.read(modelClassRepresentations); + const idFieldName = (_a = attributes === null || attributes === void 0 ? void 0 : attributes.primaryKey) === null || _a === void 0 ? void 0 : _a.shift(); + databaseSchema.stores.push({ + databaseName: databaseSchema.databaseName, + name: modelName, + id: { + keyPath: idFieldName || 'id', + autoIncrement: fields[idFieldName] ? ((_b = fields[idFieldName]) === null || _b === void 0 ? void 0 : _b.primaryKey) == true : true, + type: FieldType.INT + }, + attributes: attributes, + fields: [], + fieldTypes + }); + for (const [fieldName, Field] of Object.entries(fields)) { + // dont register fields that is primary key and auto increment + if (!((Field === null || Field === void 0 ? void 0 : Field.primaryKey) && (Field === null || Field === void 0 ? void 0 : Field.autoIncrement)) && !((_c = fieldTypes['ManyToManyField']) === null || _c === void 0 ? void 0 : _c.includes(fieldName)) && !((_d = fieldTypes['Unknown']) === null || _d === void 0 ? void 0 : _d.includes(fieldName))) { + const removeReferenceField = Object.assign({}, Field); + if (removeReferenceField === null || removeReferenceField === void 0 ? void 0 : removeReferenceField.model) { + removeReferenceField.model = removeReferenceField.model.getModelName(); + } + databaseSchema.stores[index].fields.push({ + name: fieldName, + keyPath: fieldName, + options: { + unique: (Field === null || Field === void 0 ? void 0 : Field.unique) || false, + type: Field.type + }, + className: Field === null || Field === void 0 ? void 0 : Field.fieldName, + fieldAttributes: Object.assign({}, removeReferenceField) + }); + } + if (Field instanceof OneToOneField) { + await ModelEditor.addMethodOneToOneField(Field, fieldName, modelName, databaseSchema); + } + else if (Field instanceof ForeignKey) { + await ModelEditor.addMethodForeignKey(Field, fieldName, modelName, databaseSchema); + } + else if (Field instanceof ManyToManyField) { + await ModelEditor.addMethodManyToManyField(Field, fieldName, modelName, databaseSchema); + } + } + models[ModelName] = modelClassRepresentations; + const tableSchema = databaseSchema.stores.find((e) => e.name == ModelName); + modelsConfig[ModelName] = { + DatabaseSchema: databaseSchema, + TableSchema: tableSchema + }; + index++; + } + DatabaseManagerSchema.prepare(databaseSchema); + for (const stores of databaseSchema.stores) { + const model = models[stores.name]; + const DbName = databaseSchema.databaseName; + ModelEditor.setTableSchema(model, DbName); + ModelEditor.getDBSchema(model, DbName); + // ModelEditor.setModel(model, DbName) + DatabaseManagerSchema.getDb(DbName).getTable(stores.name).setModel(model); + transactionOnCommit.prepare(model); + objModels[DbName + stores.name] = model; + } + if (databaseSchema.type == 'indexedDB') { + await ModelAPIRequest.obj(databaseSchema).migrate(); + ModelMigrations.migrationsState(databaseSchema.databaseName, true); + } + } + static manyToManyRelationShip(foreignKeyField, FieldName, modelName, databaseSchema) { + const foreignKeyFieldModel = foreignKeyField.model; + const currentModel = models[modelName]; + const foreignKeyFieldModelName = foreignKeyFieldModel.getModelName(); + const currentModelName = models[modelName].getModelName(); + const tableName = currentModelName + foreignKeyFieldModelName; + const num = databaseSchema.stores.push({ + databaseName: databaseSchema.databaseName, + name: tableName, + id: { keyPath: 'id', autoIncrement: true, type: FieldType.INT }, + fields: [ + { + name: 'iD' + foreignKeyFieldModelName, + keyPath: 'iD' + foreignKeyFieldModelName, + options: { + unique: false, + type: FieldType.INT + }, + className: 'IntegerField' + }, + { + name: 'iD' + currentModelName, + keyPath: 'iD' + currentModelName, + options: { + unique: false, + type: FieldType.INT + }, + className: 'IntegerField' + } + ], + attributes: {}, + fieldTypes: { + IntegerField: ['iD' + foreignKeyFieldModelName, 'iD' + currentModelName] + } + }); + const id = num - 1; + models[tableName] = generateGenericModel({ + DBSchema: databaseSchema, + ModelName: tableName, + TableSchema: databaseSchema.stores[id] + }); + return generateGenericModel({ + DBSchema: databaseSchema, + ModelName: tableName, + TableSchema: databaseSchema.stores[id] + }); + } +} +async function cachedValue(Model) { + const emptyFields = Model.getEmptyFields(); + Model.getEmptyFields = function () { + return emptyFields; + }; + const getModelName = Model.getModelName(); + Model.getModelName = function () { + return getModelName; + }; +} +export class registerLocalStorage { + static async register(entries) { + const databaseSchema = { + databaseName: entries.databaseName, + version: entries.version, + type: 'localStorage', + stores: [] + }; + let index = 0; + for (const modelClassRepresentations of entries.models) { + const ModelName = this.ModelName(modelClassRepresentations, entries.databaseName); + modelsLocalStorage[ModelName] = modelClassRepresentations; + const { fields, modelName, attributes, fieldTypes } = LocalStorageModelReader.read(modelClassRepresentations, entries.ignoreFieldsStartWidth || []); + 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 stores of databaseSchema.stores) { + const model = modelsLocalStorage[stores.name]; + ModelEditor.setTableSchemaLocalStorage(model, stores); + ModelEditor.getDBSchemaLocalStorage(model, databaseSchema); + } + } + static edit(ModelName, databaseSchema, modelClassRepresentations, entries) { + const tableSchema = databaseSchema.stores.find((e) => e.name == ModelName); + modelClassRepresentations.getDBSchema = () => { + return databaseSchema; + }; + modelClassRepresentations.getTableSchema = () => { + return tableSchema; + }; + modelClassRepresentations.getModelName = () => { + return ModelName; + }; + modelsConfigLocalStorage[ModelName] = { + DatabaseSchema: databaseSchema, + TableSchema: tableSchema + }; + modelsLocalStorage[ModelName] = modelClassRepresentations; + if (entries === null || entries === void 0 ? void 0 : entries.restore) { + modelClassRepresentations.get(null); + } + } + static ModelName(modelClassRepresentations, DbName) { + const ModelName = DbName + '/' + modelClassRepresentations.getModelName(); + if (modelsLocalStorage[ModelName]) { + return hashCode(DbName + '/' + modelClassRepresentations.toString()).toString(); + } + return ModelName; + } +} +export class ModelEditor { + static setTableSchemaLocalStorage(ModelToEdit, TableSchema) { + ModelToEdit.getTableSchema = () => { + return TableSchema; + }; + } + static getDBSchemaLocalStorage(ModelToEdit, DatabaseSchema) { + ModelToEdit.getDBSchema = () => { + return DatabaseSchema; + }; + } + static setTableSchema(ModelToEdit, DbName) { + const ModelName = ModelToEdit.getModelName(); + const DBSchema = DatabaseManagerSchema.getDb(DbName); + const TableSchemaClass = DBSchema.getTable(ModelName); + ModelToEdit.prototype.getTableSchema = () => { + return TableSchemaClass.config; + }; + ModelToEdit.getTableSchema = () => { + return TableSchemaClass.config; + }; + } + static getDBSchema(ModelToEdit, DbName) { + const ModelName = ModelToEdit.getModelName(); + const DBSchema = DatabaseManagerSchema.getDb(DbName); + ModelToEdit.prototype.getDBSchema = () => { + return DBSchema.config; + }; + ModelToEdit.getDBSchema = () => { + return DBSchema.config; + }; + } + // static setModel(ModelToEdit: typeof Model, DbName) { + // const ModelName = ModelToEdit.getModelName() + // const DBSchema = DatabaseManagerSchema.getDb(DbName) + // const TableSchemaClass = DBSchema.getTable(ModelName) + // console.log('set model '+ ModelName) + // ModelToEdit.prototype.getModel = () => { + // const model = TableSchemaClass.getModel() + // if(!model) { + // console.log('model!!!!!!!!!!!!!', model, ModelName) + // } + // return new model() + // } + // ModelToEdit.getModel = () => { + // const model = TableSchemaClass.getModel() + // if(!model) { + // console.log('model!!!!!!!!!!!!!', model, ModelName) + // } + // return new model() + // } + // } + static addMethodOneToOneField(foreignKeyField, FieldName, modelName, databaseSchema) { + const foreignKeyFieldModel = foreignKeyField.model; + const currentModel = models[modelName]; + // place + foreignKeyFieldModel['prototype'][modelName] = async function (body) { + const foreignModel = currentModel; + const TableSchema = foreignModel.getTableSchema(); + const obj = {}; + obj[FieldName] = this.getPrimaryKeyValue(); + return await foreignModel.get(obj); + }; + // restaurant + currentModel['prototype'][foreignKeyFieldModel['name']] = async function () { + const foreignModel = foreignKeyFieldModel; + let params = {}; + const TableSchema = foreignModel.getTableSchema(); + params[TableSchema.id.keyPath] = this[FieldName]; + return await foreignModel.get(params); + }; + } + static addMethodForeignKey(foreignKeyField, FieldName, modelName, databaseSchema) { + const foreignKeyFieldModel = foreignKeyField.model; + const currentModel = models[modelName]; + const FunctionName = uncapitalize(modelName); + foreignKeyFieldModel['prototype'][FunctionName + '_setAll'] = async function () { + const obj = {}; + obj[FieldName] = this.getPrimaryKeyValue(); + const currentModel = models[modelName]; + return await currentModel.filter(obj).execute(); + }; + foreignKeyFieldModel['prototype'][FunctionName + '_setAdd'] = async function (arg) { + const reporter = this; + arg[FieldName] = reporter; + return currentModel['create'](arg); + }; + currentModel['prototype'][foreignKeyFieldModel.getModelName()] = async function () { + const TableSchema = foreignKeyFieldModel.getTableSchema(); + const obj = {}; + obj[TableSchema.id.keyPath] = this[FieldName]; + return foreignKeyFieldModel.filter(obj).execute(); + }; + } + static async addMethodManyToManyField(foreignKeyField, FieldName, modelName, databaseSchema) { + const foreignKeyFieldModel = foreignKeyField.model; + FieldName = FieldName; + const currentModel = models[modelName]; + const _middleTable = await registerModel.manyToManyRelationShip(foreignKeyField, FieldName, modelName, databaseSchema); + currentModel['prototype'][FieldName + '_add'] = async function (modelInstances) { + const middleTable = DatabaseManagerSchema.getDb(databaseSchema.databaseName).getTable(_middleTable.getModelName()).getModel(); + if (modelInstances.constructor.name != 'Array') { + modelInstances = [modelInstances]; + } + for (const modelInstance of modelInstances) { + if (modelInstance instanceof foreignKeyFieldModel) { + let params = {}; + params[`iD${currentModel.getModelName()}`] = this.getPrimaryKeyValue(); + params[`iD${modelInstance.getModelName()}`] = modelInstance.getPrimaryKeyValue(); + await middleTable['create'](params); + } + else { + throw ('Need to be instance of ' + foreignKeyFieldModel.getModelName()); + } + } + }; + currentModel['prototype'][FieldName] = function () { + const middleTable = DatabaseManagerSchema.getDb(databaseSchema.databaseName).getTable(_middleTable.getModelName()).getModel(); + let _model = this; + return { + async all() { + let params = {}; + params[`iD${_model.getModelName()}`] = _model.getPrimaryKeyValue(); + const middleTableResult = await middleTable['filter'](params).execute(); + foreignKeyField.model; + return middleTableResult; + } + }; + }; + currentModel['prototype'][FieldName + '_all'] = async function () { + const middleTable = DatabaseManagerSchema.getDb(databaseSchema.databaseName).getTable(_middleTable.getModelName()).getModel(); + let _model = this; + let params = {}; + let result = []; + params[`iD${_model.getModelName()}`] = _model.getPrimaryKeyValue(); + const middleTableResult = await middleTable['filter'](params).execute(); + let ids; + if (middleTableResult) { + const TableSchema = foreignKeyField.model.getTableSchema(); + ids = middleTableResult.map((e) => { + return e[`iD${foreignKeyField.model.name}`]; + }); + let params = {}; + for (const id of ids) { + try { + params[TableSchema.id.keyPath] = id; + const row = await foreignKeyField.model.get(params); + result.push(row); + } + catch (error) { + } + } + } + return result; + }; + foreignKeyField.model['prototype'][uncapitalize(modelName) + '_set_all'] = async function () { + let _model = this; + const middleTable = DatabaseManagerSchema.getDb(databaseSchema.databaseName).getTable(_middleTable.getModelName()).getModel(); + let params = {}; + let result = []; + params[`iD${_model.getModelName()}`] = _model.getPrimaryKeyValue(); + const middleTableResult = await middleTable['filter'](params).execute(); + let ids; + if (middleTableResult) { + const TableSchema = currentModel.getTableSchema(); + ids = middleTableResult.map((e) => { + return e[`iD${modelName}`]; + }); + let params = {}; + for (const id of ids) { + try { + params[TableSchema.id.keyPath] = id; + const row = await currentModel.get(params); + result.push(row); + } + catch (error) { + } + } + } + return result; + }; + } +} +function generateGenericModel({ DBSchema, ModelName, TableSchema }) { + class GenericModel extends Model { + } + for (const [Field, value] of Object.entries(Model)) { + GenericModel[Field] = value; + } + // GenericModel.prototype = Model.prototype + GenericModel.prototype['getDBSchema'] = () => { + return DBSchema; + }; + GenericModel.prototype['getModelName'] = () => { + return ModelName; + }; + GenericModel.prototype['getTableSchema'] = () => { + return TableSchema; + }; + // GenericModel.prototype.getModel = (): any => { + // return new GenericModel() + // } + // GenericModel.getModel = (): any => { + // return new GenericModel() + // } + GenericModel['getDBSchema'] = () => { + return DBSchema; + }; + GenericModel['getModelName'] = () => { + return ModelName; + }; + GenericModel['getTableSchema'] = () => { + return TableSchema; + }; + return GenericModel; +} diff --git a/src/plugin/src/models/schema/databae-manager-schema.d.ts b/src/plugin/src/models/schema/databae-manager-schema.d.ts new file mode 100644 index 000000000..0b8152401 --- /dev/null +++ b/src/plugin/src/models/schema/databae-manager-schema.d.ts @@ -0,0 +1,7 @@ +import { DatabaseSchema as DatabaseSchemaInterface } from "../register-modal.interface.js"; +import { DatabaseSchemaClass } from "./database-schema.js"; +export declare class DatabaseManagerSchema { + private static databases; + static prepare(config: DatabaseSchemaInterface): Promise; + static getDb(databaseName: any): DatabaseSchemaClass; +} diff --git a/src/plugin/src/models/schema/databae-manager-schema.js b/src/plugin/src/models/schema/databae-manager-schema.js new file mode 100644 index 000000000..1f00818f6 --- /dev/null +++ b/src/plugin/src/models/schema/databae-manager-schema.js @@ -0,0 +1,13 @@ +import { DatabaseSchemaClass } from "./database-schema.js"; +export class DatabaseManagerSchema { + static async prepare(config) { + if (this.databases[config.databaseName]) { + throw ('Database name already exist. Force create'); + } + this.databases[config.databaseName] = new DatabaseSchemaClass({ config }); + } + static getDb(databaseName) { + return this.databases[databaseName]; + } +} +DatabaseManagerSchema.databases = {}; diff --git a/src/plugin/src/models/schema/database-schema.d.ts b/src/plugin/src/models/schema/database-schema.d.ts new file mode 100644 index 000000000..e4cf7ec7f --- /dev/null +++ b/src/plugin/src/models/schema/database-schema.d.ts @@ -0,0 +1,14 @@ +import { DatabaseSchema as DatabaseSchemaInterface } from '../register-modal.interface.js'; +import { TableSchemaClass } from './table-schema.js'; +export declare class DatabaseSchemaClass { + name: string; + version: string; + tables: { + [storeName: string]: TableSchemaClass; + }; + config: DatabaseSchemaInterface; + constructor({ config }: { + config: DatabaseSchemaInterface; + }); + getTable(name: any): TableSchemaClass; +} diff --git a/src/plugin/src/models/schema/database-schema.js b/src/plugin/src/models/schema/database-schema.js new file mode 100644 index 000000000..9ce002beb --- /dev/null +++ b/src/plugin/src/models/schema/database-schema.js @@ -0,0 +1,16 @@ +import { TableSchemaClass } from './table-schema.js'; +export class DatabaseSchemaClass { + constructor({ config }) { + this.name = ''; + this.version = ''; + this.tables = {}; + this.config = config; + this.name = this.config.databaseName; + for (let store of config.stores) { + this.tables[store.name] = new TableSchemaClass({ store }); + } + } + getTable(name) { + return this.tables[name]; + } +} diff --git a/src/plugin/src/models/schema/table-schema.d.ts b/src/plugin/src/models/schema/table-schema.d.ts new file mode 100644 index 000000000..96e1c7ec1 --- /dev/null +++ b/src/plugin/src/models/schema/table-schema.d.ts @@ -0,0 +1,13 @@ +import { Model } from '../model.js'; +import { TableSchema as FieldSchemaInterface } from '../register-modal.interface.js'; +export declare class TableSchemaClass { + config: FieldSchemaInterface; + name: string; + version: string; + model: typeof Model; + constructor({ store }: { + store: FieldSchemaInterface; + }); + setModel(modal: any): void; + getModel(): typeof Model; +} diff --git a/src/plugin/src/models/schema/table-schema.js b/src/plugin/src/models/schema/table-schema.js new file mode 100644 index 000000000..6cc661f34 --- /dev/null +++ b/src/plugin/src/models/schema/table-schema.js @@ -0,0 +1,14 @@ +export class TableSchemaClass { + constructor({ store }) { + this.name = ''; + this.version = ''; + this.name = store.name; + this.config = store; + } + setModel(modal) { + this.model = modal; + } + getModel() { + return this.model; + } +} diff --git a/src/plugin/src/models/signal.d.ts b/src/plugin/src/models/signal.d.ts new file mode 100644 index 000000000..4440a4557 --- /dev/null +++ b/src/plugin/src/models/signal.d.ts @@ -0,0 +1,21 @@ +import { LocalStorage } from "./model.js"; +import { params } from './signal.interface.js'; +export declare const rewrite: { + rewriteGet: { + connect(callback: (params: params) => void, models: (typeof LocalStorage)[]): void; + }; + rewriteSave: { + connect(callback: (params: params) => void, models: (typeof LocalStorage)[]): void; + }; + rewriteDelete: { + connect(callback: (params: params) => void, models: (typeof LocalStorage)[]): void; + }; + hasRewriteGet(ModalName: string): boolean; + hasRewriteSave(ModalName: string): boolean; + hasRewriteDelete(ModalName: string): boolean; +}; +export declare const signalExecutor: { + rewriteGet(ModalName: string, instance: any): any; + rewriteSave(ModalName: string, instance: any, dataToSave: any): any; + rewriteDelete(ModalName: string, instance: any): any; +}; diff --git a/src/plugin/src/models/signal.interface.d.ts b/src/plugin/src/models/signal.interface.d.ts new file mode 100644 index 000000000..f26905e2f --- /dev/null +++ b/src/plugin/src/models/signal.interface.d.ts @@ -0,0 +1,7 @@ +import { LocalStorage } from "./model"; +export interface params { + key: string; + localStorage: typeof localStorage; + instance: typeof LocalStorage[]; + dataToSave: any; +} diff --git a/src/plugin/src/models/signal.interface.js b/src/plugin/src/models/signal.interface.js new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/src/plugin/src/models/signal.interface.js @@ -0,0 +1 @@ +export {}; diff --git a/src/plugin/src/models/signal.js b/src/plugin/src/models/signal.js new file mode 100644 index 000000000..b7e50af6d --- /dev/null +++ b/src/plugin/src/models/signal.js @@ -0,0 +1,51 @@ +const signalServiceData = { + rewriteGet: {}, + rewriteSave: {}, + rewriteDelete: {}, +}; +export const rewrite = { + rewriteGet: { + connect(callback, models) { + for (let model of models) { + const modelName = model.getTableSchema().id.keyPath; + signalServiceData.rewriteGet[modelName] = callback; + } + } + }, + rewriteSave: { + connect(callback, models) { + for (let model of models) { + const modelName = model.getTableSchema().id.keyPath; + signalServiceData.rewriteSave[modelName] = callback; + } + } + }, + rewriteDelete: { + connect(callback, models) { + for (let model of models) { + const modelName = model.getTableSchema().id.keyPath; + signalServiceData.rewriteDelete[modelName] = callback; + } + } + }, + hasRewriteGet(ModalName) { + return signalServiceData.rewriteGet[ModalName] != null; + }, + hasRewriteSave(ModalName) { + return signalServiceData.rewriteSave[ModalName] != null; + }, + hasRewriteDelete(ModalName) { + return signalServiceData.rewriteDelete[ModalName] != null; + } +}; +export const signalExecutor = { + rewriteGet(ModalName, instance) { + return signalServiceData.rewriteGet[ModalName]({ key: ModalName, localStorage: localStorage, instance }); + }, + rewriteSave(ModalName, instance, dataToSave) { + return signalServiceData.rewriteSave[ModalName]({ key: ModalName, localStorage: localStorage, instance, dataToSave }); + }, + rewriteDelete(ModalName, instance) { + return signalServiceData.rewriteDelete[ModalName]({ key: ModalName, localStorage: localStorage, instance }); + } +}; diff --git a/src/plugin/src/models/split.d.ts b/src/plugin/src/models/split.d.ts new file mode 100644 index 000000000..dd3f2a4b2 --- /dev/null +++ b/src/plugin/src/models/split.d.ts @@ -0,0 +1,2 @@ +import { Model } from "./model.js"; +export declare const split: (name: any, model: Model) => Model; diff --git a/src/plugin/src/models/split.js b/src/plugin/src/models/split.js new file mode 100644 index 000000000..4e3477f54 --- /dev/null +++ b/src/plugin/src/models/split.js @@ -0,0 +1,9 @@ +export const split = (name, model) => { + model['prototype']['getModelName'] = function () { + return name; + }; + model['getModelName'] = function () { + return name; + }; + return model; +}; diff --git a/src/plugin/src/reactive/DynamicList.d.ts b/src/plugin/src/reactive/DynamicList.d.ts new file mode 100644 index 000000000..01ef5e1f7 --- /dev/null +++ b/src/plugin/src/reactive/DynamicList.d.ts @@ -0,0 +1,9 @@ +import { Model } from "../models/model.js"; +export declare class ReactiveList { + static subscribe(model: typeof Model, callback: any): { + readonly value: any; + readonly subscribe: any; + unsubscribe: () => Promise; + setUpdateUi(func: any): void; + }; +} diff --git a/src/plugin/src/reactive/DynamicList.js b/src/plugin/src/reactive/DynamicList.js new file mode 100644 index 000000000..e1ed0cfb4 --- /dev/null +++ b/src/plugin/src/reactive/DynamicList.js @@ -0,0 +1,36 @@ +import { Model } from "../models/model.js"; +import { transactionOnCommit } from "../triggers/transaction.js"; +let values = {}; +export class ReactiveList { + static subscribe(model, callback) { + let transactionOnCommitSubscription; + let value; + let updateUi; + transactionOnCommitSubscription = transactionOnCommit.subscribe(model, async () => { + value = await callback(Model); + if (updateUi) { + updateUi(); + } + }); + callback(Model).then(result => { + value = result; + if (updateUi) { + updateUi(); + } + }); + return { + get value() { + return value; + }, + get subscribe() { + return transactionOnCommitSubscription.subscribe; + }, + unsubscribe: async () => { + return await transactionOnCommitSubscription.unsubscribe(); + }, + setUpdateUi(func) { + updateUi = func; + } + }; + } +} diff --git a/src/plugin/src/sql/Operators/Object-condition-operator.d.ts b/src/plugin/src/sql/Operators/Object-condition-operator.d.ts new file mode 100644 index 000000000..7f1e4550b --- /dev/null +++ b/src/plugin/src/sql/Operators/Object-condition-operator.d.ts @@ -0,0 +1,10 @@ +import { TableSchema } from '../../models/register-modal.interface.js'; +import { argsAttributes } from './args-attributes.js'; +export declare class ObjectConditionOperator { + private TableSchema; + private args; + row: any; + constructor(TableSchema: TableSchema, args: argsAttributes); + run(row: any): boolean | any; + private execute; +} diff --git a/src/plugin/src/sql/Operators/Object-condition-operator.js b/src/plugin/src/sql/Operators/Object-condition-operator.js new file mode 100644 index 000000000..5193cda2a --- /dev/null +++ b/src/plugin/src/sql/Operators/Object-condition-operator.js @@ -0,0 +1,33 @@ +export class ObjectConditionOperator { + constructor(TableSchema, args) { + this.TableSchema = TableSchema; + this.args = args; + } + run(row) { + this.row = row; + for (const arg of this.args.value) { + const result = this.execute(arg); + if (result) { + return true; + } + } + } + execute(objOperator) { + for (let objOperatorFieldName in objOperator) { + const field = objOperator[objOperatorFieldName]; + const fieldName = field.fieldName; + const fieldPath = field.fieldPath; + const operation = field.operation; + const operationArg = field.operationArg; + const fieldClassName = field.fieldClassName; + const operator = field.operator; + const customData = field.customData({ row: this.row, fieldPath }); + const arg = operationArg; + let operationResult = operator({ fieldName, arg, row: this.row, TableSchema: this.TableSchema, element: fieldName, fieldPath, customData }); + if (!operationResult) { + return false; + } + } + return true; + } +} diff --git a/src/plugin/src/sql/Operators/args-attributes.d.ts b/src/plugin/src/sql/Operators/args-attributes.d.ts new file mode 100644 index 000000000..d3bdedddc --- /dev/null +++ b/src/plugin/src/sql/Operators/args-attributes.d.ts @@ -0,0 +1,31 @@ +import { AttributesMap, FieldKeys, FieldsMap } from "../../models/field/fields.interface.js"; +import { OperatorKeys } from "./object-operator.js"; +import { TableSchema, FieldSchema } from '../../models/register-modal.interface.js'; +export interface Field { + fieldName: string; + fieldPath: string; + operation: OperatorKeys; + operationArg?: string; + operator: Function; + fieldClassName: FieldKeys; + customData?: Function; +} +export interface value { + fieldName: string; + fieldPath: string; + operation: any; + operationArg: any; + operator: Function; + fieldClassName: any; + customData?: Function; +} +export declare class argsAttributes { + private TableSchema; + value: Array>; + schemeFields: AttributesMap; + constructor(args: any, TableSchema: TableSchema); + private analyzeArgs; + private detectClassName; + private detectOperator; + private argsPrettyTransform; +} diff --git a/src/plugin/src/sql/Operators/args-attributes.js b/src/plugin/src/sql/Operators/args-attributes.js new file mode 100644 index 000000000..a60c91980 --- /dev/null +++ b/src/plugin/src/sql/Operators/args-attributes.js @@ -0,0 +1,114 @@ +import { OperatorsKeysArray, operator, ObjOperatorOverwrite, ArrOperatorOverwrite } from "./object-operator.js"; +import { info } from "./operators.js"; +export class argsAttributes { + constructor(args, TableSchema) { + this.TableSchema = TableSchema; + this.value = []; + this.schemeFields = {} = {}; + for (const field of this.TableSchema.fields) { + this.schemeFields[field.name] = field; + } + this.schemeFields[this.TableSchema.id.keyPath] = { + keyPath: this.TableSchema.id.keyPath, + name: this.TableSchema.id.keyPath, + className: 'IntegerField', + }; + if (args.constructor.name != 'Array') { + args = [args]; + } + const conditions = this.argsPrettyTransform(args); + this.value = this.analyzeArgs(conditions); + } + analyzeArgs(conditions) { + return conditions.map((condition) => { + const newObject = {}; + const keys = Object.keys(condition); + for (let field of keys) { + let fieldName; + let fieldPath; + let arg; + const element = field.split('__'); + if (element.length == 1) { + element.push('eq'); + } + let operation = element[element.length - 1]; + if (OperatorsKeysArray.includes(operation)) { + operation = element.pop(); + } + else { + operation = 'eq'; + } + fieldName = element[0]; + fieldPath = element.join('.'); + if (OperatorsKeysArray.includes(operation)) { + arg = condition[field]; + } + else { + throw ('operator'); + } + const fieldClassName = this.detectClassName(fieldName); + newObject[field] = { + fieldName: fieldName, + fieldPath: fieldPath, + operation: operation, + operationArg: arg, + operator: this.detectOperator(fieldClassName, operation, fieldName), + fieldClassName: fieldClassName, + }; + if (fieldClassName == 'indexedDBArrayField' || fieldClassName == 'indexedDBJsonField') { + newObject[field]['customData'] = info.run; + } + else { + newObject[field]['customData'] = () => { }; + } + } + return newObject; + }); + } + detectClassName(fieldName) { + return this.schemeFields[fieldName].className; + } + detectOperator(fieldClassName, operation, fieldName) { + try { + if (fieldClassName == 'indexedDBJsonField') { + return ObjOperatorOverwrite[operation]; + } + else if (fieldClassName == 'indexedDBArrayField') { + return ArrOperatorOverwrite[operation]; + } + else { + return operator[operation]; + } + } + catch (err) { + throw ('Field ' + fieldName + ' does not exit on the table' + err); + } + } + argsPrettyTransform(args) { + const conditions = []; + const loop = (o) => { + // https://stackoverflow.com/a/38597076/14115342 + const condition = {}; + for (const k of Object.keys(o)) { + if (o[k].constructor.name === 'Array') { + loop(o[k]); + } + else { + if (o.constructor.name === 'Array') { + for (const j of Object.keys(o[k])) { + condition[j] = o[k][j]; + } + } + else { + condition[k] = o[k]; + } + } + } + if (JSON.stringify(condition) !== '{}') { + conditions.push(condition); + } + }; + loop(args); + return conditions; + } +} diff --git a/src/plugin/src/sql/Operators/object-operator.d.ts b/src/plugin/src/sql/Operators/object-operator.d.ts new file mode 100644 index 000000000..c027dfb9f --- /dev/null +++ b/src/plugin/src/sql/Operators/object-operator.d.ts @@ -0,0 +1,478 @@ +export declare const OperatorsKeysArray: readonly ["gt", "gte", "lt", "lte", "not", "eq", "contains", "len", "hasKey", "ForeignKey", "containedBy", "overlap", "isNull", "contained_by", "has_key", "has_keys", "has_any_keys", "len", "overlap", "iexact"]; +export declare type OperatorKeys = typeof OperatorsKeysArray[number]; +export declare const operator: { + gt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + gte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + lt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + lte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + not: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => any; + len({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + hasKey({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + containedBy({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + overlap({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): any; + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + iexact({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; +}; +export declare const ObjOperatorOverwrite: { + gt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + gte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + lt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + lte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + not: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => any; + len({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + hasKey({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + containedBy({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + overlap({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): any; + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + iexact({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; +} & { + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + contained_by: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + has_key({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + has_keys({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + has_any_keys({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; +}; +export declare const ArrOperatorOverwrite: { + gt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + gte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + lt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + lte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + not: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => any; + len({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + hasKey({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + containedBy({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + overlap({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): any; + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + iexact({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; +} & { + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }): boolean; + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + contained_by: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + len: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; + overlap: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + TableSchema: any; + element: any; + fieldPath: any; + customData: any; + }) => boolean; +}; diff --git a/src/plugin/src/sql/Operators/object-operator.js b/src/plugin/src/sql/Operators/object-operator.js new file mode 100644 index 000000000..9322d5db1 --- /dev/null +++ b/src/plugin/src/sql/Operators/object-operator.js @@ -0,0 +1,107 @@ +import * as operatorsObject from './operators.js'; +export const OperatorsKeysArray = [ + 'gt', + 'gte', + 'lt', + 'lte', + 'not', + 'eq', + 'contains', + 'len', + 'hasKey', + 'ForeignKey', + 'containedBy', + 'overlap', + 'isNull', + 'contained_by', + 'has_key', + 'has_keys', + 'has_any_keys', + 'len', + 'overlap', + 'iexact' +]; // TS3.4 syntax +export const operator = { + gt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.gt.validate({ fieldName, arg, row, fieldPath, customData }); + }, + gte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.gte.validate({ fieldName, arg, row, fieldPath, customData }); + }, + lt: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.lt.validate({ fieldName, arg, row, fieldPath, customData }); + }, + lte: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.lte.validate({ fieldName, arg, row, fieldPath }); + }, + not: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.not.validate({ fieldName, arg, row, fieldPath }); + }, + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.eq.validate({ fieldName, arg, row, fieldPath, customData }); + }, + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.contains.validate({ fieldName, arg, row, fieldPath, customData }); + }, + len({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.len.validate({ fieldName, arg, row, fieldPath, customData }); + }, + hasKey({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.hasKey.validate({ fieldName, arg, row, fieldPath, customData }); + }, + containedBy({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.containedBy.validate({ fieldName, arg, row, fieldPath, customData }); + }, + overlap({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.overlap.validate({ fieldName, arg, row, fieldPath, customData }); + }, + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.isNull.validate({ fieldName, arg, row, fieldPath, customData }); + }, + iexact({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.iexact.validate({ fieldName, arg, row, fieldPath, customData }); + } +}; +export const ObjOperatorOverwrite = Object.assign(Object.assign({}, operator), { + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.objectIsnull.validate({ fieldName, arg, row, fieldPath, customData }); + }, + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.objectEq.validate({ fieldName, arg, row, fieldPath, customData }); + }, + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.objectContains.validate({ fieldName, arg, row, fieldPath, customData }); + }, + contained_by: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.objectContains_by.validate({ fieldName, arg, row, fieldPath, customData }); + }, + has_key({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.objectHasKey.validate({ fieldName, arg, row, fieldPath, customData }); + }, + has_keys({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.objectHasKeys.validate({ fieldName, arg, row, fieldPath, customData }); + }, + has_any_keys({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.objectHasnyKeys.validate({ fieldName, arg, row, fieldPath, customData }); + } +}); +export const ArrOperatorOverwrite = Object.assign(Object.assign({}, operator), { + isNull({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) { + return operatorsObject.objectIsnull.validate({ fieldName, arg, row, fieldPath, customData }); + }, + eq: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.ArrayFieldEq.validate({ fieldName, arg, row, fieldPath, customData }); + }, + contains: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.ArrayFieldContains.validate({ fieldName, arg, row, fieldPath, customData }); + }, + contained_by: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.ArrayFieldContains_by.validate({ fieldName, arg, row, fieldPath, customData }); + }, + len: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.ArrayFieldContains_len.validate({ fieldName, arg, row, fieldPath, customData }); + }, + overlap: ({ fieldName, arg, row, TableSchema, element, fieldPath, customData }) => { + return operatorsObject.ArrayFieldContains_overlap.validate({ fieldName, arg, row, fieldPath, customData }); + } +}); diff --git a/src/plugin/src/sql/Operators/operators.d.ts b/src/plugin/src/sql/Operators/operators.d.ts new file mode 100644 index 000000000..fc7c952a5 --- /dev/null +++ b/src/plugin/src/sql/Operators/operators.d.ts @@ -0,0 +1,258 @@ +export declare class gt { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class iexact { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class gte { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class lt { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class lte { + static validate({ fieldName, arg, row, fieldPath }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + }): boolean; +} +export declare class not { + static validate({ fieldName, arg, row, fieldPath }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + }): boolean; +} +export declare class eq { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class contains { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): any; +} +export declare class info { + static run({ row, fieldPath }: { + row: any; + fieldPath: any; + }): { + value: any; + present: any; + }; +} +export declare class containsOBj { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class containedBy { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class overlap { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): any; +} +export declare class len { + static validate({ fieldName, arg, rowFieldValue, row, fieldPath, customData }: { + fieldName: any; + arg: any; + rowFieldValue?: any[]; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class hasKey { + static validate({ fieldName, arg, rowFieldValue, row, fieldPath, customData }: { + fieldName: any; + arg: any; + rowFieldValue?: any[]; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class hasAnyKeys { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): any; +} +/** + * @returns true when all of the given keys are in the data + */ +export declare class hasKeys { + static validate(fieldObj: any, keys: any, row: any): boolean; +} +export declare class isNull { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class objectIsnull { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class objectEq { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class objectContains { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class objectContains_by { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class objectHasKey { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class objectHasKeys { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class objectHasnyKeys { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class ArrayFieldEq { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class ArrayFieldContains { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class ArrayFieldContains_by { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class ArrayFieldContains_overlap { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} +export declare class ArrayFieldContains_len { + static validate({ fieldName, arg, row, fieldPath, customData }: { + fieldName: any; + arg: any; + row: any; + fieldPath: any; + customData: any; + }): boolean; +} diff --git a/src/plugin/src/sql/Operators/operators.js b/src/plugin/src/sql/Operators/operators.js new file mode 100644 index 000000000..b4f216e2f --- /dev/null +++ b/src/plugin/src/sql/Operators/operators.js @@ -0,0 +1,573 @@ +import { getDeep } from '../../utils.js'; +export class gt { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue > arg; + } +} +export class iexact { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue === arg; + } +} +export class gte { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue >= arg; + } +} +export class lt { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue < arg; + } +} +export class lte { + static validate({ fieldName, arg, row, fieldPath }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue <= arg; + } +} +export class not { + static validate({ fieldName, arg, row, fieldPath }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue != arg; + } +} +export class eq { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue == arg; + } +} +export class contains { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue.some(r => arg.includes(r)); + } +} +export class info { + static run({ row, fieldPath }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return { + present: false, + value: undefined + }; + } + } + catch (error) { + return { + present: false, + value: undefined + }; + } + return { + present: true, + value: undefined + }; + } +} +export class containsOBj { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + const keys = Object.keys(arg); + for (let key of keys) { + if (!_rowFieldValue[key]) { + return false; + } + } + return true; + } +} +export class containedBy { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + for (let value of _rowFieldValue) { + if (!arg.includes(value)) { + return false; + } + } + return true; + } +} +export class overlap { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue.some(r => arg.includes(r)); + } +} +export class len { + static validate({ fieldName, arg, rowFieldValue = [], row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue.length == arg; + } +} +export class hasKey { + static validate({ fieldName, arg, rowFieldValue = [], row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + const keys = Object.keys(arg); + for (let key of keys) { + if (!_rowFieldValue[key]) { + return false; + } + } + } +} +export class hasAnyKeys { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return _rowFieldValue.some(key => !arg.includes(key)); + } +} +/** + * @returns true when all of the given keys are in the data + */ +export class hasKeys { + static validate(fieldObj, keys, row) { + for (let fieldName of keys) { + if (!fieldObj[fieldName]) { + return false; + } + } + return true; + } +} +// Slice transforms +export class isNull { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + return (_rowFieldValue == null) == arg; + } +} +// object +export class objectIsnull { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowFieldValue; + try { + rowFieldValue = getDeep(row, fieldPath); + if (rowFieldValue === undefined) { + if (arg == true) { + return true; + } + } + } + catch (error) { + if (arg == true) { + return true; + } + return false; + } + if (JSON.stringify(rowFieldValue) == '{}' && arg == false) { + return true; + } + else if (rowFieldValue == null && arg == true) { + return true; + } + else if (rowFieldValue == undefined) { + return true; + } + return false; + } +} +export class objectEq { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + if (JSON.stringify(_rowFieldValue = getDeep(row, fieldPath)) == '{}' && '{}' == JSON.stringify(arg)) { + return true; + } + else if (arg == null && JSON.stringify(_rowFieldValue) == '{}') { + return true; + } + else if (fieldPath) { + if (arg == _rowFieldValue) { + return true; + } + } + return false; + } +} +export class objectContains { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + for (const keys of Object.keys(arg)) { + if (!rowValue[keys]) { + return false; + } + else { + if (rowValue[keys] != arg[keys]) { + return false; + } + } + } + return true; + } +} +export class objectContains_by { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + const keyCount = Object.keys(arg).length; + let keyFoundNEqual = 0; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + else { + for (const keys of Object.keys(arg)) { + if (rowValue[keys]) { + if (rowValue[keys] == arg[keys]) { + keyFoundNEqual++; + } + } + } + } + } + catch (error) { + return false; + } + if (keyFoundNEqual == 0) { + return true; + } + else if (keyFoundNEqual == keyCount) { + return true; + } + return false; + } +} +export class objectHasKey { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + if (rowValue[arg]) { + return true; + } + return false; + } +} +export class objectHasKeys { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + const keys = Object.keys(rowValue); + for (const a of arg) { + if (!keys.includes(a)) { + return false; + } + } + return true; + } +} +export class objectHasnyKeys { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + const keys = Object.keys(rowValue); + for (const a of arg) { + if (keys.includes(a)) { + return true; + } + } + return false; + } +} +// array shit +export class ArrayFieldEq { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let _rowFieldValue; + try { + _rowFieldValue = getDeep(row, fieldPath); + if (_rowFieldValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + if (JSON.stringify(_rowFieldValue) == '[]' && '[]' == JSON.stringify(arg)) { + return true; + } + else if (arg == null && JSON.stringify(_rowFieldValue) == '[]') { + return true; + } + else if (fieldPath) { + if (arg == _rowFieldValue) { + return true; + } + } + return false; + } +} +export class ArrayFieldContains { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + try { + for (const keys of arg) { + if (!rowValue.includes(keys)) { + return false; + } + } + } + catch (error) { + return false; + } + return true; + } +} +export class ArrayFieldContains_by { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + try { + for (const keys of arg) { + if (rowValue.includes(keys)) { + return true; + } + } + } + catch (error) { + return false; + } + return false; + } +} +export class ArrayFieldContains_overlap { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + try { + for (const keys of arg) { + if (rowValue.includes(keys)) { + return true; + } + } + } + catch (error) { + return false; + } + return false; + } +} +export class ArrayFieldContains_len { + static validate({ fieldName, arg, row, fieldPath, customData }) { + let rowValue; + try { + rowValue = getDeep(row, fieldPath); + if (rowValue === undefined) { + return false; + } + } + catch (error) { + return false; + } + if (rowValue.length == arg) { + return true; + } + return false; + } +} diff --git a/src/plugin/src/sql/Operators/query-bulder.d.ts b/src/plugin/src/sql/Operators/query-bulder.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/sql/Operators/query-bulder.js b/src/plugin/src/sql/Operators/query-bulder.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/plugin/src/sql/methods/filter.d.ts b/src/plugin/src/sql/methods/filter.d.ts new file mode 100644 index 000000000..1169c4cf1 --- /dev/null +++ b/src/plugin/src/sql/methods/filter.d.ts @@ -0,0 +1,11 @@ +import { ObjectConditionOperator } from '../Operators/Object-condition-operator.js'; +import { argsAttributes } from '../Operators/args-attributes.js'; +export declare class filter { + private arg; + private TableSchema; + rows: any[]; + operator: ObjectConditionOperator; + constructor(arg: argsAttributes, TableSchema: any); + cursor(row: object, resolve?: any, limit?: any): Promise; + run(rows: any[]): Promise; +} diff --git a/src/plugin/src/sql/methods/filter.js b/src/plugin/src/sql/methods/filter.js new file mode 100644 index 000000000..e8563a9ba --- /dev/null +++ b/src/plugin/src/sql/methods/filter.js @@ -0,0 +1,28 @@ +import { ObjectConditionOperator } from '../Operators/Object-condition-operator.js'; +export class filter { + constructor(arg, TableSchema) { + this.arg = arg; + this.TableSchema = TableSchema; + this.rows = []; + this.operator = new ObjectConditionOperator(this.TableSchema, this.arg); + } + async cursor(row, resolve, limit) { + const operationsResult = await this.operator.run(row); + if (operationsResult == true) { + this.rows.push(row); + if (this.rows.length == limit) { + resolve(this.rows); + } + } + } + async run(rows) { + const newRows = []; + for (let row of rows) { + const operationsResult = await this.operator.run(row); + if (operationsResult == true) { + newRows.push(row); + } + } + return newRows; + } +} diff --git a/src/plugin/src/sql/methods/methods.d.ts b/src/plugin/src/sql/methods/methods.d.ts new file mode 100644 index 000000000..36eb234c1 --- /dev/null +++ b/src/plugin/src/sql/methods/methods.d.ts @@ -0,0 +1,14 @@ +export declare const methodsType: readonly ["filter"]; +export declare type methodsTypeKeys = typeof methodsType[number]; +export declare type methodsMap = { + [P in K]?: T; +}; +export declare class methodFunction { + private arg; + private TableSchema; + rows: any[]; + constructor(arg: any, TableSchema: any); + cursor(row: object, resolve?: any, limit?: any): Promise; + run(rows: any[]): Promise; +} +export declare const methods: methodsMap; diff --git a/src/plugin/src/sql/methods/methods.js b/src/plugin/src/sql/methods/methods.js new file mode 100644 index 000000000..04abc8bd0 --- /dev/null +++ b/src/plugin/src/sql/methods/methods.js @@ -0,0 +1,7 @@ +import { filter } from './filter.js'; +export const methodsType = [ + 'filter', +]; // TS3.4 syntax +export const methods = { + filter: filter +}; diff --git a/src/plugin/src/sql/query/interface.d.ts b/src/plugin/src/sql/query/interface.d.ts new file mode 100644 index 000000000..c51a9ae6c --- /dev/null +++ b/src/plugin/src/sql/query/interface.d.ts @@ -0,0 +1,12 @@ +export declare enum FieldType { + AUTO = 0, + INT = 1, + BIGINT = 2, + TEXT = 3, + VARCHAR = 4, + DATE = 5, + BOOL = 6, + CHAR = 7, + JSON = 8, + ARRAY = 9 +} diff --git a/src/plugin/src/sql/query/interface.js b/src/plugin/src/sql/query/interface.js new file mode 100644 index 000000000..42481b09a --- /dev/null +++ b/src/plugin/src/sql/query/interface.js @@ -0,0 +1,14 @@ +export var FieldType; +(function (FieldType) { + FieldType[FieldType["AUTO"] = 0] = "AUTO"; + FieldType[FieldType["INT"] = 1] = "INT"; + FieldType[FieldType["BIGINT"] = 2] = "BIGINT"; + FieldType[FieldType["TEXT"] = 3] = "TEXT"; + FieldType[FieldType["VARCHAR"] = 4] = "VARCHAR"; + FieldType[FieldType["DATE"] = 5] = "DATE"; + FieldType[FieldType["BOOL"] = 6] = "BOOL"; + FieldType[FieldType["CHAR"] = 7] = "CHAR"; + FieldType[FieldType["JSON"] = 8] = "JSON"; + FieldType[FieldType["ARRAY"] = 9] = "ARRAY"; +})(FieldType || (FieldType = {})); +// diff --git a/src/plugin/src/sql/sqlObject/sql.d.ts b/src/plugin/src/sql/sqlObject/sql.d.ts new file mode 100644 index 000000000..a4c423060 --- /dev/null +++ b/src/plugin/src/sql/sqlObject/sql.d.ts @@ -0,0 +1,3 @@ +declare class sql { + filter(): void; +} diff --git a/src/plugin/src/sql/sqlObject/sql.js b/src/plugin/src/sql/sqlObject/sql.js new file mode 100644 index 000000000..4c777dc5c --- /dev/null +++ b/src/plugin/src/sql/sqlObject/sql.js @@ -0,0 +1,3 @@ +class sql { + filter() { } +} diff --git a/src/plugin/src/sql/sqlObject/sqlObject.d.ts b/src/plugin/src/sql/sqlObject/sqlObject.d.ts new file mode 100644 index 000000000..69abf4c89 --- /dev/null +++ b/src/plugin/src/sql/sqlObject/sqlObject.d.ts @@ -0,0 +1,17 @@ +import { Method } from '../../models/model.interface.js'; +import { TableSchema } from '../../models/register-modal.interface.js'; +import { methodFunction } from '../methods/methods.js'; +import { argsAttributes } from '../Operators/args-attributes.js'; +export declare class SqlObject { + private TableSchema; + private Methods; + limit: number; + rows: any[]; + firstMethod: methodFunction; + params: any[]; + argsAttributes: argsAttributes; + constructor(TableSchema: TableSchema, Methods: Method[]); + runFirstMethod(row: any, resolve?: any, limit?: any): Promise; + doneRunFirstMethod(): Promise; + run(): Promise; +} diff --git a/src/plugin/src/sql/sqlObject/sqlObject.js b/src/plugin/src/sql/sqlObject/sqlObject.js new file mode 100644 index 000000000..e59a2c9f6 --- /dev/null +++ b/src/plugin/src/sql/sqlObject/sqlObject.js @@ -0,0 +1,31 @@ +import { methods } from '../methods/methods.js'; +import { argsAttributes } from '../Operators/args-attributes.js'; +export class SqlObject { + constructor(TableSchema, Methods) { + this.TableSchema = TableSchema; + this.Methods = Methods; + this.limit = 0; + this.rows = []; + this.params = []; + const arg = this.Methods[0].arguments; + const methodName = this.Methods[0].methodName; + this.argsAttributes = new argsAttributes(arg, TableSchema); + this.firstMethod = new methods[methodName](this.argsAttributes, this.TableSchema); + } + async runFirstMethod(row, resolve, limit) { + this.firstMethod.cursor(row, resolve, limit); + } + async doneRunFirstMethod() { + this.rows = this.firstMethod.rows; + } + async run() { + for (let i = 1; i < this.Methods.length; i++) { + const method = this.Methods[i]; + const methodName = method.methodName; + if (methods[methodName]) { + const methodToExecute = new methods[methodName](this.argsAttributes, this.TableSchema); + this.rows = await methodToExecute.run(this.rows); + } + } + } +} diff --git a/src/plugin/src/triggers/transaction.d.ts b/src/plugin/src/triggers/transaction.d.ts new file mode 100644 index 000000000..6b9d299f9 --- /dev/null +++ b/src/plugin/src/triggers/transaction.d.ts @@ -0,0 +1,19 @@ +import { Model } from "../models/model.js"; +export declare class transactionOnCommit { + static stores: { + [dbName: string]: { + [store: string]: { + [requestId: string]: Function; + }; + }; + }; + static subscription: { + [SubscriptionName: string]: boolean; + }; + static prepare(model: typeof Model): void; + static subscribe(model: typeof Model, callback: any): { + queryId: string; + subscribe: boolean; + unsubscribe: () => Promise; + }; +} diff --git a/src/plugin/src/triggers/transaction.js b/src/plugin/src/triggers/transaction.js new file mode 100644 index 000000000..896425781 --- /dev/null +++ b/src/plugin/src/triggers/transaction.js @@ -0,0 +1,59 @@ +import { taskHolder } from "../connection/taskHolder.js"; +import { ModelAPIRequest } from "../models/model-manager.js"; +import { uniqueGenerator } from "../utils.js"; +export class transactionOnCommit { + static prepare(model) { + const TableSchema = model.getTableSchema(); + const DatabaseSchema = model.getDBSchema(); + const databaseName = DatabaseSchema.databaseName; + const table = TableSchema.name; + this.stores[databaseName] = {}; + this.stores[databaseName][table] = {}; + } + static subscribe(model, callback) { + const TableSchema = model.getTableSchema(); + const DatabaseSchema = model.getDBSchema(); + const databaseName = DatabaseSchema.databaseName; + const table = TableSchema.name; + const SubscriptionName = databaseName + table; + const queryId = uniqueGenerator(); + let subscribe = false; + this.stores[databaseName][table][queryId] = callback; + if (!this.subscription[SubscriptionName]) { + // + const args = { + type: 'transactionOnCommit', + subscribe: true + }; + ModelAPIRequest.obj(DatabaseSchema, TableSchema).trigger(args, SubscriptionName, async () => { + subscribe = true; + taskHolder.updateFunction(SubscriptionName, 'callback', () => { + for (const [requestId, callback] of Object.entries(this.stores[databaseName][table])) { + callback(); + } + }); + }); + } + return { + queryId, + subscribe, + unsubscribe: () => { + return new Promise((resolve, reject) => { + delete this.stores[databaseName][table][queryId]; + if (Object.keys(this.stores[databaseName][table]).length == 0) { + ModelAPIRequest.obj(DatabaseSchema, TableSchema).trigger({ type: 'transactionOnCommit', subscribe: false }, SubscriptionName, async (data) => { + delete this.subscription[SubscriptionName]; + taskHolder.finish(SubscriptionName); + resolve(data); + }); + } + else { + resolve(true); + } + }); + } + }; + } +} +transactionOnCommit.stores = {}; +transactionOnCommit.subscription = {}; diff --git a/src/plugin/src/triggers/triggers.d.ts b/src/plugin/src/triggers/triggers.d.ts new file mode 100644 index 000000000..d911f386b --- /dev/null +++ b/src/plugin/src/triggers/triggers.d.ts @@ -0,0 +1,36 @@ +import { Model } from "../models/model.js"; +interface Trigger { + callback: Function; +} +export declare class triggers { + static beforeInsert(Model: Model, callback: Function): { + SubscriptionName: string; + disconnect(): void; + }; + static AfterInsert(Model: any, callback: Function): { + dispatchUID: string; + disconnect(): void; + }; + static beforeDelete(Model: any, callback: Function): { + dispatchUID: string; + disconnect(): void; + }; + static AfterDelete(Model: any, callback: Function): { + dispatchUID: string; + disconnect(): void; + }; +} +export declare class triggerSignal { + static beforeInsertExist(Model: any): Trigger[]; + static beforeInsert(instance: Model): Promise; + static AfterInsertExist(Model: any): Trigger[]; + static AfterInsert(instance: Model): Promise; + static AfterDeleteExist(Model: any): Trigger[]; + static AfterDelete(instance: Model | string, { modelName, databaseName }: any): Promise; + static BeforeDeleteExist(Model: any): Trigger[]; + static BeforeDelete(instance: Model | string, { modelName, databaseName }: { + modelName: any; + databaseName: any; + }): Promise; +} +export {}; diff --git a/src/plugin/src/triggers/triggers.js b/src/plugin/src/triggers/triggers.js new file mode 100644 index 000000000..03c0de48e --- /dev/null +++ b/src/plugin/src/triggers/triggers.js @@ -0,0 +1,152 @@ +import { ModelAPIRequest } from "../models/model-manager.js"; +import { hashCode, uniqueGenerator } from "../utils.js"; +let triggerBeforeInsert = {}; +let triggerAfterInsert = {}; +let triggerBeforeDelete = {}; +let triggerAfterDelete = {}; +function createModelAttributeBefore(Model, triggerType) { + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + if (!triggerBeforeInsert[databaseName]) { + triggerBeforeInsert[databaseName] = {}; + } + if (!triggerBeforeInsert[databaseName][ModelName]) { + triggerBeforeInsert[databaseName][ModelName] = []; + } + return { ModelName, databaseName }; +} +function createModelAttributeAfter(Model, triggerType) { + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + if (!triggerAfterInsert[databaseName]) { + triggerAfterInsert[databaseName] = {}; + } + if (!triggerAfterInsert[databaseName][ModelName]) { + triggerAfterInsert[databaseName][ModelName] = []; + } + return { ModelName, databaseName }; +} +function deleteModelAttributeBeforeDelete(Model, triggerType) { + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + if (!triggerBeforeDelete[databaseName]) { + triggerBeforeDelete[databaseName] = {}; + } + if (!triggerBeforeDelete[databaseName][ModelName]) { + triggerBeforeDelete[databaseName][ModelName] = []; + } + return { ModelName, databaseName }; +} +function deleteModelAttributeAfterDelete(Model, triggerType) { + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + if (!triggerAfterDelete[databaseName]) { + triggerAfterDelete[databaseName] = {}; + } + if (!triggerAfterDelete[databaseName][ModelName]) { + triggerAfterDelete[databaseName][ModelName] = []; + } + return { ModelName, databaseName }; +} +export class triggers { + static beforeInsert(Model, callback) { + const SubscriptionName = Model.getDBSchema().databaseName + Model.getTableSchema().name + 'beforeInsert'; + const Subscription = hashCode(SubscriptionName).toString(); + const { ModelName, databaseName } = createModelAttributeBefore(Model); + triggerBeforeInsert[databaseName][ModelName].push({ callback }); + const functionId = uniqueGenerator(); + const args = {}; + const eventHandler = () => { + }; + ModelAPIRequest.obj(Model.getDBSchema(), Model.getTableSchema()).trigger(args, Subscription, eventHandler); + return { + SubscriptionName: SubscriptionName, + disconnect() { + delete triggerBeforeInsert[databaseName][ModelName]; + } + }; + } + static AfterInsert(Model, callback) { + const id = uniqueGenerator(); + const { ModelName, databaseName } = createModelAttributeAfter(Model); + triggerAfterInsert[databaseName][ModelName].push({ callback }); + return { + dispatchUID: id, + disconnect() { + delete triggerBeforeInsert[databaseName][ModelName]; + } + }; + } + static beforeDelete(Model, callback) { + const id = uniqueGenerator(); + const { ModelName, databaseName } = deleteModelAttributeBeforeDelete(Model); + triggerBeforeDelete[databaseName][ModelName].push({ callback }); + return { + dispatchUID: id, + disconnect() { + delete triggerBeforeDelete[databaseName][ModelName]; + } + }; + } + static AfterDelete(Model, callback) { + const id = uniqueGenerator(); + const { ModelName, databaseName } = deleteModelAttributeAfterDelete(Model); + triggerAfterDelete[databaseName][ModelName].push({ callback }); + return { + dispatchUID: id, + disconnect() { + delete triggerAfterDelete[databaseName][ModelName]; + } + }; + } +} +export class triggerSignal { + static beforeInsertExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerBeforeInsert === null || triggerBeforeInsert === void 0 ? void 0 : triggerBeforeInsert[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async beforeInsert(instance) { + const ModelName = instance.getModelName(); + const databaseName = instance.getDBSchema().databaseName; + for (const trigger of triggerBeforeInsert[databaseName][ModelName]) { + trigger.callback(instance); + } + } + static AfterInsertExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerAfterInsert === null || triggerAfterInsert === void 0 ? void 0 : triggerAfterInsert[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async AfterInsert(instance) { + const ModelName = instance.getModelName(); + const databaseName = instance.getDBSchema().databaseName; + for (const trigger of triggerAfterInsert[databaseName][ModelName]) { + trigger.callback(instance); + } + } + static AfterDeleteExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerAfterDelete === null || triggerAfterDelete === void 0 ? void 0 : triggerAfterDelete[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async AfterDelete(instance, { modelName, databaseName }) { + for (const trigger of triggerAfterDelete[databaseName][modelName]) { + trigger.callback(instance); + } + } + static BeforeDeleteExist(Model) { + var _a; + const ModelName = Model.getModelName(); + const databaseName = Model.getDBSchema().databaseName; + return (_a = triggerBeforeDelete === null || triggerBeforeDelete === void 0 ? void 0 : triggerBeforeDelete[databaseName]) === null || _a === void 0 ? void 0 : _a[ModelName]; + } + static async BeforeDelete(instance, { modelName, databaseName }) { + for (const trigger of triggerBeforeDelete[databaseName][modelName]) { + trigger.callback(instance); + } + } +} diff --git a/src/plugin/src/tsconfig.tsbuildinfo b/src/plugin/src/tsconfig.tsbuildinfo new file mode 100644 index 000000000..4ee068f35 --- /dev/null +++ b/src/plugin/src/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../src/utils.ts","../../src/models/model.interface.ts","../../src/sql/query/interface.ts","../../src/models/field/field.ts","../../src/models/field/allfields.ts","../../src/models/field/interface.ts","../../src/models/field/fields.ts","../../src/models/field/fields.interface.ts","../../src/models/register-modal.interface.ts","../../src/sql/operators/operators.ts","../../src/sql/operators/object-operator.ts","../../src/sql/operators/args-attributes.ts","../../src/sql/operators/object-condition-operator.ts","../../src/sql/methods/filter.ts","../../src/sql/methods/methods.ts","../../src/sql/sqlobject/sqlobject.ts","../../src/connection/taskholder.ts","../../src/connection/indexeddb/postmessage.ts","../../src/connection/indexeddb/transaction.ts","../../src/connection/indexeddb/objectstore.ts","../../src/connection/indexeddb/connect.ts","../../src/connection/indexeddb/database.ts","../../src/connection/indexeddb/databasemanager.ts","../../src/connection/indexeddb/indexedb.ts","../../src/connection/intreface.ts","../../src/connection/workermanager.ts","../../src/connection/dbswtich.ts","../../src/models/mode-migrations.ts","../../src/models/model-manager.ts","../../src/models/model.reader.ts","../../src/triggers/transaction.ts","../../src/models/schema/table-schema.ts","../../src/models/schema/database-schema.ts","../../src/models/schema/databae-manager-schema.ts","../../src/models/register-model.ts","../../src/reactive/dynamiclist.ts","../../src/models/signal.interface.ts","../../src/models/signal.ts","../../src/models/model.ts","../../src/index.ts","../../src/connection/worker.ts","../../src/connection/indexeddb/connector.interface.d.ts","../../src/connection/indexeddb/triggers/triggers.ts","../../src/connection/localstorage/localstorage.ts","../../src/connection/memory/db.ts","../../src/models/model-from.ts","../../src/models/split.ts","../../src/sql/operators/interface.d.ts","../../src/sql/operators/query-bulder.ts","../../src/sql/sqlobject/sql.ts","../../src/triggers/triggers.ts","../../node_modules/@babel/types/lib/index.d.ts","../../node_modules/@types/babel__generator/index.d.ts","../../node_modules/@babel/parser/typings/babel-parser.d.ts","../../node_modules/@types/babel__template/index.d.ts","../../node_modules/@types/babel__traverse/index.d.ts","../../node_modules/@types/babel__core/index.d.ts","../../node_modules/@types/ms/index.d.ts","../../node_modules/@types/debug/index.d.ts","../../node_modules/chalk/index.d.ts","../../node_modules/jest-diff/build/cleanupsemantic.d.ts","../../node_modules/pretty-format/build/types.d.ts","../../node_modules/pretty-format/build/index.d.ts","../../node_modules/jest-diff/build/types.d.ts","../../node_modules/jest-diff/build/difflines.d.ts","../../node_modules/jest-diff/build/printdiffs.d.ts","../../node_modules/jest-diff/build/index.d.ts","../../node_modules/jest-matcher-utils/build/index.d.ts","../../node_modules/@types/jest/index.d.ts","../../node_modules/@types/node/assert.d.ts","../../node_modules/@types/node/assert/strict.d.ts","../../node_modules/@types/node/globals.d.ts","../../node_modules/@types/node/async_hooks.d.ts","../../node_modules/@types/node/buffer.d.ts","../../node_modules/@types/node/child_process.d.ts","../../node_modules/@types/node/cluster.d.ts","../../node_modules/@types/node/console.d.ts","../../node_modules/@types/node/constants.d.ts","../../node_modules/@types/node/crypto.d.ts","../../node_modules/@types/node/dgram.d.ts","../../node_modules/@types/node/diagnostics_channel.d.ts","../../node_modules/@types/node/dns.d.ts","../../node_modules/@types/node/dns/promises.d.ts","../../node_modules/@types/node/domain.d.ts","../../node_modules/@types/node/events.d.ts","../../node_modules/@types/node/fs.d.ts","../../node_modules/@types/node/fs/promises.d.ts","../../node_modules/@types/node/http.d.ts","../../node_modules/@types/node/http2.d.ts","../../node_modules/@types/node/https.d.ts","../../node_modules/@types/node/inspector.d.ts","../../node_modules/@types/node/module.d.ts","../../node_modules/@types/node/net.d.ts","../../node_modules/@types/node/os.d.ts","../../node_modules/@types/node/path.d.ts","../../node_modules/@types/node/perf_hooks.d.ts","../../node_modules/@types/node/process.d.ts","../../node_modules/@types/node/punycode.d.ts","../../node_modules/@types/node/querystring.d.ts","../../node_modules/@types/node/readline.d.ts","../../node_modules/@types/node/repl.d.ts","../../node_modules/@types/node/stream.d.ts","../../node_modules/@types/node/stream/promises.d.ts","../../node_modules/@types/node/stream/consumers.d.ts","../../node_modules/@types/node/stream/web.d.ts","../../node_modules/@types/node/string_decoder.d.ts","../../node_modules/@types/node/timers.d.ts","../../node_modules/@types/node/timers/promises.d.ts","../../node_modules/@types/node/tls.d.ts","../../node_modules/@types/node/trace_events.d.ts","../../node_modules/@types/node/tty.d.ts","../../node_modules/@types/node/url.d.ts","../../node_modules/@types/node/util.d.ts","../../node_modules/@types/node/v8.d.ts","../../node_modules/@types/node/vm.d.ts","../../node_modules/@types/node/wasi.d.ts","../../node_modules/@types/node/worker_threads.d.ts","../../node_modules/@types/node/zlib.d.ts","../../node_modules/@types/node/globals.global.d.ts","../../node_modules/@types/node/index.d.ts","../../node_modules/devtools-protocol/types/protocol.d.ts","../../node_modules/devtools-protocol/types/protocol-mapping.d.ts","../../node_modules/puppeteer/lib/types.d.ts","../../node_modules/@types/expect-puppeteer/index.d.ts","../../node_modules/@types/fs-extra/index.d.ts","../../node_modules/@types/graceful-fs/index.d.ts","../../node_modules/@types/istanbul-lib-coverage/index.d.ts","../../node_modules/@types/istanbul-lib-report/index.d.ts","../../node_modules/@types/istanbul-reports/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/types/build/global.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/types/build/circus.d.ts","../../node_modules/@types/yargs-parser/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@types/yargs/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/types/build/config.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/types/build/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/jest-mock/build/index.d.ts","../../node_modules/source-map/source-map.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/transform/build/types.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/transform/build/scripttransformer.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/transform/build/shouldinstrument.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/transform/build/index.d.ts","../../node_modules/callsites/index.d.ts","../../node_modules/@jest/source-map/build/getcallsite.d.ts","../../node_modules/@jest/source-map/build/types.d.ts","../../node_modules/@jest/source-map/build/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/console/build/types.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/console/build/bufferedconsole.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/console/build/customconsole.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/console/build/nullconsole.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/console/build/getconsoleoutput.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/console/build/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/test-result/build/types.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/test-result/build/formattestresults.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/test-result/build/helpers.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/test-result/build/index.d.ts","../../node_modules/@types/stack-utils/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/jest-message-util/build/types.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/jest-message-util/build/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/fake-timers/build/jestfaketimers.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/fake-timers/build/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/node_modules/@jest/environment/build/index.d.ts","../../node_modules/@types/jest-environment-puppeteer/index.d.ts","../../node_modules/@types/lockfile/index.d.ts","../../node_modules/minipass/index.d.ts","../../node_modules/form-data/index.d.ts","../../node_modules/@types/node-fetch/externals.d.ts","../../node_modules/@types/node-fetch/index.d.ts","../../node_modules/@types/normalize-package-data/index.d.ts","../../node_modules/@types/prettier/index.d.ts","../../node_modules/@types/puppeteer/index.d.ts","../../node_modules/@types/semver/classes/semver.d.ts","../../node_modules/@types/semver/functions/parse.d.ts","../../node_modules/@types/semver/functions/valid.d.ts","../../node_modules/@types/semver/functions/clean.d.ts","../../node_modules/@types/semver/functions/inc.d.ts","../../node_modules/@types/semver/functions/diff.d.ts","../../node_modules/@types/semver/functions/major.d.ts","../../node_modules/@types/semver/functions/minor.d.ts","../../node_modules/@types/semver/functions/patch.d.ts","../../node_modules/@types/semver/functions/prerelease.d.ts","../../node_modules/@types/semver/functions/compare.d.ts","../../node_modules/@types/semver/functions/rcompare.d.ts","../../node_modules/@types/semver/functions/compare-loose.d.ts","../../node_modules/@types/semver/functions/compare-build.d.ts","../../node_modules/@types/semver/functions/sort.d.ts","../../node_modules/@types/semver/functions/rsort.d.ts","../../node_modules/@types/semver/functions/gt.d.ts","../../node_modules/@types/semver/functions/lt.d.ts","../../node_modules/@types/semver/functions/eq.d.ts","../../node_modules/@types/semver/functions/neq.d.ts","../../node_modules/@types/semver/functions/gte.d.ts","../../node_modules/@types/semver/functions/lte.d.ts","../../node_modules/@types/semver/functions/cmp.d.ts","../../node_modules/@types/semver/functions/coerce.d.ts","../../node_modules/@types/semver/classes/comparator.d.ts","../../node_modules/@types/semver/classes/range.d.ts","../../node_modules/@types/semver/functions/satisfies.d.ts","../../node_modules/@types/semver/ranges/max-satisfying.d.ts","../../node_modules/@types/semver/ranges/min-satisfying.d.ts","../../node_modules/@types/semver/ranges/to-comparators.d.ts","../../node_modules/@types/semver/ranges/min-version.d.ts","../../node_modules/@types/semver/ranges/valid.d.ts","../../node_modules/@types/semver/ranges/outside.d.ts","../../node_modules/@types/semver/ranges/gtr.d.ts","../../node_modules/@types/semver/ranges/ltr.d.ts","../../node_modules/@types/semver/ranges/intersects.d.ts","../../node_modules/@types/semver/ranges/simplify.d.ts","../../node_modules/@types/semver/ranges/subset.d.ts","../../node_modules/@types/semver/internals/identifiers.d.ts","../../node_modules/@types/semver/index.d.ts","../../node_modules/@types/strip-bom/index.d.ts","../../node_modules/@types/strip-json-comments/index.d.ts","../../node_modules/@types/tar/index.d.ts","../../node_modules/@types/url-join/index.d.ts","../../node_modules/@types/yargs/index.d.ts","../../node_modules/@types/yauzl/index.d.ts","../../../../../node_modules/@types/slice-ansi/index.d.ts"],"fileInfos":[{"version":"89f78430e422a0f06d13019d60d5a45b37ec2d28e67eb647f73b1b0d19a46b72","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940",{"version":"abba1071bfd89e55e88a054b0c851ea3e8a494c340d0f3fab19eb18f6afb0c9e","affectsGlobalScope":true},{"version":"d8996609230d17e90484a2dd58f22668f9a05a3bfe00bfb1d6271171e54a31fb","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"4378fc8122ec9d1a685b01eb66c46f62aba6b239ca7228bb6483bcf8259ee493","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"d071129cba6a5f2700be09c86c07ad2791ab67d4e5ed1eb301d6746c62745ea4","affectsGlobalScope":true},{"version":"10bbdc1981b8d9310ee75bfac28ee0477bb2353e8529da8cff7cb26c409cb5e8","affectsGlobalScope":true},"be429d42040c571c50e1d517c4fb11b9dee70376abb60a374581457633d9871b","fea55d2f97adfd6ef6cbfb11720a63a7fe219c3474a490a352f5ea3a046ed763","3602e4fac3f6654b2f6a645ba89d7ca9a5b1483faf56d11ce2207c9ecd77463a","993d595705ef81975ae2713c0d10e35e2a8303c7249efff73a49540b7e5f42eb","a8225d3d569c7d246717b2f28cefd271dd494df78ec756b18639ae184a4fbfd2","4b92d1148c924eafd3ec9064fd6f27091dbdc9cf49fd1e22759c19277ce1ae52","9bbc65140cdc4f48ed94b662fa27c29aae125d7cb872651accb8d9d8a749cc46","bbfa6b773cd8b406d19cd08ffb0a217a7251833828b6109aabb0a2bcd9e50a70","d4c83b0d749cd3feafbce371f55bed1560884b940702ecb81d5e87fb22abd86b","d994e43ada2ffbfeab1a20528ae8bc97d7462b26c8310b5fdb1e5ff5c94d55b5","643fed25a8de159610049fd27e29c2782535dc85066e9a41162b25e339ede355","c5a8458bbb10caf3f4170a0c40ebd2b647c96bde97dc91627b5735d571384955","aee4add50896a00aabd8b7a26239e4097a4b812ec973aa92c5d76d0316894519","b9b8a353bface1e14f944fde55faa257fc336cd2f0b35d7f776e50e2036e0d97","d060c7f8393c4387d01a56cdf34af0b3881ea6c5c4bff9a1808087a372e81d8e",{"version":"8d89246a98f6dac77b1f7d41059b5b6df56cfcda85af9df3dc72391b9391970a","signature":"9bc014456edabdc33ae9142921dc0fded6b78ebb382233d73381e76a1411ef18"},"7b51498fda00981bae143271f7e3c8efbf995e4198759b92d67fe17dba5959be","95a183c115ac1763c27addfb6432ffaeae02703c52adb745e033d966a0dc22dc","6bdf7dc4f4fa74b4574b0663406385bc77dc3743b9274c220c69287e5f1fcb3e","8e8f53f5f5064002c103eae1d7c81cc7b92f24037f8bf15557e0cd6e42779495","1e1aa3544d74b09bb07dad39f35a862092e7f8e996f4d440ea92419725590a2e","42b96b0856e723c4e51808703f0fadcae8df0a54f9fa57ab587e1e0b3019f068","35e50e1648f757899d51d246daa77b6d614768905014fea9dad952f812d4b9f4",{"version":"dec0ec0dea02388f7e21980128ecd0d1cb9bf5539f281bc3b4b93b419e8f868b","signature":"91a9a1546ebd6f222ddf8a9c967181cd74c20e826cb58c048ed1087ce7e1b453"},"d81c0c8c8823e71e80b1dbf89264fdbc284991a83a27951ed6a42726eaeab8b7","f239e87bd54e44e8b1c171413f5c53f2a600ffd0192ea194c1310e081f06ae2e",{"version":"99c20bbb72c0a36d2586701fa6f125649f63f1f1310cd8634dabfe8ab195e3d6","signature":"6c15b56179566471b16b817830972c7026e55d46167facdc51137bd9c678ac6d"},"998de96fe0965eb212136e76993229341bd117cd87d7297bee639865dea80b7c",{"version":"27f6e2bc2c3b805618b07c6b3935248aaf7ec98b908bee4980cbfb9217139ab5","signature":"0026e3ecf32dba89ea2d8d0b962c06a15450dca6f7e0b02dfd09e3419dd123db"},{"version":"d1601e801a021191d2c7a181af3c5fda3b88bd640ad225312f584d8653221df6","signature":"05112d1a82b911e17926bd62987c3820393fda2ee03c3207cb7262502de053de"},"10511f49bb513bd610bd4dfd3ba33a3bb92869fcb14f7432eea52475204c3887","d2e845fbae53b2162de45769050b3e87996af38a3be1efa16a1da1905db9a962","c170bd5f737e412bd28a6f73b729c1b27a67c687b8fa34b97bb930b504fe1757","4740ac13adc0e94d0956b4c3aeaa1f08f382507fe77eb9da8aed33b2fa982f9a","e4d4e49ee4d7d43510b9ac08ddee280da54759209e91599ad4065733fd0afbcc","8cfd43364917d74b9f4eb3233af5a552f2eace4eb14cc3bc6cf6b6e1316bee7f",{"version":"4280860f62c4b4b7fe5a397a867b67cc45c0c557d043329cecaaf37de3ea3804","signature":"ff7d47aa6467e19f4dbe9cb0ac3dc65ed350a84c28da1594dd1f71cf9c0b38c4"},{"version":"c0856f833baa7a1a0b19649b9a2278c189f4c64a679727dd50de8a0bc583b6a1","signature":"e9ef719855b9346527ddc007596a4fa05ef6425912c829b9febb3f1eb2252f01"},{"version":"ad11a35006f07701f199a04411a2096135ae31ea85a9f11ac527ea25fbe0373d","signature":"52ec6223c00d040e63231f13c70c2a7850c9dd406b386372f212e30625b85f32"},{"version":"c5f87a13ff5627797654a8c4f92cb0b6f51330bc8444e5d9cdc0a8206dd873a0","signature":"8bc23ee6559268b2aac5511a9e3f72bc23456b632948fa6f32529a127babdc1c"},{"version":"c31c67792ec95666f0c414292fe39bbf4776c0c03e6e4ab769506809a347e468","signature":"f761c91419d0a89422a0004ef1a92929dd4d2d5e5c16758654d8b0467d1998c6"},"23a511dee8019025cfda73723ffda3326d8a8dd7445001f79099e44c65b394bc","9f8813b3962c3b098dcf2e6d806f050168fd088b34493bb05476b50852f342c5","e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","fd43e526cfedef028b313197033b6b5d2c7224e0198b1693d1aaec72cac5f0da","b4954094b1411f4aedfa83a259d260843e7a7fdac41f755bc6bed39edbde113b","e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",{"version":"9183c0fe546b8e4be7153e0dd0374dccaf8ea292c63cc8bbaa21b9f1c102f023","affectsGlobalScope":true},"ab1ebf01e5998c95e28a83abb7e3f41eaf1275946c8770d5922b94c9d35e1792","2ff9995137f3e5d68971388ec58af0c79721626323884513f9f5e2e996ac1fdd","cc957354aa3c94c9961ebf46282cfde1e81d107fc5785a61f62c67f1dd3ac2eb","1a7cc144992d79b062c22ac0309c6624dbb0d49bbddff7ea3b9daa0c17bcac0a","93de1c6dab503f053efe8d304cb522bb3a89feab8c98f307a674a4fae04773e9","3b043cf9a81854a72963fdb57d1884fc4da1cf5be69b5e0a4c5b751e58cb6d88","dd5647a9ccccb2b074dca8a02b00948ac293091ebe73fdf2e6e98f718819f669","6a9c5127096b35264eb7cd21b2417bfc1d42cceca9ba4ce2bb0c3410b7816042","78828b06c0d3b586954015e9ebde5480b009e166c71244763bda328ec0920f41","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","d8aab31ba8e618cc3eea10b0945de81cb93b7e8150a013a482332263b9305322","462bccdf75fcafc1ae8c30400c9425e1a4681db5d605d1a0edb4f990a54d8094","5923d8facbac6ecf7c84739a5c701a57af94a6f6648d6229a6c768cf28f0f8cb","7adecb2c3238794c378d336a8182d4c3dd2c4fa6fa1785e2797a3db550edea62","dc12dc0e5aa06f4e1a7692149b78f89116af823b9e1f1e4eae140cd3e0e674e6","1bfc6565b90c8771615cd8cfcf9b36efc0275e5e83ac7d9181307e96eb495161","8a8a96898906f065f296665e411f51010b51372fa260d5373bf9f64356703190","7f82ef88bdb67d9a850dd1c7cd2d690f33e0f0acd208e3c9eba086f3670d4f73",{"version":"3fe15a491a792852283caeece8142bc7427a29c183d9fec8691d95a49c8932a1","affectsGlobalScope":true},"0cba3a5d7b81356222594442753cf90dd2892e5ccfe1d262aaca6896ba6c1380","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"c2ab70bbc7a24c42a790890739dd8a0ba9d2e15038b40dff8163a97a5d148c00","affectsGlobalScope":true},"422dbb183fdced59425ca072c8bd09efaa77ce4e2ab928ec0d8a1ce062d2a45a",{"version":"712ba0d43b44d144dfd01593f61af6e2e21cfae83e834d297643e7973e55ed61","affectsGlobalScope":true},"1dab5ab6bcf11de47ab9db295df8c4f1d92ffa750e8f095e88c71ce4c3299628","f71f46ccd5a90566f0a37b25b23bc4684381ab2180bdf6733f4e6624474e1894",{"version":"54e65985a3ee3cec182e6a555e20974ea936fc8b8d1738c14e8ed8a42bd921d4","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","98a3ebfa494b46265634a73459050befba5da8fdc6ca0ef9b7269421780f4ff3","34e5de87d983bc6aefef8b17658556e3157003e8d9555d3cb098c6bef0b5fbc8","cc0b61316c4f37393f1f9595e93b673f4184e9d07f4c127165a490ec4a928668","f27371653aded82b2b160f7a7033fb4a5b1534b6f6081ef7be1468f0f15327d3","c762cd6754b13a461c54b59d0ae0ab7aeef3c292c6cf889873f786ee4d8e75c9","f4ea7d5df644785bd9fbf419930cbaec118f0d8b4160037d2339b8e23c059e79",{"version":"bfea28e6162ed21a0aeed181b623dcf250aa79abf49e24a6b7e012655af36d81","affectsGlobalScope":true},"7a5459efa09ea82088234e6533a203d528c594b01787fb90fba148885a36e8b6","ae97e20f2e10dbeec193d6a2f9cd9a367a1e293e7d6b33b68bacea166afd7792","10d4796a130577d57003a77b95d8723530bbec84718e364aa2129fa8ffba0378","ad41bb744149e92adb06eb953da195115620a3f2ad48e7d3ae04d10762dae197","bf73c576885408d4a176f44a9035d798827cc5020d58284cb18d7573430d9022","7ae078ca42a670445ae0c6a97c029cb83d143d62abd1730efb33f68f0b2c0e82",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"5d0a9ea09d990b5788f867f1c79d4878f86f7384cb7dab38eecbf22f9efd063d","12eea70b5e11e924bb0543aea5eadc16ced318aa26001b453b0d561c2fd0bd1e","08777cd9318d294646b121838574e1dd7acbb22c21a03df84e1f2c87b1ad47f2","08a90bcdc717df3d50a2ce178d966a8c353fd23e5c392fd3594a6e39d9bb6304",{"version":"4cd4cff679c9b3d9239fd7bf70293ca4594583767526916af8e5d5a47d0219c7","affectsGlobalScope":true},"2a12d2da5ac4c4979401a3f6eaafa874747a37c365e4bc18aa2b171ae134d21b","002b837927b53f3714308ecd96f72ee8a053b8aeb28213d8ec6de23ed1608b66","1dc9c847473bb47279e398b22c740c83ea37a5c88bf66629666e3cf4c5b9f99c","a9e4a5a24bf2c44de4c98274975a1a705a0abbaad04df3557c2d3cd8b1727949","00fa7ce8bc8acc560dc341bbfdf37840a8c59e6a67c9bfa3fa5f36254df35db2","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","5f0ed51db151c2cdc4fa3bb0f44ce6066912ad001b607a34e65a96c52eb76248",{"version":"3345c276cab0e76dda86c0fb79104ff915a4580ba0f3e440870e183b1baec476","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","e383ff72aabf294913f8c346f5da1445ae6ad525836d28efd52cbadc01a361a6","f52fbf64c7e480271a9096763c4882d356b05cab05bf56a64e68a95313cd2ce2","59bdb65f28d7ce52ccfc906e9aaf422f8b8534b2d21c32a27d7819be5ad81df7",{"version":"3a2da34079a2567161c1359316a32e712404b56566c45332ac9dcee015ecce9f","affectsGlobalScope":true},"28a2e7383fd898c386ffdcacedf0ec0845e5d1a86b5a43f25b86bc315f556b79","3aff9c8c36192e46a84afe7b926136d520487155154ab9ba982a8b544ea8fc95","a880cf8d85af2e4189c709b0fea613741649c0e40fffb4360ec70762563d5de0","85bbf436a15bbeda4db888be3062d47f99c66fd05d7c50f0f6473a9151b6a070","9f9c49c95ecd25e0cb2587751925976cf64fd184714cb11e213749c80cf0f927","f0c75c08a71f9212c93a719a25fb0320d53f2e50ca89a812640e08f8ad8c408c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"9cafe917bf667f1027b2bb62e2de454ecd2119c80873ad76fc41d941089753b8","7417ff3102c2ed96fe1c7bb0fbc03fc63d0314d41e72e130a6a115e3c43fb327","e432dfa7ded4469c8d6104885eb093a6eb5a9720092e855ea411a58a0755201b","7b01601babc431f99e4e1e1b8d8503f751f70eb684c1b7c6a3bbc56a3599a6f9",{"version":"5eb3282fc08f420358916d640ff5773f79e1a9c9443506e95f3d93f0baa68c5e","affectsGlobalScope":true},"ed19da84b7dbf00952ad0b98ce5c194f1903bcf7c94d8103e8e0d63b271543ae","3ebae8c00411116a66fca65b08228ea0cf0b72724701f9b854442100aab55aba","8b06ac3faeacb8484d84ddb44571d8f410697f98d7bfa86c0fda60373a9f5215","7eb06594824ada538b1d8b48c3925a83e7db792f47a081a62cf3e5c4e23cf0ee","029769d13d9917e3284cb2356ed28a6576e8b07ae6a06ee1e672518adf21a102","95fc223e09fa61be43d32fdd520b69c5a0a1395918648dda36d75fcb13bff614","deb2df5ef798d3e3568f4f2f2ec1cc9a9fba076d3c208124722dd32a94065041","f7e133b20ee2669b6c0e5d7f0cd510868c57cd64b283e68c7f598e30ce9d76d2","d9f5e2cb6bce0d05a252e991b33e051f6385299b0dd18d842fc863b59173a18e","70b490c1576775d884ff93ddadafc9f1dcc4c80cbbc30dda939fbf12e877f06d","98544c6cfb1c6875bdeadeccd3b96a142e190c1fae67c4a1f111f61245c8b74a","b08cbbb546908520fce2834fd8543f92c20bf6883b611f064f09be5251158262","2887592574fcdfd087647c539dcb0fbe5af2521270dad4a37f9d17c16190d579","b49c10528613b38382abe256c1302cc3a98f7c625f85da8e29b728390464eff6","9538ba1e050922328f0091c940ddc88549060592865558da834b20e3de79999c","8cabd23efe2e1b75810e39087bc6afc9f38d33c1f83fa9484df3234375d2f37c","4e2d2cce61ea1d60368272f77fd005c399f58393964c07bed0e313bc4d52fc05","6fdc7cbbbc0601f9bb153c30c0e8063321cd1c9211ad512b9fde1d1f785b35dd","4b2a3b4ac5e787056240277d500f391c4992e1ec24c44f2501c0acfb8b17cfea","22df15db12131dafb6357b99ef2c207820f01bbf5ad991743ca4f712f2609cd7","f3f3aab53dfc2373dc974be05b77907c63b5054585038e47266229d6d1b3f889","04aa08bcfcace065e87b37280d0933cb80f50a240d3035c22e69f38e74b45709","aff56013acc0a41280922c0d823293812b57b61b69089936e348e6f7f38f9c87","635439cd724fe9aa039730cb57213085a325894ce7c4ce5a70409bfaa33ff8ee","d0c8e590d18d0ffc8ace6df17613de1b16e8c2d54c2b7665dcddf8cd0772122e","512e28b4cc9e94d3e55a75e459a2f5261c05f012bff24748b1ed91200fd54034","eac4714eb5a7f9292e541eca578f4c5a2dc142fdf6f34b33390a858e9351448c","c447430bdd43e6914a29b14a6cc3dea46c5cd4c86a3456b3a427d9fcce3db0f3","24ea7b5de4eb78228498379986eeaf95b09c06b345dcd0c445841058736e38ec","20253f93ec6bee0e88fc4a67e614cac43eae080820bebc51550639f419e616d8","4ee60d7156712e261163d580277d6de9b5946bf7266865d69d2e6c675b578a49","41422586881bcd739b4e62d9b91cd29909f8572aa3e3cdf316b7c50f14708d49","42b7c6eb9beab0b20c889f3e474890c4386402f37e009b3c75c5bc213f364a7a","ec662431c395527a4e0274110566ffdbbcc3ae2c7f653fe49e31adeb632b4d5d","59509a1029510f22e84b98abcff703700e723b666b6e6cfe5d9f43cdf93f49e2","0c502e88bed6fbb22636a919c2cb38f51780168a5e89d00532dd8cb0c95f8ea4","d20c5037d863db66231a434cc742e6bb9e8d9359dfe819b024d4723ff34a988a",{"version":"c5cc243a8f65e1334f47eefe133986467191ff441bbed86f59a9d5f45034d73f","affectsGlobalScope":true},"23c77af9fdadb3569d425dbc7bbf06a118a4b02bd9db14b7abfafc3183d58bb6","db0f87a03fe40d544ab0d6363919a270e7fa339f450d6d288cde4fc0aaa10fa8","736097ddbb2903bef918bb3b5811ef1c9c5656f2a73bd39b22a91b9cc2525e50","3898e3dbe94b6fe529fbe8f0faee1309c1923100516d7a014b301955e52ece77","3663d1b50f356656a314e5df169bb51cb9d5fd75905fa703f75db6bb32030568","6fa0008bf91a4cc9c8963bace4bba0bd6865cbfa29c3e3ccc461155660fb113a","6209c901f30cc321f4b86800d11fad3d67e73a3308f19946b1bc642af0280298","5b75ced9905bec50e4ba6961c59b9a850152fbbbc4d55d8e2abe1cce1fc01c2d","2b93035328f7778d200252681c1d86285d501ed424825a18f81e4c3028aa51d9","2ac9c8332c5f8510b8bdd571f8271e0f39b0577714d5e95c1e79a12b2616f069","42c21aa963e7b86fa00801d96e88b36803188018d5ad91db2a9101bccd40b3ff","d31eb848cdebb4c55b4893b335a7c0cca95ad66dee13cbb7d0893810c0a9c301","77c1d91a129ba60b8c405f9f539e42df834afb174fe0785f89d92a2c7c16b77a","7a9e0a564fee396cacf706523b5aeed96e04c6b871a8bebefad78499fbffc5bc","906c751ef5822ec0dadcea2f0e9db64a33fb4ee926cc9f7efa38afe5d5371b2a","5387c049e9702f2d2d7ece1a74836a14b47fbebe9bbeb19f94c580a37c855351","c68391fb9efad5d99ff332c65b1606248c4e4a9f1dd9a087204242b56c7126d6","e9cf02252d3a0ced987d24845dcb1f11c1be5541f17e5daa44c6de2d18138d0c","e8b02b879754d85f48489294f99147aeccc352c760d95a6fe2b6e49cd400b2fe","9f6908ab3d8a86c68b86e38578afc7095114e66b2fc36a2a96e9252aac3998e0","0eedb2344442b143ddcd788f87096961cd8572b64f10b4afc3356aa0460171c6","71405cc70f183d029cc5018375f6c35117ffdaf11846c35ebf85ee3956b1b2a6","c68baff4d8ba346130e9753cefe2e487a16731bf17e05fdacc81e8c9a26aae9d","2cd15528d8bb5d0453aa339b4b52e0696e8b07e790c153831c642c3dea5ac8af","479d622e66283ffa9883fbc33e441f7fc928b2277ff30aacbec7b7761b4e9579","ade307876dc5ca267ca308d09e737b611505e015c535863f22420a11fffc1c54","f8cdefa3e0dee639eccbe9794b46f90291e5fd3989fcba60d2f08fde56179fb9","86c5a62f99aac7053976e317dbe9acb2eaf903aaf3d2e5bb1cafe5c2df7b37a8","2b300954ce01a8343866f737656e13243e86e5baef51bd0631b21dcef1f6e954","a2d409a9ffd872d6b9d78ead00baa116bbc73cfa959fce9a2f29d3227876b2a1","b288936f560cd71f4a6002953290de9ff8dfbfbf37f5a9391be5c83322324898","61178a781ef82e0ff54f9430397e71e8f365fc1e3725e0e5346f2de7b0d50dfa","6a6ccb37feb3aad32d9be026a3337db195979cd5727a616fc0f557e974101a54","c649ea79205c029a02272ef55b7ab14ada0903db26144d2205021f24727ac7a3","38e2b02897c6357bbcff729ef84c736727b45cc152abe95a7567caccdfad2a1d","d6610ea7e0b1a7686dba062a1e5544dd7d34140f4545305b7c6afaebfb348341","3dee35db743bdba2c8d19aece7ac049bde6fa587e195d86547c882784e6ba34c","b15e55c5fa977c2f25ca0b1db52cfa2d1fd4bf0baf90a8b90d4a7678ca462ff1","f41d30972724714763a2698ae949fbc463afb203b5fa7c4ad7e4de0871129a17","843dd7b6a7c6269fd43827303f5cbe65c1fecabc30b4670a50d5a15d57daeeb9","f06d8b8567ee9fd799bf7f806efe93b67683ef24f4dea5b23ef12edff4434d9d","6017384f697ff38bc3ef6a546df5b230c3c31329db84cbfe686c83bec011e2b2","e1a5b30d9248549ca0c0bb1d653bafae20c64c4aa5928cc4cd3017b55c2177b0","a593632d5878f17295bd53e1c77f27bf4c15212822f764a2bfc1702f4b413fa0","a868a534ba1c2ca9060b8a13b0ffbbbf78b4be7b0ff80d8c75b02773f7192c29","da7545aba8f54a50fde23e2ede00158dc8112560d934cee58098dfb03aae9b9d","34baf65cfee92f110d6653322e2120c2d368ee64b3c7981dff08ed105c4f19b0","6aee496bf0ecfbf6731aa8cca32f4b6e92cdc0a444911a7d88410408a45ecc5d","4006c872e38a2c4e09c593bc0cdd32b7b4f5c4843910bea0def631c483fff6c5","ab6aa3a65d473871ee093e3b7b71ed0f9c69e07d1d4295f45c9efd91a771241d","239f0c1d83d1ca9677327198196ee2ce6827dc7b469771ab5abf7bea7fbdb674","d9c5f8d21771758700d7b6eeef796700b99c643a5818195cf0d01bed98407df1","6ba73232c9d3267ca36ddb83e335d474d2c0e167481e3dec416c782894e11438","b2d70a269840a9528db473ac7565442434333a05c1f66801a7a672e82beb903e","857f9cda624606f2bfb1cb758d47499edfbee66b2cf46804f54620bd430ea26f"],"options":{"allowSyntheticDefaultImports":true,"allowUmdGlobalAccess":true,"composite":false,"declaration":true,"declarationDir":"./","emitDecoratorMetadata":true,"esModuleInterop":true,"experimentalDecorators":true,"module":6,"outDir":"./","skipLibCheck":true,"strict":false,"strictNullChecks":false,"strictPropertyInitialization":false,"suppressImplicitAnyIndexErrors":true,"target":4},"fileIdsList":[[91,152],[152],[152,181],[152,182,183],[91,92,93,94,95,152],[91,93,152],[97,152],[108,152,162],[125,152,159],[152,166],[152,166,167],[152,154,162,174,175,199,200],[116,152,184,185],[116,152,159,185],[152,185],[152,185,186,187,188,189],[152,187],[108,152,154,159,174,175,180,199],[152,198],[152,159,175,197],[152,191],[152,191,192,193],[152,166,174,190],[152,177,178,179],[152,174,177],[152,154,159,174,176],[152,159,169],[152,159,168,172],[152,159,166],[152,169,170,173],[152,171],[152,174,194,196],[152,195],[152,159],[102,107,152],[127,151,152,159,204,205],[109,152],[112,152],[113,118,152],[114,124,125,132,141,151,152],[114,115,124,132,152],[116,152],[117,118,125,133,152],[118,141,148,152],[119,121,124,132,152],[120,152],[121,122,152],[123,124,152],[124,152],[124,125,126,141,151,152],[124,125,126,141,152],[127,132,141,151,152],[124,125,127,128,132,141,148,151,152],[127,129,141,148,151,152],[109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158],[124,130,152],[131,151,152],[121,124,132,141,152],[133,152],[134,152],[112,135,152],[136,150,152,156],[137,152],[138,152],[124,139,152],[139,140,152,154],[124,141,142,143,152],[141,143,152],[141,142,152],[144,152],[145,152],[124,146,147,152],[146,147,152],[118,132,141,148,152],[149,152],[132,150,152],[113,127,138,151,152],[118,152],[141,152,153],[152,154],[152,155],[113,118,124,126,135,141,151,152,154,156],[141,152,157],[114,152,159],[152,210,249],[152,210,234,249],[152,249],[152,210],[152,210,235,249],[152,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248],[152,235,249],[124,141,152,157,159,203],[124,141,152,159],[152,160],[127,141,152,159],[100,103,152],[100,103,104,105,152],[102,152],[99,106,152],[101,152],[114,141,152,159,160,161],[56,63,64,65,152],[48,152],[48,59,60,152],[48,61,152],[41,48,55,57,61,62,152],[48,57,58,152],[56,152],[48,63,64,152],[46,69,74,77,78,152],[42,43,45,47,152],[47,152],[46,152],[44,45,152],[43,44,152],[40,41,48,66,67,152],[78,152],[47,79,152],[40,41,42,44,48,56,68,70,74,75,77,152],[42,45,47,152],[40,42,44,48,67,68,69,70,73,78,152],[48,72,152],[48,71,78,152],[48,78,152],[76,78,152],[40,70,78,152],[51,52,152],[53,152],[47,48,49,50,152],[47,48,51,152],[49,152],[40,152],[41,48,51,54,152],[40,56,68,78,152],[40,68,78,152],[64],[41,48,61],[45,69,74,76,78],[41,48],[47],[78],[76,78],[41,48,51,54]],"referencedMap":[[93,1],[91,2],[182,3],[184,4],[183,2],[96,5],[92,1],[94,6],[95,1],[98,7],[163,8],[164,9],[165,9],[166,2],[167,10],[168,11],[201,12],[186,13],[187,14],[189,15],[190,16],[188,17],[185,2],[200,18],[199,19],[198,20],[192,21],[193,21],[194,22],[191,23],[180,24],[178,25],[179,25],[177,26],[170,27],[173,28],[169,29],[174,30],[172,31],[197,32],[196,33],[175,34],[108,35],[202,2],[97,2],[205,2],[206,36],[109,37],[110,37],[112,38],[113,39],[114,40],[115,41],[116,42],[117,43],[118,44],[119,45],[120,46],[121,47],[122,47],[123,48],[124,49],[125,50],[126,51],[111,2],[158,2],[127,52],[128,53],[129,54],[159,55],[130,56],[131,57],[132,58],[133,59],[134,60],[135,61],[136,62],[137,63],[138,64],[139,65],[140,66],[141,67],[143,68],[142,69],[144,70],[145,71],[146,72],[147,73],[148,74],[149,75],[150,76],[151,77],[152,78],[153,79],[154,80],[155,81],[156,82],[157,83],[207,2],[208,2],[209,84],[234,85],[235,86],[210,87],[213,87],[232,85],[233,85],[223,85],[222,88],[220,85],[215,85],[228,85],[226,85],[230,85],[214,85],[227,85],[231,85],[216,85],[217,85],[229,85],[211,85],[218,85],[219,85],[221,85],[225,85],[236,89],[224,85],[212,85],[249,90],[248,2],[243,89],[245,91],[244,89],[237,89],[238,89],[240,89],[242,89],[246,91],[247,91],[239,91],[241,91],[195,2],[250,2],[251,2],[252,92],[253,2],[171,2],[254,31],[255,93],[181,2],[99,2],[161,94],[160,2],[204,95],[100,2],[104,96],[106,97],[105,96],[103,98],[107,99],[203,93],[102,100],[101,2],[162,101],[176,2],[8,2],[10,2],[9,2],[2,2],[11,2],[12,2],[13,2],[14,2],[15,2],[16,2],[17,2],[18,2],[3,2],[4,2],[22,2],[19,2],[20,2],[21,2],[23,2],[24,2],[25,2],[5,2],[26,2],[27,2],[28,2],[29,2],[6,2],[30,2],[31,2],[32,2],[33,2],[7,2],[38,2],[34,2],[35,2],[36,2],[37,2],[1,2],[39,2],[66,102],[60,103],[81,2],[61,104],[62,105],[63,106],[59,107],[57,108],[58,2],[82,2],[64,2],[83,2],[84,2],[56,2],[80,109],[65,108],[79,110],[44,111],[43,112],[47,113],[46,114],[45,115],[67,2],[85,2],[68,116],[41,117],[69,118],[78,119],[48,120],[74,121],[73,122],[72,123],[71,124],[76,117],[77,125],[86,117],[75,126],[53,127],[54,128],[51,129],[87,2],[52,130],[50,131],[49,132],[88,2],[42,2],[89,2],[55,133],[70,134],[90,135],[40,2],[256,2]],"exportedModulesMap":[[93,1],[91,2],[182,3],[184,4],[183,2],[96,5],[92,1],[94,6],[95,1],[98,7],[163,8],[164,9],[165,9],[166,2],[167,10],[168,11],[201,12],[186,13],[187,14],[189,15],[190,16],[188,17],[185,2],[200,18],[199,19],[198,20],[192,21],[193,21],[194,22],[191,23],[180,24],[178,25],[179,25],[177,26],[170,27],[173,28],[169,29],[174,30],[172,31],[197,32],[196,33],[175,34],[108,35],[202,2],[97,2],[205,2],[206,36],[109,37],[110,37],[112,38],[113,39],[114,40],[115,41],[116,42],[117,43],[118,44],[119,45],[120,46],[121,47],[122,47],[123,48],[124,49],[125,50],[126,51],[111,2],[158,2],[127,52],[128,53],[129,54],[159,55],[130,56],[131,57],[132,58],[133,59],[134,60],[135,61],[136,62],[137,63],[138,64],[139,65],[140,66],[141,67],[143,68],[142,69],[144,70],[145,71],[146,72],[147,73],[148,74],[149,75],[150,76],[151,77],[152,78],[153,79],[154,80],[155,81],[156,82],[157,83],[207,2],[208,2],[209,84],[234,85],[235,86],[210,87],[213,87],[232,85],[233,85],[223,85],[222,88],[220,85],[215,85],[228,85],[226,85],[230,85],[214,85],[227,85],[231,85],[216,85],[217,85],[229,85],[211,85],[218,85],[219,85],[221,85],[225,85],[236,89],[224,85],[212,85],[249,90],[248,2],[243,89],[245,91],[244,89],[237,89],[238,89],[240,89],[242,89],[246,91],[247,91],[239,91],[241,91],[195,2],[250,2],[251,2],[252,92],[253,2],[171,2],[254,31],[255,93],[181,2],[99,2],[161,94],[160,2],[204,95],[100,2],[104,96],[106,97],[105,96],[103,98],[107,99],[203,93],[102,100],[101,2],[162,101],[176,2],[8,2],[10,2],[9,2],[2,2],[11,2],[12,2],[13,2],[14,2],[15,2],[16,2],[17,2],[18,2],[3,2],[4,2],[22,2],[19,2],[20,2],[21,2],[23,2],[24,2],[25,2],[5,2],[26,2],[27,2],[28,2],[29,2],[6,2],[30,2],[31,2],[32,2],[33,2],[7,2],[38,2],[34,2],[35,2],[36,2],[37,2],[1,2],[39,2],[66,136],[60,103],[81,2],[61,104],[62,105],[63,137],[59,107],[57,108],[58,2],[82,2],[64,2],[83,2],[84,2],[56,2],[65,108],[79,138],[44,111],[43,112],[47,113],[46,114],[45,115],[67,2],[85,2],[68,139],[41,117],[69,140],[78,139],[48,120],[74,121],[73,122],[72,123],[71,124],[76,141],[77,142],[86,117],[75,126],[53,127],[54,128],[51,129],[87,2],[52,130],[50,131],[49,132],[88,2],[42,2],[89,2],[55,143],[70,134],[90,135],[40,2],[256,2]],"semanticDiagnosticsPerFile":[93,91,182,184,183,96,92,94,95,98,163,164,165,166,167,168,201,186,187,189,190,188,185,200,199,198,192,193,194,191,180,178,179,177,170,173,169,174,172,197,196,175,108,202,97,205,206,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,111,158,127,128,129,159,130,131,132,133,134,135,136,137,138,139,140,141,143,142,144,145,146,147,148,149,150,151,152,153,154,155,156,157,207,208,209,234,235,210,213,232,233,223,222,220,215,228,226,230,214,227,231,216,217,229,211,218,219,221,225,236,224,212,249,248,243,245,244,237,238,240,242,246,247,239,241,195,250,251,252,253,171,254,255,181,99,161,160,204,100,104,106,105,103,107,203,102,101,162,176,8,10,9,2,11,12,13,14,15,16,17,18,3,4,22,19,20,21,23,24,25,5,26,27,28,29,6,30,31,32,33,7,38,34,35,36,37,1,39,66,60,81,61,62,63,59,57,58,82,64,83,84,56,80,65,79,44,43,47,46,45,67,85,68,41,69,78,48,74,73,72,71,76,77,86,75,53,54,51,87,52,50,49,88,42,89,55,70,90,40,256]},"version":"4.5.5"} \ No newline at end of file diff --git a/src/plugin/src/utils.d.ts b/src/plugin/src/utils.d.ts new file mode 100644 index 000000000..1d1f7e7a7 --- /dev/null +++ b/src/plugin/src/utils.d.ts @@ -0,0 +1,7 @@ +export declare function uniqueGenerator(): string; +export declare function hashCode(str: string): number; +export declare function getDeep(obj: any, path: any): any; +/** First Character uppercase */ +export declare function capitalize(str: any): any; +/** First Character lowercase */ +export declare function uncapitalize(str: any): any; diff --git a/src/plugin/src/utils.js b/src/plugin/src/utils.js new file mode 100644 index 000000000..b5770f4cc --- /dev/null +++ b/src/plugin/src/utils.js @@ -0,0 +1,34 @@ +// generate unique string +export function uniqueGenerator() { + return (Math.random() + 'uuid' + new Date().getTime()).slice(2); +} +export function hashCode(str) { + var hash = 0; + for (var i = 0; i < str.length; i++) { + var char = str.charCodeAt(i); + hash = ((hash << 5) - hash) + char; + hash = hash & hash; + } + return hash; +} +export function getDeep(obj, path) { + try { + for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) { + obj = obj[path[i]]; + } + ; + return obj; + } + catch (error) { + return undefined; + } +} +; +/** First Character uppercase */ +export function capitalize(str) { + return str.charAt(0).toUpperCase() + str.slice(1); +} +/** First Character lowercase */ +export function uncapitalize(str) { + return str.charAt(0).toLowerCase() + str.slice(1); +} diff --git a/version/git-version.ts b/version/git-version.ts index 66e618d9c..9b5a35bdf 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "9676bab7e", - "SHA": "9676bab7eb0427cf26a4970ce8bd7d96deaf504b", + "shortSHA": "c69ea92c9", + "SHA": "c69ea92c910b1cd241296cf4d8633e0d2dcf9537", "branch": "feature/gabinete-search", - "lastCommitAuthor": "'Peter Maquiran'", - "lastCommitTime": "'Thu Jul 6 13:35:11 2023 +0100'", - "lastCommitMessage": "main data of refresh", - "lastCommitNumber": "5040", + "lastCommitAuthor": "'Eudes Inácio'", + "lastCommitTime": "'Mon Jul 10 12:38:41 2023 +0100'", + "lastCommitMessage": "improve edition of draft", + "lastCommitNumber": "5041", "change": "", - "changeStatus": "On branch feature/gabinete-search\nYour branch is up to date with 'origin/feature/gabinete-search'.\n\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/modals/view-document/view-document.page.ts\n\tmodified: src/app/pages/gabinete-digital/despachos/despacho/despacho.page.ts\n\tmodified: src/app/pages/login/login.page.ts\n\tmodified: src/app/services/auth.service.ts\n\tmodified: src/app/services/http-error-handle.service.ts\n\tmodified: src/app/services/processes.service.ts\n\tmodified: src/app/shared/popover/event-details-documents-options/event-details-documents-options.page.html\n\tmodified: src/app/shared/popover/event-details-documents-options/event-details-documents-options.page.ts\n\tmodified: src/app/tiny-mce/tiny-mce.page.html\n\tmodified: src/app/tiny-mce/tiny-mce.page.ts", + "changeStatus": "On branch feature/gabinete-search\nYour branch and 'origin/feature/gabinete-search' have diverged,\nand have 1 and 3 different commits each, respectively.\n (use \"git pull\" to merge the remote branch into yours)\n\nAll conflicts fixed but you are still merging.\n (use \"git commit\" to conclude merge)\n\nChanges to be committed:\n\tmodified: .gitignore\n\tnew file: src/app/models/beast-orm-function.ts\n\tmodified: src/app/models/beast-orm.ts\n\tmodified: src/app/models/envarioment.ts\n\tmodified: src/app/pages/login/login.page.ts\n\tmodified: src/app/services/auth.service.ts\n\tmodified: src/app/services/chat/room.service.ts\n\tmodified: src/app/services/processes.service.ts\n\tmodified: src/app/store/documentManagement.ts\n\tmodified: src/environments/suport/dev.ts\n\tmodified: src/environments/suport/doneIt.ts\n\tmodified: src/environments/suport/oapr.ts\n\tnew file: src/plugin/src/connection/dbSwtich.d.ts\n\tnew file: src/plugin/src/connection/dbSwtich.js\n\tnew file: src/plugin/src/connection/indexedDb/DatabaseManager.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/DatabaseManager.js\n\tnew file: src/plugin/src/connection/indexedDb/connect.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/connect.js\n\tnew file: src/plugin/src/connection/indexedDb/database.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/database.js\n\tnew file: src/plugin/src/connection/indexedDb/indexedb.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/indexedb.js\n\tnew file: src/plugin/src/connection/indexedDb/objectStore.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/objectStore.js\n\tnew file: src/plugin/src/connection/indexedDb/postMessage.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/postMessage.js\n\tnew file: src/plugin/src/connection/indexedDb/transaction.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/transaction.js\n\tnew file: src/plugin/src/connection/indexedDb/triggers/triggers.d.ts\n\tnew file: src/plugin/src/connection/indexedDb/triggers/triggers.js\n\tnew file: src/plugin/src/connection/intreface.d.ts\n\tnew file: src/plugin/src/connection/intreface.js\n\tnew file: src/plugin/src/connection/localStorage/localStorage.d.ts\n\tnew file: src/plugin/src/connection/localStorage/localStorage.js\n\tnew file: src/plugin/src/connection/memory/db.d.ts\n\tnew file: src/plugin/src/connection/memory/db.js\n\tnew file: src/plugin/src/connection/taskHolder.d.ts\n\tnew file: src/plugin/src/connection/taskHolder.js\n\tnew file: src/plugin/src/connection/worker.d.ts\n\tnew file: src/plugin/src/connection/worker.js\n\tnew file: src/plugin/src/connection/workerManager.d.ts\n\tnew file: src/plugin/src/connection/workerManager.js\n\tnew file: src/plugin/src/index.d.ts\n\tnew file: src/plugin/src/index.js\n\tnew file: src/plugin/src/models/field/allFields.d.ts\n\tnew file: src/plugin/src/models/field/allFields.js\n\tnew file: src/plugin/src/models/field/field.d.ts\n\tnew file: src/plugin/src/models/field/field.js\n\tnew file: src/plugin/src/models/field/fields.d.ts\n\tnew file: src/plugin/src/models/field/fields.interface.d.ts\n\tnew file: src/plugin/src/models/field/fields.interface.js\n\tnew file: src/plugin/src/models/field/fields.js\n\tnew file: src/plugin/src/models/field/interface.d.ts\n\tnew file: src/plugin/src/models/field/interface.js\n\tnew file: src/plugin/src/models/mode-migrations.d.ts\n\tnew file: src/plugin/src/models/mode-migrations.js\n\tnew file: src/plugin/src/models/model-from.d.ts\n\tnew file: src/plugin/src/models/model-from.js\n\tnew file: src/plugin/src/models/model-manager.d.ts\n\tnew file: src/plugin/src/models/model-manager.js\n\tnew file: src/plugin/src/models/model.d.ts\n\tnew file: src/plugin/src/models/model.interface.d.ts\n\tnew file: src/plugin/src/models/model.interface.js\n\tnew file: src/plugin/src/models/model.js\n\tnew file: src/plugin/src/models/model.reader.d.ts\n\tnew file: src/plugin/src/models/model.reader.js\n\tnew file: src/plugin/src/models/register-modal.interface.d.ts\n\tnew file: src/plugin/src/models/register-modal.interface.js\n\tnew file: src/plugin/src/models/register-model.d.ts\n\tnew file: src/plugin/src/models/register-model.js\n\tnew file: src/plugin/src/models/schema/databae-manager-schema.d.ts\n\tnew file: src/plugin/src/models/schema/databae-manager-schema.js\n\tnew file: src/plugin/src/models/schema/database-schema.d.ts\n\tnew file: src/plugin/src/models/schema/database-schema.js\n\tnew file: src/plugin/src/models/schema/table-schema.d.ts\n\tnew file: src/plugin/src/models/schema/table-schema.js\n\tnew file: src/plugin/src/models/signal.d.ts\n\tnew file: src/plugin/src/models/signal.interface.d.ts\n\tnew file: src/plugin/src/models/signal.interface.js\n\tnew file: src/plugin/src/models/signal.js\n\tnew file: src/plugin/src/models/split.d.ts\n\tnew file: src/plugin/src/models/split.js\n\tnew file: src/plugin/src/reactive/DynamicList.d.ts\n\tnew file: src/plugin/src/reactive/DynamicList.js\n\tnew file: src/plugin/src/sql/Operators/Object-condition-operator.d.ts\n\tnew file: src/plugin/src/sql/Operators/Object-condition-operator.js\n\tnew file: src/plugin/src/sql/Operators/args-attributes.d.ts\n\tnew file: src/plugin/src/sql/Operators/args-attributes.js\n\tnew file: src/plugin/src/sql/Operators/object-operator.d.ts\n\tnew file: src/plugin/src/sql/Operators/object-operator.js\n\tnew file: src/plugin/src/sql/Operators/operators.d.ts\n\tnew file: src/plugin/src/sql/Operators/operators.js\n\tnew file: src/plugin/src/sql/Operators/query-bulder.d.ts\n\tnew file: src/plugin/src/sql/Operators/query-bulder.js\n\tnew file: src/plugin/src/sql/methods/filter.d.ts\n\tnew file: src/plugin/src/sql/methods/filter.js\n\tnew file: src/plugin/src/sql/methods/methods.d.ts\n\tnew file: src/plugin/src/sql/methods/methods.js\n\tnew file: src/plugin/src/sql/query/interface.d.ts\n\tnew file: src/plugin/src/sql/query/interface.js\n\tnew file: src/plugin/src/sql/sqlObject/sql.d.ts\n\tnew file: src/plugin/src/sql/sqlObject/sql.js\n\tnew file: src/plugin/src/sql/sqlObject/sqlObject.d.ts\n\tnew file: src/plugin/src/sql/sqlObject/sqlObject.js\n\tnew file: src/plugin/src/triggers/transaction.d.ts\n\tnew file: src/plugin/src/triggers/transaction.js\n\tnew file: src/plugin/src/triggers/triggers.d.ts\n\tnew file: src/plugin/src/triggers/triggers.js\n\tnew file: src/plugin/src/tsconfig.tsbuildinfo\n\tnew file: src/plugin/src/utils.d.ts\n\tnew file: src/plugin/src/utils.js", "changeAuthor": "eudes.inacio" } \ No newline at end of file