@atproto/syntax 0.5.1 → 0.5.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atproto/syntax
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4815](https://github.com/bluesky-social/atproto/pull/4815) [`3711454`](https://github.com/bluesky-social/atproto/commit/371145432178b6c8c411f1289c266314cc7ec592) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rewrite of tests
8
+
9
+ ## 0.5.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#4792](https://github.com/bluesky-social/atproto/pull/4792) [`0dbea15`](https://github.com/bluesky-social/atproto/commit/0dbea15da48a6ca913cc3a3a2d8c0ffe64d7c69a) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Make AT-uri validation faster
14
+
15
+ - [#4408](https://github.com/bluesky-social/atproto/pull/4408) [`d0c136c`](https://github.com/bluesky-social/atproto/commit/d0c136cba2ec8fa97017849b1023d5af5d2cc60c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `isHandleIdentifier` and `isDidIdentifier` utilities to discriminate `AtIdentifierString` variants
16
+
17
+ - [#4779](https://github.com/bluesky-social/atproto/pull/4779) [`527f5d4`](https://github.com/bluesky-social/atproto/commit/527f5d4c5d0c9264c2ff6f23ad06a41163fc6809) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove year 10 limit on `DatetimeString` and `AtprotoDate`
18
+
3
19
  ## 0.5.1
4
20
 
5
21
  ### Patch Changes
@@ -108,7 +108,7 @@ function ensureValidAtUriRegex(input) {
108
108
  }
109
109
  function isValidAtUri(input) {
110
110
  try {
111
- ensureValidAtUriRegex(input);
111
+ ensureValidAtUri(input);
112
112
  }
113
113
  catch {
114
114
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"aturi_validation.js","sourceRoot":"","sources":["../src/aturi_validation.ts"],"names":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M,CAAC,SAAS,CAAC,CAAA;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,IAAA,4BAAmB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,IAAI,CAAC,IAAA,qBAAW,EAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAC1C,CAAC;AACH,CAAC;AAED,SAAgB,YAAY,CAC1B,KAAQ;IAER,IAAI,CAAC;QACH,qBAAqB,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { AtIdentifierString, ensureValidAtIdentifier } from './at-identifier.js'\nimport { ensureValidDidRegex } from './did.js'\nimport { ensureValidHandleRegex } from './handle.js'\nimport { NsidString, isValidNsid } from './nsid.js'\n\nexport type AtUriString =\n | `at://${AtIdentifierString}`\n | `at://${AtIdentifierString}/${NsidString}`\n | `at://${AtIdentifierString}/${NsidString}/${string}`\n\n// Human-readable constraints on ATURI:\n// - following regular URLs, a 8KByte hard total length limit\n// - follows ATURI docs on website\n// - all ASCII characters, no whitespace. non-ASCII could be URL-encoded\n// - starts \"at://\"\n// - \"authority\" is a valid DID or a valid handle\n// - optionally, follow \"authority\" with \"/\" and valid NSID as start of path\n// - optionally, if NSID given, follow that with \"/\" and rkey\n// - rkey path component can include URL-encoded (\"percent encoded\"), or:\n// ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\" / \":\" / \"@\" / \"!\" / \"$\" / \"&\" / \"'\" / \"(\" / \")\" / \"*\" / \"+\" / \",\" / \";\" / \"=\"\n// [a-zA-Z0-9._~:@!$&'\\(\\)*+,;=-]\n// - rkey must have at least one char\n// - regardless of path component, a fragment can follow as \"#\" and then a JSON pointer (RFC-6901)\n\nexport function ensureValidAtUri<I extends string>(\n input: I,\n): asserts input is I & AtUriString {\n const fragmentIndex = input.indexOf('#')\n if (fragmentIndex !== -1) {\n if (input.charCodeAt(fragmentIndex + 1) !== 47) {\n throw new Error('ATURI fragment must be non-empty and start with slash')\n }\n if (input.includes('#', fragmentIndex + 1)) {\n throw new Error('ATURI can have at most one \"#\", separating fragment out')\n }\n\n // NOTE: enforcing *some* checks here for sanity. Eg, at least no whitespace\n const fragment = input.slice(fragmentIndex + 1)\n if (!/^\\/[a-zA-Z0-9._~:@!$&')(*+,;=%[\\]/-]*$/.test(fragment)) {\n throw new Error('Disallowed characters in ATURI fragment (ASCII)')\n }\n }\n\n const uri = fragmentIndex === -1 ? input : input.slice(0, fragmentIndex)\n\n if (uri.length > 8 * 1024) {\n throw new Error('ATURI is far too long')\n }\n\n if (!uri.startsWith('at://')) {\n throw new Error('ATURI must start with \"at://\"')\n }\n\n // check that all chars are boring ASCII\n if (!/^[a-zA-Z0-9._~:@!$&')(*+,;=%/-]*$/.test(uri)) {\n throw new Error('Disallowed characters in ATURI (ASCII)')\n }\n\n const authorityEnd = uri.indexOf('/', 5)\n const authority =\n authorityEnd === -1 ? uri.slice(5) : uri.slice(5, authorityEnd)\n try {\n ensureValidAtIdentifier(authority)\n } catch (cause) {\n throw new Error('ATURI authority must be a valid handle or DID', { cause })\n }\n\n const collectionStart = authorityEnd === -1 ? -1 : authorityEnd + 1\n const collectionEnd =\n collectionStart === -1 ? -1 : uri.indexOf('/', collectionStart)\n\n if (collectionStart !== -1) {\n const collection =\n collectionEnd === -1\n ? uri.slice(collectionStart)\n : uri.slice(collectionStart, collectionEnd)\n\n if (collection.length === 0) {\n throw new Error(\n 'ATURI can not have a slash after authority without a path segment',\n )\n }\n if (!isValidNsid(collection)) {\n throw new Error(\n 'ATURI requires first path segment (if supplied) to be valid NSID',\n )\n }\n }\n\n const recordKeyStart = collectionEnd === -1 ? -1 : collectionEnd + 1\n const recordKeyEnd =\n recordKeyStart === -1 ? -1 : uri.indexOf('/', recordKeyStart)\n\n if (recordKeyStart !== -1) {\n if (recordKeyStart === uri.length) {\n throw new Error(\n 'ATURI can not have a slash after collection, unless record key is provided',\n )\n }\n // would validate rkey here, but there are basically no constraints!\n }\n\n if (recordKeyEnd !== -1) {\n throw new Error(\n 'ATURI path can have at most two parts, and no trailing slash',\n )\n }\n}\n\nexport function ensureValidAtUriRegex<I extends string>(\n input: I,\n): asserts input is I & AtUriString {\n // simple regex to enforce most constraints via just regex and length.\n // hand wrote this regex based on above constraints. whew!\n const aturiRegex =\n /^at:\\/\\/(?<authority>[a-zA-Z0-9._:%-]+)(\\/(?<collection>[a-zA-Z0-9-.]+)(\\/(?<rkey>[a-zA-Z0-9._~:@!$&%')(*+,;=-]+))?)?(#(?<fragment>\\/[a-zA-Z0-9._~:@!$&%')(*+,;=\\-[\\]/\\\\]*))?$/\n const rm = input.match(aturiRegex)\n if (!rm || !rm.groups) {\n throw new Error(\"ATURI didn't validate via regex\")\n }\n const groups = rm.groups\n\n try {\n ensureValidHandleRegex(groups.authority)\n } catch {\n try {\n ensureValidDidRegex(groups.authority)\n } catch {\n throw new Error('ATURI authority must be a valid handle or DID')\n }\n }\n\n if (groups.collection && !isValidNsid(groups.collection)) {\n throw new Error('ATURI collection path segment must be a valid NSID')\n }\n\n if (input.length > 8 * 1024) {\n throw new Error('ATURI is far too long')\n }\n}\n\nexport function isValidAtUri<I extends string>(\n input: I,\n): input is I & AtUriString {\n try {\n ensureValidAtUriRegex(input)\n } catch {\n return false\n }\n\n return true\n}\n"]}
1
+ {"version":3,"file":"aturi_validation.js","sourceRoot":"","sources":["../src/aturi_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B,EAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,IAAA,4BAAmB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,IAAI,CAAC,IAAA,qBAAW,EAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACvE,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAC1C,CAAC;AACH,CAAC;AAED,SAAgB,YAAY,CAC1B,KAAQ;IAER,IAAI,CAAC;QACH,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { AtIdentifierString, ensureValidAtIdentifier } from './at-identifier.js'\nimport { ensureValidDidRegex } from './did.js'\nimport { ensureValidHandleRegex } from './handle.js'\nimport { NsidString, isValidNsid } from './nsid.js'\n\nexport type AtUriString =\n | `at://${AtIdentifierString}`\n | `at://${AtIdentifierString}/${NsidString}`\n | `at://${AtIdentifierString}/${NsidString}/${string}`\n\n// Human-readable constraints on ATURI:\n// - following regular URLs, a 8KByte hard total length limit\n// - follows ATURI docs on website\n// - all ASCII characters, no whitespace. non-ASCII could be URL-encoded\n// - starts \"at://\"\n// - \"authority\" is a valid DID or a valid handle\n// - optionally, follow \"authority\" with \"/\" and valid NSID as start of path\n// - optionally, if NSID given, follow that with \"/\" and rkey\n// - rkey path component can include URL-encoded (\"percent encoded\"), or:\n// ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\" / \":\" / \"@\" / \"!\" / \"$\" / \"&\" / \"'\" / \"(\" / \")\" / \"*\" / \"+\" / \",\" / \";\" / \"=\"\n// [a-zA-Z0-9._~:@!$&'\\(\\)*+,;=-]\n// - rkey must have at least one char\n// - regardless of path component, a fragment can follow as \"#\" and then a JSON pointer (RFC-6901)\n\nexport function ensureValidAtUri<I extends string>(\n input: I,\n): asserts input is I & AtUriString {\n const fragmentIndex = input.indexOf('#')\n if (fragmentIndex !== -1) {\n if (input.charCodeAt(fragmentIndex + 1) !== 47) {\n throw new Error('ATURI fragment must be non-empty and start with slash')\n }\n if (input.includes('#', fragmentIndex + 1)) {\n throw new Error('ATURI can have at most one \"#\", separating fragment out')\n }\n\n // NOTE: enforcing *some* checks here for sanity. Eg, at least no whitespace\n const fragment = input.slice(fragmentIndex + 1)\n if (!/^\\/[a-zA-Z0-9._~:@!$&')(*+,;=%[\\]/-]*$/.test(fragment)) {\n throw new Error('Disallowed characters in ATURI fragment (ASCII)')\n }\n }\n\n const uri = fragmentIndex === -1 ? input : input.slice(0, fragmentIndex)\n\n if (uri.length > 8 * 1024) {\n throw new Error('ATURI is far too long')\n }\n\n if (!uri.startsWith('at://')) {\n throw new Error('ATURI must start with \"at://\"')\n }\n\n // check that all chars are boring ASCII\n if (!/^[a-zA-Z0-9._~:@!$&')(*+,;=%/-]*$/.test(uri)) {\n throw new Error('Disallowed characters in ATURI (ASCII)')\n }\n\n const authorityEnd = uri.indexOf('/', 5)\n const authority =\n authorityEnd === -1 ? uri.slice(5) : uri.slice(5, authorityEnd)\n try {\n ensureValidAtIdentifier(authority)\n } catch (cause) {\n throw new Error('ATURI authority must be a valid handle or DID', { cause })\n }\n\n const collectionStart = authorityEnd === -1 ? -1 : authorityEnd + 1\n const collectionEnd =\n collectionStart === -1 ? -1 : uri.indexOf('/', collectionStart)\n\n if (collectionStart !== -1) {\n const collection =\n collectionEnd === -1\n ? uri.slice(collectionStart)\n : uri.slice(collectionStart, collectionEnd)\n\n if (collection.length === 0) {\n throw new Error(\n 'ATURI can not have a slash after authority without a path segment',\n )\n }\n if (!isValidNsid(collection)) {\n throw new Error(\n 'ATURI requires first path segment (if supplied) to be valid NSID',\n )\n }\n }\n\n const recordKeyStart = collectionEnd === -1 ? -1 : collectionEnd + 1\n const recordKeyEnd =\n recordKeyStart === -1 ? -1 : uri.indexOf('/', recordKeyStart)\n\n if (recordKeyStart !== -1) {\n if (recordKeyStart === uri.length) {\n throw new Error(\n 'ATURI can not have a slash after collection, unless record key is provided',\n )\n }\n // would validate rkey here, but there are basically no constraints!\n }\n\n if (recordKeyEnd !== -1) {\n throw new Error(\n 'ATURI path can have at most two parts, and no trailing slash',\n )\n }\n}\n\nexport function ensureValidAtUriRegex<I extends string>(\n input: I,\n): asserts input is I & AtUriString {\n // simple regex to enforce most constraints via just regex and length.\n // hand wrote this regex based on above constraints. whew!\n const aturiRegex =\n /^at:\\/\\/(?<authority>[a-zA-Z0-9._:%-]+)(\\/(?<collection>[a-zA-Z0-9-.]+)(\\/(?<rkey>[a-zA-Z0-9._~:@!$&%')(*+,;=-]+))?)?(#(?<fragment>\\/[a-zA-Z0-9._~:@!$&%')(*+,;=\\-[\\]/\\\\]*))?$/\n const rm = input.match(aturiRegex)\n if (!rm || !rm.groups) {\n throw new Error(\"ATURI didn't validate via regex\")\n }\n const groups = rm.groups\n\n try {\n ensureValidHandleRegex(groups.authority)\n } catch {\n try {\n ensureValidDidRegex(groups.authority)\n } catch {\n throw new Error('ATURI authority must be a valid handle or DID')\n }\n }\n\n if (groups.collection && !isValidNsid(groups.collection)) {\n throw new Error('ATURI collection path segment must be a valid NSID')\n }\n\n if (input.length > 8 * 1024) {\n throw new Error('ATURI is far too long')\n }\n}\n\nexport function isValidAtUri<I extends string>(\n input: I,\n): input is I & AtUriString {\n try {\n ensureValidAtUri(input)\n } catch {\n return false\n }\n\n return true\n}\n"]}
package/dist/datetime.js CHANGED
@@ -226,9 +226,6 @@ function parseDate(date) {
226
226
  if (fullYear > 9999) {
227
227
  return failure('datetime year is too far in the future');
228
228
  }
229
- if (fullYear < 10) {
230
- return failure('datetime so close to year zero not allowed');
231
- }
232
229
  return success(date);
233
230
  }
234
231
  //# sourceMappingURL=datetime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"datetime.js","sourceRoot":"","sources":["../src/datetime.ts"],"names":[],"mappings":";;;AA8BA,8CAKC;AAKD,sCAGC;AAKD,sCAEC;AAKD,sCAEC;AAkCD,oDAOC;AA6GyB,mDAAmB;AApG7C,4CAGC;AAOD,4CAEC;AAyFqB,2CAAe;AAjFrC,4CAIC;AAOD,sDAEC;AAWD,4CAEC;AAeD,8CAkBC;AAWD,0DAMC;AA3MD;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,KAAK;CAAG;AAAlD,oDAAkD;AAsBlD;;GAEG;AACH,SAAgB,iBAAiB,CAAC,IAAU;IAC1C,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,IAAI,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC7C,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACvB,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAA;AAChC,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AAC/C,CAAC;AA2BD;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAClC,KAAQ;IAER,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;IACj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AM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;IAE5B,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,IAAU;IAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;IACtC,4EAA4E;IAC5E,2EAA2E;IAC3E,kDAAkD;IAClD,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,oCAAoC,CAAC,CAAA;IACtD,CAAC;IACD,wEAAwE;IACxE,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO,OAAO,CAAC,wCAAwC,CAAC,CAAA;IAC1D,CAAC;IACD,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC;QACpB,OAAO,OAAO,CAAC,wCAAwC,CAAC,CAAA;IAC1D,CAAC;IACD,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC,4CAA4C,CAAC,CAAA;IAC9D,CAAC;IACD,OAAO,OAAO,CAAC,IAAmB,CAAC,CAAA;AACrC,CAAC","sourcesContent":["/**\n * Indicates a date or string is not a valid representation of a datetime\n * according to the atproto\n * {@link https://atproto.com/specs/lexicon#datetime specification}.\n */\nexport class InvalidDatetimeError extends Error {}\n\n/**\n * A subset of {@link DatetimeString} that represent valid datetime strings with\n * the format: `YYYY-MM-DDTHH:mm:ss.sssZ`, as returned by `Date.toISOString()\n * for dates between the years 0000 and 9999.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString}\n */\nexport type ISODatetimeString =\n // @TODO Switch to branded types for more accurate type safety.\n `${string}-${string}-${string}T${string}:${string}:${string}.${string}Z`\n\n/**\n * Represents a {@link Date} that can be safely stringified into a valid atproto\n * {@link DatetimeString} using the {@link Date.toISOString toISOString()}\n * method.\n */\nexport interface AtprotoDate extends Date {\n toISOString(): ISODatetimeString\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function assertAtprotoDate(date: Date): asserts date is AtprotoDate {\n const res = parseDate(date)\n if (!res.success) {\n throw new InvalidDatetimeError(res.message)\n }\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function asAtprotoDate(date: Date): AtprotoDate {\n assertAtprotoDate(date)\n return date\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function isAtprotoDate(date: Date): date is AtprotoDate {\n return parseDate(date).success\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function ifAtprotoDate(date: Date): AtprotoDate | undefined {\n return isAtprotoDate(date) ? date : undefined\n}\n\n/**\n * Datetime strings in atproto data structures and API calls should meet the\n * {@link https://ijmacd.github.io/rfc3339-iso8601/ intersecting} requirements\n * of the RFC 3339, ISO 8601, and WHATWG HTML datetime standards.\n *\n * @note This literal template type is not accurate enough to ensure that a\n * string is a valid atproto datetime. The {@link DatetimeString} validation\n * functions ({@link assertDatetimeString}, {@link isDatetimeString}, etc)\n * should be used to validate that a string meets the atproto datetime\n * requirements, and the {@link toDatetimeString} function should be used to\n * convert a {@link Date} object into a valid {@link DatetimeString} string.\n *\n * @example \"2024-01-15T12:30:00Z\"\n * @example \"2024-01-15T12:30:00.000Z\"\n * @example \"2024-01-15T12:30:00+00:00\"\n * @example \"2024-01-15T11:30:00-01:00\"\n * @see {@link https://atproto.com/specs/lexicon#datetime atproto Lexicon datetime format}\n * @see {@link https://www.rfc-editor.org/rfc/rfc3339 RFC 3339}\n * @see {@link https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601}\n */\nexport type DatetimeString =\n // @TODO Switch to branded types for more accurate type safety?\n | `${string}-${string}-${string}T${string}:${string}:${string}Z`\n | `${string}-${string}-${string}T${string}:${string}:${string}${'+' | '-'}${string}:${string}`\n\n/**\n * Validates that a string is a valid {@link DatetimeString} format string,\n * throwing an error if it is not.\n *\n * @throws InvalidDatetimeError if the input string does not meet the atproto 'datetime' format requirements.\n * @see {@link DatetimeString}\n */\nexport function assertDatetimeString<I>(\n input: I,\n): asserts input is I & DatetimeString {\n const result = parseString(input)\n if (!result.success) {\n throw new InvalidDatetimeError(result.message)\n }\n}\n\n/**\n * Casts a string to a {@link DatetimeString} if it is a valid datetime format\n * string, throwing an error if it is not.\n *\n * @throws InvalidDatetimeError if the input string does not meet the atproto 'datetime' format requirements.\n * @see {@link DatetimeString}\n */\nexport function asDatetimeString<I>(input: I): I & DatetimeString {\n assertDatetimeString(input)\n return input\n}\n\n/**\n * Checks if a string is a valid {@link DatetimeString} format string.\n *\n * @see {@link DatetimeString}\n */\nexport function isDatetimeString<I>(input: I): input is I & DatetimeString {\n return parseString(input).success\n}\n\n/**\n * Returns the input if it is a valid {@link DatetimeString} format string, or\n * `undefined` if it is not.\n *\n * @see {@link DatetimeString}\n */\nexport function ifDatetimeString<I>(\n input: I,\n): undefined | (I & DatetimeString) {\n return isDatetimeString(input) ? input : undefined\n}\n\n/**\n * Returns the current date and time as a {@link DatetimeString}.\n *\n * @see {@link DatetimeString}\n */\nexport function currentDatetimeString(): DatetimeString {\n return toDatetimeString(new Date())\n}\n\n/**\n * Converts any {@link Date} into a {@link DatetimeString} if possible, throwing\n * an error if the date is not a valid atproto datetime.\n *\n * This is short-hand for `asAtprotoDate(date).toISOString()`.\n *\n * @throws InvalidDatetimeError if the input date is not a valid atproto datetime (eg, it is too far in the future or past, or it normalizes to a negative year).\n * @see {@link DatetimeString}\n */\nexport function toDatetimeString(date: Date): DatetimeString {\n return asAtprotoDate(date).toISOString()\n}\n\n/**\n * Takes a flexible datetime string and normalizes its representation.\n *\n * This function will work with any valid value that can be parsed as a date. It\n * *additionally* is more flexible about accepting datetimes that are missing\n * timezone information, and normalizing them to a valid atproto datetime.\n *\n * One use-case is a consistent, sortable string. Another is to work with older\n * invalid createdAt datetimes.\n *\n * @returns ISODatetimeString - a valid atproto datetime with millisecond precision (3 sub-second digits) and UTC timezone with trailing 'Z' syntax.\n * @throws InvalidDatetimeError - if the input string could not be parsed as a datetime, even with permissive parsing.\n */\nexport function normalizeDatetime(dtStr: string): ISODatetimeString {\n // Parse the string as is\n const date = new Date(dtStr)\n if (isAtprotoDate(date)) {\n return date.toISOString()\n }\n\n // if dtStr is not a valid date, try parsing again with a timezone\n if (isNaN(date.getTime()) && !/.*(([+-]\\d\\d:?\\d\\d)|[a-zA-Z])$/.test(dtStr)) {\n const date = new Date(`${dtStr}Z`)\n if (isAtprotoDate(date)) {\n return date.toISOString()\n }\n }\n\n throw new InvalidDatetimeError(\n 'datetime did not parse as any timestamp format',\n )\n}\n\n/**\n * Variant of {@link normalizeDatetime} which always returns a valid datetime\n * string.\n *\n * If a {@link InvalidDatetimeError} is encountered, returns the UNIX epoch time\n * as a UTC datetime (`1970-01-01T00:00:00.000Z`).\n *\n * @see {@link normalizeDatetime}\n */\nexport function normalizeDatetimeAlways(dtStr: string): ISODatetimeString {\n try {\n return normalizeDatetime(dtStr)\n } catch (err) {\n return '1970-01-01T00:00:00.000Z'\n }\n}\n\n// Legacy exports (should we deprecate these ?)\nexport {\n assertDatetimeString as ensureValidDatetime,\n isDatetimeString as isValidDatetime,\n}\n\n// -----------------------------------------------------------------------------\n// ------------------------- Internal validation logic -------------------------\n// -----------------------------------------------------------------------------\n\n// Validation utils that allow avoiding try/catch for control flow (performance\n// optimization). Other syntax formats should also use this pattern to avoid\n// try/catch in their validation logic, at which point these utils can be moved\n// to a common internal utils.\ntype FailureResult = { success: false; message: string }\nconst failure = (m: string): FailureResult => ({ success: false, message: m })\ntype SuccessResult<V> = { success: true; value: V }\nconst success = <V>(v: V): SuccessResult<V> => ({ success: true, value: v })\ntype Result<V> = FailureResult | SuccessResult<V>\n\n/**\n * @see {@link https://www.rfc-editor.org/rfc/rfc3339#section-5.6 Internet Date/Time Format}\n *\n * @example\n * ```abnf\n * date-fullyear = 4DIGIT\n * date-month = 2DIGIT ; 01-12\n * date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on\n * ; month/year\n * time-hour = 2DIGIT ; 00-23\n * time-minute = 2DIGIT ; 00-59\n * time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second\n * ; rules\n * time-secfrac = \".\" 1*DIGIT\n * time-numoffset = (\"+\" / \"-\") time-hour \":\" time-minute\n * time-offset = \"Z\" / time-numoffset\n * partial-time = time-hour \":\" time-minute \":\" time-second\n * [time-secfrac]\n * full-date = date-fullyear \"-\" date-month \"-\" date-mday\n * full-time = partial-time time-offset\n * date-time = full-date \"T\" full-time\n * ```\n */\nconst DATETIME_REGEX =\n /^(?<full_year>[0-9]{4})-(?<date_month>0[1-9]|1[012])-(?<date_mday>[0-2][0-9]|3[01])T(?<time_hour>[0-1][0-9]|2[0-3]):(?<time_minute>[0-5][0-9]):(?<time_second>[0-5][0-9]|60)(?<time_secfrac>\\.[0-9]+)?(?<time_offset>Z|(?<time_numoffset>[+-](?:[0-1][0-9]|2[0-3]):[0-5][0-9]))$/\n\n/**\n * Validates that the input is a datetime string according to atproto Lexicon\n * rules, and parses it into a Date object.\n */\nfunction parseString(input: unknown): Result<AtprotoDate> {\n // @NOTE Performing cheap tests first\n if (typeof input !== 'string') {\n return failure('datetime must be a string')\n }\n if (input.length > 64) {\n return failure('datetime is too long (64 chars max)')\n }\n if (input.endsWith('-00:00')) {\n return failure('datetime can not use \"-00:00\" for UTC timezone')\n }\n if (!DATETIME_REGEX.test(input)) {\n return failure(\n \"datetime is not in a valid format (must match RFC 3339 & ISO 8601 with 'Z' or ±hh:mm timezone)\",\n )\n }\n\n // must parse as ISO 8601; this also verifies semantics like leap seconds and\n // correct number of days in month, which the regex does not check for\n const date = new Date(input)\n\n return parseDate(date)\n}\n\n/**\n * Ensures that a Date object represents a valid datetime according to atproto\n * Lexicon rules. This ensures that `date.toISOString()` will produce a valid\n * datetime string that can be used where {@link DatetimeString} is expected.\n */\nfunction parseDate(date: Date): Result<AtprotoDate> {\n const fullYear = date.getUTCFullYear()\n // Ensures that the date is valid. We could check isNaN(date.getTime()) here\n // but since we'll check the year anyway, we just use that for the validity\n // check since an invalid date will have NaN year.\n if (Number.isNaN(fullYear)) {\n return failure('datetime did not parse as ISO 8601')\n }\n // Ensure that the ISO string representation does not start with ±YYYYYY\n if (fullYear < 0) {\n return failure('datetime normalized to a negative time')\n }\n if (fullYear > 9999) {\n return failure('datetime year is too far in the future')\n }\n if (fullYear < 10) {\n return failure('datetime so close to year zero not allowed')\n }\n return success(date as AtprotoDate)\n}\n"]}
1
+ {"version":3,"file":"datetime.js","sourceRoot":"","sources":["../src/datetime.ts"],"names":[],"mappings":";;;AA8BA,8CAKC;AAKD,sCAGC;AAKD,sCAEC;AAKD,sCAEC;AAkCD,oDAOC;AA6GyB,mDAAmB;AApG7C,4CAGC;AAOD,4CAEC;AAyFqB,2CAAe;AAjFrC,4CAIC;AAOD,sDAEC;AAWD,4CAEC;AAeD,8CAkBC;AAWD,0DAMC;AA3MD;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,KAAK;CAAG;AAAlD,oDAAkD;AAsBlD;;GAEG;AACH,SAAgB,iBAAiB,CAAC,IAAU;IAC1C,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAC3B,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,IAAI,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC7C,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACvB,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAA;AAChC,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAU;IACtC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,C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AAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CACZ,gGAAgG,CACjG,CAAA;IACH,CAAC;IAED,6EAA6E;IAC7E,sEAAsE;IACtE,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;IAE5B,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,IAAU;IAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;IACtC,4EAA4E;IAC5E,2EAA2E;IAC3E,kDAAkD;IAClD,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,oCAAoC,CAAC,CAAA;IACtD,CAAC;IACD,wEAAwE;IACxE,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO,OAAO,CAAC,wCAAwC,CAAC,CAAA;IAC1D,CAAC;IACD,IAAI,QAAQ,GAAG,IAAI,EAAE,CAAC;QACpB,OAAO,OAAO,CAAC,wCAAwC,CAAC,CAAA;IAC1D,CAAC;IACD,OAAO,OAAO,CAAC,IAAmB,CAAC,CAAA;AACrC,CAAC","sourcesContent":["/**\n * Indicates a date or string is not a valid representation of a datetime\n * according to the atproto\n * {@link https://atproto.com/specs/lexicon#datetime specification}.\n */\nexport class InvalidDatetimeError extends Error {}\n\n/**\n * A subset of {@link DatetimeString} that represent valid datetime strings with\n * the format: `YYYY-MM-DDTHH:mm:ss.sssZ`, as returned by `Date.toISOString()\n * for dates between the years 0000 and 9999.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString}\n */\nexport type ISODatetimeString =\n // @TODO Switch to branded types for more accurate type safety.\n `${string}-${string}-${string}T${string}:${string}:${string}.${string}Z`\n\n/**\n * Represents a {@link Date} that can be safely stringified into a valid atproto\n * {@link DatetimeString} using the {@link Date.toISOString toISOString()}\n * method.\n */\nexport interface AtprotoDate extends Date {\n toISOString(): ISODatetimeString\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function assertAtprotoDate(date: Date): asserts date is AtprotoDate {\n const res = parseDate(date)\n if (!res.success) {\n throw new InvalidDatetimeError(res.message)\n }\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function asAtprotoDate(date: Date): AtprotoDate {\n assertAtprotoDate(date)\n return date\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function isAtprotoDate(date: Date): date is AtprotoDate {\n return parseDate(date).success\n}\n\n/**\n * @see {@link AtprotoDate}\n */\nexport function ifAtprotoDate(date: Date): AtprotoDate | undefined {\n return isAtprotoDate(date) ? date : undefined\n}\n\n/**\n * Datetime strings in atproto data structures and API calls should meet the\n * {@link https://ijmacd.github.io/rfc3339-iso8601/ intersecting} requirements\n * of the RFC 3339, ISO 8601, and WHATWG HTML datetime standards.\n *\n * @note This literal template type is not accurate enough to ensure that a\n * string is a valid atproto datetime. The {@link DatetimeString} validation\n * functions ({@link assertDatetimeString}, {@link isDatetimeString}, etc)\n * should be used to validate that a string meets the atproto datetime\n * requirements, and the {@link toDatetimeString} function should be used to\n * convert a {@link Date} object into a valid {@link DatetimeString} string.\n *\n * @example \"2024-01-15T12:30:00Z\"\n * @example \"2024-01-15T12:30:00.000Z\"\n * @example \"2024-01-15T12:30:00+00:00\"\n * @example \"2024-01-15T11:30:00-01:00\"\n * @see {@link https://atproto.com/specs/lexicon#datetime atproto Lexicon datetime format}\n * @see {@link https://www.rfc-editor.org/rfc/rfc3339 RFC 3339}\n * @see {@link https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601}\n */\nexport type DatetimeString =\n // @TODO Switch to branded types for more accurate type safety?\n | `${string}-${string}-${string}T${string}:${string}:${string}Z`\n | `${string}-${string}-${string}T${string}:${string}:${string}${'+' | '-'}${string}:${string}`\n\n/**\n * Validates that a string is a valid {@link DatetimeString} format string,\n * throwing an error if it is not.\n *\n * @throws InvalidDatetimeError if the input string does not meet the atproto 'datetime' format requirements.\n * @see {@link DatetimeString}\n */\nexport function assertDatetimeString<I>(\n input: I,\n): asserts input is I & DatetimeString {\n const result = parseString(input)\n if (!result.success) {\n throw new InvalidDatetimeError(result.message)\n }\n}\n\n/**\n * Casts a string to a {@link DatetimeString} if it is a valid datetime format\n * string, throwing an error if it is not.\n *\n * @throws InvalidDatetimeError if the input string does not meet the atproto 'datetime' format requirements.\n * @see {@link DatetimeString}\n */\nexport function asDatetimeString<I>(input: I): I & DatetimeString {\n assertDatetimeString(input)\n return input\n}\n\n/**\n * Checks if a string is a valid {@link DatetimeString} format string.\n *\n * @see {@link DatetimeString}\n */\nexport function isDatetimeString<I>(input: I): input is I & DatetimeString {\n return parseString(input).success\n}\n\n/**\n * Returns the input if it is a valid {@link DatetimeString} format string, or\n * `undefined` if it is not.\n *\n * @see {@link DatetimeString}\n */\nexport function ifDatetimeString<I>(\n input: I,\n): undefined | (I & DatetimeString) {\n return isDatetimeString(input) ? input : undefined\n}\n\n/**\n * Returns the current date and time as a {@link DatetimeString}.\n *\n * @see {@link DatetimeString}\n */\nexport function currentDatetimeString(): DatetimeString {\n return toDatetimeString(new Date())\n}\n\n/**\n * Converts any {@link Date} into a {@link DatetimeString} if possible, throwing\n * an error if the date is not a valid atproto datetime.\n *\n * This is short-hand for `asAtprotoDate(date).toISOString()`.\n *\n * @throws InvalidDatetimeError if the input date is not a valid atproto datetime (eg, it is too far in the future or past, or it normalizes to a negative year).\n * @see {@link DatetimeString}\n */\nexport function toDatetimeString(date: Date): DatetimeString {\n return asAtprotoDate(date).toISOString()\n}\n\n/**\n * Takes a flexible datetime string and normalizes its representation.\n *\n * This function will work with any valid value that can be parsed as a date. It\n * *additionally* is more flexible about accepting datetimes that are missing\n * timezone information, and normalizing them to a valid atproto datetime.\n *\n * One use-case is a consistent, sortable string. Another is to work with older\n * invalid createdAt datetimes.\n *\n * @returns ISODatetimeString - a valid atproto datetime with millisecond precision (3 sub-second digits) and UTC timezone with trailing 'Z' syntax.\n * @throws InvalidDatetimeError - if the input string could not be parsed as a datetime, even with permissive parsing.\n */\nexport function normalizeDatetime(dtStr: string): ISODatetimeString {\n // Parse the string as is\n const date = new Date(dtStr)\n if (isAtprotoDate(date)) {\n return date.toISOString()\n }\n\n // if dtStr is not a valid date, try parsing again with a timezone\n if (isNaN(date.getTime()) && !/.*(([+-]\\d\\d:?\\d\\d)|[a-zA-Z])$/.test(dtStr)) {\n const date = new Date(`${dtStr}Z`)\n if (isAtprotoDate(date)) {\n return date.toISOString()\n }\n }\n\n throw new InvalidDatetimeError(\n 'datetime did not parse as any timestamp format',\n )\n}\n\n/**\n * Variant of {@link normalizeDatetime} which always returns a valid datetime\n * string.\n *\n * If a {@link InvalidDatetimeError} is encountered, returns the UNIX epoch time\n * as a UTC datetime (`1970-01-01T00:00:00.000Z`).\n *\n * @see {@link normalizeDatetime}\n */\nexport function normalizeDatetimeAlways(dtStr: string): ISODatetimeString {\n try {\n return normalizeDatetime(dtStr)\n } catch (err) {\n return '1970-01-01T00:00:00.000Z'\n }\n}\n\n// Legacy exports (should we deprecate these ?)\nexport {\n assertDatetimeString as ensureValidDatetime,\n isDatetimeString as isValidDatetime,\n}\n\n// -----------------------------------------------------------------------------\n// ------------------------- Internal validation logic -------------------------\n// -----------------------------------------------------------------------------\n\n// Validation utils that allow avoiding try/catch for control flow (performance\n// optimization). Other syntax formats should also use this pattern to avoid\n// try/catch in their validation logic, at which point these utils can be moved\n// to a common internal utils.\ntype FailureResult = { success: false; message: string }\nconst failure = (m: string): FailureResult => ({ success: false, message: m })\ntype SuccessResult<V> = { success: true; value: V }\nconst success = <V>(v: V): SuccessResult<V> => ({ success: true, value: v })\ntype Result<V> = FailureResult | SuccessResult<V>\n\n/**\n * @see {@link https://www.rfc-editor.org/rfc/rfc3339#section-5.6 Internet Date/Time Format}\n *\n * @example\n * ```abnf\n * date-fullyear = 4DIGIT\n * date-month = 2DIGIT ; 01-12\n * date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on\n * ; month/year\n * time-hour = 2DIGIT ; 00-23\n * time-minute = 2DIGIT ; 00-59\n * time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second\n * ; rules\n * time-secfrac = \".\" 1*DIGIT\n * time-numoffset = (\"+\" / \"-\") time-hour \":\" time-minute\n * time-offset = \"Z\" / time-numoffset\n * partial-time = time-hour \":\" time-minute \":\" time-second\n * [time-secfrac]\n * full-date = date-fullyear \"-\" date-month \"-\" date-mday\n * full-time = partial-time time-offset\n * date-time = full-date \"T\" full-time\n * ```\n */\nconst DATETIME_REGEX =\n /^(?<full_year>[0-9]{4})-(?<date_month>0[1-9]|1[012])-(?<date_mday>[0-2][0-9]|3[01])T(?<time_hour>[0-1][0-9]|2[0-3]):(?<time_minute>[0-5][0-9]):(?<time_second>[0-5][0-9]|60)(?<time_secfrac>\\.[0-9]+)?(?<time_offset>Z|(?<time_numoffset>[+-](?:[0-1][0-9]|2[0-3]):[0-5][0-9]))$/\n\n/**\n * Validates that the input is a datetime string according to atproto Lexicon\n * rules, and parses it into a Date object.\n */\nfunction parseString(input: unknown): Result<AtprotoDate> {\n // @NOTE Performing cheap tests first\n if (typeof input !== 'string') {\n return failure('datetime must be a string')\n }\n if (input.length > 64) {\n return failure('datetime is too long (64 chars max)')\n }\n if (input.endsWith('-00:00')) {\n return failure('datetime can not use \"-00:00\" for UTC timezone')\n }\n if (!DATETIME_REGEX.test(input)) {\n return failure(\n \"datetime is not in a valid format (must match RFC 3339 & ISO 8601 with 'Z' or ±hh:mm timezone)\",\n )\n }\n\n // must parse as ISO 8601; this also verifies semantics like leap seconds and\n // correct number of days in month, which the regex does not check for\n const date = new Date(input)\n\n return parseDate(date)\n}\n\n/**\n * Ensures that a Date object represents a valid datetime according to atproto\n * Lexicon rules. This ensures that `date.toISOString()` will produce a valid\n * datetime string that can be used where {@link DatetimeString} is expected.\n */\nfunction parseDate(date: Date): Result<AtprotoDate> {\n const fullYear = date.getUTCFullYear()\n // Ensures that the date is valid. We could check isNaN(date.getTime()) here\n // but since we'll check the year anyway, we just use that for the validity\n // check since an invalid date will have NaN year.\n if (Number.isNaN(fullYear)) {\n return failure('datetime did not parse as ISO 8601')\n }\n // Ensure that the ISO string representation does not start with ±YYYYYY\n if (fullYear < 0) {\n return failure('datetime normalized to a negative time')\n }\n if (fullYear > 9999) {\n return failure('datetime year is too far in the future')\n }\n return success(date as AtprotoDate)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/syntax",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "license": "MIT",
5
5
  "description": "Validation for atproto identifiers and formats: DID, handle, NSID, AT URI, etc",
6
6
  "keywords": [
@@ -143,7 +143,7 @@ export function isValidAtUri<I extends string>(
143
143
  input: I,
144
144
  ): input is I & AtUriString {
145
145
  try {
146
- ensureValidAtUriRegex(input)
146
+ ensureValidAtUri(input)
147
147
  } catch {
148
148
  return false
149
149
  }
package/src/datetime.ts CHANGED
@@ -297,8 +297,5 @@ function parseDate(date: Date): Result<AtprotoDate> {
297
297
  if (fullYear > 9999) {
298
298
  return failure('datetime year is too far in the future')
299
299
  }
300
- if (fullYear < 10) {
301
- return failure('datetime so close to year zero not allowed')
302
- }
303
300
  return success(date as AtprotoDate)
304
301
  }
@@ -0,0 +1,183 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { describe, expect, test } from 'vitest'
3
+ import { ensureValidAtUri, isValidAtUri } from '../src'
4
+
5
+ describe('valid interop', () => {
6
+ for (const value of readLines(
7
+ `${__dirname}/../../../interop-test-files/syntax/aturi_syntax_valid.txt`,
8
+ )) {
9
+ testValid(value)
10
+ }
11
+ })
12
+
13
+ // describe('invalid interop', () => {
14
+ // for (const value of readLines(
15
+ // `${__dirname}/../../../interop-test-files/syntax/aturi_syntax_invalid.txt`,
16
+ // )) {
17
+ // testInvalid(value)
18
+ // }
19
+ // })
20
+
21
+ describe('custom cases', () => {
22
+ describe('valid spec basics', () => {
23
+ testValid('at://did:plc:asdf123')
24
+ testValid('at://user.bsky.social')
25
+ testValid('at://did:plc:asdf123/com.atproto.feed.post')
26
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/record')
27
+
28
+ testValid('at://did:plc:asdf123#/frag')
29
+ testValid('at://user.bsky.social#/frag')
30
+ testValid('at://did:plc:asdf123/com.atproto.feed.post#/frag')
31
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/record#/frag')
32
+ })
33
+
34
+ describe('invalid spec basics', () => {
35
+ testInvalid('a://did:plc:asdf123')
36
+ testInvalid('at//did:plc:asdf123')
37
+ testInvalid('at:/a/did:plc:asdf123')
38
+ testInvalid('at:/did:plc:asdf123')
39
+ testInvalid('AT://did:plc:asdf123')
40
+ testInvalid('http://did:plc:asdf123')
41
+ testInvalid('://did:plc:asdf123')
42
+ testInvalid('at:did:plc:asdf123')
43
+ testInvalid('at:/did:plc:asdf123')
44
+ testInvalid('at:///did:plc:asdf123')
45
+ testInvalid('at://:/did:plc:asdf123')
46
+ testInvalid('at:/ /did:plc:asdf123')
47
+ testInvalid('at://did:plc:asdf123 ')
48
+ testInvalid('at://did:plc:asdf123/ ')
49
+ testInvalid(' at://did:plc:asdf123')
50
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post ')
51
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post# ')
52
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post#/ ')
53
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post#/frag ')
54
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post#fr ag')
55
+ testInvalid('//did:plc:asdf123')
56
+ testInvalid('at://name')
57
+ testInvalid('at://name.0')
58
+ testInvalid('at://diD:plc:asdf123')
59
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.p@st')
60
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.p$st')
61
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.p%st')
62
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.p&st')
63
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.p()t')
64
+ testInvalid('at://did:plc:asdf123/com.atproto.feed_post')
65
+ testInvalid('at://did:plc:asdf123/-com.atproto.feed.post')
66
+ testInvalid('at://did:plc:asdf@123/com.atproto.feed.post')
67
+
68
+ testInvalid('at://DID:plc:asdf123')
69
+ testInvalid('at://user.bsky.123')
70
+ testInvalid('at://bsky')
71
+ testInvalid('at://did:plc:')
72
+ testInvalid('at://did:plc:')
73
+ testInvalid('at://frag')
74
+ })
75
+
76
+ describe('very long strings', () => {
77
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/' + 'o'.repeat(800))
78
+ testInvalid(`at://did:plc:${'o'.repeat(8200)}/com.atproto.feed.post/record`)
79
+ })
80
+
81
+ describe('invalid collection', () => {
82
+ testInvalid('at://did:plc:asdf123/short/stuff')
83
+ testInvalid('at://did:plc:asdf123/12345')
84
+ })
85
+
86
+ describe('invalid repeated slashes', () => {
87
+ testInvalid('at://user.bsky.social//')
88
+ testInvalid('at://user.bsky.social//com.atproto.feed.post')
89
+ testInvalid('at://user.bsky.social/com.atproto.feed.post//')
90
+ })
91
+
92
+ describe('invalid trailing slashes', () => {
93
+ testInvalid('at://did:plc:asdf123/')
94
+ testInvalid('at://user.bsky.social/')
95
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/')
96
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/record/')
97
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/record/#/frag')
98
+ })
99
+
100
+ describe('invalid segment count', () => {
101
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/asdf123/asdf')
102
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/asdf123/more/more')
103
+ })
104
+
105
+ describe('valid record key', () => {
106
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/a')
107
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/asdf123')
108
+ })
109
+
110
+ describe('invalid trailing slash', () => {
111
+ testInvalid('at://did:plc:asdf123/')
112
+ testInvalid('at://user.bsky.social/')
113
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/')
114
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/record/')
115
+ testInvalid('at://did:plc:asdf123/com.atproto.feed.post/record/#/frag')
116
+ })
117
+
118
+ describe('invalid record keys', () => {
119
+ // is probably too permissive about URL encoding
120
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/%30')
121
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/%3')
122
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/%')
123
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/%zz')
124
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/%%%')
125
+
126
+ // is very permissive about fragments
127
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/%23')
128
+
129
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/$@!*)(:,;~.sdf123')
130
+ testValid("at://did:plc:asdf123/com.atproto.feed.post/~'sdf123")
131
+
132
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/$')
133
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/@')
134
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/!')
135
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/*')
136
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/(')
137
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/,')
138
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/;')
139
+ testValid('at://did:plc:asdf123/com.atproto.feed.post/abc%30123')
140
+ })
141
+
142
+ describe('valid fragment', () => {
143
+ testValid('at://did:plc:asdf123#/frac')
144
+ })
145
+
146
+ describe('invalid fragment', () => {
147
+ testValid('at://did:plc:asdf123#/com.atproto.feed.post')
148
+ testValid('at://did:plc:asdf123#/com.atproto.feed.post/')
149
+ testValid('at://did:plc:asdf123#/asdf/')
150
+
151
+ testValid('at://did:plc:asdf123/com.atproto.feed.post#/$@!*():,;~.sdf123')
152
+ testValid('at://did:plc:asdf123#/[asfd]')
153
+
154
+ testValid('at://did:plc:asdf123#/$')
155
+ testValid('at://did:plc:asdf123#/*')
156
+ testValid('at://did:plc:asdf123#/;')
157
+ testValid('at://did:plc:asdf123#/,')
158
+
159
+ testInvalid('at://did:plc:asdf123#')
160
+ testInvalid('at://did:plc:asdf123##')
161
+ testInvalid('#at://did:plc:asdf123')
162
+ testInvalid('at://did:plc:asdf123#/asdf#/asdf')
163
+ })
164
+ })
165
+
166
+ function testValid(value: string) {
167
+ test(value, () => {
168
+ expect(isValidAtUri(value)).toBe(true)
169
+ expect(() => ensureValidAtUri(value)).not.toThrow()
170
+ })
171
+ }
172
+
173
+ function testInvalid(value: string) {
174
+ test(value, () => {
175
+ expect(isValidAtUri(value)).toBe(false)
176
+ })
177
+ }
178
+
179
+ function readLines(filePath: string): string[] {
180
+ return readFileSync(filePath, 'utf-8')
181
+ .split(/\r?\n/)
182
+ .filter((line) => !line.startsWith('#') && line.length > 0)
183
+ }
@@ -1,12 +1,26 @@
1
- import * as fs from 'node:fs'
2
- import * as readline from 'node:readline'
3
- import { describe, expect, it } from 'vitest'
4
- import { AtUri, ensureValidAtUri, ensureValidAtUriRegex } from '../src'
1
+ import { readFileSync } from 'node:fs'
2
+ import { describe, expect, it, test } from 'vitest'
3
+ import { AtUri } from '../src'
5
4
 
6
5
  describe(AtUri, () => {
7
- it('parses valid at uris', () => {
8
- // input host path query hash
9
- type AtUriTest = [string, string, string, string, string]
6
+ describe('parses valid interop', () => {
7
+ for (const value of readLines(
8
+ `${__dirname}/../../../interop-test-files/syntax/aturi_syntax_valid.txt`,
9
+ )) {
10
+ test(value, () => {
11
+ expect(() => new AtUri(value)).not.toThrow()
12
+ })
13
+ }
14
+ })
15
+
16
+ describe('valid at uris', () => {
17
+ type AtUriTest = [
18
+ input: string,
19
+ host: string,
20
+ path: string,
21
+ query: string,
22
+ hash: string,
23
+ ]
10
24
  const TESTS: AtUriTest[] = [
11
25
  ['foo.com', 'foo.com', '', '', ''],
12
26
  ['at://foo.com', 'foo.com', '', '', ''],
@@ -246,15 +260,17 @@ describe(AtUri, () => {
246
260
  '',
247
261
  ],
248
262
  ]
249
- for (const [uri, hostname, pathname, search, hash] of TESTS) {
250
- const urip = new AtUri(uri)
251
- expect(urip.protocol).toBe('at:')
252
- expect(urip.host).toBe(hostname)
253
- expect(urip.hostname).toBe(hostname)
254
- expect(urip.origin).toBe(`at://${hostname}`)
255
- expect(urip.pathname).toBe(pathname)
256
- expect(urip.search).toBe(search)
257
- expect(urip.hash).toBe(hash)
263
+ for (const [input, host, path, search, hash] of TESTS) {
264
+ test(input, () => {
265
+ const urip = new AtUri(input)
266
+ expect(urip.protocol).toBe('at:')
267
+ expect(urip.host).toBe(host)
268
+ expect(urip.hostname).toBe(host)
269
+ expect(urip.origin).toBe(`at://${host}`)
270
+ expect(urip.pathname).toBe(path)
271
+ expect(urip.search).toBe(search)
272
+ expect(urip.hash).toBe(hash)
273
+ })
258
274
  }
259
275
  })
260
276
 
@@ -316,11 +332,9 @@ describe(AtUri, () => {
316
332
  expect(urip.toString()).toBe('at://foo.com/foo?foo=bar&baz=buux#hash')
317
333
  })
318
334
 
319
- it('supports relative URIs', () => {
320
- // input path query hash
321
- type AtUriTest = [string, string, string, string]
335
+ describe('relative URIs', () => {
336
+ type AtUriTest = [input: string, path: string, search: string, hash: string]
322
337
  const TESTS: AtUriTest[] = [
323
- // input hostname pathname query hash
324
338
  ['', '', '', ''],
325
339
  ['/', '/', '', ''],
326
340
  ['/foo', '/foo', '', ''],
@@ -347,180 +361,23 @@ describe(AtUri, () => {
347
361
  ]
348
362
 
349
363
  for (const base of BASES) {
350
- const basep = new AtUri(base)
351
- for (const [relative, pathname, search, hash] of TESTS) {
352
- const urip = new AtUri(relative, base)
353
- expect(urip.protocol).toBe('at:')
354
- expect(urip.host).toBe(basep.host)
355
- expect(urip.hostname).toBe(basep.hostname)
356
- expect(urip.origin).toBe(basep.origin)
357
- expect(urip.pathname).toBe(pathname)
358
- expect(urip.search).toBe(search)
359
- expect(urip.hash).toBe(hash)
360
- }
364
+ describe(base, () => {
365
+ for (const [input, path, search, hash] of TESTS) {
366
+ test(input, () => {
367
+ const baseUri = new AtUri(base)
368
+ const uri = new AtUri(input, base)
369
+ expect(uri.protocol).toBe('at:')
370
+ expect(uri.host).toBe(baseUri.host)
371
+ expect(uri.hostname).toBe(baseUri.hostname)
372
+ expect(uri.origin).toBe(baseUri.origin)
373
+ expect(uri.pathname).toBe(path)
374
+ expect(uri.search).toBe(search)
375
+ expect(uri.hash).toBe(hash)
376
+ })
377
+ }
378
+ })
361
379
  }
362
380
  })
363
- })
364
-
365
- describe('AtUri validation', () => {
366
- const expectValid = (h: string) => {
367
- ensureValidAtUri(h)
368
- ensureValidAtUriRegex(h)
369
- }
370
- const expectInvalid = (h: string) => {
371
- expect(() => ensureValidAtUri(h)).toThrow()
372
- expect(() => ensureValidAtUriRegex(h)).toThrow()
373
- }
374
-
375
- it('enforces spec basics', () => {
376
- expectValid('at://did:plc:asdf123')
377
- expectValid('at://user.bsky.social')
378
- expectValid('at://did:plc:asdf123/com.atproto.feed.post')
379
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/record')
380
-
381
- expectValid('at://did:plc:asdf123#/frag')
382
- expectValid('at://user.bsky.social#/frag')
383
- expectValid('at://did:plc:asdf123/com.atproto.feed.post#/frag')
384
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/record#/frag')
385
-
386
- expectInvalid('a://did:plc:asdf123')
387
- expectInvalid('at//did:plc:asdf123')
388
- expectInvalid('at:/a/did:plc:asdf123')
389
- expectInvalid('at:/did:plc:asdf123')
390
- expectInvalid('AT://did:plc:asdf123')
391
- expectInvalid('http://did:plc:asdf123')
392
- expectInvalid('://did:plc:asdf123')
393
- expectInvalid('at:did:plc:asdf123')
394
- expectInvalid('at:/did:plc:asdf123')
395
- expectInvalid('at:///did:plc:asdf123')
396
- expectInvalid('at://:/did:plc:asdf123')
397
- expectInvalid('at:/ /did:plc:asdf123')
398
- expectInvalid('at://did:plc:asdf123 ')
399
- expectInvalid('at://did:plc:asdf123/ ')
400
- expectInvalid(' at://did:plc:asdf123')
401
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post ')
402
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post# ')
403
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post#/ ')
404
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post#/frag ')
405
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post#fr ag')
406
- expectInvalid('//did:plc:asdf123')
407
- expectInvalid('at://name')
408
- expectInvalid('at://name.0')
409
- expectInvalid('at://diD:plc:asdf123')
410
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.p@st')
411
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.p$st')
412
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.p%st')
413
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.p&st')
414
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.p()t')
415
- expectInvalid('at://did:plc:asdf123/com.atproto.feed_post')
416
- expectInvalid('at://did:plc:asdf123/-com.atproto.feed.post')
417
- expectInvalid('at://did:plc:asdf@123/com.atproto.feed.post')
418
-
419
- expectInvalid('at://DID:plc:asdf123')
420
- expectInvalid('at://user.bsky.123')
421
- expectInvalid('at://bsky')
422
- expectInvalid('at://did:plc:')
423
- expectInvalid('at://did:plc:')
424
- expectInvalid('at://frag')
425
-
426
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/' + 'o'.repeat(800))
427
- expectInvalid(
428
- 'at://did:plc:asdf123/com.atproto.feed.post/' + 'o'.repeat(8200),
429
- )
430
- })
431
-
432
- it('has specified behavior on edge cases', () => {
433
- expectInvalid('at://user.bsky.social//')
434
- expectInvalid('at://user.bsky.social//com.atproto.feed.post')
435
- expectInvalid('at://user.bsky.social/com.atproto.feed.post//')
436
- expectInvalid(
437
- 'at://did:plc:asdf123/com.atproto.feed.post/asdf123/more/more',
438
- )
439
- expectInvalid('at://did:plc:asdf123/short/stuff')
440
- expectInvalid('at://did:plc:asdf123/12345')
441
- })
442
-
443
- it('enforces no trailing slashes', () => {
444
- expectValid('at://did:plc:asdf123')
445
- expectInvalid('at://did:plc:asdf123/')
446
-
447
- expectValid('at://user.bsky.social')
448
- expectInvalid('at://user.bsky.social/')
449
-
450
- expectValid('at://did:plc:asdf123/com.atproto.feed.post')
451
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post/')
452
-
453
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/record')
454
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post/record/')
455
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post/record/#/frag')
456
- })
457
-
458
- it('enforces strict paths', () => {
459
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/asdf123')
460
- expectInvalid('at://did:plc:asdf123/com.atproto.feed.post/asdf123/asdf')
461
- })
462
-
463
- it('is very permissive about record keys', () => {
464
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/asdf123')
465
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/a')
466
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/%23')
467
-
468
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/$@!*)(:,;~.sdf123')
469
- expectValid("at://did:plc:asdf123/com.atproto.feed.post/~'sdf123")
470
-
471
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/$')
472
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/@')
473
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/!')
474
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/*')
475
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/(')
476
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/,')
477
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/;')
478
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/abc%30123')
479
- })
480
-
481
- it('is probably too permissive about URL encoding', () => {
482
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/%30')
483
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/%3')
484
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/%')
485
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/%zz')
486
- expectValid('at://did:plc:asdf123/com.atproto.feed.post/%%%')
487
- })
488
-
489
- it('is very permissive about fragments', () => {
490
- expectValid('at://did:plc:asdf123#/frac')
491
-
492
- expectInvalid('at://did:plc:asdf123#')
493
- expectInvalid('at://did:plc:asdf123##')
494
- expectInvalid('#at://did:plc:asdf123')
495
- expectInvalid('at://did:plc:asdf123#/asdf#/asdf')
496
-
497
- expectValid('at://did:plc:asdf123#/com.atproto.feed.post')
498
- expectValid('at://did:plc:asdf123#/com.atproto.feed.post/')
499
- expectValid('at://did:plc:asdf123#/asdf/')
500
-
501
- expectValid('at://did:plc:asdf123/com.atproto.feed.post#/$@!*():,;~.sdf123')
502
- expectValid('at://did:plc:asdf123#/[asfd]')
503
-
504
- expectValid('at://did:plc:asdf123#/$')
505
- expectValid('at://did:plc:asdf123#/*')
506
- expectValid('at://did:plc:asdf123#/;')
507
- expectValid('at://did:plc:asdf123#/,')
508
- })
509
-
510
- it('conforms to interop valid ATURIs', () => {
511
- const lineReader = readline.createInterface({
512
- input: fs.createReadStream(
513
- `${__dirname}/interop-files/aturi_syntax_valid.txt`,
514
- ),
515
- terminal: false,
516
- })
517
- lineReader.on('line', (line) => {
518
- if (line.startsWith('#') || line.length === 0) {
519
- return
520
- }
521
- expectValid(line)
522
- })
523
- })
524
381
 
525
382
  it('properly checks that the did property is a valid did', () => {
526
383
  const urip = new AtUri('at://did:example:123')
@@ -568,6 +425,10 @@ describe('AtUri validation', () => {
568
425
  expect(urip.rkey).toBe('not a valid rkey')
569
426
  expect(() => urip.rkeySafe).toThrow()
570
427
  })
571
-
572
- // NOTE: this package is currently more permissive than spec about AT URIs, so invalid cases are not errors
573
428
  })
429
+
430
+ function readLines(filePath: string): string[] {
431
+ return readFileSync(filePath, 'utf-8')
432
+ .split(/\r?\n/)
433
+ .filter((line) => !line.startsWith('#') && line.length > 0)
434
+ }
@@ -131,6 +131,37 @@ describe(normalizeDatetime, () => {
131
131
  expect(normalizeDatetime('Fri, 02 Jan 1999 12:34:56 GMT')).toEqual(
132
132
  '1999-01-02T12:34:56.000Z',
133
133
  )
134
+ expect(normalizeDatetime('0001-01-01T00:00:00+01:00')).toEqual(
135
+ '0000-12-31T23:00:00.000Z',
136
+ )
137
+ })
138
+
139
+ it('accepts years 1-9', () => {
140
+ expect(normalizeDatetime('0009-12-31T23:59:59Z')).toEqual(
141
+ '0009-12-31T23:59:59.000Z',
142
+ )
143
+ expect(normalizeDatetime('0005-06-15T12:00:00Z')).toEqual(
144
+ '0005-06-15T12:00:00.000Z',
145
+ )
146
+ expect(normalizeDatetime('0001-01-01T00:00:00Z')).toEqual(
147
+ '0001-01-01T00:00:00.000Z',
148
+ )
149
+ expect(normalizeDatetime('0002-03-04T05:06:07.890Z')).toEqual(
150
+ '0002-03-04T05:06:07.890Z',
151
+ )
152
+ })
153
+
154
+ it('accepts single-digit years with leading zeros', () => {
155
+ expect(normalizeDatetime('0007-01-01T00:00:00Z')).toEqual(
156
+ '0007-01-01T00:00:00.000Z',
157
+ )
158
+ })
159
+
160
+ it('accepts year 1 with timezone offsets', () => {
161
+ // Year 1 with negative offset stays in valid range
162
+ expect(normalizeDatetime('0001-12-31T23:00:00-01:00')).toEqual(
163
+ '0002-01-01T00:00:00.000Z',
164
+ )
134
165
  })
135
166
 
136
167
  it('throws on invalid input', () => {
@@ -145,9 +176,6 @@ describe(normalizeDatetime, () => {
145
176
  expect(() => normalizeDatetime('0000-01-01T00:00:00+01:00')).toThrow(
146
177
  InvalidDatetimeError,
147
178
  )
148
- expect(() => normalizeDatetime('0001-01-01T00:00:00+01:00')).toThrow(
149
- InvalidDatetimeError,
150
- )
151
179
  // 9999-12-31T23:59:00-00:01 is syntactically valid, but normalizing to
152
180
  // UTC advances it to 10000-01-01T00:00:00Z, which is out of range
153
181
  expect(() => normalizeDatetime('9999-12-31T23:59:00-00:01')).toThrow(