mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
1 line
58 KiB
JSON
1 line
58 KiB
JSON
|
|
{"ast":null,"code":"import _asyncToGenerator from \"C:/Users/eudes.inacio/GabineteDigital/gabinete-digital-fo/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nvar _a;\nimport { hashCode, uniqueGenerator } from '../utils.js';\nimport { ModelAPIRequest } from './model-manager.js';\nimport { models, modelsConfig, modelsConfigLocalStorage } from './register-model.js';\nimport { FieldType } from '../sql/query/interface.js';\nimport * as Fields from './field/allFields.js';\nimport { taskHolder } from '../connection/taskHolder.js';\nimport { transactionOnCommit } from '../triggers/transaction.js';\nimport { ReactiveList } from '../reactive/DynamicList.js';\nlet methods = ({} = {});\n// inspire by https://github.com/brianschardt/browser-orm\nexport class Model {\n constructor(obg) {\n Object.assign(this, obg);\n }\n get(arg) {\n return Model.get(arg);\n }\n getDBSchema() {\n const modelName = this.constructor.name;\n return modelsConfig[modelName].DatabaseSchema;\n }\n getModelName() {\n return this.constructor.name;\n }\n filter(...arg) {\n return Model.filter(arg);\n }\n getTableSchema() {\n const modelName = this.constructor.name;\n return modelsConfig[modelName].TableSchema;\n }\n getPrimaryKeyValue() {\n const TableSchema = this.getTableSchema();\n const idFieldName = TableSchema.id.keyPath;\n return this[idFieldName];\n }\n save() {\n var _this = this;\n return _asyncToGenerator(function* () {\n const DBconfig = _this.getDBSchema();\n const tableSchema = _this.getTableSchema();\n const fiendsName = tableSchema.fields.map(field => field.name);\n fiendsName.push(tableSchema.id.keyPath);\n const Fields = {};\n for (let name of fiendsName) {\n Fields[name] = _this[name];\n }\n const methods = [{\n methodName: 'save',\n arguments: Fields\n }];\n const queryId = uniqueGenerator();\n yield ModelAPIRequest.obj(DBconfig, tableSchema).save(methods, queryId);\n taskHolder.finish(queryId);\n })();\n }\n delete() {\n var _this2 = this;\n return _asyncToGenerator(function* () {\n const DBconfig = _this2.getDBSchema();\n const TableSchema = _this2.getTableSchema();\n const idFieldName = TableSchema.id.keyPath;\n const createArg = {};\n createArg[idFieldName] = _this2[idFieldName];\n const _methods = [{\n methodName: 'delete',\n arguments: createArg\n }];\n const queryId = uniqueGenerator();\n yield ModelAPIRequest.obj(DBconfig, TableSchema).delete(_methods, queryId);\n taskHolder.finish(queryId);\n })();\n }\n static deleteAll() {\n var _this3 = this;\n return _asyncToGenerator(function* () {\n const DBconfig = _this3.getDBSchema();\n const TableSchema = _this3.getTableSchema();\n const idFieldName = TableSchema.id.keyPath;\n const createArg = {};\n createArg[idFieldName] = _this3[idFieldName];\n const _methods = [{\n methodName: 'delete',\n arguments: '*'\n }];\n const queryId = uniqueGenerator();\n yield ModelAPIRequest.obj(DBconfig, TableSchema).delete(_methods, queryId);\n taskHolder.finish(queryId);\n })();\n }\n all() {\n var _this4 = this;\n return _asyncToGenerator(function* () {\n const DBconfig = _this4.getDBSchema();\n const TableSchema = _this4.getTableSchema();\n const queryId = uniqueGenerator();\n const result = yield Model.object({\n queryId,\n DBconfig,\n TableSchema\n }).all();\n taskHolder.finish(queryId);\n return result;\n })();\n }\n getFields(arg) {\n return Model.getFields(arg);\n }\n formValidation(data) {\n return Model.formValidation(data);\n }\n Value(args) {\n return Model.Value(args);\n }\n static Value(args) {\n return '';\n }\n static formValidation(data) {\n const TableSchema = this.getTableSchema();\n for (let field of TableSchema.fields) {\n const Field = new Fields[field.className](field.fieldAttributes);\
|