@cloudpss/yaml 0.4.15 → 0.4.16

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.
@@ -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
+ `;
@@ -0,0 +1,9 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`can dump set 1`] = `
4
+ "!!js/set
5
+ - 1
6
+ - 2
7
+ - '3'
8
+ "
9
+ `;
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
  }