capdag 0.158.370 → 0.161.384
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 +5 -5
- package/RULES.md +6 -6
- package/capdag.js +26 -2
- package/capdag.test.js +241 -241
- package/machine.pegjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ npm install capdag
|
|
|
23
23
|
const { CapUrn, CapUrnBuilder, CapMatcher } = require('capdag');
|
|
24
24
|
|
|
25
25
|
// Create from string (with required direction specifiers)
|
|
26
|
-
const cap = CapUrn.fromString('cap:in="media:binary";
|
|
26
|
+
const cap = CapUrn.fromString('cap:in="media:binary";extract;out="media:object"');
|
|
27
27
|
console.log(cap.toString());
|
|
28
28
|
|
|
29
29
|
// Use builder pattern
|
|
@@ -35,14 +35,14 @@ const built = new CapUrnBuilder()
|
|
|
35
35
|
.build();
|
|
36
36
|
|
|
37
37
|
// Matching
|
|
38
|
-
const request = CapUrn.fromString('cap:in="media:binary";
|
|
38
|
+
const request = CapUrn.fromString('cap:in="media:binary";extract;out="media:object"');
|
|
39
39
|
console.log(cap.accepts(request)); // true
|
|
40
40
|
|
|
41
41
|
// Find best match by specificity
|
|
42
42
|
const caps = [
|
|
43
|
-
CapUrn.fromString('cap:in=*;
|
|
44
|
-
CapUrn.fromString('cap:in="media:binary";
|
|
45
|
-
CapUrn.fromString('cap:ext=pdf;in="media:binary";
|
|
43
|
+
CapUrn.fromString('cap:in=*;extract;out=*'),
|
|
44
|
+
CapUrn.fromString('cap:in="media:binary";extract;out="media:object"'),
|
|
45
|
+
CapUrn.fromString('cap:ext=pdf;in="media:binary";extract;out="media:object"')
|
|
46
46
|
];
|
|
47
47
|
const best = CapMatcher.findBestMatch(caps, request);
|
|
48
48
|
console.log(best.toString()); // Most specific match
|
package/RULES.md
CHANGED
|
@@ -14,7 +14,7 @@ Cap URNs **must** include `in` and `out` tags that specify input/output media ty
|
|
|
14
14
|
|
|
15
15
|
```javascript
|
|
16
16
|
// Valid cap URN with direction specifiers
|
|
17
|
-
const cap = CapUrn.fromString('cap:in="media:binary";
|
|
17
|
+
const cap = CapUrn.fromString('cap:in="media:binary";extract;out="media:object"');
|
|
18
18
|
|
|
19
19
|
// Invalid - missing direction specifiers
|
|
20
20
|
CapUrn.fromString('cap:op=extract'); // throws ErrorCodes.MISSING_IN_SPEC
|
|
@@ -26,13 +26,13 @@ Direction specifier values must be valid Media URNs or special pattern values:
|
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
28
|
// Valid: Media URN value
|
|
29
|
-
'cap:in="media:binary";
|
|
29
|
+
'cap:in="media:binary";extract;out="media:object"'
|
|
30
30
|
|
|
31
31
|
// Valid: Must-have-any (any media type)
|
|
32
|
-
'cap:in=*;
|
|
32
|
+
'cap:in=*;extract;out=*'
|
|
33
33
|
|
|
34
34
|
// Invalid: Not a Media URN or special value
|
|
35
|
-
'cap:in=binary;
|
|
35
|
+
'cap:in=binary;extract;out=object' // throws ErrorCodes.INVALID_MEDIA_URN
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
### 3. Matching Semantics
|
|
@@ -59,8 +59,8 @@ Specificity uses graded scoring:
|
|
|
59
59
|
| Unspecified (K=?) or missing | 0 |
|
|
60
60
|
|
|
61
61
|
Examples:
|
|
62
|
-
- `cap:in="media:binary";
|
|
63
|
-
- `cap:in=*;
|
|
62
|
+
- `cap:in="media:binary";extract;out="media:object"` → 3+3+3 = 9
|
|
63
|
+
- `cap:in=*;extract;out=*` → 2+3+2 = 7
|
|
64
64
|
|
|
65
65
|
## Cap-Specific Error Codes
|
|
66
66
|
|
package/capdag.js
CHANGED
|
@@ -922,7 +922,7 @@ const MEDIA_YAML_RECORD = 'media:record;textable;yaml';
|
|
|
922
922
|
const MEDIA_YAML_LIST = 'media:list;textable;yaml';
|
|
923
923
|
const MEDIA_YAML_LIST_RECORD = 'media:list;record;textable;yaml';
|
|
924
924
|
const MEDIA_CSV = 'media:csv;list;record;textable';
|
|
925
|
-
const MEDIA_CSV_LIST = 'media:csv;list;textable';
|
|
925
|
+
const MEDIA_CSV_LIST = 'media:csv;list;record;textable';
|
|
926
926
|
|
|
927
927
|
// File path type — for arguments that represent filesystem paths.
|
|
928
928
|
// There is a single media URN; cardinality (single file vs many files)
|
|
@@ -4646,15 +4646,17 @@ class InstalledCartridgeIdentity {
|
|
|
4646
4646
|
* @param {string} opts.id
|
|
4647
4647
|
* @param {string} opts.version
|
|
4648
4648
|
* @param {string} opts.sha256
|
|
4649
|
+
* @param {Array<Object>} [opts.capGroups=[]] - Cartridge's manifest cap_groups; each element is `{name, caps, adapter_urns}`.
|
|
4649
4650
|
* @param {CartridgeAttachmentError|null} [opts.attachmentError=null]
|
|
4650
4651
|
* @param {CartridgeRuntimeStats|null} [opts.runtimeStats=null]
|
|
4651
4652
|
*/
|
|
4652
|
-
constructor({ registryUrl = null, channel, id, version, sha256, attachmentError = null, runtimeStats = null }) {
|
|
4653
|
+
constructor({ registryUrl = null, channel, id, version, sha256, capGroups = [], attachmentError = null, runtimeStats = null }) {
|
|
4653
4654
|
this.registry_url = registryUrl;
|
|
4654
4655
|
this.channel = channel;
|
|
4655
4656
|
this.id = id;
|
|
4656
4657
|
this.version = version;
|
|
4657
4658
|
this.sha256 = sha256;
|
|
4659
|
+
this.cap_groups = capGroups;
|
|
4658
4660
|
this.attachment_error = attachmentError;
|
|
4659
4661
|
this.runtime_stats = runtimeStats;
|
|
4660
4662
|
}
|
|
@@ -4667,6 +4669,7 @@ class InstalledCartridgeIdentity {
|
|
|
4667
4669
|
sha256: this.sha256,
|
|
4668
4670
|
};
|
|
4669
4671
|
if (this.registry_url !== null) obj.registry_url = this.registry_url;
|
|
4672
|
+
if (this.cap_groups && this.cap_groups.length > 0) obj.cap_groups = this.cap_groups;
|
|
4670
4673
|
if (this.attachment_error !== null) obj.attachment_error = this.attachment_error.toJSON();
|
|
4671
4674
|
if (this.runtime_stats !== null) obj.runtime_stats = this.runtime_stats.toJSON();
|
|
4672
4675
|
return obj;
|
|
@@ -4679,10 +4682,31 @@ class InstalledCartridgeIdentity {
|
|
|
4679
4682
|
id: d.id,
|
|
4680
4683
|
version: d.version,
|
|
4681
4684
|
sha256: d.sha256,
|
|
4685
|
+
capGroups: Array.isArray(d.cap_groups) ? d.cap_groups : [],
|
|
4682
4686
|
attachmentError: d.attachment_error ? CartridgeAttachmentError.fromJSON(d.attachment_error) : null,
|
|
4683
4687
|
runtimeStats: d.runtime_stats ? CartridgeRuntimeStats.fromJSON(d.runtime_stats) : null,
|
|
4684
4688
|
});
|
|
4685
4689
|
}
|
|
4690
|
+
|
|
4691
|
+
/**
|
|
4692
|
+
* Flat de-duplicated cap-URN view across this cartridge's groups,
|
|
4693
|
+
* preserving first-seen order.
|
|
4694
|
+
* @returns {Array<string>}
|
|
4695
|
+
*/
|
|
4696
|
+
capUrns() {
|
|
4697
|
+
const seen = new Set();
|
|
4698
|
+
const out = [];
|
|
4699
|
+
for (const group of this.cap_groups) {
|
|
4700
|
+
const caps = (group && Array.isArray(group.caps)) ? group.caps : [];
|
|
4701
|
+
for (const cap of caps) {
|
|
4702
|
+
const urn = (cap && typeof cap.urn === 'string') ? cap.urn : '';
|
|
4703
|
+
if (!urn || seen.has(urn)) continue;
|
|
4704
|
+
seen.add(urn);
|
|
4705
|
+
out.push(urn);
|
|
4706
|
+
}
|
|
4707
|
+
}
|
|
4708
|
+
return out;
|
|
4709
|
+
}
|
|
4686
4710
|
}
|
|
4687
4711
|
|
|
4688
4712
|
// ============================================================================
|