@thisisagile/easy
Advanced tools
Comparing version 1.14.6 to 1.14.7
import { Record } from './Record'; | ||
import { Id } from '../types'; | ||
import { Id, Json } from '../types'; | ||
export declare abstract class Entity extends Record { | ||
readonly id: Id; | ||
toJSON(add?: Json): Json; | ||
} | ||
export declare const isEntity: (e?: unknown) => e is Entity; |
@@ -14,2 +14,3 @@ "use strict"; | ||
const Record_1 = require("./Record"); | ||
const types_1 = require("../types"); | ||
const validation_1 = require("../validation"); | ||
@@ -21,2 +22,5 @@ class Entity extends Record_1.Record { | ||
} | ||
toJSON(add = {}) { | ||
return types_1.toJson({ ...this, ...add, id: this.state.id, state: undefined }); | ||
} | ||
} | ||
@@ -23,0 +27,0 @@ __decorate([ |
@@ -6,4 +6,4 @@ import { Json, Validatable } from '../types'; | ||
get isValid(): boolean; | ||
toJSON(): Json; | ||
update: (add?: unknown) => Record; | ||
toJSON(add?: Json): Json; | ||
update: (add?: Json) => Record; | ||
} |
@@ -14,4 +14,4 @@ "use strict"; | ||
} | ||
toJSON() { | ||
return types_1.jsonify({ ...this, state: undefined }); | ||
toJSON(add = {}) { | ||
return types_1.toJson({ ...this, ...add, state: undefined }); | ||
} | ||
@@ -18,0 +18,0 @@ } |
@@ -8,3 +8,2 @@ export declare type JsonValue = string | number | boolean | null | Json | JsonValue[]; | ||
}; | ||
export declare const jsonify: (subject?: unknown) => Json; | ||
export declare const toJson: (subject?: unknown, add?: unknown) => Json; | ||
export declare const toJson: (...items: unknown[]) => Json; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toJson = exports.jsonify = exports.isJson = void 0; | ||
exports.toJson = exports.isJson = void 0; | ||
const IsA_1 = require("./IsA"); | ||
const isJson = (subject) => IsA_1.isA(subject, 'toJSON'); | ||
exports.isJson = isJson; | ||
const jsonify = (subject = {}) => ({ ...JSON.parse(JSON.stringify(subject)) }); | ||
exports.jsonify = jsonify; | ||
const toJson = (subject = {}, add = {}) => ({ | ||
...(exports.isJson(subject) ? subject.toJSON() : exports.jsonify(subject)), | ||
...(exports.isJson(add) ? add.toJSON() : exports.jsonify(add)), | ||
}); | ||
const toJson = (...items) => items.map(i => JSON.parse(JSON.stringify(i !== null && i !== void 0 ? i : {}))).reduce((json, j) => ({ ...json, ...j }), {}); | ||
exports.toJson = toJson; | ||
//# sourceMappingURL=Json.js.map |
{ | ||
"name": "@thisisagile/easy", | ||
"version": "1.14.6", | ||
"version": "1.14.7", | ||
"description": "Straightforward library for building domain-driven microservice architectures", | ||
@@ -5,0 +5,0 @@ "author": "Sander Hoogendoorn", |
import { Record } from './Record'; | ||
import { Id } from '../types'; | ||
import { Id, Json, toJson } from '../types'; | ||
import { required } from '../validation'; | ||
@@ -7,4 +7,8 @@ | ||
@required() readonly id: Id = this.state.id; | ||
toJSON(add: Json = {}): Json { | ||
return toJson({ ...this, ...add, id: this.state.id, state: undefined }); | ||
} | ||
} | ||
export const isEntity = (e?: unknown): e is Entity => e instanceof Entity; |
@@ -1,2 +0,2 @@ | ||
import { Json, jsonify, Validatable } from '../types'; | ||
import { Json, toJson, Validatable } from '../types'; | ||
import { validate } from '../validation'; | ||
@@ -11,7 +11,7 @@ | ||
toJSON(): Json { | ||
return jsonify({ ...this, state: undefined }); | ||
toJSON(add: Json = {}): Json { | ||
return toJson({ ...this, ...add, state: undefined }); | ||
} | ||
update = (add?: unknown): Record => this; | ||
update = (add?: Json): Record => this; | ||
} |
@@ -8,7 +8,2 @@ import { isA } from './IsA'; | ||
export const jsonify = (subject: unknown = {}): Json => ({ ...JSON.parse(JSON.stringify(subject)) }); | ||
export const toJson = (subject: unknown = {}, add: unknown = {}): Json => ({ | ||
...(isJson(subject) ? subject.toJSON() : jsonify(subject)), | ||
...(isJson(add) ? add.toJSON() : jsonify(add)), | ||
}); | ||
export const toJson = (...items: unknown[]): Json => items.map(i => JSON.parse(JSON.stringify(i ?? {}))).reduce((json, j) => ({ ...json, ...j }), {}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
150942
2306