@cloudpss/yaml 0.4.15 → 0.4.17
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/index.d.ts +1 -1
- package/dist/schema.js +3 -15
- package/dist/schema.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/schema.js +3 -17
- package/tests/__snapshots__/map.js.snap +12 -0
- package/tests/__snapshots__/reference.js.snap +132 -0
- package/tests/__snapshots__/set.js.snap +9 -0
- package/tests/map.js +59 -0
- package/tests/reference.js +90 -0
- package/tests/set.js +31 -0
- package/tests/tsconfig.json +9 -0
- package/tests/types.js +5 -11
- package/tsconfig.json +8 -0
- package/coverage/clover.xml +0 -124
- package/coverage/coverage-final.json +0 -3
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/index.ts.html +0 -157
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/schema.js.html +0 -349
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -179
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import type { LoadOptions, DumpOptions } from 'js-yaml';
|
|
|
3
3
|
export declare function load(str: string, opts?: LoadOptions): unknown;
|
|
4
4
|
/** 序列化为 YAML */
|
|
5
5
|
export declare function dump(obj: unknown, opts?: DumpOptions): string;
|
|
6
|
-
export type { LoadOptions, DumpOptions };
|
|
6
|
+
export type { LoadOptions, DumpOptions } from 'js-yaml';
|
package/dist/schema.js
CHANGED
|
@@ -13,17 +13,7 @@ const buffer = new Type('tag:yaml.org,2002:js/ArrayBuffer', {
|
|
|
13
13
|
instanceOf: ArrayBuffer,
|
|
14
14
|
represent: (object) => fromUint8Array(new Uint8Array(object)),
|
|
15
15
|
});
|
|
16
|
-
const typedArrays = [
|
|
17
|
-
Float32Array,
|
|
18
|
-
Float64Array,
|
|
19
|
-
Uint8Array,
|
|
20
|
-
Uint8ClampedArray,
|
|
21
|
-
Uint16Array,
|
|
22
|
-
Uint32Array,
|
|
23
|
-
Int8Array,
|
|
24
|
-
Int16Array,
|
|
25
|
-
Int32Array,
|
|
26
|
-
].flatMap((c) => {
|
|
16
|
+
const typedArrays = [Float32Array, Float64Array, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array].flatMap((c) => {
|
|
27
17
|
const yamlType = `tag:yaml.org,2002:js/${c.name}`;
|
|
28
18
|
/** @type {import('js-yaml').TypeConstructorOptions} */
|
|
29
19
|
const commonInit = {
|
|
@@ -43,13 +33,11 @@ const typedArrays = [
|
|
|
43
33
|
instanceOf: c,
|
|
44
34
|
defaultStyle: 'base64',
|
|
45
35
|
represent: {
|
|
46
|
-
base64: (
|
|
47
|
-
/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
|
|
36
|
+
base64: (/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
|
|
48
37
|
const buf = new Uint8Array(object.buffer, object.byteOffset, object.byteLength);
|
|
49
38
|
return fromUint8Array(buf);
|
|
50
39
|
},
|
|
51
|
-
sequence: (
|
|
52
|
-
/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
|
|
40
|
+
sequence: (/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
|
|
53
41
|
return [...object];
|
|
54
42
|
},
|
|
55
43
|
},
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources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AAC,CAAC,GAAG,MAAM,CAAC;CACjE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC;IAC9C,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,EAAE,GAAG,CAAC;CAC/C,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudpss/yaml",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.17",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prepublishOnly": "yarn build",
|
|
18
18
|
"clean": "rimraf dist",
|
|
19
19
|
"benchmark": "node ./benchmark",
|
|
20
|
-
"test": "cross-env NODE_OPTIONS
|
|
20
|
+
"test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@types/js-yaml": "^4.0.5",
|
package/src/index.ts
CHANGED
package/src/schema.js
CHANGED
|
@@ -16,17 +16,7 @@ const buffer = new Type('tag:yaml.org,2002:js/ArrayBuffer', {
|
|
|
16
16
|
represent: (object) => fromUint8Array(new Uint8Array(object)),
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const typedArrays = [
|
|
20
|
-
Float32Array,
|
|
21
|
-
Float64Array,
|
|
22
|
-
Uint8Array,
|
|
23
|
-
Uint8ClampedArray,
|
|
24
|
-
Uint16Array,
|
|
25
|
-
Uint32Array,
|
|
26
|
-
Int8Array,
|
|
27
|
-
Int16Array,
|
|
28
|
-
Int32Array,
|
|
29
|
-
].flatMap((c) => {
|
|
19
|
+
const typedArrays = [Float32Array, Float64Array, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array].flatMap((c) => {
|
|
30
20
|
const yamlType = `tag:yaml.org,2002:js/${c.name}`;
|
|
31
21
|
/** @type {import('js-yaml').TypeConstructorOptions} */
|
|
32
22
|
const commonInit = {
|
|
@@ -46,15 +36,11 @@ const typedArrays = [
|
|
|
46
36
|
instanceOf: c,
|
|
47
37
|
defaultStyle: 'base64',
|
|
48
38
|
represent: {
|
|
49
|
-
base64: (
|
|
50
|
-
/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object,
|
|
51
|
-
) => {
|
|
39
|
+
base64: (/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
|
|
52
40
|
const buf = new Uint8Array(object.buffer, object.byteOffset, object.byteLength);
|
|
53
41
|
return fromUint8Array(buf);
|
|
54
42
|
},
|
|
55
|
-
sequence: (
|
|
56
|
-
/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object,
|
|
57
|
-
) => {
|
|
43
|
+
sequence: (/** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
|
|
58
44
|
return [...object];
|
|
59
45
|
},
|
|
60
46
|
},
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`can handle yaml reference 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"actions": {
|
|
6
|
+
"restart": {
|
|
7
|
+
"type": "systemd-restart",
|
|
8
|
+
"unit": "cloudpss-message-stream.service",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
"inputs": {
|
|
12
|
+
"clickhouse.host": null,
|
|
13
|
+
"clickhouse.password": null,
|
|
14
|
+
"clickhouse.port": null,
|
|
15
|
+
"clickhouse.user": null,
|
|
16
|
+
"message_stream.clickhouse_database": {
|
|
17
|
+
"default": "message_stream",
|
|
18
|
+
"description": "ClickHouse database name for message stream",
|
|
19
|
+
"hidden": true,
|
|
20
|
+
"main": true,
|
|
21
|
+
"type": "text",
|
|
22
|
+
},
|
|
23
|
+
"message_stream.mysql_database": {
|
|
24
|
+
"default": "message-stream",
|
|
25
|
+
"description": "MySQL database name for message stream",
|
|
26
|
+
"hidden": true,
|
|
27
|
+
"main": true,
|
|
28
|
+
"type": "text",
|
|
29
|
+
},
|
|
30
|
+
"mysql.host": null,
|
|
31
|
+
"mysql.password": null,
|
|
32
|
+
"mysql.port": null,
|
|
33
|
+
"mysql.user": null,
|
|
34
|
+
"redis.host": null,
|
|
35
|
+
"redis.password": null,
|
|
36
|
+
"redis.port": null,
|
|
37
|
+
},
|
|
38
|
+
"outputs": {
|
|
39
|
+
"clickhouse.host": {
|
|
40
|
+
"key": "CLICKHOUSE_HOST",
|
|
41
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
42
|
+
"post": "restart",
|
|
43
|
+
"type": "env-file",
|
|
44
|
+
"value": "\${config.clickhouse.host}",
|
|
45
|
+
},
|
|
46
|
+
"clickhouse.password": {
|
|
47
|
+
"key": "CLICKHOUSE_PASSWORD",
|
|
48
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
49
|
+
"post": "restart",
|
|
50
|
+
"type": "env-file",
|
|
51
|
+
"value": "\${config.clickhouse.password}",
|
|
52
|
+
},
|
|
53
|
+
"clickhouse.port": {
|
|
54
|
+
"key": "CLICKHOUSE_PORT",
|
|
55
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
56
|
+
"post": "restart",
|
|
57
|
+
"type": "env-file",
|
|
58
|
+
"value": "\${config.clickhouse.port}",
|
|
59
|
+
},
|
|
60
|
+
"clickhouse.user": {
|
|
61
|
+
"key": "CLICKHOUSE_USER",
|
|
62
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
63
|
+
"post": "restart",
|
|
64
|
+
"type": "env-file",
|
|
65
|
+
"value": "\${config.clickhouse.user}",
|
|
66
|
+
},
|
|
67
|
+
"message_stream.clickhouse_database": {
|
|
68
|
+
"key": "CLICKHOUSE_DATABASE",
|
|
69
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
70
|
+
"post": "restart",
|
|
71
|
+
"type": "env-file",
|
|
72
|
+
"value": "\${config.message_stream.clickhouse_database}",
|
|
73
|
+
},
|
|
74
|
+
"message_stream.mysql_database": {
|
|
75
|
+
"key": "MYSQL_DATABASE",
|
|
76
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
77
|
+
"post": "restart",
|
|
78
|
+
"type": "env-file",
|
|
79
|
+
"value": "\${config.message_stream.mysql_database}",
|
|
80
|
+
},
|
|
81
|
+
"mysql.host": {
|
|
82
|
+
"key": "MYSQL_HOST",
|
|
83
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
84
|
+
"post": "restart",
|
|
85
|
+
"type": "env-file",
|
|
86
|
+
"value": "\${config.mysql.host}",
|
|
87
|
+
},
|
|
88
|
+
"mysql.password": {
|
|
89
|
+
"key": "MYSQL_PASSWORD",
|
|
90
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
91
|
+
"post": "restart",
|
|
92
|
+
"type": "env-file",
|
|
93
|
+
"value": "\${config.mysql.password}",
|
|
94
|
+
},
|
|
95
|
+
"mysql.port": {
|
|
96
|
+
"key": "MYSQL_PORT",
|
|
97
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
98
|
+
"post": "restart",
|
|
99
|
+
"type": "env-file",
|
|
100
|
+
"value": "\${config.mysql.port}",
|
|
101
|
+
},
|
|
102
|
+
"mysql.user": {
|
|
103
|
+
"key": "MYSQL_USER",
|
|
104
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
105
|
+
"post": "restart",
|
|
106
|
+
"type": "env-file",
|
|
107
|
+
"value": "\${config.mysql.user}",
|
|
108
|
+
},
|
|
109
|
+
"redis.host": {
|
|
110
|
+
"key": "REDIS_HOST",
|
|
111
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
112
|
+
"post": "restart",
|
|
113
|
+
"type": "env-file",
|
|
114
|
+
"value": "\${config.redis.host}",
|
|
115
|
+
},
|
|
116
|
+
"redis.password": {
|
|
117
|
+
"key": "REDIS_PASSWORD",
|
|
118
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
119
|
+
"post": "restart",
|
|
120
|
+
"type": "env-file",
|
|
121
|
+
"value": "\${config.redis.password}",
|
|
122
|
+
},
|
|
123
|
+
"redis.port": {
|
|
124
|
+
"key": "REDIS_PORT",
|
|
125
|
+
"path": "/etc/cloudpss/message-stream.env",
|
|
126
|
+
"post": "restart",
|
|
127
|
+
"type": "env-file",
|
|
128
|
+
"value": "\${config.redis.port}",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
`;
|
package/tests/map.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { load, dump } from '@cloudpss/yaml';
|
|
2
|
+
|
|
3
|
+
describe(`can load map`, () => {
|
|
4
|
+
it(`from pair sequence`, () => {
|
|
5
|
+
const map = load(`!!js/map [['a', 1], ['b', { c: 2 }], [{ d: 3 }, 'e']]`);
|
|
6
|
+
expect(map).toBeInstanceOf(Map);
|
|
7
|
+
expect(map).toEqual(
|
|
8
|
+
new Map(
|
|
9
|
+
/** @type {Array<[unknown, unknown]>} */ ([
|
|
10
|
+
['a', 1],
|
|
11
|
+
['b', { c: 2 }],
|
|
12
|
+
[{ d: 3 }, 'e'],
|
|
13
|
+
]),
|
|
14
|
+
),
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
it(`from null`, () => {
|
|
18
|
+
const map = load(`!!js/map`);
|
|
19
|
+
expect(map).toBeInstanceOf(Map);
|
|
20
|
+
expect(map).toEqual(new Map());
|
|
21
|
+
});
|
|
22
|
+
it(`with duplicate`, () => {
|
|
23
|
+
const map = load(`!!js/map [['a', 1], ['b', { c: 2 }], ['a', 1]]`);
|
|
24
|
+
expect(map).toBeInstanceOf(Map);
|
|
25
|
+
expect(map).toEqual(
|
|
26
|
+
new Map(
|
|
27
|
+
/** @type {Array<[unknown, unknown]>} */ ([
|
|
28
|
+
['a', 1],
|
|
29
|
+
['b', { c: 2 }],
|
|
30
|
+
]),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
it(`with duplicate objects`, () => {
|
|
35
|
+
const map = load(`!!js/map [[{ a: 1 }, 'b'], [{ a: 1 }, 'c']]`);
|
|
36
|
+
expect(map).toBeInstanceOf(Map);
|
|
37
|
+
expect(map).toEqual(
|
|
38
|
+
new Map(
|
|
39
|
+
/** @type {Array<[unknown, unknown]>} */ ([
|
|
40
|
+
[{ a: 1 }, 'b'],
|
|
41
|
+
[{ a: 1 }, 'c'],
|
|
42
|
+
]),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it(`can dump map`, () => {
|
|
49
|
+
const map = new Map(
|
|
50
|
+
/** @type {Array<[unknown, unknown]>} */ ([
|
|
51
|
+
['a', 1],
|
|
52
|
+
['b', { c: 2 }],
|
|
53
|
+
[{ d: 3 }, 'e'],
|
|
54
|
+
]),
|
|
55
|
+
);
|
|
56
|
+
const dumped = dump(map);
|
|
57
|
+
expect(dumped).toMatchSnapshot();
|
|
58
|
+
expect(load(dumped)).toEqual(map);
|
|
59
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { load } from '@cloudpss/yaml';
|
|
2
|
+
|
|
3
|
+
it(`can handle yaml reference`, () => {
|
|
4
|
+
const result = load(`
|
|
5
|
+
inputs:
|
|
6
|
+
mysql.host:
|
|
7
|
+
mysql.port:
|
|
8
|
+
mysql.user:
|
|
9
|
+
mysql.password:
|
|
10
|
+
redis.host:
|
|
11
|
+
redis.port:
|
|
12
|
+
redis.password:
|
|
13
|
+
clickhouse.host:
|
|
14
|
+
clickhouse.port:
|
|
15
|
+
clickhouse.user:
|
|
16
|
+
clickhouse.password:
|
|
17
|
+
message_stream.mysql_database:
|
|
18
|
+
type: text
|
|
19
|
+
main: true
|
|
20
|
+
hidden: true
|
|
21
|
+
description: MySQL database name for message stream
|
|
22
|
+
default: message-stream
|
|
23
|
+
message_stream.clickhouse_database:
|
|
24
|
+
type: text
|
|
25
|
+
main: true
|
|
26
|
+
hidden: true
|
|
27
|
+
description: ClickHouse database name for message stream
|
|
28
|
+
default: message_stream
|
|
29
|
+
outputs:
|
|
30
|
+
mysql.host: &env-file
|
|
31
|
+
type: env-file
|
|
32
|
+
path: /etc/cloudpss/message-stream.env
|
|
33
|
+
key: MYSQL_HOST
|
|
34
|
+
value: \${config.mysql.host}
|
|
35
|
+
post: restart
|
|
36
|
+
mysql.port:
|
|
37
|
+
<<: *env-file
|
|
38
|
+
key: MYSQL_PORT
|
|
39
|
+
value: \${config.mysql.port}
|
|
40
|
+
mysql.user:
|
|
41
|
+
<<: *env-file
|
|
42
|
+
key: MYSQL_USER
|
|
43
|
+
value: \${config.mysql.user}
|
|
44
|
+
mysql.password:
|
|
45
|
+
<<: *env-file
|
|
46
|
+
key: MYSQL_PASSWORD
|
|
47
|
+
value: \${config.mysql.password}
|
|
48
|
+
redis.host:
|
|
49
|
+
<<: *env-file
|
|
50
|
+
key: REDIS_HOST
|
|
51
|
+
value: \${config.redis.host}
|
|
52
|
+
redis.port:
|
|
53
|
+
<<: *env-file
|
|
54
|
+
key: REDIS_PORT
|
|
55
|
+
value: \${config.redis.port}
|
|
56
|
+
redis.password:
|
|
57
|
+
<<: *env-file
|
|
58
|
+
key: REDIS_PASSWORD
|
|
59
|
+
value: \${config.redis.password}
|
|
60
|
+
clickhouse.host:
|
|
61
|
+
<<: *env-file
|
|
62
|
+
key: CLICKHOUSE_HOST
|
|
63
|
+
value: \${config.clickhouse.host}
|
|
64
|
+
clickhouse.port:
|
|
65
|
+
<<: *env-file
|
|
66
|
+
key: CLICKHOUSE_PORT
|
|
67
|
+
value: \${config.clickhouse.port}
|
|
68
|
+
clickhouse.user:
|
|
69
|
+
<<: *env-file
|
|
70
|
+
key: CLICKHOUSE_USER
|
|
71
|
+
value: \${config.clickhouse.user}
|
|
72
|
+
clickhouse.password:
|
|
73
|
+
<<: *env-file
|
|
74
|
+
key: CLICKHOUSE_PASSWORD
|
|
75
|
+
value: \${config.clickhouse.password}
|
|
76
|
+
message_stream.mysql_database:
|
|
77
|
+
<<: *env-file
|
|
78
|
+
key: MYSQL_DATABASE
|
|
79
|
+
value: \${config.message_stream.mysql_database}
|
|
80
|
+
message_stream.clickhouse_database:
|
|
81
|
+
<<: *env-file
|
|
82
|
+
key: CLICKHOUSE_DATABASE
|
|
83
|
+
value: \${config.message_stream.clickhouse_database}
|
|
84
|
+
actions:
|
|
85
|
+
restart:
|
|
86
|
+
type: systemd-restart
|
|
87
|
+
unit: cloudpss-message-stream.service
|
|
88
|
+
`);
|
|
89
|
+
expect(result).toMatchSnapshot();
|
|
90
|
+
});
|
package/tests/set.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { load, dump } from '@cloudpss/yaml';
|
|
2
|
+
|
|
3
|
+
describe(`can load set`, () => {
|
|
4
|
+
it(`from sequence`, () => {
|
|
5
|
+
const set = load(`!!js/set [1, 2, '3']`);
|
|
6
|
+
expect(set).toBeInstanceOf(Set);
|
|
7
|
+
expect(set).toEqual(new Set([1, 2, '3']));
|
|
8
|
+
});
|
|
9
|
+
it(`from null`, () => {
|
|
10
|
+
const set = load(`!!js/set`);
|
|
11
|
+
expect(set).toBeInstanceOf(Set);
|
|
12
|
+
expect(set).toEqual(new Set());
|
|
13
|
+
});
|
|
14
|
+
it(`with duplicate`, () => {
|
|
15
|
+
const set = load(`!!js/set [1, 2, 1]`);
|
|
16
|
+
expect(set).toBeInstanceOf(Set);
|
|
17
|
+
expect(set).toEqual(new Set([1, 2]));
|
|
18
|
+
});
|
|
19
|
+
it(`with duplicate objects`, () => {
|
|
20
|
+
const set = load(`!!js/set [{ a: 1 }, { a: 1 }]`);
|
|
21
|
+
expect(set).toBeInstanceOf(Set);
|
|
22
|
+
expect(set).toEqual(new Set([{ a: 1 }, { a: 1 }]));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it(`can dump set`, () => {
|
|
27
|
+
const set = new Set([1, 2, '3']);
|
|
28
|
+
const dumped = dump(set);
|
|
29
|
+
expect(dumped).toMatchSnapshot();
|
|
30
|
+
expect(load(dumped)).toEqual(set);
|
|
31
|
+
});
|
package/tests/types.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { dump, load } from '@cloudpss/yaml';
|
|
2
2
|
|
|
3
|
-
const TypedArrays = [
|
|
4
|
-
Float32Array,
|
|
5
|
-
Float64Array,
|
|
6
|
-
Uint8Array,
|
|
7
|
-
Uint8ClampedArray,
|
|
8
|
-
Uint16Array,
|
|
9
|
-
Uint32Array,
|
|
10
|
-
Int8Array,
|
|
11
|
-
Int16Array,
|
|
12
|
-
Int32Array,
|
|
13
|
-
];
|
|
3
|
+
const TypedArrays = [Float32Array, Float64Array, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array];
|
|
14
4
|
|
|
15
5
|
it('ArrayBuffer should be dumped as base64', () => {
|
|
16
6
|
const data = new Uint8Array([63, 43, 213, 117, 49, 122, 160, 215]);
|
|
@@ -37,7 +27,9 @@ describe('TypedArray should be dumped as base64', () => {
|
|
|
37
27
|
const buffer = new Uint8Array([63, 43, 213, 117, 49, 122, 160, 215]).buffer;
|
|
38
28
|
const data = new type(buffer);
|
|
39
29
|
const dumped = dump(data, { styles: { [`!!js/${type.name}`]: 'base64' } });
|
|
30
|
+
const dumped2 = dump(data, { styles: { [`!!js/TypedArray`]: 'base64' } });
|
|
40
31
|
expect(dumped).toMatchSnapshot();
|
|
32
|
+
expect(dumped2).toEqual(dumped);
|
|
41
33
|
expect(load(dumped)).toEqual(data);
|
|
42
34
|
});
|
|
43
35
|
}
|
|
@@ -49,7 +41,9 @@ describe('TypedArray should be dumped as array', () => {
|
|
|
49
41
|
const buffer = new Uint8Array([63, 43, 213, 117, 49, 122, 160, 215]).buffer;
|
|
50
42
|
const data = new type(buffer);
|
|
51
43
|
const dumped = dump(data, { styles: { [`!!js/${type.name}`]: 'sequence' } });
|
|
44
|
+
const dumped2 = dump(data, { styles: { [`!!js/TypedArray`]: 'sequence' } });
|
|
52
45
|
expect(dumped).toMatchSnapshot();
|
|
46
|
+
expect(dumped2).toEqual(dumped);
|
|
53
47
|
expect(load(dumped)).toEqual(data);
|
|
54
48
|
});
|
|
55
49
|
}
|
package/tsconfig.json
ADDED
package/coverage/clover.xml
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<coverage generated="1681985606662" clover="3.2.0">
|
|
3
|
-
<project timestamp="1681985606663" name="All files">
|
|
4
|
-
<metrics statements="112" coveredstatements="112" conditionals="23" coveredconditionals="18" methods="13" coveredmethods="13" elements="148" coveredelements="143" complexity="0" loc="112" ncloc="112" packages="1" files="2" classes="2"/>
|
|
5
|
-
<file name="index.ts" path="C:\Users\lzy\Documents\Sources\cloudpssnet\sdk\packages\03-yaml\src\index.ts">
|
|
6
|
-
<metrics statements="24" coveredstatements="24" conditionals="2" coveredconditionals="2" methods="2" coveredmethods="2"/>
|
|
7
|
-
<line num="1" count="1" type="stmt"/>
|
|
8
|
-
<line num="2" count="1" type="stmt"/>
|
|
9
|
-
<line num="3" count="1" type="stmt"/>
|
|
10
|
-
<line num="4" count="1" type="stmt"/>
|
|
11
|
-
<line num="5" count="1" type="stmt"/>
|
|
12
|
-
<line num="6" count="1" type="stmt"/>
|
|
13
|
-
<line num="7" count="1" type="cond" truecount="1" falsecount="0"/>
|
|
14
|
-
<line num="8" count="30" type="stmt"/>
|
|
15
|
-
<line num="9" count="30" type="stmt"/>
|
|
16
|
-
<line num="10" count="30" type="stmt"/>
|
|
17
|
-
<line num="11" count="30" type="stmt"/>
|
|
18
|
-
<line num="12" count="30" type="stmt"/>
|
|
19
|
-
<line num="13" count="1" type="stmt"/>
|
|
20
|
-
<line num="14" count="1" type="cond" truecount="1" falsecount="0"/>
|
|
21
|
-
<line num="15" count="30" type="stmt"/>
|
|
22
|
-
<line num="16" count="30" type="stmt"/>
|
|
23
|
-
<line num="17" count="30" type="stmt"/>
|
|
24
|
-
<line num="18" count="30" type="stmt"/>
|
|
25
|
-
<line num="19" count="30" type="stmt"/>
|
|
26
|
-
<line num="20" count="30" type="stmt"/>
|
|
27
|
-
<line num="21" count="30" type="stmt"/>
|
|
28
|
-
<line num="22" count="30" type="stmt"/>
|
|
29
|
-
<line num="23" count="30" type="stmt"/>
|
|
30
|
-
<line num="24" count="1" type="stmt"/>
|
|
31
|
-
</file>
|
|
32
|
-
<file name="schema.js" path="C:\Users\lzy\Documents\Sources\cloudpssnet\sdk\packages\03-yaml\src\schema.js">
|
|
33
|
-
<metrics statements="88" coveredstatements="88" conditionals="21" coveredconditionals="16" methods="11" coveredmethods="11"/>
|
|
34
|
-
<line num="1" count="1" type="stmt"/>
|
|
35
|
-
<line num="2" count="1" type="stmt"/>
|
|
36
|
-
<line num="3" count="1" type="stmt"/>
|
|
37
|
-
<line num="4" count="1" type="stmt"/>
|
|
38
|
-
<line num="5" count="1" type="stmt"/>
|
|
39
|
-
<line num="6" count="19" type="cond" truecount="1" falsecount="0"/>
|
|
40
|
-
<line num="7" count="19" type="cond" truecount="0" falsecount="1"/>
|
|
41
|
-
<line num="8" count="19" type="stmt"/>
|
|
42
|
-
<line num="9" count="19" type="stmt"/>
|
|
43
|
-
<line num="10" count="1" type="stmt"/>
|
|
44
|
-
<line num="11" count="1" type="stmt"/>
|
|
45
|
-
<line num="12" count="1" type="stmt"/>
|
|
46
|
-
<line num="13" count="1" type="stmt"/>
|
|
47
|
-
<line num="14" count="1" type="cond" truecount="1" falsecount="1"/>
|
|
48
|
-
<line num="15" count="1" type="stmt"/>
|
|
49
|
-
<line num="16" count="1" type="cond" truecount="1" falsecount="0"/>
|
|
50
|
-
<line num="17" count="1" type="stmt"/>
|
|
51
|
-
<line num="18" count="1" type="stmt"/>
|
|
52
|
-
<line num="19" count="1" type="stmt"/>
|
|
53
|
-
<line num="20" count="1" type="stmt"/>
|
|
54
|
-
<line num="21" count="1" type="stmt"/>
|
|
55
|
-
<line num="22" count="1" type="stmt"/>
|
|
56
|
-
<line num="23" count="1" type="stmt"/>
|
|
57
|
-
<line num="24" count="1" type="stmt"/>
|
|
58
|
-
<line num="25" count="1" type="stmt"/>
|
|
59
|
-
<line num="26" count="1" type="stmt"/>
|
|
60
|
-
<line num="27" count="1" type="stmt"/>
|
|
61
|
-
<line num="28" count="1" type="stmt"/>
|
|
62
|
-
<line num="29" count="1" type="cond" truecount="1" falsecount="0"/>
|
|
63
|
-
<line num="30" count="9" type="stmt"/>
|
|
64
|
-
<line num="31" count="9" type="stmt"/>
|
|
65
|
-
<line num="32" count="9" type="stmt"/>
|
|
66
|
-
<line num="33" count="9" type="cond" truecount="1" falsecount="0"/>
|
|
67
|
-
<line num="34" count="27" type="cond" truecount="1" falsecount="0"/>
|
|
68
|
-
<line num="35" count="9" type="stmt"/>
|
|
69
|
-
<line num="36" count="9" type="stmt"/>
|
|
70
|
-
<line num="37" count="18" type="cond" truecount="1" falsecount="0"/>
|
|
71
|
-
<line num="38" count="9" type="stmt"/>
|
|
72
|
-
<line num="39" count="9" type="cond" truecount="1" falsecount="0"/>
|
|
73
|
-
<line num="40" count="27" type="cond" truecount="1" falsecount="0"/>
|
|
74
|
-
<line num="41" count="9" type="stmt"/>
|
|
75
|
-
<line num="42" count="9" type="stmt"/>
|
|
76
|
-
<line num="43" count="27" type="cond" truecount="1" falsecount="1"/>
|
|
77
|
-
<line num="44" count="27" type="stmt"/>
|
|
78
|
-
<line num="45" count="9" type="stmt"/>
|
|
79
|
-
<line num="46" count="9" type="stmt"/>
|
|
80
|
-
<line num="47" count="9" type="stmt"/>
|
|
81
|
-
<line num="48" count="9" type="stmt"/>
|
|
82
|
-
<line num="49" count="9" type="cond" truecount="1" falsecount="0"/>
|
|
83
|
-
<line num="50" count="18" type="stmt"/>
|
|
84
|
-
<line num="51" count="18" type="stmt"/>
|
|
85
|
-
<line num="52" count="18" type="stmt"/>
|
|
86
|
-
<line num="53" count="18" type="stmt"/>
|
|
87
|
-
<line num="54" count="9" type="stmt"/>
|
|
88
|
-
<line num="55" count="9" type="cond" truecount="1" falsecount="0"/>
|
|
89
|
-
<line num="56" count="9" type="stmt"/>
|
|
90
|
-
<line num="57" count="9" type="stmt"/>
|
|
91
|
-
<line num="58" count="9" type="stmt"/>
|
|
92
|
-
<line num="59" count="9" type="stmt"/>
|
|
93
|
-
<line num="60" count="9" type="stmt"/>
|
|
94
|
-
<line num="61" count="9" type="stmt"/>
|
|
95
|
-
<line num="62" count="9" type="stmt"/>
|
|
96
|
-
<line num="63" count="9" type="stmt"/>
|
|
97
|
-
<line num="64" count="9" type="stmt"/>
|
|
98
|
-
<line num="65" count="9" type="stmt"/>
|
|
99
|
-
<line num="66" count="9" type="stmt"/>
|
|
100
|
-
<line num="67" count="9" type="stmt"/>
|
|
101
|
-
<line num="68" count="9" type="stmt"/>
|
|
102
|
-
<line num="69" count="9" type="stmt"/>
|
|
103
|
-
<line num="70" count="9" type="stmt"/>
|
|
104
|
-
<line num="71" count="9" type="stmt"/>
|
|
105
|
-
<line num="72" count="1" type="stmt"/>
|
|
106
|
-
<line num="73" count="1" type="stmt"/>
|
|
107
|
-
<line num="74" count="1" type="stmt"/>
|
|
108
|
-
<line num="75" count="1" type="cond" truecount="1" falsecount="1"/>
|
|
109
|
-
<line num="76" count="1" type="stmt"/>
|
|
110
|
-
<line num="77" count="1" type="cond" truecount="1" falsecount="0"/>
|
|
111
|
-
<line num="78" count="1" type="stmt"/>
|
|
112
|
-
<line num="79" count="1" type="stmt"/>
|
|
113
|
-
<line num="80" count="1" type="stmt"/>
|
|
114
|
-
<line num="81" count="1" type="cond" truecount="1" falsecount="1"/>
|
|
115
|
-
<line num="82" count="1" type="stmt"/>
|
|
116
|
-
<line num="83" count="1" type="cond" truecount="1" falsecount="0"/>
|
|
117
|
-
<line num="84" count="1" type="stmt"/>
|
|
118
|
-
<line num="85" count="1" type="stmt"/>
|
|
119
|
-
<line num="86" count="1" type="stmt"/>
|
|
120
|
-
<line num="87" count="1" type="stmt"/>
|
|
121
|
-
<line num="88" count="1" type="stmt"/>
|
|
122
|
-
</file>
|
|
123
|
-
</project>
|
|
124
|
-
</coverage>
|