@rolster/vinegar 2.0.0 → 2.1.1
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 +54 -56
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +49 -51
- package/dist/es/index.js.map +1 -1
- package/dist/esm/database.d.ts +2 -2
- package/dist/esm/database.js +1 -1
- package/dist/esm/database.js.map +1 -1
- package/dist/esm/datasource.d.ts +8 -9
- package/dist/esm/datasource.js +1 -1
- package/dist/esm/datasource.js.map +1 -1
- package/dist/esm/entity-manager.d.ts +26 -29
- package/dist/esm/entity-manager.js +11 -9
- package/dist/esm/entity-manager.js.map +1 -1
- package/dist/esm/entity.d.ts +26 -1
- package/dist/esm/entity.js +49 -0
- package/dist/esm/entity.js.map +1 -1
- package/dist/esm/index.d.ts +1 -4
- package/dist/esm/index.js +1 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/persistent-unit.d.ts +1 -1
- package/dist/esm/persistent-unit.js +1 -1
- package/dist/esm/persistent-unit.js.map +1 -1
- package/dist/esm/procedure.d.ts +1 -1
- package/dist/esm/procedure.js +1 -1
- package/dist/esm/procedure.js.map +1 -1
- package/dist/esm/repository.d.ts +1 -1
- package/dist/esm/repository.js +1 -1
- package/dist/esm/repository.js.map +1 -1
- package/dist/esm/types.d.ts +21 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +3 -3
- package/dist/esm/entity-link.d.ts +0 -9
- package/dist/esm/entity-link.js +0 -7
- package/dist/esm/entity-link.js.map +0 -1
- package/dist/esm/entity-sync.d.ts +0 -14
- package/dist/esm/entity-sync.js +0 -38
- package/dist/esm/entity-sync.js.map +0 -1
- package/dist/esm/entity-update.d.ts +0 -9
- package/dist/esm/entity-update.js +0 -8
- package/dist/esm/entity-update.js.map +0 -1
- package/dist/esm/model.d.ts +0 -13
- package/dist/esm/model.js +0 -2
- package/dist/esm/model.js.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class AbstractEntityDatabase {
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
class
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class EntityLink {
|
|
12
|
-
constructor(entity, bindable = true) {
|
|
13
|
-
this.entity = entity;
|
|
14
|
-
this.bindable = bindable;
|
|
15
|
-
}
|
|
8
|
+
class AbstractEntityDataSource {
|
|
16
9
|
}
|
|
17
10
|
|
|
18
11
|
function itIsDefined(object) {
|
|
@@ -76,9 +69,12 @@ function fromPromise(value) {
|
|
|
76
69
|
return value instanceof Promise ? value : Promise.resolve(value);
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
|
|
72
|
+
function modelIsHidden(model) {
|
|
73
|
+
return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
|
|
74
|
+
}
|
|
75
|
+
class AbstractEntityManager {
|
|
80
76
|
}
|
|
81
|
-
class
|
|
77
|
+
class EntityManager {
|
|
82
78
|
constructor(source) {
|
|
83
79
|
this.source = source;
|
|
84
80
|
this.links = [];
|
|
@@ -108,7 +104,9 @@ class RolsterEntityManager {
|
|
|
108
104
|
}
|
|
109
105
|
destroy(entity) {
|
|
110
106
|
this.select(entity).present((model) => {
|
|
111
|
-
|
|
107
|
+
modelIsHidden(model)
|
|
108
|
+
? this.hiddens.push(model)
|
|
109
|
+
: this.destroys.push(model);
|
|
112
110
|
});
|
|
113
111
|
}
|
|
114
112
|
procedure(procedure) {
|
|
@@ -144,7 +142,7 @@ class RolsterEntityManager {
|
|
|
144
142
|
}
|
|
145
143
|
persistAll() {
|
|
146
144
|
const { links, source } = this;
|
|
147
|
-
return Promise.all(links.map((link) => fromPromise(link.
|
|
145
|
+
return Promise.all(links.map((link) => fromPromise(link.create(this)).then((model) => {
|
|
148
146
|
const { bindable, entity } = link;
|
|
149
147
|
if (bindable) {
|
|
150
148
|
this.relation(entity, model);
|
|
@@ -164,11 +162,11 @@ class RolsterEntityManager {
|
|
|
164
162
|
const dirty = sync.verify();
|
|
165
163
|
if (dirty) {
|
|
166
164
|
const { model } = sync;
|
|
167
|
-
syncs.push(
|
|
165
|
+
syncs.push([model, dirty]);
|
|
168
166
|
}
|
|
169
167
|
return syncs;
|
|
170
168
|
}, [])
|
|
171
|
-
.map((
|
|
169
|
+
.map(([model, dirty]) => source.update(model, dirty)));
|
|
172
170
|
}
|
|
173
171
|
destroyAll() {
|
|
174
172
|
const { destroys, source } = this;
|
|
@@ -182,23 +180,41 @@ class RolsterEntityManager {
|
|
|
182
180
|
const { procedures, source } = this;
|
|
183
181
|
return Promise.all(procedures.map((procedure) => source.procedure(procedure)));
|
|
184
182
|
}
|
|
185
|
-
}
|
|
186
|
-
function isHidden(model) {
|
|
187
|
-
return 'hidden' in model && 'hiddenAt' in model;
|
|
188
183
|
}
|
|
189
184
|
|
|
185
|
+
function modelIsEditable(model) {
|
|
186
|
+
return typeof model === 'object' && 'updatedAt' in model;
|
|
187
|
+
}
|
|
188
|
+
class Entity {
|
|
189
|
+
constructor(uuid) {
|
|
190
|
+
this.uuid = uuid;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
class EntityUpdate {
|
|
194
|
+
constructor(entity, model, bindable = true) {
|
|
195
|
+
this.entity = entity;
|
|
196
|
+
this.model = model;
|
|
197
|
+
this.bindable = bindable;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
class EntityLink {
|
|
201
|
+
constructor(entity, bindable = true) {
|
|
202
|
+
this.entity = entity;
|
|
203
|
+
this.bindable = bindable;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
190
206
|
class EntitySync {
|
|
191
207
|
constructor(entity, model, bindable = true) {
|
|
192
208
|
this.entity = entity;
|
|
193
209
|
this.model = model;
|
|
194
210
|
this.bindable = bindable;
|
|
195
|
-
this.
|
|
211
|
+
this.firstDirty = this.createDirtyFromModel(model);
|
|
196
212
|
}
|
|
197
213
|
verify() {
|
|
198
214
|
this.sync();
|
|
199
215
|
return this.createDirty();
|
|
200
216
|
}
|
|
201
|
-
|
|
217
|
+
createDirtyFromModel(model) {
|
|
202
218
|
const dirty = {};
|
|
203
219
|
Object.keys(model).forEach((key) => {
|
|
204
220
|
dirty[key] = model[key];
|
|
@@ -206,57 +222,39 @@ class EntitySync {
|
|
|
206
222
|
return dirty;
|
|
207
223
|
}
|
|
208
224
|
createDirty() {
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
dirty = true;
|
|
215
|
-
modelDirty[key] = currentStatus[key];
|
|
225
|
+
const currentDirty = this.createDirtyFromModel(this.model);
|
|
226
|
+
const finalDirty = {};
|
|
227
|
+
Object.keys(currentDirty).forEach((key) => {
|
|
228
|
+
if (currentDirty[key] !== this.firstDirty[key]) {
|
|
229
|
+
finalDirty[key] = currentDirty[key];
|
|
216
230
|
}
|
|
217
231
|
});
|
|
218
|
-
|
|
219
|
-
|
|
232
|
+
const requiredUpdate = Object.keys(finalDirty).length > 0;
|
|
233
|
+
if (requiredUpdate && modelIsEditable(this.model)) {
|
|
234
|
+
finalDirty['updatedAt'] = new Date();
|
|
220
235
|
}
|
|
221
|
-
return
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function isUpdated(model) {
|
|
225
|
-
return 'updatedAt' in model;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
class EntityUpdate {
|
|
229
|
-
constructor(entity, model, bindable = true) {
|
|
230
|
-
this.entity = entity;
|
|
231
|
-
this.model = model;
|
|
232
|
-
this.bindable = bindable;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
class Entity {
|
|
237
|
-
constructor(uuid) {
|
|
238
|
-
this.uuid = uuid;
|
|
236
|
+
return requiredUpdate ? finalDirty : undefined;
|
|
239
237
|
}
|
|
240
238
|
}
|
|
241
239
|
|
|
242
|
-
class
|
|
240
|
+
class AbstractPersistentUnit {
|
|
243
241
|
}
|
|
244
242
|
|
|
245
|
-
class
|
|
243
|
+
class AbstractProcedure {
|
|
246
244
|
}
|
|
247
245
|
|
|
248
|
-
class
|
|
246
|
+
class AbstractRepository {
|
|
249
247
|
}
|
|
250
248
|
|
|
249
|
+
exports.AbstractEntityDataSource = AbstractEntityDataSource;
|
|
250
|
+
exports.AbstractEntityDatabase = AbstractEntityDatabase;
|
|
251
|
+
exports.AbstractEntityManager = AbstractEntityManager;
|
|
252
|
+
exports.AbstractPersistentUnit = AbstractPersistentUnit;
|
|
253
|
+
exports.AbstractProcedure = AbstractProcedure;
|
|
254
|
+
exports.AbstractRepository = AbstractRepository;
|
|
251
255
|
exports.Entity = Entity;
|
|
252
|
-
exports.EntityDataSource = EntityDataSource;
|
|
253
|
-
exports.EntityDatabase = EntityDatabase;
|
|
254
256
|
exports.EntityLink = EntityLink;
|
|
255
257
|
exports.EntityManager = EntityManager;
|
|
256
258
|
exports.EntitySync = EntitySync;
|
|
257
259
|
exports.EntityUpdate = EntityUpdate;
|
|
258
|
-
exports.PersistentUnit = PersistentUnit;
|
|
259
|
-
exports.Procedure = Procedure;
|
|
260
|
-
exports.Repository = Repository;
|
|
261
|
-
exports.RolsterEntityManager = RolsterEntityManager;
|
|
262
260
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../esm/entity-link.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-sync.js","../esm/entity-update.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js"],"sourcesContent":["export class EntityDatabase {\r\n}\r\n//# sourceMappingURL=database.js.map","export class EntityDataSource {\r\n}\r\n//# sourceMappingURL=datasource.js.map","export class EntityLink {\r\n constructor(entity, bindable = true) {\r\n this.entity = entity;\r\n this.bindable = bindable;\r\n }\r\n}\r\n//# sourceMappingURL=entity-link.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\r\nconst SLICE_SIZE = 512;\r\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\r\nconst prototypeToString = Object.prototype.toString;\r\nfunction clone(object, caches) {\r\n if (typeof object !== 'object') {\r\n return object;\r\n }\r\n if (prototypeToString.call(object) === '[object Object]') {\r\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\r\n /* istanbul ignore if */\r\n if (cacheObject) {\r\n return cacheObject;\r\n }\r\n caches.push(object);\r\n }\r\n const prototypeObject = Object.getPrototypeOf(object);\r\n const ConstructorObject = prototypeObject.constructor;\r\n if (PRIMITIVES.includes(ConstructorObject)) {\r\n return new ConstructorObject(object);\r\n }\r\n const cloneObject = new ConstructorObject();\r\n for (const prop in object) {\r\n cloneObject[prop] = clone(object[prop], caches);\r\n }\r\n return cloneObject;\r\n}\r\nexport function itIsDefined(object) {\r\n return typeof object !== 'undefined' && object !== null;\r\n}\r\nexport function itIsUndefined(object) {\r\n return !itIsDefined(object);\r\n}\r\nexport function parseBoolean(value) {\r\n return !(itIsUndefined(value) ||\r\n value === false ||\r\n FALSY_VALUE.includes(value));\r\n}\r\nexport function parse(value) {\r\n try {\r\n return JSON.parse(value);\r\n }\r\n catch {\r\n return value;\r\n }\r\n}\r\nexport function evalValueOrFunction(value) {\r\n return typeof value === 'function' ? value() : value;\r\n}\r\nexport function deepClone(object) {\r\n return clone(object, []);\r\n}\r\nexport function deepFreeze(object) {\r\n for (const prop in object) {\r\n const value = object[prop];\r\n if (typeof value === 'object' && !Object.isFrozen(value)) {\r\n deepFreeze(value);\r\n }\r\n }\r\n return Object.freeze(object);\r\n}\r\nexport function callback(call, ...args) {\r\n return typeof call !== 'function' ? undefined : call.apply(call, args);\r\n}\r\n/* istanbul ignore next */\r\nexport function base64ToBlob(data64, mimeType) {\r\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\r\n const byteCharacters = window.atob(result64);\r\n const byteArrays = [];\r\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\r\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\r\n const byteNumbers = new Array(slice.length);\r\n for (let i = 0; i < slice.length; i++) {\r\n byteNumbers[i] = slice.charCodeAt(i);\r\n }\r\n const byteArray = new Uint8Array(byteNumbers);\r\n byteArrays.push(byteArray);\r\n }\r\n return new Blob(byteArrays, { type: mimeType });\r\n}\r\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\r\nexport class Optional {\r\n constructor(value) {\r\n this.value = value;\r\n }\r\n present(callback) {\r\n return this.isPresent() ? callback(this.get()) : undefined;\r\n }\r\n empty(callback) {\r\n return this.isEmpty() ? callback() : undefined;\r\n }\r\n when(present, empty) {\r\n return this.isPresent() ? present(this.get()) : empty();\r\n }\r\n static build(value) {\r\n return itIsDefined(value) ? this.of(value) : this.empty();\r\n }\r\n static of(value) {\r\n if (itIsDefined(value)) {\r\n return new PresentOptional(value);\r\n }\r\n throw new Error('The passed value was null or undefined.');\r\n }\r\n static empty() {\r\n return new EmptyOptional();\r\n }\r\n}\r\nclass PresentOptional extends Optional {\r\n constructor(presentValue) {\r\n super(presentValue);\r\n this.presentValue = presentValue;\r\n }\r\n isPresent() {\r\n return true;\r\n }\r\n isEmpty() {\r\n return false;\r\n }\r\n get() {\r\n return this.presentValue;\r\n }\r\n}\r\nclass EmptyOptional extends Optional {\r\n isPresent() {\r\n return false;\r\n }\r\n isEmpty() {\r\n return true;\r\n }\r\n get() {\r\n throw new Error('The optional is not present.');\r\n }\r\n}\r\n//# sourceMappingURL=optional.js.map","function resolvePromises(props) {\r\n const { error, index, promises, result, success } = props;\r\n if (index === promises.length) {\r\n return success(result);\r\n }\r\n const callback = promises[index];\r\n new Promise(() => {\r\n callback()\r\n .then((value) => resolvePromises({\r\n ...props,\r\n index: index + 1,\r\n result: [...result, value]\r\n }))\r\n .catch((err) => error(err));\r\n });\r\n}\r\nexport function fromPromise(value) {\r\n return value instanceof Promise ? value : Promise.resolve(value);\r\n}\r\nexport function zipPromise(promises) {\r\n return promises.length\r\n ? new Promise((resolve, reject) => {\r\n resolvePromises({\r\n error: (err) => {\r\n reject(err);\r\n },\r\n index: 0,\r\n result: [],\r\n promises,\r\n success: (result) => {\r\n resolve(result);\r\n }\r\n });\r\n })\r\n : Promise.resolve([]);\r\n}\r\nexport function thenPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n throw err;\r\n });\r\n}\r\nexport function voidPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\nexport function catchPromise(promise, printError = false) {\r\n return promise.catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\r\nexport class EntityManager {\r\n}\r\nexport class RolsterEntityManager {\r\n constructor(source) {\r\n this.source = source;\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n this.relations = new Map();\r\n }\r\n persist(link) {\r\n this.links.push(link);\r\n }\r\n update(update) {\r\n const { bindable, entity, model } = update;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.updates.push(update);\r\n }\r\n sync(sync) {\r\n const { bindable, entity, model } = sync;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.syncs.push(sync);\r\n }\r\n destroy(entity) {\r\n this.select(entity).present((model) => {\r\n isHidden(model) ? this.hiddens.push(model) : this.destroys.push(model);\r\n });\r\n }\r\n procedure(procedure) {\r\n this.procedures.push(procedure);\r\n }\r\n relation({ uuid }, model) {\r\n this.relations.set(uuid, model);\r\n }\r\n link(entity, model) {\r\n this.relation(entity, model);\r\n return entity;\r\n }\r\n select({ uuid }) {\r\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\r\n }\r\n async flush() {\r\n await this.persistAll();\r\n await this.updateAll();\r\n await this.syncAll();\r\n await this.hiddenAll();\r\n await this.destroyAll();\r\n await this.procedureAll();\r\n this.dispose();\r\n }\r\n dispose() {\r\n this.relations.clear();\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n }\r\n persistAll() {\r\n const { links, source } = this;\r\n return Promise.all(links.map((link) => fromPromise(link.createModel(this)).then((model) => {\r\n const { bindable, entity } = link;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n return source.insert(model);\r\n })));\r\n }\r\n updateAll() {\r\n const { source, updates } = this;\r\n return Promise.all(updates.map(({ model }) => source.update(model)));\r\n }\r\n syncAll() {\r\n const { destroys, source, syncs } = this;\r\n return Promise.all(syncs\r\n .filter(({ model }) => !destroys.includes(model))\r\n .reduce((syncs, sync) => {\r\n const dirty = sync.verify();\r\n if (dirty) {\r\n const { model } = sync;\r\n syncs.push({ model, dirty });\r\n }\r\n return syncs;\r\n }, [])\r\n .map(({ model, dirty }) => source.update(model, dirty)));\r\n }\r\n destroyAll() {\r\n const { destroys, source } = this;\r\n return Promise.all(destroys.map((destroy) => source.delete(destroy)));\r\n }\r\n hiddenAll() {\r\n const { hiddens, source } = this;\r\n return Promise.all(hiddens.map((hidden) => source.hidden(hidden)));\r\n }\r\n procedureAll() {\r\n const { procedures, source } = this;\r\n return Promise.all(procedures.map((procedure) => source.procedure(procedure)));\r\n }\r\n}\r\nfunction isHidden(model) {\r\n return 'hidden' in model && 'hiddenAt' in model;\r\n}\r\n//# sourceMappingURL=entity-manager.js.map","export class EntitySync {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n this.firstStatus = this.mapperModel(model);\r\n }\r\n verify() {\r\n this.sync();\r\n return this.createDirty();\r\n }\r\n mapperModel(model) {\r\n const dirty = {};\r\n Object.keys(model).forEach((key) => {\r\n dirty[key] = model[key];\r\n });\r\n return dirty;\r\n }\r\n createDirty() {\r\n const currentStatus = this.mapperModel(this.model);\r\n const modelDirty = {};\r\n let dirty = false;\r\n Object.keys(currentStatus).forEach((key) => {\r\n if (currentStatus[key] !== this.firstStatus[key]) {\r\n dirty = true;\r\n modelDirty[key] = currentStatus[key];\r\n }\r\n });\r\n if (isUpdated(this.model)) {\r\n modelDirty['updatedAt'] = new Date();\r\n }\r\n return dirty ? modelDirty : undefined;\r\n }\r\n}\r\nfunction isUpdated(model) {\r\n return 'updatedAt' in model;\r\n}\r\n//# sourceMappingURL=entity-sync.js.map","export class EntityUpdate {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n }\r\n}\r\n//# sourceMappingURL=entity-update.js.map","export class Entity {\r\n constructor(uuid) {\r\n this.uuid = uuid;\r\n }\r\n}\r\n//# sourceMappingURL=entity.js.map","export class PersistentUnit {\r\n}\r\n//# sourceMappingURL=persistent-unit.js.map","export class Procedure {\r\n}\r\n//# sourceMappingURL=procedure.js.map","export class Repository {\r\n}\r\n//# sourceMappingURL=repository.js.map"],"names":[],"mappings":";;;;AAAO,MAAM,cAAc,CAAC;AAC5B;;ACDO,MAAM,gBAAgB,CAAC;AAC9B;;ACDO,MAAM,UAAU,CAAC;AACxB,IAAI,WAAW,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,EAAE;AACzC,QAAQ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;AAC7B,QAAQ,IAAI,CAAC,QAAQ,GAAG,QAAQ,C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AAC;AAC7B,gBAAgB,UAAU,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AACrD,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AACnC,YAAY,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACjD,SAAS;AACT,QAAQ,OAAO,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AAC9C,KAAK;AACL,CAAC;AACD,SAAS,SAAS,CAAC,KAAK,EAAE;AAC1B,IAAI,OAAO,WAAW,IAAI,KAAK,CAAC;AAChC;;ACpCO,MAAM,YAAY,CAAC;AAC1B,IAAI,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE;AAChD,QAAQ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;AAC7B,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,QAAQ,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,KAAK;AACL;;ACNO,MAAM,MAAM,CAAC;AACpB,IAAI,WAAW,CAAC,IAAI,EAAE;AACtB,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACzB,KAAK;AACL;;ACJO,MAAM,cAAc,CAAC;AAC5B;;ACDO,MAAM,SAAS,CAAC;AACvB;;ACDO,MAAM,UAAU,CAAC;AACxB;;;;;;;;;;;;;;"}
|
|
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 {\r\n}\r\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\r\n}\r\n//# sourceMappingURL=datasource.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\r\nconst SLICE_SIZE = 512;\r\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\r\nconst prototypeToString = Object.prototype.toString;\r\nfunction clone(object, caches) {\r\n if (typeof object !== 'object') {\r\n return object;\r\n }\r\n if (prototypeToString.call(object) === '[object Object]') {\r\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\r\n /* istanbul ignore if */\r\n if (cacheObject) {\r\n return cacheObject;\r\n }\r\n caches.push(object);\r\n }\r\n const prototypeObject = Object.getPrototypeOf(object);\r\n const ConstructorObject = prototypeObject.constructor;\r\n if (PRIMITIVES.includes(ConstructorObject)) {\r\n return new ConstructorObject(object);\r\n }\r\n const cloneObject = new ConstructorObject();\r\n for (const prop in object) {\r\n cloneObject[prop] = clone(object[prop], caches);\r\n }\r\n return cloneObject;\r\n}\r\nexport function itIsDefined(object) {\r\n return typeof object !== 'undefined' && object !== null;\r\n}\r\nexport function itIsUndefined(object) {\r\n return !itIsDefined(object);\r\n}\r\nexport function parseBoolean(value) {\r\n return !(itIsUndefined(value) ||\r\n value === false ||\r\n FALSY_VALUE.includes(value));\r\n}\r\nexport function parse(value) {\r\n try {\r\n return JSON.parse(value);\r\n }\r\n catch {\r\n return value;\r\n }\r\n}\r\nexport function evalValueOrFunction(value) {\r\n return typeof value === 'function' ? value() : value;\r\n}\r\nexport function deepClone(object) {\r\n return clone(object, []);\r\n}\r\nexport function deepFreeze(object) {\r\n for (const prop in object) {\r\n const value = object[prop];\r\n if (typeof value === 'object' && !Object.isFrozen(value)) {\r\n deepFreeze(value);\r\n }\r\n }\r\n return Object.freeze(object);\r\n}\r\nexport function callback(call, ...args) {\r\n return typeof call !== 'function' ? undefined : call.apply(call, args);\r\n}\r\n/* istanbul ignore next */\r\nexport function base64ToBlob(data64, mimeType) {\r\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\r\n const byteCharacters = window.atob(result64);\r\n const byteArrays = [];\r\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\r\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\r\n const byteNumbers = new Array(slice.length);\r\n for (let i = 0; i < slice.length; i++) {\r\n byteNumbers[i] = slice.charCodeAt(i);\r\n }\r\n const byteArray = new Uint8Array(byteNumbers);\r\n byteArrays.push(byteArray);\r\n }\r\n return new Blob(byteArrays, { type: mimeType });\r\n}\r\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\r\nexport class Optional {\r\n constructor(value) {\r\n this.value = value;\r\n }\r\n present(callback) {\r\n return this.isPresent() ? callback(this.get()) : undefined;\r\n }\r\n empty(callback) {\r\n return this.isEmpty() ? callback() : undefined;\r\n }\r\n when(present, empty) {\r\n return this.isPresent() ? present(this.get()) : empty();\r\n }\r\n static build(value) {\r\n return itIsDefined(value) ? this.of(value) : this.empty();\r\n }\r\n static of(value) {\r\n if (itIsDefined(value)) {\r\n return new PresentOptional(value);\r\n }\r\n throw new Error('The passed value was null or undefined.');\r\n }\r\n static empty() {\r\n return new EmptyOptional();\r\n }\r\n}\r\nclass PresentOptional extends Optional {\r\n constructor(presentValue) {\r\n super(presentValue);\r\n this.presentValue = presentValue;\r\n }\r\n isPresent() {\r\n return true;\r\n }\r\n isEmpty() {\r\n return false;\r\n }\r\n get() {\r\n return this.presentValue;\r\n }\r\n}\r\nclass EmptyOptional extends Optional {\r\n isPresent() {\r\n return false;\r\n }\r\n isEmpty() {\r\n return true;\r\n }\r\n get() {\r\n throw new Error('The optional is not present.');\r\n }\r\n}\r\n//# sourceMappingURL=optional.js.map","import { itIsDefined } from './helpers';\r\nexport function fromPromise(value) {\r\n return value instanceof Promise ? value : Promise.resolve(value);\r\n}\r\nexport function thenPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n throw err;\r\n });\r\n}\r\nexport function voidPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\nexport function catchPromise(promise, printError = false) {\r\n return promise.catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\nfunction zipResolveCallbacks(options) {\r\n const { callbacks, catchError, index, resolve, result } = options;\r\n if (index === callbacks.length) {\r\n return resolve(result);\r\n }\r\n new Promise(() => {\r\n callbacks[index]()\r\n .then((value) => {\r\n result.push(value);\r\n return zipResolveCallbacks({\r\n ...options,\r\n index: index + 1,\r\n result\r\n });\r\n })\r\n .catch((err) => {\r\n return catchError(err);\r\n });\r\n });\r\n}\r\nexport function zipPromise(callbacks) {\r\n const result = [];\r\n return new Promise((resolve, reject) => {\r\n zipResolveCallbacks({\r\n callbacks,\r\n catchError: (err) => {\r\n reject(err);\r\n },\r\n index: 0,\r\n resolve: (result) => {\r\n resolve(result);\r\n },\r\n result\r\n });\r\n });\r\n}\r\nexport function securePromise(callback, catchError) {\r\n let promise$ = undefined;\r\n function itIsInstanced() {\r\n return itIsDefined(promise$);\r\n }\r\n function resolve() {\r\n if (!promise$) {\r\n promise$ = callback().catch((err) => {\r\n const errorValue = catchError && catchError(err);\r\n reset();\r\n if (errorValue) {\r\n return errorValue;\r\n }\r\n throw err;\r\n });\r\n }\r\n return promise$;\r\n }\r\n function reset() {\r\n promise$ = undefined;\r\n }\r\n return { itIsInstanced, reset, resolve };\r\n}\r\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\r\nfunction modelIsHidden(model) {\r\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\r\n}\r\nexport class AbstractEntityManager {\r\n}\r\nexport class EntityManager {\r\n constructor(source) {\r\n this.source = source;\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n this.relations = new Map();\r\n }\r\n persist(link) {\r\n this.links.push(link);\r\n }\r\n update(update) {\r\n const { bindable, entity, model } = update;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.updates.push(update);\r\n }\r\n sync(sync) {\r\n const { bindable, entity, model } = sync;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.syncs.push(sync);\r\n }\r\n destroy(entity) {\r\n this.select(entity).present((model) => {\r\n modelIsHidden(model)\r\n ? this.hiddens.push(model)\r\n : this.destroys.push(model);\r\n });\r\n }\r\n procedure(procedure) {\r\n this.procedures.push(procedure);\r\n }\r\n relation({ uuid }, model) {\r\n this.relations.set(uuid, model);\r\n }\r\n link(entity, model) {\r\n this.relation(entity, model);\r\n return entity;\r\n }\r\n select({ uuid }) {\r\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\r\n }\r\n async flush() {\r\n await this.persistAll();\r\n await this.updateAll();\r\n await this.syncAll();\r\n await this.hiddenAll();\r\n await this.destroyAll();\r\n await this.procedureAll();\r\n this.dispose();\r\n }\r\n dispose() {\r\n this.relations.clear();\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n }\r\n persistAll() {\r\n const { links, source } = this;\r\n return Promise.all(links.map((link) => fromPromise(link.create(this)).then((model) => {\r\n const { bindable, entity } = link;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n return source.insert(model);\r\n })));\r\n }\r\n updateAll() {\r\n const { source, updates } = this;\r\n return Promise.all(updates.map(({ model }) => source.update(model)));\r\n }\r\n syncAll() {\r\n const { destroys, source, syncs } = this;\r\n return Promise.all(syncs\r\n .filter(({ model }) => !destroys.includes(model))\r\n .reduce((syncs, sync) => {\r\n const dirty = sync.verify();\r\n if (dirty) {\r\n const { model } = sync;\r\n syncs.push([model, dirty]);\r\n }\r\n return syncs;\r\n }, [])\r\n .map(([model, dirty]) => source.update(model, dirty)));\r\n }\r\n destroyAll() {\r\n const { destroys, source } = this;\r\n return Promise.all(destroys.map((destroy) => source.delete(destroy)));\r\n }\r\n hiddenAll() {\r\n const { hiddens, source } = this;\r\n return Promise.all(hiddens.map((hidden) => source.hidden(hidden)));\r\n }\r\n procedureAll() {\r\n const { procedures, source } = this;\r\n return Promise.all(procedures.map((procedure) => source.procedure(procedure)));\r\n }\r\n}\r\n//# sourceMappingURL=entity-manager.js.map","function modelIsEditable(model) {\r\n return typeof model === 'object' && 'updatedAt' in model;\r\n}\r\nexport class Entity {\r\n constructor(uuid) {\r\n this.uuid = uuid;\r\n }\r\n}\r\nexport class EntityUpdate {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n }\r\n}\r\nexport class EntityLink {\r\n constructor(entity, bindable = true) {\r\n this.entity = entity;\r\n this.bindable = bindable;\r\n }\r\n}\r\nexport class EntitySync {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n this.firstDirty = this.createDirtyFromModel(model);\r\n }\r\n verify() {\r\n this.sync();\r\n return this.createDirty();\r\n }\r\n createDirtyFromModel(model) {\r\n const dirty = {};\r\n Object.keys(model).forEach((key) => {\r\n dirty[key] = model[key];\r\n });\r\n return dirty;\r\n }\r\n createDirty() {\r\n const currentDirty = this.createDirtyFromModel(this.model);\r\n const finalDirty = {};\r\n Object.keys(currentDirty).forEach((key) => {\r\n if (currentDirty[key] !== this.firstDirty[key]) {\r\n finalDirty[key] = currentDirty[key];\r\n }\r\n });\r\n const requiredUpdate = Object.keys(finalDirty).length > 0;\r\n if (requiredUpdate && modelIsEditable(this.model)) {\r\n finalDirty['updatedAt'] = new Date();\r\n }\r\n return requiredUpdate ? finalDirty : undefined;\r\n }\r\n}\r\n//# sourceMappingURL=entity.js.map","export class AbstractPersistentUnit {\r\n}\r\n//# sourceMappingURL=persistent-unit.js.map","export class AbstractProcedure {\r\n}\r\n//# sourceMappingURL=procedure.js.map","export class AbstractRepository {\r\n}\r\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,WAAW,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;AAClE,KAAK;AACL,IAAI,OAAO,EAAE,CAAC,KAAK,EAAE;AACrB,QAAQ,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;AAChC,YAAY,OAAO,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;AAC9C,SAAS;AACT,QAAQ,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ACT,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;;;;;;;;;;;;;;"}
|
package/dist/es/index.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
class
|
|
1
|
+
class AbstractEntityDatabase {
|
|
2
2
|
}
|
|
3
3
|
|
|
4
|
-
class
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
class EntityLink {
|
|
8
|
-
constructor(entity, bindable = true) {
|
|
9
|
-
this.entity = entity;
|
|
10
|
-
this.bindable = bindable;
|
|
11
|
-
}
|
|
4
|
+
class AbstractEntityDataSource {
|
|
12
5
|
}
|
|
13
6
|
|
|
14
7
|
function itIsDefined(object) {
|
|
@@ -72,9 +65,12 @@ function fromPromise(value) {
|
|
|
72
65
|
return value instanceof Promise ? value : Promise.resolve(value);
|
|
73
66
|
}
|
|
74
67
|
|
|
75
|
-
|
|
68
|
+
function modelIsHidden(model) {
|
|
69
|
+
return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
|
|
70
|
+
}
|
|
71
|
+
class AbstractEntityManager {
|
|
76
72
|
}
|
|
77
|
-
class
|
|
73
|
+
class EntityManager {
|
|
78
74
|
constructor(source) {
|
|
79
75
|
this.source = source;
|
|
80
76
|
this.links = [];
|
|
@@ -104,7 +100,9 @@ class RolsterEntityManager {
|
|
|
104
100
|
}
|
|
105
101
|
destroy(entity) {
|
|
106
102
|
this.select(entity).present((model) => {
|
|
107
|
-
|
|
103
|
+
modelIsHidden(model)
|
|
104
|
+
? this.hiddens.push(model)
|
|
105
|
+
: this.destroys.push(model);
|
|
108
106
|
});
|
|
109
107
|
}
|
|
110
108
|
procedure(procedure) {
|
|
@@ -140,7 +138,7 @@ class RolsterEntityManager {
|
|
|
140
138
|
}
|
|
141
139
|
persistAll() {
|
|
142
140
|
const { links, source } = this;
|
|
143
|
-
return Promise.all(links.map((link) => fromPromise(link.
|
|
141
|
+
return Promise.all(links.map((link) => fromPromise(link.create(this)).then((model) => {
|
|
144
142
|
const { bindable, entity } = link;
|
|
145
143
|
if (bindable) {
|
|
146
144
|
this.relation(entity, model);
|
|
@@ -160,11 +158,11 @@ class RolsterEntityManager {
|
|
|
160
158
|
const dirty = sync.verify();
|
|
161
159
|
if (dirty) {
|
|
162
160
|
const { model } = sync;
|
|
163
|
-
syncs.push(
|
|
161
|
+
syncs.push([model, dirty]);
|
|
164
162
|
}
|
|
165
163
|
return syncs;
|
|
166
164
|
}, [])
|
|
167
|
-
.map((
|
|
165
|
+
.map(([model, dirty]) => source.update(model, dirty)));
|
|
168
166
|
}
|
|
169
167
|
destroyAll() {
|
|
170
168
|
const { destroys, source } = this;
|
|
@@ -178,23 +176,41 @@ class RolsterEntityManager {
|
|
|
178
176
|
const { procedures, source } = this;
|
|
179
177
|
return Promise.all(procedures.map((procedure) => source.procedure(procedure)));
|
|
180
178
|
}
|
|
181
|
-
}
|
|
182
|
-
function isHidden(model) {
|
|
183
|
-
return 'hidden' in model && 'hiddenAt' in model;
|
|
184
179
|
}
|
|
185
180
|
|
|
181
|
+
function modelIsEditable(model) {
|
|
182
|
+
return typeof model === 'object' && 'updatedAt' in model;
|
|
183
|
+
}
|
|
184
|
+
class Entity {
|
|
185
|
+
constructor(uuid) {
|
|
186
|
+
this.uuid = uuid;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
class EntityUpdate {
|
|
190
|
+
constructor(entity, model, bindable = true) {
|
|
191
|
+
this.entity = entity;
|
|
192
|
+
this.model = model;
|
|
193
|
+
this.bindable = bindable;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
class EntityLink {
|
|
197
|
+
constructor(entity, bindable = true) {
|
|
198
|
+
this.entity = entity;
|
|
199
|
+
this.bindable = bindable;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
186
202
|
class EntitySync {
|
|
187
203
|
constructor(entity, model, bindable = true) {
|
|
188
204
|
this.entity = entity;
|
|
189
205
|
this.model = model;
|
|
190
206
|
this.bindable = bindable;
|
|
191
|
-
this.
|
|
207
|
+
this.firstDirty = this.createDirtyFromModel(model);
|
|
192
208
|
}
|
|
193
209
|
verify() {
|
|
194
210
|
this.sync();
|
|
195
211
|
return this.createDirty();
|
|
196
212
|
}
|
|
197
|
-
|
|
213
|
+
createDirtyFromModel(model) {
|
|
198
214
|
const dirty = {};
|
|
199
215
|
Object.keys(model).forEach((key) => {
|
|
200
216
|
dirty[key] = model[key];
|
|
@@ -202,47 +218,29 @@ class EntitySync {
|
|
|
202
218
|
return dirty;
|
|
203
219
|
}
|
|
204
220
|
createDirty() {
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
dirty = true;
|
|
211
|
-
modelDirty[key] = currentStatus[key];
|
|
221
|
+
const currentDirty = this.createDirtyFromModel(this.model);
|
|
222
|
+
const finalDirty = {};
|
|
223
|
+
Object.keys(currentDirty).forEach((key) => {
|
|
224
|
+
if (currentDirty[key] !== this.firstDirty[key]) {
|
|
225
|
+
finalDirty[key] = currentDirty[key];
|
|
212
226
|
}
|
|
213
227
|
});
|
|
214
|
-
|
|
215
|
-
|
|
228
|
+
const requiredUpdate = Object.keys(finalDirty).length > 0;
|
|
229
|
+
if (requiredUpdate && modelIsEditable(this.model)) {
|
|
230
|
+
finalDirty['updatedAt'] = new Date();
|
|
216
231
|
}
|
|
217
|
-
return
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function isUpdated(model) {
|
|
221
|
-
return 'updatedAt' in model;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
class EntityUpdate {
|
|
225
|
-
constructor(entity, model, bindable = true) {
|
|
226
|
-
this.entity = entity;
|
|
227
|
-
this.model = model;
|
|
228
|
-
this.bindable = bindable;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
class Entity {
|
|
233
|
-
constructor(uuid) {
|
|
234
|
-
this.uuid = uuid;
|
|
232
|
+
return requiredUpdate ? finalDirty : undefined;
|
|
235
233
|
}
|
|
236
234
|
}
|
|
237
235
|
|
|
238
|
-
class
|
|
236
|
+
class AbstractPersistentUnit {
|
|
239
237
|
}
|
|
240
238
|
|
|
241
|
-
class
|
|
239
|
+
class AbstractProcedure {
|
|
242
240
|
}
|
|
243
241
|
|
|
244
|
-
class
|
|
242
|
+
class AbstractRepository {
|
|
245
243
|
}
|
|
246
244
|
|
|
247
|
-
export {
|
|
245
|
+
export { AbstractEntityDataSource, AbstractEntityDatabase, AbstractEntityManager, AbstractPersistentUnit, AbstractProcedure, AbstractRepository, Entity, EntityLink, EntityManager, EntitySync, EntityUpdate };
|
|
248
246
|
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../esm/entity-link.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-sync.js","../esm/entity-update.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js"],"sourcesContent":["export class EntityDatabase {\r\n}\r\n//# sourceMappingURL=database.js.map","export class EntityDataSource {\r\n}\r\n//# sourceMappingURL=datasource.js.map","export class EntityLink {\r\n constructor(entity, bindable = true) {\r\n this.entity = entity;\r\n this.bindable = bindable;\r\n }\r\n}\r\n//# sourceMappingURL=entity-link.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\r\nconst SLICE_SIZE = 512;\r\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\r\nconst prototypeToString = Object.prototype.toString;\r\nfunction clone(object, caches) {\r\n if (typeof object !== 'object') {\r\n return object;\r\n }\r\n if (prototypeToString.call(object) === '[object Object]') {\r\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\r\n /* istanbul ignore if */\r\n if (cacheObject) {\r\n return cacheObject;\r\n }\r\n caches.push(object);\r\n }\r\n const prototypeObject = Object.getPrototypeOf(object);\r\n const ConstructorObject = prototypeObject.constructor;\r\n if (PRIMITIVES.includes(ConstructorObject)) {\r\n return new ConstructorObject(object);\r\n }\r\n const cloneObject = new ConstructorObject();\r\n for (const prop in object) {\r\n cloneObject[prop] = clone(object[prop], caches);\r\n }\r\n return cloneObject;\r\n}\r\nexport function itIsDefined(object) {\r\n return typeof object !== 'undefined' && object !== null;\r\n}\r\nexport function itIsUndefined(object) {\r\n return !itIsDefined(object);\r\n}\r\nexport function parseBoolean(value) {\r\n return !(itIsUndefined(value) ||\r\n value === false ||\r\n FALSY_VALUE.includes(value));\r\n}\r\nexport function parse(value) {\r\n try {\r\n return JSON.parse(value);\r\n }\r\n catch {\r\n return value;\r\n }\r\n}\r\nexport function evalValueOrFunction(value) {\r\n return typeof value === 'function' ? value() : value;\r\n}\r\nexport function deepClone(object) {\r\n return clone(object, []);\r\n}\r\nexport function deepFreeze(object) {\r\n for (const prop in object) {\r\n const value = object[prop];\r\n if (typeof value === 'object' && !Object.isFrozen(value)) {\r\n deepFreeze(value);\r\n }\r\n }\r\n return Object.freeze(object);\r\n}\r\nexport function callback(call, ...args) {\r\n return typeof call !== 'function' ? undefined : call.apply(call, args);\r\n}\r\n/* istanbul ignore next */\r\nexport function base64ToBlob(data64, mimeType) {\r\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\r\n const byteCharacters = window.atob(result64);\r\n const byteArrays = [];\r\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\r\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\r\n const byteNumbers = new Array(slice.length);\r\n for (let i = 0; i < slice.length; i++) {\r\n byteNumbers[i] = slice.charCodeAt(i);\r\n }\r\n const byteArray = new Uint8Array(byteNumbers);\r\n byteArrays.push(byteArray);\r\n }\r\n return new Blob(byteArrays, { type: mimeType });\r\n}\r\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\r\nexport class Optional {\r\n constructor(value) {\r\n this.value = value;\r\n }\r\n present(callback) {\r\n return this.isPresent() ? callback(this.get()) : undefined;\r\n }\r\n empty(callback) {\r\n return this.isEmpty() ? callback() : undefined;\r\n }\r\n when(present, empty) {\r\n return this.isPresent() ? present(this.get()) : empty();\r\n }\r\n static build(value) {\r\n return itIsDefined(value) ? this.of(value) : this.empty();\r\n }\r\n static of(value) {\r\n if (itIsDefined(value)) {\r\n return new PresentOptional(value);\r\n }\r\n throw new Error('The passed value was null or undefined.');\r\n }\r\n static empty() {\r\n return new EmptyOptional();\r\n }\r\n}\r\nclass PresentOptional extends Optional {\r\n constructor(presentValue) {\r\n super(presentValue);\r\n this.presentValue = presentValue;\r\n }\r\n isPresent() {\r\n return true;\r\n }\r\n isEmpty() {\r\n return false;\r\n }\r\n get() {\r\n return this.presentValue;\r\n }\r\n}\r\nclass EmptyOptional extends Optional {\r\n isPresent() {\r\n return false;\r\n }\r\n isEmpty() {\r\n return true;\r\n }\r\n get() {\r\n throw new Error('The optional is not present.');\r\n }\r\n}\r\n//# sourceMappingURL=optional.js.map","function resolvePromises(props) {\r\n const { error, index, promises, result, success } = props;\r\n if (index === promises.length) {\r\n return success(result);\r\n }\r\n const callback = promises[index];\r\n new Promise(() => {\r\n callback()\r\n .then((value) => resolvePromises({\r\n ...props,\r\n index: index + 1,\r\n result: [...result, value]\r\n }))\r\n .catch((err) => error(err));\r\n });\r\n}\r\nexport function fromPromise(value) {\r\n return value instanceof Promise ? value : Promise.resolve(value);\r\n}\r\nexport function zipPromise(promises) {\r\n return promises.length\r\n ? new Promise((resolve, reject) => {\r\n resolvePromises({\r\n error: (err) => {\r\n reject(err);\r\n },\r\n index: 0,\r\n result: [],\r\n promises,\r\n success: (result) => {\r\n resolve(result);\r\n }\r\n });\r\n })\r\n : Promise.resolve([]);\r\n}\r\nexport function thenPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n throw err;\r\n });\r\n}\r\nexport function voidPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\nexport function catchPromise(promise, printError = false) {\r\n return promise.catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\r\nexport class EntityManager {\r\n}\r\nexport class RolsterEntityManager {\r\n constructor(source) {\r\n this.source = source;\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n this.relations = new Map();\r\n }\r\n persist(link) {\r\n this.links.push(link);\r\n }\r\n update(update) {\r\n const { bindable, entity, model } = update;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.updates.push(update);\r\n }\r\n sync(sync) {\r\n const { bindable, entity, model } = sync;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.syncs.push(sync);\r\n }\r\n destroy(entity) {\r\n this.select(entity).present((model) => {\r\n isHidden(model) ? this.hiddens.push(model) : this.destroys.push(model);\r\n });\r\n }\r\n procedure(procedure) {\r\n this.procedures.push(procedure);\r\n }\r\n relation({ uuid }, model) {\r\n this.relations.set(uuid, model);\r\n }\r\n link(entity, model) {\r\n this.relation(entity, model);\r\n return entity;\r\n }\r\n select({ uuid }) {\r\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\r\n }\r\n async flush() {\r\n await this.persistAll();\r\n await this.updateAll();\r\n await this.syncAll();\r\n await this.hiddenAll();\r\n await this.destroyAll();\r\n await this.procedureAll();\r\n this.dispose();\r\n }\r\n dispose() {\r\n this.relations.clear();\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n }\r\n persistAll() {\r\n const { links, source } = this;\r\n return Promise.all(links.map((link) => fromPromise(link.createModel(this)).then((model) => {\r\n const { bindable, entity } = link;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n return source.insert(model);\r\n })));\r\n }\r\n updateAll() {\r\n const { source, updates } = this;\r\n return Promise.all(updates.map(({ model }) => source.update(model)));\r\n }\r\n syncAll() {\r\n const { destroys, source, syncs } = this;\r\n return Promise.all(syncs\r\n .filter(({ model }) => !destroys.includes(model))\r\n .reduce((syncs, sync) => {\r\n const dirty = sync.verify();\r\n if (dirty) {\r\n const { model } = sync;\r\n syncs.push({ model, dirty });\r\n }\r\n return syncs;\r\n }, [])\r\n .map(({ model, dirty }) => source.update(model, dirty)));\r\n }\r\n destroyAll() {\r\n const { destroys, source } = this;\r\n return Promise.all(destroys.map((destroy) => source.delete(destroy)));\r\n }\r\n hiddenAll() {\r\n const { hiddens, source } = this;\r\n return Promise.all(hiddens.map((hidden) => source.hidden(hidden)));\r\n }\r\n procedureAll() {\r\n const { procedures, source } = this;\r\n return Promise.all(procedures.map((procedure) => source.procedure(procedure)));\r\n }\r\n}\r\nfunction isHidden(model) {\r\n return 'hidden' in model && 'hiddenAt' in model;\r\n}\r\n//# sourceMappingURL=entity-manager.js.map","export class EntitySync {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n this.firstStatus = this.mapperModel(model);\r\n }\r\n verify() {\r\n this.sync();\r\n return this.createDirty();\r\n }\r\n mapperModel(model) {\r\n const dirty = {};\r\n Object.keys(model).forEach((key) => {\r\n dirty[key] = model[key];\r\n });\r\n return dirty;\r\n }\r\n createDirty() {\r\n const currentStatus = this.mapperModel(this.model);\r\n const modelDirty = {};\r\n let dirty = false;\r\n Object.keys(currentStatus).forEach((key) => {\r\n if (currentStatus[key] !== this.firstStatus[key]) {\r\n dirty = true;\r\n modelDirty[key] = currentStatus[key];\r\n }\r\n });\r\n if (isUpdated(this.model)) {\r\n modelDirty['updatedAt'] = new Date();\r\n }\r\n return dirty ? modelDirty : undefined;\r\n }\r\n}\r\nfunction isUpdated(model) {\r\n return 'updatedAt' in model;\r\n}\r\n//# sourceMappingURL=entity-sync.js.map","export class EntityUpdate {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n }\r\n}\r\n//# sourceMappingURL=entity-update.js.map","export class Entity {\r\n constructor(uuid) {\r\n this.uuid = uuid;\r\n }\r\n}\r\n//# sourceMappingURL=entity.js.map","export class PersistentUnit {\r\n}\r\n//# sourceMappingURL=persistent-unit.js.map","export class Procedure {\r\n}\r\n//# sourceMappingURL=procedure.js.map","export class Repository {\r\n}\r\n//# sourceMappingURL=repository.js.map"],"names":[],"mappings":"AAAO,MAAM,cAAc,CAAC;AAC5B;;ACDO,MAAM,gBAAgB,CAAC;AAC9B;;ACDO,MAAM,UAAU,CAAC;AACxB,IAAI,WAAW,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,EAAE;AACzC,QAAQ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;AAC7B,QAAQ,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,KAAK;AACL;;ACsBO,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,GA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,CAAC,KAAK,EAAE;AAC1B,IAAI,OAAO,WAAW,IAAI,KAAK,CAAC;AAChC;;ACpCO,MAAM,YAAY,CAAC;AAC1B,IAAI,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE;AAChD,QAAQ,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;AAC7B,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,QAAQ,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACjC,KAAK;AACL;;ACNO,MAAM,MAAM,CAAC;AACpB,IAAI,WAAW,CAAC,IAAI,EAAE;AACtB,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACzB,KAAK;AACL;;ACJO,MAAM,cAAc,CAAC;AAC5B;;ACDO,MAAM,SAAS,CAAC;AACvB;;ACDO,MAAM,UAAU,CAAC;AACxB;;;;"}
|
|
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 {\r\n}\r\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\r\n}\r\n//# sourceMappingURL=datasource.js.map","const PRIMITIVES = [Date, RegExp, Function, String, Boolean, Number];\r\nconst SLICE_SIZE = 512;\r\nconst FALSY_VALUE = ['false', 'undefined', '0', 0];\r\nconst prototypeToString = Object.prototype.toString;\r\nfunction clone(object, caches) {\r\n if (typeof object !== 'object') {\r\n return object;\r\n }\r\n if (prototypeToString.call(object) === '[object Object]') {\r\n const [cacheObject] = caches.filter((cacheObject) => cacheObject === object);\r\n /* istanbul ignore if */\r\n if (cacheObject) {\r\n return cacheObject;\r\n }\r\n caches.push(object);\r\n }\r\n const prototypeObject = Object.getPrototypeOf(object);\r\n const ConstructorObject = prototypeObject.constructor;\r\n if (PRIMITIVES.includes(ConstructorObject)) {\r\n return new ConstructorObject(object);\r\n }\r\n const cloneObject = new ConstructorObject();\r\n for (const prop in object) {\r\n cloneObject[prop] = clone(object[prop], caches);\r\n }\r\n return cloneObject;\r\n}\r\nexport function itIsDefined(object) {\r\n return typeof object !== 'undefined' && object !== null;\r\n}\r\nexport function itIsUndefined(object) {\r\n return !itIsDefined(object);\r\n}\r\nexport function parseBoolean(value) {\r\n return !(itIsUndefined(value) ||\r\n value === false ||\r\n FALSY_VALUE.includes(value));\r\n}\r\nexport function parse(value) {\r\n try {\r\n return JSON.parse(value);\r\n }\r\n catch {\r\n return value;\r\n }\r\n}\r\nexport function evalValueOrFunction(value) {\r\n return typeof value === 'function' ? value() : value;\r\n}\r\nexport function deepClone(object) {\r\n return clone(object, []);\r\n}\r\nexport function deepFreeze(object) {\r\n for (const prop in object) {\r\n const value = object[prop];\r\n if (typeof value === 'object' && !Object.isFrozen(value)) {\r\n deepFreeze(value);\r\n }\r\n }\r\n return Object.freeze(object);\r\n}\r\nexport function callback(call, ...args) {\r\n return typeof call !== 'function' ? undefined : call.apply(call, args);\r\n}\r\n/* istanbul ignore next */\r\nexport function base64ToBlob(data64, mimeType) {\r\n const result64 = data64.replace(/^[^,]+,/, '').replace(/\\s/g, '');\r\n const byteCharacters = window.atob(result64);\r\n const byteArrays = [];\r\n for (let offset = 0; offset < byteCharacters.length; offset += SLICE_SIZE) {\r\n const slice = byteCharacters.slice(offset, offset + SLICE_SIZE);\r\n const byteNumbers = new Array(slice.length);\r\n for (let i = 0; i < slice.length; i++) {\r\n byteNumbers[i] = slice.charCodeAt(i);\r\n }\r\n const byteArray = new Uint8Array(byteNumbers);\r\n byteArrays.push(byteArray);\r\n }\r\n return new Blob(byteArrays, { type: mimeType });\r\n}\r\n//# sourceMappingURL=helpers.js.map","import { itIsDefined } from './helpers';\r\nexport class Optional {\r\n constructor(value) {\r\n this.value = value;\r\n }\r\n present(callback) {\r\n return this.isPresent() ? callback(this.get()) : undefined;\r\n }\r\n empty(callback) {\r\n return this.isEmpty() ? callback() : undefined;\r\n }\r\n when(present, empty) {\r\n return this.isPresent() ? present(this.get()) : empty();\r\n }\r\n static build(value) {\r\n return itIsDefined(value) ? this.of(value) : this.empty();\r\n }\r\n static of(value) {\r\n if (itIsDefined(value)) {\r\n return new PresentOptional(value);\r\n }\r\n throw new Error('The passed value was null or undefined.');\r\n }\r\n static empty() {\r\n return new EmptyOptional();\r\n }\r\n}\r\nclass PresentOptional extends Optional {\r\n constructor(presentValue) {\r\n super(presentValue);\r\n this.presentValue = presentValue;\r\n }\r\n isPresent() {\r\n return true;\r\n }\r\n isEmpty() {\r\n return false;\r\n }\r\n get() {\r\n return this.presentValue;\r\n }\r\n}\r\nclass EmptyOptional extends Optional {\r\n isPresent() {\r\n return false;\r\n }\r\n isEmpty() {\r\n return true;\r\n }\r\n get() {\r\n throw new Error('The optional is not present.');\r\n }\r\n}\r\n//# sourceMappingURL=optional.js.map","import { itIsDefined } from './helpers';\r\nexport function fromPromise(value) {\r\n return value instanceof Promise ? value : Promise.resolve(value);\r\n}\r\nexport function thenPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n throw err;\r\n });\r\n}\r\nexport function voidPromise(promise, printError = false) {\r\n return promise\r\n .then(() => undefined)\r\n .catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\nexport function catchPromise(promise, printError = false) {\r\n return promise.catch((err) => {\r\n /* istanbul ignore if */\r\n if (printError) {\r\n console.log(err);\r\n }\r\n return undefined;\r\n });\r\n}\r\nfunction zipResolveCallbacks(options) {\r\n const { callbacks, catchError, index, resolve, result } = options;\r\n if (index === callbacks.length) {\r\n return resolve(result);\r\n }\r\n new Promise(() => {\r\n callbacks[index]()\r\n .then((value) => {\r\n result.push(value);\r\n return zipResolveCallbacks({\r\n ...options,\r\n index: index + 1,\r\n result\r\n });\r\n })\r\n .catch((err) => {\r\n return catchError(err);\r\n });\r\n });\r\n}\r\nexport function zipPromise(callbacks) {\r\n const result = [];\r\n return new Promise((resolve, reject) => {\r\n zipResolveCallbacks({\r\n callbacks,\r\n catchError: (err) => {\r\n reject(err);\r\n },\r\n index: 0,\r\n resolve: (result) => {\r\n resolve(result);\r\n },\r\n result\r\n });\r\n });\r\n}\r\nexport function securePromise(callback, catchError) {\r\n let promise$ = undefined;\r\n function itIsInstanced() {\r\n return itIsDefined(promise$);\r\n }\r\n function resolve() {\r\n if (!promise$) {\r\n promise$ = callback().catch((err) => {\r\n const errorValue = catchError && catchError(err);\r\n reset();\r\n if (errorValue) {\r\n return errorValue;\r\n }\r\n throw err;\r\n });\r\n }\r\n return promise$;\r\n }\r\n function reset() {\r\n promise$ = undefined;\r\n }\r\n return { itIsInstanced, reset, resolve };\r\n}\r\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\r\nfunction modelIsHidden(model) {\r\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\r\n}\r\nexport class AbstractEntityManager {\r\n}\r\nexport class EntityManager {\r\n constructor(source) {\r\n this.source = source;\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n this.relations = new Map();\r\n }\r\n persist(link) {\r\n this.links.push(link);\r\n }\r\n update(update) {\r\n const { bindable, entity, model } = update;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.updates.push(update);\r\n }\r\n sync(sync) {\r\n const { bindable, entity, model } = sync;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n this.syncs.push(sync);\r\n }\r\n destroy(entity) {\r\n this.select(entity).present((model) => {\r\n modelIsHidden(model)\r\n ? this.hiddens.push(model)\r\n : this.destroys.push(model);\r\n });\r\n }\r\n procedure(procedure) {\r\n this.procedures.push(procedure);\r\n }\r\n relation({ uuid }, model) {\r\n this.relations.set(uuid, model);\r\n }\r\n link(entity, model) {\r\n this.relation(entity, model);\r\n return entity;\r\n }\r\n select({ uuid }) {\r\n return Optional.build(this.relations.has(uuid) ? this.relations.get(uuid) : undefined);\r\n }\r\n async flush() {\r\n await this.persistAll();\r\n await this.updateAll();\r\n await this.syncAll();\r\n await this.hiddenAll();\r\n await this.destroyAll();\r\n await this.procedureAll();\r\n this.dispose();\r\n }\r\n dispose() {\r\n this.relations.clear();\r\n this.links = [];\r\n this.updates = [];\r\n this.syncs = [];\r\n this.destroys = [];\r\n this.hiddens = [];\r\n this.procedures = [];\r\n }\r\n persistAll() {\r\n const { links, source } = this;\r\n return Promise.all(links.map((link) => fromPromise(link.create(this)).then((model) => {\r\n const { bindable, entity } = link;\r\n if (bindable) {\r\n this.relation(entity, model);\r\n }\r\n return source.insert(model);\r\n })));\r\n }\r\n updateAll() {\r\n const { source, updates } = this;\r\n return Promise.all(updates.map(({ model }) => source.update(model)));\r\n }\r\n syncAll() {\r\n const { destroys, source, syncs } = this;\r\n return Promise.all(syncs\r\n .filter(({ model }) => !destroys.includes(model))\r\n .reduce((syncs, sync) => {\r\n const dirty = sync.verify();\r\n if (dirty) {\r\n const { model } = sync;\r\n syncs.push([model, dirty]);\r\n }\r\n return syncs;\r\n }, [])\r\n .map(([model, dirty]) => source.update(model, dirty)));\r\n }\r\n destroyAll() {\r\n const { destroys, source } = this;\r\n return Promise.all(destroys.map((destroy) => source.delete(destroy)));\r\n }\r\n hiddenAll() {\r\n const { hiddens, source } = this;\r\n return Promise.all(hiddens.map((hidden) => source.hidden(hidden)));\r\n }\r\n procedureAll() {\r\n const { procedures, source } = this;\r\n return Promise.all(procedures.map((procedure) => source.procedure(procedure)));\r\n }\r\n}\r\n//# sourceMappingURL=entity-manager.js.map","function modelIsEditable(model) {\r\n return typeof model === 'object' && 'updatedAt' in model;\r\n}\r\nexport class Entity {\r\n constructor(uuid) {\r\n this.uuid = uuid;\r\n }\r\n}\r\nexport class EntityUpdate {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n }\r\n}\r\nexport class EntityLink {\r\n constructor(entity, bindable = true) {\r\n this.entity = entity;\r\n this.bindable = bindable;\r\n }\r\n}\r\nexport class EntitySync {\r\n constructor(entity, model, bindable = true) {\r\n this.entity = entity;\r\n this.model = model;\r\n this.bindable = bindable;\r\n this.firstDirty = this.createDirtyFromModel(model);\r\n }\r\n verify() {\r\n this.sync();\r\n return this.createDirty();\r\n }\r\n createDirtyFromModel(model) {\r\n const dirty = {};\r\n Object.keys(model).forEach((key) => {\r\n dirty[key] = model[key];\r\n });\r\n return dirty;\r\n }\r\n createDirty() {\r\n const currentDirty = this.createDirtyFromModel(this.model);\r\n const finalDirty = {};\r\n Object.keys(currentDirty).forEach((key) => {\r\n if (currentDirty[key] !== this.firstDirty[key]) {\r\n finalDirty[key] = currentDirty[key];\r\n }\r\n });\r\n const requiredUpdate = Object.keys(finalDirty).length > 0;\r\n if (requiredUpdate && modelIsEditable(this.model)) {\r\n finalDirty['updatedAt'] = new Date();\r\n }\r\n return requiredUpdate ? finalDirty : undefined;\r\n }\r\n}\r\n//# sourceMappingURL=entity.js.map","export class AbstractPersistentUnit {\r\n}\r\n//# sourceMappingURL=persistent-unit.js.map","export class AbstractProcedure {\r\n}\r\n//# sourceMappingURL=procedure.js.map","export class AbstractRepository {\r\n}\r\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;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,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK;AAC5C,YAAY,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;AACpC,SAAS,CAAC,CAAC;AACX,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,WAAW,GAAG;AAClB,QAAQ,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,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,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AAC3D,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;;;;"}
|
package/dist/esm/database.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare abstract class
|
|
1
|
+
export declare abstract class AbstractEntityDatabase {
|
|
2
2
|
abstract connect(): Promise<void>;
|
|
3
|
-
abstract disconnect(
|
|
3
|
+
abstract disconnect(all?: boolean): Promise<void>;
|
|
4
4
|
abstract transaction(): Promise<void>;
|
|
5
5
|
abstract commit(): Promise<void>;
|
|
6
6
|
abstract rollback(): Promise<void>;
|
package/dist/esm/database.js
CHANGED
package/dist/esm/database.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/database.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/database.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,sBAAsB;CAU3C"}
|
package/dist/esm/datasource.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
abstract
|
|
6
|
-
abstract
|
|
7
|
-
abstract
|
|
8
|
-
abstract
|
|
9
|
-
abstract procedure(procedure: Procedure): Promise<void>;
|
|
1
|
+
import { AbstractProcedure } from './procedure';
|
|
2
|
+
import { AbstractModel, DirtyModel, ModelHideable } from './types';
|
|
3
|
+
export declare abstract class AbstractEntityDataSource {
|
|
4
|
+
abstract insert(model: AbstractModel): Promise<void>;
|
|
5
|
+
abstract update(model: AbstractModel, dirty?: DirtyModel): Promise<void>;
|
|
6
|
+
abstract delete(model: AbstractModel): Promise<void>;
|
|
7
|
+
abstract hidden(model: ModelHideable): Promise<void>;
|
|
8
|
+
abstract procedure(procedure: AbstractProcedure): Promise<void>;
|
|
10
9
|
}
|
package/dist/esm/datasource.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../src/datasource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../src/datasource.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,wBAAwB;CAU7C"}
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
import { Optional } from '@rolster/commons';
|
|
2
|
-
import {
|
|
3
|
-
import { EntityLink } from './entity
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
abstract
|
|
14
|
-
abstract
|
|
15
|
-
abstract
|
|
16
|
-
abstract
|
|
17
|
-
abstract
|
|
18
|
-
abstract relation(entity: Entity, model: BaseModel): void;
|
|
19
|
-
abstract link<E extends Entity>(entity: E, model: BaseModel): E;
|
|
20
|
-
abstract select<T extends BaseModel>(entity: Entity): Optional<T>;
|
|
2
|
+
import { AbstractEntityDataSource } from './datasource';
|
|
3
|
+
import { EntityLink, EntitySync, EntityUpdate } from './entity';
|
|
4
|
+
import { AbstractModel, AbstractEntity, QueryEntityManager } from './types';
|
|
5
|
+
import { AbstractProcedure } from './procedure';
|
|
6
|
+
type ManagerLink = EntityLink<AbstractEntity, AbstractModel>;
|
|
7
|
+
type ManagerUpdate = EntityUpdate<AbstractEntity, AbstractModel>;
|
|
8
|
+
type ManagerSync = EntitySync<AbstractEntity, AbstractModel>;
|
|
9
|
+
export declare abstract class AbstractEntityManager implements QueryEntityManager {
|
|
10
|
+
abstract persist(link: ManagerLink): void;
|
|
11
|
+
abstract update(update: ManagerUpdate): void;
|
|
12
|
+
abstract sync(sync: ManagerSync): void;
|
|
13
|
+
abstract destroy(entity: AbstractEntity): void;
|
|
14
|
+
abstract procedure(procedure: AbstractProcedure): void;
|
|
15
|
+
abstract relation(entity: AbstractEntity, model: AbstractModel): void;
|
|
16
|
+
abstract link<E extends AbstractEntity>(entity: E, model: AbstractModel): E;
|
|
17
|
+
abstract select<T extends AbstractModel>(entity: AbstractEntity): Optional<T>;
|
|
21
18
|
abstract flush(): Promise<void>;
|
|
22
19
|
abstract dispose(): void;
|
|
23
20
|
}
|
|
24
|
-
export declare class
|
|
21
|
+
export declare class EntityManager implements AbstractEntityManager {
|
|
25
22
|
private source;
|
|
26
23
|
private relations;
|
|
27
24
|
private links;
|
|
@@ -30,15 +27,15 @@ export declare class RolsterEntityManager implements EntityManager {
|
|
|
30
27
|
private destroys;
|
|
31
28
|
private hiddens;
|
|
32
29
|
private procedures;
|
|
33
|
-
constructor(source:
|
|
34
|
-
persist(link:
|
|
35
|
-
update(update:
|
|
36
|
-
sync(sync:
|
|
37
|
-
destroy(entity:
|
|
38
|
-
procedure(procedure:
|
|
39
|
-
relation({ uuid }:
|
|
40
|
-
link<E extends
|
|
41
|
-
select<
|
|
30
|
+
constructor(source: AbstractEntityDataSource);
|
|
31
|
+
persist(link: ManagerLink): void;
|
|
32
|
+
update(update: ManagerUpdate): void;
|
|
33
|
+
sync(sync: ManagerSync): void;
|
|
34
|
+
destroy(entity: AbstractEntity): void;
|
|
35
|
+
procedure(procedure: AbstractProcedure): void;
|
|
36
|
+
relation({ uuid }: AbstractEntity, model: AbstractModel): void;
|
|
37
|
+
link<E extends AbstractEntity>(entity: E, model: AbstractModel): E;
|
|
38
|
+
select<M extends AbstractModel>({ uuid }: AbstractEntity): Optional<M>;
|
|
42
39
|
flush(): Promise<void>;
|
|
43
40
|
dispose(): void;
|
|
44
41
|
private persistAll;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Optional, fromPromise } from '@rolster/commons';
|
|
2
|
-
|
|
2
|
+
function modelIsHidden(model) {
|
|
3
|
+
return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
|
|
4
|
+
}
|
|
5
|
+
export class AbstractEntityManager {
|
|
3
6
|
}
|
|
4
|
-
export class
|
|
7
|
+
export class EntityManager {
|
|
5
8
|
constructor(source) {
|
|
6
9
|
this.source = source;
|
|
7
10
|
this.links = [];
|
|
@@ -31,7 +34,9 @@ export class RolsterEntityManager {
|
|
|
31
34
|
}
|
|
32
35
|
destroy(entity) {
|
|
33
36
|
this.select(entity).present((model) => {
|
|
34
|
-
|
|
37
|
+
modelIsHidden(model)
|
|
38
|
+
? this.hiddens.push(model)
|
|
39
|
+
: this.destroys.push(model);
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
42
|
procedure(procedure) {
|
|
@@ -67,7 +72,7 @@ export class RolsterEntityManager {
|
|
|
67
72
|
}
|
|
68
73
|
persistAll() {
|
|
69
74
|
const { links, source } = this;
|
|
70
|
-
return Promise.all(links.map((link) => fromPromise(link.
|
|
75
|
+
return Promise.all(links.map((link) => fromPromise(link.create(this)).then((model) => {
|
|
71
76
|
const { bindable, entity } = link;
|
|
72
77
|
if (bindable) {
|
|
73
78
|
this.relation(entity, model);
|
|
@@ -87,11 +92,11 @@ export class RolsterEntityManager {
|
|
|
87
92
|
const dirty = sync.verify();
|
|
88
93
|
if (dirty) {
|
|
89
94
|
const { model } = sync;
|
|
90
|
-
syncs.push(
|
|
95
|
+
syncs.push([model, dirty]);
|
|
91
96
|
}
|
|
92
97
|
return syncs;
|
|
93
98
|
}, [])
|
|
94
|
-
.map((
|
|
99
|
+
.map(([model, dirty]) => source.update(model, dirty)));
|
|
95
100
|
}
|
|
96
101
|
destroyAll() {
|
|
97
102
|
const { destroys, source } = this;
|
|
@@ -106,7 +111,4 @@ export class RolsterEntityManager {
|
|
|
106
111
|
return Promise.all(procedures.map((procedure) => source.procedure(procedure)));
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
|
-
function isHidden(model) {
|
|
110
|
-
return 'hidden' in model && 'hiddenAt' in model;
|
|
111
|
-
}
|
|
112
114
|
//# 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;
|
|
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,SAA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
|
|
1
|
-
|
|
1
|
+
import { AbstractEntity, AbstractModel, DirtyModel, QueryEntityManager } from './types';
|
|
2
|
+
export declare class Entity implements AbstractEntity {
|
|
2
3
|
readonly uuid: string;
|
|
3
4
|
constructor(uuid: string);
|
|
4
5
|
}
|
|
6
|
+
export declare abstract class EntityUpdate<E extends AbstractEntity, M extends AbstractModel> {
|
|
7
|
+
readonly entity: E;
|
|
8
|
+
readonly model: M;
|
|
9
|
+
readonly bindable: boolean;
|
|
10
|
+
constructor(entity: E, model: M, bindable?: boolean);
|
|
11
|
+
abstract update(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class EntityLink<E extends AbstractEntity, M extends AbstractModel> {
|
|
14
|
+
readonly entity: E;
|
|
15
|
+
readonly bindable: boolean;
|
|
16
|
+
constructor(entity: E, bindable?: boolean);
|
|
17
|
+
abstract create(manager: QueryEntityManager): M | Promise<M>;
|
|
18
|
+
}
|
|
19
|
+
export declare abstract class EntitySync<E extends AbstractEntity, M extends AbstractModel> {
|
|
20
|
+
readonly entity: E;
|
|
21
|
+
readonly model: M;
|
|
22
|
+
readonly bindable: boolean;
|
|
23
|
+
private firstDirty;
|
|
24
|
+
constructor(entity: E, model: M, bindable?: boolean);
|
|
25
|
+
abstract sync(): void;
|
|
26
|
+
verify(): Undefined<DirtyModel>;
|
|
27
|
+
private createDirtyFromModel;
|
|
28
|
+
private createDirty;
|
|
29
|
+
}
|
package/dist/esm/entity.js
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
|
+
function modelIsEditable(model) {
|
|
2
|
+
return typeof model === 'object' && 'updatedAt' in model;
|
|
3
|
+
}
|
|
1
4
|
export class Entity {
|
|
2
5
|
constructor(uuid) {
|
|
3
6
|
this.uuid = uuid;
|
|
4
7
|
}
|
|
5
8
|
}
|
|
9
|
+
export class EntityUpdate {
|
|
10
|
+
constructor(entity, model, bindable = true) {
|
|
11
|
+
this.entity = entity;
|
|
12
|
+
this.model = model;
|
|
13
|
+
this.bindable = bindable;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class EntityLink {
|
|
17
|
+
constructor(entity, bindable = true) {
|
|
18
|
+
this.entity = entity;
|
|
19
|
+
this.bindable = bindable;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class EntitySync {
|
|
23
|
+
constructor(entity, model, bindable = true) {
|
|
24
|
+
this.entity = entity;
|
|
25
|
+
this.model = model;
|
|
26
|
+
this.bindable = bindable;
|
|
27
|
+
this.firstDirty = this.createDirtyFromModel(model);
|
|
28
|
+
}
|
|
29
|
+
verify() {
|
|
30
|
+
this.sync();
|
|
31
|
+
return this.createDirty();
|
|
32
|
+
}
|
|
33
|
+
createDirtyFromModel(model) {
|
|
34
|
+
const dirty = {};
|
|
35
|
+
Object.keys(model).forEach((key) => {
|
|
36
|
+
dirty[key] = model[key];
|
|
37
|
+
});
|
|
38
|
+
return dirty;
|
|
39
|
+
}
|
|
40
|
+
createDirty() {
|
|
41
|
+
const currentDirty = this.createDirtyFromModel(this.model);
|
|
42
|
+
const finalDirty = {};
|
|
43
|
+
Object.keys(currentDirty).forEach((key) => {
|
|
44
|
+
if (currentDirty[key] !== this.firstDirty[key]) {
|
|
45
|
+
finalDirty[key] = currentDirty[key];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const requiredUpdate = Object.keys(finalDirty).length > 0;
|
|
49
|
+
if (requiredUpdate && modelIsEditable(this.model)) {
|
|
50
|
+
finalDirty['updatedAt'] = new Date();
|
|
51
|
+
}
|
|
52
|
+
return requiredUpdate ? finalDirty : undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
6
55
|
//# sourceMappingURL=entity.js.map
|
package/dist/esm/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":"AAQ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CAAC,CAAC;QAC3D,MAAM,UAAU,GAAe,EAAE,CAAC;QAElC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACxC,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAC9C,UAAU,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;aACrC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAE1D,IAAI,cAAc,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACjD,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;SACtC;QAED,OAAO,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IACjD,CAAC;CACF"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export * from './database';
|
|
2
2
|
export * from './datasource';
|
|
3
|
-
export * from './entity-link';
|
|
4
3
|
export * from './entity-manager';
|
|
5
|
-
export * from './entity-sync';
|
|
6
|
-
export * from './entity-update';
|
|
7
4
|
export * from './entity';
|
|
8
|
-
export * from './model';
|
|
9
5
|
export * from './persistent-unit';
|
|
10
6
|
export * from './procedure';
|
|
11
7
|
export * from './repository';
|
|
8
|
+
export * from './types';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
export * from './database';
|
|
2
2
|
export * from './datasource';
|
|
3
|
-
export * from './entity-link';
|
|
4
3
|
export * from './entity-manager';
|
|
5
|
-
export * from './entity-sync';
|
|
6
|
-
export * from './entity-update';
|
|
7
4
|
export * from './entity';
|
|
8
|
-
export * from './model';
|
|
9
5
|
export * from './persistent-unit';
|
|
10
6
|
export * from './procedure';
|
|
11
7
|
export * from './repository';
|
|
8
|
+
export * from './types';
|
|
12
9
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistent-unit.js","sourceRoot":"","sources":["../../src/persistent-unit.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,
|
|
1
|
+
{"version":3,"file":"persistent-unit.js","sourceRoot":"","sources":["../../src/persistent-unit.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,sBAAsB;CAE3C"}
|
package/dist/esm/procedure.d.ts
CHANGED
package/dist/esm/procedure.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../src/procedure.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,
|
|
1
|
+
{"version":3,"file":"procedure.js","sourceRoot":"","sources":["../../src/procedure.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,iBAAiB;CAEtC"}
|
package/dist/esm/repository.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Optional } from '@rolster/commons';
|
|
2
2
|
import { Entity } from './entity';
|
|
3
|
-
export declare abstract class
|
|
3
|
+
export declare abstract class AbstractRepository<T extends Entity> {
|
|
4
4
|
abstract persist(entity: T): Promise<void>;
|
|
5
5
|
abstract findByUuid(uuid: string): Promise<Optional<T>>;
|
|
6
6
|
abstract findAll(): Promise<T[]>;
|
package/dist/esm/repository.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,kBAAkB;CAQvC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Optional } from '@rolster/commons';
|
|
2
|
+
export type DirtyModel = Record<string, any>;
|
|
3
|
+
export interface AbstractModel {
|
|
4
|
+
id: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ModelEditable extends AbstractModel {
|
|
7
|
+
updatedAt?: Date;
|
|
8
|
+
}
|
|
9
|
+
export interface ModelHideable extends AbstractModel {
|
|
10
|
+
hidden: boolean;
|
|
11
|
+
hiddenAt?: Date;
|
|
12
|
+
}
|
|
13
|
+
export interface Model extends ModelHideable {
|
|
14
|
+
updatedAt?: Date;
|
|
15
|
+
}
|
|
16
|
+
export interface AbstractEntity {
|
|
17
|
+
readonly uuid: string;
|
|
18
|
+
}
|
|
19
|
+
export interface QueryEntityManager {
|
|
20
|
+
select<T extends AbstractModel>(entity: AbstractEntity): Optional<T>;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rolster/vinegar",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Container package of basic classes to implement a clean architecture.",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -26,12 +26,13 @@
|
|
|
26
26
|
"prepublishOnly": "npm run build"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@rolster/commons": "^2.0.
|
|
29
|
+
"@rolster/commons": "^2.0.5"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@rollup/plugin-commonjs": "^25.0.4",
|
|
33
33
|
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
34
34
|
"@rollup/plugin-typescript": "^11.1.3",
|
|
35
|
+
"@rolster/rollup": "^1.0.6",
|
|
35
36
|
"@rolster/types": "^1.0.9",
|
|
36
37
|
"@types/jest": "^29.5.1",
|
|
37
38
|
"jest": "^29.5.0",
|
|
@@ -50,7 +51,6 @@
|
|
|
50
51
|
"rolster",
|
|
51
52
|
"typescript",
|
|
52
53
|
"vinegar",
|
|
53
|
-
"hexagonal",
|
|
54
54
|
"clean-architecture"
|
|
55
55
|
],
|
|
56
56
|
"publishConfig": {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { EntityManager } from './entity-manager';
|
|
2
|
-
import { Entity } from './entity';
|
|
3
|
-
import { BaseModel } from './model';
|
|
4
|
-
export declare abstract class EntityLink<E extends Entity, M extends BaseModel> {
|
|
5
|
-
readonly entity: E;
|
|
6
|
-
readonly bindable: boolean;
|
|
7
|
-
constructor(entity: E, bindable?: boolean);
|
|
8
|
-
abstract createModel(manager: EntityManager): M | Promise<M>;
|
|
9
|
-
}
|
package/dist/esm/entity-link.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entity-link.js","sourceRoot":"","sources":["../../src/entity-link.ts"],"names":[],"mappings":"AAIA,MAAM,OAAgB,UAAU;IAC9B,YAA4B,MAAS,EAAkB,WAAW,IAAI;QAA1C,WAAM,GAAN,MAAM,CAAG;QAAkB,aAAQ,GAAR,QAAQ,CAAO;IAAG,CAAC;CAG3E"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Entity } from './entity';
|
|
2
|
-
import { BaseModel } from './model';
|
|
3
|
-
export type ModelDirty = Record<string, any>;
|
|
4
|
-
export declare abstract class EntitySync<E extends Entity, M extends BaseModel> {
|
|
5
|
-
readonly entity: E;
|
|
6
|
-
readonly model: M;
|
|
7
|
-
readonly bindable: boolean;
|
|
8
|
-
private firstStatus;
|
|
9
|
-
constructor(entity: E, model: M, bindable?: boolean);
|
|
10
|
-
abstract sync(): void;
|
|
11
|
-
verify(): Undefined<ModelDirty>;
|
|
12
|
-
private mapperModel;
|
|
13
|
-
private createDirty;
|
|
14
|
-
}
|
package/dist/esm/entity-sync.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export class EntitySync {
|
|
2
|
-
constructor(entity, model, bindable = true) {
|
|
3
|
-
this.entity = entity;
|
|
4
|
-
this.model = model;
|
|
5
|
-
this.bindable = bindable;
|
|
6
|
-
this.firstStatus = this.mapperModel(model);
|
|
7
|
-
}
|
|
8
|
-
verify() {
|
|
9
|
-
this.sync();
|
|
10
|
-
return this.createDirty();
|
|
11
|
-
}
|
|
12
|
-
mapperModel(model) {
|
|
13
|
-
const dirty = {};
|
|
14
|
-
Object.keys(model).forEach((key) => {
|
|
15
|
-
dirty[key] = model[key];
|
|
16
|
-
});
|
|
17
|
-
return dirty;
|
|
18
|
-
}
|
|
19
|
-
createDirty() {
|
|
20
|
-
const currentStatus = this.mapperModel(this.model);
|
|
21
|
-
const modelDirty = {};
|
|
22
|
-
let dirty = false;
|
|
23
|
-
Object.keys(currentStatus).forEach((key) => {
|
|
24
|
-
if (currentStatus[key] !== this.firstStatus[key]) {
|
|
25
|
-
dirty = true;
|
|
26
|
-
modelDirty[key] = currentStatus[key];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
if (isUpdated(this.model)) {
|
|
30
|
-
modelDirty['updatedAt'] = new Date();
|
|
31
|
-
}
|
|
32
|
-
return dirty ? modelDirty : undefined;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function isUpdated(model) {
|
|
36
|
-
return 'updatedAt' in model;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=entity-sync.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entity-sync.js","sourceRoot":"","sources":["../../src/entity-sync.ts"],"names":[],"mappings":"AAKA,MAAM,OAAgB,UAAU;IAG9B,YACkB,MAAS,EACT,KAAQ,EACR,WAAW,IAAI;QAFf,WAAM,GAAN,MAAM,CAAG;QACT,UAAK,GAAL,KAAK,CAAG;QACR,aAAQ,GAAR,QAAQ,CAAO;QAE/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAIM,MAAM;QACX,IAAI,CAAC,IAAI,EAAE,CAAC;QAEZ,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAEO,WAAW,CAAC,KAAQ;QAC1B,MAAM,KAAK,GAAe,EAAE,CAAC;QAE7B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACjC,KAAK,CAAC,GAAG,CAAC,GAAI,KAAa,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,WAAW;QACjB,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnD,MAAM,UAAU,GAAe,EAAE,CAAC;QAElC,IAAI,KAAK,GAAG,KAAK,CAAC;QAElB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACzC,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE;gBAChD,KAAK,GAAG,IAAI,CAAC;gBACb,UAAU,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;aACtC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACzB,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;SACtC;QAED,OAAO,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IACxC,CAAC;CACF;AAED,SAAS,SAAS,CAAC,KAAU;IAC3B,OAAO,WAAW,IAAI,KAAK,CAAC;AAC9B,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Entity } from './entity';
|
|
2
|
-
import { BaseModel } from './model';
|
|
3
|
-
export declare abstract class EntityUpdate<E extends Entity, M extends BaseModel> {
|
|
4
|
-
readonly entity: E;
|
|
5
|
-
readonly model: M;
|
|
6
|
-
readonly bindable: boolean;
|
|
7
|
-
constructor(entity: E, model: M, bindable?: boolean);
|
|
8
|
-
abstract update(): void;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entity-update.js","sourceRoot":"","sources":["../../src/entity-update.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,YAAY;IAChC,YACkB,MAAS,EACT,KAAQ,EACR,WAAW,IAAI;QAFf,WAAM,GAAN,MAAM,CAAG;QACT,UAAK,GAAL,KAAK,CAAG;QACR,aAAQ,GAAR,QAAQ,CAAO;IAC9B,CAAC;CAGL"}
|
package/dist/esm/model.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface BaseModel {
|
|
2
|
-
id: number;
|
|
3
|
-
}
|
|
4
|
-
export interface ModelUpdated extends BaseModel {
|
|
5
|
-
updatedAt?: Date;
|
|
6
|
-
}
|
|
7
|
-
export interface ModelHidden extends BaseModel {
|
|
8
|
-
hidden: boolean;
|
|
9
|
-
hiddenAt?: Date;
|
|
10
|
-
}
|
|
11
|
-
export interface Model extends ModelHidden {
|
|
12
|
-
updatedAt?: Date;
|
|
13
|
-
}
|
package/dist/esm/model.js
DELETED
package/dist/esm/model.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":""}
|