@atproto/syntax 0.2.1-next.0 → 0.2.1

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/dist/did.js DELETED
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidDidError = exports.ensureValidDidRegex = exports.ensureValidDid = void 0;
4
- // Human-readable constraints:
5
- // - valid W3C DID (https://www.w3.org/TR/did-core/#did-syntax)
6
- // - entire URI is ASCII: [a-zA-Z0-9._:%-]
7
- // - always starts "did:" (lower-case)
8
- // - method name is one or more lower-case letters, followed by ":"
9
- // - remaining identifier can have any of the above chars, but can not end in ":"
10
- // - it seems that a bunch of ":" can be included, and don't need spaces between
11
- // - "%" is used only for "percent encoding" and must be followed by two hex characters (and thus can't end in "%")
12
- // - query ("?") and fragment ("#") stuff is defined for "DID URIs", but not as part of identifier itself
13
- // - "The current specification does not take a position on the maximum length of a DID"
14
- // - in current atproto, only allowing did:plc and did:web. But not *forcing* this at lexicon layer
15
- // - hard length limit of 8KBytes
16
- // - not going to validate "percent encoding" here
17
- const ensureValidDid = (did) => {
18
- // check that all chars are boring ASCII
19
- if (!/^[a-zA-Z0-9._:%-]*$/.test(did)) {
20
- throw new InvalidDidError('Disallowed characters in DID (ASCII letters, digits, and a couple other characters only)');
21
- }
22
- const parts = did.split(':');
23
- if (parts.length < 3) {
24
- throw new InvalidDidError('DID requires prefix, method, and method-specific content');
25
- }
26
- if (parts[0] != 'did') {
27
- throw new InvalidDidError('DID requires "did:" prefix');
28
- }
29
- if (!/^[a-z]+$/.test(parts[1])) {
30
- throw new InvalidDidError('DID method must be lower-case letters');
31
- }
32
- if (did.endsWith(':') || did.endsWith('%')) {
33
- throw new InvalidDidError('DID can not end with ":" or "%"');
34
- }
35
- if (did.length > 2 * 1024) {
36
- throw new InvalidDidError('DID is too long (2048 chars max)');
37
- }
38
- };
39
- exports.ensureValidDid = ensureValidDid;
40
- const ensureValidDidRegex = (did) => {
41
- // simple regex to enforce most constraints via just regex and length.
42
- // hand wrote this regex based on above constraints
43
- if (!/^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/.test(did)) {
44
- throw new InvalidDidError("DID didn't validate via regex");
45
- }
46
- if (did.length > 2 * 1024) {
47
- throw new InvalidDidError('DID is too long (2048 chars max)');
48
- }
49
- };
50
- exports.ensureValidDidRegex = ensureValidDidRegex;
51
- class InvalidDidError extends Error {
52
- }
53
- exports.InvalidDidError = InvalidDidError;
54
- //# sourceMappingURL=did.js.map
package/dist/did.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"did.js","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,iEAAiE;AACjE,+CAA+C;AAC/C,2CAA2C;AAC3C,wEAAwE;AACxE,sFAAsF;AACtF,qFAAqF;AACrF,wHAAwH;AACxH,8GAA8G;AAC9G,6FAA6F;AAC7F,qGAAqG;AACrG,mCAAmC;AACnC,oDAAoD;AAC7C,MAAM,cAAc,GAAG,CAAC,GAAW,EAAQ,EAAE;IAClD,wCAAwC;IACxC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,eAAe,CACvB,0FAA0F,CAC3F,CAAA;IACH,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,eAAe,CACvB,0DAA0D,CAC3D,CAAA;IACH,CAAC;IAED,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,IAAI,eAAe,CAAC,4BAA4B,CAAC,CAAA;IACzD,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC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9D,CAAA;AAED,eAAO,MAAM,aAAa,WAAY,MAAM,KAAG,OAW9C,CAAA;AAED,eAAO,MAAM,UAAU,WAAY,MAAM,KAAG,OAE3C,CAAA;AAED,qBAAa,kBAAmB,SAAQ,KAAK;CAAG;AAChD,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AACjD,qBAAa,sBAAuB,SAAQ,KAAK;CAAG;AACpD,qBAAa,qBAAsB,SAAQ,KAAK;CAAG"}
package/dist/handle.js DELETED
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DisallowedDomainError = exports.UnsupportedDomainError = exports.ReservedHandleError = exports.InvalidHandleError = exports.isValidTld = exports.isValidHandle = exports.normalizeAndEnsureValidHandle = exports.normalizeHandle = exports.ensureValidHandleRegex = exports.ensureValidHandle = exports.DISALLOWED_TLDS = exports.INVALID_HANDLE = void 0;
4
- exports.INVALID_HANDLE = 'handle.invalid';
5
- // Currently these are registration-time restrictions, not protocol-level
6
- // restrictions. We have a couple accounts in the wild that we need to clean up
7
- // before hard-disallow.
8
- // See also: https://en.wikipedia.org/wiki/Top-level_domain#Reserved_domains
9
- exports.DISALLOWED_TLDS = [
10
- '.local',
11
- '.arpa',
12
- '.invalid',
13
- '.localhost',
14
- '.internal',
15
- '.example',
16
- '.alt',
17
- // policy could concievably change on ".onion" some day
18
- '.onion',
19
- // NOTE: .test is allowed in testing and devopment. In practical terms
20
- // "should" "never" actually resolve and get registered in production
21
- ];
22
- // Handle constraints, in English:
23
- // - must be a possible domain name
24
- // - RFC-1035 is commonly referenced, but has been updated. eg, RFC-3696,
25
- // section 2. and RFC-3986, section 3. can now have leading numbers (eg,
26
- // 4chan.org)
27
- // - "labels" (sub-names) are made of ASCII letters, digits, hyphens
28
- // - can not start or end with a hyphen
29
- // - TLD (last component) should not start with a digit
30
- // - can't end with a hyphen (can end with digit)
31
- // - each segment must be between 1 and 63 characters (not including any periods)
32
- // - overall length can't be more than 253 characters
33
- // - separated by (ASCII) periods; does not start or end with period
34
- // - case insensitive
35
- // - domains (handles) are equal if they are the same lower-case
36
- // - punycode allowed for internationalization
37
- // - no whitespace, null bytes, joining chars, etc
38
- // - does not validate whether domain or TLD exists, or is a reserved or
39
- // special TLD (eg, .onion or .local)
40
- // - does not validate punycode
41
- const ensureValidHandle = (handle) => {
42
- // check that all chars are boring ASCII
43
- if (!/^[a-zA-Z0-9.-]*$/.test(handle)) {
44
- throw new InvalidHandleError('Disallowed characters in handle (ASCII letters, digits, dashes, periods only)');
45
- }
46
- if (handle.length > 253) {
47
- throw new InvalidHandleError('Handle is too long (253 chars max)');
48
- }
49
- const labels = handle.split('.');
50
- if (labels.length < 2) {
51
- throw new InvalidHandleError('Handle domain needs at least two parts');
52
- }
53
- for (let i = 0; i < labels.length; i++) {
54
- const l = labels[i];
55
- if (l.length < 1) {
56
- throw new InvalidHandleError('Handle parts can not be empty');
57
- }
58
- if (l.length > 63) {
59
- throw new InvalidHandleError('Handle part too long (max 63 chars)');
60
- }
61
- if (l.endsWith('-') || l.startsWith('-')) {
62
- throw new InvalidHandleError('Handle parts can not start or end with hyphens');
63
- }
64
- if (i + 1 == labels.length && !/^[a-zA-Z]/.test(l)) {
65
- throw new InvalidHandleError('Handle final component (TLD) must start with ASCII letter');
66
- }
67
- }
68
- };
69
- exports.ensureValidHandle = ensureValidHandle;
70
- // simple regex translation of above constraints
71
- const ensureValidHandleRegex = (handle) => {
72
- if (!/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/.test(handle)) {
73
- throw new InvalidHandleError("Handle didn't validate via regex");
74
- }
75
- if (handle.length > 253) {
76
- throw new InvalidHandleError('Handle is too long (253 chars max)');
77
- }
78
- };
79
- exports.ensureValidHandleRegex = ensureValidHandleRegex;
80
- const normalizeHandle = (handle) => {
81
- return handle.toLowerCase();
82
- };
83
- exports.normalizeHandle = normalizeHandle;
84
- const normalizeAndEnsureValidHandle = (handle) => {
85
- const normalized = (0, exports.normalizeHandle)(handle);
86
- (0, exports.ensureValidHandle)(normalized);
87
- return normalized;
88
- };
89
- exports.normalizeAndEnsureValidHandle = normalizeAndEnsureValidHandle;
90
- const isValidHandle = (handle) => {
91
- try {
92
- (0, exports.ensureValidHandle)(handle);
93
- }
94
- catch (err) {
95
- if (err instanceof InvalidHandleError) {
96
- return false;
97
- }
98
- throw err;
99
- }
100
- return true;
101
- };
102
- exports.isValidHandle = isValidHandle;
103
- const isValidTld = (handle) => {
104
- return !exports.DISALLOWED_TLDS.some((domain) => handle.endsWith(domain));
105
- };
106
- exports.isValidTld = isValidTld;
107
- class InvalidHandleError extends Error {
108
- }
109
- exports.InvalidHandleError = InvalidHandleError;
110
- class ReservedHandleError extends Error {
111
- }
112
- exports.ReservedHandleError = ReservedHandleError;
113
- class UnsupportedDomainError extends Error {
114
- }
115
- exports.UnsupportedDomainError = UnsupportedDomainError;
116
- class DisallowedDomainError extends Error {
117
- }
118
- exports.DisallowedDomainError = DisallowedDomainError;
119
- //# sourceMappingURL=handle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,gBAAgB,CAAA;AAE9C,yEAAyE;AACzE,+EAA+E;AAC/E,wBAAwB;AACxB,4EAA4E;AAC/D,QAAA,eAAe,GAAG;IAC7B,QAAQ;IACR,OAAO;IACP,UAAU;IACV,YAAY;IACZ,WAAW;IACX,UAAU;IACV,MAAM;IACN,uDAAuD;IACvD,QAAQ;IACR,sEAAsE;IACtE,qEAAqE;CACtE,CAAA;AAED,kCAAkC;AAClC,oCAAoC;AACpC,4EAA4E;AAC5E,6EAA6E;AAC7E,kBAAkB;AAClB,uEAAuE;AACvE,0CAA0C;AAC1C,0DAA0D;AAC1D,oDAAoD;AACpD,oFAAoF;AACpF,wDAAwD;AACxD,uEAAuE;AACvE,w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AU,GAAG,CAAC,MAAc,EAAW,EAAE;IACpD,OAAO,CAAC,uBAAe,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;AACnE,CAAC,CAAA;AAFY,QAAA,UAAU,cAEtB;AAED,MAAa,kBAAmB,SAAQ,KAAK;CAAG;AAAhD,gDAAgD;AAChD,MAAa,mBAAoB,SAAQ,KAAK;CAAG;AAAjD,kDAAiD;AACjD,MAAa,sBAAuB,SAAQ,KAAK;CAAG;AAApD,wDAAoD;AACpD,MAAa,qBAAsB,SAAQ,KAAK;CAAG;AAAnD,sDAAmD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"nsid.d.ts","sourceRoot":"","sources":["../src/nsid.ts"],"names":[],"mappings":"AAaA,qBAAa,IAAI;IACf,QAAQ,EAAE,MAAM,EAAE,CAAK;IAEvB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIhC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAKpD,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;gBASzB,IAAI,EAAE,MAAM;IAKxB,IAAI,SAAS,WAKZ;IAED,IAAI,IAAI,uBAEP;IAED,QAAQ;CAGT;AAKD,eAAO,MAAM,eAAe,SAAU,MAAM,KAAG,IAmC9C,CAAA;AAED,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,IAanD,CAAA;AAED,qBAAa,gBAAiB,SAAQ,KAAK;CAAG"}
package/dist/nsid.js DELETED
@@ -1,107 +0,0 @@
1
- "use strict";
2
- /*
3
- Grammar:
4
-
5
- alpha = "a" / "b" / "c" / "d" / "e" / "f" / "g" / "h" / "i" / "j" / "k" / "l" / "m" / "n" / "o" / "p" / "q" / "r" / "s" / "t" / "u" / "v" / "w" / "x" / "y" / "z" / "A" / "B" / "C" / "D" / "E" / "F" / "G" / "H" / "I" / "J" / "K" / "L" / "M" / "N" / "O" / "P" / "Q" / "R" / "S" / "T" / "U" / "V" / "W" / "X" / "Y" / "Z"
6
- number = "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" / "0"
7
- delim = "."
8
- segment = alpha *( alpha / number / "-" )
9
- authority = segment *( delim segment )
10
- name = alpha *( alpha )
11
- nsid = authority delim name
12
-
13
- */
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.InvalidNsidError = exports.ensureValidNsidRegex = exports.ensureValidNsid = exports.NSID = void 0;
16
- class NSID {
17
- static parse(nsid) {
18
- return new NSID(nsid);
19
- }
20
- static create(authority, name) {
21
- const segments = [...authority.split('.').reverse(), name].join('.');
22
- return new NSID(segments);
23
- }
24
- static isValid(nsid) {
25
- try {
26
- NSID.parse(nsid);
27
- return true;
28
- }
29
- catch (e) {
30
- return false;
31
- }
32
- }
33
- constructor(nsid) {
34
- Object.defineProperty(this, "segments", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: []
39
- });
40
- (0, exports.ensureValidNsid)(nsid);
41
- this.segments = nsid.split('.');
42
- }
43
- get authority() {
44
- return this.segments
45
- .slice(0, this.segments.length - 1)
46
- .reverse()
47
- .join('.');
48
- }
49
- get name() {
50
- return this.segments.at(this.segments.length - 1);
51
- }
52
- toString() {
53
- return this.segments.join('.');
54
- }
55
- }
56
- exports.NSID = NSID;
57
- // Human readable constraints on NSID:
58
- // - a valid domain in reversed notation
59
- // - followed by an additional period-separated name, which is camel-case letters
60
- const ensureValidNsid = (nsid) => {
61
- const toCheck = nsid;
62
- // check that all chars are boring ASCII
63
- if (!/^[a-zA-Z0-9.-]*$/.test(toCheck)) {
64
- throw new InvalidNsidError('Disallowed characters in NSID (ASCII letters, digits, dashes, periods only)');
65
- }
66
- if (toCheck.length > 253 + 1 + 63) {
67
- throw new InvalidNsidError('NSID is too long (317 chars max)');
68
- }
69
- const labels = toCheck.split('.');
70
- if (labels.length < 3) {
71
- throw new InvalidNsidError('NSID needs at least three parts');
72
- }
73
- for (let i = 0; i < labels.length; i++) {
74
- const l = labels[i];
75
- if (l.length < 1) {
76
- throw new InvalidNsidError('NSID parts can not be empty');
77
- }
78
- if (l.length > 63) {
79
- throw new InvalidNsidError('NSID part too long (max 63 chars)');
80
- }
81
- if (l.endsWith('-') || l.startsWith('-')) {
82
- throw new InvalidNsidError('NSID parts can not start or end with hyphen');
83
- }
84
- if (/^[0-9]/.test(l) && i == 0) {
85
- throw new InvalidNsidError('NSID first part may not start with a digit');
86
- }
87
- if (!/^[a-zA-Z]+$/.test(l) && i + 1 == labels.length) {
88
- throw new InvalidNsidError('NSID name part must be only letters');
89
- }
90
- }
91
- };
92
- exports.ensureValidNsid = ensureValidNsid;
93
- const ensureValidNsidRegex = (nsid) => {
94
- // simple regex to enforce most constraints via just regex and length.
95
- // hand wrote this regex based on above constraints
96
- if (!/^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\.[a-zA-Z]([a-zA-Z]{0,61}[a-zA-Z])?)$/.test(nsid)) {
97
- throw new InvalidNsidError("NSID didn't validate via regex");
98
- }
99
- if (nsid.length > 253 + 1 + 63) {
100
- throw new InvalidNsidError('NSID is too long (317 chars max)');
101
- }
102
- };
103
- exports.ensureValidNsidRegex = ensureValidNsidRegex;
104
- class InvalidNsidError extends Error {
105
- }
106
- exports.InvalidNsidError = InvalidNsidError;
107
- //# sourceMappingURL=nsid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AA6C,CAAC,CAAA;QAC3E,CAAC;QACD,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,gBAAgB,CAAC,4CAA4C,CAAC,CAAA;QAC1E,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YACrD,MAAM,IAAI,gBAAgB,CAAC,qCAAqC,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;AACH,CAAC,CAAA;AAnCY,QAAA,eAAe,mBAmC3B;AAEM,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAQ,EAAE;IACzD,sEAAsE;IACtE,mDAAmD;IACnD,IACE,CAAC,iIAAiI,CAAC,IAAI,CACrI,IAAI,CACL,EACD,CAAC;QACD,MAAM,IAAI,gBAAgB,CAAC,gCAAgC,CAAC,CAAA;IAC9D,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC;QAC/B,MAAM,IAAI,gBAAgB,CAAC,kCAAkC,CAAC,CAAA;IAChE,CAAC;AACH,CAAC,CAAA;AAbY,QAAA,oBAAoB,wBAahC;AAED,MAAa,gBAAiB,SAAQ,KAAK;CAAG;AAA9C,4CAA8C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"recordkey.d.ts","sourceRoot":"","sources":["../src/recordkey.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,IAUnD,CAAA;AAED,eAAO,MAAM,gBAAgB,SAAU,MAAM,KAAG,OAW/C,CAAA;AAED,qBAAa,qBAAsB,SAAQ,KAAK;CAAG"}
package/dist/recordkey.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidRecordKeyError = exports.isValidRecordKey = exports.ensureValidRecordKey = void 0;
4
- const ensureValidRecordKey = (rkey) => {
5
- if (rkey.length > 512 || rkey.length < 1) {
6
- throw new InvalidRecordKeyError('record key must be 1 to 512 characters');
7
- }
8
- // simple regex to enforce most constraints via just regex and length.
9
- if (!/^[a-zA-Z0-9_~.:-]{1,512}$/.test(rkey)) {
10
- throw new InvalidRecordKeyError('record key syntax not valid (regex)');
11
- }
12
- if (rkey == '.' || rkey == '..')
13
- throw new InvalidRecordKeyError('record key can not be "." or ".."');
14
- };
15
- exports.ensureValidRecordKey = ensureValidRecordKey;
16
- const isValidRecordKey = (rkey) => {
17
- try {
18
- (0, exports.ensureValidRecordKey)(rkey);
19
- }
20
- catch (err) {
21
- if (err instanceof InvalidRecordKeyError) {
22
- return false;
23
- }
24
- throw err;
25
- }
26
- return true;
27
- };
28
- exports.isValidRecordKey = isValidRecordKey;
29
- class InvalidRecordKeyError extends Error {
30
- }
31
- exports.InvalidRecordKeyError = InvalidRecordKeyError;
32
- //# sourceMappingURL=recordkey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"recordkey.js","sourceRoot":"","sources":["../src/recordkey.ts"],"names":[],"mappings":";;;AAAO,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAQ,EAAE;IACzD,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,qBAAqB,CAAC,wCAAwC,CAAC,CAAA;IAC3E,CAAC;IACD,sEAAsE;IACtE,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,qBAAqB,CAAC,qCAAqC,CAAC,CAAA;IACxE,CAAC;IACD,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI;QAC7B,MAAM,IAAI,qBAAqB,CAAC,mCAAmC,CAAC,CAAA;AACxE,CAAC,CAAA;AAVY,QAAA,oBAAoB,wBAUhC;AAEM,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAW,EAAE;IACxD,IAAI,CAAC;QACH,IAAA,4BAAoB,EAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,qBAAqB,EAAE,CAAC;YACzC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAXY,QAAA,gBAAgB,oBAW5B;AAED,MAAa,qBAAsB,SAAQ,KAAK;CAAG;AAAnD,sDAAmD"}
package/dist/tid.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"tid.d.ts","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,IAQ5C,CAAA;AAED,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,OAWxC,CAAA;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG"}
package/dist/tid.js DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidTidError = exports.isValidTid = exports.ensureValidTid = void 0;
4
- const ensureValidTid = (tid) => {
5
- if (tid.length != 13) {
6
- throw new InvalidTidError('TID must be 13 characters');
7
- }
8
- // simple regex to enforce most constraints via just regex and length.
9
- if (!/^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/.test(tid)) {
10
- throw new InvalidTidError('TID syntax not valid (regex)');
11
- }
12
- };
13
- exports.ensureValidTid = ensureValidTid;
14
- const isValidTid = (tid) => {
15
- try {
16
- (0, exports.ensureValidTid)(tid);
17
- }
18
- catch (err) {
19
- if (err instanceof InvalidTidError) {
20
- return false;
21
- }
22
- throw err;
23
- }
24
- return true;
25
- };
26
- exports.isValidTid = isValidTid;
27
- class InvalidTidError extends Error {
28
- }
29
- exports.InvalidTidError = InvalidTidError;
30
- //# sourceMappingURL=tid.js.map
package/dist/tid.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"tid.js","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":";;;AAAO,MAAM,cAAc,GAAG,CAAC,GAAW,EAAQ,EAAE;IAClD,IAAI,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAA;IACxD,CAAC;IACD,sEAAsE;IACtE,IAAI,CAAC,4DAA4D,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,eAAe,CAAC,8BAA8B,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC,CAAA;AARY,QAAA,cAAc,kBAQ1B;AAEM,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE;IACjD,IAAI,CAAC;QACH,IAAA,sBAAc,EAAC,GAAG,CAAC,CAAA;IACrB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,eAAe,EAAE,CAAC;YACnC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,GAAG,CAAA;IACX,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAXY,QAAA,UAAU,cAWtB;AAED,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C"}
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/tests.json",
3
- "compilerOptions": {
4
- "rootDir": "."
5
- },
6
- "include": ["./tests"]
7
- }