@toa.io/core 1.0.0-alpha.3 → 1.0.0-alpha.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"description": "Toa Core",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@rsql/parser": "1.2.4",
|
|
24
|
-
"@toa.io/console": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
26
|
-
"@toa.io/yaml": "1.0.0-alpha.
|
|
24
|
+
"@toa.io/console": "1.0.0-alpha.4",
|
|
25
|
+
"@toa.io/generic": "1.0.0-alpha.4",
|
|
26
|
+
"@toa.io/yaml": "1.0.0-alpha.4",
|
|
27
27
|
"error-value": "0.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"clone-deep": "4.0.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "80a91c0d9c167484247a91e69a0c0a3c344f90d0"
|
|
33
33
|
}
|
package/src/entities/entity.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
difference,
|
|
5
|
+
newid
|
|
6
|
+
} = require('@toa.io/generic')
|
|
4
7
|
|
|
5
8
|
const { EntityContractException } = require('../exceptions')
|
|
6
9
|
|
|
@@ -43,13 +46,23 @@ class Entity {
|
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
#init (id) {
|
|
46
|
-
const value = {
|
|
49
|
+
const value = {
|
|
50
|
+
...this.#schema.defaults({ id }),
|
|
51
|
+
_version: 0
|
|
52
|
+
}
|
|
47
53
|
|
|
48
54
|
this.#set(value)
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
#set (value) {
|
|
52
|
-
Object.defineProperty(value, 'id', {
|
|
58
|
+
Object.defineProperty(value, 'id', {
|
|
59
|
+
writable: false,
|
|
60
|
+
configurable: false
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
if (this.#state !== undefined) {
|
|
64
|
+
value._version++
|
|
65
|
+
}
|
|
53
66
|
|
|
54
67
|
this.#state = value
|
|
55
68
|
}
|
package/src/query/criteria.js
CHANGED
|
@@ -33,9 +33,9 @@ const coerce = (node, properties) => {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const COERCE = {
|
|
36
|
-
number: Number,
|
|
37
|
-
integer: parseInt,
|
|
38
|
-
boolean:
|
|
36
|
+
number: Number.parseFloat,
|
|
37
|
+
integer: Number.parseInt,
|
|
38
|
+
boolean: (value) => value === 'true'
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
exports.criteria = criteria
|
|
@@ -16,10 +16,13 @@ const state = () => ({
|
|
|
16
16
|
_created: generate(),
|
|
17
17
|
_updated: generate(),
|
|
18
18
|
_deleted: generate(),
|
|
19
|
-
_version:
|
|
19
|
+
_version: 0
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
const failed = () => ({
|
|
22
|
+
const failed = () => ({
|
|
23
|
+
...state(),
|
|
24
|
+
fail: true
|
|
25
|
+
})
|
|
23
26
|
|
|
24
27
|
exports.schema = schema
|
|
25
28
|
exports.state = state
|
|
@@ -28,7 +28,10 @@ describe('argument', () => {
|
|
|
28
28
|
it('should provide initial state if no argument passed', () => {
|
|
29
29
|
const entity = new Entity(fixtures.schema)
|
|
30
30
|
const defaults = fixtures.schema.defaults.mock.results[0].value
|
|
31
|
-
const expected = {
|
|
31
|
+
const expected = {
|
|
32
|
+
...defaults,
|
|
33
|
+
_version: 0
|
|
34
|
+
}
|
|
32
35
|
|
|
33
36
|
expect(entity.get()).toStrictEqual(expected)
|
|
34
37
|
})
|
|
@@ -54,7 +57,10 @@ it('should provide event', () => {
|
|
|
54
57
|
expect(event).toEqual({
|
|
55
58
|
state,
|
|
56
59
|
origin,
|
|
57
|
-
changeset: {
|
|
60
|
+
changeset: {
|
|
61
|
+
foo: 'new value',
|
|
62
|
+
_version: 1
|
|
63
|
+
}
|
|
58
64
|
})
|
|
59
65
|
})
|
|
60
66
|
|