@nest-yalc-2/omnikernel-module 2.2.2 → 2.2.6
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/package.json +17 -15
- package/src/__tests__/omni-collection.entity.spec.ts +49 -49
- package/src/__tests__/omni-collection.service.spec.ts +83 -83
- package/src/__tests__/omni-document.entity.spec.ts +55 -55
- package/src/__tests__/omni-document.service.spec.ts +83 -83
- package/src/__tests__/omni-extension-projection-constraints.spec.ts +518 -518
- package/src/__tests__/omni-extension-projection.registration.spec.ts +947 -946
- package/src/__tests__/omni-extension-projection.service.spec.ts +806 -806
- package/src/__tests__/omni-external-ref.entity.spec.ts +36 -36
- package/src/__tests__/omni-external-ref.service.spec.ts +252 -252
- package/src/__tests__/omni-named.entity.spec.ts +33 -33
- package/src/__tests__/omni-record.entity.spec.ts +32 -32
- package/src/__tests__/omni-record.service.spec.ts +107 -107
- package/src/__tests__/omni-relation-semantics.spec.ts +102 -102
- package/src/__tests__/omni-relation.entity.spec.ts +38 -38
- package/src/__tests__/omni-scope-substrate.spec.ts +81 -81
- package/src/__tests__/omni-scoped.backend.spec.ts +115 -115
- package/src/__tests__/omni-scoped.service.spec.ts +354 -354
- package/src/__tests__/omnikernel.diagnostics.spec.ts +94 -94
- package/src/__tests__/omnikernel.module.spec.ts +38 -40
- package/src/__tests__/omnikernel.persistence.spec.ts +154 -154
- package/src/__tests__/omnikernel.public-api.spec.ts +238 -238
- package/src/__tests__/omnikernel.query.service.spec.ts +155 -155
- package/src/base/omni-base.entity.ts +41 -41
- package/src/base/omni-external-ref.entity.ts +53 -53
- package/src/base/omni-named.entity.ts +16 -16
- package/src/base/omni-record.entity.ts +51 -51
- package/src/base/omni-relation.entity.ts +72 -72
- package/src/index.ts +49 -49
- package/src/omni-collection-kind.enum.ts +10 -10
- package/src/omni-collection.backend.ts +16 -16
- package/src/omni-collection.dto.ts +170 -170
- package/src/omni-collection.entity.ts +21 -21
- package/src/omni-collection.service.ts +75 -75
- package/src/omni-document-kind.enum.ts +12 -12
- package/src/omni-document.backend.ts +16 -16
- package/src/omni-document.dto.ts +198 -198
- package/src/omni-document.entity.ts +30 -30
- package/src/omni-document.service.ts +75 -75
- package/src/omni-dto.helpers.ts +21 -21
- package/src/omni-extension-projection.definition.ts +294 -294
- package/src/omni-extension-projection.resource.ts +274 -274
- package/src/omni-extension-projection.service.ts +452 -452
- package/src/omni-external-ref-binding.validator.ts +53 -53
- package/src/omni-external-ref-internal-type.enum.ts +11 -11
- package/src/omni-external-ref.backend.ts +25 -25
- package/src/omni-external-ref.dto.ts +128 -128
- package/src/omni-external-ref.service.ts +255 -255
- package/src/omni-migration.ts +365 -365
- package/src/omni-named.backend.ts +11 -11
- package/src/omni-named.dto.ts +86 -86
- package/src/omni-projection.catalog.ts +345 -345
- package/src/omni-projection.lifecycle.ts +53 -53
- package/src/omni-record-status.enum.ts +11 -11
- package/src/omni-record.backend.ts +19 -19
- package/src/omni-record.dto.ts +157 -157
- package/src/omni-record.service.ts +113 -113
- package/src/omni-relation-kind.contract.ts +49 -49
- package/src/omni-relation-kind.enum.ts +12 -12
- package/src/omni-relation-projection.definition.ts +166 -166
- package/src/omni-relation-projection.resource.ts +360 -360
- package/src/omni-relation-projection.service.ts +610 -610
- package/src/omni-relation-semantics.ts +52 -52
- package/src/omni-relation-status.enum.ts +11 -11
- package/src/omni-relation.backend.ts +21 -21
- package/src/omni-relation.dto.ts +142 -142
- package/src/omni-relation.service.ts +159 -159
- package/src/omni-scope.ts +161 -161
- package/src/omni-scoped.backend.ts +110 -110
- package/src/omni-scoped.repository.ts +34 -34
- package/src/omni-scoped.service.ts +338 -338
- package/src/omnikernel.diagnostics.ts +83 -83
- package/src/omnikernel.module.ts +97 -97
- package/src/omnikernel.query.service.ts +108 -108
|
@@ -1,946 +1,947 @@
|
|
|
1
|
-
import { Scope, type INestApplication } from '@nestjs/common';
|
|
2
|
-
import { afterAll, afterEach, beforeAll, describe, expect, it, jest } from '@jest/globals';
|
|
3
|
-
import { ApolloDriver, type ApolloDriverConfig } from '@nestjs/apollo';
|
|
4
|
-
import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
5
|
-
import { GraphQLModule, GraphQLSchemaHost } from '@nestjs/graphql';
|
|
6
|
-
import { ModuleRef } from '@nestjs/core';
|
|
7
|
-
import { getDataSourceToken, TypeOrmModule } from '@nestjs/typeorm';
|
|
8
|
-
import { Test } from '@nestjs/testing';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
]
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
expect(registration
|
|
199
|
-
expect(registration.
|
|
200
|
-
expect(registration.
|
|
201
|
-
expect(registration.
|
|
202
|
-
expect(registration.
|
|
203
|
-
expect(registration.providers).toHaveLength(
|
|
204
|
-
expect(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
provider
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
provider
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
expect(relationRegistration
|
|
231
|
-
expect(relationRegistration.
|
|
232
|
-
|
|
233
|
-
'
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
expect(relationRegistration.
|
|
237
|
-
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
...
|
|
315
|
-
...
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
...
|
|
345
|
-
...
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
'
|
|
381
|
-
'
|
|
382
|
-
'
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
'
|
|
389
|
-
'
|
|
390
|
-
'
|
|
391
|
-
'
|
|
392
|
-
'
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
.
|
|
399
|
-
.
|
|
400
|
-
.expect(
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
.
|
|
412
|
-
.expect(
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
.
|
|
418
|
-
.expect(
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
.
|
|
426
|
-
.
|
|
427
|
-
.expect(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
expect(graphCreate.body.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
.
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
.expect(
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
expect(body.
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
.
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
expect(graphRead.body.
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
expect.objectContaining({ guid:
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
.
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
expect(graphRelation.body.
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
$
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
expect(graphRelationUpdate.body.
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
.
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
$
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
expect(graphUpdate.body.
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
.
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
.
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
.
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
.
|
|
606
|
-
.
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
.
|
|
610
|
-
.
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
.
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
$
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
.
|
|
651
|
-
|
|
652
|
-
expect(
|
|
653
|
-
expect(response.body.
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
.
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
expect(graphRelationDelete.body.
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
.
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
expect(graphDelete.body.
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
.
|
|
685
|
-
.expect(
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
expect(
|
|
694
|
-
expect(
|
|
695
|
-
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
expect(()
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
expect(
|
|
804
|
-
expect(Object.isFrozen(plan
|
|
805
|
-
expect(Object.isFrozen(plan.
|
|
806
|
-
expect(Object.isFrozen(
|
|
807
|
-
expect(Object.isFrozen(captured
|
|
808
|
-
expect(Object.isFrozen(captured.
|
|
809
|
-
expect(
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
"omni-
|
|
813
|
-
"omni-
|
|
814
|
-
"omni-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
firstSnapshot
|
|
830
|
-
|
|
831
|
-
migrationSource.
|
|
832
|
-
|
|
833
|
-
expect(plan.createTables()[0].name).not.toBe(
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
.
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
provider
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
expect(indexStatement.
|
|
908
|
-
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
await planRunner.
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
await planRunner.
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
expect(await downRunner.hasTable(
|
|
938
|
-
await
|
|
939
|
-
|
|
940
|
-
expect(await downRunner.hasTable(
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1
|
+
import { Scope, type INestApplication } from '@nestjs/common';
|
|
2
|
+
import { afterAll, afterEach, beforeAll, describe, expect, it, jest } from '@jest/globals';
|
|
3
|
+
import { ApolloDriver, type ApolloDriverConfig } from '@nestjs/apollo';
|
|
4
|
+
import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
5
|
+
import { GraphQLModule, GraphQLSchemaHost } from '@nestjs/graphql';
|
|
6
|
+
import { ModuleRef } from '@nestjs/core';
|
|
7
|
+
import { getDataSourceToken, TypeOrmModule } from '@nestjs/typeorm';
|
|
8
|
+
import { Test } from '@nestjs/testing';
|
|
9
|
+
jest.setTimeout(30000);
|
|
10
|
+
import {
|
|
11
|
+
ConflictException,
|
|
12
|
+
NotFoundException,
|
|
13
|
+
} from '@nestjs/common';
|
|
14
|
+
import {
|
|
15
|
+
createProjectionDialect,
|
|
16
|
+
CrudGenResourceFactory,
|
|
17
|
+
} from "@nest-yalc-2/crud-gen";
|
|
18
|
+
import { EventModule } from '@nest-yalc-2/event-manager';
|
|
19
|
+
import { UUIDScalar } from '@nest-yalc-2/graphql/scalars/uuid.scalar.js';
|
|
20
|
+
import request from 'supertest';
|
|
21
|
+
import { DataSource } from "typeorm";
|
|
22
|
+
import type { OmniMigrationRunner } from '../omni-migration.js';
|
|
23
|
+
|
|
24
|
+
import { OmniNamedEntity } from "../base/omni-named.entity.js";
|
|
25
|
+
import { OmniRecordEntity } from "../base/omni-record.entity.js";
|
|
26
|
+
import { OmniRelationEntity } from "../base/omni-relation.entity.js";
|
|
27
|
+
import { OmniExternalRefEntity } from "../base/omni-external-ref.entity.js";
|
|
28
|
+
import { OmniCollectionEntity } from "../omni-collection.entity.js";
|
|
29
|
+
import { OmniDocumentEntity } from "../omni-document.entity.js";
|
|
30
|
+
import { OmniRecordStatus } from "../omni-record-status.enum.js";
|
|
31
|
+
import { OmniKernelModule } from '../omnikernel.module.js';
|
|
32
|
+
import {
|
|
33
|
+
OmniRecordCondition,
|
|
34
|
+
OmniRecordCreateInput,
|
|
35
|
+
OmniRecordType,
|
|
36
|
+
OmniRecordUpdateInput,
|
|
37
|
+
} from '../omni-record.dto.js';
|
|
38
|
+
import {
|
|
39
|
+
createOmniExtensionProjectionEntity,
|
|
40
|
+
defineOmniExtensionProjection,
|
|
41
|
+
} from "../omni-extension-projection.definition.js";
|
|
42
|
+
import { createOmniExtensionProjectionRegistration } from "../omni-extension-projection.resource.js";
|
|
43
|
+
import { defineOmniRelationProjection } from '../omni-relation-projection.definition.js';
|
|
44
|
+
import { createOmniRelationProjectionRegistration } from '../omni-relation-projection.resource.js';
|
|
45
|
+
import {
|
|
46
|
+
captureOmniMigrationSnapshot,
|
|
47
|
+
createOmniMigrationPlan,
|
|
48
|
+
defineOmniMigrationSnapshot,
|
|
49
|
+
} from "../omni-migration.js";
|
|
50
|
+
import { createOmniProjectionReaderCatalogProvider } from '../omni-projection.catalog.js';
|
|
51
|
+
|
|
52
|
+
type ExtensionRow = {
|
|
53
|
+
scopeId: string;
|
|
54
|
+
guid: string;
|
|
55
|
+
label: string;
|
|
56
|
+
payload: Record<string, unknown>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
class ExampleExtensionApi {
|
|
60
|
+
guid!: string;
|
|
61
|
+
label!: string;
|
|
62
|
+
enabled!: boolean;
|
|
63
|
+
revision!: number;
|
|
64
|
+
payload!: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
class ExampleLinkApi {
|
|
68
|
+
guid!: string;
|
|
69
|
+
sourceRecordId!: string;
|
|
70
|
+
targetRecordId!: string;
|
|
71
|
+
revision!: number;
|
|
72
|
+
payload!: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const rawRecordResource = CrudGenResourceFactory<typeof OmniRecordEntity>({
|
|
76
|
+
entityModel: OmniRecordEntity,
|
|
77
|
+
backend: false,
|
|
78
|
+
graphql: {
|
|
79
|
+
resolver: {
|
|
80
|
+
dto: OmniRecordType,
|
|
81
|
+
input: {
|
|
82
|
+
create: OmniRecordCreateInput,
|
|
83
|
+
update: OmniRecordUpdateInput,
|
|
84
|
+
conditions: OmniRecordCondition,
|
|
85
|
+
},
|
|
86
|
+
prefix: 'Raw_',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
rest: {
|
|
90
|
+
dto: OmniRecordType,
|
|
91
|
+
path: 'raw-records',
|
|
92
|
+
idField: 'guid',
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const definition = defineOmniExtensionProjection({
|
|
97
|
+
id: "example.nest-extension.v1",
|
|
98
|
+
tableName: "example-nest-extension",
|
|
99
|
+
identity: { column: "guid", uniqueWithinScope: true },
|
|
100
|
+
scope: { column: "scopeId", serverOwned: true },
|
|
101
|
+
revision: { column: "revision" },
|
|
102
|
+
payload: { column: "payload", allowCreate: true },
|
|
103
|
+
deletion: "hard",
|
|
104
|
+
fields: [
|
|
105
|
+
{
|
|
106
|
+
name: "guid",
|
|
107
|
+
storage: "column",
|
|
108
|
+
column: "guid",
|
|
109
|
+
codec: "uuid",
|
|
110
|
+
nullable: false,
|
|
111
|
+
requiredOnCreate: true,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "label",
|
|
115
|
+
storage: "column",
|
|
116
|
+
column: "label",
|
|
117
|
+
codec: "string",
|
|
118
|
+
nullable: false,
|
|
119
|
+
requiredOnCreate: true,
|
|
120
|
+
query: { filter: ["eq"], sort: true },
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "enabled",
|
|
124
|
+
storage: "json",
|
|
125
|
+
path: ["state", "enabled"],
|
|
126
|
+
codec: "boolean",
|
|
127
|
+
nullable: false,
|
|
128
|
+
requiredOnCreate: true,
|
|
129
|
+
index: { name: "example_nest_extension_enabled_idx" },
|
|
130
|
+
query: { filter: ["eq"], sort: true },
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
owner: {
|
|
134
|
+
kind: "example_nest_extension",
|
|
135
|
+
title: "Example Nest extension",
|
|
136
|
+
status: OmniRecordStatus.Active,
|
|
137
|
+
schema: { id: "example.nest-extension.v1", version: 1 },
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const relationDefinition = defineOmniRelationProjection({
|
|
142
|
+
id: 'example.nest-extension-link.v1',
|
|
143
|
+
relation: {
|
|
144
|
+
allowedKinds: ['example_link', 'example_blocks'],
|
|
145
|
+
sourceKind: definition.owner.kind,
|
|
146
|
+
targetKind: definition.owner.kind,
|
|
147
|
+
schema: { id: 'example.nest-extension-link.v1', version: 1 },
|
|
148
|
+
},
|
|
149
|
+
aliases: {
|
|
150
|
+
kind: 'linkKind',
|
|
151
|
+
source: 'sourceWorkItemId',
|
|
152
|
+
target: 'targetWorkItemId',
|
|
153
|
+
payload: 'metadata',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const scope = {
|
|
158
|
+
scopeId: "scope-registration",
|
|
159
|
+
cacheKey: (key: string) => `scope-registration:${key}`,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const events = {
|
|
163
|
+
errorBadRequest: (_event: string, options: any) =>
|
|
164
|
+
new ConflictException(options.response.message),
|
|
165
|
+
errorConflict: (_event: string, options: any) =>
|
|
166
|
+
new ConflictException(options.response.message),
|
|
167
|
+
errorNotFound: (_event: string, options: any) =>
|
|
168
|
+
new NotFoundException(options.response.message),
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const lifecycleToken = Symbol('example-projection-lifecycle');
|
|
172
|
+
const catalogToken = Symbol('example-projection-catalog');
|
|
173
|
+
const moduleRefToken = Symbol('example-consumer-module-ref');
|
|
174
|
+
const lifecycleBeforeCreate = jest.fn();
|
|
175
|
+
const lifecycleBeforeUpdate = jest.fn();
|
|
176
|
+
const lifecycleBeforeDelete = jest.fn();
|
|
177
|
+
|
|
178
|
+
const postgresUrl = process.env.OMNI_EXTENSION_PROJECTION_POSTGRES_URL;
|
|
179
|
+
const dialectCases: Array<{ name: "sqlite" | "postgres"; url?: string }> = [
|
|
180
|
+
{ name: "sqlite" },
|
|
181
|
+
...(postgresUrl ? [{ name: "postgres" as const, url: postgresUrl }] : []),
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
describe("Omni extension projection registration", () => {
|
|
185
|
+
it("returns generated CrudGen REST and GraphQL surfaces with request-scoped providers", () => {
|
|
186
|
+
const entity = createOmniExtensionProjectionEntity<ExtensionRow>(
|
|
187
|
+
definition,
|
|
188
|
+
createProjectionDialect("sqlite"),
|
|
189
|
+
);
|
|
190
|
+
const registration = createOmniExtensionProjectionRegistration({
|
|
191
|
+
entity,
|
|
192
|
+
apiModel: ExampleExtensionApi,
|
|
193
|
+
definition,
|
|
194
|
+
dbConnection: "default",
|
|
195
|
+
rest: { path: "example-extensions" },
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(Object.isFrozen(registration)).toBe(true);
|
|
199
|
+
expect(registration.definition).toBe(definition);
|
|
200
|
+
expect(registration.entities).toEqual([entity]);
|
|
201
|
+
expect(registration.reservedRecordKinds).toEqual([definition.owner.kind]);
|
|
202
|
+
expect(registration.controllers).toHaveLength(1);
|
|
203
|
+
expect(registration.resource.providers).toHaveLength(1);
|
|
204
|
+
expect(registration.providers).toHaveLength(3);
|
|
205
|
+
expect(
|
|
206
|
+
registration.providers.filter(
|
|
207
|
+
(provider) =>
|
|
208
|
+
typeof provider === 'object' &&
|
|
209
|
+
provider !== null &&
|
|
210
|
+
'provide' in provider &&
|
|
211
|
+
provider.provide === registration.serviceToken,
|
|
212
|
+
),
|
|
213
|
+
).toHaveLength(1);
|
|
214
|
+
expect(
|
|
215
|
+
registration.providers.filter(
|
|
216
|
+
(provider) =>
|
|
217
|
+
typeof provider === 'object' &&
|
|
218
|
+
provider !== null &&
|
|
219
|
+
'provide' in provider &&
|
|
220
|
+
provider.provide === registration.dataLoaderToken,
|
|
221
|
+
),
|
|
222
|
+
).toHaveLength(1);
|
|
223
|
+
|
|
224
|
+
const relationRegistration = createOmniRelationProjectionRegistration({
|
|
225
|
+
apiModel: ExampleLinkApi,
|
|
226
|
+
definition: relationDefinition,
|
|
227
|
+
dbConnection: 'default',
|
|
228
|
+
rest: { path: 'example-links' },
|
|
229
|
+
});
|
|
230
|
+
expect(Object.isFrozen(relationRegistration)).toBe(true);
|
|
231
|
+
expect(relationRegistration.entities).toEqual([]);
|
|
232
|
+
expect(relationRegistration.relationKinds).toEqual([
|
|
233
|
+
'example_link',
|
|
234
|
+
'example_blocks',
|
|
235
|
+
]);
|
|
236
|
+
expect(relationRegistration.controllers).toHaveLength(1);
|
|
237
|
+
expect(relationRegistration.providers).toHaveLength(3);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe('Omni extension projection generated transport', () => {
|
|
242
|
+
let app: INestApplication;
|
|
243
|
+
let dataSource: DataSource;
|
|
244
|
+
const restGuid = '10000000-0000-4000-8000-000000000201';
|
|
245
|
+
const graphqlGuid = '10000000-0000-4000-8000-000000000202';
|
|
246
|
+
const relationGuid = '10000000-0000-4000-8000-000000000206';
|
|
247
|
+
const normalRecordGuid = '10000000-0000-4000-8000-000000000203';
|
|
248
|
+
const rejectedRecordGuid = '10000000-0000-4000-8000-000000000204';
|
|
249
|
+
|
|
250
|
+
beforeAll(async () => {
|
|
251
|
+
const entity = createOmniExtensionProjectionEntity<ExtensionRow>(
|
|
252
|
+
definition,
|
|
253
|
+
createProjectionDialect('sqlite'),
|
|
254
|
+
);
|
|
255
|
+
const registration = createOmniExtensionProjectionRegistration({
|
|
256
|
+
entity,
|
|
257
|
+
apiModel: ExampleExtensionApi,
|
|
258
|
+
definition,
|
|
259
|
+
dbConnection: 'default',
|
|
260
|
+
catalog: { token: catalogToken },
|
|
261
|
+
lifecycle: { token: lifecycleToken },
|
|
262
|
+
moduleRefToken,
|
|
263
|
+
rest: { path: 'example-extensions' },
|
|
264
|
+
graphql: {
|
|
265
|
+
names: {
|
|
266
|
+
object: 'TransportExampleExtensionApi',
|
|
267
|
+
create: 'TransportExampleExtensionApiCreateInput',
|
|
268
|
+
patch: 'TransportExampleExtensionApiUpdateInput',
|
|
269
|
+
conditions: 'TransportExampleExtensionApiCondition',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
const relationRegistration = createOmniRelationProjectionRegistration({
|
|
274
|
+
apiModel: ExampleLinkApi,
|
|
275
|
+
definition: relationDefinition,
|
|
276
|
+
dbConnection: 'default',
|
|
277
|
+
catalog: { token: catalogToken },
|
|
278
|
+
lifecycle: { token: lifecycleToken },
|
|
279
|
+
moduleRefToken,
|
|
280
|
+
rest: { path: 'example-links' },
|
|
281
|
+
graphql: {
|
|
282
|
+
names: {
|
|
283
|
+
object: 'TransportExampleLinkApi',
|
|
284
|
+
create: 'TransportExampleLinkApiCreateInput',
|
|
285
|
+
patch: 'TransportExampleLinkApiUpdateInput',
|
|
286
|
+
conditions: 'TransportExampleLinkApiCondition',
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
const moduleRef = await Test.createTestingModule({
|
|
291
|
+
imports: [
|
|
292
|
+
GraphQLModule.forRoot<ApolloDriverConfig>({
|
|
293
|
+
driver: ApolloDriver,
|
|
294
|
+
autoSchemaFile: true,
|
|
295
|
+
path: '/graphql',
|
|
296
|
+
}),
|
|
297
|
+
EventEmitterModule.forRoot(),
|
|
298
|
+
EventModule.forRootAsync(),
|
|
299
|
+
TypeOrmModule.forRoot({
|
|
300
|
+
type: 'sqlite',
|
|
301
|
+
database: ':memory:',
|
|
302
|
+
synchronize: false,
|
|
303
|
+
autoLoadEntities: true,
|
|
304
|
+
}),
|
|
305
|
+
OmniKernelModule.register({
|
|
306
|
+
dbConnection: 'default',
|
|
307
|
+
defaultScopeId: scope.scopeId,
|
|
308
|
+
reservedRecordKinds: registration.reservedRecordKinds,
|
|
309
|
+
relationKinds: relationRegistration.relationKinds,
|
|
310
|
+
}),
|
|
311
|
+
TypeOrmModule.forFeature(registration.entities),
|
|
312
|
+
],
|
|
313
|
+
controllers: [
|
|
314
|
+
...registration.controllers,
|
|
315
|
+
...relationRegistration.controllers,
|
|
316
|
+
...rawRecordResource.controllers,
|
|
317
|
+
],
|
|
318
|
+
providers: [
|
|
319
|
+
UUIDScalar,
|
|
320
|
+
{ provide: moduleRefToken, useExisting: ModuleRef },
|
|
321
|
+
createOmniProjectionReaderCatalogProvider(
|
|
322
|
+
[registration, relationRegistration],
|
|
323
|
+
catalogToken,
|
|
324
|
+
),
|
|
325
|
+
{
|
|
326
|
+
provide: lifecycleToken,
|
|
327
|
+
scope: Scope.REQUEST,
|
|
328
|
+
useFactory: () => ({
|
|
329
|
+
beforeCreate: async (context: any) => {
|
|
330
|
+
lifecycleBeforeCreate(context);
|
|
331
|
+
await context.readers.extension(definition.id).list({
|
|
332
|
+
where: { label: '__missing__' },
|
|
333
|
+
take: 1,
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
beforeUpdate: async (context: any) => {
|
|
337
|
+
lifecycleBeforeUpdate(context);
|
|
338
|
+
},
|
|
339
|
+
beforeDelete: async (context: any) => {
|
|
340
|
+
lifecycleBeforeDelete(context);
|
|
341
|
+
},
|
|
342
|
+
}),
|
|
343
|
+
},
|
|
344
|
+
...registration.providers,
|
|
345
|
+
...relationRegistration.providers,
|
|
346
|
+
...rawRecordResource.providers,
|
|
347
|
+
],
|
|
348
|
+
}).compile();
|
|
349
|
+
|
|
350
|
+
dataSource = moduleRef.get<DataSource>(getDataSourceToken());
|
|
351
|
+
const snapshot = captureOmniMigrationSnapshot(
|
|
352
|
+
'example-nest-extension-transport-v1',
|
|
353
|
+
dataSource,
|
|
354
|
+
[registration],
|
|
355
|
+
);
|
|
356
|
+
const migration = createOmniMigrationPlan(snapshot);
|
|
357
|
+
const queryRunner = dataSource.createQueryRunner();
|
|
358
|
+
const migrationRunner: OmniMigrationRunner = queryRunner;
|
|
359
|
+
await queryRunner.connect();
|
|
360
|
+
try {
|
|
361
|
+
await migration.create(migrationRunner);
|
|
362
|
+
} finally {
|
|
363
|
+
await queryRunner.release();
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
app = moduleRef.createNestApplication();
|
|
367
|
+
await app.init();
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
afterAll(async () => {
|
|
371
|
+
await app?.close();
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('boots with EventModule, a consumer ModuleRef token, and generated CRUD', async () => {
|
|
375
|
+
const schema = app.get(GraphQLSchemaHost).schema;
|
|
376
|
+
const queryFields = Object.keys(schema.getQueryType()!.getFields());
|
|
377
|
+
const mutationFields = Object.keys(schema.getMutationType()!.getFields());
|
|
378
|
+
expect(queryFields).toEqual(
|
|
379
|
+
expect.arrayContaining([
|
|
380
|
+
'getExampleExtensionApi',
|
|
381
|
+
'getExampleExtensionApiGrid',
|
|
382
|
+
'getExampleLinkApi',
|
|
383
|
+
'getExampleLinkApiGrid',
|
|
384
|
+
]),
|
|
385
|
+
);
|
|
386
|
+
expect(mutationFields).toEqual(
|
|
387
|
+
expect.arrayContaining([
|
|
388
|
+
'createExampleExtensionApi',
|
|
389
|
+
'updateExampleExtensionApi',
|
|
390
|
+
'deleteExampleExtensionApi',
|
|
391
|
+
'createExampleLinkApi',
|
|
392
|
+
'updateExampleLinkApi',
|
|
393
|
+
'deleteExampleLinkApi',
|
|
394
|
+
]),
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
await request(app.getHttpServer())
|
|
398
|
+
.post('/example-extensions')
|
|
399
|
+
.send({ guid: restGuid, label: 'REST extension', enabled: true })
|
|
400
|
+
.expect(201)
|
|
401
|
+
.expect(({ body }) => {
|
|
402
|
+
expect(body).toMatchObject({
|
|
403
|
+
guid: restGuid,
|
|
404
|
+
label: 'REST extension',
|
|
405
|
+
enabled: true,
|
|
406
|
+
revision: 1,
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
await request(app.getHttpServer())
|
|
411
|
+
.get(`/example-extensions/${restGuid}`)
|
|
412
|
+
.expect(200)
|
|
413
|
+
.expect(({ body }) => {
|
|
414
|
+
expect(body.enabled).toBe(true);
|
|
415
|
+
});
|
|
416
|
+
await request(app.getHttpServer())
|
|
417
|
+
.get('/example-extensions')
|
|
418
|
+
.expect(200)
|
|
419
|
+
.expect(({ body }) => {
|
|
420
|
+
expect(body.list).toEqual(
|
|
421
|
+
expect.arrayContaining([expect.objectContaining({ guid: restGuid })]),
|
|
422
|
+
);
|
|
423
|
+
});
|
|
424
|
+
await request(app.getHttpServer())
|
|
425
|
+
.put(`/example-extensions/${restGuid}`)
|
|
426
|
+
.send({ label: 'REST extension patched', enabled: false, expectedRevision: 1 })
|
|
427
|
+
.expect(200)
|
|
428
|
+
.expect(({ body }) => {
|
|
429
|
+
expect(body).toMatchObject({
|
|
430
|
+
guid: restGuid,
|
|
431
|
+
label: 'REST extension patched',
|
|
432
|
+
enabled: false,
|
|
433
|
+
revision: 2,
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
const graphCreate = await request(app.getHttpServer())
|
|
438
|
+
.post('/graphql')
|
|
439
|
+
.send({
|
|
440
|
+
query: `mutation CreateExample($input: TransportExampleExtensionApiCreateInput!) {
|
|
441
|
+
createExampleExtensionApi(input: $input) { guid label enabled revision }
|
|
442
|
+
}`,
|
|
443
|
+
variables: {
|
|
444
|
+
input: {
|
|
445
|
+
guid: graphqlGuid,
|
|
446
|
+
label: 'GraphQL extension',
|
|
447
|
+
enabled: true,
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
})
|
|
451
|
+
.expect(200);
|
|
452
|
+
expect(graphCreate.body.errors).toBeUndefined();
|
|
453
|
+
expect(graphCreate.body.data.createExampleExtensionApi).toMatchObject({
|
|
454
|
+
guid: graphqlGuid,
|
|
455
|
+
enabled: true,
|
|
456
|
+
revision: 1,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
await request(app.getHttpServer())
|
|
460
|
+
.post('/example-links')
|
|
461
|
+
.send({
|
|
462
|
+
guid: relationGuid,
|
|
463
|
+
linkKind: 'example_link',
|
|
464
|
+
sourceWorkItemId: restGuid,
|
|
465
|
+
targetWorkItemId: graphqlGuid,
|
|
466
|
+
metadata: { origin: 'generated REST' },
|
|
467
|
+
})
|
|
468
|
+
.expect(201)
|
|
469
|
+
.expect(({ body }) => {
|
|
470
|
+
expect(body).toMatchObject({
|
|
471
|
+
guid: relationGuid,
|
|
472
|
+
linkKind: 'example_link',
|
|
473
|
+
sourceWorkItemId: restGuid,
|
|
474
|
+
targetWorkItemId: graphqlGuid,
|
|
475
|
+
metadata: { origin: 'generated REST' },
|
|
476
|
+
});
|
|
477
|
+
expect(body.kind).toBeUndefined();
|
|
478
|
+
expect(body.status).toBeUndefined();
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
const graphRead = await request(app.getHttpServer())
|
|
482
|
+
.post('/graphql')
|
|
483
|
+
.send({
|
|
484
|
+
query: `query {
|
|
485
|
+
getExampleExtensionApi(guid: "${restGuid}") { guid label enabled revision }
|
|
486
|
+
getExampleExtensionApiGrid { nodes { guid label enabled } pageData { count } }
|
|
487
|
+
}`,
|
|
488
|
+
})
|
|
489
|
+
.expect(200);
|
|
490
|
+
expect(graphRead.body.errors).toBeUndefined();
|
|
491
|
+
expect(graphRead.body.data.getExampleExtensionApi).toMatchObject({
|
|
492
|
+
guid: restGuid,
|
|
493
|
+
enabled: false,
|
|
494
|
+
revision: 2,
|
|
495
|
+
});
|
|
496
|
+
expect(graphRead.body.data.getExampleExtensionApiGrid.nodes).toEqual(
|
|
497
|
+
expect.arrayContaining([
|
|
498
|
+
expect.objectContaining({ guid: restGuid }),
|
|
499
|
+
expect.objectContaining({ guid: graphqlGuid }),
|
|
500
|
+
]),
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const graphRelation = await request(app.getHttpServer())
|
|
504
|
+
.post('/graphql')
|
|
505
|
+
.send({
|
|
506
|
+
query: `query {
|
|
507
|
+
getExampleLinkApi(guid: "${relationGuid}") {
|
|
508
|
+
guid linkKind sourceWorkItemId targetWorkItemId metadata
|
|
509
|
+
}
|
|
510
|
+
getExampleLinkApiGrid { nodes { guid } pageData { count } }
|
|
511
|
+
}`,
|
|
512
|
+
})
|
|
513
|
+
.expect(200);
|
|
514
|
+
expect(graphRelation.body.errors).toBeUndefined();
|
|
515
|
+
expect(graphRelation.body.data.getExampleLinkApi).toMatchObject({
|
|
516
|
+
guid: relationGuid,
|
|
517
|
+
linkKind: 'example_link',
|
|
518
|
+
sourceWorkItemId: restGuid,
|
|
519
|
+
targetWorkItemId: graphqlGuid,
|
|
520
|
+
});
|
|
521
|
+
expect(graphRelation.body.data.getExampleLinkApiGrid.nodes).toEqual(
|
|
522
|
+
expect.arrayContaining([expect.objectContaining({ guid: relationGuid })]),
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
const graphRelationUpdate = await request(app.getHttpServer())
|
|
526
|
+
.post('/graphql')
|
|
527
|
+
.send({
|
|
528
|
+
query: `mutation UpdateLink(
|
|
529
|
+
$conditions: TransportExampleLinkApiCondition!
|
|
530
|
+
$input: TransportExampleLinkApiUpdateInput!
|
|
531
|
+
) {
|
|
532
|
+
updateExampleLinkApi(conditions: $conditions, input: $input) {
|
|
533
|
+
guid metadata revision
|
|
534
|
+
}
|
|
535
|
+
}`,
|
|
536
|
+
variables: {
|
|
537
|
+
conditions: { guid: relationGuid },
|
|
538
|
+
input: {
|
|
539
|
+
metadata: { origin: 'generated GraphQL' },
|
|
540
|
+
expectedRevision: 1,
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
})
|
|
544
|
+
.expect(200);
|
|
545
|
+
expect(graphRelationUpdate.body.errors).toBeUndefined();
|
|
546
|
+
expect(graphRelationUpdate.body.data.updateExampleLinkApi).toMatchObject({
|
|
547
|
+
guid: relationGuid,
|
|
548
|
+
metadata: { origin: 'generated GraphQL' },
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
const graphUpdate = await request(app.getHttpServer())
|
|
552
|
+
.post('/graphql')
|
|
553
|
+
.send({
|
|
554
|
+
query: `mutation UpdateExample(
|
|
555
|
+
$conditions: TransportExampleExtensionApiCondition!
|
|
556
|
+
$input: TransportExampleExtensionApiUpdateInput!
|
|
557
|
+
) {
|
|
558
|
+
updateExampleExtensionApi(conditions: $conditions, input: $input) {
|
|
559
|
+
guid label enabled revision
|
|
560
|
+
}
|
|
561
|
+
}`,
|
|
562
|
+
variables: {
|
|
563
|
+
conditions: { guid: graphqlGuid },
|
|
564
|
+
input: { label: 'GraphQL extension patched', enabled: false, expectedRevision: 1 },
|
|
565
|
+
},
|
|
566
|
+
})
|
|
567
|
+
.expect(200);
|
|
568
|
+
expect(graphUpdate.body.errors).toBeUndefined();
|
|
569
|
+
expect(graphUpdate.body.data.updateExampleExtensionApi).toMatchObject({
|
|
570
|
+
guid: graphqlGuid,
|
|
571
|
+
enabled: false,
|
|
572
|
+
revision: 2,
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
await request(app.getHttpServer())
|
|
576
|
+
.post('/raw-records')
|
|
577
|
+
.send({
|
|
578
|
+
guid: rejectedRecordGuid,
|
|
579
|
+
title: 'attempted owner',
|
|
580
|
+
kind: definition.owner.kind,
|
|
581
|
+
status: OmniRecordStatus.Active,
|
|
582
|
+
payloadSchemaId: definition.owner.schema.id,
|
|
583
|
+
payloadSchemaVersion: definition.owner.schema.version,
|
|
584
|
+
})
|
|
585
|
+
.expect(400);
|
|
586
|
+
await request(app.getHttpServer())
|
|
587
|
+
.post('/raw-records')
|
|
588
|
+
.send({
|
|
589
|
+
guid: normalRecordGuid,
|
|
590
|
+
title: 'normal record',
|
|
591
|
+
kind: 'normal_record',
|
|
592
|
+
status: OmniRecordStatus.Active,
|
|
593
|
+
})
|
|
594
|
+
.expect(201);
|
|
595
|
+
await request(app.getHttpServer())
|
|
596
|
+
.post('/example-links')
|
|
597
|
+
.send({
|
|
598
|
+
guid: '10000000-0000-4000-8000-000000000207',
|
|
599
|
+
linkKind: 'example_link',
|
|
600
|
+
sourceWorkItemId: normalRecordGuid,
|
|
601
|
+
targetWorkItemId: graphqlGuid,
|
|
602
|
+
})
|
|
603
|
+
.expect(400);
|
|
604
|
+
await request(app.getHttpServer())
|
|
605
|
+
.put(`/raw-records/${normalRecordGuid}`)
|
|
606
|
+
.send({ kind: definition.owner.kind })
|
|
607
|
+
.expect(400);
|
|
608
|
+
await request(app.getHttpServer())
|
|
609
|
+
.put(`/raw-records/${restGuid}`)
|
|
610
|
+
.send({ kind: 'normal_record' })
|
|
611
|
+
.expect(400);
|
|
612
|
+
await request(app.getHttpServer())
|
|
613
|
+
.delete(`/raw-records/${restGuid}`)
|
|
614
|
+
.expect(400);
|
|
615
|
+
|
|
616
|
+
for (const requestBody of [
|
|
617
|
+
{
|
|
618
|
+
query: `mutation CreateRaw($input: OmniRecordCreateInput!) {
|
|
619
|
+
Raw_createOmniRecordEntity(input: $input) { guid }
|
|
620
|
+
}`,
|
|
621
|
+
variables: {
|
|
622
|
+
input: {
|
|
623
|
+
guid: '10000000-0000-4000-8000-000000000205',
|
|
624
|
+
title: 'attempted GraphQL owner',
|
|
625
|
+
kind: definition.owner.kind,
|
|
626
|
+
status: 'Active',
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
query: `mutation UpdateRaw(
|
|
632
|
+
$conditions: OmniRecordCondition!
|
|
633
|
+
$input: OmniRecordUpdateInput!
|
|
634
|
+
) {
|
|
635
|
+
Raw_updateOmniRecordEntity(conditions: $conditions, input: $input) { guid }
|
|
636
|
+
}`,
|
|
637
|
+
variables: {
|
|
638
|
+
conditions: { guid: restGuid },
|
|
639
|
+
input: { kind: 'normal_record' },
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
query: `mutation DeleteRaw($conditions: OmniRecordCondition!) {
|
|
644
|
+
Raw_deleteOmniRecordEntity(conditions: $conditions)
|
|
645
|
+
}`,
|
|
646
|
+
variables: { conditions: { guid: restGuid } },
|
|
647
|
+
},
|
|
648
|
+
]) {
|
|
649
|
+
const response = await request(app.getHttpServer())
|
|
650
|
+
.post('/graphql')
|
|
651
|
+
.send(requestBody);
|
|
652
|
+
expect([200, 400]).toContain(response.status);
|
|
653
|
+
expect(response.body.data ?? null).toBeNull();
|
|
654
|
+
expect(response.body.errors?.[0]?.message ?? response.body.message).toContain(
|
|
655
|
+
'owned by a registered extension projection',
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const graphRelationDelete = await request(app.getHttpServer())
|
|
660
|
+
.post('/graphql')
|
|
661
|
+
.send({
|
|
662
|
+
query: `mutation DeleteLink($conditions: TransportExampleLinkApiCondition!) {
|
|
663
|
+
deleteExampleLinkApi(conditions: $conditions)
|
|
664
|
+
}`,
|
|
665
|
+
variables: { conditions: { guid: relationGuid } },
|
|
666
|
+
})
|
|
667
|
+
.expect(200);
|
|
668
|
+
expect(graphRelationDelete.body.errors).toBeUndefined();
|
|
669
|
+
expect(graphRelationDelete.body.data.deleteExampleLinkApi).toBe(true);
|
|
670
|
+
|
|
671
|
+
const graphDelete = await request(app.getHttpServer())
|
|
672
|
+
.post('/graphql')
|
|
673
|
+
.send({
|
|
674
|
+
query: `mutation DeleteExample($conditions: TransportExampleExtensionApiCondition!) {
|
|
675
|
+
deleteExampleExtensionApi(conditions: $conditions)
|
|
676
|
+
}`,
|
|
677
|
+
variables: { conditions: { guid: graphqlGuid } },
|
|
678
|
+
})
|
|
679
|
+
.expect(200);
|
|
680
|
+
expect(graphDelete.body.errors).toBeUndefined();
|
|
681
|
+
expect(graphDelete.body.data.deleteExampleExtensionApi).toBe(true);
|
|
682
|
+
|
|
683
|
+
await request(app.getHttpServer())
|
|
684
|
+
.delete(`/example-extensions/${restGuid}`)
|
|
685
|
+
.expect(200)
|
|
686
|
+
.expect({ deleted: true });
|
|
687
|
+
expect(
|
|
688
|
+
await dataSource.getRepository(OmniRecordEntity).findOneBy({
|
|
689
|
+
scopeId: scope.scopeId,
|
|
690
|
+
guid: restGuid,
|
|
691
|
+
}),
|
|
692
|
+
).toBeNull();
|
|
693
|
+
expect(lifecycleBeforeCreate).toHaveBeenCalledTimes(3);
|
|
694
|
+
expect(lifecycleBeforeUpdate).toHaveBeenCalledTimes(3);
|
|
695
|
+
expect(lifecycleBeforeDelete).toHaveBeenCalledTimes(3);
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
describe('Omni migration snapshot ordering', () => {
|
|
700
|
+
it('orders referenced extension tables independently of snapshot order', () => {
|
|
701
|
+
const parent = {
|
|
702
|
+
name: 'projection_parent',
|
|
703
|
+
columns: [],
|
|
704
|
+
};
|
|
705
|
+
const child = {
|
|
706
|
+
name: 'projection_child',
|
|
707
|
+
columns: [],
|
|
708
|
+
foreignKeys: [
|
|
709
|
+
{
|
|
710
|
+
name: 'projection_child_parent_fk',
|
|
711
|
+
columnNames: ['scopeId', 'parentGuid'],
|
|
712
|
+
referencedTableName: 'projection_parent',
|
|
713
|
+
referencedColumnNames: ['scopeId', 'guid'],
|
|
714
|
+
onDelete: 'RESTRICT' as const,
|
|
715
|
+
},
|
|
716
|
+
],
|
|
717
|
+
};
|
|
718
|
+
const plan = createOmniMigrationPlan(
|
|
719
|
+
defineOmniMigrationSnapshot({
|
|
720
|
+
version: 'projection-order-v1',
|
|
721
|
+
dialect: 'sqlite',
|
|
722
|
+
tables: [child, parent],
|
|
723
|
+
indexStatements: [],
|
|
724
|
+
}),
|
|
725
|
+
);
|
|
726
|
+
|
|
727
|
+
expect(plan.tableNames).toEqual(['projection_parent', 'projection_child']);
|
|
728
|
+
expect(() =>
|
|
729
|
+
createOmniMigrationPlan(
|
|
730
|
+
defineOmniMigrationSnapshot({
|
|
731
|
+
version: 'projection-order-cycle-v1',
|
|
732
|
+
dialect: 'sqlite',
|
|
733
|
+
tables: [
|
|
734
|
+
child,
|
|
735
|
+
{
|
|
736
|
+
...parent,
|
|
737
|
+
foreignKeys: [
|
|
738
|
+
{
|
|
739
|
+
name: 'projection_parent_child_fk',
|
|
740
|
+
columnNames: ['scopeId', 'childGuid'],
|
|
741
|
+
referencedTableName: 'projection_child',
|
|
742
|
+
referencedColumnNames: ['scopeId', 'guid'],
|
|
743
|
+
onDelete: 'RESTRICT',
|
|
744
|
+
},
|
|
745
|
+
],
|
|
746
|
+
},
|
|
747
|
+
],
|
|
748
|
+
indexStatements: [],
|
|
749
|
+
}),
|
|
750
|
+
),
|
|
751
|
+
).toThrow('cross-table foreign-key cycle');
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
describe.each(dialectCases)(
|
|
756
|
+
"Omni migration plan (%s)",
|
|
757
|
+
({ name, url }) => {
|
|
758
|
+
let dataSource: DataSource;
|
|
759
|
+
|
|
760
|
+
afterEach(async () => {
|
|
761
|
+
if (dataSource?.isInitialized) await dataSource.destroy();
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
it("uses a frozen metadata snapshot to create Omni base and extension tables without synchronize", async () => {
|
|
765
|
+
const entity = createOmniExtensionProjectionEntity<ExtensionRow>(
|
|
766
|
+
definition,
|
|
767
|
+
createProjectionDialect(name),
|
|
768
|
+
);
|
|
769
|
+
const registration = createOmniExtensionProjectionRegistration({
|
|
770
|
+
entity,
|
|
771
|
+
apiModel: ExampleExtensionApi,
|
|
772
|
+
definition,
|
|
773
|
+
dbConnection: "default",
|
|
774
|
+
});
|
|
775
|
+
dataSource = new DataSource({
|
|
776
|
+
type: name,
|
|
777
|
+
...(name === "sqlite"
|
|
778
|
+
? { database: ":memory:" }
|
|
779
|
+
: { url: url!, ssl: false }),
|
|
780
|
+
synchronize: false,
|
|
781
|
+
entities: [
|
|
782
|
+
OmniNamedEntity,
|
|
783
|
+
OmniRecordEntity,
|
|
784
|
+
OmniDocumentEntity,
|
|
785
|
+
OmniCollectionEntity,
|
|
786
|
+
OmniRelationEntity,
|
|
787
|
+
OmniExternalRefEntity,
|
|
788
|
+
...registration.entities,
|
|
789
|
+
],
|
|
790
|
+
});
|
|
791
|
+
await dataSource.initialize();
|
|
792
|
+
if (name === "postgres") await dataSource.dropDatabase();
|
|
793
|
+
|
|
794
|
+
const captured = captureOmniMigrationSnapshot(
|
|
795
|
+
`example-nest-extension-${name}-v1`,
|
|
796
|
+
dataSource,
|
|
797
|
+
[registration],
|
|
798
|
+
);
|
|
799
|
+
const migrationSource = structuredClone(captured);
|
|
800
|
+
const plan = createOmniMigrationPlan(
|
|
801
|
+
defineOmniMigrationSnapshot(migrationSource),
|
|
802
|
+
);
|
|
803
|
+
expect(dataSource.options.synchronize).toBe(false);
|
|
804
|
+
expect(Object.isFrozen(plan)).toBe(true);
|
|
805
|
+
expect(Object.isFrozen(plan.tableNames)).toBe(true);
|
|
806
|
+
expect(Object.isFrozen(plan.indexStatements)).toBe(true);
|
|
807
|
+
expect(Object.isFrozen(captured)).toBe(true);
|
|
808
|
+
expect(Object.isFrozen(captured.tables)).toBe(true);
|
|
809
|
+
expect(Object.isFrozen(captured.indexStatements)).toBe(true);
|
|
810
|
+
expect(plan.tableNames).toEqual(
|
|
811
|
+
expect.arrayContaining([
|
|
812
|
+
"omni-named",
|
|
813
|
+
"omni-record",
|
|
814
|
+
"omni-relation",
|
|
815
|
+
"omni-external-ref",
|
|
816
|
+
definition.tableName,
|
|
817
|
+
]),
|
|
818
|
+
);
|
|
819
|
+
const shuffledPlan = createOmniMigrationPlan(
|
|
820
|
+
defineOmniMigrationSnapshot({
|
|
821
|
+
...captured,
|
|
822
|
+
tables: [...captured.tables].reverse(),
|
|
823
|
+
}),
|
|
824
|
+
);
|
|
825
|
+
expect(
|
|
826
|
+
shuffledPlan.tableNames.indexOf('omni-record'),
|
|
827
|
+
).toBeLessThan(shuffledPlan.tableNames.indexOf(definition.tableName));
|
|
828
|
+
|
|
829
|
+
const firstSnapshot = plan.createTables();
|
|
830
|
+
firstSnapshot[0].name = "mutated-copy";
|
|
831
|
+
migrationSource.tables[0].name = "mutated-migration-source";
|
|
832
|
+
migrationSource.indexStatements[0] = "mutated-index-statement";
|
|
833
|
+
expect(plan.createTables()[0].name).not.toBe("mutated-copy");
|
|
834
|
+
expect(plan.createTables()[0].name).not.toBe(
|
|
835
|
+
"mutated-migration-source",
|
|
836
|
+
);
|
|
837
|
+
expect(plan.indexStatements[0]).not.toBe("mutated-index-statement");
|
|
838
|
+
const enabledIndex = definition.fields.find(
|
|
839
|
+
(field) => field.name === "enabled",
|
|
840
|
+
)!.index!.name;
|
|
841
|
+
expect(plan.indexStatements).toEqual(
|
|
842
|
+
expect.arrayContaining([
|
|
843
|
+
expect.stringContaining(`CREATE INDEX "${enabledIndex}"`),
|
|
844
|
+
]),
|
|
845
|
+
);
|
|
846
|
+
|
|
847
|
+
const queryRunner = dataSource.createQueryRunner();
|
|
848
|
+
await queryRunner.connect();
|
|
849
|
+
try {
|
|
850
|
+
await plan.create(queryRunner);
|
|
851
|
+
} finally {
|
|
852
|
+
await queryRunner.release();
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const verificationRunner = dataSource.createQueryRunner();
|
|
856
|
+
await verificationRunner.connect();
|
|
857
|
+
try {
|
|
858
|
+
expect(await verificationRunner.hasTable(definition.tableName)).toBe(
|
|
859
|
+
true,
|
|
860
|
+
);
|
|
861
|
+
} finally {
|
|
862
|
+
await verificationRunner.release();
|
|
863
|
+
}
|
|
864
|
+
const extensionTable = plan
|
|
865
|
+
.createTables()
|
|
866
|
+
.find((table) => table.name === definition.tableName)!;
|
|
867
|
+
expect(extensionTable.foreignKeys).toEqual([
|
|
868
|
+
expect.objectContaining({
|
|
869
|
+
columnNames: ["scopeId", "guid"],
|
|
870
|
+
referencedTableName: "omni-record",
|
|
871
|
+
referencedColumnNames: ["scopeId", "guid"],
|
|
872
|
+
onDelete: "CASCADE",
|
|
873
|
+
}),
|
|
874
|
+
]);
|
|
875
|
+
expect(extensionTable.findColumnByName("payload")?.type).toBe(
|
|
876
|
+
name === "postgres" ? "jsonb" : "text",
|
|
877
|
+
);
|
|
878
|
+
|
|
879
|
+
const serviceProvider = registration.providers.find(
|
|
880
|
+
(provider) =>
|
|
881
|
+
typeof provider === "object" &&
|
|
882
|
+
provider !== null &&
|
|
883
|
+
"provide" in provider &&
|
|
884
|
+
provider.provide === registration.serviceToken,
|
|
885
|
+
) as any;
|
|
886
|
+
const service = serviceProvider.useFactory(dataSource, scope, events);
|
|
887
|
+
await service.createEntity({
|
|
888
|
+
guid: "10000000-0000-4000-8000-000000000101",
|
|
889
|
+
label: "migration-owned",
|
|
890
|
+
enabled: true,
|
|
891
|
+
});
|
|
892
|
+
expect(
|
|
893
|
+
await dataSource.getRepository(OmniRecordEntity).countBy({
|
|
894
|
+
scopeId: scope.scopeId,
|
|
895
|
+
guid: "10000000-0000-4000-8000-000000000101",
|
|
896
|
+
}),
|
|
897
|
+
).toBe(1);
|
|
898
|
+
|
|
899
|
+
const projectionDialect = createProjectionDialect(name);
|
|
900
|
+
const evidence = await projectionDialect.inspect(dataSource, definition);
|
|
901
|
+
expect(evidence.indexes).toContain(enabledIndex);
|
|
902
|
+
const indexStatement = plan.indexStatements.find((statement) =>
|
|
903
|
+
statement.includes(`CREATE INDEX "${enabledIndex}"`),
|
|
904
|
+
)!;
|
|
905
|
+
const prefix = `CREATE INDEX "${enabledIndex}" ON "${definition.tableName}" ("scopeId", `;
|
|
906
|
+
const suffix = `, "${definition.identity.column}")`;
|
|
907
|
+
expect(indexStatement.startsWith(prefix)).toBe(true);
|
|
908
|
+
expect(indexStatement.endsWith(suffix)).toBe(true);
|
|
909
|
+
const expression = indexStatement.slice(prefix.length, -suffix.length);
|
|
910
|
+
const planRunner = dataSource.createQueryRunner();
|
|
911
|
+
await planRunner.connect();
|
|
912
|
+
try {
|
|
913
|
+
if (name === "postgres") {
|
|
914
|
+
await planRunner.startTransaction();
|
|
915
|
+
await planRunner.query("SET LOCAL enable_seqscan = off");
|
|
916
|
+
const rows = await planRunner.query(
|
|
917
|
+
`EXPLAIN (COSTS OFF) SELECT "${definition.identity.column}" FROM "${definition.tableName}" WHERE "${definition.scope.column}" = $1 AND ${expression} = $2 ORDER BY "${definition.identity.column}" ASC`,
|
|
918
|
+
[scope.scopeId, true],
|
|
919
|
+
);
|
|
920
|
+
expect(JSON.stringify(rows)).toContain(enabledIndex);
|
|
921
|
+
} else {
|
|
922
|
+
const rows = await planRunner.query(
|
|
923
|
+
`EXPLAIN QUERY PLAN SELECT "${definition.identity.column}" FROM "${definition.tableName}" INDEXED BY "${enabledIndex}" WHERE "${definition.scope.column}" = ? AND ${expression} = ? ORDER BY "${definition.identity.column}" ASC`,
|
|
924
|
+
[scope.scopeId, 1],
|
|
925
|
+
);
|
|
926
|
+
expect(JSON.stringify(rows)).toContain(enabledIndex);
|
|
927
|
+
}
|
|
928
|
+
} finally {
|
|
929
|
+
if (planRunner.isTransactionActive) await planRunner.rollbackTransaction();
|
|
930
|
+
await planRunner.release();
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const downRunner = dataSource.createQueryRunner();
|
|
934
|
+
await downRunner.connect();
|
|
935
|
+
try {
|
|
936
|
+
await plan.drop(downRunner);
|
|
937
|
+
expect(await downRunner.hasTable(definition.tableName)).toBe(false);
|
|
938
|
+
expect(await downRunner.hasTable('omni-record')).toBe(false);
|
|
939
|
+
await plan.create(downRunner);
|
|
940
|
+
expect(await downRunner.hasTable(definition.tableName)).toBe(true);
|
|
941
|
+
expect(await downRunner.hasTable('omni-record')).toBe(true);
|
|
942
|
+
} finally {
|
|
943
|
+
await downRunner.release();
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
},
|
|
947
|
+
);
|