@rolster/vinegar 2.3.7 → 2.3.9
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
|
@@ -69,7 +69,7 @@ function fromPromise(value) {
|
|
|
69
69
|
return value instanceof Promise ? value : Promise.resolve(value);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
function
|
|
72
|
+
function isModelHidden(model) {
|
|
73
73
|
return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
|
|
74
74
|
}
|
|
75
75
|
class AbstractEntityManager {
|
|
@@ -100,7 +100,7 @@ class EntityManager {
|
|
|
100
100
|
}
|
|
101
101
|
destroy(entity) {
|
|
102
102
|
this.select(entity).present((model) => {
|
|
103
|
-
|
|
103
|
+
isModelHidden(model)
|
|
104
104
|
? this.hiddens.push(model)
|
|
105
105
|
: this.destroys.push(model);
|
|
106
106
|
});
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../../node_modules/@rolster/commons/dist/esm/helpers.js","../../node_modules/@rolster/commons/dist/esm/optional.js","../../node_modules/@rolster/commons/dist/esm/promises.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js","../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 itIsModelHidden(model) {\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\n}\nexport class AbstractEntityManager {\n}\nexport class EntityManager {\n constructor(dataSource) {\n this.dataSource = dataSource;\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n this.relations = new Map();\n }\n persist(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 this.select(entity).present((model) => {\n itIsModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n });\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation(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.manager && 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,G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AAC;AAC3B,KAAK;AACL;;;;;;;;;;;;;;;"}
|
|
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 this.select(entity).present((model) => {\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.manager && 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,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,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AAM,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
|
@@ -65,7 +65,7 @@ function fromPromise(value) {
|
|
|
65
65
|
return value instanceof Promise ? value : Promise.resolve(value);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function
|
|
68
|
+
function isModelHidden(model) {
|
|
69
69
|
return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
|
|
70
70
|
}
|
|
71
71
|
class AbstractEntityManager {
|
|
@@ -96,7 +96,7 @@ class EntityManager {
|
|
|
96
96
|
}
|
|
97
97
|
destroy(entity) {
|
|
98
98
|
this.select(entity).present((model) => {
|
|
99
|
-
|
|
99
|
+
isModelHidden(model)
|
|
100
100
|
? this.hiddens.push(model)
|
|
101
101
|
: this.destroys.push(model);
|
|
102
102
|
});
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../esm/database.js","../esm/datasource.js","../../node_modules/@rolster/commons/dist/esm/helpers.js","../../node_modules/@rolster/commons/dist/esm/optional.js","../../node_modules/@rolster/commons/dist/esm/promises.js","../esm/entity-manager.js","../esm/entity.js","../esm/persistent-unit.js","../esm/procedure.js","../esm/repository.js","../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 itIsModelHidden(model) {\n return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;\n}\nexport class AbstractEntityManager {\n}\nexport class EntityManager {\n constructor(dataSource) {\n this.dataSource = dataSource;\n this.links = [];\n this.refreshs = [];\n this.syncs = [];\n this.destroys = [];\n this.hiddens = [];\n this.procedures = [];\n this.relations = new Map();\n }\n persist(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 this.select(entity).present((model) => {\n itIsModelHidden(model)\n ? this.hiddens.push(model)\n : this.destroys.push(model);\n });\n }\n procedure(procedure) {\n this.procedures.push(procedure);\n }\n relation(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.manager && 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,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,K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C,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","../../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 this.select(entity).present((model) => {\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.manager && 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,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
@@ -19,8 +19,8 @@ export declare abstract class AbstractEntityManager implements QueryEntityManage
|
|
|
19
19
|
abstract flush(): Promise<PersistentUnitResult[]>;
|
|
20
20
|
abstract dispose(): void;
|
|
21
21
|
}
|
|
22
|
-
export declare class EntityManager implements AbstractEntityManager {
|
|
23
|
-
|
|
22
|
+
export declare class EntityManager<D extends AbstractEntityDataSource = AbstractEntityDataSource> implements AbstractEntityManager {
|
|
23
|
+
protected dataSource: D;
|
|
24
24
|
private relations;
|
|
25
25
|
private links;
|
|
26
26
|
private refreshs;
|
|
@@ -28,7 +28,7 @@ export declare class EntityManager implements AbstractEntityManager {
|
|
|
28
28
|
private destroys;
|
|
29
29
|
private hiddens;
|
|
30
30
|
private procedures;
|
|
31
|
-
constructor(dataSource:
|
|
31
|
+
constructor(dataSource: D);
|
|
32
32
|
persist(link: VinegarLink): void;
|
|
33
33
|
refresh(refresh: VinegarRefresh): void;
|
|
34
34
|
sync(sync: VinegarSync): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Optional, fromPromise } from '@rolster/commons';
|
|
2
|
-
function
|
|
2
|
+
function isModelHidden(model) {
|
|
3
3
|
return typeof model === 'object' && 'hidden' in model && 'hiddenAt' in model;
|
|
4
4
|
}
|
|
5
5
|
export class AbstractEntityManager {
|
|
@@ -30,7 +30,7 @@ export class EntityManager {
|
|
|
30
30
|
}
|
|
31
31
|
destroy(entity) {
|
|
32
32
|
this.select(entity).present((model) => {
|
|
33
|
-
|
|
33
|
+
isModelHidden(model)
|
|
34
34
|
? this.hiddens.push(model)
|
|
35
35
|
: this.destroys.push(model);
|
|
36
36
|
});
|
|
@@ -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;AAkBzD,SAAS,
|
|
1
|
+
{"version":3,"file":"entity-manager.js","sourceRoot":"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