capns 0.77.17595 → 0.83.18915

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/README.md CHANGED
@@ -65,7 +65,6 @@ console.log(best.toString()); // Most specific match
65
65
  - `withTag(key, value)` - Add/update tag (returns new instance)
66
66
  - `withoutTag(key)` - Remove tag (returns new instance)
67
67
  - `accepts(request)` - Check if this cap (as pattern) accepts a request
68
- - `canHandle(request)` - Check if this cap can handle a request
69
68
  - `specificity()` - Get specificity score for matching
70
69
  - `isMoreSpecificThan(other)` - Compare specificity
71
70
  - `equals(other)` - Check equality
package/capns.js CHANGED
@@ -444,69 +444,9 @@ class CapUrn {
444
444
  return true;
445
445
  }
446
446
 
447
- // First check if they're compatible
448
- if (!this.isCompatibleWith(other)) {
449
- return false;
450
- }
451
-
452
447
  return this.specificity() > other.specificity();
453
448
  }
454
449
 
455
- /**
456
- * Check if this cap is compatible with another
457
- *
458
- * Two caps are compatible if they can potentially match
459
- * the same types of requests (considering wildcards and missing tags as wildcards)
460
- * Direction specs are compatible if either is a subtype of the other via TaggedUrn matching
461
- *
462
- * @param {CapUrn} other - The other cap to check compatibility with
463
- * @returns {boolean} Whether the caps are compatible
464
- */
465
- isCompatibleWith(other) {
466
- if (!other) {
467
- return true;
468
- }
469
-
470
- // Check in_urn compatibility: either direction of conformsTo succeeds
471
- if (this.inSpec !== '*' && other.inSpec !== '*') {
472
- const selfIn = TaggedUrn.fromString(this.inSpec);
473
- const otherIn = TaggedUrn.fromString(other.inSpec);
474
- const fwd = selfIn.conformsTo(otherIn);
475
- const rev = otherIn.conformsTo(selfIn);
476
- if (!fwd && !rev) {
477
- return false;
478
- }
479
- }
480
- // Check out_urn compatibility
481
- if (this.outSpec !== '*' && other.outSpec !== '*') {
482
- const selfOut = TaggedUrn.fromString(this.outSpec);
483
- const otherOut = TaggedUrn.fromString(other.outSpec);
484
- const fwd = selfOut.conformsTo(otherOut);
485
- const rev = otherOut.conformsTo(selfOut);
486
- if (!fwd && !rev) {
487
- return false;
488
- }
489
- }
490
-
491
- // Get all unique tag keys from both caps
492
- const allKeys = new Set([...Object.keys(this.tags), ...Object.keys(other.tags)]);
493
-
494
- for (const key of allKeys) {
495
- const v1 = this.tags[key];
496
- const v2 = other.tags[key];
497
-
498
- if (v1 !== undefined && v2 !== undefined) {
499
- // Both have the tag - they must match or one must be wildcard
500
- if (v1 !== '*' && v2 !== '*' && v1 !== v2) {
501
- return false;
502
- }
503
- }
504
- // If only one has the tag, it's compatible (missing tag is wildcard)
505
- }
506
-
507
- return true;
508
- }
509
-
510
450
  /**
511
451
  * Create a new cap with a specific tag set to wildcard
512
452
  * Handles "in" and "out" specially
@@ -741,7 +681,7 @@ class CapMatcher {
741
681
  static areCompatible(caps1, caps2) {
742
682
  for (const c1 of caps1) {
743
683
  for (const c2 of caps2) {
744
- if (c1.isCompatibleWith(c2)) {
684
+ if (c1.accepts(c2) || c2.accepts(c1)) {
745
685
  return true;
746
686
  }
747
687
  }
@@ -828,6 +768,14 @@ const MEDIA_PATH_OUTPUT = 'media:model-path;textable;form=map';
828
768
  const MEDIA_EMBEDDING_VECTOR = 'media:embedding-vector;textable;form=map';
829
769
  const MEDIA_LLM_INFERENCE_OUTPUT = 'media:generated-text;textable;form=map';
830
770
 
771
+ // =============================================================================
772
+ // STANDARD CAP URN CONSTANTS
773
+ // =============================================================================
774
+
775
+ // Standard echo capability URN
776
+ // Accepts any media type as input and outputs any media type
777
+ const CAP_IDENTITY = 'cap:in=media:;out=media:';
778
+
831
779
  // =============================================================================
832
780
  // MEDIA URN CLASS
833
781
  // =============================================================================
package/capns.test.js CHANGED
@@ -401,22 +401,24 @@ function test023_builderPreservesCase() {
401
401
  assertEqual(cap.getTag('MyKey'), 'MyValue', 'getTag should be case-insensitive for keys');
402
402
  }
403
403
 
404
- // TEST024: isCompatibleWith checks, missing tags = wildcards
404
+ // TEST024: Directional accepts checks
405
405
  function test024_compatibility() {
406
+ // General cap accepts specific request (missing tags = wildcards)
407
+ const general = CapUrn.fromString(testUrn('op=generate'));
408
+ const specific = CapUrn.fromString(testUrn('op=generate;ext=pdf'));
409
+ assert(general.accepts(specific), 'General cap should accept specific request');
410
+ // Specific cap also accepts general request (cap has extra tag, not blocking)
411
+ assert(specific.accepts(general), 'Specific cap accepts general request (extra tags ok)');
412
+
413
+ // Different op values: neither accepts the other
406
414
  const cap1 = CapUrn.fromString(testUrn('op=generate;ext=pdf'));
407
- const cap2 = CapUrn.fromString(testUrn('op=generate;format=*'));
408
415
  const cap3 = CapUrn.fromString(testUrn('type=image;op=extract'));
416
+ assert(!cap1.accepts(cap3), 'Different op should not accept');
417
+ assert(!cap3.accepts(cap1), 'Different op should not accept (reverse)');
409
418
 
410
- assert(cap1.isCompatibleWith(cap2), 'Same op should be compatible');
411
- assert(!cap1.isCompatibleWith(cap3), 'Different op should not be compatible');
412
-
413
- // Missing tags treated as wildcards
414
- const cap4 = CapUrn.fromString(testUrn('op=generate'));
415
- assert(cap1.isCompatibleWith(cap4), 'Missing ext in cap4 should be wildcard');
416
-
417
- // Different in/out should not be compatible
419
+ // Different in/out should not accept
418
420
  const cap5 = CapUrn.fromString('cap:in="media:textable;form=scalar";out="media:object";op=generate');
419
- assert(!cap1.isCompatibleWith(cap5), 'Different inSpec should not be compatible');
421
+ assert(!cap1.accepts(cap5), 'Different inSpec should not accept');
420
422
  }
421
423
 
422
424
  // TEST025: CapMatcher.findBestMatch returns most specific
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Bahram Joharshamshiri",
3
3
  "dependencies": {
4
- "tagged-urn": "^0.23.4524"
4
+ "tagged-urn": "^0.26.4740"
5
5
  },
6
6
  "description": "JavaScript implementation of Cap URN (Capability Uniform Resource Names) with strict validation and matching",
7
7
  "engines": {
@@ -27,10 +27,10 @@
27
27
  "repository": {
28
28
  "directory": "capns-js",
29
29
  "type": "git",
30
- "url": "https://github.com/jowharshamshiri/capns-j.git"
30
+ "url": "https://github.com/filegrind/capns-js.git"
31
31
  },
32
32
  "scripts": {
33
33
  "test": "node capns.test.js"
34
34
  },
35
- "version": "0.77.17595"
36
- }
35
+ "version": "0.83.18915"
36
+ }