pico-engine 1.6.1 → 1.6.4

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.
@@ -2,7 +2,8 @@ ruleset io.picolabs.subscription {
2
2
  meta {
3
3
  name "subscription "
4
4
  description <<
5
- Tx/Rx ruleset.
5
+ Pico-to-pico relationships (Tx/Rx). User-facing term: relationship.
6
+ Ruleset RID io.picolabs.subscription is stable; prefer module alias relationship.
6
7
  >>
7
8
  author "Tedrub Modulus"
8
9
  use module io.picolabs.wrangler alias wrangler
@@ -25,14 +26,24 @@ ruleset io.picolabs.subscription {
25
26
  "attrs": [ "wellKnown_Tx","password"] },
26
27
  { "domain": "wrangler", "name": "subscription",
27
28
  "attrs": [ "wellKnown_Tx"] },
29
+ { "domain": "wrangler", "name": "relationship",
30
+ "attrs": [ "wellKnown_Tx","Rx_role","Tx_role","name","channel_type","Tx_host","password","layer2","target_did"] },
28
31
  { "domain": "wrangler", "name": "pending_subscription_approval",
29
32
  "attrs": [ "Id" ] },
33
+ { "domain": "wrangler", "name": "pending_relationship_approval",
34
+ "attrs": [ "Id" ] },
30
35
  { "domain": "wrangler", "name": "subscription_cancellation",
31
36
  "attrs": [ "Id" ] },
37
+ { "domain": "wrangler", "name": "relationship_cancellation",
38
+ "attrs": [ "Id" ] },
32
39
  { "domain": "wrangler", "name": "inbound_rejection",
33
40
  "attrs": [ "Id" ] },
41
+ { "domain": "wrangler", "name": "inbound_relationship_rejection",
42
+ "attrs": [ "Id" ] },
34
43
  { "domain": "wrangler", "name": "outbound_cancellation",
35
44
  "attrs": [ "Id" ] },
45
+ { "domain": "wrangler", "name": "outbound_relationship_cancellation",
46
+ "attrs": [ "Id" ] },
36
47
  { "domain": "wrangler", "name": "autoAcceptConfigUpdate",
37
48
  "attrs": [ "configName", "password", "regexMap","delete" ] },
38
49
  { "domain": "wrangler", "name": "intent_to_delete",
@@ -79,6 +90,7 @@ ent:established [
79
90
  wellKnown_eventPolicy = { // we need to restrict what attributes are allowed on this channel, specifically Id.
80
91
  "allow": [
81
92
  {"domain": "wrangler", "name": "subscription"},
93
+ {"domain": "wrangler", "name": "relationship"},
82
94
  {"domain": "wrangler", "name": "new_subscription_request"},
83
95
  {"domain": "wrangler", "name": "inbound_removal"}
84
96
  ],
@@ -231,6 +243,7 @@ ent:established [
231
243
 
232
244
  rule cleanup_subscriptions {
233
245
  select when wrangler rulesets_need_to_cleanup
246
+ or wrangler cleanup_relationships
234
247
  always {
235
248
  raise wrangler event "cancel_subscriptions" attributes event:attrs
236
249
  }
@@ -310,13 +323,14 @@ ent:established [
310
323
 
311
324
  rule createRxBus {
312
325
  select when wrangler subscription
326
+ or wrangler relationship
313
327
  pre {
314
328
  layer2 = event:attr("layer2") == true
315
329
  channel_name = event:attr("name").defaultsTo(random:word())
316
330
  channel_type = event:attr("channel_type").defaultsTo("Tx_Rx","Tx_Rx channel_type used.")
317
331
  pending_entry = pending_entry().put(["wellKnown_Tx"],event:attr("wellKnown_Tx"))
318
332
  }
319
- if not layer2 && pending_entry{"wellKnown_Tx"} then // check if we have someone to send a request to
333
+ if not layer2 && pending_entry{"wellKnown_Tx"} && pending_entry{"wellKnown_Tx"} != wellKnown_Rx(){"id"} then // check if we have someone to send a request to
320
334
  ctx:newChannel([channel_name,channel_type],allow_all_eventPolicy,allow_all_queryPolicy) setting(channel); // create Rx
321
335
  fired {
322
336
  newBus = pending_entry.put({ "Rx" : channel{"id"} });
@@ -330,11 +344,23 @@ ent:established [
330
344
  raise wrangler event "subscription_request_needed"
331
345
  attributes event:attrs.put(fullNewBus);
332
346
  raise wrangler event "outbound_pending_subscription_added" attributes event:attrs.put(fullNewBus)// API event
347
+ raise wrangler event "outbound_pending_relationship_added" attributes event:attrs.put(fullNewBus)// API event
333
348
  }
334
349
  }//end createMySubscription rule
335
350
 
351
+ rule createRxBusLegacySelfFailure {
352
+ select when wrangler subscription
353
+ or wrangler relationship
354
+ where not event:attr("layer2") == true
355
+ && event:attr("wellKnown_Tx") == wellKnown_Rx(){"id"}
356
+ fired {
357
+ raise wrangler event "self_relationship_failure" attributes event:attrs
358
+ }
359
+ }
360
+
336
361
  rule createRxBusLegacyFailure {
337
362
  select when wrangler subscription
363
+ or wrangler relationship
338
364
  pre {
339
365
  layer2 = event:attr("layer2") == true
340
366
  hasWellKnown = event:attr("wellKnown_Tx")
@@ -347,6 +373,7 @@ ent:established [
347
373
 
348
374
  rule createRxBusLayer2 {
349
375
  select when wrangler subscription
376
+ or wrangler relationship
350
377
  pre {
351
378
  layer2 = event:attr("layer2") == true
352
379
  target_did = event:attr("target_did")
@@ -356,7 +383,7 @@ ent:established [
356
383
  .put(["target_did"], target_did)
357
384
  .put(["layer2"], true)
358
385
  }
359
- if layer2 && target_did then
386
+ if layer2 && target_did && target_did != wrangler:myDid() then
360
387
  ctx:newChannel([channel_name,channel_type],allow_all_eventPolicy,allow_all_queryPolicy) setting(channel)
361
388
  fired {
362
389
  newBus = pending_entry.put({ "Rx" : channel{"id"} })
@@ -368,11 +395,23 @@ ent:established [
368
395
  ent:outbound := outbound().append(fullNewBus)
369
396
  raise wrangler event "subscription_request_needed" attributes event:attrs.put(fullNewBus)
370
397
  raise wrangler event "outbound_pending_subscription_added" attributes event:attrs.put(fullNewBus)
398
+ raise wrangler event "outbound_pending_relationship_added" attributes event:attrs.put(fullNewBus)
399
+ }
400
+ }
401
+
402
+ rule createRxBusLayer2SelfFailure {
403
+ select when wrangler subscription
404
+ or wrangler relationship
405
+ where event:attr("layer2") == true
406
+ && event:attr("target_did") == wrangler:myDid()
407
+ fired {
408
+ raise wrangler event "self_relationship_failure" attributes event:attrs
371
409
  }
372
410
  }
373
411
 
374
412
  rule createRxBusLayer2Failure {
375
413
  select when wrangler subscription
414
+ or wrangler relationship
376
415
  pre {
377
416
  layer2 = event:attr("layer2") == true
378
417
  target_did = event:attr("target_did")
@@ -410,7 +449,7 @@ ent:established [
410
449
  pre {
411
450
  layer2 = event:attr("layer2") == true
412
451
  target = event:attr("target_did")
413
- sent = layer2 && target => dido:sendSkyIntro({
452
+ sent = layer2 && target && target != wrangler:myDid() => dido:sendSkyIntro({
414
453
  "subscriptionId": event:attr("Id"),
415
454
  "targetDid": target,
416
455
  "name": event:attr("name").defaultsTo(event:attr("channel_name")),
@@ -437,6 +476,7 @@ ent:established [
437
476
  fired {
438
477
  ent:inbound := inbound().append(pending_entry)
439
478
  raise wrangler event "inbound_pending_subscription_added" attributes event:attrs
479
+ raise wrangler event "inbound_pending_relationship_added" attributes event:attrs
440
480
  }
441
481
  else {
442
482
  raise wrangler event "no_Tx_did_failure" attributes event:attrs
@@ -458,6 +498,7 @@ ent:established [
458
498
  });
459
499
  ent:inbound := inbound().append( newBus );
460
500
  raise wrangler event "inbound_pending_subscription_added" attributes event:attrs.put(["Rx"], Rx); // API event
501
+ raise wrangler event "inbound_pending_relationship_added" attributes event:attrs.put(["Rx"], Rx); // API event
461
502
  }
462
503
  else {
463
504
  raise wrangler event "no_Tx_failure" attributes event:attrs // API event
@@ -466,6 +507,7 @@ ent:established [
466
507
 
467
508
  rule approveInboundPendingSubscriptionLayer2 {
468
509
  select when wrangler pending_subscription_approval
510
+ or wrangler pending_relationship_approval
469
511
  pre {
470
512
  bus = findBus(inbound())
471
513
  response = bus{"layer2"} == true => dido:sendSkyIntroResponse(bus{"Id"}, bus{"Tx_did"}, {"status": "accepted"}) | null
@@ -473,11 +515,13 @@ ent:established [
473
515
  if bus{"layer2"} == true then noop()
474
516
  fired {
475
517
  raise wrangler event "inbound_pending_subscription_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
518
+ raise wrangler event "inbound_pending_relationship_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
476
519
  }
477
520
  }
478
521
 
479
522
  rule approveInboundPendingSubscription {
480
523
  select when wrangler pending_subscription_approval
524
+ or wrangler pending_relationship_approval
481
525
  pre {
482
526
  bus = findBus(inbound())
483
527
  }
@@ -492,6 +536,7 @@ ent:established [
492
536
  }, bus{"Tx_host"})
493
537
  fired {
494
538
  raise wrangler event "inbound_pending_subscription_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
539
+ raise wrangler event "inbound_pending_relationship_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
495
540
  }
496
541
  }
497
542
 
@@ -511,11 +556,13 @@ ent:established [
511
556
  ent:established := established().append(updated)
512
557
  ent:outbound := buses.splice(index, 1)
513
558
  raise wrangler event "subscription_added" attributes event:attrs.put(["bus"], updated)
559
+ raise wrangler event "relationship_added" attributes event:attrs.put(["bus"], updated)
514
560
  }
515
561
  }
516
562
 
517
563
  rule addOutboundSubscription {
518
564
  select when wrangler outbound_pending_subscription_approved
565
+ or wrangler outbound_pending_relationship_approved
519
566
  pre{
520
567
  outbound = outbound()
521
568
  bus = findBus(outbound).put({"Tx" : event:attr("Tx"),
@@ -530,11 +577,13 @@ ent:established [
530
577
  ent:established := established().append(bus);
531
578
  ent:outbound := outbound.splice(index,1);
532
579
  raise wrangler event "subscription_added" attributes event:attrs.put(["bus"], bus) // API event
580
+ raise wrangler event "relationship_added" attributes event:attrs.put(["bus"], bus) // API event
533
581
  }
534
582
  }
535
583
 
536
584
  rule addInboundSubscription {
537
585
  select when wrangler inbound_pending_subscription_approved
586
+ or wrangler inbound_pending_relationship_approved
538
587
  pre{
539
588
  inbound = inbound()
540
589
  index = indexOfId(inbound,event:attr("Id"))
@@ -546,12 +595,14 @@ ent:established [
546
595
  ent:established := established().append( event:attr("bus") );
547
596
  ent:inbound := inbound.splice(index,1);
548
597
  raise wrangler event "subscription_added" attributes event:attrs // API event
598
+ raise wrangler event "relationship_added" attributes event:attrs // API event
549
599
  }
550
600
  }
551
601
 
552
602
  // Layer 2 (1.6+): provision did:peer + internal Rx identity when bus.layer2 is set.
553
603
  rule establish_layer2_subscription_identity {
554
604
  select when wrangler subscription_added
605
+ or wrangler relationship_added
555
606
  pre {
556
607
  bus = event:attr("bus").defaultsTo({})
557
608
  layer2_identity = bus{"layer2"} == true => dido:establishSubscription(bus) | null
@@ -569,6 +620,7 @@ ent:established [
569
620
 
570
621
  rule cancelEstablishedLayer2 {
571
622
  select when wrangler subscription_cancellation
623
+ or wrangler relationship_cancellation
572
624
  pre {
573
625
  bus = findBus(established())
574
626
  sent = bus{"layer2"} == true => dido:crossPicoEvent(bus{"Id"}, {
@@ -585,6 +637,7 @@ ent:established [
585
637
 
586
638
  rule cancelEstablished {
587
639
  select when wrangler subscription_cancellation
640
+ or wrangler relationship_cancellation
588
641
  pre{
589
642
  bus = findBus(established())
590
643
  Tx_host = bus{"Tx_host"}
@@ -617,11 +670,13 @@ ent:established [
617
670
  fired {
618
671
  ent:established := buses.splice(index,1);
619
672
  raise wrangler event "subscription_removed" attributes event:attrs.put({ "bus" : bus }) // API event
673
+ raise wrangler event "relationship_removed" attributes event:attrs.put({ "bus" : bus }) // API event
620
674
  }
621
675
  }
622
676
 
623
677
  rule cancelInboundLayer2 {
624
678
  select when wrangler inbound_rejection
679
+ or wrangler inbound_relationship_rejection
625
680
  pre {
626
681
  bus = findBus(inbound())
627
682
  sent = bus{"layer2"} == true => dido:crossPicoEvent(bus{"Id"}, {
@@ -638,6 +693,7 @@ ent:established [
638
693
 
639
694
  rule cancelInbound {
640
695
  select when wrangler inbound_rejection
696
+ or wrangler inbound_relationship_rejection
641
697
  pre{
642
698
  bus = findBus(inbound())
643
699
  Tx_host = bus{"Tx_host"}
@@ -668,11 +724,13 @@ ent:established [
668
724
  fired {
669
725
  ent:inbound := buses.splice(index,1);
670
726
  raise wrangler event "inbound_subscription_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
727
+ raise wrangler event "inbound_relationship_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
671
728
  }
672
729
  }
673
730
 
674
731
  rule cancelOutboundLayer2 {
675
732
  select when wrangler outbound_cancellation
733
+ or wrangler outbound_relationship_cancellation
676
734
  pre {
677
735
  bus = findBus(outbound())
678
736
  sent = bus{"layer2"} == true => dido:crossPicoEvent(bus{"Id"}, {
@@ -689,6 +747,7 @@ ent:established [
689
747
 
690
748
  rule cancelOutbound {
691
749
  select when wrangler outbound_cancellation
750
+ or wrangler outbound_relationship_cancellation
692
751
  pre{
693
752
  bus = findBus(outbound())
694
753
  Tx_host = bus{"Tx_host"}
@@ -720,11 +779,13 @@ ent:established [
720
779
  fired {
721
780
  ent:outbound := buses.splice(index,1);
722
781
  raise wrangler event "outbound_subscription_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
782
+ raise wrangler event "outbound_relationship_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
723
783
  }
724
784
  }
725
785
 
726
786
  rule sendEventToSubCheck {
727
787
  select when wrangler send_event_on_subs
788
+ or wrangler send_event_on_relationships
728
789
  pre {
729
790
  subID = event:attr("subID")
730
791
  Tx_role = event:attr("Tx_role")
@@ -744,6 +805,11 @@ ent:established [
744
805
  "domainGiven":event:attr("domain").as("Boolean"),
745
806
  "typeGiven":event:attr("type").as("Boolean"),
746
807
  })
808
+ raise wrangler event "failed_to_send_event_to_relationship" attributes event:attrs.put({
809
+ "foundSubsToSendTo":subs.length() > 0,
810
+ "domainGiven":event:attr("domain").as("Boolean"),
811
+ "typeGiven":event:attr("type").as("Boolean"),
812
+ })
747
813
  }
748
814
  }
749
815
 
@@ -766,6 +832,7 @@ ent:established [
766
832
 
767
833
  rule autoAccept {
768
834
  select when wrangler inbound_pending_subscription_added
835
+ or wrangler inbound_pending_relationship_added
769
836
  pre{
770
837
  /*
771
838
  autoAcceptConfig{
@@ -788,7 +855,9 @@ ent:established [
788
855
  if matches then noop()
789
856
  fired {
790
857
  raise wrangler event "pending_subscription_approval" attributes event:attrs;
858
+ raise wrangler event "pending_relationship_approval" attributes event:attrs;
791
859
  raise wrangler event "auto_accepted_subscription_request" attributes event:attrs; //API event
860
+ raise wrangler event "auto_accepted_relationship_request" attributes event:attrs; //API event
792
861
  }// else ...
793
862
  }
794
863
 
@@ -18,13 +18,13 @@ ruleset io.picolabs.wrangler {
18
18
  channels, createChannel, updateChannel, deleteChannel, //channel
19
19
  discoveryChannel, filterBindingsForCaller, //discovery
20
20
  rulesetConfig, rulesetMeta, installedRIDs, //ruleset
21
- children, parent_eci, name, myself, myDid, publicIntro, establishSubscription, callerDid //pico
21
+ children, parent_eci, name, myself, myDid, publicIntro, establishSubscription, establishRelationship, callerDid //pico
22
22
 
23
23
  shares skyQuery, picoQuery,
24
24
  channels, //channel
25
25
  discoveryChannel, filterBindingsForCaller, //discovery
26
26
  rulesetConfig, rulesetMeta,installedRIDs, //ruleset
27
- children, parent_eci, name, myself, myDid, publicIntro, establishSubscription, callerDid, id //pico
27
+ children, parent_eci, name, myself, myDid, publicIntro, establishSubscription, establishRelationship, callerDid, id //pico
28
28
  }
29
29
  global {
30
30
  __testing = { "queries": [ {"name": "name"},
@@ -340,11 +340,14 @@ ruleset io.picolabs.wrangler {
340
340
  dido:setPublicIntro(enabled)
341
341
  }
342
342
 
343
- /** Layer 2: create did:peer + internal Rx for a subscription bus map. */
343
+ /** Layer 2: create did:peer + internal Rx for a relationship bus map. */
344
344
  establishSubscription = function(bus) {
345
345
  dido:establishSubscription(bus)
346
346
  }
347
347
 
348
+ /** Alias for establishSubscription (preferred name in new rulesets). */
349
+ establishRelationship = establishSubscription
350
+
348
351
  /** did:webvh of the pico that sent the current event (layer2 cross-pico delivery). */
349
352
  callerDid = function() {
350
353
  event:attr("callerDid")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pico-engine",
3
- "version": "1.6.1",
3
+ "version": "1.6.4",
4
4
  "description": "An implementation of the pico-engine targeting node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,6 +54,9 @@
54
54
  "test:layer2-wrangler": "ava reset-cache && ava --serial ./test/layer2Wrangler.ts --timeout=2m",
55
55
  "test:layer2-policy": "ava reset-cache && ava --serial ./test/layer2ChannelPolicy.ts --timeout=2m",
56
56
  "test:cross-engine": "ava reset-cache && ava --serial ./test/crossEngineSubscription.ts --timeout=3m",
57
+ "test:relationship-alias": "ava reset-cache && ava --serial ./test/relationshipAlias.ts --timeout=2m",
58
+ "test:relationship-self": "ava reset-cache && ava --serial ./test/relationshipSelf.ts --timeout=2m",
59
+ "test:relationship-lifecycle": "ava reset-cache && ava --serial ./test/relationshipLifecycle.ts --timeout=2m",
57
60
  "test:epic9": "ava reset-cache && ava --serial ./test/epic9Matrix.ts --timeout=3m"
58
61
  },
59
62
  "dependencies": {
@@ -112,5 +115,5 @@
112
115
  "!test/helpers/**/*"
113
116
  ]
114
117
  },
115
- "gitHead": "239f23e636291da954c9eca31ab2454e07193bfa"
118
+ "gitHead": "b15b28de39f537f722e98d2e14d3cf3c857bb6cb"
116
119
  }
@@ -17,7 +17,7 @@ Find the channel with `wrangler:discoveryChannel()` or `wrangler:channels(["disc
17
17
 
18
18
  ## Integrator flow
19
19
 
20
- 1. Obtain the target pico's discovery channel ECI (via subscription metadata, parent query, etc.).
20
+ 1. Obtain the target pico's discovery channel ECI (via relationship metadata, parent query, etc.).
21
21
  2. Send `discovery capabilities` on that channel.
22
22
  3. Optionally include an **`eci`** attribute — the channel the integrator will use for subsequent queries and events on this pico.
23
23
  4. Collect **`discovery capability`** directives from the event response.
@@ -39,7 +39,7 @@ event:send({
39
39
  }, host) // optional host for remote ECI
40
40
  ```
41
41
 
42
- **DID-based (1.6+) — send by DID** (requires an established DID-based subscription):
42
+ **DID-based (1.6+) — send by DID** (requires an established DID-based relationship):
43
43
 
44
44
  ```krl
45
45
  event:send({
@@ -50,18 +50,20 @@ event:send({
50
50
  })
51
51
  ```
52
52
 
53
- **DID-based — send via established subscription map** (from `subscription:established()` etc.):
53
+ **DID-based — send via established relationship map** (from `relationship:established()` etc.; legacy module name `subscription:established()`):
54
54
 
55
55
  ```krl
56
+ use module io.picolabs.subscription alias relationship
57
+
56
58
  event:send({
57
- "sub": bus, // established subscription map
59
+ "sub": bus, // established relationship (bus) map
58
60
  "domain": "wrangler",
59
61
  "type": "ping",
60
62
  "attrs": {}
61
63
  })
62
64
  ```
63
65
 
64
- When `bus.layer2` is true (DID-based subscription), routing uses `Tx_did` and DIDComm (or verified local dispatch on the same engine). ECI-based subscriptions use `bus.Tx` and optional `bus.Tx_host` as before.
66
+ When `bus.layer2` is true (DID-based relationship), routing uses `Tx_did` and DIDComm (or verified local dispatch on the same engine). ECI-based relationships use `bus.Tx` and optional `bus.Tx_host` as before.
65
67
 
66
68
  ## event:attr
67
69