@coasys/ad4m 0.13.1-staging.14 → 0.13.1-staging.15
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 +23 -3
- package/lib/index.js +23 -3
- package/lib/src/model/Ad4mModel.js +2 -1
- package/lib/src/model/shacl-gen.js +2 -0
- package/lib/src/neighbourhood/SfuManager.d.ts +8 -1
- package/lib/src/neighbourhood/SfuManager.js +9 -2
- package/lib/src/shacl/SHACLShape.d.ts +4 -0
- package/lib/src/shacl/SHACLShape.js +10 -0
- package/package.json +2 -2
- package/src/model/Ad4mModel.ts +2 -1
- package/src/model/shacl-gen.ts +1 -0
- package/src/model/shacl-roundtrip.test.ts +28 -0
- package/src/neighbourhood/SfuManager.test.ts +57 -5
- package/src/neighbourhood/SfuManager.ts +10 -2
- package/src/shacl/SHACLShape.test.ts +21 -0
- package/src/shacl/SHACLShape.ts +16 -0
package/lib/index.cjs
CHANGED
|
@@ -3148,8 +3148,15 @@ class SfuManager {
|
|
|
3148
3148
|
SfuManager.MAX_RECONNECTS = 3;
|
|
3149
3149
|
/** How long one rebuild keeps retrying a join the executor cannot take yet. */
|
|
3150
3150
|
SfuManager.REJOIN_WINDOW_MS = 120000;
|
|
3151
|
-
/**
|
|
3152
|
-
|
|
3151
|
+
/** The executor's wait before the first resend of an unanswered offer.
|
|
3152
|
+
* `OFFER_RETRY_BASE` in `rust-executor/src/sfu/server.rs`. */
|
|
3153
|
+
SfuManager.OFFER_RESEND_BASE_MS = 10000;
|
|
3154
|
+
/** How long ICE has to come back after that resend arrives. */
|
|
3155
|
+
SfuManager.RESTART_AFTER_RESEND_MS = 5000;
|
|
3156
|
+
/** How long an ICE restart has to bring the connection back before a rebuild.
|
|
3157
|
+
* The window stays open through the first resend, then the previous 5 s
|
|
3158
|
+
* for ICE. A restart that connects clears the timer at once. */
|
|
3159
|
+
SfuManager.RESTART_TIMEOUT_MS = SfuManager.OFFER_RESEND_BASE_MS + SfuManager.RESTART_AFTER_RESEND_MS;
|
|
3153
3160
|
/** How long the roster may leave this session out before the call is rebuilt. */
|
|
3154
3161
|
SfuManager.UNLISTED_GRACE_MS = 3000;
|
|
3155
3162
|
|
|
@@ -6142,6 +6149,13 @@ class SHACLShape {
|
|
|
6142
6149
|
target: `literal:string:${prop.relationKind}`
|
|
6143
6150
|
});
|
|
6144
6151
|
}
|
|
6152
|
+
if (prop.polymorphic) {
|
|
6153
|
+
links.push({
|
|
6154
|
+
source: propShapeId,
|
|
6155
|
+
predicate: "ad4m://polymorphic",
|
|
6156
|
+
target: `literal:${prop.polymorphic}`
|
|
6157
|
+
});
|
|
6158
|
+
}
|
|
6145
6159
|
if (prop.targetClassName) {
|
|
6146
6160
|
links.push({
|
|
6147
6161
|
source: propShapeId,
|
|
@@ -6281,6 +6295,7 @@ class SHACLShape {
|
|
|
6281
6295
|
in: json(id, "sh://in"),
|
|
6282
6296
|
relationKind: ['hasMany', 'hasOne', 'belongsToOne', 'belongsToMany'].includes(relationKind)
|
|
6283
6297
|
? relationKind : undefined,
|
|
6298
|
+
polymorphic: bool(id, "ad4m://polymorphic"),
|
|
6284
6299
|
targetClassName: str(id, "ad4m://targetClassName"),
|
|
6285
6300
|
whereFilter: json(id, "ad4m://whereFilter"),
|
|
6286
6301
|
wherePredicates: json(id, "ad4m://wherePredicates"),
|
|
@@ -6329,6 +6344,7 @@ class SHACLShape {
|
|
|
6329
6344
|
class: p.class,
|
|
6330
6345
|
in: p.in,
|
|
6331
6346
|
relation_kind: p.relationKind,
|
|
6347
|
+
polymorphic: p.polymorphic,
|
|
6332
6348
|
collection: p.collection ?? (isCollection(p) || undefined),
|
|
6333
6349
|
target_class_name: p.targetClassName,
|
|
6334
6350
|
where_filter: p.whereFilter,
|
|
@@ -6383,6 +6399,7 @@ class SHACLShape {
|
|
|
6383
6399
|
class: p.class,
|
|
6384
6400
|
in: p.in,
|
|
6385
6401
|
relationKind: p.relation_kind,
|
|
6402
|
+
polymorphic: p.polymorphic,
|
|
6386
6403
|
collection: p.collection,
|
|
6387
6404
|
targetClassName: p.target_class_name,
|
|
6388
6405
|
whereFilter: p.where_filter,
|
|
@@ -6708,6 +6725,8 @@ isAbstract) {
|
|
|
6708
6725
|
// Encode relation kind so the executor can derive direction and
|
|
6709
6726
|
// scalar-vs-collection rendering without consulting the JS class.
|
|
6710
6727
|
relShape.relationKind = relMeta.kind;
|
|
6728
|
+
if (relMeta.polymorphic)
|
|
6729
|
+
relShape.polymorphic = true;
|
|
6711
6730
|
// Scalar relations cap at 1.
|
|
6712
6731
|
if (relMeta.kind === 'hasOne' || relMeta.kind === 'belongsToOne') {
|
|
6713
6732
|
relShape.maxCount = 1;
|
|
@@ -21027,7 +21046,8 @@ const SUBJECT_CLASS_KEY = '__subjectClass';
|
|
|
21027
21046
|
* The walk stops descending *through* a polymorphic relation, because there is
|
|
21028
21047
|
* nothing to descend into: its targets are of several classes by definition, so
|
|
21029
21048
|
* no single class's metadata could say what a deeper include means. The
|
|
21030
|
-
* executor
|
|
21049
|
+
* executor applies each concrete class's declared default from its shape
|
|
21050
|
+
* (`ad4m://polymorphic`) to those nested includes instead.
|
|
21031
21051
|
*/
|
|
21032
21052
|
function applyPolymorphicIncludeDefaults(includes, ctor) {
|
|
21033
21053
|
const relMeta = getRelationsMetadata(ctor);
|
package/lib/index.js
CHANGED
|
@@ -3144,8 +3144,15 @@ class SfuManager {
|
|
|
3144
3144
|
SfuManager.MAX_RECONNECTS = 3;
|
|
3145
3145
|
/** How long one rebuild keeps retrying a join the executor cannot take yet. */
|
|
3146
3146
|
SfuManager.REJOIN_WINDOW_MS = 120000;
|
|
3147
|
-
/**
|
|
3148
|
-
|
|
3147
|
+
/** The executor's wait before the first resend of an unanswered offer.
|
|
3148
|
+
* `OFFER_RETRY_BASE` in `rust-executor/src/sfu/server.rs`. */
|
|
3149
|
+
SfuManager.OFFER_RESEND_BASE_MS = 10000;
|
|
3150
|
+
/** How long ICE has to come back after that resend arrives. */
|
|
3151
|
+
SfuManager.RESTART_AFTER_RESEND_MS = 5000;
|
|
3152
|
+
/** How long an ICE restart has to bring the connection back before a rebuild.
|
|
3153
|
+
* The window stays open through the first resend, then the previous 5 s
|
|
3154
|
+
* for ICE. A restart that connects clears the timer at once. */
|
|
3155
|
+
SfuManager.RESTART_TIMEOUT_MS = SfuManager.OFFER_RESEND_BASE_MS + SfuManager.RESTART_AFTER_RESEND_MS;
|
|
3149
3156
|
/** How long the roster may leave this session out before the call is rebuilt. */
|
|
3150
3157
|
SfuManager.UNLISTED_GRACE_MS = 3000;
|
|
3151
3158
|
|
|
@@ -6138,6 +6145,13 @@ class SHACLShape {
|
|
|
6138
6145
|
target: `literal:string:${prop.relationKind}`
|
|
6139
6146
|
});
|
|
6140
6147
|
}
|
|
6148
|
+
if (prop.polymorphic) {
|
|
6149
|
+
links.push({
|
|
6150
|
+
source: propShapeId,
|
|
6151
|
+
predicate: "ad4m://polymorphic",
|
|
6152
|
+
target: `literal:${prop.polymorphic}`
|
|
6153
|
+
});
|
|
6154
|
+
}
|
|
6141
6155
|
if (prop.targetClassName) {
|
|
6142
6156
|
links.push({
|
|
6143
6157
|
source: propShapeId,
|
|
@@ -6277,6 +6291,7 @@ class SHACLShape {
|
|
|
6277
6291
|
in: json(id, "sh://in"),
|
|
6278
6292
|
relationKind: ['hasMany', 'hasOne', 'belongsToOne', 'belongsToMany'].includes(relationKind)
|
|
6279
6293
|
? relationKind : undefined,
|
|
6294
|
+
polymorphic: bool(id, "ad4m://polymorphic"),
|
|
6280
6295
|
targetClassName: str(id, "ad4m://targetClassName"),
|
|
6281
6296
|
whereFilter: json(id, "ad4m://whereFilter"),
|
|
6282
6297
|
wherePredicates: json(id, "ad4m://wherePredicates"),
|
|
@@ -6325,6 +6340,7 @@ class SHACLShape {
|
|
|
6325
6340
|
class: p.class,
|
|
6326
6341
|
in: p.in,
|
|
6327
6342
|
relation_kind: p.relationKind,
|
|
6343
|
+
polymorphic: p.polymorphic,
|
|
6328
6344
|
collection: p.collection ?? (isCollection(p) || undefined),
|
|
6329
6345
|
target_class_name: p.targetClassName,
|
|
6330
6346
|
where_filter: p.whereFilter,
|
|
@@ -6379,6 +6395,7 @@ class SHACLShape {
|
|
|
6379
6395
|
class: p.class,
|
|
6380
6396
|
in: p.in,
|
|
6381
6397
|
relationKind: p.relation_kind,
|
|
6398
|
+
polymorphic: p.polymorphic,
|
|
6382
6399
|
collection: p.collection,
|
|
6383
6400
|
targetClassName: p.target_class_name,
|
|
6384
6401
|
whereFilter: p.where_filter,
|
|
@@ -6704,6 +6721,8 @@ isAbstract) {
|
|
|
6704
6721
|
// Encode relation kind so the executor can derive direction and
|
|
6705
6722
|
// scalar-vs-collection rendering without consulting the JS class.
|
|
6706
6723
|
relShape.relationKind = relMeta.kind;
|
|
6724
|
+
if (relMeta.polymorphic)
|
|
6725
|
+
relShape.polymorphic = true;
|
|
6707
6726
|
// Scalar relations cap at 1.
|
|
6708
6727
|
if (relMeta.kind === 'hasOne' || relMeta.kind === 'belongsToOne') {
|
|
6709
6728
|
relShape.maxCount = 1;
|
|
@@ -21023,7 +21042,8 @@ const SUBJECT_CLASS_KEY = '__subjectClass';
|
|
|
21023
21042
|
* The walk stops descending *through* a polymorphic relation, because there is
|
|
21024
21043
|
* nothing to descend into: its targets are of several classes by definition, so
|
|
21025
21044
|
* no single class's metadata could say what a deeper include means. The
|
|
21026
|
-
* executor
|
|
21045
|
+
* executor applies each concrete class's declared default from its shape
|
|
21046
|
+
* (`ad4m://polymorphic`) to those nested includes instead.
|
|
21027
21047
|
*/
|
|
21028
21048
|
function applyPolymorphicIncludeDefaults(includes, ctor) {
|
|
21029
21049
|
const relMeta = getRelationsMetadata(ctor);
|
|
@@ -51,7 +51,8 @@ const SUBJECT_CLASS_KEY = '__subjectClass';
|
|
|
51
51
|
* The walk stops descending *through* a polymorphic relation, because there is
|
|
52
52
|
* nothing to descend into: its targets are of several classes by definition, so
|
|
53
53
|
* no single class's metadata could say what a deeper include means. The
|
|
54
|
-
* executor
|
|
54
|
+
* executor applies each concrete class's declared default from its shape
|
|
55
|
+
* (`ad4m://polymorphic`) to those nested includes instead.
|
|
55
56
|
*/
|
|
56
57
|
function applyPolymorphicIncludeDefaults(includes, ctor) {
|
|
57
58
|
const relMeta = getRelationsMetadata(ctor);
|
|
@@ -292,6 +292,8 @@ isAbstract) {
|
|
|
292
292
|
// Encode relation kind so the executor can derive direction and
|
|
293
293
|
// scalar-vs-collection rendering without consulting the JS class.
|
|
294
294
|
relShape.relationKind = relMeta.kind;
|
|
295
|
+
if (relMeta.polymorphic)
|
|
296
|
+
relShape.polymorphic = true;
|
|
295
297
|
// Scalar relations cap at 1.
|
|
296
298
|
if (relMeta.kind === 'hasOne' || relMeta.kind === 'belongsToOne') {
|
|
297
299
|
relShape.maxCount = 1;
|
|
@@ -116,7 +116,14 @@ export declare class SfuManager {
|
|
|
116
116
|
private static readonly MAX_RECONNECTS;
|
|
117
117
|
/** How long one rebuild keeps retrying a join the executor cannot take yet. */
|
|
118
118
|
private static readonly REJOIN_WINDOW_MS;
|
|
119
|
-
/**
|
|
119
|
+
/** The executor's wait before the first resend of an unanswered offer.
|
|
120
|
+
* `OFFER_RETRY_BASE` in `rust-executor/src/sfu/server.rs`. */
|
|
121
|
+
private static readonly OFFER_RESEND_BASE_MS;
|
|
122
|
+
/** How long ICE has to come back after that resend arrives. */
|
|
123
|
+
private static readonly RESTART_AFTER_RESEND_MS;
|
|
124
|
+
/** How long an ICE restart has to bring the connection back before a rebuild.
|
|
125
|
+
* The window stays open through the first resend, then the previous 5 s
|
|
126
|
+
* for ICE. A restart that connects clears the timer at once. */
|
|
120
127
|
private static readonly RESTART_TIMEOUT_MS;
|
|
121
128
|
/** A rebuild is running: a second failure signal joins it rather than starting another. */
|
|
122
129
|
private reconnecting;
|
|
@@ -874,7 +874,14 @@ export class SfuManager {
|
|
|
874
874
|
SfuManager.MAX_RECONNECTS = 3;
|
|
875
875
|
/** How long one rebuild keeps retrying a join the executor cannot take yet. */
|
|
876
876
|
SfuManager.REJOIN_WINDOW_MS = 120000;
|
|
877
|
-
/**
|
|
878
|
-
|
|
877
|
+
/** The executor's wait before the first resend of an unanswered offer.
|
|
878
|
+
* `OFFER_RETRY_BASE` in `rust-executor/src/sfu/server.rs`. */
|
|
879
|
+
SfuManager.OFFER_RESEND_BASE_MS = 10000;
|
|
880
|
+
/** How long ICE has to come back after that resend arrives. */
|
|
881
|
+
SfuManager.RESTART_AFTER_RESEND_MS = 5000;
|
|
882
|
+
/** How long an ICE restart has to bring the connection back before a rebuild.
|
|
883
|
+
* The window stays open through the first resend, then the previous 5 s
|
|
884
|
+
* for ICE. A restart that connects clears the timer at once. */
|
|
885
|
+
SfuManager.RESTART_TIMEOUT_MS = SfuManager.OFFER_RESEND_BASE_MS + SfuManager.RESTART_AFTER_RESEND_MS;
|
|
879
886
|
/** How long the roster may leave this session out before the call is rebuilt. */
|
|
880
887
|
SfuManager.UNLISTED_GRACE_MS = 3000;
|
|
@@ -98,6 +98,10 @@ export interface SHACLPropertyShape {
|
|
|
98
98
|
* Drives direction (forward/reverse), scalar-vs-collection rendering,
|
|
99
99
|
* and default max-count. */
|
|
100
100
|
relationKind?: 'hasMany' | 'hasOne' | 'belongsToOne' | 'belongsToMany';
|
|
101
|
+
/** AD4M-specific: the relation is read `polymorphic: true` unless the query
|
|
102
|
+
* says otherwise (`ad4m://polymorphic`). Carried in the shape so the executor
|
|
103
|
+
* applies it at every include depth, below a polymorphic include too. */
|
|
104
|
+
polymorphic?: boolean;
|
|
101
105
|
/** AD4M-specific: target class name (local-name) for a relation property.
|
|
102
106
|
* Complements `class` (the SHACL node-shape URI) by providing the bare
|
|
103
107
|
* model class name used by the executor to look up the target shape
|
|
@@ -456,6 +456,13 @@ export class SHACLShape {
|
|
|
456
456
|
target: `literal:string:${prop.relationKind}`
|
|
457
457
|
});
|
|
458
458
|
}
|
|
459
|
+
if (prop.polymorphic) {
|
|
460
|
+
links.push({
|
|
461
|
+
source: propShapeId,
|
|
462
|
+
predicate: "ad4m://polymorphic",
|
|
463
|
+
target: `literal:${prop.polymorphic}`
|
|
464
|
+
});
|
|
465
|
+
}
|
|
459
466
|
if (prop.targetClassName) {
|
|
460
467
|
links.push({
|
|
461
468
|
source: propShapeId,
|
|
@@ -595,6 +602,7 @@ export class SHACLShape {
|
|
|
595
602
|
in: json(id, "sh://in"),
|
|
596
603
|
relationKind: ['hasMany', 'hasOne', 'belongsToOne', 'belongsToMany'].includes(relationKind)
|
|
597
604
|
? relationKind : undefined,
|
|
605
|
+
polymorphic: bool(id, "ad4m://polymorphic"),
|
|
598
606
|
targetClassName: str(id, "ad4m://targetClassName"),
|
|
599
607
|
whereFilter: json(id, "ad4m://whereFilter"),
|
|
600
608
|
wherePredicates: json(id, "ad4m://wherePredicates"),
|
|
@@ -643,6 +651,7 @@ export class SHACLShape {
|
|
|
643
651
|
class: p.class,
|
|
644
652
|
in: p.in,
|
|
645
653
|
relation_kind: p.relationKind,
|
|
654
|
+
polymorphic: p.polymorphic,
|
|
646
655
|
collection: p.collection ?? (isCollection(p) || undefined),
|
|
647
656
|
target_class_name: p.targetClassName,
|
|
648
657
|
where_filter: p.whereFilter,
|
|
@@ -697,6 +706,7 @@ export class SHACLShape {
|
|
|
697
706
|
class: p.class,
|
|
698
707
|
in: p.in,
|
|
699
708
|
relationKind: p.relation_kind,
|
|
709
|
+
polymorphic: p.polymorphic,
|
|
700
710
|
collection: p.collection,
|
|
701
711
|
targetClassName: p.target_class_name,
|
|
702
712
|
whereFilter: p.where_filter,
|
package/package.json
CHANGED
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"ws": "8.13.0"
|
|
54
54
|
},
|
|
55
55
|
"patchedDependencies": {},
|
|
56
|
-
"version": "0.13.1-staging.
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"version": "0.13.1-staging.15",
|
|
57
|
+
"gitHead": "72dc335c6cb13c4348f10d2b8dc3d06862f8da51",
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "patch-package && tsc && pnpm run bundle",
|
|
60
60
|
"bundle": "rollup -c rollup.config.js",
|
package/src/model/Ad4mModel.ts
CHANGED
|
@@ -73,7 +73,8 @@ const SUBJECT_CLASS_KEY = '__subjectClass';
|
|
|
73
73
|
* The walk stops descending *through* a polymorphic relation, because there is
|
|
74
74
|
* nothing to descend into: its targets are of several classes by definition, so
|
|
75
75
|
* no single class's metadata could say what a deeper include means. The
|
|
76
|
-
* executor
|
|
76
|
+
* executor applies each concrete class's declared default from its shape
|
|
77
|
+
* (`ad4m://polymorphic`) to those nested includes instead.
|
|
77
78
|
*/
|
|
78
79
|
function applyPolymorphicIncludeDefaults(includes: IncludeMap, ctor: Function): void {
|
|
79
80
|
const relMeta = getRelationsMetadata(ctor);
|
package/src/model/shacl-gen.ts
CHANGED
|
@@ -329,6 +329,7 @@ export function buildSHACL(
|
|
|
329
329
|
// Encode relation kind so the executor can derive direction and
|
|
330
330
|
// scalar-vs-collection rendering without consulting the JS class.
|
|
331
331
|
relShape.relationKind = relMeta.kind;
|
|
332
|
+
if (relMeta.polymorphic) relShape.polymorphic = true;
|
|
332
333
|
|
|
333
334
|
// Scalar relations cap at 1.
|
|
334
335
|
if (relMeta.kind === 'hasOne' || relMeta.kind === 'belongsToOne') {
|
|
@@ -39,6 +39,34 @@ function findLinkTarget(
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
describe("Decorators → SHACL writer round-trip", () => {
|
|
42
|
+
it("emits ad4m:polymorphic only for a relation that declares it", () => {
|
|
43
|
+
@Model({ name: "PolyHolder" })
|
|
44
|
+
class PolyHolder extends Ad4mModel {
|
|
45
|
+
@HasOne({ through: "ns://node", polymorphic: true })
|
|
46
|
+
node: string = "";
|
|
47
|
+
|
|
48
|
+
@BelongsToOne({ through: "ns://extracted", polymorphic: true })
|
|
49
|
+
extractedFrom: string = "";
|
|
50
|
+
|
|
51
|
+
@HasMany({ through: "ns://plain" })
|
|
52
|
+
plain: string[] = [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { shape } = PolyHolder.generateSHACL();
|
|
56
|
+
const links = flatten(shape);
|
|
57
|
+
const propUri = (name: string) => `ns://PolyHolder.${name}`;
|
|
58
|
+
|
|
59
|
+
expect(findLinkTarget(links, propUri("node"), "ad4m://polymorphic")).toBe(
|
|
60
|
+
"literal:true",
|
|
61
|
+
);
|
|
62
|
+
expect(
|
|
63
|
+
findLinkTarget(links, propUri("extractedFrom"), "ad4m://polymorphic"),
|
|
64
|
+
).toBe("literal:true");
|
|
65
|
+
expect(
|
|
66
|
+
findLinkTarget(links, propUri("plain"), "ad4m://polymorphic"),
|
|
67
|
+
).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
|
|
42
70
|
it("emits ad4m:relationKind for every relation kind", () => {
|
|
43
71
|
@Model({ name: "Target" })
|
|
44
72
|
class Target extends Ad4mModel {}
|
|
@@ -1424,16 +1424,66 @@ test("ICE disconnected also checks the executor socket once, with the restart",
|
|
|
1424
1424
|
}
|
|
1425
1425
|
})
|
|
1426
1426
|
|
|
1427
|
-
test("a restart
|
|
1427
|
+
test("a lost restart offer stays open until the executor can resend it", async () => {
|
|
1428
|
+
// ICE drops, the offer is lost, and signaling returns 2 s later. The
|
|
1429
|
+
// executor resends that offer at 10 s. The restart stays open through
|
|
1430
|
+
// that resend, then long enough for ICE to finish.
|
|
1428
1431
|
fakeTimers()
|
|
1429
1432
|
try {
|
|
1430
1433
|
const api = fakeApi()
|
|
1431
1434
|
const manager = new SfuManager(api, ROOM, ME, URL)
|
|
1432
1435
|
await manager.join(fakeStream())
|
|
1433
1436
|
await iceState("connected")
|
|
1437
|
+
api.log.length = 0
|
|
1434
1438
|
|
|
1435
1439
|
await iceState("disconnected")
|
|
1436
|
-
|
|
1440
|
+
expect(api.sfuCallRestartIce).toHaveBeenCalledTimes(1)
|
|
1441
|
+
await jest.advanceTimersByTimeAsync(2_000)
|
|
1442
|
+
api.emitNetworkChange()
|
|
1443
|
+
await flush()
|
|
1444
|
+
expect(api.sfuCallRestartIce).toHaveBeenCalledTimes(2)
|
|
1445
|
+
|
|
1446
|
+
// t = 7 s. A 5 s window started at t = 2 s would rebuild here.
|
|
1447
|
+
await jest.advanceTimersByTimeAsync(5_000)
|
|
1448
|
+
expect(api.sfuCallLeave).not.toHaveBeenCalled()
|
|
1449
|
+
// t = 10 s. The executor's first resend is due. Still no rebuild.
|
|
1450
|
+
await jest.advanceTimersByTimeAsync(3_000)
|
|
1451
|
+
expect(api.sfuCallLeave).not.toHaveBeenCalled()
|
|
1452
|
+
|
|
1453
|
+
// The original peer must apply the resent offer and post its answer
|
|
1454
|
+
// before ICE recovery. `connected` clears the restart timer on its own.
|
|
1455
|
+
const peer = currentPc()
|
|
1456
|
+
api.emitOffer(offer("restart-offer"))
|
|
1457
|
+
await flush()
|
|
1458
|
+
expect(peer.remoteSdps()).toContain("restart-offer")
|
|
1459
|
+
expect(api.sfuCallAnswerServerOffer).toHaveBeenCalledTimes(1)
|
|
1460
|
+
expect(api.sfuCallAnswerServerOffer).toHaveBeenCalledWith(
|
|
1461
|
+
URL,
|
|
1462
|
+
ROOM,
|
|
1463
|
+
MINE,
|
|
1464
|
+
JSON.stringify({ type: "answer", sdp: "local-answer" }),
|
|
1465
|
+
)
|
|
1466
|
+
|
|
1467
|
+
await iceState("connected")
|
|
1468
|
+
await jest.advanceTimersByTimeAsync(30_000)
|
|
1469
|
+
expect(api.sfuCallLeave).not.toHaveBeenCalled()
|
|
1470
|
+
expect(FakePeerConnection.instances).toHaveLength(1)
|
|
1471
|
+
expect(manager.getState().peerConnection).toBe(FakePeerConnection.instances[0])
|
|
1472
|
+
} finally {
|
|
1473
|
+
jest.useRealTimers()
|
|
1474
|
+
}
|
|
1475
|
+
})
|
|
1476
|
+
|
|
1477
|
+
test("a restart that has not brought the connection back after 15 s falls back to a rebuild", async () => {
|
|
1478
|
+
fakeTimers()
|
|
1479
|
+
try {
|
|
1480
|
+
const api = fakeApi()
|
|
1481
|
+
const manager = new SfuManager(api, ROOM, ME, URL)
|
|
1482
|
+
await manager.join(fakeStream())
|
|
1483
|
+
await iceState("connected")
|
|
1484
|
+
|
|
1485
|
+
await iceState("disconnected")
|
|
1486
|
+
await jest.advanceTimersByTimeAsync(14_900)
|
|
1437
1487
|
expect(api.sfuCallLeave).not.toHaveBeenCalled()
|
|
1438
1488
|
await jest.advanceTimersByTimeAsync(200)
|
|
1439
1489
|
expect(api.sfuCallLeave).toHaveBeenCalledTimes(1)
|
|
@@ -1458,7 +1508,9 @@ test("a refused restart also waits for the timeout before rebuilding", async ()
|
|
|
1458
1508
|
expect(api.sfuCallLeave).not.toHaveBeenCalled()
|
|
1459
1509
|
|
|
1460
1510
|
await iceState("disconnected")
|
|
1461
|
-
await jest.advanceTimersByTimeAsync(
|
|
1511
|
+
await jest.advanceTimersByTimeAsync(14_900)
|
|
1512
|
+
expect(api.sfuCallLeave).not.toHaveBeenCalled()
|
|
1513
|
+
await jest.advanceTimersByTimeAsync(200)
|
|
1462
1514
|
expect(api.sfuCallLeave).toHaveBeenCalledTimes(1)
|
|
1463
1515
|
} finally {
|
|
1464
1516
|
jest.useRealTimers()
|
|
@@ -1477,7 +1529,7 @@ test("a network change restarts ICE even while the connection still looks connec
|
|
|
1477
1529
|
await flush()
|
|
1478
1530
|
expect(api.sfuCallRestartIce).toHaveBeenCalledTimes(1)
|
|
1479
1531
|
// Still connected when the timeout comes: nothing to rebuild.
|
|
1480
|
-
await jest.advanceTimersByTimeAsync(
|
|
1532
|
+
await jest.advanceTimersByTimeAsync(15_000)
|
|
1481
1533
|
expect(api.sfuCallLeave).not.toHaveBeenCalled()
|
|
1482
1534
|
} finally {
|
|
1483
1535
|
jest.useRealTimers()
|
|
@@ -1560,7 +1612,7 @@ test("a roster that lists this agent during a restart lets the restart finish in
|
|
|
1560
1612
|
|
|
1561
1613
|
test("a roster that leaves this agent out during a restart rebuilds after its grace, once", async () => {
|
|
1562
1614
|
// The server dropped the session: the restart cannot heal it, so the
|
|
1563
|
-
// roster's grace (3 s) ends it before the restart's timeout (
|
|
1615
|
+
// roster's grace (3 s) ends it before the restart's timeout (15 s).
|
|
1564
1616
|
fakeTimers()
|
|
1565
1617
|
try {
|
|
1566
1618
|
const api = fakeApi()
|
|
@@ -274,8 +274,16 @@ export class SfuManager {
|
|
|
274
274
|
private static readonly MAX_RECONNECTS = 3
|
|
275
275
|
/** How long one rebuild keeps retrying a join the executor cannot take yet. */
|
|
276
276
|
private static readonly REJOIN_WINDOW_MS = 120_000
|
|
277
|
-
/**
|
|
278
|
-
|
|
277
|
+
/** The executor's wait before the first resend of an unanswered offer.
|
|
278
|
+
* `OFFER_RETRY_BASE` in `rust-executor/src/sfu/server.rs`. */
|
|
279
|
+
private static readonly OFFER_RESEND_BASE_MS = 10_000
|
|
280
|
+
/** How long ICE has to come back after that resend arrives. */
|
|
281
|
+
private static readonly RESTART_AFTER_RESEND_MS = 5_000
|
|
282
|
+
/** How long an ICE restart has to bring the connection back before a rebuild.
|
|
283
|
+
* The window stays open through the first resend, then the previous 5 s
|
|
284
|
+
* for ICE. A restart that connects clears the timer at once. */
|
|
285
|
+
private static readonly RESTART_TIMEOUT_MS =
|
|
286
|
+
SfuManager.OFFER_RESEND_BASE_MS + SfuManager.RESTART_AFTER_RESEND_MS
|
|
279
287
|
/** A rebuild is running: a second failure signal joins it rather than starting another. */
|
|
280
288
|
private reconnecting = false
|
|
281
289
|
/** Bumped by `leave()`, so a reconnect in flight stops before rejoining. */
|
|
@@ -668,6 +668,27 @@ describe('SHACLShape', () => {
|
|
|
668
668
|
expect(round.properties[0].relationKind).toBe('hasMany');
|
|
669
669
|
});
|
|
670
670
|
|
|
671
|
+
it('emits, parses and round-trips polymorphic through links and JSON', () => {
|
|
672
|
+
const shape = new SHACLShape('ns://Placement');
|
|
673
|
+
shape.addProperty({ name: 'node', path: 'ns://placed', relationKind: 'hasOne', polymorphic: true });
|
|
674
|
+
shape.addProperty({ name: 'plain', path: 'ns://plain', relationKind: 'hasOne' });
|
|
675
|
+
const links = shape.toLinks();
|
|
676
|
+
const polyLinks = links.filter(l => l.predicate === 'ad4m://polymorphic');
|
|
677
|
+
expect(polyLinks).toHaveLength(1);
|
|
678
|
+
expect(polyLinks[0].source).toContain('Placement.node');
|
|
679
|
+
expect(polyLinks[0].target).toBe('literal:true');
|
|
680
|
+
|
|
681
|
+
const round = SHACLShape.fromLinks(links, shape.nodeShapeUri);
|
|
682
|
+
expect(round.properties.find(p => p.name === 'node')?.polymorphic).toBe(true);
|
|
683
|
+
expect(round.properties.find(p => p.name === 'plain')?.polymorphic).toBeUndefined();
|
|
684
|
+
|
|
685
|
+
const json = shape.toJSON();
|
|
686
|
+
expect((json as any).properties.find((p: any) => p.name === 'node').polymorphic).toBe(true);
|
|
687
|
+
const fromJson = SHACLShape.fromJSON(json);
|
|
688
|
+
expect(fromJson.properties.find(p => p.name === 'node')?.polymorphic).toBe(true);
|
|
689
|
+
expect(fromJson.properties.find(p => p.name === 'plain')?.polymorphic).toBeUndefined();
|
|
690
|
+
});
|
|
691
|
+
|
|
671
692
|
it('emits and parses targetClassName', () => {
|
|
672
693
|
const shape = new SHACLShape('ns://Recipe');
|
|
673
694
|
shape.addProperty({
|
package/src/shacl/SHACLShape.ts
CHANGED
|
@@ -235,6 +235,11 @@ export interface SHACLPropertyShape {
|
|
|
235
235
|
* and default max-count. */
|
|
236
236
|
relationKind?: 'hasMany' | 'hasOne' | 'belongsToOne' | 'belongsToMany';
|
|
237
237
|
|
|
238
|
+
/** AD4M-specific: the relation is read `polymorphic: true` unless the query
|
|
239
|
+
* says otherwise (`ad4m://polymorphic`). Carried in the shape so the executor
|
|
240
|
+
* applies it at every include depth, below a polymorphic include too. */
|
|
241
|
+
polymorphic?: boolean;
|
|
242
|
+
|
|
238
243
|
/** AD4M-specific: target class name (local-name) for a relation property.
|
|
239
244
|
* Complements `class` (the SHACL node-shape URI) by providing the bare
|
|
240
245
|
* model class name used by the executor to look up the target shape
|
|
@@ -682,6 +687,14 @@ export class SHACLShape {
|
|
|
682
687
|
});
|
|
683
688
|
}
|
|
684
689
|
|
|
690
|
+
if (prop.polymorphic) {
|
|
691
|
+
links.push({
|
|
692
|
+
source: propShapeId,
|
|
693
|
+
predicate: "ad4m://polymorphic",
|
|
694
|
+
target: `literal:${prop.polymorphic}`
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
|
|
685
698
|
if (prop.targetClassName) {
|
|
686
699
|
links.push({
|
|
687
700
|
source: propShapeId,
|
|
@@ -827,6 +840,7 @@ export class SHACLShape {
|
|
|
827
840
|
in: json(id, "sh://in"),
|
|
828
841
|
relationKind: ['hasMany', 'hasOne', 'belongsToOne', 'belongsToMany'].includes(relationKind!)
|
|
829
842
|
? relationKind as SHACLPropertyShape['relationKind'] : undefined,
|
|
843
|
+
polymorphic: bool(id, "ad4m://polymorphic"),
|
|
830
844
|
targetClassName: str(id, "ad4m://targetClassName"),
|
|
831
845
|
whereFilter: json(id, "ad4m://whereFilter"),
|
|
832
846
|
wherePredicates: json(id, "ad4m://wherePredicates"),
|
|
@@ -877,6 +891,7 @@ export class SHACLShape {
|
|
|
877
891
|
class: p.class,
|
|
878
892
|
in: p.in,
|
|
879
893
|
relation_kind: p.relationKind,
|
|
894
|
+
polymorphic: p.polymorphic,
|
|
880
895
|
collection: p.collection ?? (isCollection(p) || undefined),
|
|
881
896
|
target_class_name: p.targetClassName,
|
|
882
897
|
where_filter: p.whereFilter,
|
|
@@ -936,6 +951,7 @@ export class SHACLShape {
|
|
|
936
951
|
class: p.class,
|
|
937
952
|
in: p.in,
|
|
938
953
|
relationKind: p.relation_kind,
|
|
954
|
+
polymorphic: p.polymorphic,
|
|
939
955
|
collection: p.collection,
|
|
940
956
|
targetClassName: p.target_class_name,
|
|
941
957
|
whereFilter: p.where_filter,
|