@balena/odata-to-abstract-sql 8.0.2 → 9.0.0
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/out/odata-to-abstract-sql.d.ts +3 -4
- package/out/odata-to-abstract-sql.js +71 -120
- package/out/odata-to-abstract-sql.js.map +1 -1
- package/package.json +13 -8
- package/.eslintrc.cjs +0 -10
- package/.github/workflows/flowzone.yml +0 -21
- package/.husky/pre-commit +0 -2
- package/.lintstagedrc +0 -5
- package/.versionbot/CHANGELOG.yml +0 -13398
- package/CHANGELOG.md +0 -4415
- package/repo.yml +0 -12
- package/src/odata-to-abstract-sql.ts +0 -2117
- package/test/chai-sql-types.d.ts +0 -25
- package/test/chai-sql.ts +0 -454
- package/test/expand.ts +0 -606
- package/test/filterby.ts +0 -2164
- package/test/model.sbvr +0 -79
- package/test/orderby.ts +0 -544
- package/test/paging.ts +0 -75
- package/test/resource_parsing.ts +0 -773
- package/test/select.ts +0 -418
- package/test/stress.ts +0 -14
- package/test/test.ts +0 -106
- package/tsconfig.js.json +0 -13
- package/tsconfig.json +0 -18
package/test/resource_parsing.ts
DELETED
|
@@ -1,773 +0,0 @@
|
|
|
1
|
-
import { expect } from 'chai';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
aliasFields,
|
|
5
|
-
pilotFields,
|
|
6
|
-
licenceFields,
|
|
7
|
-
planeFields,
|
|
8
|
-
teamFields,
|
|
9
|
-
pilotCanFlyPlaneFields,
|
|
10
|
-
$count,
|
|
11
|
-
} from './chai-sql';
|
|
12
|
-
|
|
13
|
-
import test from './test';
|
|
14
|
-
import * as ODataParser from '@balena/odata-parser';
|
|
15
|
-
|
|
16
|
-
test('/', (result) => {
|
|
17
|
-
it('Service root should return $serviceroot', () => {
|
|
18
|
-
expect(result).to.deep.equal(['$serviceroot']);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('/$metadata', (result) => {
|
|
23
|
-
it('$metadata should return $metadata', () => {
|
|
24
|
-
expect(result).to.deep.equal(['$metadata']);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('/pilot', (result) => {
|
|
29
|
-
it('should select from pilot', () => {
|
|
30
|
-
expect(result).to.be.a.query.that.selects(pilotFields).from('pilot');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('/aircraft', (result) => {
|
|
35
|
-
it('should select from aircraft (plane)', () => {
|
|
36
|
-
expect(result).to.be.a.query.that.selects(planeFields).from('plane');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('/pilot__can_fly__aircraft', (result) => {
|
|
41
|
-
it('should select from pilot can fly aircraft (pilot can fly plane)', () => {
|
|
42
|
-
expect(result)
|
|
43
|
-
.to.be.a.query.that.selects(pilotCanFlyPlaneFields)
|
|
44
|
-
.from('pilot-can fly-plane');
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('/pilot(1)', (result) => {
|
|
49
|
-
it('should select from pilot with id', () => {
|
|
50
|
-
expect(result)
|
|
51
|
-
.to.be.a.query.that.selects(pilotFields)
|
|
52
|
-
.from('pilot')
|
|
53
|
-
.where([
|
|
54
|
-
'IsNotDistinctFrom',
|
|
55
|
-
['ReferencedField', 'pilot', 'id'],
|
|
56
|
-
['Bind', 0],
|
|
57
|
-
]);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('/pilot(0)', (result) => {
|
|
62
|
-
it('should select from pilot with id', () => {
|
|
63
|
-
expect(result)
|
|
64
|
-
.to.be.a.query.that.selects(pilotFields)
|
|
65
|
-
.from('pilot')
|
|
66
|
-
.where([
|
|
67
|
-
'IsNotDistinctFrom',
|
|
68
|
-
['ReferencedField', 'pilot', 'id'],
|
|
69
|
-
['Bind', 0],
|
|
70
|
-
]);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("/pilot('TextKey')", (result) => {
|
|
75
|
-
it('should select from pilot with id', () => {
|
|
76
|
-
expect(result)
|
|
77
|
-
.to.be.a.query.that.selects(pilotFields)
|
|
78
|
-
.from('pilot')
|
|
79
|
-
.where([
|
|
80
|
-
'IsNotDistinctFrom',
|
|
81
|
-
['ReferencedField', 'pilot', 'id'],
|
|
82
|
-
['Bind', 0],
|
|
83
|
-
]);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('/pilot(id=1)', (result) => {
|
|
88
|
-
it('should select from pilot with id', () => {
|
|
89
|
-
expect(result)
|
|
90
|
-
.to.be.a.query.that.selects(pilotFields)
|
|
91
|
-
.from('pilot')
|
|
92
|
-
.where([
|
|
93
|
-
'IsNotDistinctFrom',
|
|
94
|
-
['ReferencedField', 'pilot', 'id'],
|
|
95
|
-
['Bind', 0],
|
|
96
|
-
]);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("/pilot(id='TextKey')", (result) => {
|
|
101
|
-
it('should select from pilot with id', () => {
|
|
102
|
-
expect(result)
|
|
103
|
-
.to.be.a.query.that.selects(pilotFields)
|
|
104
|
-
.from('pilot')
|
|
105
|
-
.where([
|
|
106
|
-
'IsNotDistinctFrom',
|
|
107
|
-
['ReferencedField', 'pilot', 'id'],
|
|
108
|
-
['Bind', 0],
|
|
109
|
-
]);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('/pilot__can_fly__plane(pilot=12,can_fly__plane=23)', (result) => {
|
|
114
|
-
it('should select from pilot with id', () => {
|
|
115
|
-
expect(result)
|
|
116
|
-
.to.be.a.query.that.selects(pilotCanFlyPlaneFields)
|
|
117
|
-
.from('pilot-can fly-plane')
|
|
118
|
-
.where([
|
|
119
|
-
'And',
|
|
120
|
-
[
|
|
121
|
-
'IsNotDistinctFrom',
|
|
122
|
-
['ReferencedField', 'pilot-can fly-plane', 'pilot'],
|
|
123
|
-
['Bind', 0],
|
|
124
|
-
],
|
|
125
|
-
[
|
|
126
|
-
'IsNotDistinctFrom',
|
|
127
|
-
['ReferencedField', 'pilot-can fly-plane', 'can fly-plane'],
|
|
128
|
-
['Bind', 1],
|
|
129
|
-
],
|
|
130
|
-
]);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('/pilot(1)/licence', (result) => {
|
|
135
|
-
it('should select from the licence of pilot with id', () => {
|
|
136
|
-
expect(result)
|
|
137
|
-
.to.be.a.query.that.selects(aliasFields('pilot', licenceFields))
|
|
138
|
-
.from('pilot', ['licence', 'pilot.licence'])
|
|
139
|
-
.where([
|
|
140
|
-
'And',
|
|
141
|
-
[
|
|
142
|
-
'Equals',
|
|
143
|
-
['ReferencedField', 'pilot', 'licence'],
|
|
144
|
-
['ReferencedField', 'pilot.licence', 'id'],
|
|
145
|
-
],
|
|
146
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]],
|
|
147
|
-
]);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test('/pilot(1)/p', (result) => {
|
|
152
|
-
it('should fail to select an invalid path', () => {
|
|
153
|
-
expect(result)
|
|
154
|
-
.to.be.instanceOf(SyntaxError)
|
|
155
|
-
.and.to.have.property(
|
|
156
|
-
'message',
|
|
157
|
-
`Could not resolve relationship mapping from 'pilot' to 'p'`,
|
|
158
|
-
);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('/pilot(1)/p/licence', (result) => {
|
|
163
|
-
it('should fail to select from the licence of pilot with id when using an invalid path', () => {
|
|
164
|
-
expect(result)
|
|
165
|
-
.to.be.instanceOf(SyntaxError)
|
|
166
|
-
.and.to.have.property(
|
|
167
|
-
'message',
|
|
168
|
-
`Could not resolve relationship mapping from 'pilot' to 'p'`,
|
|
169
|
-
);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test('/licence(1)/is_of__pilot', (result) => {
|
|
174
|
-
it('should select from the pilots of licence with id', () => {
|
|
175
|
-
expect(result)
|
|
176
|
-
.to.be.a.query.that.selects(aliasFields('licence', pilotFields, 'is of'))
|
|
177
|
-
.from('licence', ['pilot', 'licence.is of-pilot'])
|
|
178
|
-
.where([
|
|
179
|
-
'And',
|
|
180
|
-
[
|
|
181
|
-
'Equals',
|
|
182
|
-
['ReferencedField', 'licence', 'id'],
|
|
183
|
-
['ReferencedField', 'licence.is of-pilot', 'licence'],
|
|
184
|
-
],
|
|
185
|
-
[
|
|
186
|
-
'IsNotDistinctFrom',
|
|
187
|
-
['ReferencedField', 'licence', 'id'],
|
|
188
|
-
['Bind', 0],
|
|
189
|
-
],
|
|
190
|
-
]);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('/pilot(1)/can_fly__plane/plane', (result) => {
|
|
195
|
-
it('should select from the plane of pilot with id', () => {
|
|
196
|
-
expect(result)
|
|
197
|
-
.to.be.a.query.that.selects(
|
|
198
|
-
aliasFields('pilot.pilot-can fly-plane', planeFields),
|
|
199
|
-
)
|
|
200
|
-
.from(
|
|
201
|
-
'pilot',
|
|
202
|
-
['pilot-can fly-plane', 'pilot.pilot-can fly-plane'],
|
|
203
|
-
['plane', 'pilot.pilot-can fly-plane.plane'],
|
|
204
|
-
)
|
|
205
|
-
.where([
|
|
206
|
-
'And',
|
|
207
|
-
[
|
|
208
|
-
'Equals',
|
|
209
|
-
['ReferencedField', 'pilot.pilot-can fly-plane', 'can fly-plane'],
|
|
210
|
-
['ReferencedField', 'pilot.pilot-can fly-plane.plane', 'id'],
|
|
211
|
-
],
|
|
212
|
-
[
|
|
213
|
-
'Equals',
|
|
214
|
-
['ReferencedField', 'pilot', 'id'],
|
|
215
|
-
['ReferencedField', 'pilot.pilot-can fly-plane', 'pilot'],
|
|
216
|
-
],
|
|
217
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]],
|
|
218
|
-
]);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test('/plane(1)/can_be_flown_by__pilot/pilot', (result) => {
|
|
223
|
-
it('should select from the pilots of plane with id', () => {
|
|
224
|
-
expect(result)
|
|
225
|
-
.to.be.a.query.that.selects(
|
|
226
|
-
aliasFields('plane.pilot-can fly-plane', pilotFields),
|
|
227
|
-
)
|
|
228
|
-
.from(
|
|
229
|
-
'plane',
|
|
230
|
-
['pilot-can fly-plane', 'plane.pilot-can fly-plane'],
|
|
231
|
-
['pilot', 'plane.pilot-can fly-plane.pilot'],
|
|
232
|
-
)
|
|
233
|
-
.where([
|
|
234
|
-
'And',
|
|
235
|
-
[
|
|
236
|
-
'Equals',
|
|
237
|
-
['ReferencedField', 'plane.pilot-can fly-plane', 'pilot'],
|
|
238
|
-
['ReferencedField', 'plane.pilot-can fly-plane.pilot', 'id'],
|
|
239
|
-
],
|
|
240
|
-
[
|
|
241
|
-
'Equals',
|
|
242
|
-
['ReferencedField', 'plane', 'id'],
|
|
243
|
-
['ReferencedField', 'plane.pilot-can fly-plane', 'can fly-plane'],
|
|
244
|
-
],
|
|
245
|
-
['IsNotDistinctFrom', ['ReferencedField', 'plane', 'id'], ['Bind', 0]],
|
|
246
|
-
]);
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
test('/pilot(1)', 'DELETE', (result) => {
|
|
251
|
-
it('should delete the pilot with id 1', () => {
|
|
252
|
-
expect(result)
|
|
253
|
-
.to.be.a.query.that.deletes.from('pilot')
|
|
254
|
-
.where([
|
|
255
|
-
'IsNotDistinctFrom',
|
|
256
|
-
['ReferencedField', 'pilot', 'id'],
|
|
257
|
-
['Bind', 0],
|
|
258
|
-
]);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
test('/pilot(1)', 'PUT', (result) => {
|
|
263
|
-
describe('should upsert the pilot with id 1', function () {
|
|
264
|
-
const whereClause = [
|
|
265
|
-
'IsNotDistinctFrom',
|
|
266
|
-
['ReferencedField', 'pilot', 'id'],
|
|
267
|
-
['Bind', 0],
|
|
268
|
-
];
|
|
269
|
-
it('should be an upsert', () => expect(result).to.be.a.query.that.upserts);
|
|
270
|
-
it('that inserts', () => {
|
|
271
|
-
expect(result[1])
|
|
272
|
-
.to.be.a.query.that.inserts.fields('id')
|
|
273
|
-
.values(
|
|
274
|
-
'SelectQuery',
|
|
275
|
-
['Select', [['ReferencedField', '$insert', 'id']]],
|
|
276
|
-
[
|
|
277
|
-
'From',
|
|
278
|
-
[
|
|
279
|
-
'Alias',
|
|
280
|
-
[
|
|
281
|
-
'SelectQuery',
|
|
282
|
-
[
|
|
283
|
-
'Select',
|
|
284
|
-
[
|
|
285
|
-
['Alias', ['Cast', ['Null'], 'Date Time'], 'created at'],
|
|
286
|
-
['Alias', ['Cast', ['Null'], 'Date Time'], 'modified at'],
|
|
287
|
-
[
|
|
288
|
-
'Alias',
|
|
289
|
-
['Cast', ['Bind', ['pilot', 'id']], 'Serial'],
|
|
290
|
-
'id',
|
|
291
|
-
],
|
|
292
|
-
['Alias', ['Cast', ['Null'], 'ConceptType'], 'person'],
|
|
293
|
-
['Alias', ['Cast', ['Null'], 'Boolean'], 'is experienced'],
|
|
294
|
-
['Alias', ['Cast', ['Null'], 'Short Text'], 'name'],
|
|
295
|
-
['Alias', ['Cast', ['Null'], 'Integer'], 'age'],
|
|
296
|
-
['Alias', ['Cast', ['Null'], 'Color'], 'favourite colour'],
|
|
297
|
-
['Alias', ['Cast', ['Null'], 'ForeignKey'], 'is on-team'],
|
|
298
|
-
['Alias', ['Cast', ['Null'], 'ForeignKey'], 'licence'],
|
|
299
|
-
['Alias', ['Cast', ['Null'], 'Date Time'], 'hire date'],
|
|
300
|
-
[
|
|
301
|
-
'Alias',
|
|
302
|
-
['Cast', ['Null'], 'ForeignKey'],
|
|
303
|
-
'was trained by-pilot',
|
|
304
|
-
],
|
|
305
|
-
],
|
|
306
|
-
],
|
|
307
|
-
],
|
|
308
|
-
'$insert',
|
|
309
|
-
],
|
|
310
|
-
],
|
|
311
|
-
[
|
|
312
|
-
'Where',
|
|
313
|
-
[
|
|
314
|
-
'Exists',
|
|
315
|
-
[
|
|
316
|
-
'SelectQuery',
|
|
317
|
-
['Select', []],
|
|
318
|
-
[
|
|
319
|
-
'From',
|
|
320
|
-
[
|
|
321
|
-
'Alias',
|
|
322
|
-
[
|
|
323
|
-
'SelectQuery',
|
|
324
|
-
['Select', [['ReferencedField', '$insert', '*']]],
|
|
325
|
-
],
|
|
326
|
-
'pilot',
|
|
327
|
-
],
|
|
328
|
-
],
|
|
329
|
-
[
|
|
330
|
-
'Where',
|
|
331
|
-
[
|
|
332
|
-
'IsNotDistinctFrom',
|
|
333
|
-
['ReferencedField', 'pilot', 'id'],
|
|
334
|
-
['Bind', 0],
|
|
335
|
-
],
|
|
336
|
-
],
|
|
337
|
-
],
|
|
338
|
-
],
|
|
339
|
-
],
|
|
340
|
-
)
|
|
341
|
-
.from('pilot');
|
|
342
|
-
});
|
|
343
|
-
it('and updates', () => {
|
|
344
|
-
expect(result[2])
|
|
345
|
-
.to.be.a.query.that.updates.fields(
|
|
346
|
-
'created at',
|
|
347
|
-
'modified at',
|
|
348
|
-
'id',
|
|
349
|
-
'person',
|
|
350
|
-
'is experienced',
|
|
351
|
-
'name',
|
|
352
|
-
'age',
|
|
353
|
-
'favourite colour',
|
|
354
|
-
'is on-team',
|
|
355
|
-
'licence',
|
|
356
|
-
'hire date',
|
|
357
|
-
'was trained by-pilot',
|
|
358
|
-
)
|
|
359
|
-
.values(
|
|
360
|
-
'Default',
|
|
361
|
-
'Default',
|
|
362
|
-
['Bind', ['pilot', 'id']],
|
|
363
|
-
'Default',
|
|
364
|
-
'Default',
|
|
365
|
-
'Default',
|
|
366
|
-
'Default',
|
|
367
|
-
'Default',
|
|
368
|
-
'Default',
|
|
369
|
-
'Default',
|
|
370
|
-
'Default',
|
|
371
|
-
'Default',
|
|
372
|
-
)
|
|
373
|
-
.from('pilot')
|
|
374
|
-
.where(whereClause);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
(function () {
|
|
380
|
-
const testFunc = (result) => {
|
|
381
|
-
it('should update the pilot with id 1', () => {
|
|
382
|
-
expect(result)
|
|
383
|
-
.to.be.a.query.that.updates.fields('is experienced', 'favourite colour')
|
|
384
|
-
.values(
|
|
385
|
-
['Bind', ['pilot', 'is_experienced']],
|
|
386
|
-
['Bind', ['pilot', 'favourite_colour']],
|
|
387
|
-
)
|
|
388
|
-
.from('pilot')
|
|
389
|
-
.where([
|
|
390
|
-
'IsNotDistinctFrom',
|
|
391
|
-
['ReferencedField', 'pilot', 'id'],
|
|
392
|
-
['Bind', 0],
|
|
393
|
-
]);
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
test(
|
|
397
|
-
'/pilot(1)',
|
|
398
|
-
'PATCH',
|
|
399
|
-
{ is_experienced: true, favourite_colour: null },
|
|
400
|
-
testFunc,
|
|
401
|
-
);
|
|
402
|
-
test(
|
|
403
|
-
'/pilot(1)',
|
|
404
|
-
'MERGE',
|
|
405
|
-
{ is_experienced: true, favourite_colour: null },
|
|
406
|
-
testFunc,
|
|
407
|
-
);
|
|
408
|
-
})();
|
|
409
|
-
|
|
410
|
-
test('/pilot', 'POST', { name: 'Peter' }, (result) => {
|
|
411
|
-
it('should insert a pilot', () => {
|
|
412
|
-
expect(result)
|
|
413
|
-
.to.be.a.query.that.inserts.fields('name')
|
|
414
|
-
.values(['Bind', ['pilot', 'name']])
|
|
415
|
-
.from('pilot');
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
test('/pilot__can_fly__plane(1)', 'DELETE', (result) => {
|
|
420
|
-
it('should delete the pilot__can_fly__plane with id 1', () => {
|
|
421
|
-
expect(result)
|
|
422
|
-
.to.be.a.query.that.deletes.from('pilot-can fly-plane')
|
|
423
|
-
.where([
|
|
424
|
-
'IsNotDistinctFrom',
|
|
425
|
-
['ReferencedField', 'pilot-can fly-plane', 'id'],
|
|
426
|
-
['Bind', 0],
|
|
427
|
-
]);
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
test('/pilot__can_fly__plane(1)', 'PUT', (result) => {
|
|
432
|
-
describe('should upsert the pilot__can_fly__plane with id 1', function () {
|
|
433
|
-
const whereClause = [
|
|
434
|
-
'IsNotDistinctFrom',
|
|
435
|
-
['ReferencedField', 'pilot-can fly-plane', 'id'],
|
|
436
|
-
['Bind', 0],
|
|
437
|
-
];
|
|
438
|
-
it('should be an upsert', () => expect(result).to.be.a.query.that.upserts);
|
|
439
|
-
it('that inserts', () => {
|
|
440
|
-
expect(result[1])
|
|
441
|
-
.to.be.a.query.that.inserts.fields('id')
|
|
442
|
-
.values(
|
|
443
|
-
'SelectQuery',
|
|
444
|
-
['Select', [['ReferencedField', '$insert', 'id']]],
|
|
445
|
-
[
|
|
446
|
-
'From',
|
|
447
|
-
[
|
|
448
|
-
'Alias',
|
|
449
|
-
[
|
|
450
|
-
'SelectQuery',
|
|
451
|
-
[
|
|
452
|
-
'Select',
|
|
453
|
-
[
|
|
454
|
-
['Alias', ['Cast', ['Null'], 'Date Time'], 'created at'],
|
|
455
|
-
['Alias', ['Cast', ['Null'], 'Date Time'], 'modified at'],
|
|
456
|
-
['Alias', ['Cast', ['Null'], 'ForeignKey'], 'pilot'],
|
|
457
|
-
[
|
|
458
|
-
'Alias',
|
|
459
|
-
['Cast', ['Null'], 'ForeignKey'],
|
|
460
|
-
'can fly-plane',
|
|
461
|
-
],
|
|
462
|
-
[
|
|
463
|
-
'Alias',
|
|
464
|
-
[
|
|
465
|
-
'Cast',
|
|
466
|
-
['Bind', ['pilot-can fly-plane', 'id']],
|
|
467
|
-
'Serial',
|
|
468
|
-
],
|
|
469
|
-
'id',
|
|
470
|
-
],
|
|
471
|
-
],
|
|
472
|
-
],
|
|
473
|
-
],
|
|
474
|
-
'$insert',
|
|
475
|
-
],
|
|
476
|
-
],
|
|
477
|
-
[
|
|
478
|
-
'Where',
|
|
479
|
-
[
|
|
480
|
-
'Exists',
|
|
481
|
-
[
|
|
482
|
-
'SelectQuery',
|
|
483
|
-
['Select', []],
|
|
484
|
-
[
|
|
485
|
-
'From',
|
|
486
|
-
[
|
|
487
|
-
'Alias',
|
|
488
|
-
[
|
|
489
|
-
'SelectQuery',
|
|
490
|
-
['Select', [['ReferencedField', '$insert', '*']]],
|
|
491
|
-
],
|
|
492
|
-
'pilot-can fly-plane',
|
|
493
|
-
],
|
|
494
|
-
],
|
|
495
|
-
[
|
|
496
|
-
'Where',
|
|
497
|
-
[
|
|
498
|
-
'IsNotDistinctFrom',
|
|
499
|
-
['ReferencedField', 'pilot-can fly-plane', 'id'],
|
|
500
|
-
['Bind', 0],
|
|
501
|
-
],
|
|
502
|
-
],
|
|
503
|
-
],
|
|
504
|
-
],
|
|
505
|
-
],
|
|
506
|
-
)
|
|
507
|
-
.from('pilot-can fly-plane');
|
|
508
|
-
});
|
|
509
|
-
it('and updates', () => {
|
|
510
|
-
expect(result[2])
|
|
511
|
-
.to.be.a.query.that.updates.fields(
|
|
512
|
-
'created at',
|
|
513
|
-
'modified at',
|
|
514
|
-
'pilot',
|
|
515
|
-
'can fly-plane',
|
|
516
|
-
'id',
|
|
517
|
-
)
|
|
518
|
-
.values('Default', 'Default', 'Default', 'Default', [
|
|
519
|
-
'Bind',
|
|
520
|
-
['pilot-can fly-plane', 'id'],
|
|
521
|
-
])
|
|
522
|
-
.from('pilot-can fly-plane')
|
|
523
|
-
.where(whereClause);
|
|
524
|
-
});
|
|
525
|
-
});
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
(function () {
|
|
529
|
-
const testFunc = (result) => {
|
|
530
|
-
it('should update the pilot__can_fly__plane with id 1', () => {
|
|
531
|
-
expect(result)
|
|
532
|
-
.to.be.a.query.that.updates.fields('pilot')
|
|
533
|
-
.values(['Bind', ['pilot-can fly-plane', 'pilot']])
|
|
534
|
-
.from('pilot-can fly-plane')
|
|
535
|
-
.where([
|
|
536
|
-
'IsNotDistinctFrom',
|
|
537
|
-
['ReferencedField', 'pilot-can fly-plane', 'id'],
|
|
538
|
-
['Bind', 0],
|
|
539
|
-
]);
|
|
540
|
-
});
|
|
541
|
-
};
|
|
542
|
-
test('/pilot__can_fly__plane(1)', 'PATCH', { pilot: 2 }, testFunc);
|
|
543
|
-
test('/pilot__can_fly__plane(1)', 'MERGE', { pilot: 2 }, testFunc);
|
|
544
|
-
})();
|
|
545
|
-
|
|
546
|
-
test(
|
|
547
|
-
'/pilot__can_fly__plane',
|
|
548
|
-
'POST',
|
|
549
|
-
{ pilot: 2, can_fly__plane: 3 },
|
|
550
|
-
(result) => {
|
|
551
|
-
it('should add a pilot__can_fly__plane', () => {
|
|
552
|
-
expect(result)
|
|
553
|
-
.to.be.a.query.that.inserts.fields('pilot', 'can fly-plane')
|
|
554
|
-
.values(
|
|
555
|
-
['Bind', ['pilot-can fly-plane', 'pilot']],
|
|
556
|
-
['Bind', ['pilot-can fly-plane', 'can_fly__plane']],
|
|
557
|
-
)
|
|
558
|
-
.from('pilot-can fly-plane');
|
|
559
|
-
});
|
|
560
|
-
},
|
|
561
|
-
);
|
|
562
|
-
|
|
563
|
-
test('/pilot(1)/$links/licence', (result) => {
|
|
564
|
-
it('should select the list of licence ids, for generating the links', () => {
|
|
565
|
-
expect(result)
|
|
566
|
-
.to.be.a.query.that.selects([
|
|
567
|
-
['Alias', ['ReferencedField', 'pilot', 'licence'], 'licence'],
|
|
568
|
-
])
|
|
569
|
-
.from('pilot')
|
|
570
|
-
.where([
|
|
571
|
-
'IsNotDistinctFrom',
|
|
572
|
-
['ReferencedField', 'pilot', 'id'],
|
|
573
|
-
['Bind', 0],
|
|
574
|
-
]);
|
|
575
|
-
});
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
test('/pilot(1)/$links/licence(2)', (result) => {
|
|
579
|
-
it('should select the licence id 2, for generating the link', () => {
|
|
580
|
-
expect(result)
|
|
581
|
-
.to.be.a.query.that.selects([
|
|
582
|
-
['Alias', ['ReferencedField', 'pilot', 'licence'], 'licence'],
|
|
583
|
-
])
|
|
584
|
-
.from('pilot')
|
|
585
|
-
.where([
|
|
586
|
-
'And',
|
|
587
|
-
[
|
|
588
|
-
'IsNotDistinctFrom',
|
|
589
|
-
['ReferencedField', 'pilot', 'licence'],
|
|
590
|
-
['Bind', 1],
|
|
591
|
-
],
|
|
592
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]],
|
|
593
|
-
]);
|
|
594
|
-
});
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
test("/pilot('Peter')/$links/licence('X')", (result) => {
|
|
598
|
-
it('should select the licence id 2, for generating the link', () => {
|
|
599
|
-
expect(result)
|
|
600
|
-
.to.be.a.query.that.selects([
|
|
601
|
-
['Alias', ['ReferencedField', 'pilot', 'licence'], 'licence'],
|
|
602
|
-
])
|
|
603
|
-
.from('pilot')
|
|
604
|
-
.where([
|
|
605
|
-
'And',
|
|
606
|
-
[
|
|
607
|
-
'IsNotDistinctFrom',
|
|
608
|
-
['ReferencedField', 'pilot', 'licence'],
|
|
609
|
-
['Bind', 1],
|
|
610
|
-
],
|
|
611
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]],
|
|
612
|
-
]);
|
|
613
|
-
});
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
test('/pilot(1)/can_fly__plane/$links/plane', (result) => {
|
|
617
|
-
it('should select the list of plane ids, for generating the links', () => {
|
|
618
|
-
expect(result)
|
|
619
|
-
.to.be.a.query.that.selects([
|
|
620
|
-
[
|
|
621
|
-
'Alias',
|
|
622
|
-
['ReferencedField', 'pilot.pilot-can fly-plane', 'can fly-plane'],
|
|
623
|
-
'plane',
|
|
624
|
-
],
|
|
625
|
-
])
|
|
626
|
-
.from('pilot', ['pilot-can fly-plane', 'pilot.pilot-can fly-plane'])
|
|
627
|
-
.where([
|
|
628
|
-
'And',
|
|
629
|
-
[
|
|
630
|
-
'Equals',
|
|
631
|
-
['ReferencedField', 'pilot', 'id'],
|
|
632
|
-
['ReferencedField', 'pilot.pilot-can fly-plane', 'pilot'],
|
|
633
|
-
],
|
|
634
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]],
|
|
635
|
-
]);
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
test.skip('/pilot(1)/favourite_colour/red', () => {
|
|
640
|
-
it("should select the red component of the pilot's favourite colour");
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
test.skip('/method(1)/child?foo=bar', () => it('should do something..'));
|
|
644
|
-
|
|
645
|
-
test("/team('purple')", (result) => {
|
|
646
|
-
it('should select the team with the "favourite colour" id of "purple"', () => {
|
|
647
|
-
expect(result)
|
|
648
|
-
.to.be.a.query.that.selects(teamFields)
|
|
649
|
-
.from('team')
|
|
650
|
-
.where([
|
|
651
|
-
'IsNotDistinctFrom',
|
|
652
|
-
['ReferencedField', 'team', 'favourite colour'],
|
|
653
|
-
['Bind', 0],
|
|
654
|
-
]);
|
|
655
|
-
});
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
test('/team', 'POST', { favourite_colour: 'purple' }, (result) => {
|
|
659
|
-
it('should insert a team', () => {
|
|
660
|
-
expect(result)
|
|
661
|
-
.to.be.a.query.that.inserts.fields('favourite colour')
|
|
662
|
-
.values(['Bind', ['team', 'favourite_colour']])
|
|
663
|
-
.from('team');
|
|
664
|
-
});
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
test('/pilot/$count/$count', (result) => {
|
|
668
|
-
it('should fail because it is invalid', () => {
|
|
669
|
-
expect(result).to.be.instanceOf(ODataParser.SyntaxError);
|
|
670
|
-
});
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
test('/pilot/$count', (result) => {
|
|
674
|
-
it('should select count(*) from pilot', () => {
|
|
675
|
-
expect(result).to.be.a.query.that.selects($count).from('pilot');
|
|
676
|
-
});
|
|
677
|
-
});
|
|
678
|
-
|
|
679
|
-
test('/pilot(5)/$count', (result) => {
|
|
680
|
-
it('should fail because it is invalid', () => {
|
|
681
|
-
expect(result).to.be.instanceOf(ODataParser.SyntaxError);
|
|
682
|
-
});
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
test('/pilot?$filter=id eq 5/$count', (result) => {
|
|
686
|
-
it('should fail because it is invalid', () => {
|
|
687
|
-
expect(result).to.be.instanceOf(ODataParser.SyntaxError);
|
|
688
|
-
});
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
test('/pilot/$count?$filter=id gt 5', (result) => {
|
|
692
|
-
it('should select count(*) from pilot where pilot/id > 5 ', () => {
|
|
693
|
-
expect(result)
|
|
694
|
-
.to.be.a.query.that.selects($count)
|
|
695
|
-
.from('pilot')
|
|
696
|
-
.where(['GreaterThan', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]]);
|
|
697
|
-
});
|
|
698
|
-
});
|
|
699
|
-
|
|
700
|
-
test('/pilot/$count?$filter=id eq 5 or id eq 10', (result) => {
|
|
701
|
-
it('should select count(*) from pilot where id in (5,10)', () => {
|
|
702
|
-
expect(result)
|
|
703
|
-
.to.be.a.query.that.selects($count)
|
|
704
|
-
.from('pilot')
|
|
705
|
-
.where([
|
|
706
|
-
'Or',
|
|
707
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]],
|
|
708
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 1]],
|
|
709
|
-
]);
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
test('/pilot(5)/licence/$count', (result) => {
|
|
714
|
-
it('should select count(*) the licence from pilot where pilot/id', () => {
|
|
715
|
-
expect(result)
|
|
716
|
-
.to.be.a.query.that.selects($count)
|
|
717
|
-
.from('pilot', ['licence', 'pilot.licence'])
|
|
718
|
-
.where([
|
|
719
|
-
'And',
|
|
720
|
-
[
|
|
721
|
-
'Equals',
|
|
722
|
-
['ReferencedField', 'pilot', 'licence'],
|
|
723
|
-
['ReferencedField', 'pilot.licence', 'id'],
|
|
724
|
-
],
|
|
725
|
-
['IsNotDistinctFrom', ['ReferencedField', 'pilot', 'id'], ['Bind', 0]],
|
|
726
|
-
]);
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
test('/pilot/$count?$orderby=id asc', (result) => {
|
|
731
|
-
it('should select count(*) from pilot and ignore orderby', () => {
|
|
732
|
-
expect(result)
|
|
733
|
-
.to.be.a.query.that.selects($count)
|
|
734
|
-
.from('pilot')
|
|
735
|
-
.and.has.a.lengthOf(3);
|
|
736
|
-
});
|
|
737
|
-
});
|
|
738
|
-
|
|
739
|
-
test('/pilot/$count?$skip=5', (result) => {
|
|
740
|
-
it('should select count(*) from pilot and ignore skip', () => {
|
|
741
|
-
expect(result)
|
|
742
|
-
.to.be.a.query.that.selects($count)
|
|
743
|
-
.from('pilot')
|
|
744
|
-
.and.has.a.lengthOf(3);
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
test('/pilot/$count?$top=5', (result) => {
|
|
749
|
-
it('should select count(*) from pilot and ignore top', () => {
|
|
750
|
-
expect(result)
|
|
751
|
-
.to.be.a.query.that.selects($count)
|
|
752
|
-
.from('pilot')
|
|
753
|
-
.and.has.a.lengthOf(3);
|
|
754
|
-
});
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
test('/pilot/$count?$top=5&$skip=5', (result) => {
|
|
758
|
-
it('should select count(*) from pilot and ignore top and skip', () => {
|
|
759
|
-
expect(result)
|
|
760
|
-
.to.be.a.query.that.selects($count)
|
|
761
|
-
.from('pilot')
|
|
762
|
-
.and.has.a.lengthOf(3);
|
|
763
|
-
});
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
test('/pilot/$count?$select=id', (result) => {
|
|
767
|
-
it('should select count(*) from pilot and ignore select', () => {
|
|
768
|
-
expect(result)
|
|
769
|
-
.to.be.a.query.that.selects($count)
|
|
770
|
-
.from('pilot')
|
|
771
|
-
.and.has.a.lengthOf(3);
|
|
772
|
-
});
|
|
773
|
-
});
|