@rolster/vinegar 2.4.0 → 2.5.0

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 CHANGED
@@ -2,73 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var commons = require('@rolster/commons');
6
+
5
7
  class AbstractEntityDatabase {
6
8
  }
7
9
 
8
10
  class AbstractEntityDataSource {
9
11
  }
10
12
 
11
- function itIsDefined(value) {
12
- return typeof value !== 'undefined' && value !== null;
13
- }
14
-
15
- class Optional {
16
- constructor(value) {
17
- this.value = value;
18
- }
19
- present(callback) {
20
- return this.isPresent() ? callback(this.get()) : undefined;
21
- }
22
- empty(callback) {
23
- return this.isEmpty() ? callback() : undefined;
24
- }
25
- when(present, empty) {
26
- return this.isPresent() ? present(this.get()) : empty();
27
- }
28
- static build(value) {
29
- return itIsDefined(value) ? this.of(value) : this.empty();
30
- }
31
- static of(value) {
32
- if (itIsDefined(value)) {
33
- return new PresentOptional(value);
34
- }
35
- throw new Error('The passed value was null or undefined.');
36
- }
37
- static empty() {
38
- return new EmptyOptional();
39
- }
40
- }
41
- class PresentOptional extends Optional {
42
- constructor(presentValue) {
43
- super(presentValue);
44
- this.presentValue = presentValue;
45
- }
46
- isPresent() {
47
- return true;
48
- }
49
- isEmpty() {
50
- return false;
51
- }
52
- get() {
53
- return this.presentValue;
54
- }
55
- }
56
- class EmptyOptional extends Optional {
57
- isPresent() {
58
- return false;
59
- }
60
- isEmpty() {
61
- return true;
62
- }
63
- get() {
64
- throw new Error('The optional is not present.');
65
- }
66
- }
67
-
68
- function fromPromise(value) {
69
- return value instanceof Promise ? value : Promise.resolve(value);
70
- }
71
-
72
13
  function isModelHidden(model) {
73
14
  return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
74
15
  }
@@ -118,7 +59,7 @@ class EntityManager {
118
59
  return entity;
119
60
  }
120
61
  select(entity) {
121
- return Optional.build(this.relations.has(entity) ? this.relations.get(entity) : undefined);
62
+ return commons.Optional.build(this.relations.has(entity) ? this.relations.get(entity) : undefined);
122
63
  }
123
64
  async flush() {
124
65
  const results = [
@@ -143,7 +84,7 @@ class EntityManager {
143
84
  }
144
85
  persistAll() {
145
86
  return Promise.all(this.links.map(async (link) => {
146
- const model = await fromPromise(link.create(this));
87
+ const model = await commons.fromPromise(link.create(this));
147
88
  link.relationable && this.relation(link.entity, model);
148
89
  return this.dataSource.insert(model);
149
90
  }));
@@ -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","../esm/result.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","const primitives = [Date, RegExp, Set, Map, Function, String, Boolean, Number];\nconst sliceSize = 512;\nconst falsyValue = ['false', 'undefined', '0', 0];\nlet _cloneStrategy = () => true;\nfunction _clone(value, caches, overrides) {\n if (itIsUndefined(value) || typeof value !== 'object') {\n return value;\n }\n if (Object.prototype.toString.call(value) === '[object Object]') {\n const [object] = caches.filter((_object) => _object === value);\n /* istanbul ignore if */\n if (object) {\n return object;\n }\n caches.push(value);\n }\n const ConstructorObject = Object.getPrototypeOf(value).constructor;\n if (primitives.includes(ConstructorObject)) {\n return new ConstructorObject(value);\n }\n if (Array.isArray(value)) {\n return value.map((item) => _clone(item, caches, {}));\n }\n const object = new ConstructorObject();\n const keys = Object.keys(overrides ?? {});\n for (const key in value) {\n if (_cloneStrategy(value, key)) {\n if (overrides) {\n object[key] = keys.includes(key)\n ? overrides[key]\n : _clone(value[key], caches, {});\n }\n else {\n object[key] = _clone(value[key], caches, {});\n }\n }\n }\n return object;\n}\nexport function setCloneStrategy(cloneStrategy) {\n _cloneStrategy = cloneStrategy;\n}\nexport function itIsDefined(value) {\n return typeof value !== 'undefined' && value !== null;\n}\nexport function itIsUndefined(value) {\n return !itIsDefined(value);\n}\nexport function parseBoolean(value) {\n return !(itIsUndefined(value) ||\n value === false ||\n falsyValue.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 clone(value, overrides) {\n return _clone(value, [], overrides);\n}\nexport function freeze(value) {\n if (typeof value !== 'object') {\n return value;\n }\n for (const key in value) {\n const item = value[key];\n if (typeof item === 'object' && !Object.isFrozen(item)) {\n freeze(item);\n }\n }\n return Object.freeze(value);\n}\nexport function seal(value) {\n if (typeof value !== 'object') {\n return value;\n }\n for (const key in value) {\n const item = value[key];\n if (typeof item === 'object' && !Object.isSealed(item)) {\n seal(item);\n }\n }\n return Object.seal(value);\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 += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\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}\nexport function ceilDecimals(number, size) {\n const factor = Math.pow(10, size);\n return Math.ceil(number * factor) / factor;\n}\nexport function floorDecimals(number, size) {\n const factor = Math.pow(10, size);\n return Math.floor(number * factor) / factor;\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 resolvePromise(promise, catchError) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n catchError && catchError(err);\n throw err;\n });\n}\nexport function voidPromise(promise, catchError) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n catchError && catchError(err);\n return undefined;\n });\n}\nexport function catchPromise(promise, catchError) {\n return promise.catch((err) => {\n catchError && catchError(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 let _isRequesting = false;\n function isInstanced() {\n return itIsDefined(promise$);\n }\n function isRequesting() {\n return _isRequesting;\n }\n function resolve() {\n if (!promise$) {\n _isRequesting = true;\n promise$ = callback()\n .catch((err) => {\n const errorValue = catchError && catchError(err);\n reset();\n if (errorValue) {\n return errorValue;\n }\n throw err;\n })\n .finally(() => {\n _isRequesting = false;\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 {\n isInstanced,\n isRequesting,\n refresh,\n reset,\n resolve\n };\n}\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction isModelHidden(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(link) {\n this.links.push(link);\n }\n refresh(refresh) {\n const { entity, model, relationable } = refresh;\n relationable && this.relation(entity, model);\n this.refreshs.push(refresh);\n }\n sync(sync) {\n const { entity, model, relationable } = sync;\n relationable && this.relation(entity, model);\n this.syncs.push(sync);\n }\n destroy(entity) {\n const optional = this.select(entity);\n if (optional.isPresent()) {\n const model = optional.get();\n isModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n }\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation(entity, model) {\n this.relations.set(entity, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select(entity) {\n return Optional.build(this.relations.has(entity) ? this.relations.get(entity) : undefined);\n }\n async flush() {\n const results = [\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 ];\n this.dispose();\n return results;\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(async (link) => {\n const model = await fromPromise(link.create(this));\n link.relationable && this.relation(link.entity, model);\n return this.dataSource.insert(model);\n }));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map((refresh) => {\n refresh.setManager(this);\n return this.dataSource.refresh(refresh);\n }));\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(this);\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.dataSource.update(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 isModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityLink {\n constructor(entity, relationable = true) {\n this.entity = entity;\n this.relationable = relationable;\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 setManager(manager) {\n this.manager = manager;\n }\n async execute() {\n this.refresh(this.manager);\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.dirty = this.createDirtyFromModel(model);\n }\n verify(manager) {\n this.sync(manager);\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.entries(model).forEach(([key, value]) => {\n dirty[key] = value;\n });\n return dirty;\n }\n createDirty() {\n const _model = this.createDirtyFromModel(this.model);\n const _dirty = {};\n Object.entries(_model).forEach(([key, value]) => {\n if (_model[key] !== this.dirty[key]) {\n _dirty[key] = value;\n }\n });\n const requiredUpdate = Object.keys(_dirty).length > 0;\n if (requiredUpdate && isModelEditable(this.model)) {\n _dirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? _dirty : 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","export class PersistentUnitResult {\n constructor(code, error, model) {\n this.code = code;\n this.error = error;\n this.model = model;\n }\n}\n//# sourceMappingURL=result.js.map"],"names":[],"mappings":";;;;AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;AACtC;;ACyCO,SAAS,WAAW,CAAC,KAAK,EAAE;AACnC,IAAI,OAAO,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,IAAI,CAAC;AAC1D;;AC3CO,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,GAA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CAAC,CAAC;AAC7D,QAAQ,MAAM,MAAM,GAAG,EAAE,CAAC;AAC1B,QAAQ,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AACzD,YAAY,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;AACjD,gBAAgB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACpC,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9D,QAAQ,IAAI,cAAc,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AAC3D,YAAY,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AAC7C,SAAS;AACT,QAAQ,OAAO,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;AACnD,KAAK;AACL;;AC3DO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,iBAAiB,CAAC;AAC/B;;ACDO,MAAM,kBAAkB,CAAC;AAChC;;ACDO,MAAM,oBAAoB,CAAC;AAClC,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;AACpC,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACzB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,KAAK;AACL;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js","../esm/result.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction isModelHidden(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(link) {\n this.links.push(link);\n }\n refresh(refresh) {\n const { entity, model, relationable } = refresh;\n relationable && this.relation(entity, model);\n this.refreshs.push(refresh);\n }\n sync(sync) {\n const { entity, model, relationable } = sync;\n relationable && this.relation(entity, model);\n this.syncs.push(sync);\n }\n destroy(entity) {\n const optional = this.select(entity);\n if (optional.isPresent()) {\n const model = optional.get();\n isModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n }\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation(entity, model) {\n this.relations.set(entity, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select(entity) {\n return Optional.build(this.relations.has(entity) ? this.relations.get(entity) : undefined);\n }\n async flush() {\n const results = [\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 ];\n this.dispose();\n return results;\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(async (link) => {\n const model = await fromPromise(link.create(this));\n link.relationable && this.relation(link.entity, model);\n return this.dataSource.insert(model);\n }));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map((refresh) => {\n refresh.setManager(this);\n return this.dataSource.refresh(refresh);\n }));\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(this);\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.dataSource.update(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 isModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityLink {\n constructor(entity, relationable = true) {\n this.entity = entity;\n this.relationable = relationable;\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 setManager(manager) {\n this.manager = manager;\n }\n async execute() {\n this.refresh(this.manager);\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.dirty = this.createDirtyFromModel(model);\n }\n verify(manager) {\n this.sync(manager);\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.entries(model).forEach(([key, value]) => {\n dirty[key] = value;\n });\n return dirty;\n }\n createDirty() {\n const _model = this.createDirtyFromModel(this.model);\n const _dirty = {};\n Object.entries(_model).forEach(([key, value]) => {\n if (_model[key] !== this.dirty[key]) {\n _dirty[key] = value;\n }\n });\n const requiredUpdate = Object.keys(_dirty).length > 0;\n if (requiredUpdate && isModelEditable(this.model)) {\n _dirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? _dirty : 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","export class PersistentUnitResult {\n constructor(code, error, model) {\n this.code = code;\n this.error = error;\n this.model = model;\n }\n}\n//# sourceMappingURL=result.js.map"],"names":["Optional","fromPromise"],"mappings":";;;;;;AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;AACtC;;ACAA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,IAAI,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC;AACjF,CAAC;AACM,MAAM,qBAAqB,CAAC;AACnC,CAAC;AACM,MAAM,aAAa,CAAC;AAC3B,IAAI,WAAW,CAAC,UAAU,EAAE;AAC5B,QAAQ,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AACrC,QAAQ,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;AACxB,QAAQ,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;AACxB,QAAQ,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;AAC3B,QAAQ,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;AAC1B,QAAQ,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;AAC7B,QAAQ,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;AACnC,KAAK;AACL,IAAI,OAAO,CAAC,IAAI,EAAE;AAClB,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9B,KAAK;AACL,IAAI,OAAO,CAAC,OAAO,EAAE;AACrB,QAAQ,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;AACxD,QAAQ,YAAY,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACrD,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,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AQ,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AACzD,YAAY,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;AACjD,gBAAgB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACpC,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9D,QAAQ,IAAI,cAAc,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AAC3D,YAAY,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AAC7C,SAAS;AACT,QAAQ,OAAO,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;AACnD,KAAK;AACL;;AC3DO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,iBAAiB,CAAC;AAC/B;;ACDO,MAAM,kBAAkB,CAAC;AAChC;;ACDO,MAAM,oBAAoB,CAAC;AAClC,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;AACpC,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACzB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,KAAK;AACL;;;;;;;;;;;;;;;"}
package/dist/es/index.js CHANGED
@@ -1,70 +1,11 @@
1
+ import { Optional, fromPromise } from '@rolster/commons';
2
+
1
3
  class AbstractEntityDatabase {
2
4
  }
3
5
 
4
6
  class AbstractEntityDataSource {
5
7
  }
6
8
 
7
- function itIsDefined(value) {
8
- return typeof value !== 'undefined' && value !== null;
9
- }
10
-
11
- class Optional {
12
- constructor(value) {
13
- this.value = value;
14
- }
15
- present(callback) {
16
- return this.isPresent() ? callback(this.get()) : undefined;
17
- }
18
- empty(callback) {
19
- return this.isEmpty() ? callback() : undefined;
20
- }
21
- when(present, empty) {
22
- return this.isPresent() ? present(this.get()) : empty();
23
- }
24
- static build(value) {
25
- return itIsDefined(value) ? this.of(value) : this.empty();
26
- }
27
- static of(value) {
28
- if (itIsDefined(value)) {
29
- return new PresentOptional(value);
30
- }
31
- throw new Error('The passed value was null or undefined.');
32
- }
33
- static empty() {
34
- return new EmptyOptional();
35
- }
36
- }
37
- class PresentOptional extends Optional {
38
- constructor(presentValue) {
39
- super(presentValue);
40
- this.presentValue = presentValue;
41
- }
42
- isPresent() {
43
- return true;
44
- }
45
- isEmpty() {
46
- return false;
47
- }
48
- get() {
49
- return this.presentValue;
50
- }
51
- }
52
- class EmptyOptional extends Optional {
53
- isPresent() {
54
- return false;
55
- }
56
- isEmpty() {
57
- return true;
58
- }
59
- get() {
60
- throw new Error('The optional is not present.');
61
- }
62
- }
63
-
64
- function fromPromise(value) {
65
- return value instanceof Promise ? value : Promise.resolve(value);
66
- }
67
-
68
9
  function isModelHidden(model) {
69
10
  return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
70
11
  }
@@ -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","../esm/result.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","const primitives = [Date, RegExp, Set, Map, Function, String, Boolean, Number];\nconst sliceSize = 512;\nconst falsyValue = ['false', 'undefined', '0', 0];\nlet _cloneStrategy = () => true;\nfunction _clone(value, caches, overrides) {\n if (itIsUndefined(value) || typeof value !== 'object') {\n return value;\n }\n if (Object.prototype.toString.call(value) === '[object Object]') {\n const [object] = caches.filter((_object) => _object === value);\n /* istanbul ignore if */\n if (object) {\n return object;\n }\n caches.push(value);\n }\n const ConstructorObject = Object.getPrototypeOf(value).constructor;\n if (primitives.includes(ConstructorObject)) {\n return new ConstructorObject(value);\n }\n if (Array.isArray(value)) {\n return value.map((item) => _clone(item, caches, {}));\n }\n const object = new ConstructorObject();\n const keys = Object.keys(overrides ?? {});\n for (const key in value) {\n if (_cloneStrategy(value, key)) {\n if (overrides) {\n object[key] = keys.includes(key)\n ? overrides[key]\n : _clone(value[key], caches, {});\n }\n else {\n object[key] = _clone(value[key], caches, {});\n }\n }\n }\n return object;\n}\nexport function setCloneStrategy(cloneStrategy) {\n _cloneStrategy = cloneStrategy;\n}\nexport function itIsDefined(value) {\n return typeof value !== 'undefined' && value !== null;\n}\nexport function itIsUndefined(value) {\n return !itIsDefined(value);\n}\nexport function parseBoolean(value) {\n return !(itIsUndefined(value) ||\n value === false ||\n falsyValue.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 clone(value, overrides) {\n return _clone(value, [], overrides);\n}\nexport function freeze(value) {\n if (typeof value !== 'object') {\n return value;\n }\n for (const key in value) {\n const item = value[key];\n if (typeof item === 'object' && !Object.isFrozen(item)) {\n freeze(item);\n }\n }\n return Object.freeze(value);\n}\nexport function seal(value) {\n if (typeof value !== 'object') {\n return value;\n }\n for (const key in value) {\n const item = value[key];\n if (typeof item === 'object' && !Object.isSealed(item)) {\n seal(item);\n }\n }\n return Object.seal(value);\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 += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\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}\nexport function ceilDecimals(number, size) {\n const factor = Math.pow(10, size);\n return Math.ceil(number * factor) / factor;\n}\nexport function floorDecimals(number, size) {\n const factor = Math.pow(10, size);\n return Math.floor(number * factor) / factor;\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 resolvePromise(promise, catchError) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n catchError && catchError(err);\n throw err;\n });\n}\nexport function voidPromise(promise, catchError) {\n return promise\n .then(() => undefined)\n .catch((err) => {\n catchError && catchError(err);\n return undefined;\n });\n}\nexport function catchPromise(promise, catchError) {\n return promise.catch((err) => {\n catchError && catchError(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 let _isRequesting = false;\n function isInstanced() {\n return itIsDefined(promise$);\n }\n function isRequesting() {\n return _isRequesting;\n }\n function resolve() {\n if (!promise$) {\n _isRequesting = true;\n promise$ = callback()\n .catch((err) => {\n const errorValue = catchError && catchError(err);\n reset();\n if (errorValue) {\n return errorValue;\n }\n throw err;\n })\n .finally(() => {\n _isRequesting = false;\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 {\n isInstanced,\n isRequesting,\n refresh,\n reset,\n resolve\n };\n}\n//# sourceMappingURL=promises.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction isModelHidden(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(link) {\n this.links.push(link);\n }\n refresh(refresh) {\n const { entity, model, relationable } = refresh;\n relationable && this.relation(entity, model);\n this.refreshs.push(refresh);\n }\n sync(sync) {\n const { entity, model, relationable } = sync;\n relationable && this.relation(entity, model);\n this.syncs.push(sync);\n }\n destroy(entity) {\n const optional = this.select(entity);\n if (optional.isPresent()) {\n const model = optional.get();\n isModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n }\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation(entity, model) {\n this.relations.set(entity, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select(entity) {\n return Optional.build(this.relations.has(entity) ? this.relations.get(entity) : undefined);\n }\n async flush() {\n const results = [\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 ];\n this.dispose();\n return results;\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(async (link) => {\n const model = await fromPromise(link.create(this));\n link.relationable && this.relation(link.entity, model);\n return this.dataSource.insert(model);\n }));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map((refresh) => {\n refresh.setManager(this);\n return this.dataSource.refresh(refresh);\n }));\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(this);\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.dataSource.update(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 isModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityLink {\n constructor(entity, relationable = true) {\n this.entity = entity;\n this.relationable = relationable;\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 setManager(manager) {\n this.manager = manager;\n }\n async execute() {\n this.refresh(this.manager);\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.dirty = this.createDirtyFromModel(model);\n }\n verify(manager) {\n this.sync(manager);\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.entries(model).forEach(([key, value]) => {\n dirty[key] = value;\n });\n return dirty;\n }\n createDirty() {\n const _model = this.createDirtyFromModel(this.model);\n const _dirty = {};\n Object.entries(_model).forEach(([key, value]) => {\n if (_model[key] !== this.dirty[key]) {\n _dirty[key] = value;\n }\n });\n const requiredUpdate = Object.keys(_dirty).length > 0;\n if (requiredUpdate && isModelEditable(this.model)) {\n _dirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? _dirty : 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","export class PersistentUnitResult {\n constructor(code, error, model) {\n this.code = code;\n this.error = error;\n this.model = model;\n }\n}\n//# sourceMappingURL=result.js.map"],"names":[],"mappings":"AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;AACtC;;ACyCO,SAAS,WAAW,CAAC,KAAK,EAAE;AACnC,IAAI,OAAO,OAAO,KAAK,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,CAAC;AAClC,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;AACpC,QAAQ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACzB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js","../esm/result.js"],"sourcesContent":["export class AbstractEntityDatabase {\n}\n//# sourceMappingURL=database.js.map","export class AbstractEntityDataSource {\n}\n//# sourceMappingURL=datasource.js.map","import { Optional, fromPromise } from '@rolster/commons';\nfunction isModelHidden(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(link) {\n this.links.push(link);\n }\n refresh(refresh) {\n const { entity, model, relationable } = refresh;\n relationable && this.relation(entity, model);\n this.refreshs.push(refresh);\n }\n sync(sync) {\n const { entity, model, relationable } = sync;\n relationable && this.relation(entity, model);\n this.syncs.push(sync);\n }\n destroy(entity) {\n const optional = this.select(entity);\n if (optional.isPresent()) {\n const model = optional.get();\n isModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n }\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation(entity, model) {\n this.relations.set(entity, model);\n }\n link(entity, model) {\n this.relation(entity, model);\n return entity;\n }\n select(entity) {\n return Optional.build(this.relations.has(entity) ? this.relations.get(entity) : undefined);\n }\n async flush() {\n const results = [\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 ];\n this.dispose();\n return results;\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(async (link) => {\n const model = await fromPromise(link.create(this));\n link.relationable && this.relation(link.entity, model);\n return this.dataSource.insert(model);\n }));\n }\n refreshAll() {\n return Promise.all(this.refreshs.map((refresh) => {\n refresh.setManager(this);\n return this.dataSource.refresh(refresh);\n }));\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(this);\n dirty && syncs.push([sync.model, dirty]);\n return syncs;\n }, [])\n .map(([model, dirty]) => {\n return this.dataSource.update(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 isModelEditable(model) {\n return typeof model === 'object' && 'updatedAt' in model;\n}\nexport class Entity {\n constructor(uuid) {\n this.uuid = uuid;\n }\n}\nexport class EntityLink {\n constructor(entity, relationable = true) {\n this.entity = entity;\n this.relationable = relationable;\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 setManager(manager) {\n this.manager = manager;\n }\n async execute() {\n this.refresh(this.manager);\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.dirty = this.createDirtyFromModel(model);\n }\n verify(manager) {\n this.sync(manager);\n return this.createDirty();\n }\n createDirtyFromModel(model) {\n const dirty = {};\n Object.entries(model).forEach(([key, value]) => {\n dirty[key] = value;\n });\n return dirty;\n }\n createDirty() {\n const _model = this.createDirtyFromModel(this.model);\n const _dirty = {};\n Object.entries(_model).forEach(([key, value]) => {\n if (_model[key] !== this.dirty[key]) {\n _dirty[key] = value;\n }\n });\n const requiredUpdate = Object.keys(_dirty).length > 0;\n if (requiredUpdate && isModelEditable(this.model)) {\n _dirty['updatedAt'] = new Date();\n }\n return requiredUpdate ? _dirty : 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","export class PersistentUnitResult {\n constructor(code, error, model) {\n this.code = code;\n this.error = error;\n this.model = model;\n }\n}\n//# sourceMappingURL=result.js.map"],"names":[],"mappings":";;AAAO,MAAM,sBAAsB,CAAC;AACpC;;ACDO,MAAM,wBAAwB,CAAC;AACtC;;ACAA,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B,IAAI,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,UAAU,IAAI,KAAK,CAAC;AACjF,CAAC;AACM,MAAM,qBAAqB,CAAC;AACnC,CAAC;AACM,MAAM,aAAa,CAAC;AAC3B,IAAI,WAAW,CAAC,UAAU,EAAE;AAC5B,QAAQ,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;AACrC,QAAQ,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;AACxB,QAAQ,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;AACxB,QAAQ,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;AAC3B,QAAQ,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;AAC1B,QAAQ,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;AAC7B,QAAQ,IAAI,CAAC,SA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AG,IAAI,CAAC;AACzB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,KAAK;AACL;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolster/vinegar",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
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",