File tree Expand file tree Collapse file tree 3 files changed +438
-11
lines changed Expand file tree Collapse file tree 3 files changed +438
-11
lines changed Original file line number Diff line number Diff line change
1
+ import internalSchemaToMongoDB from './schema-convertors/internalToMongoDB' ;
1
2
import { Schema as InternalSchema } from './schema-analyzer' ;
2
- import { ExtendedJSONSchema , MongoDBJSONSchema , StandardJSONSchema } from './types' ;
3
+ import { ExtendedJSONSchema , StandardJSONSchema } from './types' ;
3
4
4
5
function internalSchemaToStandard (
5
6
internalSchema : InternalSchema ,
6
7
options : {
7
8
signal ?: AbortSignal
8
9
} ) : StandardJSONSchema {
9
10
// TODO: COMPASS-8700
10
- return { } ;
11
- }
12
-
13
- function internalSchemaToMongoDB (
14
- internalSchema : InternalSchema ,
15
- options : {
16
- signal ?: AbortSignal
17
- } ) : MongoDBJSONSchema {
18
- // TODO: COMPASS-8701
19
- return { } as MongoDBJSONSchema ;
11
+ return { } as StandardJSONSchema ;
20
12
}
21
13
22
14
function internalSchemaToExtended (
Original file line number Diff line number Diff line change
1
+ import assert from 'assert' ;
2
+ import internalSchemaToStandard from './internalToMongodb' ;
3
+
4
+ describe . only ( 'internalSchemaToStandard' , function ( ) {
5
+ describe ( 'Converts: ' , function ( ) {
6
+ it ( 'document/object' , function ( ) {
7
+ const internal = {
8
+ count : 2 ,
9
+ fields : [
10
+ {
11
+ name : 'author' ,
12
+ path : [
13
+ 'author'
14
+ ] ,
15
+ count : 1 ,
16
+ type : [
17
+ 'Document' ,
18
+ 'Undefined'
19
+ ] ,
20
+ probability : 1 ,
21
+ hasDuplicates : false ,
22
+ types : [
23
+ {
24
+ name : 'Document' ,
25
+ path : [
26
+ 'author'
27
+ ] ,
28
+ count : 1 ,
29
+ probability : 0.5 ,
30
+ bsonType : 'Document' ,
31
+ fields : [
32
+ {
33
+ name : 'name' ,
34
+ path : [
35
+ 'author' ,
36
+ 'name'
37
+ ] ,
38
+ count : 1 ,
39
+ type : 'String' ,
40
+ probability : 1 ,
41
+ hasDuplicates : false ,
42
+ types : [
43
+ {
44
+ name : 'String' ,
45
+ path : [
46
+ 'author' ,
47
+ 'name'
48
+ ] ,
49
+ count : 1 ,
50
+ probability : 1 ,
51
+ unique : 1 ,
52
+ hasDuplicates : false ,
53
+ values : [
54
+ 'Peter Sonder'
55
+ ] ,
56
+ bsonType : 'String'
57
+ }
58
+ ]
59
+ } ,
60
+ {
61
+ name : 'rating' ,
62
+ path : [
63
+ 'author' ,
64
+ 'rating'
65
+ ] ,
66
+ count : 1 ,
67
+ type : 'Double' ,
68
+ probability : 1 ,
69
+ hasDuplicates : false ,
70
+ types : [
71
+ {
72
+ name : 'Double' ,
73
+ path : [
74
+ 'author' ,
75
+ 'rating'
76
+ ] ,
77
+ count : 1 ,
78
+ probability : 1 ,
79
+ unique : 1 ,
80
+ hasDuplicates : false ,
81
+ values : [
82
+ 1.3
83
+ ] ,
84
+ bsonType : 'Double'
85
+ }
86
+ ]
87
+ }
88
+ ]
89
+ } ,
90
+ {
91
+ name : 'Undefined' ,
92
+ bsonType : 'Undefined' ,
93
+ unique : 1 ,
94
+ hasDuplicates : false ,
95
+ path : [
96
+ 'author'
97
+ ] ,
98
+ count : 1 ,
99
+ probability : 0.5
100
+ }
101
+ ]
102
+ }
103
+ ]
104
+ } ;
105
+ const standard = internalSchemaToStandard ( internal ) ;
106
+ assert . deepStrictEqual ( standard , {
107
+ bsonType : 'object' ,
108
+ required : [ 'author' ] ,
109
+ properties : {
110
+ author : {
111
+ bsonType : 'object' ,
112
+ required : [ 'name' , 'rating' ] ,
113
+ properties : {
114
+ name : {
115
+ bsonType : 'string'
116
+ } ,
117
+ rating : {
118
+ bsonType : 'double'
119
+ }
120
+ }
121
+ }
122
+ }
123
+ } ) ;
124
+ } ) ;
125
+
126
+ it ( 'array - single type' , function ( ) {
127
+ const internal = {
128
+ count : 2 ,
129
+ fields : [
130
+ {
131
+ name : 'genres' ,
132
+ path : [
133
+ 'genres'
134
+ ] ,
135
+ count : 1 ,
136
+ type : [
137
+ 'array' ,
138
+ 'Undefined'
139
+ ] ,
140
+ probability : 0.5 ,
141
+ hasDuplicates : false ,
142
+ types : [
143
+ {
144
+ name : 'array' ,
145
+ path : [
146
+ 'genres'
147
+ ] ,
148
+ count : 1 ,
149
+ probability : 0.5 ,
150
+ bsonType : 'Array' ,
151
+ types : [
152
+ {
153
+ name : 'String' ,
154
+ path : [
155
+ 'genres'
156
+ ] ,
157
+ count : 2 ,
158
+ probability : 1 ,
159
+ unique : 2 ,
160
+ hasDuplicates : false ,
161
+ values : [
162
+ 'crimi' ,
163
+ 'comedy'
164
+ ] ,
165
+ bsonType : 'String'
166
+ }
167
+ ] ,
168
+ totalCount : 2 ,
169
+ lengths : [
170
+ 2
171
+ ] ,
172
+ averageLength : 2
173
+ } ,
174
+ {
175
+ name : 'Undefined' ,
176
+ bsonType : 'Undefined' ,
177
+ unique : 1 ,
178
+ hasDuplicates : false ,
179
+ path : [
180
+ 'genres'
181
+ ] ,
182
+ count : 1 ,
183
+ probability : 0.5
184
+ }
185
+ ]
186
+ }
187
+ ]
188
+ } ;
189
+ const standard = internalSchemaToStandard ( internal ) ;
190
+ assert . deepStrictEqual ( standard , {
191
+ bsonType : 'object' ,
192
+ required : [ ] ,
193
+ properties : {
194
+ genres : {
195
+ bsonType : 'array' ,
196
+ items : {
197
+ bsonType : 'string'
198
+ }
199
+ }
200
+ }
201
+ } ) ;
202
+ } ) ;
203
+
204
+ it ( 'array - complex mixed type' , function ( ) {
205
+ const internal = {
206
+ count : 2 ,
207
+ fields : [
208
+ {
209
+ name : 'genres' ,
210
+ path : [
211
+ 'genres'
212
+ ] ,
213
+ count : 1 ,
214
+ type : [
215
+ 'Array' ,
216
+ 'Undefined'
217
+ ] ,
218
+ probability : 0.5 ,
219
+ hasDuplicates : false ,
220
+ types : [
221
+ {
222
+ name : 'Array' ,
223
+ path : [
224
+ 'genres'
225
+ ] ,
226
+ count : 1 ,
227
+ probability : 0.5 ,
228
+ bsonType : 'Array' ,
229
+ types : [
230
+ {
231
+ name : 'String' ,
232
+ path : [
233
+ 'genres'
234
+ ] ,
235
+ count : 2 ,
236
+ probability : 0.6666666666666666 ,
237
+ unique : 2 ,
238
+ hasDuplicates : false ,
239
+ values : [
240
+ 'crimi' ,
241
+ 'comedy'
242
+ ] ,
243
+ bsonType : 'String'
244
+ } ,
245
+ {
246
+ name : 'Document' ,
247
+ path : [
248
+ 'genres'
249
+ ] ,
250
+ count : 1 ,
251
+ probability : 0.3333333333333333 ,
252
+ bsonType : 'Document' ,
253
+ fields : [
254
+ {
255
+ name : 'long' ,
256
+ path : [
257
+ 'genres' ,
258
+ 'long'
259
+ ] ,
260
+ count : 1 ,
261
+ type : 'String' ,
262
+ probability : 1 ,
263
+ hasDuplicates : false ,
264
+ types : [
265
+ {
266
+ name : 'String' ,
267
+ path : [
268
+ 'genres' ,
269
+ 'long'
270
+ ] ,
271
+ count : 1 ,
272
+ probability : 1 ,
273
+ unique : 1 ,
274
+ hasDuplicates : false ,
275
+ values : [
276
+ 'science fiction'
277
+ ] ,
278
+ bsonType : 'String'
279
+ }
280
+ ]
281
+ } ,
282
+ {
283
+ name : 'short' ,
284
+ path : [
285
+ 'genres' ,
286
+ 'short'
287
+ ] ,
288
+ count : 1 ,
289
+ type : 'String' ,
290
+ probability : 1 ,
291
+ hasDuplicates : false ,
292
+ types : [
293
+ {
294
+ name : 'String' ,
295
+ path : [
296
+ 'genres' ,
297
+ 'short'
298
+ ] ,
299
+ count : 1 ,
300
+ probability : 1 ,
301
+ unique : 1 ,
302
+ hasDuplicates : false ,
303
+ values : [
304
+ 'scifi'
305
+ ] ,
306
+ bsonType : 'String'
307
+ }
308
+ ]
309
+ }
310
+ ]
311
+ }
312
+ ] ,
313
+ totalCount : 3 ,
314
+ lengths : [
315
+ 3
316
+ ] ,
317
+ averageLength : 3
318
+ } ,
319
+ {
320
+ name : 'Undefined' ,
321
+ bsonType : 'Undefined' ,
322
+ unique : 1 ,
323
+ hasDuplicates : false ,
324
+ path : [
325
+ 'genres'
326
+ ] ,
327
+ count : 1 ,
328
+ probability : 0.5
329
+ }
330
+ ]
331
+ }
332
+ ]
333
+ } ;
334
+ const standard = internalSchemaToStandard ( internal ) ;
335
+ assert . deepStrictEqual ( standard , {
336
+ bsonType : 'object' ,
337
+ required : [ ] ,
338
+ properties : {
339
+ genres : {
340
+ bsonType : 'array' ,
341
+ items : {
342
+ anyOf : [
343
+ {
344
+ bsonType : 'string'
345
+ } ,
346
+ {
347
+ bsonType : 'object' ,
348
+ required : [ 'long' , 'short' ] ,
349
+ properties : {
350
+ long : {
351
+ bsonType : 'string'
352
+ } ,
353
+ short : {
354
+ bsonType : 'string'
355
+ }
356
+ }
357
+ }
358
+ ]
359
+ }
360
+ }
361
+ }
362
+ } ) ;
363
+ } ) ;
364
+
365
+ // TODO: array - simple mixed type
366
+ } ) ;
367
+ } ) ;
You can’t perform that action at this time.
0 commit comments