@rebasepro/server-postgresql 0.0.1-canary.4d4fb3e → 0.0.1-canary.ca2cb6e
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/dist/common/src/collections/CollectionRegistry.d.ts +8 -0
- package/dist/common/src/util/entities.d.ts +22 -0
- package/dist/common/src/util/relations.d.ts +14 -4
- package/dist/common/src/util/resolutions.d.ts +1 -1
- package/dist/index.es.js +1254 -591
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1254 -591
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +17 -29
- package/dist/server-postgresql/src/auth/services.d.ts +7 -3
- package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +1 -1
- package/dist/server-postgresql/src/connection.d.ts +34 -1
- package/dist/server-postgresql/src/data-transformer.d.ts +26 -4
- package/dist/server-postgresql/src/databasePoolManager.d.ts +2 -2
- package/dist/server-postgresql/src/schema/auth-schema.d.ts +139 -38
- package/dist/server-postgresql/src/schema/doctor-cli.d.ts +2 -0
- package/dist/server-postgresql/src/schema/doctor.d.ts +43 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +1 -1
- package/dist/server-postgresql/src/schema/test-schema.d.ts +24 -0
- package/dist/server-postgresql/src/services/EntityFetchService.d.ts +22 -8
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +1 -1
- package/dist/server-postgresql/src/services/RelationService.d.ts +11 -5
- package/dist/server-postgresql/src/services/entity-helpers.d.ts +16 -2
- package/dist/server-postgresql/src/services/entityService.d.ts +8 -6
- package/dist/server-postgresql/src/services/realtimeService.d.ts +2 -0
- package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +2 -2
- package/dist/types/src/controllers/auth.d.ts +2 -0
- package/dist/types/src/controllers/client.d.ts +119 -7
- package/dist/types/src/controllers/collection_registry.d.ts +4 -3
- package/dist/types/src/controllers/customization_controller.d.ts +7 -1
- package/dist/types/src/controllers/data.d.ts +34 -7
- package/dist/types/src/controllers/data_driver.d.ts +20 -28
- package/dist/types/src/controllers/database_admin.d.ts +2 -2
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +1 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +4 -4
- package/dist/types/src/controllers/navigation.d.ts +5 -5
- package/dist/types/src/controllers/registry.d.ts +6 -3
- package/dist/types/src/controllers/side_entity_controller.d.ts +7 -6
- package/dist/types/src/controllers/storage.d.ts +24 -26
- package/dist/types/src/rebase_context.d.ts +8 -4
- package/dist/types/src/types/backend.d.ts +4 -1
- package/dist/types/src/types/builders.d.ts +5 -4
- package/dist/types/src/types/chips.d.ts +1 -1
- package/dist/types/src/types/collections.d.ts +169 -125
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +1 -1
- package/dist/types/src/types/entity_actions.d.ts +8 -8
- package/dist/types/src/types/entity_callbacks.d.ts +15 -15
- package/dist/types/src/types/entity_link_builder.d.ts +1 -1
- package/dist/types/src/types/entity_overrides.d.ts +2 -1
- package/dist/types/src/types/entity_views.d.ts +8 -8
- package/dist/types/src/types/export_import.d.ts +3 -3
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/plugins.d.ts +72 -18
- package/dist/types/src/types/properties.d.ts +118 -33
- package/dist/types/src/types/relations.d.ts +1 -1
- package/dist/types/src/types/slots.d.ts +30 -6
- package/dist/types/src/types/translations.d.ts +44 -0
- package/dist/types/src/types/user_management_delegate.d.ts +1 -0
- package/drizzle-test/0000_woozy_junta.sql +6 -0
- package/drizzle-test/0001_youthful_arachne.sql +1 -0
- package/drizzle-test/0002_lively_dragon_lord.sql +2 -0
- package/drizzle-test/0003_mean_king_cobra.sql +2 -0
- package/drizzle-test/meta/0000_snapshot.json +47 -0
- package/drizzle-test/meta/0001_snapshot.json +48 -0
- package/drizzle-test/meta/0002_snapshot.json +38 -0
- package/drizzle-test/meta/0003_snapshot.json +48 -0
- package/drizzle-test/meta/_journal.json +34 -0
- package/drizzle-test-out/0000_tan_trauma.sql +6 -0
- package/drizzle-test-out/0001_rapid_drax.sql +1 -0
- package/drizzle-test-out/meta/0000_snapshot.json +44 -0
- package/drizzle-test-out/meta/0001_snapshot.json +54 -0
- package/drizzle-test-out/meta/_journal.json +20 -0
- package/drizzle.test.config.ts +10 -0
- package/package.json +88 -89
- package/scratch.ts +41 -0
- package/src/PostgresBackendDriver.ts +63 -79
- package/src/PostgresBootstrapper.ts +7 -8
- package/src/auth/ensure-tables.ts +158 -86
- package/src/auth/services.ts +109 -50
- package/src/cli.ts +259 -16
- package/src/collections/PostgresCollectionRegistry.ts +6 -6
- package/src/connection.ts +70 -48
- package/src/data-transformer.ts +155 -116
- package/src/databasePoolManager.ts +6 -5
- package/src/history/HistoryService.ts +3 -12
- package/src/interfaces.ts +3 -3
- package/src/schema/auth-schema.ts +26 -3
- package/src/schema/doctor-cli.ts +47 -0
- package/src/schema/doctor.ts +595 -0
- package/src/schema/generate-drizzle-schema-logic.ts +204 -57
- package/src/schema/generate-drizzle-schema.ts +6 -6
- package/src/schema/test-schema.ts +11 -0
- package/src/services/BranchService.ts +5 -5
- package/src/services/EntityFetchService.ts +317 -188
- package/src/services/EntityPersistService.ts +15 -17
- package/src/services/RelationService.ts +299 -37
- package/src/services/entity-helpers.ts +39 -13
- package/src/services/entityService.ts +11 -9
- package/src/services/realtimeService.ts +58 -29
- package/src/utils/drizzle-conditions.ts +25 -24
- package/src/websocket.ts +52 -21
- package/test/auth-services.test.ts +131 -39
- package/test/batch-many-to-many-regression.test.ts +573 -0
- package/test/branchService.test.ts +22 -12
- package/test/data-transformer-hardening.test.ts +417 -0
- package/test/data-transformer.test.ts +175 -0
- package/test/doctor.test.ts +182 -0
- package/test/entityService.errors.test.ts +31 -16
- package/test/entityService.relations.test.ts +155 -59
- package/test/entityService.subcollection-search.test.ts +107 -57
- package/test/entityService.test.ts +105 -47
- package/test/generate-drizzle-schema.test.ts +262 -69
- package/test/historyService.test.ts +31 -16
- package/test/n-plus-one-regression.test.ts +314 -0
- package/test/postgresDataDriver.test.ts +260 -168
- package/test/realtimeService.test.ts +70 -39
- package/test/relation-pipeline-gaps.test.ts +637 -0
- package/test/relations.test.ts +492 -39
- package/test-drizzle-bug.ts +18 -0
- package/test-drizzle-out/0000_cultured_freak.sql +7 -0
- package/test-drizzle-out/0001_tiresome_professor_monster.sql +1 -0
- package/test-drizzle-out/meta/0000_snapshot.json +55 -0
- package/test-drizzle-out/meta/0001_snapshot.json +63 -0
- package/test-drizzle-out/meta/_journal.json +20 -0
- package/test-drizzle-prompt.sh +2 -0
- package/test-policy-prompt.sh +3 -0
- package/test-programmatic.ts +30 -0
- package/test-programmatic2.ts +59 -0
- package/test-schema-no-policies.ts +12 -0
- package/test_drizzle_mock.js +2 -2
- package/test_find_changed.mjs +3 -1
- package/test_hash.js +14 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +5 -5
|
@@ -55,8 +55,10 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
55
55
|
id: { type: "number" },
|
|
56
56
|
name: { type: "string" },
|
|
57
57
|
email: { type: "string" },
|
|
58
|
-
orders: { type: "relation",
|
|
59
|
-
|
|
58
|
+
orders: { type: "relation",
|
|
59
|
+
relationName: "orders" },
|
|
60
|
+
profile: { type: "relation",
|
|
61
|
+
relationName: "profile" }
|
|
60
62
|
},
|
|
61
63
|
relations: [
|
|
62
64
|
{
|
|
@@ -84,8 +86,10 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
84
86
|
properties: {
|
|
85
87
|
id: { type: "number" },
|
|
86
88
|
total: { type: "number" },
|
|
87
|
-
customer: { type: "relation",
|
|
88
|
-
|
|
89
|
+
customer: { type: "relation",
|
|
90
|
+
relationName: "customer" },
|
|
91
|
+
products: { type: "relation",
|
|
92
|
+
relationName: "products" }
|
|
89
93
|
},
|
|
90
94
|
relations: [
|
|
91
95
|
{
|
|
@@ -129,7 +133,8 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
129
133
|
properties: {
|
|
130
134
|
id: { type: "number" },
|
|
131
135
|
bio: { type: "string" },
|
|
132
|
-
user: { type: "relation",
|
|
136
|
+
user: { type: "relation",
|
|
137
|
+
relationName: "user" }
|
|
133
138
|
},
|
|
134
139
|
relations: [
|
|
135
140
|
{
|
|
@@ -192,8 +197,12 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
192
197
|
describe("One-to-Many Relations (Inverse)", () => {
|
|
193
198
|
it("should fetch related entities using foreign key where clause", async () => {
|
|
194
199
|
const mockOrders = [
|
|
195
|
-
{ id: 1,
|
|
196
|
-
|
|
200
|
+
{ id: 1,
|
|
201
|
+
total: 100,
|
|
202
|
+
customer_id: 1 },
|
|
203
|
+
{ id: 2,
|
|
204
|
+
total: 200,
|
|
205
|
+
customer_id: 1 }
|
|
197
206
|
];
|
|
198
207
|
// RelationService.fetchEntitiesUsingJoins ends query chain with where(), not orderBy()
|
|
199
208
|
db.where.mockReturnValue({
|
|
@@ -224,7 +233,9 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
224
233
|
it("should serialize owning relation correctly on create", async () => {
|
|
225
234
|
const newOrder = {
|
|
226
235
|
total: 150,
|
|
227
|
-
customer: { id: "1",
|
|
236
|
+
customer: { id: "1",
|
|
237
|
+
path: "customers",
|
|
238
|
+
__type: "relation" }
|
|
228
239
|
};
|
|
229
240
|
|
|
230
241
|
db.returning.mockResolvedValue([{ id: 3 }]);
|
|
@@ -268,8 +279,12 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
268
279
|
describe("Many-to-Many Relations (Through Table)", () => {
|
|
269
280
|
it("should handle many-to-many relations with junction table", async () => {
|
|
270
281
|
const mockProducts = [
|
|
271
|
-
{ id: 1,
|
|
272
|
-
|
|
282
|
+
{ id: 1,
|
|
283
|
+
name: "Product 1",
|
|
284
|
+
price: 10 },
|
|
285
|
+
{ id: 2,
|
|
286
|
+
name: "Product 2",
|
|
287
|
+
price: 20 }
|
|
273
288
|
];
|
|
274
289
|
// For many-to-many with through table, the query uses innerJoin and ends with where()
|
|
275
290
|
db.where.mockReturnValue({
|
|
@@ -290,7 +305,9 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
290
305
|
it("should create many-to-many relations correctly", async () => {
|
|
291
306
|
const newOrder = {
|
|
292
307
|
total: 300,
|
|
293
|
-
customer: { id: "1",
|
|
308
|
+
customer: { id: "1",
|
|
309
|
+
path: "customers",
|
|
310
|
+
__type: "relation" }
|
|
294
311
|
};
|
|
295
312
|
|
|
296
313
|
db.returning.mockResolvedValue([{ id: 4 }]);
|
|
@@ -312,7 +329,9 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
312
329
|
describe("One-to-One Relations", () => {
|
|
313
330
|
it("should handle one-to-one relations correctly", async () => {
|
|
314
331
|
const mockProfile = [
|
|
315
|
-
{ id: 1,
|
|
332
|
+
{ id: 1,
|
|
333
|
+
bio: "User bio",
|
|
334
|
+
user_id: 1 }
|
|
316
335
|
];
|
|
317
336
|
// RelationService ends query chain with where()
|
|
318
337
|
db.where.mockReturnValue({
|
|
@@ -331,7 +350,9 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
331
350
|
it("should create one-to-one relations correctly", async () => {
|
|
332
351
|
const newProfile = {
|
|
333
352
|
bio: "New user bio",
|
|
334
|
-
user: { id: "1",
|
|
353
|
+
user: { id: "1",
|
|
354
|
+
path: "customers",
|
|
355
|
+
__type: "relation" }
|
|
335
356
|
};
|
|
336
357
|
|
|
337
358
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
@@ -382,7 +403,8 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
382
403
|
describe("Complex Relation Queries", () => {
|
|
383
404
|
it("should handle deep nested relation paths", async () => {
|
|
384
405
|
const mockProducts = [
|
|
385
|
-
{ id: 1,
|
|
406
|
+
{ id: 1,
|
|
407
|
+
name: "Product 1" }
|
|
386
408
|
];
|
|
387
409
|
// RelationService ends query chain with where()
|
|
388
410
|
db.where.mockReturnValue({
|
|
@@ -400,7 +422,9 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
400
422
|
|
|
401
423
|
it("should apply filters on related entities", async () => {
|
|
402
424
|
const mockOrders = [
|
|
403
|
-
{ id: 1,
|
|
425
|
+
{ id: 1,
|
|
426
|
+
total: 100,
|
|
427
|
+
customer_id: 1 }
|
|
404
428
|
];
|
|
405
429
|
// RelationService ends query chain with where()
|
|
406
430
|
db.where.mockReturnValue({
|
|
@@ -420,8 +444,12 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
420
444
|
|
|
421
445
|
it("should order related entities correctly", async () => {
|
|
422
446
|
const mockOrders = [
|
|
423
|
-
{ id: 2,
|
|
424
|
-
|
|
447
|
+
{ id: 2,
|
|
448
|
+
total: 200,
|
|
449
|
+
customer_id: 1 },
|
|
450
|
+
{ id: 1,
|
|
451
|
+
total: 100,
|
|
452
|
+
customer_id: 1 }
|
|
425
453
|
];
|
|
426
454
|
// RelationService ends query chain with where()
|
|
427
455
|
db.where.mockReturnValue({
|
|
@@ -445,7 +473,9 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
445
473
|
describe("Relation Updates", () => {
|
|
446
474
|
it("should update owning relations correctly", async () => {
|
|
447
475
|
const updatedOrder = {
|
|
448
|
-
customer: { id: "2",
|
|
476
|
+
customer: { id: "2",
|
|
477
|
+
path: "customers",
|
|
478
|
+
__type: "relation" }
|
|
449
479
|
};
|
|
450
480
|
|
|
451
481
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
@@ -526,7 +556,8 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
526
556
|
properties: {
|
|
527
557
|
id: { type: "number" },
|
|
528
558
|
title: { type: "string" },
|
|
529
|
-
authorProfile: { type: "relation",
|
|
559
|
+
authorProfile: { type: "relation",
|
|
560
|
+
relationName: "authorProfile" }
|
|
530
561
|
},
|
|
531
562
|
relations: [
|
|
532
563
|
{
|
|
@@ -535,8 +566,12 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
535
566
|
cardinality: "one",
|
|
536
567
|
direction: "owning",
|
|
537
568
|
joinPath: [
|
|
538
|
-
{ table: "authors",
|
|
539
|
-
|
|
569
|
+
{ table: "authors",
|
|
570
|
+
on: { from: "posts.author_id",
|
|
571
|
+
to: "authors.id" } },
|
|
572
|
+
{ table: "user_profiles",
|
|
573
|
+
on: { from: "authors.id",
|
|
574
|
+
to: "user_profiles.user_id" } }
|
|
540
575
|
]
|
|
541
576
|
}
|
|
542
577
|
],
|
|
@@ -554,11 +589,15 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
554
589
|
|
|
555
590
|
const newPost = {
|
|
556
591
|
title: "Test Post",
|
|
557
|
-
authorProfile: { id: "1",
|
|
592
|
+
authorProfile: { id: "1",
|
|
593
|
+
path: "user_profiles",
|
|
594
|
+
__type: "relation" }
|
|
558
595
|
};
|
|
559
596
|
|
|
560
597
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
561
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
598
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
599
|
+
title: "Test Post",
|
|
600
|
+
author_id: 1 }]);
|
|
562
601
|
|
|
563
602
|
const entity = await entityService.saveEntity("posts_jp", newPost);
|
|
564
603
|
|
|
@@ -577,11 +616,13 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
577
616
|
|
|
578
617
|
const postUpdate = {
|
|
579
618
|
title: "Test Post Updated",
|
|
580
|
-
authorProfile: { id: "1",
|
|
619
|
+
authorProfile: { id: "1",
|
|
620
|
+
path: "user_profiles",
|
|
621
|
+
__type: "relation" }
|
|
581
622
|
};
|
|
582
623
|
|
|
583
624
|
const expectedOps: string[] = [];
|
|
584
|
-
|
|
625
|
+
|
|
585
626
|
// Track updateJoinPathOneToOneRelations
|
|
586
627
|
const relationService = entityService.getPersistService().getRelationService();
|
|
587
628
|
const spyJoinPath = jest.spyOn(relationService, "updateJoinPathOneToOneRelations").mockImplementation(async () => {
|
|
@@ -597,7 +638,9 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
597
638
|
return originalUpdate.call(this, table);
|
|
598
639
|
}) as any;
|
|
599
640
|
|
|
600
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
641
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
642
|
+
title: "Test Post Updated",
|
|
643
|
+
author_id: 1 }]);
|
|
601
644
|
|
|
602
645
|
try {
|
|
603
646
|
await entityService.saveEntity("posts_jp", postUpdate, 1);
|
|
@@ -614,11 +657,14 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
614
657
|
it("should update inverse one-to-one relation", async () => {
|
|
615
658
|
const customerWithProfile = {
|
|
616
659
|
name: "John Doe",
|
|
617
|
-
profile: { id: "1",
|
|
660
|
+
profile: { id: "1",
|
|
661
|
+
path: "user_profiles",
|
|
662
|
+
__type: "relation" }
|
|
618
663
|
};
|
|
619
664
|
|
|
620
665
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
621
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
666
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
667
|
+
name: "John Doe" }]);
|
|
622
668
|
|
|
623
669
|
const entity = await entityService.saveEntity("customers", customerWithProfile);
|
|
624
670
|
|
|
@@ -635,7 +681,8 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
635
681
|
properties: {
|
|
636
682
|
id: { type: "number" },
|
|
637
683
|
name: { type: "string" },
|
|
638
|
-
profile: { type: "relation",
|
|
684
|
+
profile: { type: "relation",
|
|
685
|
+
relationName: "profile" }
|
|
639
686
|
},
|
|
640
687
|
relations: [
|
|
641
688
|
{
|
|
@@ -644,8 +691,12 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
644
691
|
cardinality: "one",
|
|
645
692
|
direction: "inverse",
|
|
646
693
|
joinPath: [
|
|
647
|
-
{ table: "customers",
|
|
648
|
-
|
|
694
|
+
{ table: "customers",
|
|
695
|
+
on: { from: "authors.id",
|
|
696
|
+
to: "customers.id" } },
|
|
697
|
+
{ table: "user_profiles",
|
|
698
|
+
on: { from: "customers.id",
|
|
699
|
+
to: "user_profiles.user_id" } }
|
|
649
700
|
]
|
|
650
701
|
}
|
|
651
702
|
],
|
|
@@ -663,11 +714,14 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
663
714
|
|
|
664
715
|
const newAuthor = {
|
|
665
716
|
name: "Jane Author",
|
|
666
|
-
profile: { id: "2",
|
|
717
|
+
profile: { id: "2",
|
|
718
|
+
path: "user_profiles",
|
|
719
|
+
__type: "relation" }
|
|
667
720
|
};
|
|
668
721
|
|
|
669
722
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
670
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
723
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
724
|
+
name: "Jane Author" }]);
|
|
671
725
|
|
|
672
726
|
const entity = await entityService.saveEntity("authors_jp", newAuthor);
|
|
673
727
|
|
|
@@ -682,13 +736,18 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
682
736
|
const orderWithProducts = {
|
|
683
737
|
total: 500,
|
|
684
738
|
products: [
|
|
685
|
-
{ id: "1",
|
|
686
|
-
|
|
739
|
+
{ id: "1",
|
|
740
|
+
path: "products",
|
|
741
|
+
__type: "relation" },
|
|
742
|
+
{ id: "2",
|
|
743
|
+
path: "products",
|
|
744
|
+
__type: "relation" }
|
|
687
745
|
]
|
|
688
746
|
};
|
|
689
747
|
|
|
690
748
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
691
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
749
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
750
|
+
total: 500 }]);
|
|
692
751
|
|
|
693
752
|
const entity = await entityService.saveEntity("orders", orderWithProducts);
|
|
694
753
|
|
|
@@ -705,7 +764,8 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
705
764
|
properties: {
|
|
706
765
|
id: { type: "number" },
|
|
707
766
|
title: { type: "string" },
|
|
708
|
-
tags: { type: "relation",
|
|
767
|
+
tags: { type: "relation",
|
|
768
|
+
relationName: "tags" }
|
|
709
769
|
},
|
|
710
770
|
relations: [
|
|
711
771
|
{
|
|
@@ -714,14 +774,19 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
714
774
|
slug: "tags",
|
|
715
775
|
name: "Tags",
|
|
716
776
|
table: "tags",
|
|
717
|
-
properties: { id: { type: "number" },
|
|
777
|
+
properties: { id: { type: "number" },
|
|
778
|
+
name: { type: "string" } },
|
|
718
779
|
idField: "id"
|
|
719
780
|
}),
|
|
720
781
|
cardinality: "many",
|
|
721
782
|
direction: "owning",
|
|
722
783
|
joinPath: [
|
|
723
|
-
{ table: "post_tags",
|
|
724
|
-
|
|
784
|
+
{ table: "post_tags",
|
|
785
|
+
on: { from: "posts.id",
|
|
786
|
+
to: "post_tags.post_id" } },
|
|
787
|
+
{ table: "tags",
|
|
788
|
+
on: { from: "post_tags.tag_id",
|
|
789
|
+
to: "tags.id" } }
|
|
725
790
|
]
|
|
726
791
|
}
|
|
727
792
|
],
|
|
@@ -744,13 +809,18 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
744
809
|
const postWithTags = {
|
|
745
810
|
title: "Tagged Post",
|
|
746
811
|
tags: [
|
|
747
|
-
{ id: "1",
|
|
748
|
-
|
|
812
|
+
{ id: "1",
|
|
813
|
+
path: "tags",
|
|
814
|
+
__type: "relation" },
|
|
815
|
+
{ id: "2",
|
|
816
|
+
path: "tags",
|
|
817
|
+
__type: "relation" }
|
|
749
818
|
]
|
|
750
819
|
};
|
|
751
820
|
|
|
752
821
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
753
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
822
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
823
|
+
title: "Tagged Post" }]);
|
|
754
824
|
// Mock the fetch for tags relation - return empty array since we're testing write
|
|
755
825
|
db.orderBy.mockResolvedValue([]);
|
|
756
826
|
|
|
@@ -768,13 +838,18 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
768
838
|
const customerWithOrders = {
|
|
769
839
|
name: "Big Customer",
|
|
770
840
|
orders: [
|
|
771
|
-
{ id: "1",
|
|
772
|
-
|
|
841
|
+
{ id: "1",
|
|
842
|
+
path: "orders",
|
|
843
|
+
__type: "relation" },
|
|
844
|
+
{ id: "2",
|
|
845
|
+
path: "orders",
|
|
846
|
+
__type: "relation" }
|
|
773
847
|
]
|
|
774
848
|
};
|
|
775
849
|
|
|
776
850
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
777
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
851
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
852
|
+
name: "Big Customer" }]);
|
|
778
853
|
|
|
779
854
|
const entity = await entityService.saveEntity("customers", customerWithOrders);
|
|
780
855
|
|
|
@@ -791,7 +866,8 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
791
866
|
properties: {
|
|
792
867
|
id: { type: "number" },
|
|
793
868
|
name: { type: "string" },
|
|
794
|
-
orders: { type: "relation",
|
|
869
|
+
orders: { type: "relation",
|
|
870
|
+
relationName: "orders" }
|
|
795
871
|
},
|
|
796
872
|
relations: [
|
|
797
873
|
{
|
|
@@ -802,8 +878,12 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
802
878
|
inverseRelationName: "products",
|
|
803
879
|
// Add joinPath to satisfy the validation
|
|
804
880
|
joinPath: [
|
|
805
|
-
{ table: "order_items",
|
|
806
|
-
|
|
881
|
+
{ table: "order_items",
|
|
882
|
+
on: { from: "products.id",
|
|
883
|
+
to: "order_items.product_id" } },
|
|
884
|
+
{ table: "orders",
|
|
885
|
+
on: { from: "order_items.order_id",
|
|
886
|
+
to: "orders.id" } }
|
|
807
887
|
]
|
|
808
888
|
}
|
|
809
889
|
],
|
|
@@ -826,13 +906,18 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
826
906
|
const productWithOrders = {
|
|
827
907
|
name: "Popular Product",
|
|
828
908
|
orders: [
|
|
829
|
-
{ id: "1",
|
|
830
|
-
|
|
909
|
+
{ id: "1",
|
|
910
|
+
path: "orders",
|
|
911
|
+
__type: "relation" },
|
|
912
|
+
{ id: "2",
|
|
913
|
+
path: "orders",
|
|
914
|
+
__type: "relation" }
|
|
831
915
|
]
|
|
832
916
|
};
|
|
833
917
|
|
|
834
918
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
835
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
919
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
920
|
+
name: "Popular Product" }]);
|
|
836
921
|
// Mock the fetch for orders relation - return empty array
|
|
837
922
|
db.orderBy.mockResolvedValue([]);
|
|
838
923
|
|
|
@@ -852,7 +937,8 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
852
937
|
properties: {
|
|
853
938
|
id: { type: "number" },
|
|
854
939
|
name: { type: "string" },
|
|
855
|
-
posts: { type: "relation",
|
|
940
|
+
posts: { type: "relation",
|
|
941
|
+
relationName: "posts" }
|
|
856
942
|
},
|
|
857
943
|
relations: [
|
|
858
944
|
{
|
|
@@ -861,14 +947,19 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
861
947
|
slug: "posts",
|
|
862
948
|
name: "Posts",
|
|
863
949
|
table: "posts",
|
|
864
|
-
properties: { id: { type: "number" },
|
|
950
|
+
properties: { id: { type: "number" },
|
|
951
|
+
title: { type: "string" } },
|
|
865
952
|
idField: "id"
|
|
866
953
|
}),
|
|
867
954
|
cardinality: "many",
|
|
868
955
|
direction: "inverse",
|
|
869
956
|
joinPath: [
|
|
870
|
-
{ table: "post_tags",
|
|
871
|
-
|
|
957
|
+
{ table: "post_tags",
|
|
958
|
+
on: { from: "tags.id",
|
|
959
|
+
to: "post_tags.tag_id" } },
|
|
960
|
+
{ table: "posts",
|
|
961
|
+
on: { from: "post_tags.post_id",
|
|
962
|
+
to: "posts.id" } }
|
|
872
963
|
]
|
|
873
964
|
}
|
|
874
965
|
],
|
|
@@ -891,13 +982,18 @@ describe("EntityService - Relation Types Tests", () => {
|
|
|
891
982
|
const tagWithPosts = {
|
|
892
983
|
name: "Popular Tag",
|
|
893
984
|
posts: [
|
|
894
|
-
{ id: "1",
|
|
895
|
-
|
|
985
|
+
{ id: "1",
|
|
986
|
+
path: "posts",
|
|
987
|
+
__type: "relation" },
|
|
988
|
+
{ id: "2",
|
|
989
|
+
path: "posts",
|
|
990
|
+
__type: "relation" }
|
|
896
991
|
]
|
|
897
992
|
};
|
|
898
993
|
|
|
899
994
|
db.returning.mockResolvedValue([{ id: 1 }]);
|
|
900
|
-
db.limit.mockResolvedValue([{ id: 1,
|
|
995
|
+
db.limit.mockResolvedValue([{ id: 1,
|
|
996
|
+
name: "Popular Tag" }]);
|
|
901
997
|
// Mock the fetch for posts relation - return empty array since we're testing write
|
|
902
998
|
db.orderBy.mockResolvedValue([]);
|
|
903
999
|
|