@coasys/ad4m 0.13.1-staging.1 → 0.13.1-staging.2

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 (222) hide show
  1. package/lib/index.cjs +3789 -1192
  2. package/lib/index.js +3783 -1193
  3. package/lib/src/generated/api/AgentsByDidsRequest.d.ts +3 -0
  4. package/lib/src/generated/api/CallSessionInfo.d.ts +23 -0
  5. package/lib/src/generated/api/DiscardBatchRequest.d.ts +3 -0
  6. package/lib/src/generated/api/Events.d.ts +13 -3
  7. package/lib/src/generated/api/Events.js +1 -0
  8. package/lib/src/generated/api/FlowStateChangedEvent.d.ts +38 -0
  9. package/lib/src/generated/api/FlowStateEntry.d.ts +18 -0
  10. package/lib/src/generated/api/FlowStateEntry.js +2 -0
  11. package/lib/src/generated/api/IceServer.d.ts +18 -0
  12. package/lib/src/generated/api/IceServer.js +2 -0
  13. package/lib/src/generated/api/OnlineAgent.d.ts +4 -0
  14. package/lib/src/generated/api/PerspectiveDiscardBatchParams.d.ts +4 -0
  15. package/lib/src/generated/api/PerspectiveDiscardBatchParams.js +2 -0
  16. package/lib/src/generated/api/PerspectiveFlowFiredParams.d.ts +8 -0
  17. package/lib/src/generated/api/PerspectiveFlowFiredParams.js +2 -0
  18. package/lib/src/generated/api/PerspectiveFlowStatesParams.d.ts +11 -0
  19. package/lib/src/generated/api/PerspectiveFlowStatesParams.js +2 -0
  20. package/lib/src/generated/api/PerspectiveGetAllShaclParams.d.ts +7 -0
  21. package/lib/src/generated/api/PerspectiveGetAllShaclParams.js +2 -0
  22. package/lib/src/generated/api/PerspectiveModelQueryParams.d.ts +6 -1
  23. package/lib/src/generated/api/PerspectiveRemoveSubjectParams.d.ts +6 -0
  24. package/lib/src/generated/api/PerspectiveRemoveSubjectParams.js +2 -0
  25. package/lib/src/generated/api/PerspectiveResynced.d.ts +8 -0
  26. package/lib/src/generated/api/PerspectiveResynced.js +2 -0
  27. package/lib/src/generated/api/PerspectiveSubscribed.d.ts +10 -0
  28. package/lib/src/generated/api/PerspectiveSubscribed.js +2 -0
  29. package/lib/src/generated/api/PerspectiveUpdateSubjectParams.d.ts +10 -0
  30. package/lib/src/generated/api/PerspectiveUpdateSubjectParams.js +2 -0
  31. package/lib/src/generated/api/QuerySubscriptionUpdate.d.ts +19 -0
  32. package/lib/src/generated/api/QuerySubscriptionUpdate.js +2 -0
  33. package/lib/src/generated/api/QuerySubscriptionUpdateEvent.d.ts +7 -0
  34. package/lib/src/generated/api/QuerySubscriptionUpdateEvent.js +1 -0
  35. package/lib/src/generated/api/QueryUpdatesLagged.d.ts +7 -0
  36. package/lib/src/generated/api/QueryUpdatesLagged.js +2 -0
  37. package/lib/src/generated/api/RemoveSubjectRequest.d.ts +9 -0
  38. package/lib/src/generated/api/RemoveSubjectRequest.js +2 -0
  39. package/lib/src/generated/api/ResyncSubscriptionRequest.d.ts +3 -0
  40. package/lib/src/generated/api/ResyncSubscriptionRequest.js +2 -0
  41. package/lib/src/generated/api/RpcMethods.d.ts +134 -14
  42. package/lib/src/generated/api/RpcMethods.js +12 -0
  43. package/lib/src/generated/api/SfuAddIceCandidateParams.d.ts +8 -0
  44. package/lib/src/generated/api/SfuAddIceCandidateParams.js +2 -0
  45. package/lib/src/generated/api/SfuAnswerServerOfferParams.d.ts +8 -0
  46. package/lib/src/generated/api/SfuAnswerServerOfferParams.js +2 -0
  47. package/lib/src/generated/api/SfuCallJoinParams.d.ts +14 -0
  48. package/lib/src/generated/api/SfuCallJoinParams.js +2 -0
  49. package/lib/src/generated/api/SfuCallRenegotiationOffer.d.ts +30 -0
  50. package/lib/src/generated/api/SfuCallRenegotiationOffer.js +1 -0
  51. package/lib/src/generated/api/SfuCascadePipe.d.ts +4 -0
  52. package/lib/src/generated/api/SfuCascadePipe.js +2 -0
  53. package/lib/src/generated/api/SfuCascadeStatus.d.ts +8 -0
  54. package/lib/src/generated/api/SfuCascadeStatus.js +1 -0
  55. package/lib/src/generated/api/SfuConfig.d.ts +52 -0
  56. package/lib/src/generated/api/SfuConfig.js +1 -0
  57. package/lib/src/generated/api/SfuDataMessage.d.ts +24 -0
  58. package/lib/src/generated/api/SfuDataMessage.js +2 -0
  59. package/lib/src/generated/api/SfuEnsureMembershipParams.d.ts +4 -0
  60. package/lib/src/generated/api/SfuEnsureMembershipParams.js +2 -0
  61. package/lib/src/generated/api/SfuMigrateEvent.d.ts +21 -0
  62. package/lib/src/generated/api/SfuMigrateEvent.js +2 -0
  63. package/lib/src/generated/api/SfuNeighbourhoodParams.d.ts +3 -0
  64. package/lib/src/generated/api/SfuNeighbourhoodParams.js +2 -0
  65. package/lib/src/generated/api/SfuParticipantQualityPreference.d.ts +7 -0
  66. package/lib/src/generated/api/SfuParticipantQualityPreference.js +2 -0
  67. package/lib/src/generated/api/SfuPerspectiveParams.d.ts +6 -0
  68. package/lib/src/generated/api/SfuPerspectiveParams.js +2 -0
  69. package/lib/src/generated/api/SfuQualityPreferenceParams.d.ts +8 -0
  70. package/lib/src/generated/api/SfuQualityPreferenceParams.js +2 -0
  71. package/lib/src/generated/api/SfuRoomInfo.d.ts +11 -0
  72. package/lib/src/generated/api/SfuRoomInfo.js +1 -0
  73. package/lib/src/generated/api/SfuRoomParams.d.ts +4 -0
  74. package/lib/src/generated/api/SfuRoomParams.js +2 -0
  75. package/lib/src/generated/api/SfuRoomParticipantInfo.d.ts +11 -0
  76. package/lib/src/generated/api/SfuRoomParticipantInfo.js +2 -0
  77. package/lib/src/generated/api/SfuRoomRoster.d.ts +13 -0
  78. package/lib/src/generated/api/SfuRoomRoster.js +2 -0
  79. package/lib/src/generated/api/SfuSendDataParams.d.ts +10 -0
  80. package/lib/src/generated/api/SfuSendDataParams.js +2 -0
  81. package/lib/src/generated/api/SfuSetConfigParams.d.ts +5 -0
  82. package/lib/src/generated/api/SfuSetConfigParams.js +1 -0
  83. package/lib/src/generated/api/SfuStatus.d.ts +24 -0
  84. package/lib/src/generated/api/SfuStatus.js +2 -0
  85. package/lib/src/generated/api/TrackMapEntry.d.ts +17 -0
  86. package/lib/src/generated/api/TrackMapEntry.js +2 -0
  87. package/lib/src/generated/api/UpdateSubjectRequest.d.ts +12 -0
  88. package/lib/src/generated/api/UpdateSubjectRequest.js +2 -0
  89. package/lib/src/generated/api/index.d.ts +3 -0
  90. package/lib/src/index.d.ts +7 -0
  91. package/lib/src/index.js +4 -0
  92. package/lib/src/model/Ad4mModel.d.ts +84 -0
  93. package/lib/src/model/Ad4mModel.js +234 -4
  94. package/lib/src/model/ModelQueryBuilder.d.ts +16 -35
  95. package/lib/src/model/ModelQueryBuilder.js +88 -270
  96. package/lib/src/model/decorators.d.ts +32 -0
  97. package/lib/src/model/decorators.js +40 -1
  98. package/lib/src/model/shacl-gen.d.ts +3 -1
  99. package/lib/src/model/shacl-gen.js +13 -1
  100. package/lib/src/model/types.d.ts +7 -0
  101. package/lib/src/neighbourhood/MeshManager.d.ts +384 -0
  102. package/lib/src/neighbourhood/MeshManager.js +1144 -0
  103. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +91 -0
  104. package/lib/src/neighbourhood/NeighbourhoodClient.js +196 -0
  105. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +55 -1
  106. package/lib/src/neighbourhood/NeighbourhoodProxy.js +170 -3
  107. package/lib/src/neighbourhood/Session.d.ts +105 -0
  108. package/lib/src/neighbourhood/Session.js +412 -0
  109. package/lib/src/neighbourhood/SfuManager.d.ts +174 -0
  110. package/lib/src/neighbourhood/SfuManager.js +619 -0
  111. package/lib/src/neighbourhood/SfuTypes.d.ts +35 -0
  112. package/lib/src/neighbourhood/SfuTypes.js +8 -0
  113. package/lib/src/perspectives/FlowInstance.d.ts +63 -24
  114. package/lib/src/perspectives/FlowInstance.js +74 -31
  115. package/lib/src/perspectives/FlowModels.d.ts +0 -16
  116. package/lib/src/perspectives/FlowModels.js +8 -16
  117. package/lib/src/perspectives/LiveQuery.d.ts +49 -0
  118. package/lib/src/perspectives/LiveQuery.js +169 -0
  119. package/lib/src/perspectives/PerspectiveClient.d.ts +24 -15
  120. package/lib/src/perspectives/PerspectiveClient.js +33 -36
  121. package/lib/src/perspectives/PerspectiveProxy.d.ts +67 -167
  122. package/lib/src/perspectives/PerspectiveProxy.js +121 -475
  123. package/lib/src/perspectives/TextContent.d.ts +31 -0
  124. package/lib/src/perspectives/TextContent.js +52 -0
  125. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +23 -0
  126. package/lib/src/perspectives/WakerSubscriptionManager.js +58 -17
  127. package/lib/src/shacl/SHACLFlow.d.ts +7 -4
  128. package/lib/src/shacl/SHACLFlow.js +7 -4
  129. package/lib/src/shacl/SHACLShape.d.ts +9 -0
  130. package/lib/src/shacl/SHACLShape.js +37 -0
  131. package/package.json +2 -2
  132. package/pnpm-workspace.yaml +4 -1
  133. package/src/Ad4mClient.test.ts +89 -17
  134. package/src/generated/api/AgentsByDidsRequest.ts +3 -0
  135. package/src/generated/api/CallSessionInfo.ts +20 -0
  136. package/src/generated/api/DiscardBatchRequest.ts +3 -0
  137. package/src/generated/api/Events.ts +14 -3
  138. package/src/generated/api/FlowStateChangedEvent.ts +36 -0
  139. package/src/generated/api/FlowStateEntry.ts +18 -0
  140. package/src/generated/api/IceServer.ts +19 -0
  141. package/src/generated/api/OnlineAgent.ts +6 -1
  142. package/src/generated/api/PerspectiveDiscardBatchParams.ts +3 -0
  143. package/src/generated/api/PerspectiveFlowFiredParams.ts +7 -0
  144. package/src/generated/api/PerspectiveFlowStatesParams.ts +11 -0
  145. package/src/generated/api/PerspectiveGetAllShaclParams.ts +6 -0
  146. package/src/generated/api/PerspectiveModelQueryParams.ts +5 -1
  147. package/src/generated/api/PerspectiveRemoveSubjectParams.ts +3 -0
  148. package/src/generated/api/PerspectiveResynced.ts +7 -0
  149. package/src/generated/api/PerspectiveSubscribed.ts +8 -0
  150. package/src/generated/api/PerspectiveUpdateSubjectParams.ts +7 -0
  151. package/src/generated/api/QuerySubscriptionUpdate.ts +10 -0
  152. package/src/generated/api/QuerySubscriptionUpdateEvent.ts +9 -0
  153. package/src/generated/api/QueryUpdatesLagged.ts +7 -0
  154. package/src/generated/api/RemoveSubjectRequest.ts +7 -0
  155. package/src/generated/api/ResyncSubscriptionRequest.ts +3 -0
  156. package/src/generated/api/RpcMethods.ts +68 -8
  157. package/src/generated/api/SfuAddIceCandidateParams.ts +7 -0
  158. package/src/generated/api/SfuAnswerServerOfferParams.ts +7 -0
  159. package/src/generated/api/SfuCallJoinParams.ts +13 -0
  160. package/src/generated/api/SfuCallRenegotiationOffer.ts +29 -0
  161. package/src/generated/api/SfuCascadePipe.ts +3 -0
  162. package/src/generated/api/SfuCascadeStatus.ts +7 -0
  163. package/src/generated/api/SfuConfig.ts +53 -0
  164. package/src/generated/api/SfuDataMessage.ts +23 -0
  165. package/src/generated/api/SfuEnsureMembershipParams.ts +3 -0
  166. package/src/generated/api/SfuMigrateEvent.ts +20 -0
  167. package/src/generated/api/{KeepAliveQueryRequest.ts → SfuNeighbourhoodParams.ts} +1 -1
  168. package/src/generated/api/SfuParticipantQualityPreference.ts +6 -0
  169. package/src/generated/api/{PerspectiveSubscribeQueryResult.ts → SfuPerspectiveParams.ts} +4 -1
  170. package/src/generated/api/SfuQualityPreferenceParams.ts +7 -0
  171. package/src/generated/api/SfuRoomInfo.ts +7 -0
  172. package/src/generated/api/SfuRoomParams.ts +3 -0
  173. package/src/generated/api/SfuRoomParticipantInfo.ts +8 -0
  174. package/src/generated/api/SfuRoomRoster.ts +12 -0
  175. package/src/generated/api/SfuSendDataParams.ts +7 -0
  176. package/src/generated/api/SfuSetConfigParams.ts +4 -0
  177. package/src/generated/api/SfuStatus.ts +24 -0
  178. package/src/generated/api/TrackMapEntry.ts +18 -0
  179. package/src/generated/api/UpdateSubjectRequest.ts +10 -0
  180. package/src/generated/api/index.ts +3 -0
  181. package/src/index.ts +7 -0
  182. package/src/model/Ad4mModel.test.ts +255 -231
  183. package/src/model/Ad4mModel.ts +271 -4
  184. package/src/model/ModelQueryBuilder.ts +103 -310
  185. package/src/model/abstract-classes.test.ts +225 -0
  186. package/src/model/decorators.ts +81 -0
  187. package/src/model/shacl-gen.ts +13 -0
  188. package/src/model/types.ts +7 -0
  189. package/src/neighbourhood/MeshManager.test.ts +2640 -0
  190. package/src/neighbourhood/MeshManager.ts +1350 -0
  191. package/src/neighbourhood/NeighbourhoodClient.ts +271 -0
  192. package/src/neighbourhood/NeighbourhoodProxy.test.ts +23 -0
  193. package/src/neighbourhood/NeighbourhoodProxy.ts +247 -1
  194. package/src/neighbourhood/Session.test.ts +800 -0
  195. package/src/neighbourhood/Session.ts +525 -0
  196. package/src/neighbourhood/SfuManager.test.ts +677 -0
  197. package/src/neighbourhood/SfuManager.ts +803 -0
  198. package/src/neighbourhood/SfuTypes.ts +40 -0
  199. package/src/perspectives/FlowInstance.ts +108 -31
  200. package/src/perspectives/FlowModels.ts +8 -18
  201. package/src/perspectives/LiveQuery.test.ts +197 -0
  202. package/src/perspectives/LiveQuery.ts +189 -0
  203. package/src/perspectives/PerspectiveClient.ts +51 -51
  204. package/src/perspectives/PerspectiveProxy.test.ts +85 -401
  205. package/src/perspectives/PerspectiveProxy.ts +126 -536
  206. package/src/perspectives/TextContent.test.ts +123 -0
  207. package/src/perspectives/TextContent.ts +36 -0
  208. package/src/perspectives/WakerSubscriptionManager.test.ts +88 -6
  209. package/src/perspectives/WakerSubscriptionManager.ts +69 -18
  210. package/src/shacl/SHACLFlow.ts +7 -4
  211. package/src/shacl/SHACLShape.test.ts +2 -1
  212. package/src/shacl/SHACLShape.ts +49 -0
  213. package/lib/src/generated/api/KeepAliveQueryRequest.d.ts +0 -3
  214. package/lib/src/generated/api/PerspectiveModelSubscribeResult.d.ts +0 -7
  215. package/lib/src/generated/api/PerspectiveQuerySubscriptionFilter.d.ts +0 -6
  216. package/lib/src/generated/api/PerspectiveSubscribeQueryResult.d.ts +0 -4
  217. package/src/generated/api/PerspectiveModelSubscribeResult.ts +0 -6
  218. package/src/generated/api/PerspectiveQuerySubscriptionFilter.ts +0 -3
  219. /package/lib/src/generated/api/{KeepAliveQueryRequest.js → AgentsByDidsRequest.js} +0 -0
  220. /package/lib/src/generated/api/{PerspectiveModelSubscribeResult.js → CallSessionInfo.js} +0 -0
  221. /package/lib/src/generated/api/{PerspectiveQuerySubscriptionFilter.js → DiscardBatchRequest.js} +0 -0
  222. /package/lib/src/generated/api/{PerspectiveSubscribeQueryResult.js → FlowStateChangedEvent.js} +0 -0
@@ -1268,6 +1268,13 @@ describe("Lightweight fingerprint optimization", () => {
1268
1268
 
1269
1269
 
1270
1270
 
1271
+ /** Turn a LiveQuery's update listener into `push(result)`: each push sends the
1272
+ * next revision of `subscriptionId` with the whole result. */
1273
+ function updatesFor(subscriptionId: string, listener: (update: any) => void) {
1274
+ let revision = 0;
1275
+ return (result: any) => listener({ subscriptionId, revision: ++revision, result });
1276
+ }
1277
+
1271
1278
  // ── Subscribe callback timing ──────────────────────────────────────────
1272
1279
  describe("ModelQueryBuilder subscribe callback timing", () => {
1273
1280
  it("subscribe should not invoke callback synchronously before Promise resolves", async () => {
@@ -1280,13 +1287,14 @@ describe("ModelQueryBuilder subscribe callback timing", () => {
1280
1287
  const mockClient = {
1281
1288
  modelSubscribe: jest.fn().mockResolvedValue({
1282
1289
  subscriptionId: mockSubscriptionId,
1290
+ revision: 0,
1283
1291
  result: { instances: [], totalCount: 0 },
1284
1292
  }),
1285
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, cb: any) => {
1286
- updateCallback = cb;
1293
+ onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
1294
+ updateCallback = updatesFor(mockSubscriptionId, cb);
1287
1295
  return () => {}; // unsubscribe function
1288
1296
  }),
1289
- keepAliveQuery: jest.fn().mockResolvedValue(true),
1297
+ onReconnect: jest.fn(() => () => {}),
1290
1298
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1291
1299
  };
1292
1300
 
@@ -1339,12 +1347,13 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
1339
1347
  const mockClient = {
1340
1348
  modelSubscribe: jest.fn().mockResolvedValue({
1341
1349
  subscriptionId: mockSubscriptionId,
1350
+ revision: 0,
1342
1351
  result: { instances: [], totalCount: 0 },
1343
1352
  }),
1344
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, _cb: any) => {
1353
+ onQueryUpdate: jest.fn().mockImplementation((_cb: any) => {
1345
1354
  return () => {};
1346
1355
  }),
1347
- keepAliveQuery: jest.fn().mockResolvedValue(true),
1356
+ onReconnect: jest.fn(() => () => {}),
1348
1357
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1349
1358
  };
1350
1359
 
@@ -1394,13 +1403,14 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
1394
1403
  const mockClient = {
1395
1404
  modelSubscribe: jest.fn().mockResolvedValue({
1396
1405
  subscriptionId: mockSubscriptionId,
1406
+ revision: 0,
1397
1407
  result: { instances: [], totalCount: 0 },
1398
1408
  }),
1399
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, cb: any) => {
1400
- capturedCallback = cb;
1409
+ onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
1410
+ capturedCallback = updatesFor(mockSubscriptionId, cb);
1401
1411
  return () => {};
1402
1412
  }),
1403
- keepAliveQuery: jest.fn().mockResolvedValue(true),
1413
+ onReconnect: jest.fn(() => () => {}),
1404
1414
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1405
1415
  };
1406
1416
 
@@ -1462,13 +1472,14 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
1462
1472
  const mockClient = {
1463
1473
  modelSubscribe: jest.fn().mockResolvedValue({
1464
1474
  subscriptionId: mockSubscriptionId,
1475
+ revision: 0,
1465
1476
  result: { instances: [], totalCount: 0 },
1466
1477
  }),
1467
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, cb: any) => {
1468
- capturedCallback = cb;
1478
+ onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
1479
+ capturedCallback = updatesFor(mockSubscriptionId, cb);
1469
1480
  return () => {};
1470
1481
  }),
1471
- keepAliveQuery: jest.fn().mockResolvedValue(true),
1482
+ onReconnect: jest.fn(() => () => {}),
1472
1483
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1473
1484
  };
1474
1485
 
@@ -1531,13 +1542,14 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
1531
1542
  const mockClient = {
1532
1543
  modelSubscribe: jest.fn().mockResolvedValue({
1533
1544
  subscriptionId: mockSubscriptionId,
1545
+ revision: 0,
1534
1546
  result: { instances: [], totalCount: 0 },
1535
1547
  }),
1536
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, cb: any) => {
1537
- capturedCallback = cb;
1548
+ onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
1549
+ capturedCallback = updatesFor(mockSubscriptionId, cb);
1538
1550
  return () => {};
1539
1551
  }),
1540
- keepAliveQuery: jest.fn().mockResolvedValue(true),
1552
+ onReconnect: jest.fn(() => () => {}),
1541
1553
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1542
1554
  };
1543
1555
 
@@ -1602,13 +1614,14 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
1602
1614
  const mockClient = {
1603
1615
  modelSubscribe: jest.fn().mockResolvedValue({
1604
1616
  subscriptionId: mockSubscriptionId,
1617
+ revision: 0,
1605
1618
  result: { instances: [], totalCount: 0 },
1606
1619
  }),
1607
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, cb: any) => {
1608
- capturedCallback = cb;
1620
+ onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
1621
+ capturedCallback = updatesFor(mockSubscriptionId, cb);
1609
1622
  return () => {};
1610
1623
  }),
1611
- keepAliveQuery: jest.fn().mockResolvedValue(true),
1624
+ onReconnect: jest.fn(() => () => {}),
1612
1625
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1613
1626
  };
1614
1627
 
@@ -1673,13 +1686,14 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
1673
1686
  const mockClient = {
1674
1687
  modelSubscribe: jest.fn().mockResolvedValue({
1675
1688
  subscriptionId: mockSubscriptionId,
1689
+ revision: 0,
1676
1690
  result: { instances: [], totalCount: 0 },
1677
1691
  }),
1678
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, cb: any) => {
1679
- capturedCallback = cb;
1692
+ onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
1693
+ capturedCallback = updatesFor(mockSubscriptionId, cb);
1680
1694
  return () => {};
1681
1695
  }),
1682
- keepAliveQuery: jest.fn().mockResolvedValue(true),
1696
+ onReconnect: jest.fn(() => () => {}),
1683
1697
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1684
1698
  };
1685
1699
 
@@ -1746,44 +1760,30 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
1746
1760
  });
1747
1761
 
1748
1762
  // ============================================================================
1749
- // Subscription keepalive recovery tests
1763
+ // Subscriptions after a reconnect (the executor ends a socket's subscriptions
1764
+ // when it closes; there is no keepalive)
1750
1765
  // ============================================================================
1751
1766
 
1752
- describe("ModelQueryBuilder keepalive recovery", () => {
1753
- beforeEach(() => jest.useFakeTimers());
1754
- afterEach(() => jest.useRealTimers());
1755
-
1756
- /**
1757
- * Helper: build a mock perspective whose keepAliveQuery rejects after
1758
- * `failAfter` successful calls, simulating a server-side subscription
1759
- * eviction (returns "Subscription not found"). On resubscribe (a second
1760
- * modelSubscribe call) it returns a *new* subscription ID.
1761
- */
1762
- function buildMocks(failAfter = 0) {
1763
- let keepaliveCallCount = 0;
1764
- let modelSubscribeCallCount = 0;
1765
-
1767
+ describe("ModelQueryBuilder reconnect", () => {
1768
+ function buildMocks() {
1769
+ let subscribeCount = 0;
1770
+ const reconnectListeners = new Set<() => void>();
1766
1771
  const mockClient = {
1767
1772
  modelSubscribe: jest.fn().mockImplementation(async () => {
1768
- modelSubscribeCallCount++;
1773
+ subscribeCount++;
1769
1774
  return {
1770
- subscriptionId: `sub-${modelSubscribeCallCount}`,
1771
- result: { instances: [], totalCount: 0 },
1775
+ subscriptionId: `sub-${subscribeCount}`,
1776
+ revision: 0,
1777
+ result: { instances: [], totalCount: subscribeCount },
1772
1778
  };
1773
1779
  }),
1774
- subscribeToQueryUpdates: jest.fn().mockImplementation((_id: string, _cb: any) => {
1775
- return () => {};
1776
- }),
1777
- keepAliveQuery: jest.fn().mockImplementation(async () => {
1778
- keepaliveCallCount++;
1779
- if (keepaliveCallCount > failAfter) {
1780
- throw new Error("RPC error 500: Subscription not found");
1781
- }
1782
- return true;
1780
+ onQueryUpdate: jest.fn(() => () => {}),
1781
+ onReconnect: jest.fn((cb: () => void) => {
1782
+ reconnectListeners.add(cb);
1783
+ return () => reconnectListeners.delete(cb);
1783
1784
  }),
1784
1785
  disposeQuerySubscription: jest.fn().mockResolvedValue(true),
1785
1786
  };
1786
-
1787
1787
  const mockPerspective = {
1788
1788
  uuid: "test-uuid",
1789
1789
  client: mockClient,
@@ -1794,125 +1794,63 @@ describe("ModelQueryBuilder keepalive recovery", () => {
1794
1794
  modelQuery: jest.fn().mockResolvedValue({ instances: [], totalCount: 0 }),
1795
1795
  getLinks: jest.fn().mockResolvedValue([]),
1796
1796
  } as any;
1797
-
1798
- return { mockClient, mockPerspective, getKeepaliveCount: () => keepaliveCallCount, getSubscribeCount: () => modelSubscribeCallCount };
1797
+ const reconnect = async () => {
1798
+ reconnectListeners.forEach(cb => cb());
1799
+ await new Promise(r => setTimeout(r, 0));
1800
+ };
1801
+ return { mockClient, mockPerspective, reconnect, subscribeCount: () => subscribeCount };
1799
1802
  }
1800
1803
 
1801
- it("subscribe: resubscribes when keepalive gets 'Subscription not found'", async () => {
1802
- const { mockClient, mockPerspective, getSubscribeCount } = buildMocks(/* failAfter */ 1);
1803
-
1804
+ function testModel(name: string) {
1804
1805
  const { Ad4mModel, Model, Flag, Property } = require("./index");
1805
-
1806
- @Model({ name: "KeepaliveRecoveryTest" })
1807
- class KeepaliveRecoveryTest extends Ad4mModel {
1808
- @Flag({ through: "test://type", value: "test://ka" })
1809
- type: string = "test://ka";
1806
+ @Model({ name })
1807
+ class M extends Ad4mModel {
1808
+ @Flag({ through: "test://type", value: `test://${name}` })
1809
+ type: string = `test://${name}`;
1810
1810
  @Property({ through: "test://name" })
1811
1811
  name: string = "";
1812
1812
  }
1813
+ return M;
1814
+ }
1813
1815
 
1814
- const builder = KeepaliveRecoveryTest.query(mockPerspective);
1816
+ it("subscribe re-opens after a reconnect", async () => {
1817
+ const { mockClient, mockPerspective, reconnect, subscribeCount } = buildMocks();
1818
+ const builder = testModel("ReconnectSubscribe").query(mockPerspective);
1815
1819
  await builder.subscribe(() => {});
1816
-
1817
- // Initial subscription
1818
- expect(getSubscribeCount()).toBe(1);
1819
-
1820
- // First keepalive at 30s — succeeds (failAfter=1)
1821
- await jest.advanceTimersByTimeAsync(30_000);
1822
- expect(mockClient.keepAliveQuery).toHaveBeenCalledTimes(1);
1823
-
1824
- // Second keepalive at 60s — fails → should trigger resubscribe
1825
- await jest.advanceTimersByTimeAsync(30_000);
1826
- expect(mockClient.keepAliveQuery).toHaveBeenCalledTimes(2);
1827
-
1828
- // Allow exponential backoff (2000ms for first retry) + microtask queue to settle
1829
- await jest.advanceTimersByTimeAsync(2500);
1830
-
1831
- // A second modelSubscribe call means recovery happened
1832
- expect(getSubscribeCount()).toBe(2);
1833
-
1834
- // Clean up
1820
+ await reconnect();
1821
+ expect(subscribeCount()).toBe(2);
1835
1822
  builder.dispose();
1823
+ expect(mockClient.disposeQuerySubscription).toHaveBeenCalledWith("test-uuid", "sub-2");
1836
1824
  });
1837
1825
 
1838
- it("countSubscribe: resubscribes when keepalive gets 'Subscription not found'", async () => {
1839
- const { mockClient, mockPerspective, getSubscribeCount } = buildMocks(0); // fail immediately
1840
-
1841
- const { Ad4mModel, Model, Flag, Property } = require("./index");
1842
-
1843
- @Model({ name: "CountKeepaliveTest" })
1844
- class CountKeepaliveTest extends Ad4mModel {
1845
- @Flag({ through: "test://type", value: "test://cka" })
1846
- type: string = "test://cka";
1847
- @Property({ through: "test://name" })
1848
- name: string = "";
1849
- }
1850
-
1851
- const builder = CountKeepaliveTest.query(mockPerspective);
1852
- await builder.countSubscribe(() => {});
1853
-
1854
- expect(getSubscribeCount()).toBe(1);
1855
-
1856
- // First keepalive at 30s — fails immediately → should trigger resubscribe
1857
- await jest.advanceTimersByTimeAsync(30_000);
1858
- // Allow exponential backoff (2000ms for first retry) + microtask queue to settle
1859
- await jest.advanceTimersByTimeAsync(2500);
1860
-
1861
- expect(getSubscribeCount()).toBe(2);
1862
-
1826
+ it("countSubscribe delivers the count from the re-opened subscription", async () => {
1827
+ const { mockPerspective, reconnect } = buildMocks();
1828
+ const counts: number[] = [];
1829
+ const builder = testModel("ReconnectCount").query(mockPerspective);
1830
+ expect(await builder.countSubscribe(c => counts.push(c))).toBe(1);
1831
+ await reconnect();
1832
+ expect(counts).toEqual([2]);
1863
1833
  builder.dispose();
1864
1834
  });
1865
1835
 
1866
- it("paginateSubscribe: resubscribes when keepalive gets 'Subscription not found'", async () => {
1867
- const { mockClient, mockPerspective, getSubscribeCount } = buildMocks(0);
1868
-
1869
- const { Ad4mModel, Model, Flag, Property } = require("./index");
1870
-
1871
- @Model({ name: "PaginateKeepaliveTest" })
1872
- class PaginateKeepaliveTest extends Ad4mModel {
1873
- @Flag({ through: "test://type", value: "test://pka" })
1874
- type: string = "test://pka";
1875
- @Property({ through: "test://name" })
1876
- name: string = "";
1877
- }
1878
-
1879
- const builder = PaginateKeepaliveTest.query(mockPerspective);
1880
- await builder.paginateSubscribe(10, 1, () => {});
1881
-
1882
- expect(getSubscribeCount()).toBe(1);
1883
-
1884
- await jest.advanceTimersByTimeAsync(30_000);
1885
- // Allow exponential backoff (2000ms for first retry) + microtask queue to settle
1886
- await jest.advanceTimersByTimeAsync(2500);
1887
-
1888
- expect(getSubscribeCount()).toBe(2);
1889
-
1836
+ it("paginateSubscribe re-reads the page after a reconnect", async () => {
1837
+ const { mockPerspective, reconnect, subscribeCount } = buildMocks();
1838
+ const pages: any[] = [];
1839
+ const builder = testModel("ReconnectPaginate").query(mockPerspective);
1840
+ await builder.paginateSubscribe(10, 1, p => pages.push(p));
1841
+ await reconnect();
1842
+ expect(subscribeCount()).toBe(2);
1843
+ expect(pages).toHaveLength(1);
1890
1844
  builder.dispose();
1891
1845
  });
1892
1846
 
1893
- it("subscribe: stops retrying after dispose()", async () => {
1894
- const { mockClient, mockPerspective } = buildMocks(Infinity); // keepalive always succeeds
1895
-
1896
- const { Ad4mModel, Model, Flag, Property } = require("./index");
1897
-
1898
- @Model({ name: "DisposeTest" })
1899
- class DisposeTest extends Ad4mModel {
1900
- @Flag({ through: "test://type", value: "test://disp" })
1901
- type: string = "test://disp";
1902
- @Property({ through: "test://name" })
1903
- name: string = "";
1904
- }
1905
-
1906
- const builder = DisposeTest.query(mockPerspective);
1847
+ it("a disposed subscription does not re-open", async () => {
1848
+ const { mockPerspective, reconnect, subscribeCount } = buildMocks();
1849
+ const builder = testModel("ReconnectDisposed").query(mockPerspective);
1907
1850
  await builder.subscribe(() => {});
1908
-
1909
1851
  builder.dispose();
1910
-
1911
- // Advance well past multiple keepalive intervals
1912
- await jest.advanceTimersByTimeAsync(120_000);
1913
-
1914
- // No keepalive calls should have happened after dispose
1915
- expect(mockClient.keepAliveQuery).toHaveBeenCalledTimes(0);
1852
+ await reconnect();
1853
+ expect(subscribeCount()).toBe(1);
1916
1854
  });
1917
1855
  });
1918
1856
 
@@ -3740,127 +3678,213 @@ describe("includeUnverified — wire format", () => {
3740
3678
  });
3741
3679
  });
3742
3680
 
3743
- // ── Subscribe awaits the previous executor dispose ────────────────────
3744
- describe("ModelQueryBuilder subscribe ordering", () => {
3745
- function deferred<T>() {
3746
- let resolve!: (v: T) => void;
3747
- let reject!: (e: unknown) => void;
3748
- const promise = new Promise<T>((res, rej) => { resolve = res; reject = rej; });
3749
- return { promise, resolve, reject };
3750
- }
3751
-
3681
+ // ── One subscription per builder ──────────────────────────────────────
3682
+ describe("ModelQueryBuilder subscription ownership", () => {
3752
3683
  function makePerspective() {
3753
- const disposeGate = deferred<boolean>();
3684
+ let n = 0;
3754
3685
  const mockClient = {
3755
- modelSubscribe: jest.fn().mockResolvedValue({
3756
- subscriptionId: "shared-sub",
3686
+ modelSubscribe: jest.fn().mockImplementation(async () => ({
3687
+ subscriptionId: `sub-${++n}`,
3688
+ revision: 0,
3757
3689
  result: { instances: [], totalCount: 0 },
3758
- }),
3759
- subscribeToQueryUpdates: jest.fn().mockReturnValue(() => {}),
3760
- keepAliveQuery: jest.fn().mockResolvedValue(true),
3761
- disposeQuerySubscription: jest.fn().mockReturnValue(disposeGate.promise),
3690
+ })),
3691
+ onQueryUpdate: jest.fn(() => () => {}),
3692
+ onReconnect: jest.fn(() => () => {}),
3693
+ disposeQuerySubscription: jest.fn().mockResolvedValue(true),
3762
3694
  };
3763
3695
  const mockPerspective = {
3764
3696
  uuid: "test-uuid",
3765
3697
  client: mockClient,
3766
- modelSubscribe: jest.fn().mockImplementation(async (className: string, queryJson: string) => {
3767
- return mockClient.modelSubscribe("test-uuid", className, queryJson);
3768
- }),
3698
+ modelSubscribe: jest.fn().mockImplementation(
3699
+ async (className: string, queryJson: string) =>
3700
+ mockClient.modelSubscribe("test-uuid", className, queryJson)
3701
+ ),
3769
3702
  getLinks: jest.fn().mockResolvedValue([]),
3770
3703
  modelQuery: jest.fn().mockResolvedValue({ instances: [], totalCount: 0 }),
3771
3704
  } as any;
3772
- return { mockPerspective, mockClient, disposeGate };
3705
+ return { mockPerspective, mockClient };
3773
3706
  }
3774
3707
 
3775
3708
  const { Ad4mModel, Model, Property, Flag } = require("./index");
3776
3709
 
3777
- @Model({ name: "OrderingTest" })
3778
- class OrderingTest extends Ad4mModel {
3779
- @Flag({ through: "test://type", value: "test://ordering" })
3780
- type: string = "test://ordering";
3710
+ @Model({ name: "OwnershipTest" })
3711
+ class OwnershipTest extends Ad4mModel {
3712
+ @Flag({ through: "test://type", value: "test://ownership" })
3713
+ type: string = "test://ownership";
3781
3714
  @Property({ through: "test://name" })
3782
3715
  name: string = "";
3783
3716
  }
3784
3717
 
3785
- const flush = () => new Promise((r) => setTimeout(r, 0));
3786
-
3787
- it("re-subscribe waits for the executor to release the previous subscription", async () => {
3788
- const { mockPerspective, mockClient, disposeGate } = makePerspective();
3789
- const builder = OrderingTest.query(mockPerspective);
3718
+ it("a failed open does not end a later call's subscription", async () => {
3719
+ const { mockPerspective, mockClient } = makePerspective();
3720
+ let rejectFirst!: (e: Error) => void;
3721
+ mockClient.modelSubscribe
3722
+ .mockImplementationOnce(() => new Promise((_, reject) => { rejectFirst = reject; }))
3723
+ .mockImplementationOnce(async () => ({ subscriptionId: "sub-b", revision: 0, result: { instances: [], totalCount: 0 } }));
3724
+ const builder = OwnershipTest.query(mockPerspective);
3790
3725
 
3726
+ const first = builder.subscribe(() => {});
3727
+ await Promise.resolve();
3791
3728
  await builder.subscribe(() => {});
3792
- expect(mockPerspective.modelSubscribe).toHaveBeenCalledTimes(1);
3793
-
3794
- const second = builder.subscribe(() => {});
3795
- await flush();
3796
- // The executor has not acknowledged the dispose yet: no new registration.
3797
- expect(mockClient.disposeQuerySubscription).toHaveBeenCalledWith("test-uuid", "shared-sub");
3798
- expect(mockPerspective.modelSubscribe).toHaveBeenCalledTimes(1);
3729
+ rejectFirst(new Error("refused"));
3730
+ await expect(first).rejects.toThrow("refused");
3799
3731
 
3800
- disposeGate.resolve(true);
3801
- await second;
3802
- expect(mockPerspective.modelSubscribe).toHaveBeenCalledTimes(2);
3732
+ expect(mockClient.disposeQuerySubscription).not.toHaveBeenCalledWith("test-uuid", "sub-b");
3733
+ builder.dispose();
3734
+ expect(mockClient.disposeQuerySubscription).toHaveBeenCalledWith("test-uuid", "sub-b");
3803
3735
  });
3804
3736
 
3805
- it("re-subscribe proceeds when the executor dispose fails", async () => {
3806
- const { mockPerspective, disposeGate } = makePerspective();
3807
- const builder = OrderingTest.query(mockPerspective);
3737
+ it("paginateSubscribe() disposed while opening leaves the builder usable", async () => {
3738
+ const { mockPerspective, mockClient } = makePerspective();
3739
+ let resolveOpen!: (v: any) => void;
3740
+ mockClient.modelSubscribe.mockImplementationOnce(() => new Promise(resolve => { resolveOpen = resolve; }));
3741
+ const callback = jest.fn();
3742
+ const builder = OwnershipTest.query(mockPerspective);
3808
3743
 
3809
- await builder.subscribe(() => {});
3810
- const second = builder.subscribe(() => {});
3811
- disposeGate.reject(new Error("Subscription not found"));
3812
- await second;
3813
- expect(mockPerspective.modelSubscribe).toHaveBeenCalledTimes(2);
3744
+ const page = builder.paginateSubscribe(10, 1, callback);
3745
+ await Promise.resolve();
3746
+ builder.dispose();
3747
+ resolveOpen({ subscriptionId: "sub-p", revision: 0, result: { instances: [], totalCount: 0 } });
3748
+ await page;
3749
+
3750
+ expect(() => builder.dispose()).not.toThrow();
3751
+ await expect(builder.subscribe(() => {})).resolves.toBeDefined();
3752
+ expect(callback).not.toHaveBeenCalled();
3814
3753
  });
3815
3754
 
3816
3755
  it("overlapping subscribe() calls leave exactly one live subscription", async () => {
3817
- const { mockPerspective, mockClient, disposeGate } = makePerspective();
3818
- const unsubscribes: jest.Mock[] = [];
3819
- let n = 0;
3820
- mockClient.modelSubscribe.mockImplementation(async () => ({
3821
- subscriptionId: `sub-${++n}`,
3822
- result: { instances: [], totalCount: 0 },
3823
- }));
3824
- mockClient.subscribeToQueryUpdates.mockImplementation(() => {
3825
- const u = jest.fn();
3826
- unsubscribes.push(u);
3827
- return u;
3828
- });
3829
- mockClient.disposeQuerySubscription.mockResolvedValue(true);
3830
- disposeGate.resolve(true);
3831
- const builder = OrderingTest.query(mockPerspective);
3756
+ const { mockPerspective, mockClient } = makePerspective();
3757
+ const builder = OwnershipTest.query(mockPerspective);
3832
3758
 
3833
3759
  await Promise.all([builder.subscribe(() => {}), builder.subscribe(() => {})]);
3834
3760
 
3835
3761
  expect(mockPerspective.modelSubscribe).toHaveBeenCalledTimes(2);
3836
- // The second call ran after the first and disposed its subscription.
3762
+ // The second call ended the first subscription.
3837
3763
  expect(mockClient.disposeQuerySubscription).toHaveBeenCalledTimes(1);
3838
3764
  expect(mockClient.disposeQuerySubscription).toHaveBeenCalledWith("test-uuid", "sub-1");
3839
- expect(unsubscribes).toHaveLength(2);
3840
- expect(unsubscribes[0]).toHaveBeenCalledTimes(1);
3841
- expect(unsubscribes[1]).not.toHaveBeenCalled();
3842
- // And the builder can still release the survivor.
3843
- await builder.dispose();
3844
- expect(unsubscribes[1]).toHaveBeenCalledTimes(1);
3765
+ builder.dispose();
3845
3766
  expect(mockClient.disposeQuerySubscription).toHaveBeenCalledWith("test-uuid", "sub-2");
3846
3767
  });
3847
3768
 
3848
- it("dispose() cleans up locally at once and resolves without a subscription", async () => {
3849
- const { mockPerspective, mockClient, disposeGate } = makePerspective();
3850
- const unsubscribe = jest.fn();
3851
- mockClient.subscribeToQueryUpdates.mockReturnValue(unsubscribe);
3852
- const builder = OrderingTest.query(mockPerspective);
3853
-
3854
- await expect(builder.dispose()).resolves.toBeUndefined();
3769
+ it("dispose() ends the subscription once, however often it is called", async () => {
3770
+ const { mockPerspective, mockClient } = makePerspective();
3771
+ const builder = OwnershipTest.query(mockPerspective);
3855
3772
 
3773
+ builder.dispose();
3856
3774
  await builder.subscribe(() => {});
3857
- const done = builder.dispose();
3858
- expect(unsubscribe).toHaveBeenCalledTimes(1);
3859
- expect(mockClient.disposeQuerySubscription).toHaveBeenCalledTimes(1);
3860
- disposeGate.resolve(true);
3861
- await expect(done).resolves.toBeUndefined();
3862
- // Idempotent: a second dispose does not call the executor again.
3863
- await builder.dispose();
3775
+ builder.dispose();
3776
+ builder.dispose();
3777
+
3864
3778
  expect(mockClient.disposeQuerySubscription).toHaveBeenCalledTimes(1);
3779
+ expect(mockClient.disposeQuerySubscription).toHaveBeenCalledWith("test-uuid", "sub-1");
3780
+ });
3781
+ });
3782
+
3783
+ describe("Ad4mModel.findAllOf / queryOf (one query over several classes, #1238)", () => {
3784
+ @Model({ name: "UnionTaskU" })
3785
+ class UnionTaskU extends Ad4mModel {
3786
+ @Flag({ through: "u://kind", value: "u://task" })
3787
+ kind: string = "";
3788
+ @Property({ through: "u://status" })
3789
+ status: string = "";
3790
+ }
3791
+
3792
+ @Model({ name: "UnionNoteU" })
3793
+ class UnionNoteU extends Ad4mModel {
3794
+ @Flag({ through: "u://kind", value: "u://note" })
3795
+ kind: string = "";
3796
+ @Property({ through: "u://body" })
3797
+ body: string = "";
3798
+ }
3799
+
3800
+ const rows = {
3801
+ instances: [
3802
+ { id: "u://t1", status: "open", __subjectClass: "UnionTaskU", __subjectClasses: ["UnionTaskU"] },
3803
+ { id: "u://n1", body: "hi", __subjectClass: "UnionNoteU", __subjectClasses: ["UnionNoteU"] },
3804
+ { id: "u://x", __subjectClass: "Other", __subjectClasses: ["Other"] },
3805
+ ],
3806
+ totalCount: 7,
3807
+ };
3808
+
3809
+ it("sends every class name and builds each row as its own class", async () => {
3810
+ const perspective = { modelQuery: jest.fn().mockResolvedValue(rows), uuid: "p" } as any;
3811
+ const results = await Ad4mModel.findAllOf(perspective, [UnionTaskU, UnionNoteU], {
3812
+ where: { status: "open" },
3813
+ order: { status: "DESC" },
3814
+ limit: 2,
3815
+ preferClasses: ["UnionNoteU"],
3816
+ });
3817
+
3818
+ const [classNames, queryJson] = perspective.modelQuery.mock.calls[0];
3819
+ expect(classNames).toEqual(["UnionTaskU", "UnionNoteU"]);
3820
+ const sent = JSON.parse(queryJson);
3821
+ expect(sent.where).toEqual({ status: "open" });
3822
+ expect(sent.order).toEqual([["status", "DESC"]]);
3823
+ expect(sent.limit).toBe(2);
3824
+ expect(sent.preferClasses).toEqual(["UnionNoteU"]);
3825
+
3826
+ expect(results[0]).toBeInstanceOf(UnionTaskU);
3827
+ expect((results[0] as UnionTaskU).status).toBe("open");
3828
+ expect(results[1]).toBeInstanceOf(UnionNoteU);
3829
+ // A class the caller did not list stays plain JSON.
3830
+ expect(results[2]).not.toBeInstanceOf(Ad4mModel);
3831
+ });
3832
+
3833
+ it("queryOf().count() reads the union's totalCount", async () => {
3834
+ const perspective = { modelQuery: jest.fn().mockResolvedValue(rows), uuid: "p" } as any;
3835
+ const count = await Ad4mModel.queryOf(perspective, [UnionTaskU, UnionNoteU]).count();
3836
+ expect(count).toBe(7);
3837
+ expect(JSON.parse(perspective.modelQuery.mock.calls[0][1]).limit).toBe(0);
3838
+ });
3839
+
3840
+ it("refuses a projection key the classes tag with different target classes", () => {
3841
+ @Model({ name: "UnionCardU" })
3842
+ class UnionCardU extends Ad4mModel {
3843
+ @Property({ through: "u://title" })
3844
+ title: string = "";
3845
+ }
3846
+ @Model({ name: "UnionWaypointU" })
3847
+ class UnionWaypointU extends Ad4mModel {
3848
+ @Property({ through: "u://x" })
3849
+ x: string = "";
3850
+ }
3851
+ @Model({ name: "UnionPlacementU" })
3852
+ class UnionPlacementU extends Ad4mModel {
3853
+ @HasMany(() => UnionCardU, { through: "u://items" })
3854
+ items: string[] = [];
3855
+ }
3856
+ @Model({ name: "UnionRouteU" })
3857
+ class UnionRouteU extends Ad4mModel {
3858
+ @HasMany(() => UnionWaypointU, { through: "u://items" })
3859
+ items: string[] = [];
3860
+ }
3861
+ const include = { $items: { from: "items", where: { title: "a" } } } as any;
3862
+ expect(() =>
3863
+ Ad4mModel.prepareUnionQueryParams([UnionPlacementU, UnionRouteU], { include }),
3864
+ ).toThrow(/different target classes/);
3865
+ // Same target on both: accepted.
3866
+ expect(() =>
3867
+ Ad4mModel.prepareUnionQueryParams([UnionPlacementU, UnionPlacementU], { include }),
3868
+ ).not.toThrow();
3869
+ });
3870
+
3871
+ it("keeps a raw parent predicate and refuses a scope the classes resolve differently", () => {
3872
+ const { queryJson } = Ad4mModel.prepareUnionQueryParams([UnionTaskU, UnionNoteU], {
3873
+ parent: { id: "u://canvas", predicate: "u://item" },
3874
+ });
3875
+ expect(JSON.parse(queryJson).parent).toEqual({ id: "u://canvas", predicate: "u://item" });
3876
+
3877
+ @Model({ name: "UnionBoardU" })
3878
+ class UnionBoardU extends Ad4mModel {
3879
+ @HasMany(() => UnionTaskU, { through: "u://tasks" })
3880
+ tasks: string[] = [];
3881
+ @HasMany(() => UnionNoteU, { through: "u://notes" })
3882
+ notes: string[] = [];
3883
+ }
3884
+ expect(() =>
3885
+ Ad4mModel.prepareUnionQueryParams([UnionTaskU, UnionNoteU], {
3886
+ parent: { id: "u://board", model: UnionBoardU },
3887
+ }),
3888
+ ).toThrow(/different predicates/);
3865
3889
  });
3866
3890
  });