ipld-schema-describer 1.0.10 → 2.0.1

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.
@@ -1,297 +0,0 @@
1
- 'use strict';
2
-
3
- var ipldSchemaDescriber = require('../ipld-schema-describer.js');
4
- var chai = require('chai');
5
-
6
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
-
8
- var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
9
-
10
- const {assert} = chai__default["default"];
11
- const fauxCID = {};
12
- fauxCID.asCID = fauxCID;
13
- function verify(obj, expected) {
14
- const description = ipldSchemaDescriber.describe(obj);
15
- assert.deepEqual(description, expected);
16
- }
17
- describe('Basics', () => {
18
- it('null', () => {
19
- const expected = {
20
- schema: { types: { Null: { kind: 'null' } } },
21
- root: 'Null'
22
- };
23
- verify(null, expected);
24
- });
25
- it('bool', () => {
26
- const expected = {
27
- schema: { types: { Bool: { kind: 'bool' } } },
28
- root: 'Bool'
29
- };
30
- verify(true, expected);
31
- verify(false, expected);
32
- });
33
- it('int', () => {
34
- const expected = {
35
- schema: { types: { Int: { kind: 'int' } } },
36
- root: 'Int'
37
- };
38
- verify(101, expected);
39
- verify(-101, expected);
40
- verify(0, expected);
41
- });
42
- it('float', () => {
43
- const expected = {
44
- schema: { types: { Float: { kind: 'float' } } },
45
- root: 'Float'
46
- };
47
- verify(1.01, expected);
48
- verify(-1.01, expected);
49
- });
50
- it('string', () => {
51
- const expected = {
52
- schema: { types: { String: { kind: 'string' } } },
53
- root: 'String'
54
- };
55
- verify('a string', expected);
56
- verify('', expected);
57
- });
58
- it('link', () => {
59
- const expected = {
60
- schema: { types: { Link: { kind: 'link' } } },
61
- root: 'Link'
62
- };
63
- verify(fauxCID, expected);
64
- });
65
- it('bytes', () => {
66
- const expected = {
67
- schema: { types: { Bytes: { kind: 'bytes' } } },
68
- root: 'Bytes'
69
- };
70
- verify(Uint8Array.from([
71
- 1,
72
- 3,
73
- 4,
74
- 5
75
- ]), expected);
76
- verify(Uint8Array.from([]), expected);
77
- });
78
- it('map', () => {
79
- const obj = {
80
- s1: 'a string',
81
- s2: 'second string',
82
- s3: 'third string'
83
- };
84
- const expected = {
85
- schema: {
86
- types: {
87
- Map_1: {
88
- kind: 'map',
89
- keyType: 'String',
90
- valueType: 'String'
91
- }
92
- }
93
- },
94
- root: 'Map_1'
95
- };
96
- verify(obj, expected);
97
- });
98
- it('empty map', () => {
99
- const obj = {};
100
- const expected = {
101
- schema: {
102
- types: {
103
- Map_1: {
104
- kind: 'map',
105
- keyType: 'String',
106
- valueType: 'Any'
107
- }
108
- }
109
- },
110
- root: 'Map_1'
111
- };
112
- verify(obj, expected);
113
- });
114
- it('struct (map repr)', () => {
115
- const obj = {
116
- s: 'a string',
117
- i: 101,
118
- l: fauxCID
119
- };
120
- const expected = {
121
- schema: {
122
- types: {
123
- Struct_1: {
124
- kind: 'struct',
125
- fields: {
126
- s: { type: 'String' },
127
- i: { type: 'Int' },
128
- l: { type: { kind: 'link' } }
129
- }
130
- }
131
- }
132
- },
133
- root: 'Struct_1'
134
- };
135
- verify(obj, expected);
136
- });
137
- it('list', () => {
138
- const obj = [
139
- 'a string',
140
- 'second string',
141
- 'third string'
142
- ];
143
- const expected = {
144
- schema: {
145
- types: {
146
- List_1: {
147
- kind: 'list',
148
- valueType: 'String'
149
- }
150
- }
151
- },
152
- root: 'List_1'
153
- };
154
- verify(obj, expected);
155
- });
156
- it('empty list', () => {
157
- const obj = [];
158
- const expected = {
159
- schema: {
160
- types: {
161
- List_1: {
162
- kind: 'list',
163
- valueType: 'Any'
164
- }
165
- }
166
- },
167
- root: 'List_1'
168
- };
169
- verify(obj, expected);
170
- });
171
- it('struct (list repr)', () => {
172
- const obj = [
173
- 'a string',
174
- 101,
175
- false,
176
- null
177
- ];
178
- const expected = {
179
- schema: {
180
- types: {
181
- Struct_1: {
182
- kind: 'struct',
183
- fields: {
184
- f0: { type: 'String' },
185
- f1: { type: 'Int' },
186
- f2: { type: 'Bool' },
187
- f3: { type: 'Null' }
188
- },
189
- representation: { tuple: {} }
190
- }
191
- }
192
- },
193
- root: 'Struct_1'
194
- };
195
- verify(obj, expected);
196
- });
197
- });
198
- describe('Complex', () => {
199
- it('list of lists', () => {
200
- const sa = [
201
- 'a string',
202
- 'second string',
203
- 'third string'
204
- ];
205
- const obj = [
206
- sa,
207
- sa.slice(),
208
- sa.slice()
209
- ];
210
- const expected = {
211
- schema: {
212
- types: {
213
- List_1: {
214
- kind: 'list',
215
- valueType: 'String'
216
- },
217
- List_2: {
218
- kind: 'list',
219
- valueType: 'List_1'
220
- }
221
- }
222
- },
223
- root: 'List_2'
224
- };
225
- verify(obj, expected);
226
- });
227
- it('map of maps', () => {
228
- const sm = {
229
- s1: 'a string',
230
- s2: 'second string',
231
- s3: 'third string'
232
- };
233
- const obj = {
234
- sm1: sm,
235
- sm2: Object.assign({}, sm),
236
- sm3: Object.assign({}, sm)
237
- };
238
- const expected = {
239
- schema: {
240
- types: {
241
- Map_1: {
242
- kind: 'map',
243
- keyType: 'String',
244
- valueType: 'String'
245
- },
246
- Map_2: {
247
- kind: 'map',
248
- keyType: 'String',
249
- valueType: 'Map_1'
250
- }
251
- }
252
- },
253
- root: 'Map_2'
254
- };
255
- verify(obj, expected);
256
- });
257
- it('struct of structs', () => {
258
- const obj = [
259
- 'a string',
260
- 101,
261
- [
262
- 's',
263
- false
264
- ],
265
- [
266
- '',
267
- true
268
- ]
269
- ];
270
- const expected = {
271
- schema: {
272
- types: {
273
- Struct_1: {
274
- kind: 'struct',
275
- fields: {
276
- f0: { type: 'String' },
277
- f1: { type: 'Bool' }
278
- },
279
- representation: { tuple: {} }
280
- },
281
- Struct_2: {
282
- kind: 'struct',
283
- fields: {
284
- f0: { type: 'String' },
285
- f1: { type: 'Int' },
286
- f2: { type: 'Struct_1' },
287
- f3: { type: 'Struct_1' }
288
- },
289
- representation: { tuple: {} }
290
- }
291
- }
292
- },
293
- root: 'Struct_2'
294
- };
295
- verify(obj, expected);
296
- });
297
- });
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- var ipldSchemaDescriber = require('../ipld-schema-describer.js');
4
- var chai = require('chai');
5
-
6
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
-
8
- var chai__default = /*#__PURE__*/_interopDefaultLegacy(chai);
9
-
10
- const {assert} = chai__default["default"];
11
- describe('Errors', () => {
12
- it('bad kind', () => {
13
- assert.throws(() => ipldSchemaDescriber.describe(undefined), /Unknown IPLD kind for value: undefined/);
14
- });
15
- });
@@ -1,290 +0,0 @@
1
- import { describe as describeSchema } from '../ipld-schema-describer.js';
2
- import chai from 'chai';
3
- const {assert} = chai;
4
- const fauxCID = {};
5
- fauxCID.asCID = fauxCID;
6
- function verify(obj, expected) {
7
- const description = describeSchema(obj);
8
- assert.deepEqual(description, expected);
9
- }
10
- describe('Basics', () => {
11
- it('null', () => {
12
- const expected = {
13
- schema: { types: { Null: { kind: 'null' } } },
14
- root: 'Null'
15
- };
16
- verify(null, expected);
17
- });
18
- it('bool', () => {
19
- const expected = {
20
- schema: { types: { Bool: { kind: 'bool' } } },
21
- root: 'Bool'
22
- };
23
- verify(true, expected);
24
- verify(false, expected);
25
- });
26
- it('int', () => {
27
- const expected = {
28
- schema: { types: { Int: { kind: 'int' } } },
29
- root: 'Int'
30
- };
31
- verify(101, expected);
32
- verify(-101, expected);
33
- verify(0, expected);
34
- });
35
- it('float', () => {
36
- const expected = {
37
- schema: { types: { Float: { kind: 'float' } } },
38
- root: 'Float'
39
- };
40
- verify(1.01, expected);
41
- verify(-1.01, expected);
42
- });
43
- it('string', () => {
44
- const expected = {
45
- schema: { types: { String: { kind: 'string' } } },
46
- root: 'String'
47
- };
48
- verify('a string', expected);
49
- verify('', expected);
50
- });
51
- it('link', () => {
52
- const expected = {
53
- schema: { types: { Link: { kind: 'link' } } },
54
- root: 'Link'
55
- };
56
- verify(fauxCID, expected);
57
- });
58
- it('bytes', () => {
59
- const expected = {
60
- schema: { types: { Bytes: { kind: 'bytes' } } },
61
- root: 'Bytes'
62
- };
63
- verify(Uint8Array.from([
64
- 1,
65
- 3,
66
- 4,
67
- 5
68
- ]), expected);
69
- verify(Uint8Array.from([]), expected);
70
- });
71
- it('map', () => {
72
- const obj = {
73
- s1: 'a string',
74
- s2: 'second string',
75
- s3: 'third string'
76
- };
77
- const expected = {
78
- schema: {
79
- types: {
80
- Map_1: {
81
- kind: 'map',
82
- keyType: 'String',
83
- valueType: 'String'
84
- }
85
- }
86
- },
87
- root: 'Map_1'
88
- };
89
- verify(obj, expected);
90
- });
91
- it('empty map', () => {
92
- const obj = {};
93
- const expected = {
94
- schema: {
95
- types: {
96
- Map_1: {
97
- kind: 'map',
98
- keyType: 'String',
99
- valueType: 'Any'
100
- }
101
- }
102
- },
103
- root: 'Map_1'
104
- };
105
- verify(obj, expected);
106
- });
107
- it('struct (map repr)', () => {
108
- const obj = {
109
- s: 'a string',
110
- i: 101,
111
- l: fauxCID
112
- };
113
- const expected = {
114
- schema: {
115
- types: {
116
- Struct_1: {
117
- kind: 'struct',
118
- fields: {
119
- s: { type: 'String' },
120
- i: { type: 'Int' },
121
- l: { type: { kind: 'link' } }
122
- }
123
- }
124
- }
125
- },
126
- root: 'Struct_1'
127
- };
128
- verify(obj, expected);
129
- });
130
- it('list', () => {
131
- const obj = [
132
- 'a string',
133
- 'second string',
134
- 'third string'
135
- ];
136
- const expected = {
137
- schema: {
138
- types: {
139
- List_1: {
140
- kind: 'list',
141
- valueType: 'String'
142
- }
143
- }
144
- },
145
- root: 'List_1'
146
- };
147
- verify(obj, expected);
148
- });
149
- it('empty list', () => {
150
- const obj = [];
151
- const expected = {
152
- schema: {
153
- types: {
154
- List_1: {
155
- kind: 'list',
156
- valueType: 'Any'
157
- }
158
- }
159
- },
160
- root: 'List_1'
161
- };
162
- verify(obj, expected);
163
- });
164
- it('struct (list repr)', () => {
165
- const obj = [
166
- 'a string',
167
- 101,
168
- false,
169
- null
170
- ];
171
- const expected = {
172
- schema: {
173
- types: {
174
- Struct_1: {
175
- kind: 'struct',
176
- fields: {
177
- f0: { type: 'String' },
178
- f1: { type: 'Int' },
179
- f2: { type: 'Bool' },
180
- f3: { type: 'Null' }
181
- },
182
- representation: { tuple: {} }
183
- }
184
- }
185
- },
186
- root: 'Struct_1'
187
- };
188
- verify(obj, expected);
189
- });
190
- });
191
- describe('Complex', () => {
192
- it('list of lists', () => {
193
- const sa = [
194
- 'a string',
195
- 'second string',
196
- 'third string'
197
- ];
198
- const obj = [
199
- sa,
200
- sa.slice(),
201
- sa.slice()
202
- ];
203
- const expected = {
204
- schema: {
205
- types: {
206
- List_1: {
207
- kind: 'list',
208
- valueType: 'String'
209
- },
210
- List_2: {
211
- kind: 'list',
212
- valueType: 'List_1'
213
- }
214
- }
215
- },
216
- root: 'List_2'
217
- };
218
- verify(obj, expected);
219
- });
220
- it('map of maps', () => {
221
- const sm = {
222
- s1: 'a string',
223
- s2: 'second string',
224
- s3: 'third string'
225
- };
226
- const obj = {
227
- sm1: sm,
228
- sm2: Object.assign({}, sm),
229
- sm3: Object.assign({}, sm)
230
- };
231
- const expected = {
232
- schema: {
233
- types: {
234
- Map_1: {
235
- kind: 'map',
236
- keyType: 'String',
237
- valueType: 'String'
238
- },
239
- Map_2: {
240
- kind: 'map',
241
- keyType: 'String',
242
- valueType: 'Map_1'
243
- }
244
- }
245
- },
246
- root: 'Map_2'
247
- };
248
- verify(obj, expected);
249
- });
250
- it('struct of structs', () => {
251
- const obj = [
252
- 'a string',
253
- 101,
254
- [
255
- 's',
256
- false
257
- ],
258
- [
259
- '',
260
- true
261
- ]
262
- ];
263
- const expected = {
264
- schema: {
265
- types: {
266
- Struct_1: {
267
- kind: 'struct',
268
- fields: {
269
- f0: { type: 'String' },
270
- f1: { type: 'Bool' }
271
- },
272
- representation: { tuple: {} }
273
- },
274
- Struct_2: {
275
- kind: 'struct',
276
- fields: {
277
- f0: { type: 'String' },
278
- f1: { type: 'Int' },
279
- f2: { type: 'Struct_1' },
280
- f3: { type: 'Struct_1' }
281
- },
282
- representation: { tuple: {} }
283
- }
284
- }
285
- },
286
- root: 'Struct_2'
287
- };
288
- verify(obj, expected);
289
- });
290
- });
@@ -1,8 +0,0 @@
1
- import { describe as describeSchema } from '../ipld-schema-describer.js';
2
- import chai from 'chai';
3
- const {assert} = chai;
4
- describe('Errors', () => {
5
- it('bad kind', () => {
6
- assert.throws(() => describeSchema(undefined), /Unknown IPLD kind for value: undefined/);
7
- });
8
- });