@rolster/vinegar 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +16 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +16 -20
- package/dist/es/index.js.map +1 -1
- package/dist/esm/entity-manager.d.ts +11 -11
- package/dist/esm/entity-manager.js +12 -16
- package/dist/esm/entity-manager.js.map +1 -1
- package/dist/esm/entity.d.ts +4 -4
- package/dist/esm/entity.js +4 -4
- package/dist/esm/entity.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -75,8 +75,8 @@ function itIsModelHidden(model) {
|
|
|
75
75
|
class AbstractEntityManager {
|
|
76
76
|
}
|
|
77
77
|
class EntityManager {
|
|
78
|
-
constructor(
|
|
79
|
-
this.
|
|
78
|
+
constructor(dataSource) {
|
|
79
|
+
this.dataSource = dataSource;
|
|
80
80
|
this.links = [];
|
|
81
81
|
this.refreshs = [];
|
|
82
82
|
this.syncs = [];
|
|
@@ -89,11 +89,11 @@ class EntityManager {
|
|
|
89
89
|
this.links.push(options);
|
|
90
90
|
}
|
|
91
91
|
refresh(options) {
|
|
92
|
-
options.
|
|
92
|
+
options.relationable && this.relation(options.entity, options.model);
|
|
93
93
|
this.refreshs.push(options);
|
|
94
94
|
}
|
|
95
95
|
sync(options) {
|
|
96
|
-
options.
|
|
96
|
+
options.relationable && this.relation(options.entity, options.model);
|
|
97
97
|
this.syncs.push(options);
|
|
98
98
|
}
|
|
99
99
|
destroy(entity) {
|
|
@@ -135,17 +135,13 @@ class EntityManager {
|
|
|
135
135
|
this.procedures = [];
|
|
136
136
|
}
|
|
137
137
|
persistAll() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (bindable) {
|
|
142
|
-
this.relation(entity, model);
|
|
143
|
-
}
|
|
144
|
-
return source.insert(model);
|
|
138
|
+
return Promise.all(this.links.map((link) => fromPromise(link.create(this)).then((model) => {
|
|
139
|
+
link.bindable && this.relation(link.entity, model);
|
|
140
|
+
return this.dataSource.insert(model);
|
|
145
141
|
})));
|
|
146
142
|
}
|
|
147
143
|
refreshAll() {
|
|
148
|
-
return Promise.all(this.refreshs.map(({ model }) => this.
|
|
144
|
+
return Promise.all(this.refreshs.map(({ model }) => this.dataSource.refresh(model)));
|
|
149
145
|
}
|
|
150
146
|
syncAll() {
|
|
151
147
|
return Promise.all(this.syncs
|
|
@@ -156,17 +152,17 @@ class EntityManager {
|
|
|
156
152
|
return syncs;
|
|
157
153
|
}, [])
|
|
158
154
|
.map(([model, dirty]) => {
|
|
159
|
-
return this.
|
|
155
|
+
return this.dataSource.refresh(model, dirty);
|
|
160
156
|
}));
|
|
161
157
|
}
|
|
162
158
|
destroyAll() {
|
|
163
|
-
return Promise.all(this.destroys.map((destroy) => this.
|
|
159
|
+
return Promise.all(this.destroys.map((destroy) => this.dataSource.delete(destroy)));
|
|
164
160
|
}
|
|
165
161
|
hiddenAll() {
|
|
166
|
-
return Promise.all(this.hiddens.map((hidden) => this.
|
|
162
|
+
return Promise.all(this.hiddens.map((hidden) => this.dataSource.hidden(hidden)));
|
|
167
163
|
}
|
|
168
164
|
procedureAll() {
|
|
169
|
-
return Promise.all(this.procedures.map((procedure) => this.
|
|
165
|
+
return Promise.all(this.procedures.map((procedure) => this.dataSource.procedure(procedure)));
|
|
170
166
|
}
|
|
171
167
|
}
|
|
172
168
|
|
|
@@ -179,10 +175,10 @@ class Entity {
|
|
|
179
175
|
}
|
|
180
176
|
}
|
|
181
177
|
class EntityRefresh {
|
|
182
|
-
constructor(entity, model,
|
|
178
|
+
constructor(entity, model, relationable = true) {
|
|
183
179
|
this.entity = entity;
|
|
184
180
|
this.model = model;
|
|
185
|
-
this.
|
|
181
|
+
this.relationable = relationable;
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
class EntityLink {
|
|
@@ -192,10 +188,10 @@ class EntityLink {
|
|
|
192
188
|
}
|
|
193
189
|
}
|
|
194
190
|
class EntitySync {
|
|
195
|
-
constructor(entity, model,
|
|
191
|
+
constructor(entity, model, relationable = true) {
|
|
196
192
|
this.entity = entity;
|
|
197
193
|
this.model = model;
|
|
198
|
-
this.
|
|
194
|
+
this.relationable = relationable;
|
|
199
195
|
this.firstDirty = this.createDirtyFromModel(model);
|
|
200
196
|
}
|
|
201
197
|
verify() {
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../../node_modules/@rolster/commons/dist/esm/helpers.js","../../node_modules/@rolster/commons/dist/esm/optional.js","../../node_modules/@rolster/commons/dist/esm/promises.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\nconst SLICE_SIZE = 512;\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\nconst prototypeToString = Object.prototype.toString;\nfunction clone(object, caches) {\n if (typeof object !== 'object') {\n return object;\n }\n if (prototypeToString.call(object) === '[object Object]') {\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\n /* istanbul ignore if */\n if (cacheObject) {\n return cacheObject;\n }\n caches.push(object);\n }\n const prototypeObject = Object.getPrototypeOf(object);\n const ConstructorObject = prototypeObject.constructor;\n if (PRIMITIVES.includes(ConstructorObject)) {\n return new ConstructorObject(object);\n }\n const cloneObject = new ConstructorObject();\n for (const prop in object) {\n cloneObject[prop] = clone(object[prop], caches);\n }\n return cloneObject;\n}\nexport function itIsDefined(object) {\n return typeof object !== 'undefined' && object !== null;\n}\nexport function itIsUndefined(object) {\n return !itIsDefined(object);\n}\nexport function parseBoolean(value) {\n return !(itIsUndefined(value) ||\n value === false ||\n FALSY_VALUE.includes(value));\n}\nexport function parse(value) {\n try {\n return JSON.parse(value);\n }\n catch {\n return value;\n }\n}\nexport function evalValueOrFunction(value) {\n return typeof value === 'function' ? value() : value;\n}\nexport function deepClone(object) {\n return clone(object, []);\n}\nexport function deepFreeze(object) {\n for (const prop in object) {\n const value = object[prop];\n if (typeof value === 'object' && !Object.isFrozen(value)) {\n deepFreeze(value);\n }\n }\n return Object.freeze(object);\n}\nexport function callback(call, ...args) {\n return typeof call !== 'function' ? undefined : call.apply(call, args);\n}\nfunction normalizeValue(value) {\n return typeof value === 'object'\n ? Array.isArray(value)\n ? value.map((value) => normalizeValue(value))\n : normalizeJson(value)\n : value;\n}\nexport function normalizeJson(payload) {\n return Object.entries(payload).reduce((result, [key, value]) => {\n if (itIsDefined(value)) {\n result[key] = normalizeValue(value);\n }\n return result;\n }, {});\n}\n/* istanbul ignore next */\nexport function base64ToBlob(data64, mimeType) {\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\n const byteCharacters = window.atob(result64);\n const byteArrays = [];\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n const byteArray = new Uint8Array(byteNumbers);\n byteArrays.push(byteArray);\n }\n return new Blob(byteArrays, { type: mimeType });\n}\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\nexport class Optional {\n constructor(value) {\n this.value = value;\n }\n present(callback) {\n return this.isPresent() ? callback(this.get()) : undefined;\n }\n empty(callback) {\n return this.isEmpty() ? callback() : undefined;\n }\n when(present, empty) {\n return this.isPresent() ? present(this.get()) : empty();\n }\n static build(value) {\n return itIsDefined(value) ? this.of(value) : this.empty();\n }\n static of(value) {\n if (itIsDefined(value)) {\n return new PresentOptional(value);\n }\n throw new Error('The passed value was null or undefined.');\n }\n static empty() {\n return new EmptyOptional();\n }\n}\nclass PresentOptional extends Optional {\n constructor(presentValue) {\n super(presentValue);\n this.presentValue = presentValue;\n }\n isPresent() {\n return true;\n }\n isEmpty() {\n return false;\n }\n get() {\n return this.presentValue;\n }\n}\nclass EmptyOptional extends Optional {\n isPresent() {\n return false;\n }\n isEmpty() {\n return true;\n }\n get() {\n throw new Error('The optional is not present.');\n }\n}\n//# sourceMappingURL=optional.js.map","import { itIsDefined } from './helpers';\nexport function fromPromise(value) {\n return value instanceof Promise ? value : Promise.resolve(value);\n}\nexport function thenPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n throw err;\n });\n}\nexport function voidPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nexport function catchPromise(promise, canLogError = false) {\n return promise.catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nfunction zipResolveCallbacks(options) {\n const { callbacks, catchError, index, resolve, result } = options;\n if (index === callbacks.length) {\n return resolve(result);\n }\n const promise = callbacks[index];\n new Promise(() => {\n promise()\n .then((value) => {\n result.push(value);\n return zipResolveCallbacks({\n ...options,\n index: index + 1,\n result\n });\n })\n .catch((err) => {\n return catchError(err);\n });\n });\n}\nexport function zipPromise(callbacks) {\n const result = [];\n return new Promise((resolve, reject) => {\n zipResolveCallbacks({\n callbacks,\n catchError: (err) => {\n reject(err);\n },\n index: 0,\n resolve: (result) => {\n resolve(result);\n },\n result\n });\n });\n}\nexport function securePromise(callback, catchError) {\n let promise$ = undefined;\n function itIsInstanced() {\n return itIsDefined(promise$);\n }\n function resolve() {\n if (!promise$) {\n promise$ = callback().catch((err) => {\n const errorValue = catchError && catchError(err);\n reset();\n if (errorValue) {\n return errorValue;\n }\n throw err;\n });\n }\n return promise$;\n }\n function reset() {\n promise$ = undefined;\n }\n function refresh() {\n promise$ = undefined;\n return resolve();\n }\n return { itIsInstanced, refresh, reset, resolve };\n}\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction itIsModelHidden(model) {\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\n}\nexport class AbstractEntityManager {\n}\nexport class EntityManager {\n constructor(source) {\n this.source = source;\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n this.relations = new Map();\n }\n persist(options) {\n this.links.push(options);\n }\n refresh(options) {\n options.bindable && this.relation(options.entity, options.model);\n this.refreshs.push(options);\n }\n sync(options) {\n options.bindable && this.relation(options.entity, options.model);\n this.syncs.push(options);\n }\n destroy(entity) {\n this.select(entity).present((model) => {\n itIsModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n });\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation({ uuid }, model) {\n this.relations.set(uuid, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select({ uuid }) {\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\n }\n async flush() {\n await this.persistAll();\n await this.refreshAll();\n await this.syncAll();\n await this.hiddenAll();\n await this.destroyAll();\n await this.procedureAll();\n this.dispose();\n }\n dispose() {\n this.relations.clear();\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n }\n persistAll() {\n const { links, source } = this;\n return Promise.all(links.map((link) => fromPromise(link.create(this)).then((model) => {\n const { bindable, entity } = link;\n if (bindable) {\n this.relation(entity, model);\n }\n return source.insert(model);\n })));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map(({ model }) => this.source.refresh(model)));\n }\n syncAll() {\n return Promise.all(this.syncs\n .filter(({ model }) => !this.destroys.includes(model))\n .reduce((syncs, sync) => {\n const dirty = sync.verify();\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.source.refresh(model, dirty);\n }));\n }\n destroyAll() {\n return Promise.all(this.destroys.map((destroy) => this.source.delete(destroy)));\n }\n hiddenAll() {\n return Promise.all(this.hiddens.map((hidden) => this.source.hidden(hidden)));\n }\n procedureAll() {\n return Promise.all(this.procedures.map((procedure) => this.source.procedure(procedure)));\n }\n}\n//# sourceMappingURL=entity-manager.js.map","function itIsModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityRefresh {\n constructor(entity, model, bindable = true) {\n this.entity = entity;\n this.model = model;\n this.bindable = bindable;\n }\n}\nexport class EntityLink {\n constructor(entity, bindable = true) {\n this.entity = entity;\n this.bindable = bindable;\n }\n}\nexport class EntitySync {\n constructor(entity, model, bindable = true) {\n this.entity = entity;\n this.model = model;\n this.bindable = bindable;\n this.firstDirty = this.createDirtyFromModel(model);\n }\n verify() {\n this.sync();\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.keys(model).forEach((key) => {\n dirty[key] = model[key];\n });\n return dirty;\n }\n createDirty() {\n const currentDirty = this.createDirtyFromModel(this.model);\n const finalDirty = {};\n Object.keys(currentDirty).forEach((key) => {\n if (currentDirty[key] !== this.firstDirty[key]) {\n finalDirty[key] = currentDirty[key];\n }\n });\n const requiredUpdate = Object.keys(finalDirty).length > 0;\n if (requiredUpdate && itIsModelEditable(this.model)) {\n finalDirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? finalDirty : undefined;\n }\n}\n//# sourceMappingURL=entity.js.map","export class AbstractPersistentUnit {\n}\n//# sourceMappingURL=persistent-unit.js.map","export class AbstractProcedure {\n}\n//# sourceMappingURL=procedure.js.map","export class AbstractRepository {\n}\n//# sourceMappingURL=repository.js.map"],"names":[],"mappings":";;;;AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;AACtC;;AC0BO,SAAS,WAAW,CAAC,MAAM,EAAE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AAC,KAAK,CAAC,CAAC;AACnE,QAAQ,MAAM,UAAU,GAAG,EAAE,CAAC;AAC9B,QAAQ,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK;AACnD,YAAY,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;AAC5D,gBAAgB,UAAU,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AACpD,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAClE,QAAQ,IAAI,cAAc,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AAC7D,YAAY,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACjD,SAAS;AACT,QAAQ,OAAO,cAAc,GAAG,UAAU,GAAG,SAAS,CAAC;AACvD,KAAK;AACL;;ACrDO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,iBAAiB,CAAC;AAC/B;;ACDO,MAAM,kBAAkB,CAAC;AAChC;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../../node_modules/@rolster/commons/dist/esm/helpers.js","../../node_modules/@rolster/commons/dist/esm/optional.js","../../node_modules/@rolster/commons/dist/esm/promises.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\nconst SLICE_SIZE = 512;\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\nconst prototypeToString = Object.prototype.toString;\nfunction clone(object, caches) {\n if (typeof object !== 'object') {\n return object;\n }\n if (prototypeToString.call(object) === '[object Object]') {\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\n /* istanbul ignore if */\n if (cacheObject) {\n return cacheObject;\n }\n caches.push(object);\n }\n const prototypeObject = Object.getPrototypeOf(object);\n const ConstructorObject = prototypeObject.constructor;\n if (PRIMITIVES.includes(ConstructorObject)) {\n return new ConstructorObject(object);\n }\n const cloneObject = new ConstructorObject();\n for (const prop in object) {\n cloneObject[prop] = clone(object[prop], caches);\n }\n return cloneObject;\n}\nexport function itIsDefined(object) {\n return typeof object !== 'undefined' && object !== null;\n}\nexport function itIsUndefined(object) {\n return !itIsDefined(object);\n}\nexport function parseBoolean(value) {\n return !(itIsUndefined(value) ||\n value === false ||\n FALSY_VALUE.includes(value));\n}\nexport function parse(value) {\n try {\n return JSON.parse(value);\n }\n catch {\n return value;\n }\n}\nexport function evalValueOrFunction(value) {\n return typeof value === 'function' ? value() : value;\n}\nexport function deepClone(object) {\n return clone(object, []);\n}\nexport function deepFreeze(object) {\n for (const prop in object) {\n const value = object[prop];\n if (typeof value === 'object' && !Object.isFrozen(value)) {\n deepFreeze(value);\n }\n }\n return Object.freeze(object);\n}\nexport function callback(call, ...args) {\n return typeof call !== 'function' ? undefined : call.apply(call, args);\n}\nfunction normalizeValue(value) {\n return typeof value === 'object'\n ? Array.isArray(value)\n ? value.map((value) => normalizeValue(value))\n : normalizeJson(value)\n : value;\n}\nexport function normalizeJson(payload) {\n return Object.entries(payload).reduce((result, [key, value]) => {\n if (itIsDefined(value)) {\n result[key] = normalizeValue(value);\n }\n return result;\n }, {});\n}\n/* istanbul ignore next */\nexport function base64ToBlob(data64, mimeType) {\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\n const byteCharacters = window.atob(result64);\n const byteArrays = [];\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n const byteArray = new Uint8Array(byteNumbers);\n byteArrays.push(byteArray);\n }\n return new Blob(byteArrays, { type: mimeType });\n}\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\nexport class Optional {\n constructor(value) {\n this.value = value;\n }\n present(callback) {\n return this.isPresent() ? callback(this.get()) : undefined;\n }\n empty(callback) {\n return this.isEmpty() ? callback() : undefined;\n }\n when(present, empty) {\n return this.isPresent() ? present(this.get()) : empty();\n }\n static build(value) {\n return itIsDefined(value) ? this.of(value) : this.empty();\n }\n static of(value) {\n if (itIsDefined(value)) {\n return new PresentOptional(value);\n }\n throw new Error('The passed value was null or undefined.');\n }\n static empty() {\n return new EmptyOptional();\n }\n}\nclass PresentOptional extends Optional {\n constructor(presentValue) {\n super(presentValue);\n this.presentValue = presentValue;\n }\n isPresent() {\n return true;\n }\n isEmpty() {\n return false;\n }\n get() {\n return this.presentValue;\n }\n}\nclass EmptyOptional extends Optional {\n isPresent() {\n return false;\n }\n isEmpty() {\n return true;\n }\n get() {\n throw new Error('The optional is not present.');\n }\n}\n//# sourceMappingURL=optional.js.map","import { itIsDefined } from './helpers';\nexport function fromPromise(value) {\n return value instanceof Promise ? value : Promise.resolve(value);\n}\nexport function thenPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n throw err;\n });\n}\nexport function voidPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nexport function catchPromise(promise, canLogError = false) {\n return promise.catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nfunction zipResolveCallbacks(options) {\n const { callbacks, catchError, index, resolve, result } = options;\n if (index === callbacks.length) {\n return resolve(result);\n }\n const promise = callbacks[index];\n new Promise(() => {\n promise()\n .then((value) => {\n result.push(value);\n return zipResolveCallbacks({\n ...options,\n index: index + 1,\n result\n });\n })\n .catch((err) => {\n return catchError(err);\n });\n });\n}\nexport function zipPromise(callbacks) {\n const result = [];\n return new Promise((resolve, reject) => {\n zipResolveCallbacks({\n callbacks,\n catchError: (err) => {\n reject(err);\n },\n index: 0,\n resolve: (result) => {\n resolve(result);\n },\n result\n });\n });\n}\nexport function securePromise(callback, catchError) {\n let promise$ = undefined;\n function itIsInstanced() {\n return itIsDefined(promise$);\n }\n function resolve() {\n if (!promise$) {\n promise$ = callback().catch((err) => {\n const errorValue = catchError && catchError(err);\n reset();\n if (errorValue) {\n return errorValue;\n }\n throw err;\n });\n }\n return promise$;\n }\n function reset() {\n promise$ = undefined;\n }\n function refresh() {\n promise$ = undefined;\n return resolve();\n }\n return { itIsInstanced, refresh, reset, resolve };\n}\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction itIsModelHidden(model) {\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\n}\nexport class AbstractEntityManager {\n}\nexport class EntityManager {\n constructor(dataSource) {\n this.dataSource = dataSource;\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n this.relations = new Map();\n }\n persist(options) {\n this.links.push(options);\n }\n refresh(options) {\n options.relationable && this.relation(options.entity, options.model);\n this.refreshs.push(options);\n }\n sync(options) {\n options.relationable && this.relation(options.entity, options.model);\n this.syncs.push(options);\n }\n destroy(entity) {\n this.select(entity).present((model) => {\n itIsModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n });\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation({ uuid }, model) {\n this.relations.set(uuid, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select({ uuid }) {\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\n }\n async flush() {\n await this.persistAll();\n await this.refreshAll();\n await this.syncAll();\n await this.hiddenAll();\n await this.destroyAll();\n await this.procedureAll();\n this.dispose();\n }\n dispose() {\n this.relations.clear();\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n }\n persistAll() {\n return Promise.all(this.links.map((link) => fromPromise(link.create(this)).then((model) => {\n link.bindable && this.relation(link.entity, model);\n return this.dataSource.insert(model);\n })));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map(({ model }) => this.dataSource.refresh(model)));\n }\n syncAll() {\n return Promise.all(this.syncs\n .filter(({ model }) => !this.destroys.includes(model))\n .reduce((syncs, sync) => {\n const dirty = sync.verify();\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.dataSource.refresh(model, dirty);\n }));\n }\n destroyAll() {\n return Promise.all(this.destroys.map((destroy) => this.dataSource.delete(destroy)));\n }\n hiddenAll() {\n return Promise.all(this.hiddens.map((hidden) => this.dataSource.hidden(hidden)));\n }\n procedureAll() {\n return Promise.all(this.procedures.map((procedure) => this.dataSource.procedure(procedure)));\n }\n}\n//# sourceMappingURL=entity-manager.js.map","function itIsModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityRefresh {\n constructor(entity, model, relationable = true) {\n this.entity = entity;\n this.model = model;\n this.relationable = relationable;\n }\n}\nexport class EntityLink {\n constructor(entity, bindable = true) {\n this.entity = entity;\n this.bindable = bindable;\n }\n}\nexport class EntitySync {\n constructor(entity, model, relationable = true) {\n this.entity = entity;\n this.model = model;\n this.relationable = relationable;\n this.firstDirty = this.createDirtyFromModel(model);\n }\n verify() {\n this.sync();\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.keys(model).forEach((key) => {\n dirty[key] = model[key];\n });\n return dirty;\n }\n createDirty() {\n const currentDirty = this.createDirtyFromModel(this.model);\n const finalDirty = {};\n Object.keys(currentDirty).forEach((key) => {\n if (currentDirty[key] !== this.firstDirty[key]) {\n finalDirty[key] = currentDirty[key];\n }\n });\n const requiredUpdate = Object.keys(finalDirty).length > 0;\n if (requiredUpdate && itIsModelEditable(this.model)) {\n finalDirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? finalDirty : undefined;\n }\n}\n//# sourceMappingURL=entity.js.map","export class AbstractPersistentUnit {\n}\n//# sourceMappingURL=persistent-unit.js.map","export class AbstractProcedure {\n}\n//# sourceMappingURL=procedure.js.map","export class AbstractRepository {\n}\n//# sourceMappingURL=repository.js.map"],"names":[],"mappings":";;;;AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;AACtC;;AC0BO,SAAS,WAAW,CAAC,MAAM,EAAE;AACpC,IAAI,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,IAAI,CAAC;AAC5D;;AC5BO,MAAM,QAAQ,CAAC;AACtB,IAAI,WAAW,CAAC,KAAK,EAAE;AACvB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,KAAK;AACL,IAAI,OAAO,CAAC,QAAQ,EAAE;AACtB,QAAQ,OAAO,IAAI,CAAC,SAAS,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC;AACnE,KAAK;AACL,IAAI,KAAK,CAAC,QAAQ,EAAE;AACpB,QAAQ,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,SAAS,CAAC;AACvD,KAAK;AACL,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE;AACzB,QAAQ,OAAO,IAAI,CAAC,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC;AAChE,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,KAAK,EAAE;AACxB,QAAQ,OAAO,W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{
|
|
|
71
71
|
class AbstractEntityManager {
|
|
72
72
|
}
|
|
73
73
|
class EntityManager {
|
|
74
|
-
constructor(
|
|
75
|
-
this.
|
|
74
|
+
constructor(dataSource) {
|
|
75
|
+
this.dataSource = dataSource;
|
|
76
76
|
this.links = [];
|
|
77
77
|
this.refreshs = [];
|
|
78
78
|
this.syncs = [];
|
|
@@ -85,11 +85,11 @@ class EntityManager {
|
|
|
85
85
|
this.links.push(options);
|
|
86
86
|
}
|
|
87
87
|
refresh(options) {
|
|
88
|
-
options.
|
|
88
|
+
options.relationable && this.relation(options.entity, options.model);
|
|
89
89
|
this.refreshs.push(options);
|
|
90
90
|
}
|
|
91
91
|
sync(options) {
|
|
92
|
-
options.
|
|
92
|
+
options.relationable && this.relation(options.entity, options.model);
|
|
93
93
|
this.syncs.push(options);
|
|
94
94
|
}
|
|
95
95
|
destroy(entity) {
|
|
@@ -131,17 +131,13 @@ class EntityManager {
|
|
|
131
131
|
this.procedures = [];
|
|
132
132
|
}
|
|
133
133
|
persistAll() {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (bindable) {
|
|
138
|
-
this.relation(entity, model);
|
|
139
|
-
}
|
|
140
|
-
return source.insert(model);
|
|
134
|
+
return Promise.all(this.links.map((link) => fromPromise(link.create(this)).then((model) => {
|
|
135
|
+
link.bindable && this.relation(link.entity, model);
|
|
136
|
+
return this.dataSource.insert(model);
|
|
141
137
|
})));
|
|
142
138
|
}
|
|
143
139
|
refreshAll() {
|
|
144
|
-
return Promise.all(this.refreshs.map(({ model }) => this.
|
|
140
|
+
return Promise.all(this.refreshs.map(({ model }) => this.dataSource.refresh(model)));
|
|
145
141
|
}
|
|
146
142
|
syncAll() {
|
|
147
143
|
return Promise.all(this.syncs
|
|
@@ -152,17 +148,17 @@ class EntityManager {
|
|
|
152
148
|
return syncs;
|
|
153
149
|
}, [])
|
|
154
150
|
.map(([model, dirty]) => {
|
|
155
|
-
return this.
|
|
151
|
+
return this.dataSource.refresh(model, dirty);
|
|
156
152
|
}));
|
|
157
153
|
}
|
|
158
154
|
destroyAll() {
|
|
159
|
-
return Promise.all(this.destroys.map((destroy) => this.
|
|
155
|
+
return Promise.all(this.destroys.map((destroy) => this.dataSource.delete(destroy)));
|
|
160
156
|
}
|
|
161
157
|
hiddenAll() {
|
|
162
|
-
return Promise.all(this.hiddens.map((hidden) => this.
|
|
158
|
+
return Promise.all(this.hiddens.map((hidden) => this.dataSource.hidden(hidden)));
|
|
163
159
|
}
|
|
164
160
|
procedureAll() {
|
|
165
|
-
return Promise.all(this.procedures.map((procedure) => this.
|
|
161
|
+
return Promise.all(this.procedures.map((procedure) => this.dataSource.procedure(procedure)));
|
|
166
162
|
}
|
|
167
163
|
}
|
|
168
164
|
|
|
@@ -175,10 +171,10 @@ class Entity {
|
|
|
175
171
|
}
|
|
176
172
|
}
|
|
177
173
|
class EntityRefresh {
|
|
178
|
-
constructor(entity, model,
|
|
174
|
+
constructor(entity, model, relationable = true) {
|
|
179
175
|
this.entity = entity;
|
|
180
176
|
this.model = model;
|
|
181
|
-
this.
|
|
177
|
+
this.relationable = relationable;
|
|
182
178
|
}
|
|
183
179
|
}
|
|
184
180
|
class EntityLink {
|
|
@@ -188,10 +184,10 @@ class EntityLink {
|
|
|
188
184
|
}
|
|
189
185
|
}
|
|
190
186
|
class EntitySync {
|
|
191
|
-
constructor(entity, model,
|
|
187
|
+
constructor(entity, model, relationable = true) {
|
|
192
188
|
this.entity = entity;
|
|
193
189
|
this.model = model;
|
|
194
|
-
this.
|
|
190
|
+
this.relationable = relationable;
|
|
195
191
|
this.firstDirty = this.createDirtyFromModel(model);
|
|
196
192
|
}
|
|
197
193
|
verify() {
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../../node_modules/@rolster/commons/dist/esm/helpers.js","../../node_modules/@rolster/commons/dist/esm/optional.js","../../node_modules/@rolster/commons/dist/esm/promises.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\nconst SLICE_SIZE = 512;\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\nconst prototypeToString = Object.prototype.toString;\nfunction clone(object, caches) {\n if (typeof object !== 'object') {\n return object;\n }\n if (prototypeToString.call(object) === '[object Object]') {\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\n /* istanbul ignore if */\n if (cacheObject) {\n return cacheObject;\n }\n caches.push(object);\n }\n const prototypeObject = Object.getPrototypeOf(object);\n const ConstructorObject = prototypeObject.constructor;\n if (PRIMITIVES.includes(ConstructorObject)) {\n return new ConstructorObject(object);\n }\n const cloneObject = new ConstructorObject();\n for (const prop in object) {\n cloneObject[prop] = clone(object[prop], caches);\n }\n return cloneObject;\n}\nexport function itIsDefined(object) {\n return typeof object !== 'undefined' && object !== null;\n}\nexport function itIsUndefined(object) {\n return !itIsDefined(object);\n}\nexport function parseBoolean(value) {\n return !(itIsUndefined(value) ||\n value === false ||\n FALSY_VALUE.includes(value));\n}\nexport function parse(value) {\n try {\n return JSON.parse(value);\n }\n catch {\n return value;\n }\n}\nexport function evalValueOrFunction(value) {\n return typeof value === 'function' ? value() : value;\n}\nexport function deepClone(object) {\n return clone(object, []);\n}\nexport function deepFreeze(object) {\n for (const prop in object) {\n const value = object[prop];\n if (typeof value === 'object' && !Object.isFrozen(value)) {\n deepFreeze(value);\n }\n }\n return Object.freeze(object);\n}\nexport function callback(call, ...args) {\n return typeof call !== 'function' ? undefined : call.apply(call, args);\n}\nfunction normalizeValue(value) {\n return typeof value === 'object'\n ? Array.isArray(value)\n ? value.map((value) => normalizeValue(value))\n : normalizeJson(value)\n : value;\n}\nexport function normalizeJson(payload) {\n return Object.entries(payload).reduce((result, [key, value]) => {\n if (itIsDefined(value)) {\n result[key] = normalizeValue(value);\n }\n return result;\n }, {});\n}\n/* istanbul ignore next */\nexport function base64ToBlob(data64, mimeType) {\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\n const byteCharacters = window.atob(result64);\n const byteArrays = [];\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n const byteArray = new Uint8Array(byteNumbers);\n byteArrays.push(byteArray);\n }\n return new Blob(byteArrays, { type: mimeType });\n}\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\nexport class Optional {\n constructor(value) {\n this.value = value;\n }\n present(callback) {\n return this.isPresent() ? callback(this.get()) : undefined;\n }\n empty(callback) {\n return this.isEmpty() ? callback() : undefined;\n }\n when(present, empty) {\n return this.isPresent() ? present(this.get()) : empty();\n }\n static build(value) {\n return itIsDefined(value) ? this.of(value) : this.empty();\n }\n static of(value) {\n if (itIsDefined(value)) {\n return new PresentOptional(value);\n }\n throw new Error('The passed value was null or undefined.');\n }\n static empty() {\n return new EmptyOptional();\n }\n}\nclass PresentOptional extends Optional {\n constructor(presentValue) {\n super(presentValue);\n this.presentValue = presentValue;\n }\n isPresent() {\n return true;\n }\n isEmpty() {\n return false;\n }\n get() {\n return this.presentValue;\n }\n}\nclass EmptyOptional extends Optional {\n isPresent() {\n return false;\n }\n isEmpty() {\n return true;\n }\n get() {\n throw new Error('The optional is not present.');\n }\n}\n//# sourceMappingURL=optional.js.map","import { itIsDefined } from './helpers';\nexport function fromPromise(value) {\n return value instanceof Promise ? value : Promise.resolve(value);\n}\nexport function thenPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n throw err;\n });\n}\nexport function voidPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nexport function catchPromise(promise, canLogError = false) {\n return promise.catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nfunction zipResolveCallbacks(options) {\n const { callbacks, catchError, index, resolve, result } = options;\n if (index === callbacks.length) {\n return resolve(result);\n }\n const promise = callbacks[index];\n new Promise(() => {\n promise()\n .then((value) => {\n result.push(value);\n return zipResolveCallbacks({\n ...options,\n index: index + 1,\n result\n });\n })\n .catch((err) => {\n return catchError(err);\n });\n });\n}\nexport function zipPromise(callbacks) {\n const result = [];\n return new Promise((resolve, reject) => {\n zipResolveCallbacks({\n callbacks,\n catchError: (err) => {\n reject(err);\n },\n index: 0,\n resolve: (result) => {\n resolve(result);\n },\n result\n });\n });\n}\nexport function securePromise(callback, catchError) {\n let promise$ = undefined;\n function itIsInstanced() {\n return itIsDefined(promise$);\n }\n function resolve() {\n if (!promise$) {\n promise$ = callback().catch((err) => {\n const errorValue = catchError && catchError(err);\n reset();\n if (errorValue) {\n return errorValue;\n }\n throw err;\n });\n }\n return promise$;\n }\n function reset() {\n promise$ = undefined;\n }\n function refresh() {\n promise$ = undefined;\n return resolve();\n }\n return { itIsInstanced, refresh, reset, resolve };\n}\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction itIsModelHidden(model) {\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\n}\nexport class AbstractEntityManager {\n}\nexport class EntityManager {\n constructor(source) {\n this.source = source;\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n this.relations = new Map();\n }\n persist(options) {\n this.links.push(options);\n }\n refresh(options) {\n options.bindable && this.relation(options.entity, options.model);\n this.refreshs.push(options);\n }\n sync(options) {\n options.bindable && this.relation(options.entity, options.model);\n this.syncs.push(options);\n }\n destroy(entity) {\n this.select(entity).present((model) => {\n itIsModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n });\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation({ uuid }, model) {\n this.relations.set(uuid, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select({ uuid }) {\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\n }\n async flush() {\n await this.persistAll();\n await this.refreshAll();\n await this.syncAll();\n await this.hiddenAll();\n await this.destroyAll();\n await this.procedureAll();\n this.dispose();\n }\n dispose() {\n this.relations.clear();\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n }\n persistAll() {\n const { links, source } = this;\n return Promise.all(links.map((link) => fromPromise(link.create(this)).then((model) => {\n const { bindable, entity } = link;\n if (bindable) {\n this.relation(entity, model);\n }\n return source.insert(model);\n })));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map(({ model }) => this.source.refresh(model)));\n }\n syncAll() {\n return Promise.all(this.syncs\n .filter(({ model }) => !this.destroys.includes(model))\n .reduce((syncs, sync) => {\n const dirty = sync.verify();\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.source.refresh(model, dirty);\n }));\n }\n destroyAll() {\n return Promise.all(this.destroys.map((destroy) => this.source.delete(destroy)));\n }\n hiddenAll() {\n return Promise.all(this.hiddens.map((hidden) => this.source.hidden(hidden)));\n }\n procedureAll() {\n return Promise.all(this.procedures.map((procedure) => this.source.procedure(procedure)));\n }\n}\n//# sourceMappingURL=entity-manager.js.map","function itIsModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityRefresh {\n constructor(entity, model, bindable = true) {\n this.entity = entity;\n this.model = model;\n this.bindable = bindable;\n }\n}\nexport class EntityLink {\n constructor(entity, bindable = true) {\n this.entity = entity;\n this.bindable = bindable;\n }\n}\nexport class EntitySync {\n constructor(entity, model, bindable = true) {\n this.entity = entity;\n this.model = model;\n this.bindable = bindable;\n this.firstDirty = this.createDirtyFromModel(model);\n }\n verify() {\n this.sync();\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.keys(model).forEach((key) => {\n dirty[key] = model[key];\n });\n return dirty;\n }\n createDirty() {\n const currentDirty = this.createDirtyFromModel(this.model);\n const finalDirty = {};\n Object.keys(currentDirty).forEach((key) => {\n if (currentDirty[key] !== this.firstDirty[key]) {\n finalDirty[key] = currentDirty[key];\n }\n });\n const requiredUpdate = Object.keys(finalDirty).length > 0;\n if (requiredUpdate && itIsModelEditable(this.model)) {\n finalDirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? finalDirty : undefined;\n }\n}\n//# sourceMappingURL=entity.js.map","export class AbstractPersistentUnit {\n}\n//# sourceMappingURL=persistent-unit.js.map","export class AbstractProcedure {\n}\n//# sourceMappingURL=procedure.js.map","export class AbstractRepository {\n}\n//# sourceMappingURL=repository.js.map"],"names":[],"mappings":"AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;AACtC;;AC0BO,SAAS,WAAW,CAAC,MAAM,EAAE;AACpC,IAAI,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,IAAI,CAAC;AAC5D;;AC5BO,MAAM,QAAQ,CAAC;AACtB,IAAI,WAAW,CAAC,KAAK,EAAE;AACvB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,KAAK;AACL,IAAI,OAAO,CAAC,QAAQ,EAAE;AACtB,QAAQ,OAAO,IAAI,CAAC,SAAS,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC;AACnE,KAAK;AACL,IAAI,KAAK,CAAC,QAAQ,EAAE;AACpB,QAAQ,OAAO,IAAI,CAAC,OAAO,EAA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,CAAC;AAClE,QAAQ,IAAI,cAAc,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AAC7D,YAAY,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACjD,SAAS;AACT,QAAQ,OAAO,cAAc,GAAG,UAAU,GAAG,SAAS,CAAC;AACvD,KAAK;AACL;;ACrDO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,iBAAiB,CAAC;AAC/B;;ACDO,MAAM,kBAAkB,CAAC;AAChC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../../node_modules/@rolster/commons/dist/esm/helpers.js","../../node_modules/@rolster/commons/dist/esm/optional.js","../../node_modules/@rolster/commons/dist/esm/promises.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\nconst SLICE_SIZE = 512;\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\nconst prototypeToString = Object.prototype.toString;\nfunction clone(object, caches) {\n if (typeof object !== 'object') {\n return object;\n }\n if (prototypeToString.call(object) === '[object Object]') {\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\n /* istanbul ignore if */\n if (cacheObject) {\n return cacheObject;\n }\n caches.push(object);\n }\n const prototypeObject = Object.getPrototypeOf(object);\n const ConstructorObject = prototypeObject.constructor;\n if (PRIMITIVES.includes(ConstructorObject)) {\n return new ConstructorObject(object);\n }\n const cloneObject = new ConstructorObject();\n for (const prop in object) {\n cloneObject[prop] = clone(object[prop], caches);\n }\n return cloneObject;\n}\nexport function itIsDefined(object) {\n return typeof object !== 'undefined' && object !== null;\n}\nexport function itIsUndefined(object) {\n return !itIsDefined(object);\n}\nexport function parseBoolean(value) {\n return !(itIsUndefined(value) ||\n value === false ||\n FALSY_VALUE.includes(value));\n}\nexport function parse(value) {\n try {\n return JSON.parse(value);\n }\n catch {\n return value;\n }\n}\nexport function evalValueOrFunction(value) {\n return typeof value === 'function' ? value() : value;\n}\nexport function deepClone(object) {\n return clone(object, []);\n}\nexport function deepFreeze(object) {\n for (const prop in object) {\n const value = object[prop];\n if (typeof value === 'object' && !Object.isFrozen(value)) {\n deepFreeze(value);\n }\n }\n return Object.freeze(object);\n}\nexport function callback(call, ...args) {\n return typeof call !== 'function' ? undefined : call.apply(call, args);\n}\nfunction normalizeValue(value) {\n return typeof value === 'object'\n ? Array.isArray(value)\n ? value.map((value) => normalizeValue(value))\n : normalizeJson(value)\n : value;\n}\nexport function normalizeJson(payload) {\n return Object.entries(payload).reduce((result, [key, value]) => {\n if (itIsDefined(value)) {\n result[key] = normalizeValue(value);\n }\n return result;\n }, {});\n}\n/* istanbul ignore next */\nexport function base64ToBlob(data64, mimeType) {\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\n const byteCharacters = window.atob(result64);\n const byteArrays = [];\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n const byteArray = new Uint8Array(byteNumbers);\n byteArrays.push(byteArray);\n }\n return new Blob(byteArrays, { type: mimeType });\n}\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\nexport class Optional {\n constructor(value) {\n this.value = value;\n }\n present(callback) {\n return this.isPresent() ? callback(this.get()) : undefined;\n }\n empty(callback) {\n return this.isEmpty() ? callback() : undefined;\n }\n when(present, empty) {\n return this.isPresent() ? present(this.get()) : empty();\n }\n static build(value) {\n return itIsDefined(value) ? this.of(value) : this.empty();\n }\n static of(value) {\n if (itIsDefined(value)) {\n return new PresentOptional(value);\n }\n throw new Error('The passed value was null or undefined.');\n }\n static empty() {\n return new EmptyOptional();\n }\n}\nclass PresentOptional extends Optional {\n constructor(presentValue) {\n super(presentValue);\n this.presentValue = presentValue;\n }\n isPresent() {\n return true;\n }\n isEmpty() {\n return false;\n }\n get() {\n return this.presentValue;\n }\n}\nclass EmptyOptional extends Optional {\n isPresent() {\n return false;\n }\n isEmpty() {\n return true;\n }\n get() {\n throw new Error('The optional is not present.');\n }\n}\n//# sourceMappingURL=optional.js.map","import { itIsDefined } from './helpers';\nexport function fromPromise(value) {\n return value instanceof Promise ? value : Promise.resolve(value);\n}\nexport function thenPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n throw err;\n });\n}\nexport function voidPromise(promise, canLogError = false) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nexport function catchPromise(promise, canLogError = false) {\n return promise.catch((err) => {\n /* istanbul ignore next */\n canLogError && console.log(err);\n return undefined;\n });\n}\nfunction zipResolveCallbacks(options) {\n const { callbacks, catchError, index, resolve, result } = options;\n if (index === callbacks.length) {\n return resolve(result);\n }\n const promise = callbacks[index];\n new Promise(() => {\n promise()\n .then((value) => {\n result.push(value);\n return zipResolveCallbacks({\n ...options,\n index: index + 1,\n result\n });\n })\n .catch((err) => {\n return catchError(err);\n });\n });\n}\nexport function zipPromise(callbacks) {\n const result = [];\n return new Promise((resolve, reject) => {\n zipResolveCallbacks({\n callbacks,\n catchError: (err) => {\n reject(err);\n },\n index: 0,\n resolve: (result) => {\n resolve(result);\n },\n result\n });\n });\n}\nexport function securePromise(callback, catchError) {\n let promise$ = undefined;\n function itIsInstanced() {\n return itIsDefined(promise$);\n }\n function resolve() {\n if (!promise$) {\n promise$ = callback().catch((err) => {\n const errorValue = catchError && catchError(err);\n reset();\n if (errorValue) {\n return errorValue;\n }\n throw err;\n });\n }\n return promise$;\n }\n function reset() {\n promise$ = undefined;\n }\n function refresh() {\n promise$ = undefined;\n return resolve();\n }\n return { itIsInstanced, refresh, reset, resolve };\n}\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction itIsModelHidden(model) {\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\n}\nexport class AbstractEntityManager {\n}\nexport class EntityManager {\n constructor(dataSource) {\n this.dataSource = dataSource;\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n this.relations = new Map();\n }\n persist(options) {\n this.links.push(options);\n }\n refresh(options) {\n options.relationable && this.relation(options.entity, options.model);\n this.refreshs.push(options);\n }\n sync(options) {\n options.relationable && this.relation(options.entity, options.model);\n this.syncs.push(options);\n }\n destroy(entity) {\n this.select(entity).present((model) => {\n itIsModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n });\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation({ uuid }, model) {\n this.relations.set(uuid, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select({ uuid }) {\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\n }\n async flush() {\n await this.persistAll();\n await this.refreshAll();\n await this.syncAll();\n await this.hiddenAll();\n await this.destroyAll();\n await this.procedureAll();\n this.dispose();\n }\n dispose() {\n this.relations.clear();\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n }\n persistAll() {\n return Promise.all(this.links.map((link) => fromPromise(link.create(this)).then((model) => {\n link.bindable && this.relation(link.entity, model);\n return this.dataSource.insert(model);\n })));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map(({ model }) => this.dataSource.refresh(model)));\n }\n syncAll() {\n return Promise.all(this.syncs\n .filter(({ model }) => !this.destroys.includes(model))\n .reduce((syncs, sync) => {\n const dirty = sync.verify();\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.dataSource.refresh(model, dirty);\n }));\n }\n destroyAll() {\n return Promise.all(this.destroys.map((destroy) => this.dataSource.delete(destroy)));\n }\n hiddenAll() {\n return Promise.all(this.hiddens.map((hidden) => this.dataSource.hidden(hidden)));\n }\n procedureAll() {\n return Promise.all(this.procedures.map((procedure) => this.dataSource.procedure(procedure)));\n }\n}\n//# sourceMappingURL=entity-manager.js.map","function itIsModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityRefresh {\n constructor(entity, model, relationable = true) {\n this.entity = entity;\n this.model = model;\n this.relationable = relationable;\n }\n}\nexport class EntityLink {\n constructor(entity, bindable = true) {\n this.entity = entity;\n this.bindable = bindable;\n }\n}\nexport class EntitySync {\n constructor(entity, model, relationable = true) {\n this.entity = entity;\n this.model = model;\n this.relationable = relationable;\n this.firstDirty = this.createDirtyFromModel(model);\n }\n verify() {\n this.sync();\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.keys(model).forEach((key) => {\n dirty[key] = model[key];\n });\n return dirty;\n }\n createDirty() {\n const currentDirty = this.createDirtyFromModel(this.model);\n const finalDirty = {};\n Object.keys(currentDirty).forEach((key) => {\n if (currentDirty[key] !== this.firstDirty[key]) {\n finalDirty[key] = currentDirty[key];\n }\n });\n const requiredUpdate = Object.keys(finalDirty).length > 0;\n if (requiredUpdate && itIsModelEditable(this.model)) {\n finalDirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? finalDirty : undefined;\n }\n}\n//# sourceMappingURL=entity.js.map","export class AbstractPersistentUnit {\n}\n//# sourceMappingURL=persistent-unit.js.map","export class AbstractProcedure {\n}\n//# sourceMappingURL=procedure.js.map","export class AbstractRepository {\n}\n//# sourceMappingURL=repository.js.map"],"names":[],"mappings":"AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;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M,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK;AACnD,YAAY,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;AAC5D,gBAAgB,UAAU,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AACpD,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAClE,QAAQ,IAAI,cAAc,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AAC7D,YAAY,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACjD,SAAS;AACT,QAAQ,OAAO,cAAc,GAAG,UAAU,GAAG,SAAS,CAAC;AACvD,KAAK;AACL;;ACrDO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,iBAAiB,CAAC;AAC/B;;ACDO,MAAM,kBAAkB,CAAC;AAChC;;;;"}
|
|
@@ -3,13 +3,13 @@ import { AbstractEntityDataSource } from './datasource';
|
|
|
3
3
|
import { EntityLink, EntitySync, EntityRefresh } from './entity';
|
|
4
4
|
import { AbstractModel, AbstractEntity, QueryEntityManager } from './types';
|
|
5
5
|
import { AbstractProcedure } from './procedure';
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
type
|
|
6
|
+
type LinkOptions = EntityLink<AbstractEntity, AbstractModel>;
|
|
7
|
+
type RefreshOptions = EntityRefresh<AbstractEntity, AbstractModel>;
|
|
8
|
+
type SyncOptions = EntitySync<AbstractEntity, AbstractModel>;
|
|
9
9
|
export declare abstract class AbstractEntityManager implements QueryEntityManager {
|
|
10
|
-
abstract persist(options:
|
|
11
|
-
abstract refresh(options:
|
|
12
|
-
abstract sync(options:
|
|
10
|
+
abstract persist(options: LinkOptions): void;
|
|
11
|
+
abstract refresh(options: RefreshOptions): void;
|
|
12
|
+
abstract sync(options: SyncOptions): void;
|
|
13
13
|
abstract destroy(entity: AbstractEntity): void;
|
|
14
14
|
abstract procedure(procedure: AbstractProcedure): void;
|
|
15
15
|
abstract relation(entity: AbstractEntity, model: AbstractModel): void;
|
|
@@ -19,7 +19,7 @@ export declare abstract class AbstractEntityManager implements QueryEntityManage
|
|
|
19
19
|
abstract dispose(): void;
|
|
20
20
|
}
|
|
21
21
|
export declare class EntityManager implements AbstractEntityManager {
|
|
22
|
-
private
|
|
22
|
+
private dataSource;
|
|
23
23
|
private relations;
|
|
24
24
|
private links;
|
|
25
25
|
private refreshs;
|
|
@@ -27,10 +27,10 @@ export declare class EntityManager implements AbstractEntityManager {
|
|
|
27
27
|
private destroys;
|
|
28
28
|
private hiddens;
|
|
29
29
|
private procedures;
|
|
30
|
-
constructor(
|
|
31
|
-
persist(options:
|
|
32
|
-
refresh(options:
|
|
33
|
-
sync(options:
|
|
30
|
+
constructor(dataSource: AbstractEntityDataSource);
|
|
31
|
+
persist(options: LinkOptions): void;
|
|
32
|
+
refresh(options: RefreshOptions): void;
|
|
33
|
+
sync(options: SyncOptions): void;
|
|
34
34
|
destroy(entity: AbstractEntity): void;
|
|
35
35
|
procedure(procedure: AbstractProcedure): void;
|
|
36
36
|
relation({ uuid }: AbstractEntity, model: AbstractModel): void;
|
|
@@ -5,8 +5,8 @@ function itIsModelHidden(model) {
|
|
|
5
5
|
export class AbstractEntityManager {
|
|
6
6
|
}
|
|
7
7
|
export class EntityManager {
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
8
|
+
constructor(dataSource) {
|
|
9
|
+
this.dataSource = dataSource;
|
|
10
10
|
this.links = [];
|
|
11
11
|
this.refreshs = [];
|
|
12
12
|
this.syncs = [];
|
|
@@ -19,11 +19,11 @@ export class EntityManager {
|
|
|
19
19
|
this.links.push(options);
|
|
20
20
|
}
|
|
21
21
|
refresh(options) {
|
|
22
|
-
options.
|
|
22
|
+
options.relationable && this.relation(options.entity, options.model);
|
|
23
23
|
this.refreshs.push(options);
|
|
24
24
|
}
|
|
25
25
|
sync(options) {
|
|
26
|
-
options.
|
|
26
|
+
options.relationable && this.relation(options.entity, options.model);
|
|
27
27
|
this.syncs.push(options);
|
|
28
28
|
}
|
|
29
29
|
destroy(entity) {
|
|
@@ -65,17 +65,13 @@ export class EntityManager {
|
|
|
65
65
|
this.procedures = [];
|
|
66
66
|
}
|
|
67
67
|
persistAll() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (bindable) {
|
|
72
|
-
this.relation(entity, model);
|
|
73
|
-
}
|
|
74
|
-
return source.insert(model);
|
|
68
|
+
return Promise.all(this.links.map((link) => fromPromise(link.create(this)).then((model) => {
|
|
69
|
+
link.bindable && this.relation(link.entity, model);
|
|
70
|
+
return this.dataSource.insert(model);
|
|
75
71
|
})));
|
|
76
72
|
}
|
|
77
73
|
refreshAll() {
|
|
78
|
-
return Promise.all(this.refreshs.map(({ model }) => this.
|
|
74
|
+
return Promise.all(this.refreshs.map(({ model }) => this.dataSource.refresh(model)));
|
|
79
75
|
}
|
|
80
76
|
syncAll() {
|
|
81
77
|
return Promise.all(this.syncs
|
|
@@ -86,17 +82,17 @@ export class EntityManager {
|
|
|
86
82
|
return syncs;
|
|
87
83
|
}, [])
|
|
88
84
|
.map(([model, dirty]) => {
|
|
89
|
-
return this.
|
|
85
|
+
return this.dataSource.refresh(model, dirty);
|
|
90
86
|
}));
|
|
91
87
|
}
|
|
92
88
|
destroyAll() {
|
|
93
|
-
return Promise.all(this.destroys.map((destroy) => this.
|
|
89
|
+
return Promise.all(this.destroys.map((destroy) => this.dataSource.delete(destroy)));
|
|
94
90
|
}
|
|
95
91
|
hiddenAll() {
|
|
96
|
-
return Promise.all(this.hiddens.map((hidden) => this.
|
|
92
|
+
return Promise.all(this.hiddens.map((hidden) => this.dataSource.hidden(hidden)));
|
|
97
93
|
}
|
|
98
94
|
procedureAll() {
|
|
99
|
-
return Promise.all(this.procedures.map((procedure) => this.
|
|
95
|
+
return Promise.all(this.procedures.map((procedure) => this.dataSource.procedure(procedure)));
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
98
|
//# sourceMappingURL=entity-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-manager.js","sourceRoot":"","sources":["../../src/entity-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAiBzD,SAAS,eAAe,CAAC,KAAU;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC;AAC/E,CAAC;AAED,MAAM,OAAgB,qBAAqB;CAoB1C;AAED,MAAM,OAAO,aAAa;IAexB,YAAoB,
|
|
1
|
+
{"version":3,"file":"entity-manager.js","sourceRoot":"","sources":["../../src/entity-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAiBzD,SAAS,eAAe,CAAC,KAAU;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC;AAC/E,CAAC;AAED,MAAM,OAAgB,qBAAqB;CAoB1C;AAED,MAAM,OAAO,aAAa;IAexB,YAAoB,UAAoC;QAApC,eAAU,GAAV,UAAU,CAA0B;QAZhD,UAAK,GAAkB,EAAE,CAAC;QAE1B,aAAQ,GAAqB,EAAE,CAAC;QAEhC,UAAK,GAAkB,EAAE,CAAC;QAE1B,aAAQ,GAAoB,EAAE,CAAC;QAE/B,YAAO,GAAoB,EAAE,CAAC;QAE9B,eAAU,GAAwB,EAAE,CAAC;QAG3C,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;IACpD,CAAC;IAEM,OAAO,CAAC,OAAoB;QACjC,IAAI,C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ACJ,CAAC;IAEO,YAAY;QAClB,OAAO,OAAO,CAAC,GAAG,CAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CACzE,CAAC;IACJ,CAAC;CACF"}
|
package/dist/esm/entity.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export declare class Entity implements AbstractEntity {
|
|
|
6
6
|
export declare abstract class EntityRefresh<E extends AbstractEntity, M extends AbstractModel> {
|
|
7
7
|
readonly entity: E;
|
|
8
8
|
readonly model: M;
|
|
9
|
-
readonly
|
|
10
|
-
constructor(entity: E, model: M,
|
|
9
|
+
readonly relationable: boolean;
|
|
10
|
+
constructor(entity: E, model: M, relationable?: boolean);
|
|
11
11
|
abstract refresh(): void;
|
|
12
12
|
}
|
|
13
13
|
export declare abstract class EntityLink<E extends AbstractEntity, M extends AbstractModel> {
|
|
@@ -19,9 +19,9 @@ export declare abstract class EntityLink<E extends AbstractEntity, M extends Abs
|
|
|
19
19
|
export declare abstract class EntitySync<E extends AbstractEntity, M extends AbstractModel> {
|
|
20
20
|
readonly entity: E;
|
|
21
21
|
readonly model: M;
|
|
22
|
-
readonly
|
|
22
|
+
readonly relationable: boolean;
|
|
23
23
|
private firstDirty;
|
|
24
|
-
constructor(entity: E, model: M,
|
|
24
|
+
constructor(entity: E, model: M, relationable?: boolean);
|
|
25
25
|
abstract sync(): void;
|
|
26
26
|
verify(): Undefined<DirtyModel>;
|
|
27
27
|
private createDirtyFromModel;
|
package/dist/esm/entity.js
CHANGED
|
@@ -7,10 +7,10 @@ export class Entity {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export class EntityRefresh {
|
|
10
|
-
constructor(entity, model,
|
|
10
|
+
constructor(entity, model, relationable = true) {
|
|
11
11
|
this.entity = entity;
|
|
12
12
|
this.model = model;
|
|
13
|
-
this.
|
|
13
|
+
this.relationable = relationable;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
export class EntityLink {
|
|
@@ -20,10 +20,10 @@ export class EntityLink {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
export class EntitySync {
|
|
23
|
-
constructor(entity, model,
|
|
23
|
+
constructor(entity, model, relationable = true) {
|
|
24
24
|
this.entity = entity;
|
|
25
25
|
this.model = model;
|
|
26
|
-
this.
|
|
26
|
+
this.relationable = relationable;
|
|
27
27
|
this.firstDirty = this.createDirtyFromModel(model);
|
|
28
28
|
}
|
|
29
29
|
verify() {
|
package/dist/esm/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":"AAQA,SAAS,iBAAiB,CAAC,KAAU;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,WAAW,IAAI,KAAK,CAAC;AAC3D,CAAC;AAED,MAAM,OAAO,MAAM;IACjB,YAA4B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;CAC7C;AAED,MAAM,OAAgB,aAAa;IAIjC,YACkB,MAAS,EACT,KAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":"AAQA,SAAS,iBAAiB,CAAC,KAAU;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,WAAW,IAAI,KAAK,CAAC;AAC3D,CAAC;AAED,MAAM,OAAO,MAAM;IACjB,YAA4B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;CAC7C;AAED,MAAM,OAAgB,aAAa;IAIjC,YACkB,MAAS,EACT,KAAQ,EACR,eAAe,IAAI;QAFnB,WAAM,GAAN,MAAM,CAAG;QACT,UAAK,GAAL,KAAK,CAAG;QACR,iBAAY,GAAZ,YAAY,CAAO;IAClC,CAAC;CAGL;AAED,MAAM,OAAgB,UAAU;IAI9B,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