@atproto/syntax 0.3.2 → 0.3.3
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/CHANGELOG.md +6 -0
- package/dist/tid.d.ts.map +1 -1
- package/dist/tid.js +6 -13
- package/dist/tid.js.map +1 -1
- package/jest.config.js +1 -0
- package/package.json +1 -1
- package/src/tid.ts +7 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atproto/syntax
|
|
2
2
|
|
|
3
|
+
## 0.3.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2999](https://github.com/bluesky-social/atproto/pull/2999) [`c53d943c8`](https://github.com/bluesky-social/atproto/commit/c53d943c8be5b8886254e020970a68c0f745b14c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Improve performance of isValidTid
|
|
8
|
+
|
|
3
9
|
## 0.3.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/tid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tid.d.ts","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tid.d.ts","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,IAQ5C,CAAA;AAED,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,OAExC,CAAA;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG"}
|
package/dist/tid.js
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InvalidTidError = exports.isValidTid = exports.ensureValidTid = void 0;
|
|
4
|
+
const TID_LENGTH = 13;
|
|
5
|
+
const TID_REGEX = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/;
|
|
4
6
|
const ensureValidTid = (tid) => {
|
|
5
|
-
if (tid.length !==
|
|
6
|
-
throw new InvalidTidError(
|
|
7
|
+
if (tid.length !== TID_LENGTH) {
|
|
8
|
+
throw new InvalidTidError(`TID must be ${TID_LENGTH} characters`);
|
|
7
9
|
}
|
|
8
10
|
// simple regex to enforce most constraints via just regex and length.
|
|
9
|
-
if (
|
|
11
|
+
if (!TID_REGEX.test(tid)) {
|
|
10
12
|
throw new InvalidTidError('TID syntax not valid (regex)');
|
|
11
13
|
}
|
|
12
14
|
};
|
|
13
15
|
exports.ensureValidTid = ensureValidTid;
|
|
14
16
|
const isValidTid = (tid) => {
|
|
15
|
-
|
|
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;
|
|
17
|
+
return tid.length === TID_LENGTH && TID_REGEX.test(tid);
|
|
25
18
|
};
|
|
26
19
|
exports.isValidTid = isValidTid;
|
|
27
20
|
class InvalidTidError extends Error {
|
package/dist/tid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tid.js","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"tid.js","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":";;;AAAA,MAAM,UAAU,GAAG,EAAE,CAAA;AACrB,MAAM,SAAS,GAAG,4DAA4D,CAAA;AAEvE,MAAM,cAAc,GAAG,CAAC,GAAW,EAAQ,EAAE;IAClD,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAC9B,MAAM,IAAI,eAAe,CAAC,eAAe,UAAU,aAAa,CAAC,CAAA;IACnE,CAAC;IACD,sEAAsE;IACtE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,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,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACzD,CAAC,CAAA;AAFY,QAAA,UAAU,cAEtB;AAED,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C"}
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
package/src/tid.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
+
const TID_LENGTH = 13
|
|
2
|
+
const TID_REGEX = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/
|
|
3
|
+
|
|
1
4
|
export const ensureValidTid = (tid: string): void => {
|
|
2
|
-
if (tid.length !==
|
|
3
|
-
throw new InvalidTidError(
|
|
5
|
+
if (tid.length !== TID_LENGTH) {
|
|
6
|
+
throw new InvalidTidError(`TID must be ${TID_LENGTH} characters`)
|
|
4
7
|
}
|
|
5
8
|
// simple regex to enforce most constraints via just regex and length.
|
|
6
|
-
if (
|
|
9
|
+
if (!TID_REGEX.test(tid)) {
|
|
7
10
|
throw new InvalidTidError('TID syntax not valid (regex)')
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
export const isValidTid = (tid: string): boolean => {
|
|
12
|
-
|
|
13
|
-
ensureValidTid(tid)
|
|
14
|
-
} catch (err) {
|
|
15
|
-
if (err instanceof InvalidTidError) {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
throw err
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return true
|
|
15
|
+
return tid.length === TID_LENGTH && TID_REGEX.test(tid)
|
|
22
16
|
}
|
|
23
17
|
|
|
24
18
|
export class InvalidTidError extends Error {}
|