@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.
Files changed (136) hide show
  1. package/dist/common/src/collections/CollectionRegistry.d.ts +8 -0
  2. package/dist/common/src/util/entities.d.ts +22 -0
  3. package/dist/common/src/util/relations.d.ts +14 -4
  4. package/dist/common/src/util/resolutions.d.ts +1 -1
  5. package/dist/index.es.js +1254 -591
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/index.umd.js +1254 -591
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +17 -29
  10. package/dist/server-postgresql/src/auth/services.d.ts +7 -3
  11. package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +1 -1
  12. package/dist/server-postgresql/src/connection.d.ts +34 -1
  13. package/dist/server-postgresql/src/data-transformer.d.ts +26 -4
  14. package/dist/server-postgresql/src/databasePoolManager.d.ts +2 -2
  15. package/dist/server-postgresql/src/schema/auth-schema.d.ts +139 -38
  16. package/dist/server-postgresql/src/schema/doctor-cli.d.ts +2 -0
  17. package/dist/server-postgresql/src/schema/doctor.d.ts +43 -0
  18. package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +1 -1
  19. package/dist/server-postgresql/src/schema/test-schema.d.ts +24 -0
  20. package/dist/server-postgresql/src/services/EntityFetchService.d.ts +22 -8
  21. package/dist/server-postgresql/src/services/EntityPersistService.d.ts +1 -1
  22. package/dist/server-postgresql/src/services/RelationService.d.ts +11 -5
  23. package/dist/server-postgresql/src/services/entity-helpers.d.ts +16 -2
  24. package/dist/server-postgresql/src/services/entityService.d.ts +8 -6
  25. package/dist/server-postgresql/src/services/realtimeService.d.ts +2 -0
  26. package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +2 -2
  27. package/dist/types/src/controllers/auth.d.ts +2 -0
  28. package/dist/types/src/controllers/client.d.ts +119 -7
  29. package/dist/types/src/controllers/collection_registry.d.ts +4 -3
  30. package/dist/types/src/controllers/customization_controller.d.ts +7 -1
  31. package/dist/types/src/controllers/data.d.ts +34 -7
  32. package/dist/types/src/controllers/data_driver.d.ts +20 -28
  33. package/dist/types/src/controllers/database_admin.d.ts +2 -2
  34. package/dist/types/src/controllers/email.d.ts +34 -0
  35. package/dist/types/src/controllers/index.d.ts +1 -0
  36. package/dist/types/src/controllers/local_config_persistence.d.ts +4 -4
  37. package/dist/types/src/controllers/navigation.d.ts +5 -5
  38. package/dist/types/src/controllers/registry.d.ts +6 -3
  39. package/dist/types/src/controllers/side_entity_controller.d.ts +7 -6
  40. package/dist/types/src/controllers/storage.d.ts +24 -26
  41. package/dist/types/src/rebase_context.d.ts +8 -4
  42. package/dist/types/src/types/backend.d.ts +4 -1
  43. package/dist/types/src/types/builders.d.ts +5 -4
  44. package/dist/types/src/types/chips.d.ts +1 -1
  45. package/dist/types/src/types/collections.d.ts +169 -125
  46. package/dist/types/src/types/cron.d.ts +102 -0
  47. package/dist/types/src/types/data_source.d.ts +1 -1
  48. package/dist/types/src/types/entity_actions.d.ts +8 -8
  49. package/dist/types/src/types/entity_callbacks.d.ts +15 -15
  50. package/dist/types/src/types/entity_link_builder.d.ts +1 -1
  51. package/dist/types/src/types/entity_overrides.d.ts +2 -1
  52. package/dist/types/src/types/entity_views.d.ts +8 -8
  53. package/dist/types/src/types/export_import.d.ts +3 -3
  54. package/dist/types/src/types/index.d.ts +1 -0
  55. package/dist/types/src/types/plugins.d.ts +72 -18
  56. package/dist/types/src/types/properties.d.ts +118 -33
  57. package/dist/types/src/types/relations.d.ts +1 -1
  58. package/dist/types/src/types/slots.d.ts +30 -6
  59. package/dist/types/src/types/translations.d.ts +44 -0
  60. package/dist/types/src/types/user_management_delegate.d.ts +1 -0
  61. package/drizzle-test/0000_woozy_junta.sql +6 -0
  62. package/drizzle-test/0001_youthful_arachne.sql +1 -0
  63. package/drizzle-test/0002_lively_dragon_lord.sql +2 -0
  64. package/drizzle-test/0003_mean_king_cobra.sql +2 -0
  65. package/drizzle-test/meta/0000_snapshot.json +47 -0
  66. package/drizzle-test/meta/0001_snapshot.json +48 -0
  67. package/drizzle-test/meta/0002_snapshot.json +38 -0
  68. package/drizzle-test/meta/0003_snapshot.json +48 -0
  69. package/drizzle-test/meta/_journal.json +34 -0
  70. package/drizzle-test-out/0000_tan_trauma.sql +6 -0
  71. package/drizzle-test-out/0001_rapid_drax.sql +1 -0
  72. package/drizzle-test-out/meta/0000_snapshot.json +44 -0
  73. package/drizzle-test-out/meta/0001_snapshot.json +54 -0
  74. package/drizzle-test-out/meta/_journal.json +20 -0
  75. package/drizzle.test.config.ts +10 -0
  76. package/package.json +88 -89
  77. package/scratch.ts +41 -0
  78. package/src/PostgresBackendDriver.ts +63 -79
  79. package/src/PostgresBootstrapper.ts +7 -8
  80. package/src/auth/ensure-tables.ts +158 -86
  81. package/src/auth/services.ts +109 -50
  82. package/src/cli.ts +259 -16
  83. package/src/collections/PostgresCollectionRegistry.ts +6 -6
  84. package/src/connection.ts +70 -48
  85. package/src/data-transformer.ts +155 -116
  86. package/src/databasePoolManager.ts +6 -5
  87. package/src/history/HistoryService.ts +3 -12
  88. package/src/interfaces.ts +3 -3
  89. package/src/schema/auth-schema.ts +26 -3
  90. package/src/schema/doctor-cli.ts +47 -0
  91. package/src/schema/doctor.ts +595 -0
  92. package/src/schema/generate-drizzle-schema-logic.ts +204 -57
  93. package/src/schema/generate-drizzle-schema.ts +6 -6
  94. package/src/schema/test-schema.ts +11 -0
  95. package/src/services/BranchService.ts +5 -5
  96. package/src/services/EntityFetchService.ts +317 -188
  97. package/src/services/EntityPersistService.ts +15 -17
  98. package/src/services/RelationService.ts +299 -37
  99. package/src/services/entity-helpers.ts +39 -13
  100. package/src/services/entityService.ts +11 -9
  101. package/src/services/realtimeService.ts +58 -29
  102. package/src/utils/drizzle-conditions.ts +25 -24
  103. package/src/websocket.ts +52 -21
  104. package/test/auth-services.test.ts +131 -39
  105. package/test/batch-many-to-many-regression.test.ts +573 -0
  106. package/test/branchService.test.ts +22 -12
  107. package/test/data-transformer-hardening.test.ts +417 -0
  108. package/test/data-transformer.test.ts +175 -0
  109. package/test/doctor.test.ts +182 -0
  110. package/test/entityService.errors.test.ts +31 -16
  111. package/test/entityService.relations.test.ts +155 -59
  112. package/test/entityService.subcollection-search.test.ts +107 -57
  113. package/test/entityService.test.ts +105 -47
  114. package/test/generate-drizzle-schema.test.ts +262 -69
  115. package/test/historyService.test.ts +31 -16
  116. package/test/n-plus-one-regression.test.ts +314 -0
  117. package/test/postgresDataDriver.test.ts +260 -168
  118. package/test/realtimeService.test.ts +70 -39
  119. package/test/relation-pipeline-gaps.test.ts +637 -0
  120. package/test/relations.test.ts +492 -39
  121. package/test-drizzle-bug.ts +18 -0
  122. package/test-drizzle-out/0000_cultured_freak.sql +7 -0
  123. package/test-drizzle-out/0001_tiresome_professor_monster.sql +1 -0
  124. package/test-drizzle-out/meta/0000_snapshot.json +55 -0
  125. package/test-drizzle-out/meta/0001_snapshot.json +63 -0
  126. package/test-drizzle-out/meta/_journal.json +20 -0
  127. package/test-drizzle-prompt.sh +2 -0
  128. package/test-policy-prompt.sh +3 -0
  129. package/test-programmatic.ts +30 -0
  130. package/test-programmatic2.ts +59 -0
  131. package/test-schema-no-policies.ts +12 -0
  132. package/test_drizzle_mock.js +2 -2
  133. package/test_find_changed.mjs +3 -1
  134. package/test_hash.js +14 -0
  135. package/tsconfig.json +1 -1
  136. 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", relationName: "orders" },
59
- profile: { type: "relation", relationName: "profile" }
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", relationName: "customer" },
88
- products: { type: "relation", relationName: "products" }
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", relationName: "user" }
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, total: 100, customer_id: 1 },
196
- { id: 2, total: 200, customer_id: 1 }
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", path: "customers", __type: "relation" }
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, name: "Product 1", price: 10 },
272
- { id: 2, name: "Product 2", price: 20 }
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", path: "customers", __type: "relation" }
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, bio: "User bio", user_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", path: "customers", __type: "relation" }
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, name: "Product 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, total: 100, customer_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, total: 200, customer_id: 1 },
424
- { id: 1, total: 100, customer_id: 1 }
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", path: "customers", __type: "relation" }
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", relationName: "authorProfile" }
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", on: { from: "posts.author_id", to: "authors.id" } },
539
- { table: "user_profiles", on: { from: "authors.id", to: "user_profiles.user_id" } }
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", path: "user_profiles", __type: "relation" }
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, title: "Test Post", author_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", path: "user_profiles", __type: "relation" }
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, title: "Test Post Updated", author_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", path: "user_profiles", __type: "relation" }
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, name: "John Doe" }]);
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", relationName: "profile" }
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", on: { from: "authors.id", to: "customers.id" } },
648
- { table: "user_profiles", on: { from: "customers.id", to: "user_profiles.user_id" } }
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", path: "user_profiles", __type: "relation" }
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, name: "Jane Author" }]);
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", path: "products", __type: "relation" },
686
- { id: "2", path: "products", __type: "relation" }
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, total: 500 }]);
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", relationName: "tags" }
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" }, name: { type: "string" } },
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", on: { from: "posts.id", to: "post_tags.post_id" } },
724
- { table: "tags", on: { from: "post_tags.tag_id", to: "tags.id" } }
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", path: "tags", __type: "relation" },
748
- { id: "2", path: "tags", __type: "relation" }
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, title: "Tagged Post" }]);
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", path: "orders", __type: "relation" },
772
- { id: "2", path: "orders", __type: "relation" }
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, name: "Big Customer" }]);
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", relationName: "orders" }
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", on: { from: "products.id", to: "order_items.product_id" } },
806
- { table: "orders", on: { from: "order_items.order_id", to: "orders.id" } }
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", path: "orders", __type: "relation" },
830
- { id: "2", path: "orders", __type: "relation" }
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, name: "Popular Product" }]);
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", relationName: "posts" }
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" }, title: { type: "string" } },
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", on: { from: "tags.id", to: "post_tags.tag_id" } },
871
- { table: "posts", on: { from: "post_tags.post_id", to: "posts.id" } }
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", path: "posts", __type: "relation" },
895
- { id: "2", path: "posts", __type: "relation" }
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, name: "Popular Tag" }]);
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