@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.
- package/lib/index.cjs +3789 -1192
- package/lib/index.js +3783 -1193
- package/lib/src/generated/api/AgentsByDidsRequest.d.ts +3 -0
- package/lib/src/generated/api/CallSessionInfo.d.ts +23 -0
- package/lib/src/generated/api/DiscardBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/Events.d.ts +13 -3
- package/lib/src/generated/api/Events.js +1 -0
- package/lib/src/generated/api/FlowStateChangedEvent.d.ts +38 -0
- package/lib/src/generated/api/FlowStateEntry.d.ts +18 -0
- package/lib/src/generated/api/FlowStateEntry.js +2 -0
- package/lib/src/generated/api/IceServer.d.ts +18 -0
- package/lib/src/generated/api/IceServer.js +2 -0
- package/lib/src/generated/api/OnlineAgent.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveDiscardBatchParams.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveDiscardBatchParams.js +2 -0
- package/lib/src/generated/api/PerspectiveFlowFiredParams.d.ts +8 -0
- package/lib/src/generated/api/PerspectiveFlowFiredParams.js +2 -0
- package/lib/src/generated/api/PerspectiveFlowStatesParams.d.ts +11 -0
- package/lib/src/generated/api/PerspectiveFlowStatesParams.js +2 -0
- package/lib/src/generated/api/PerspectiveGetAllShaclParams.d.ts +7 -0
- package/lib/src/generated/api/PerspectiveGetAllShaclParams.js +2 -0
- package/lib/src/generated/api/PerspectiveModelQueryParams.d.ts +6 -1
- package/lib/src/generated/api/PerspectiveRemoveSubjectParams.d.ts +6 -0
- package/lib/src/generated/api/PerspectiveRemoveSubjectParams.js +2 -0
- package/lib/src/generated/api/PerspectiveResynced.d.ts +8 -0
- package/lib/src/generated/api/PerspectiveResynced.js +2 -0
- package/lib/src/generated/api/PerspectiveSubscribed.d.ts +10 -0
- package/lib/src/generated/api/PerspectiveSubscribed.js +2 -0
- package/lib/src/generated/api/PerspectiveUpdateSubjectParams.d.ts +10 -0
- package/lib/src/generated/api/PerspectiveUpdateSubjectParams.js +2 -0
- package/lib/src/generated/api/QuerySubscriptionUpdate.d.ts +19 -0
- package/lib/src/generated/api/QuerySubscriptionUpdate.js +2 -0
- package/lib/src/generated/api/QuerySubscriptionUpdateEvent.d.ts +7 -0
- package/lib/src/generated/api/QuerySubscriptionUpdateEvent.js +1 -0
- package/lib/src/generated/api/QueryUpdatesLagged.d.ts +7 -0
- package/lib/src/generated/api/QueryUpdatesLagged.js +2 -0
- package/lib/src/generated/api/RemoveSubjectRequest.d.ts +9 -0
- package/lib/src/generated/api/RemoveSubjectRequest.js +2 -0
- package/lib/src/generated/api/ResyncSubscriptionRequest.d.ts +3 -0
- package/lib/src/generated/api/ResyncSubscriptionRequest.js +2 -0
- package/lib/src/generated/api/RpcMethods.d.ts +134 -14
- package/lib/src/generated/api/RpcMethods.js +12 -0
- package/lib/src/generated/api/SfuAddIceCandidateParams.d.ts +8 -0
- package/lib/src/generated/api/SfuAddIceCandidateParams.js +2 -0
- package/lib/src/generated/api/SfuAnswerServerOfferParams.d.ts +8 -0
- package/lib/src/generated/api/SfuAnswerServerOfferParams.js +2 -0
- package/lib/src/generated/api/SfuCallJoinParams.d.ts +14 -0
- package/lib/src/generated/api/SfuCallJoinParams.js +2 -0
- package/lib/src/generated/api/SfuCallRenegotiationOffer.d.ts +30 -0
- package/lib/src/generated/api/SfuCallRenegotiationOffer.js +1 -0
- package/lib/src/generated/api/SfuCascadePipe.d.ts +4 -0
- package/lib/src/generated/api/SfuCascadePipe.js +2 -0
- package/lib/src/generated/api/SfuCascadeStatus.d.ts +8 -0
- package/lib/src/generated/api/SfuCascadeStatus.js +1 -0
- package/lib/src/generated/api/SfuConfig.d.ts +52 -0
- package/lib/src/generated/api/SfuConfig.js +1 -0
- package/lib/src/generated/api/SfuDataMessage.d.ts +24 -0
- package/lib/src/generated/api/SfuDataMessage.js +2 -0
- package/lib/src/generated/api/SfuEnsureMembershipParams.d.ts +4 -0
- package/lib/src/generated/api/SfuEnsureMembershipParams.js +2 -0
- package/lib/src/generated/api/SfuMigrateEvent.d.ts +21 -0
- package/lib/src/generated/api/SfuMigrateEvent.js +2 -0
- package/lib/src/generated/api/SfuNeighbourhoodParams.d.ts +3 -0
- package/lib/src/generated/api/SfuNeighbourhoodParams.js +2 -0
- package/lib/src/generated/api/SfuParticipantQualityPreference.d.ts +7 -0
- package/lib/src/generated/api/SfuParticipantQualityPreference.js +2 -0
- package/lib/src/generated/api/SfuPerspectiveParams.d.ts +6 -0
- package/lib/src/generated/api/SfuPerspectiveParams.js +2 -0
- package/lib/src/generated/api/SfuQualityPreferenceParams.d.ts +8 -0
- package/lib/src/generated/api/SfuQualityPreferenceParams.js +2 -0
- package/lib/src/generated/api/SfuRoomInfo.d.ts +11 -0
- package/lib/src/generated/api/SfuRoomInfo.js +1 -0
- package/lib/src/generated/api/SfuRoomParams.d.ts +4 -0
- package/lib/src/generated/api/SfuRoomParams.js +2 -0
- package/lib/src/generated/api/SfuRoomParticipantInfo.d.ts +11 -0
- package/lib/src/generated/api/SfuRoomParticipantInfo.js +2 -0
- package/lib/src/generated/api/SfuRoomRoster.d.ts +13 -0
- package/lib/src/generated/api/SfuRoomRoster.js +2 -0
- package/lib/src/generated/api/SfuSendDataParams.d.ts +10 -0
- package/lib/src/generated/api/SfuSendDataParams.js +2 -0
- package/lib/src/generated/api/SfuSetConfigParams.d.ts +5 -0
- package/lib/src/generated/api/SfuSetConfigParams.js +1 -0
- package/lib/src/generated/api/SfuStatus.d.ts +24 -0
- package/lib/src/generated/api/SfuStatus.js +2 -0
- package/lib/src/generated/api/TrackMapEntry.d.ts +17 -0
- package/lib/src/generated/api/TrackMapEntry.js +2 -0
- package/lib/src/generated/api/UpdateSubjectRequest.d.ts +12 -0
- package/lib/src/generated/api/UpdateSubjectRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +3 -0
- package/lib/src/index.d.ts +7 -0
- package/lib/src/index.js +4 -0
- package/lib/src/model/Ad4mModel.d.ts +84 -0
- package/lib/src/model/Ad4mModel.js +234 -4
- package/lib/src/model/ModelQueryBuilder.d.ts +16 -35
- package/lib/src/model/ModelQueryBuilder.js +88 -270
- package/lib/src/model/decorators.d.ts +32 -0
- package/lib/src/model/decorators.js +40 -1
- package/lib/src/model/shacl-gen.d.ts +3 -1
- package/lib/src/model/shacl-gen.js +13 -1
- package/lib/src/model/types.d.ts +7 -0
- package/lib/src/neighbourhood/MeshManager.d.ts +384 -0
- package/lib/src/neighbourhood/MeshManager.js +1144 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +91 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.js +196 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +55 -1
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +170 -3
- package/lib/src/neighbourhood/Session.d.ts +105 -0
- package/lib/src/neighbourhood/Session.js +412 -0
- package/lib/src/neighbourhood/SfuManager.d.ts +174 -0
- package/lib/src/neighbourhood/SfuManager.js +619 -0
- package/lib/src/neighbourhood/SfuTypes.d.ts +35 -0
- package/lib/src/neighbourhood/SfuTypes.js +8 -0
- package/lib/src/perspectives/FlowInstance.d.ts +63 -24
- package/lib/src/perspectives/FlowInstance.js +74 -31
- package/lib/src/perspectives/FlowModels.d.ts +0 -16
- package/lib/src/perspectives/FlowModels.js +8 -16
- package/lib/src/perspectives/LiveQuery.d.ts +49 -0
- package/lib/src/perspectives/LiveQuery.js +169 -0
- package/lib/src/perspectives/PerspectiveClient.d.ts +24 -15
- package/lib/src/perspectives/PerspectiveClient.js +33 -36
- package/lib/src/perspectives/PerspectiveProxy.d.ts +67 -167
- package/lib/src/perspectives/PerspectiveProxy.js +121 -475
- package/lib/src/perspectives/TextContent.d.ts +31 -0
- package/lib/src/perspectives/TextContent.js +52 -0
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +23 -0
- package/lib/src/perspectives/WakerSubscriptionManager.js +58 -17
- package/lib/src/shacl/SHACLFlow.d.ts +7 -4
- package/lib/src/shacl/SHACLFlow.js +7 -4
- package/lib/src/shacl/SHACLShape.d.ts +9 -0
- package/lib/src/shacl/SHACLShape.js +37 -0
- package/package.json +2 -2
- package/pnpm-workspace.yaml +4 -1
- package/src/Ad4mClient.test.ts +89 -17
- package/src/generated/api/AgentsByDidsRequest.ts +3 -0
- package/src/generated/api/CallSessionInfo.ts +20 -0
- package/src/generated/api/DiscardBatchRequest.ts +3 -0
- package/src/generated/api/Events.ts +14 -3
- package/src/generated/api/FlowStateChangedEvent.ts +36 -0
- package/src/generated/api/FlowStateEntry.ts +18 -0
- package/src/generated/api/IceServer.ts +19 -0
- package/src/generated/api/OnlineAgent.ts +6 -1
- package/src/generated/api/PerspectiveDiscardBatchParams.ts +3 -0
- package/src/generated/api/PerspectiveFlowFiredParams.ts +7 -0
- package/src/generated/api/PerspectiveFlowStatesParams.ts +11 -0
- package/src/generated/api/PerspectiveGetAllShaclParams.ts +6 -0
- package/src/generated/api/PerspectiveModelQueryParams.ts +5 -1
- package/src/generated/api/PerspectiveRemoveSubjectParams.ts +3 -0
- package/src/generated/api/PerspectiveResynced.ts +7 -0
- package/src/generated/api/PerspectiveSubscribed.ts +8 -0
- package/src/generated/api/PerspectiveUpdateSubjectParams.ts +7 -0
- package/src/generated/api/QuerySubscriptionUpdate.ts +10 -0
- package/src/generated/api/QuerySubscriptionUpdateEvent.ts +9 -0
- package/src/generated/api/QueryUpdatesLagged.ts +7 -0
- package/src/generated/api/RemoveSubjectRequest.ts +7 -0
- package/src/generated/api/ResyncSubscriptionRequest.ts +3 -0
- package/src/generated/api/RpcMethods.ts +68 -8
- package/src/generated/api/SfuAddIceCandidateParams.ts +7 -0
- package/src/generated/api/SfuAnswerServerOfferParams.ts +7 -0
- package/src/generated/api/SfuCallJoinParams.ts +13 -0
- package/src/generated/api/SfuCallRenegotiationOffer.ts +29 -0
- package/src/generated/api/SfuCascadePipe.ts +3 -0
- package/src/generated/api/SfuCascadeStatus.ts +7 -0
- package/src/generated/api/SfuConfig.ts +53 -0
- package/src/generated/api/SfuDataMessage.ts +23 -0
- package/src/generated/api/SfuEnsureMembershipParams.ts +3 -0
- package/src/generated/api/SfuMigrateEvent.ts +20 -0
- package/src/generated/api/{KeepAliveQueryRequest.ts → SfuNeighbourhoodParams.ts} +1 -1
- package/src/generated/api/SfuParticipantQualityPreference.ts +6 -0
- package/src/generated/api/{PerspectiveSubscribeQueryResult.ts → SfuPerspectiveParams.ts} +4 -1
- package/src/generated/api/SfuQualityPreferenceParams.ts +7 -0
- package/src/generated/api/SfuRoomInfo.ts +7 -0
- package/src/generated/api/SfuRoomParams.ts +3 -0
- package/src/generated/api/SfuRoomParticipantInfo.ts +8 -0
- package/src/generated/api/SfuRoomRoster.ts +12 -0
- package/src/generated/api/SfuSendDataParams.ts +7 -0
- package/src/generated/api/SfuSetConfigParams.ts +4 -0
- package/src/generated/api/SfuStatus.ts +24 -0
- package/src/generated/api/TrackMapEntry.ts +18 -0
- package/src/generated/api/UpdateSubjectRequest.ts +10 -0
- package/src/generated/api/index.ts +3 -0
- package/src/index.ts +7 -0
- package/src/model/Ad4mModel.test.ts +255 -231
- package/src/model/Ad4mModel.ts +271 -4
- package/src/model/ModelQueryBuilder.ts +103 -310
- package/src/model/abstract-classes.test.ts +225 -0
- package/src/model/decorators.ts +81 -0
- package/src/model/shacl-gen.ts +13 -0
- package/src/model/types.ts +7 -0
- package/src/neighbourhood/MeshManager.test.ts +2640 -0
- package/src/neighbourhood/MeshManager.ts +1350 -0
- package/src/neighbourhood/NeighbourhoodClient.ts +271 -0
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +23 -0
- package/src/neighbourhood/NeighbourhoodProxy.ts +247 -1
- package/src/neighbourhood/Session.test.ts +800 -0
- package/src/neighbourhood/Session.ts +525 -0
- package/src/neighbourhood/SfuManager.test.ts +677 -0
- package/src/neighbourhood/SfuManager.ts +803 -0
- package/src/neighbourhood/SfuTypes.ts +40 -0
- package/src/perspectives/FlowInstance.ts +108 -31
- package/src/perspectives/FlowModels.ts +8 -18
- package/src/perspectives/LiveQuery.test.ts +197 -0
- package/src/perspectives/LiveQuery.ts +189 -0
- package/src/perspectives/PerspectiveClient.ts +51 -51
- package/src/perspectives/PerspectiveProxy.test.ts +85 -401
- package/src/perspectives/PerspectiveProxy.ts +126 -536
- package/src/perspectives/TextContent.test.ts +123 -0
- package/src/perspectives/TextContent.ts +36 -0
- package/src/perspectives/WakerSubscriptionManager.test.ts +88 -6
- package/src/perspectives/WakerSubscriptionManager.ts +69 -18
- package/src/shacl/SHACLFlow.ts +7 -4
- package/src/shacl/SHACLShape.test.ts +2 -1
- package/src/shacl/SHACLShape.ts +49 -0
- package/lib/src/generated/api/KeepAliveQueryRequest.d.ts +0 -3
- package/lib/src/generated/api/PerspectiveModelSubscribeResult.d.ts +0 -7
- package/lib/src/generated/api/PerspectiveQuerySubscriptionFilter.d.ts +0 -6
- package/lib/src/generated/api/PerspectiveSubscribeQueryResult.d.ts +0 -4
- package/src/generated/api/PerspectiveModelSubscribeResult.ts +0 -6
- package/src/generated/api/PerspectiveQuerySubscriptionFilter.ts +0 -3
- /package/lib/src/generated/api/{KeepAliveQueryRequest.js → AgentsByDidsRequest.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveModelSubscribeResult.js → CallSessionInfo.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveQuerySubscriptionFilter.js → DiscardBatchRequest.js} +0 -0
- /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
|
-
|
|
1286
|
-
updateCallback = cb;
|
|
1293
|
+
onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
|
|
1294
|
+
updateCallback = updatesFor(mockSubscriptionId, cb);
|
|
1287
1295
|
return () => {}; // unsubscribe function
|
|
1288
1296
|
}),
|
|
1289
|
-
|
|
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
|
-
|
|
1353
|
+
onQueryUpdate: jest.fn().mockImplementation((_cb: any) => {
|
|
1345
1354
|
return () => {};
|
|
1346
1355
|
}),
|
|
1347
|
-
|
|
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
|
-
|
|
1400
|
-
capturedCallback = cb;
|
|
1409
|
+
onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
|
|
1410
|
+
capturedCallback = updatesFor(mockSubscriptionId, cb);
|
|
1401
1411
|
return () => {};
|
|
1402
1412
|
}),
|
|
1403
|
-
|
|
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
|
-
|
|
1468
|
-
capturedCallback = cb;
|
|
1478
|
+
onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
|
|
1479
|
+
capturedCallback = updatesFor(mockSubscriptionId, cb);
|
|
1469
1480
|
return () => {};
|
|
1470
1481
|
}),
|
|
1471
|
-
|
|
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
|
-
|
|
1537
|
-
capturedCallback = cb;
|
|
1548
|
+
onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
|
|
1549
|
+
capturedCallback = updatesFor(mockSubscriptionId, cb);
|
|
1538
1550
|
return () => {};
|
|
1539
1551
|
}),
|
|
1540
|
-
|
|
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
|
-
|
|
1608
|
-
capturedCallback = cb;
|
|
1620
|
+
onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
|
|
1621
|
+
capturedCallback = updatesFor(mockSubscriptionId, cb);
|
|
1609
1622
|
return () => {};
|
|
1610
1623
|
}),
|
|
1611
|
-
|
|
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
|
-
|
|
1679
|
-
capturedCallback = cb;
|
|
1692
|
+
onQueryUpdate: jest.fn().mockImplementation((cb: any) => {
|
|
1693
|
+
capturedCallback = updatesFor(mockSubscriptionId, cb);
|
|
1680
1694
|
return () => {};
|
|
1681
1695
|
}),
|
|
1682
|
-
|
|
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
|
-
//
|
|
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
|
|
1753
|
-
|
|
1754
|
-
|
|
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
|
-
|
|
1773
|
+
subscribeCount++;
|
|
1769
1774
|
return {
|
|
1770
|
-
subscriptionId: `sub-${
|
|
1771
|
-
|
|
1775
|
+
subscriptionId: `sub-${subscribeCount}`,
|
|
1776
|
+
revision: 0,
|
|
1777
|
+
result: { instances: [], totalCount: subscribeCount },
|
|
1772
1778
|
};
|
|
1773
1779
|
}),
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
1839
|
-
const {
|
|
1840
|
-
|
|
1841
|
-
const
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
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
|
|
1867
|
-
const {
|
|
1868
|
-
|
|
1869
|
-
const
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
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("
|
|
1894
|
-
const {
|
|
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
|
-
|
|
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
|
-
// ──
|
|
3744
|
-
describe("ModelQueryBuilder
|
|
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
|
-
|
|
3684
|
+
let n = 0;
|
|
3754
3685
|
const mockClient = {
|
|
3755
|
-
modelSubscribe: jest.fn().
|
|
3756
|
-
subscriptionId:
|
|
3686
|
+
modelSubscribe: jest.fn().mockImplementation(async () => ({
|
|
3687
|
+
subscriptionId: `sub-${++n}`,
|
|
3688
|
+
revision: 0,
|
|
3757
3689
|
result: { instances: [], totalCount: 0 },
|
|
3758
|
-
}),
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
disposeQuerySubscription: jest.fn().
|
|
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(
|
|
3767
|
-
|
|
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
|
|
3705
|
+
return { mockPerspective, mockClient };
|
|
3773
3706
|
}
|
|
3774
3707
|
|
|
3775
3708
|
const { Ad4mModel, Model, Property, Flag } = require("./index");
|
|
3776
3709
|
|
|
3777
|
-
@Model({ name: "
|
|
3778
|
-
class
|
|
3779
|
-
@Flag({ through: "test://type", value: "test://
|
|
3780
|
-
type: string = "test://
|
|
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
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3801
|
-
|
|
3802
|
-
expect(
|
|
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("
|
|
3806
|
-
const { mockPerspective,
|
|
3807
|
-
|
|
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
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
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
|
|
3818
|
-
const
|
|
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
|
|
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
|
-
|
|
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()
|
|
3849
|
-
const { mockPerspective, mockClient
|
|
3850
|
-
const
|
|
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
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
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
|
});
|