@atproto/syntax 0.4.1 → 0.4.2

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/at-identifier.d.ts +5 -0
  3. package/dist/at-identifier.d.ts.map +1 -0
  4. package/dist/at-identifier.js +19 -0
  5. package/dist/at-identifier.js.map +1 -0
  6. package/dist/aturi.d.ts +8 -6
  7. package/dist/aturi.d.ts.map +1 -1
  8. package/dist/aturi.js +36 -45
  9. package/dist/aturi.js.map +1 -1
  10. package/dist/aturi_validation.d.ts +5 -2
  11. package/dist/aturi_validation.d.ts.map +1 -1
  12. package/dist/aturi_validation.js +53 -57
  13. package/dist/aturi_validation.js.map +1 -1
  14. package/dist/datetime.d.ts +11 -4
  15. package/dist/datetime.d.ts.map +1 -1
  16. package/dist/datetime.js +16 -16
  17. package/dist/datetime.js.map +1 -1
  18. package/dist/did.d.ts +3 -2
  19. package/dist/did.d.ts.map +1 -1
  20. package/dist/did.js +8 -8
  21. package/dist/did.js.map +1 -1
  22. package/dist/handle.d.ts +7 -6
  23. package/dist/handle.d.ts.map +1 -1
  24. package/dist/handle.js +28 -31
  25. package/dist/handle.js.map +1 -1
  26. package/dist/index.d.ts +8 -7
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +8 -7
  29. package/dist/index.js.map +1 -1
  30. package/dist/nsid.d.ts +6 -5
  31. package/dist/nsid.d.ts.map +1 -1
  32. package/dist/nsid.js +1 -1
  33. package/dist/nsid.js.map +1 -1
  34. package/dist/recordkey.d.ts +3 -2
  35. package/dist/recordkey.d.ts.map +1 -1
  36. package/dist/recordkey.js +33 -22
  37. package/dist/recordkey.js.map +1 -1
  38. package/dist/tid.d.ts +3 -2
  39. package/dist/tid.d.ts.map +1 -1
  40. package/dist/tid.js +7 -7
  41. package/dist/tid.js.map +1 -1
  42. package/package.json +1 -1
  43. package/src/at-identifier.ts +22 -0
  44. package/src/aturi.ts +59 -46
  45. package/src/aturi_validation.ts +60 -49
  46. package/src/datetime.ts +17 -4
  47. package/src/did.ts +5 -2
  48. package/src/handle.ts +23 -22
  49. package/src/index.ts +8 -7
  50. package/src/nsid.ts +8 -6
  51. package/src/recordkey.ts +40 -17
  52. package/src/tid.ts +4 -2
  53. package/tsconfig.build.json +1 -0
  54. package/tsconfig.build.tsbuildinfo +1 -1
package/dist/did.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,IA8B5C,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,KAAG,IAUjD,CAAA;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG"}
1
+ {"version":3,"file":"did.d.ts","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,OAAO,CAAC,IAAI,MAAM,EAAE,CAAA;AAEvE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,SAAS,CA8BpE;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,SAAS,CAUzE;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG"}
package/dist/did.js CHANGED
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidDidError = exports.ensureValidDidRegex = exports.ensureValidDid = void 0;
4
2
  // Human-readable constraints:
5
3
  // - valid W3C DID (https://www.w3.org/TR/did-core/#did-syntax)
6
4
  // - entire URI is ASCII: [a-zA-Z0-9._:%-]
@@ -14,7 +12,11 @@ exports.InvalidDidError = exports.ensureValidDidRegex = exports.ensureValidDid =
14
12
  // - in current atproto, only allowing did:plc and did:web. But not *forcing* this at lexicon layer
15
13
  // - hard length limit of 8KBytes
16
14
  // - not going to validate "percent encoding" here
17
- const ensureValidDid = (did) => {
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.InvalidDidError = void 0;
17
+ exports.ensureValidDid = ensureValidDid;
18
+ exports.ensureValidDidRegex = ensureValidDidRegex;
19
+ function ensureValidDid(did) {
18
20
  if (!did.startsWith('did:')) {
19
21
  throw new InvalidDidError('DID requires "did:" prefix');
20
22
  }
@@ -35,9 +37,8 @@ const ensureValidDid = (did) => {
35
37
  if (did.length > 2 * 1024) {
36
38
  throw new InvalidDidError('DID is too long (2048 chars max)');
37
39
  }
38
- };
39
- exports.ensureValidDid = ensureValidDid;
40
- const ensureValidDidRegex = (did) => {
40
+ }
41
+ function ensureValidDidRegex(did) {
41
42
  // simple regex to enforce most constraints via just regex and length.
42
43
  // hand wrote this regex based on above constraints
43
44
  if (!/^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/.test(did)) {
@@ -46,8 +47,7 @@ const ensureValidDidRegex = (did) => {
46
47
  if (did.length > 2 * 1024) {
47
48
  throw new InvalidDidError('DID is too long (2048 chars max)');
48
49
  }
49
- };
50
- exports.ensureValidDidRegex = ensureValidDidRegex;
50
+ }
51
51
  class InvalidDidError extends Error {
52
52
  }
53
53
  exports.InvalidDidError = InvalidDidError;
package/dist/did.js.map CHANGED
@@ -1 +1 @@
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,IAAI,CAAC,GAAG,CAAC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IAED,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC;QAC1B,MAAM,IAAI,eAAe,CAAC,kCAAkC,CAAC,CAAA;IAC/D,CAAC;AACH,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,sEAAsE;IACtE,mDAAmD;IACnD,IAAI,CAAC,8CAA8C,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,eAAe,CAAC,+BAA+B,CAAC,CAAA;IAC5D,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC;QAC1B,MAAM,IAAI,eAAe,CAAC,kCAAkC,CAAC,CAAA;IAC/D,CAAC;AACH,CAAC;AAED,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C","sourcesContent":["// Human-readable constraints:\n// - valid W3C DID (https://www.w3.org/TR/did-core/#did-syntax)\n// - entire URI is ASCII: [a-zA-Z0-9._:%-]\n// - always starts \"did:\" (lower-case)\n// - method name is one or more lower-case letters, followed by \":\"\n// - remaining identifier can have any of the above chars, but can not end in \":\"\n// - it seems that a bunch of \":\" can be included, and don't need spaces between\n// - \"%\" is used only for \"percent encoding\" and must be followed by two hex characters (and thus can't end in \"%\")\n// - query (\"?\") and fragment (\"#\") stuff is defined for \"DID URIs\", but not as part of identifier itself\n// - \"The current specification does not take a position on the maximum length of a DID\"\n// - in current atproto, only allowing did:plc and did:web. But not *forcing* this at lexicon layer\n// - hard length limit of 8KBytes\n// - not going to validate \"percent encoding\" here\n\nexport type DidString<M extends string = string> = `did:${M}:${string}`\n\nexport function ensureValidDid(did: string): asserts did is DidString {\n if (!did.startsWith('did:')) {\n throw new InvalidDidError('DID requires \"did:\" prefix')\n }\n\n // check that all chars are boring ASCII\n if (!/^[a-zA-Z0-9._:%-]*$/.test(did)) {\n throw new InvalidDidError(\n 'Disallowed characters in DID (ASCII letters, digits, and a couple other characters only)',\n )\n }\n\n const { length, 1: method } = did.split(':')\n if (length < 3) {\n throw new InvalidDidError(\n 'DID requires prefix, method, and method-specific content',\n )\n }\n\n if (!/^[a-z]+$/.test(method)) {\n throw new InvalidDidError('DID method must be lower-case letters')\n }\n\n if (did.endsWith(':') || did.endsWith('%')) {\n throw new InvalidDidError('DID can not end with \":\" or \"%\"')\n }\n\n if (did.length > 2 * 1024) {\n throw new InvalidDidError('DID is too long (2048 chars max)')\n }\n}\n\nexport function ensureValidDidRegex(did: string): asserts did is DidString {\n // simple regex to enforce most constraints via just regex and length.\n // hand wrote this regex based on above constraints\n if (!/^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/.test(did)) {\n throw new InvalidDidError(\"DID didn't validate via regex\")\n }\n\n if (did.length > 2 * 1024) {\n throw new InvalidDidError('DID is too long (2048 chars max)')\n }\n}\n\nexport class InvalidDidError extends Error {}\n"]}
package/dist/handle.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  export declare const INVALID_HANDLE = "handle.invalid";
2
+ export type HandleString = `${string}.${string}`;
2
3
  export declare const DISALLOWED_TLDS: string[];
3
- export declare const ensureValidHandle: (handle: string) => void;
4
- export declare const ensureValidHandleRegex: (handle: string) => void;
5
- export declare const normalizeHandle: (handle: string) => string;
6
- export declare const normalizeAndEnsureValidHandle: (handle: string) => string;
7
- export declare const isValidHandle: (handle: string) => boolean;
8
- export declare const isValidTld: (handle: string) => boolean;
4
+ export declare function ensureValidHandle(handle: string): asserts handle is HandleString;
5
+ export declare function ensureValidHandleRegex(handle: string): asserts handle is HandleString;
6
+ export declare function normalizeHandle(handle: string): string;
7
+ export declare function normalizeAndEnsureValidHandle(handle: string): HandleString;
8
+ export declare function isValidHandle(handle: string): handle is HandleString;
9
+ export declare function isValidTld(handle: string): boolean;
9
10
  export declare class InvalidHandleError extends Error {
10
11
  }
11
12
  /** @deprecated Never used */
@@ -1 +1 @@
1
- {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/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C,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,YAAY,CAEpE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAOlD;AAED,qBAAa,kBAAmB,SAAQ,KAAK;CAAG;AAChD,6BAA6B;AAC7B,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AACjD,6BAA6B;AAC7B,qBAAa,sBAAuB,SAAQ,KAAK;CAAG;AACpD,6BAA6B;AAC7B,qBAAa,qBAAsB,SAAQ,KAAK;CAAG"}
package/dist/handle.js CHANGED
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
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;
3
+ exports.DisallowedDomainError = exports.UnsupportedDomainError = exports.ReservedHandleError = exports.InvalidHandleError = exports.DISALLOWED_TLDS = exports.INVALID_HANDLE = void 0;
4
+ exports.ensureValidHandle = ensureValidHandle;
5
+ exports.ensureValidHandleRegex = ensureValidHandleRegex;
6
+ exports.normalizeHandle = normalizeHandle;
7
+ exports.normalizeAndEnsureValidHandle = normalizeAndEnsureValidHandle;
8
+ exports.isValidHandle = isValidHandle;
9
+ exports.isValidTld = isValidTld;
4
10
  exports.INVALID_HANDLE = 'handle.invalid';
5
11
  // Currently these are registration-time restrictions, not protocol-level
6
12
  // restrictions. We have a couple accounts in the wild that we need to clean up
@@ -38,7 +44,7 @@ exports.DISALLOWED_TLDS = [
38
44
  // - does not validate whether domain or TLD exists, or is a reserved or
39
45
  // special TLD (eg, .onion or .local)
40
46
  // - does not validate punycode
41
- const ensureValidHandle = (handle) => {
47
+ function ensureValidHandle(handle) {
42
48
  // check that all chars are boring ASCII
43
49
  if (!/^[a-zA-Z0-9.-]*$/.test(handle)) {
44
50
  throw new InvalidHandleError('Disallowed characters in handle (ASCII letters, digits, dashes, periods only)');
@@ -65,45 +71,36 @@ const ensureValidHandle = (handle) => {
65
71
  throw new InvalidHandleError('Handle final component (TLD) must start with ASCII letter');
66
72
  }
67
73
  }
68
- };
69
- exports.ensureValidHandle = ensureValidHandle;
74
+ }
70
75
  // 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
- }
76
+ const HANDLE_REGEX = /^([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])?$/;
77
+ function ensureValidHandleRegex(handle) {
75
78
  if (handle.length > 253) {
76
79
  throw new InvalidHandleError('Handle is too long (253 chars max)');
77
80
  }
78
- };
79
- exports.ensureValidHandleRegex = ensureValidHandleRegex;
80
- const normalizeHandle = (handle) => {
81
+ if (!HANDLE_REGEX.test(handle)) {
82
+ throw new InvalidHandleError("Handle didn't validate via regex");
83
+ }
84
+ }
85
+ function normalizeHandle(handle) {
81
86
  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
+ }
88
+ function normalizeAndEnsureValidHandle(handle) {
89
+ const normalized = normalizeHandle(handle);
90
+ ensureValidHandle(normalized);
87
91
  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) {
92
+ }
93
+ function isValidHandle(handle) {
94
+ return handle.length <= 253 && HANDLE_REGEX.test(handle);
95
+ }
96
+ function isValidTld(handle) {
97
+ for (const tld of exports.DISALLOWED_TLDS) {
98
+ if (handle.endsWith(tld)) {
96
99
  return false;
97
100
  }
98
- throw err;
99
101
  }
100
102
  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;
103
+ }
107
104
  class InvalidHandleError extends Error {
108
105
  }
109
106
  exports.InvalidHandleError = InvalidHandleError;
@@ -1 +1 @@
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,wBAAwB;AACxB,mEAAmE;AACnE,iDAAiD;AACjD,mDAAmD;AACnD,yEAAyE;AACzE,wCAAwC;AACxC,gCAAgC;AACzB,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAQ,EAAE;IACxD,wCAAwC;IACxC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,kBAAkB,CAC1B,+EAA+E,CAChF,CAAA;IACH,CAAC;IA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AAgB,eAAe,CAAC,MAAc;IAC5C,OAAO,MAAM,CAAC,WAAW,EAAE,CAAA;AAC7B,CAAC;AAED,SAAgB,6BAA6B,CAAC,MAAc;IAC1D,MAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;IAC1C,iBAAiB,CAAC,UAAU,CAAC,CAAA;IAC7B,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IAC1C,OAAO,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC1D,CAAC;AAED,SAAgB,UAAU,CAAC,MAAc;IACvC,KAAK,MAAM,GAAG,IAAI,uBAAe,EAAE,CAAC;QAClC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAa,kBAAmB,SAAQ,KAAK;CAAG;AAAhD,gDAAgD;AAChD,6BAA6B;AAC7B,MAAa,mBAAoB,SAAQ,KAAK;CAAG;AAAjD,kDAAiD;AACjD,6BAA6B;AAC7B,MAAa,sBAAuB,SAAQ,KAAK;CAAG;AAApD,wDAAoD;AACpD,6BAA6B;AAC7B,MAAa,qBAAsB,SAAQ,KAAK;CAAG;AAAnD,sDAAmD","sourcesContent":["export const INVALID_HANDLE = 'handle.invalid'\n\nexport type HandleString = `${string}.${string}`\n\n// Currently these are registration-time restrictions, not protocol-level\n// restrictions. We have a couple accounts in the wild that we need to clean up\n// before hard-disallow.\n// See also: https://en.wikipedia.org/wiki/Top-level_domain#Reserved_domains\nexport const DISALLOWED_TLDS = [\n '.local',\n '.arpa',\n '.invalid',\n '.localhost',\n '.internal',\n '.example',\n '.alt',\n // policy could concievably change on \".onion\" some day\n '.onion',\n // NOTE: .test is allowed in testing and devopment. In practical terms\n // \"should\" \"never\" actually resolve and get registered in production\n]\n\n// Handle constraints, in English:\n// - must be a possible domain name\n// - RFC-1035 is commonly referenced, but has been updated. eg, RFC-3696,\n// section 2. and RFC-3986, section 3. can now have leading numbers (eg,\n// 4chan.org)\n// - \"labels\" (sub-names) are made of ASCII letters, digits, hyphens\n// - can not start or end with a hyphen\n// - TLD (last component) should not start with a digit\n// - can't end with a hyphen (can end with digit)\n// - each segment must be between 1 and 63 characters (not including any periods)\n// - overall length can't be more than 253 characters\n// - separated by (ASCII) periods; does not start or end with period\n// - case insensitive\n// - domains (handles) are equal if they are the same lower-case\n// - punycode allowed for internationalization\n// - no whitespace, null bytes, joining chars, etc\n// - does not validate whether domain or TLD exists, or is a reserved or\n// special TLD (eg, .onion or .local)\n// - does not validate punycode\nexport function ensureValidHandle(\n handle: string,\n): asserts handle is HandleString {\n // check that all chars are boring ASCII\n if (!/^[a-zA-Z0-9.-]*$/.test(handle)) {\n throw new InvalidHandleError(\n 'Disallowed characters in handle (ASCII letters, digits, dashes, periods only)',\n )\n }\n\n if (handle.length > 253) {\n throw new InvalidHandleError('Handle is too long (253 chars max)')\n }\n const labels = handle.split('.')\n if (labels.length < 2) {\n throw new InvalidHandleError('Handle domain needs at least two parts')\n }\n for (let i = 0; i < labels.length; i++) {\n const l = labels[i]\n if (l.length < 1) {\n throw new InvalidHandleError('Handle parts can not be empty')\n }\n if (l.length > 63) {\n throw new InvalidHandleError('Handle part too long (max 63 chars)')\n }\n if (l.endsWith('-') || l.startsWith('-')) {\n throw new InvalidHandleError(\n 'Handle parts can not start or end with hyphens',\n )\n }\n if (i + 1 === labels.length && !/^[a-zA-Z]/.test(l)) {\n throw new InvalidHandleError(\n 'Handle final component (TLD) must start with ASCII letter',\n )\n }\n }\n}\n\n// simple regex translation of above constraints\nconst HANDLE_REGEX =\n /^([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])?$/\n\nexport function ensureValidHandleRegex(\n handle: string,\n): asserts handle is HandleString {\n if (handle.length > 253) {\n throw new InvalidHandleError('Handle is too long (253 chars max)')\n }\n if (!HANDLE_REGEX.test(handle)) {\n throw new InvalidHandleError(\"Handle didn't validate via regex\")\n }\n}\n\nexport function normalizeHandle(handle: string): string {\n return handle.toLowerCase()\n}\n\nexport function normalizeAndEnsureValidHandle(handle: string): HandleString {\n const normalized = normalizeHandle(handle)\n ensureValidHandle(normalized)\n return normalized\n}\n\nexport function isValidHandle(handle: string): handle is HandleString {\n return handle.length <= 253 && HANDLE_REGEX.test(handle)\n}\n\nexport function isValidTld(handle: string): boolean {\n for (const tld of DISALLOWED_TLDS) {\n if (handle.endsWith(tld)) {\n return false\n }\n }\n return true\n}\n\nexport class InvalidHandleError extends Error {}\n/** @deprecated Never used */\nexport class ReservedHandleError extends Error {}\n/** @deprecated Never used */\nexport class UnsupportedDomainError extends Error {}\n/** @deprecated Never used */\nexport class DisallowedDomainError extends Error {}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export * from './handle';
2
- export * from './did';
3
- export * from './nsid';
4
- export * from './aturi';
5
- export * from './tid';
6
- export * from './recordkey';
7
- export * from './datetime';
1
+ export * from './handle.js';
2
+ export * from './did.js';
3
+ export * from './nsid.js';
4
+ export * from './aturi.js';
5
+ export * from './at-identifier.js';
6
+ export * from './tid.js';
7
+ export * from './recordkey.js';
8
+ export * from './datetime.js';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA"}
package/dist/index.js CHANGED
@@ -14,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./handle"), exports);
18
- __exportStar(require("./did"), exports);
19
- __exportStar(require("./nsid"), exports);
20
- __exportStar(require("./aturi"), exports);
21
- __exportStar(require("./tid"), exports);
22
- __exportStar(require("./recordkey"), exports);
23
- __exportStar(require("./datetime"), exports);
17
+ __exportStar(require("./handle.js"), exports);
18
+ __exportStar(require("./did.js"), exports);
19
+ __exportStar(require("./nsid.js"), exports);
20
+ __exportStar(require("./aturi.js"), exports);
21
+ __exportStar(require("./at-identifier.js"), exports);
22
+ __exportStar(require("./tid.js"), exports);
23
+ __exportStar(require("./recordkey.js"), exports);
24
+ __exportStar(require("./datetime.js"), exports);
24
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,wCAAqB;AACrB,yCAAsB;AACtB,0CAAuB;AACvB,wCAAqB;AACrB,8CAA2B;AAC3B,6CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,2CAAwB;AACxB,4CAAyB;AACzB,6CAA0B;AAC1B,qDAAkC;AAClC,2CAAwB;AACxB,iDAA8B;AAC9B,gDAA6B","sourcesContent":["export * from './handle.js'\nexport * from './did.js'\nexport * from './nsid.js'\nexport * from './aturi.js'\nexport * from './at-identifier.js'\nexport * from './tid.js'\nexport * from './recordkey.js'\nexport * from './datetime.js'\n"]}
package/dist/nsid.d.ts CHANGED
@@ -1,8 +1,9 @@
1
+ export type NsidString = `${string}.${string}.${string}`;
1
2
  export declare class NSID {
2
3
  readonly segments: readonly string[];
3
4
  static parse(input: string): NSID;
4
5
  static create(authority: string, name: string): NSID;
5
- static isValid(nsid: string): boolean;
6
+ static isValid(nsid: string): nsid is `${string}.${string}.${string}`;
6
7
  static from(input: {
7
8
  toString: () => string;
8
9
  }): NSID;
@@ -11,9 +12,9 @@ export declare class NSID {
11
12
  get name(): string | undefined;
12
13
  toString(): string;
13
14
  }
14
- export declare function ensureValidNsid(nsid: string): void;
15
+ export declare function ensureValidNsid(nsid: string): asserts nsid is NsidString;
15
16
  export declare function parseNsid(nsid: string): string[];
16
- export declare function isValidNsid(nsid: string): boolean;
17
+ export declare function isValidNsid(nsid: string): nsid is NsidString;
17
18
  type ValidateResult<T> = {
18
19
  success: true;
19
20
  value: T;
@@ -27,12 +28,12 @@ export declare function validateNsid(input: string): ValidateResult<string[]>;
27
28
  * {@link parseNsid}/{@link NSID.parse} if you need the parsed segments, or
28
29
  * {@link isValidNsid} if you just want a boolean.
29
30
  */
30
- export declare function ensureValidNsidRegex(nsid: string): void;
31
+ export declare function ensureValidNsidRegex(nsid: string): asserts nsid is NsidString;
31
32
  /**
32
33
  * Regexp based validation that behaves identically to the previous code but
33
34
  * provides less detailed error messages (while being 20% to 50% faster).
34
35
  */
35
- export declare function validateNsidRegex(value: string): ValidateResult<string>;
36
+ export declare function validateNsidRegex(value: string): ValidateResult<NsidString>;
36
37
  export declare class InvalidNsidError extends Error {
37
38
  }
38
39
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"nsid.d.ts","sourceRoot":"","sources":["../src/nsid.ts"],"names":[],"mappings":"AAaA,qBAAa,IAAI;IACf,QAAQ,CA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K;CAAG"}
package/dist/nsid.js CHANGED
@@ -188,7 +188,7 @@ function validateNsidRegex(value) {
188
188
  }
189
189
  return {
190
190
  success: true,
191
- value,
191
+ value: value,
192
192
  };
193
193
  }
194
194
  class InvalidNsidError extends Error {
package/dist/nsid.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"nsid.js","sourceRoot":"","sources":["../src/nsid.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;EAWE;;;AAiDF,0CAGC;AAED,8BAIC;AAED,kCAIC;AASD,oCA0DC;AAiCD,oDAGC;AAMD,8CAuBC;AAlMD,MAAa,IAAI;IAGf,MAAM,CAAC,KAAK,CAAC,KAAa;QACxB,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,SAAiB,EAAE,IAAY;QAC3C,MAAM,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACjE,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,IAAY;QACzB,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,KAAiC;QAC3C,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;YAC1B,sCAAsC;YACtC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,IAAI,CAAE,KAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QAChD,CAAC;QACD,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAChC,CAAC;IAED,YAAY,IAAY;QA1Bf;;;;;WAA2B;QA2BlC,IAAI,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,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC;QAChC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,kCAAkC;SAC5C,CAAA;IACH,CAAC;IAED,IACE,CAAC,sIAAsI,CAAC,IAAI,CAC1I,KAAK,CACN,EACD,CAAC;QACD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,gCAAgC;SAC1C,CAAA;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,KAAmB;KAC3B,CAAA;AACH,CAAC;AAED,MAAa,gBAAiB,SAAQ,KAAK;CAAG;AAA9C,4CAA8C","sourcesContent":["/*\nGrammar:\n\nalpha = \"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\"\nnumber = \"1\" / \"2\" / \"3\" / \"4\" / \"5\" / \"6\" / \"7\" / \"8\" / \"9\" / \"0\"\ndelim = \".\"\nsegment = alpha *( alpha / number / \"-\" )\nauthority = segment *( delim segment )\nname = alpha *( alpha / number )\nnsid = authority delim name\n\n*/\n\nexport type NsidString = `${string}.${string}.${string}`\n\nexport class NSID {\n readonly segments: readonly string[]\n\n static parse(input: string): NSID {\n return new NSID(input)\n }\n\n static create(authority: string, name: string): NSID {\n const input = [...authority.split('.').reverse(), name].join('.')\n return new NSID(input)\n }\n\n static isValid(nsid: string) {\n return isValidNsid(nsid)\n }\n\n static from(input: { toString: () => string }): NSID {\n if (input instanceof NSID) {\n // No need to clone, NSID is immutable\n return input\n }\n if (Array.isArray(input)) {\n return new NSID((input as string[]).join('.'))\n }\n return new NSID(String(input))\n }\n\n constructor(nsid: string) {\n this.segments = parseNsid(nsid)\n }\n\n get authority() {\n return this.segments\n .slice(0, this.segments.length - 1)\n .reverse()\n .join('.')\n }\n\n get name() {\n return this.segments.at(this.segments.length - 1)\n }\n\n toString() {\n return this.segments.join('.')\n }\n}\n\nexport function ensureValidNsid(nsid: string): asserts nsid is NsidString {\n const result = validateNsid(nsid)\n if (!result.success) throw new InvalidNsidError(result.message)\n}\n\nexport function parseNsid(nsid: string): string[] {\n const result = validateNsid(nsid)\n if (!result.success) throw new InvalidNsidError(result.message)\n return result.value\n}\n\nexport function isValidNsid(nsid: string): nsid is NsidString {\n // Since the regex version is more performant for valid NSIDs, we use it when\n // we don't care about error details.\n return validateNsidRegex(nsid).success\n}\n\ntype ValidateResult<T> =\n | { success: true; value: T }\n | { success: false; message: string }\n\n// Human readable constraints on NSID:\n// - a valid domain in reversed notation\n// - followed by an additional period-separated name, which is camel-case letters\nexport function validateNsid(input: string): ValidateResult<string[]> {\n if (input.length > 253 + 1 + 63) {\n return {\n success: false,\n message: 'NSID is too long (317 chars max)',\n }\n }\n if (hasDisallowedCharacters(input)) {\n return {\n success: false,\n message:\n 'Disallowed characters in NSID (ASCII letters, digits, dashes, periods only)',\n }\n }\n const segments = input.split('.')\n if (segments.length < 3) {\n return {\n success: false,\n message: 'NSID needs at least three parts',\n }\n }\n for (const l of segments) {\n if (l.length < 1) {\n return {\n success: false,\n message: 'NSID parts can not be empty',\n }\n }\n if (l.length > 63) {\n return {\n success: false,\n message: 'NSID part too long (max 63 chars)',\n }\n }\n if (startsWithHyphen(l) || endsWithHyphen(l)) {\n return {\n success: false,\n message: 'NSID parts can not start or end with hyphen',\n }\n }\n }\n if (startsWithNumber(segments[0])) {\n return {\n success: false,\n message: 'NSID first part may not start with a digit',\n }\n }\n if (!isValidIdentifier(segments[segments.length - 1])) {\n return {\n success: false,\n message:\n 'NSID name part must be only letters and digits (and no leading digit)',\n }\n }\n return {\n success: true,\n value: segments,\n }\n}\n\nfunction hasDisallowedCharacters(v: string) {\n return !/^[a-zA-Z0-9.-]*$/.test(v)\n}\n\nfunction startsWithNumber(v: string) {\n const charCode = v.charCodeAt(0)\n return charCode >= 48 && charCode <= 57\n}\n\nfunction startsWithHyphen(v: string) {\n return v.charCodeAt(0) === 45 /* - */\n}\n\nfunction endsWithHyphen(v: string) {\n return v.charCodeAt(v.length - 1) === 45 /* - */\n}\n\nfunction isValidIdentifier(v: string) {\n // Note, since we already know that \"v\" only contains [a-zA-Z0-9-], we can\n // simplify the following regex by checking only the first char and presence\n // of \"-\".\n\n // return /^[a-zA-Z][a-zA-Z0-9]*$/.test(v)\n return !startsWithNumber(v) && !v.includes('-')\n}\n\n/**\n * @deprecated Use {@link ensureValidNsid} if you care about error details,\n * {@link parseNsid}/{@link NSID.parse} if you need the parsed segments, or\n * {@link isValidNsid} if you just want a boolean.\n */\nexport function ensureValidNsidRegex(nsid: string): asserts nsid is NsidString {\n const result = validateNsidRegex(nsid)\n if (!result.success) throw new InvalidNsidError(result.message)\n}\n\n/**\n * Regexp based validation that behaves identically to the previous code but\n * provides less detailed error messages (while being 20% to 50% faster).\n */\nexport function validateNsidRegex(value: string): ValidateResult<NsidString> {\n if (value.length > 253 + 1 + 63) {\n return {\n success: false,\n message: 'NSID is too long (317 chars max)',\n }\n }\n\n if (\n !/^[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-Z0-9]{0,62})?)$/.test(\n value,\n )\n ) {\n return {\n success: false,\n message: \"NSID didn't validate via regex\",\n }\n }\n\n return {\n success: true,\n value: value as NsidString,\n }\n}\n\nexport class InvalidNsidError extends Error {}\n"]}
@@ -1,5 +1,6 @@
1
- export declare const ensureValidRecordKey: (rkey: string) => void;
2
- export declare const isValidRecordKey: (rkey: string) => boolean;
1
+ export type RecordKeyString = string;
2
+ export declare function ensureValidRecordKey(rkey: string): asserts rkey is RecordKeyString;
3
+ export declare function isValidRecordKey(rkey: string): rkey is RecordKeyString;
3
4
  export declare class InvalidRecordKeyError extends Error {
4
5
  }
5
6
  //# sourceMappingURL=recordkey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recordkey.d.ts","sourceRoot":"","sources":["../src/recordkey.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,IAUnD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,OAW/C,CAAA;AAED,qBAAa,qBAAsB,SAAQ,KAAK;CAAG"}
1
+ {"version":3,"file":"recordkey.d.ts","sourceRoot":"","sources":["../src/recordkey.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,MAAM,CAAA;AAmBpC,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,IAAI,eAAe,CAgBjC;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAOtE;AAED,qBAAa,qBAAsB,SAAQ,KAAK;CAAG"}
package/dist/recordkey.js CHANGED
@@ -1,31 +1,42 @@
1
1
  "use strict";
2
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)');
3
+ exports.InvalidRecordKeyError = void 0;
4
+ exports.ensureValidRecordKey = ensureValidRecordKey;
5
+ exports.isValidRecordKey = isValidRecordKey;
6
+ const RECORD_KEY_MAX_LENGTH = 512;
7
+ const RECORD_KEY_MIN_LENGTH = 1;
8
+ const RECORD_KEY_INVALID_VALUES = new Set(['.', '..']);
9
+ const RECORD_KEY_REGEX = /^[a-zA-Z0-9_~.:-]{1,512}$/;
10
+ // https://atproto.com/specs/record-key#record-key-syntax
11
+ // Regardless of the type, Record Keys must fulfill some baseline syntax constraints:
12
+ // - restricted to a subset of ASCII characters -- the allowed characters are
13
+ // alphanumeric (A-Za-z0-9), period, dash, underscore, colon, or tilde (.-_:~)
14
+ // - must have at least 1 and at most 512 characters
15
+ // - the specific record key values . and .. are not allowed
16
+ // - must be a permissible part of repository MST path string (the above
17
+ // constraints satisfy this condition)
18
+ // - must be permissible to include in a path component of a URI (following
19
+ // RFC-3986, section 3.3). The above constraints satisfy this condition, by
20
+ // matching the "unreserved" characters allowed in generic URI paths.
21
+ function ensureValidRecordKey(rkey) {
22
+ if (rkey.length > RECORD_KEY_MAX_LENGTH ||
23
+ rkey.length < RECORD_KEY_MIN_LENGTH) {
24
+ throw new InvalidRecordKeyError(`record key must be ${RECORD_KEY_MIN_LENGTH} to ${RECORD_KEY_MAX_LENGTH} characters`);
11
25
  }
12
- if (rkey === '.' || rkey === '..')
26
+ if (RECORD_KEY_INVALID_VALUES.has(rkey)) {
13
27
  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
28
  }
20
- catch (err) {
21
- if (err instanceof InvalidRecordKeyError) {
22
- return false;
23
- }
24
- throw err;
29
+ // simple regex to enforce most constraints via just regex and length.
30
+ if (!RECORD_KEY_REGEX.test(rkey)) {
31
+ throw new InvalidRecordKeyError('record key syntax not valid (regex)');
25
32
  }
26
- return true;
27
- };
28
- exports.isValidRecordKey = isValidRecordKey;
33
+ }
34
+ function isValidRecordKey(rkey) {
35
+ return (rkey.length >= RECORD_KEY_MIN_LENGTH &&
36
+ rkey.length <= RECORD_KEY_MAX_LENGTH &&
37
+ RECORD_KEY_REGEX.test(rkey) &&
38
+ !RECORD_KEY_INVALID_VALUES.has(rkey));
39
+ }
29
40
  class InvalidRecordKeyError extends Error {
30
41
  }
31
42
  exports.InvalidRecordKeyError = InvalidRecordKeyError;
@@ -1 +1 @@
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,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI;QAC/B,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;CAA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CAAC;AAED,MAAa,qBAAsB,SAAQ,KAAK;CAAG;AAAnD,sDAAmD","sourcesContent":["export type RecordKeyString = string\n\nconst RECORD_KEY_MAX_LENGTH = 512\nconst RECORD_KEY_MIN_LENGTH = 1\nconst RECORD_KEY_INVALID_VALUES = new Set(['.', '..'])\nconst RECORD_KEY_REGEX = /^[a-zA-Z0-9_~.:-]{1,512}$/\n\n// https://atproto.com/specs/record-key#record-key-syntax\n// Regardless of the type, Record Keys must fulfill some baseline syntax constraints:\n// - restricted to a subset of ASCII characters -- the allowed characters are\n// alphanumeric (A-Za-z0-9), period, dash, underscore, colon, or tilde (.-_:~)\n// - must have at least 1 and at most 512 characters\n// - the specific record key values . and .. are not allowed\n// - must be a permissible part of repository MST path string (the above\n// constraints satisfy this condition)\n// - must be permissible to include in a path component of a URI (following\n// RFC-3986, section 3.3). The above constraints satisfy this condition, by\n// matching the \"unreserved\" characters allowed in generic URI paths.\n\nexport function ensureValidRecordKey(\n rkey: string,\n): asserts rkey is RecordKeyString {\n if (\n rkey.length > RECORD_KEY_MAX_LENGTH ||\n rkey.length < RECORD_KEY_MIN_LENGTH\n ) {\n throw new InvalidRecordKeyError(\n `record key must be ${RECORD_KEY_MIN_LENGTH} to ${RECORD_KEY_MAX_LENGTH} characters`,\n )\n }\n if (RECORD_KEY_INVALID_VALUES.has(rkey)) {\n throw new InvalidRecordKeyError('record key can not be \".\" or \"..\"')\n }\n // simple regex to enforce most constraints via just regex and length.\n if (!RECORD_KEY_REGEX.test(rkey)) {\n throw new InvalidRecordKeyError('record key syntax not valid (regex)')\n }\n}\n\nexport function isValidRecordKey(rkey: string): rkey is RecordKeyString {\n return (\n rkey.length >= RECORD_KEY_MIN_LENGTH &&\n rkey.length <= RECORD_KEY_MAX_LENGTH &&\n RECORD_KEY_REGEX.test(rkey) &&\n !RECORD_KEY_INVALID_VALUES.has(rkey)\n )\n}\n\nexport class InvalidRecordKeyError extends Error {}\n"]}
package/dist/tid.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export declare const ensureValidTid: (tid: string) => void;
2
- export declare const isValidTid: (tid: string) => boolean;
1
+ export type TidString = string;
2
+ export declare function ensureValidTid(tid: string): asserts tid is TidString;
3
+ export declare function isValidTid(tid: string): tid is TidString;
3
4
  export declare class InvalidTidError extends Error {
4
5
  }
5
6
  //# sourceMappingURL=tid.d.ts.map
package/dist/tid.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tid.d.ts","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,IAQ5C,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAExC,CAAA;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG"}
1
+ {"version":3,"file":"tid.d.ts","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAK9B,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,SAAS,CAQpE;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,SAAS,CAExD;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG"}
package/dist/tid.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidTidError = exports.isValidTid = exports.ensureValidTid = void 0;
3
+ exports.InvalidTidError = void 0;
4
+ exports.ensureValidTid = ensureValidTid;
5
+ exports.isValidTid = isValidTid;
4
6
  const TID_LENGTH = 13;
5
7
  const TID_REGEX = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/;
6
- const ensureValidTid = (tid) => {
8
+ function ensureValidTid(tid) {
7
9
  if (tid.length !== TID_LENGTH) {
8
10
  throw new InvalidTidError(`TID must be ${TID_LENGTH} characters`);
9
11
  }
@@ -11,12 +13,10 @@ const ensureValidTid = (tid) => {
11
13
  if (!TID_REGEX.test(tid)) {
12
14
  throw new InvalidTidError('TID syntax not valid (regex)');
13
15
  }
14
- };
15
- exports.ensureValidTid = ensureValidTid;
16
- const isValidTid = (tid) => {
16
+ }
17
+ function isValidTid(tid) {
17
18
  return tid.length === TID_LENGTH && TID_REGEX.test(tid);
18
- };
19
- exports.isValidTid = isValidTid;
19
+ }
20
20
  class InvalidTidError extends Error {
21
21
  }
22
22
  exports.InvalidTidError = InvalidTidError;
package/dist/tid.js.map CHANGED
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"tid.js","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":";;;AAKA,wCAQC;AAED,gCAEC;AAfD,MAAM,UAAU,GAAG,EAAE,CAAA;AACrB,MAAM,SAAS,GAAG,4DAA4D,CAAA;AAE9E,SAAgB,cAAc,CAAC,GAAW;IACxC,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;AAED,SAAgB,UAAU,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,KAAK,UAAU,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACzD,CAAC;AAED,MAAa,eAAgB,SAAQ,KAAK;CAAG;AAA7C,0CAA6C","sourcesContent":["export type TidString = string\n\nconst TID_LENGTH = 13\nconst TID_REGEX = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/\n\nexport function ensureValidTid(tid: string): asserts tid is TidString {\n if (tid.length !== TID_LENGTH) {\n throw new InvalidTidError(`TID must be ${TID_LENGTH} characters`)\n }\n // simple regex to enforce most constraints via just regex and length.\n if (!TID_REGEX.test(tid)) {\n throw new InvalidTidError('TID syntax not valid (regex)')\n }\n}\n\nexport function isValidTid(tid: string): tid is TidString {\n return tid.length === TID_LENGTH && TID_REGEX.test(tid)\n}\n\nexport class InvalidTidError extends Error {}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/syntax",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "license": "MIT",
5
5
  "description": "Validation for atproto identifiers and formats: DID, handle, NSID, AT URI, etc",
6
6
  "keywords": [
@@ -0,0 +1,22 @@
1
+ import { DidString, ensureValidDidRegex } from './did.js'
2
+ import {
3
+ HandleString,
4
+ InvalidHandleError,
5
+ ensureValidHandleRegex,
6
+ } from './handle.js'
7
+
8
+ export type AtIdentifierString = DidString | HandleString
9
+
10
+ export function ensureValidAtIdentifier(
11
+ input: string,
12
+ ): asserts input is AtIdentifierString {
13
+ try {
14
+ if (input.startsWith('did:')) {
15
+ ensureValidDidRegex(input)
16
+ } else {
17
+ ensureValidHandleRegex(input)
18
+ }
19
+ } catch (cause) {
20
+ throw new InvalidHandleError('Invalid DID or handle', { cause })
21
+ }
22
+ }