@atproto/lex-schema 0.0.10 → 0.0.12

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 (239) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/core/$type.d.ts +149 -0
  3. package/dist/core/$type.d.ts.map +1 -1
  4. package/dist/core/$type.js +44 -0
  5. package/dist/core/$type.js.map +1 -1
  6. package/dist/core/record-key.d.ts +44 -0
  7. package/dist/core/record-key.d.ts.map +1 -1
  8. package/dist/core/record-key.js +30 -0
  9. package/dist/core/record-key.js.map +1 -1
  10. package/dist/core/result.d.ts +85 -4
  11. package/dist/core/result.d.ts.map +1 -1
  12. package/dist/core/result.js +60 -4
  13. package/dist/core/result.js.map +1 -1
  14. package/dist/core/schema.d.ts +229 -2
  15. package/dist/core/schema.d.ts.map +1 -1
  16. package/dist/core/schema.js +197 -4
  17. package/dist/core/schema.js.map +1 -1
  18. package/dist/core/string-format.d.ts +244 -11
  19. package/dist/core/string-format.d.ts.map +1 -1
  20. package/dist/core/string-format.js +150 -0
  21. package/dist/core/string-format.js.map +1 -1
  22. package/dist/core/types.d.ts +90 -3
  23. package/dist/core/types.d.ts.map +1 -1
  24. package/dist/core/types.js.map +1 -1
  25. package/dist/core/validation-error.d.ts +61 -1
  26. package/dist/core/validation-error.d.ts.map +1 -1
  27. package/dist/core/validation-error.js +60 -0
  28. package/dist/core/validation-error.js.map +1 -1
  29. package/dist/core/validation-issue.d.ts +61 -0
  30. package/dist/core/validation-issue.d.ts.map +1 -1
  31. package/dist/core/validation-issue.js +51 -0
  32. package/dist/core/validation-issue.js.map +1 -1
  33. package/dist/core/validator.d.ts +347 -10
  34. package/dist/core/validator.d.ts.map +1 -1
  35. package/dist/core/validator.js +184 -3
  36. package/dist/core/validator.js.map +1 -1
  37. package/dist/helpers.d.ts +13 -25
  38. package/dist/helpers.d.ts.map +1 -1
  39. package/dist/helpers.js +2 -2
  40. package/dist/helpers.js.map +1 -1
  41. package/dist/schema/array.d.ts +45 -0
  42. package/dist/schema/array.d.ts.map +1 -1
  43. package/dist/schema/array.js +14 -0
  44. package/dist/schema/array.js.map +1 -1
  45. package/dist/schema/blob.d.ts +46 -0
  46. package/dist/schema/blob.d.ts.map +1 -1
  47. package/dist/schema/blob.js +39 -0
  48. package/dist/schema/blob.js.map +1 -1
  49. package/dist/schema/boolean.d.ts +28 -0
  50. package/dist/schema/boolean.d.ts.map +1 -1
  51. package/dist/schema/boolean.js +28 -0
  52. package/dist/schema/boolean.js.map +1 -1
  53. package/dist/schema/bytes.d.ts +38 -0
  54. package/dist/schema/bytes.d.ts.map +1 -1
  55. package/dist/schema/bytes.js +32 -0
  56. package/dist/schema/bytes.js.map +1 -1
  57. package/dist/schema/cid.d.ts +38 -0
  58. package/dist/schema/cid.d.ts.map +1 -1
  59. package/dist/schema/cid.js +33 -0
  60. package/dist/schema/cid.js.map +1 -1
  61. package/dist/schema/custom.d.ts +66 -1
  62. package/dist/schema/custom.d.ts.map +1 -1
  63. package/dist/schema/custom.js +54 -0
  64. package/dist/schema/custom.js.map +1 -1
  65. package/dist/schema/dict.d.ts +44 -0
  66. package/dist/schema/dict.d.ts.map +1 -1
  67. package/dist/schema/dict.js +44 -0
  68. package/dist/schema/dict.js.map +1 -1
  69. package/dist/schema/discriminated-union.d.ts +58 -0
  70. package/dist/schema/discriminated-union.d.ts.map +1 -1
  71. package/dist/schema/discriminated-union.js +45 -0
  72. package/dist/schema/discriminated-union.js.map +1 -1
  73. package/dist/schema/enum.d.ts +48 -0
  74. package/dist/schema/enum.d.ts.map +1 -1
  75. package/dist/schema/enum.js +48 -0
  76. package/dist/schema/enum.js.map +1 -1
  77. package/dist/schema/integer.d.ts +42 -0
  78. package/dist/schema/integer.d.ts.map +1 -1
  79. package/dist/schema/integer.js +36 -0
  80. package/dist/schema/integer.js.map +1 -1
  81. package/dist/schema/intersection.d.ts +54 -0
  82. package/dist/schema/intersection.d.ts.map +1 -1
  83. package/dist/schema/intersection.js +49 -0
  84. package/dist/schema/intersection.js.map +1 -1
  85. package/dist/schema/literal.d.ts +44 -0
  86. package/dist/schema/literal.d.ts.map +1 -1
  87. package/dist/schema/literal.js +44 -0
  88. package/dist/schema/literal.js.map +1 -1
  89. package/dist/schema/never.d.ts +42 -0
  90. package/dist/schema/never.d.ts.map +1 -1
  91. package/dist/schema/never.js +42 -0
  92. package/dist/schema/never.js.map +1 -1
  93. package/dist/schema/null.d.ts +29 -0
  94. package/dist/schema/null.d.ts.map +1 -1
  95. package/dist/schema/null.js +29 -0
  96. package/dist/schema/null.js.map +1 -1
  97. package/dist/schema/nullable.d.ts +41 -0
  98. package/dist/schema/nullable.d.ts.map +1 -1
  99. package/dist/schema/nullable.js +41 -0
  100. package/dist/schema/nullable.js.map +1 -1
  101. package/dist/schema/object.d.ts +56 -0
  102. package/dist/schema/object.d.ts.map +1 -1
  103. package/dist/schema/object.js +51 -0
  104. package/dist/schema/object.js.map +1 -1
  105. package/dist/schema/optional.d.ts +42 -0
  106. package/dist/schema/optional.d.ts.map +1 -1
  107. package/dist/schema/optional.js +42 -0
  108. package/dist/schema/optional.js.map +1 -1
  109. package/dist/schema/params.d.ts +89 -7
  110. package/dist/schema/params.d.ts.map +1 -1
  111. package/dist/schema/params.js +84 -10
  112. package/dist/schema/params.js.map +1 -1
  113. package/dist/schema/payload.d.ts +111 -15
  114. package/dist/schema/payload.d.ts.map +1 -1
  115. package/dist/schema/payload.js +70 -0
  116. package/dist/schema/payload.js.map +1 -1
  117. package/dist/schema/permission-set.d.ts +58 -0
  118. package/dist/schema/permission-set.d.ts.map +1 -1
  119. package/dist/schema/permission-set.js +50 -0
  120. package/dist/schema/permission-set.js.map +1 -1
  121. package/dist/schema/permission.d.ts +42 -0
  122. package/dist/schema/permission.d.ts.map +1 -1
  123. package/dist/schema/permission.js +39 -0
  124. package/dist/schema/permission.js.map +1 -1
  125. package/dist/schema/procedure.d.ts +64 -0
  126. package/dist/schema/procedure.d.ts.map +1 -1
  127. package/dist/schema/procedure.js +64 -0
  128. package/dist/schema/procedure.js.map +1 -1
  129. package/dist/schema/query.d.ts +55 -0
  130. package/dist/schema/query.d.ts.map +1 -1
  131. package/dist/schema/query.js +55 -0
  132. package/dist/schema/query.js.map +1 -1
  133. package/dist/schema/record.d.ts +63 -8
  134. package/dist/schema/record.d.ts.map +1 -1
  135. package/dist/schema/record.js +20 -0
  136. package/dist/schema/record.js.map +1 -1
  137. package/dist/schema/ref.d.ts +50 -0
  138. package/dist/schema/ref.d.ts.map +1 -1
  139. package/dist/schema/ref.js +17 -0
  140. package/dist/schema/ref.js.map +1 -1
  141. package/dist/schema/refine.d.ts +58 -9
  142. package/dist/schema/refine.d.ts.map +1 -1
  143. package/dist/schema/refine.js.map +1 -1
  144. package/dist/schema/regexp.d.ts +44 -0
  145. package/dist/schema/regexp.d.ts.map +1 -1
  146. package/dist/schema/regexp.js +44 -0
  147. package/dist/schema/regexp.js.map +1 -1
  148. package/dist/schema/string.d.ts +50 -0
  149. package/dist/schema/string.d.ts.map +1 -1
  150. package/dist/schema/string.js +41 -0
  151. package/dist/schema/string.js.map +1 -1
  152. package/dist/schema/subscription.d.ts +72 -2
  153. package/dist/schema/subscription.d.ts.map +1 -1
  154. package/dist/schema/subscription.js +59 -0
  155. package/dist/schema/subscription.js.map +1 -1
  156. package/dist/schema/token.d.ts +47 -0
  157. package/dist/schema/token.d.ts.map +1 -1
  158. package/dist/schema/token.js +47 -0
  159. package/dist/schema/token.js.map +1 -1
  160. package/dist/schema/typed-object.d.ts +62 -8
  161. package/dist/schema/typed-object.d.ts.map +1 -1
  162. package/dist/schema/typed-object.js +18 -0
  163. package/dist/schema/typed-object.js.map +1 -1
  164. package/dist/schema/typed-ref.d.ts +53 -0
  165. package/dist/schema/typed-ref.d.ts.map +1 -1
  166. package/dist/schema/typed-ref.js +15 -0
  167. package/dist/schema/typed-ref.js.map +1 -1
  168. package/dist/schema/typed-union.d.ts +50 -1
  169. package/dist/schema/typed-union.d.ts.map +1 -1
  170. package/dist/schema/typed-union.js +50 -1
  171. package/dist/schema/typed-union.js.map +1 -1
  172. package/dist/schema/union.d.ts +45 -0
  173. package/dist/schema/union.d.ts.map +1 -1
  174. package/dist/schema/union.js +40 -0
  175. package/dist/schema/union.js.map +1 -1
  176. package/dist/schema/unknown-object.d.ts +34 -0
  177. package/dist/schema/unknown-object.d.ts.map +1 -1
  178. package/dist/schema/unknown-object.js +31 -0
  179. package/dist/schema/unknown-object.js.map +1 -1
  180. package/dist/schema/unknown.d.ts +33 -0
  181. package/dist/schema/unknown.d.ts.map +1 -1
  182. package/dist/schema/unknown.js +33 -0
  183. package/dist/schema/unknown.js.map +1 -1
  184. package/dist/schema/with-default.d.ts +44 -0
  185. package/dist/schema/with-default.d.ts.map +1 -1
  186. package/dist/schema/with-default.js +44 -0
  187. package/dist/schema/with-default.js.map +1 -1
  188. package/package.json +4 -4
  189. package/src/core/$type.ts +150 -18
  190. package/src/core/record-key.ts +44 -0
  191. package/src/core/result.ts +86 -4
  192. package/src/core/schema.ts +236 -7
  193. package/src/core/string-format.ts +259 -13
  194. package/src/core/types.ts +91 -3
  195. package/src/core/validation-error.ts +60 -0
  196. package/src/core/validation-issue.ts +65 -0
  197. package/src/core/validator.ts +351 -10
  198. package/src/helpers.test.ts +110 -29
  199. package/src/helpers.ts +14 -14
  200. package/src/schema/array.test.ts +94 -79
  201. package/src/schema/array.ts +45 -0
  202. package/src/schema/blob.ts +46 -0
  203. package/src/schema/boolean.ts +28 -0
  204. package/src/schema/bytes.ts +38 -0
  205. package/src/schema/cid.ts +38 -0
  206. package/src/schema/custom.ts +66 -1
  207. package/src/schema/dict.ts +44 -0
  208. package/src/schema/discriminated-union.ts +58 -0
  209. package/src/schema/enum.ts +48 -0
  210. package/src/schema/integer.ts +42 -0
  211. package/src/schema/intersection.ts +54 -0
  212. package/src/schema/literal.ts +44 -0
  213. package/src/schema/never.ts +42 -0
  214. package/src/schema/null.ts +29 -0
  215. package/src/schema/nullable.ts +41 -0
  216. package/src/schema/object.ts +56 -0
  217. package/src/schema/optional.ts +42 -0
  218. package/src/schema/params.test.ts +58 -2
  219. package/src/schema/params.ts +124 -16
  220. package/src/schema/payload.test.ts +3 -3
  221. package/src/schema/payload.ts +142 -38
  222. package/src/schema/permission-set.ts +58 -0
  223. package/src/schema/permission.ts +42 -0
  224. package/src/schema/procedure.ts +64 -0
  225. package/src/schema/query.ts +55 -0
  226. package/src/schema/record.ts +63 -8
  227. package/src/schema/ref.ts +50 -0
  228. package/src/schema/refine.ts +58 -9
  229. package/src/schema/regexp.ts +44 -0
  230. package/src/schema/string.ts +50 -0
  231. package/src/schema/subscription.ts +72 -2
  232. package/src/schema/token.ts +47 -0
  233. package/src/schema/typed-object.ts +62 -8
  234. package/src/schema/typed-ref.ts +53 -0
  235. package/src/schema/typed-union.ts +55 -2
  236. package/src/schema/union.ts +45 -0
  237. package/src/schema/unknown-object.ts +34 -0
  238. package/src/schema/unknown.ts +33 -0
  239. package/src/schema/with-default.ts +44 -0
@@ -1,27 +1,165 @@
1
1
  import { AtIdentifierString, AtUriString, DatetimeString, DidString, HandleString, NsidString, RecordKeyString, TidString, UriString } from '@atproto/syntax';
2
2
  import { CheckFn } from '../util/assertion-util.js';
3
- export type { AtIdentifierString };
3
+ /**
4
+ * Type guard that checks if a value is a valid AT identifier (DID or handle).
5
+ *
6
+ * @param value - The value to check
7
+ * @returns `true` if the value is a valid AT identifier
8
+ */
4
9
  export declare const isAtIdentifierString: CheckFn<AtIdentifierString>;
5
- export type { AtUriString };
10
+ export type {
11
+ /**
12
+ * An AT identifier string - either a DID or a handle.
13
+ *
14
+ * @example `"did:plc:1234..."` or `"alice.bsky.social"`
15
+ */
16
+ AtIdentifierString, };
17
+ /**
18
+ * Type guard that checks if a value is a valid AT URI.
19
+ *
20
+ * @param value - The value to check
21
+ * @returns `true` if the value is a valid AT URI
22
+ */
6
23
  export declare const isAtUriString: CheckFn<AtUriString>;
7
- export type CidString = string;
24
+ export type {
25
+ /**
26
+ * An AT URI string pointing to a resource in the AT Protocol network.
27
+ *
28
+ * @example `"at://did:plc:1234.../app.bsky.feed.post/3k2..."`
29
+ */
30
+ AtUriString, };
31
+ /**
32
+ * Type guard that checks if a value is a valid CID string.
33
+ *
34
+ * @param value - The value to check
35
+ * @returns `true` if the value is a valid CID string
36
+ */
8
37
  export declare const isCidString: CheckFn<CidString>;
9
- export type { DatetimeString };
38
+ /**
39
+ * A Content Identifier (CID) string.
40
+ *
41
+ * CIDs are self-describing content addresses used to identify data by its hash.
42
+ *
43
+ * @example `"bafyreig..."`
44
+ */
45
+ export type CidString = string;
46
+ /**
47
+ * Type guard that checks if a value is a valid datetime string.
48
+ *
49
+ * @param value - The value to check
50
+ * @returns `true` if the value is a valid datetime string
51
+ */
10
52
  export declare const isDatetimeString: CheckFn<DatetimeString>;
11
- export type { DidString };
53
+ export type {
54
+ /**
55
+ * An ISO 8601 datetime string.
56
+ *
57
+ * @example `"2024-01-15T12:30:00.000Z"`
58
+ */
59
+ DatetimeString, };
60
+ /**
61
+ * Type guard that checks if a value is a valid DID string.
62
+ *
63
+ * @param value - The value to check
64
+ * @returns `true` if the value is a valid DID string
65
+ */
12
66
  export declare const isDidString: CheckFn<DidString>;
13
- export type { HandleString };
67
+ export type {
68
+ /**
69
+ * A Decentralized Identifier (DID) string.
70
+ *
71
+ * DIDs are globally unique identifiers that don't require a central authority.
72
+ *
73
+ * @example `"did:plc:1234abcd..."` or `"did:web:example.com"`
74
+ */
75
+ DidString, };
76
+ /**
77
+ * Type guard that checks if a value is a valid handle string.
78
+ *
79
+ * @param value - The value to check
80
+ * @returns `true` if the value is a valid handle string
81
+ */
14
82
  export declare const isHandleString: CheckFn<HandleString>;
15
- export type LanguageString = string;
83
+ export type {
84
+ /**
85
+ * A handle string - a human-readable identifier for users.
86
+ *
87
+ * @example `"alice.bsky.social"` or `"bob.example.com"`
88
+ */
89
+ HandleString, };
90
+ /**
91
+ * Type guard that checks if a value is a valid BCP-47 language tag.
92
+ *
93
+ * @param value - The value to check
94
+ * @returns `true` if the value is a valid language string
95
+ */
16
96
  export declare const isLanguageString: CheckFn<LanguageString>;
17
- export type { NsidString };
97
+ /**
98
+ * A BCP-47 language tag string.
99
+ *
100
+ * @example `"en"`, `"en-US"`, `"zh-Hans"`
101
+ */
102
+ export type LanguageString = string;
103
+ /**
104
+ * Type guard that checks if a value is a valid NSID string.
105
+ *
106
+ * @param value - The value to check
107
+ * @returns `true` if the value is a valid NSID string
108
+ */
18
109
  export declare const isNsidString: CheckFn<NsidString>;
19
- export type { RecordKeyString };
110
+ export type {
111
+ /**
112
+ * A Namespaced Identifier (NSID) string identifying a lexicon.
113
+ *
114
+ * NSIDs use reverse-domain notation to identify schemas.
115
+ *
116
+ * @example `"app.bsky.feed.post"`, `"com.atproto.repo.createRecord"`
117
+ */
118
+ NsidString, };
119
+ /**
120
+ * Type guard that checks if a value is a valid record key string.
121
+ *
122
+ * @param value - The value to check
123
+ * @returns `true` if the value is a valid record key string
124
+ */
20
125
  export declare const isRecordKeyString: CheckFn<RecordKeyString>;
21
- export type { TidString };
126
+ export type {
127
+ /**
128
+ * A record key string identifying a record within a collection.
129
+ *
130
+ * @example `"3k2..."` (TID format) or `"self"` (literal key)
131
+ */
132
+ RecordKeyString, };
133
+ /**
134
+ * Type guard that checks if a value is a valid TID string.
135
+ *
136
+ * @param value - The value to check
137
+ * @returns `true` if the value is a valid TID string
138
+ */
22
139
  export declare const isTidString: CheckFn<TidString>;
23
- export type { UriString };
140
+ export type {
141
+ /**
142
+ * A Timestamp Identifier (TID) string.
143
+ *
144
+ * TIDs are time-based identifiers used for record keys.
145
+ *
146
+ * @example `"3k2..."`
147
+ */
148
+ TidString, };
149
+ /**
150
+ * Type guard that checks if a value is a valid URI string.
151
+ *
152
+ * @param value - The value to check
153
+ * @returns `true` if the value is a valid URI string
154
+ */
24
155
  export declare const isUriString: CheckFn<UriString>;
156
+ export type {
157
+ /**
158
+ * A standard URI string.
159
+ *
160
+ * @example `"https://example.com/path"`
161
+ */
162
+ UriString, };
25
163
  type StringFormats = {
26
164
  'at-identifier': AtIdentifierString;
27
165
  'at-uri': AtUriString;
@@ -35,11 +173,106 @@ type StringFormats = {
35
173
  tid: TidString;
36
174
  uri: UriString;
37
175
  };
176
+ /**
177
+ * Union type of all valid string format names.
178
+ */
38
179
  export type StringFormat = Extract<keyof StringFormats, string>;
180
+ /**
181
+ * Infers the string type for a given format name.
182
+ *
183
+ * @typeParam F - The format name
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * type Did = InferStringFormat<'did'>
188
+ * // Result: DidString
189
+ * ```
190
+ */
39
191
  export type InferStringFormat<F extends StringFormat> = F extends StringFormat ? StringFormats[F] : never;
192
+ /**
193
+ * Type guard that checks if a string matches a specific format.
194
+ *
195
+ * @typeParam I - The input string type
196
+ * @typeParam F - The format to check
197
+ * @param input - The string to validate
198
+ * @param format - The format name to validate against
199
+ * @returns `true` if the string matches the format
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const value: string = 'did:plc:1234...'
204
+ * if (isStringFormat(value, 'did')) {
205
+ * // value is typed as DidString
206
+ * console.log('Valid DID:', value)
207
+ * }
208
+ * ```
209
+ */
40
210
  export declare function isStringFormat<I extends string, F extends StringFormat>(input: I, format: F): input is I & StringFormats[F];
211
+ /**
212
+ * Asserts that a string matches a specific format, throwing if invalid.
213
+ *
214
+ * @typeParam I - The input string type
215
+ * @typeParam F - The format to check
216
+ * @param input - The string to validate
217
+ * @param format - The format name to validate against
218
+ * @throws {TypeError} If the string doesn't match the format
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * assertStringFormat(value, 'handle')
223
+ * // value is now typed as HandleString
224
+ * ```
225
+ */
41
226
  export declare function assertStringFormat<I extends string, F extends StringFormat>(input: I, format: F): asserts input is I & StringFormats[F];
227
+ /**
228
+ * Validates and returns a string as the specified format type, throwing if invalid.
229
+ *
230
+ * This is useful when you need to convert a string to a format type in an expression.
231
+ *
232
+ * @typeParam I - The input string type
233
+ * @typeParam F - The format to validate against
234
+ * @param input - The string to validate
235
+ * @param format - The format name to validate against
236
+ * @returns The input typed as the format type
237
+ * @throws {TypeError} If the string doesn't match the format
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * const did = asStringFormat(userInput, 'did')
242
+ * // did is typed as DidString
243
+ * ```
244
+ */
42
245
  export declare function asStringFormat<I extends string, F extends StringFormat>(input: I, format: F): I & StringFormats[F];
246
+ /**
247
+ * Returns the string as the format type if valid, otherwise returns `undefined`.
248
+ *
249
+ * This is useful for optional validation where you want to handle invalid values
250
+ * without throwing.
251
+ *
252
+ * @typeParam I - The input string type
253
+ * @typeParam F - The format to validate against
254
+ * @param input - The string to validate
255
+ * @param format - The format name to validate against
256
+ * @returns The typed string if valid, otherwise `undefined`
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const did = ifStringFormat(maybeInvalid, 'did')
261
+ * if (did) {
262
+ * // did is typed as DidString
263
+ * }
264
+ * ```
265
+ */
43
266
  export declare function ifStringFormat<I extends string, F extends StringFormat>(input: I, format: F): undefined | (I & StringFormats[F]);
267
+ /**
268
+ * Array of all valid string format names.
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * for (const format of STRING_FORMATS) {
273
+ * console.log(format) // 'at-identifier', 'at-uri', 'cid', ...
274
+ * }
275
+ * ```
276
+ */
44
277
  export declare const STRING_FORMATS: readonly StringFormat[];
45
278
  //# sourceMappingURL=string-format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"string-format.d.ts","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,SAAS,EACT,YAAY,EACZ,UAAU,EACV,eAAe,EACf,SAAS,EACT,SAAS,EAWV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAInD,YAAY,EAAE,kBAAkB,EAAE,CAAA;AAClC,eAAO,MAAM,oBAAoB,EAAE,OAA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C,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACzE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAIvC;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAGtB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,YAAY,EACrE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,GACR,SAAS,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAEpC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAEtB,SAAS,YAAY,EAAE,CAAA"}
@@ -7,16 +7,85 @@ exports.asStringFormat = asStringFormat;
7
7
  exports.ifStringFormat = ifStringFormat;
8
8
  const lex_data_1 = require("@atproto/lex-data");
9
9
  const syntax_1 = require("@atproto/syntax");
10
+ // -----------------------------------------------------------------------------
11
+ // Individual string format types and type guards
12
+ // -----------------------------------------------------------------------------
13
+ /**
14
+ * Type guard that checks if a value is a valid AT identifier (DID or handle).
15
+ *
16
+ * @param value - The value to check
17
+ * @returns `true` if the value is a valid AT identifier
18
+ */
10
19
  exports.isAtIdentifierString = syntax_1.isValidAtIdentifier;
20
+ /**
21
+ * Type guard that checks if a value is a valid AT URI.
22
+ *
23
+ * @param value - The value to check
24
+ * @returns `true` if the value is a valid AT URI
25
+ */
11
26
  exports.isAtUriString = syntax_1.isValidAtUri;
27
+ /**
28
+ * Type guard that checks if a value is a valid CID string.
29
+ *
30
+ * @param value - The value to check
31
+ * @returns `true` if the value is a valid CID string
32
+ */
12
33
  exports.isCidString = ((v) => (0, lex_data_1.validateCidString)(v));
34
+ /**
35
+ * Type guard that checks if a value is a valid datetime string.
36
+ *
37
+ * @param value - The value to check
38
+ * @returns `true` if the value is a valid datetime string
39
+ */
13
40
  exports.isDatetimeString = syntax_1.isValidDatetime;
41
+ /**
42
+ * Type guard that checks if a value is a valid DID string.
43
+ *
44
+ * @param value - The value to check
45
+ * @returns `true` if the value is a valid DID string
46
+ */
14
47
  exports.isDidString = syntax_1.isValidDid;
48
+ /**
49
+ * Type guard that checks if a value is a valid handle string.
50
+ *
51
+ * @param value - The value to check
52
+ * @returns `true` if the value is a valid handle string
53
+ */
15
54
  exports.isHandleString = syntax_1.isValidHandle;
55
+ /**
56
+ * Type guard that checks if a value is a valid BCP-47 language tag.
57
+ *
58
+ * @param value - The value to check
59
+ * @returns `true` if the value is a valid language string
60
+ */
16
61
  exports.isLanguageString = syntax_1.isValidLanguage;
62
+ /**
63
+ * Type guard that checks if a value is a valid NSID string.
64
+ *
65
+ * @param value - The value to check
66
+ * @returns `true` if the value is a valid NSID string
67
+ */
17
68
  exports.isNsidString = syntax_1.isValidNsid;
69
+ /**
70
+ * Type guard that checks if a value is a valid record key string.
71
+ *
72
+ * @param value - The value to check
73
+ * @returns `true` if the value is a valid record key string
74
+ */
18
75
  exports.isRecordKeyString = syntax_1.isValidRecordKey;
76
+ /**
77
+ * Type guard that checks if a value is a valid TID string.
78
+ *
79
+ * @param value - The value to check
80
+ * @returns `true` if the value is a valid TID string
81
+ */
19
82
  exports.isTidString = syntax_1.isValidTid;
83
+ /**
84
+ * Type guard that checks if a value is a valid URI string.
85
+ *
86
+ * @param value - The value to check
87
+ * @returns `true` if the value is a valid URI string
88
+ */
20
89
  exports.isUriString = syntax_1.isValidUri;
21
90
  const stringFormatVerifiers = /*#__PURE__*/ Object.freeze({
22
91
  __proto__: null,
@@ -32,6 +101,24 @@ const stringFormatVerifiers = /*#__PURE__*/ Object.freeze({
32
101
  tid: exports.isTidString,
33
102
  uri: exports.isUriString,
34
103
  });
104
+ /**
105
+ * Type guard that checks if a string matches a specific format.
106
+ *
107
+ * @typeParam I - The input string type
108
+ * @typeParam F - The format to check
109
+ * @param input - The string to validate
110
+ * @param format - The format name to validate against
111
+ * @returns `true` if the string matches the format
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const value: string = 'did:plc:1234...'
116
+ * if (isStringFormat(value, 'did')) {
117
+ * // value is typed as DidString
118
+ * console.log('Valid DID:', value)
119
+ * }
120
+ * ```
121
+ */
35
122
  /*@__NO_SIDE_EFFECTS__*/
36
123
  function isStringFormat(input, format) {
37
124
  const formatVerifier = stringFormatVerifiers[format];
@@ -40,21 +127,84 @@ function isStringFormat(input, format) {
40
127
  throw new TypeError(`Unknown string format: ${format}`);
41
128
  return formatVerifier(input);
42
129
  }
130
+ /**
131
+ * Asserts that a string matches a specific format, throwing if invalid.
132
+ *
133
+ * @typeParam I - The input string type
134
+ * @typeParam F - The format to check
135
+ * @param input - The string to validate
136
+ * @param format - The format name to validate against
137
+ * @throws {TypeError} If the string doesn't match the format
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * assertStringFormat(value, 'handle')
142
+ * // value is now typed as HandleString
143
+ * ```
144
+ */
43
145
  /*@__NO_SIDE_EFFECTS__*/
44
146
  function assertStringFormat(input, format) {
45
147
  if (!isStringFormat(input, format)) {
46
148
  throw new TypeError(`Invalid string format (${format}): ${input}`);
47
149
  }
48
150
  }
151
+ /**
152
+ * Validates and returns a string as the specified format type, throwing if invalid.
153
+ *
154
+ * This is useful when you need to convert a string to a format type in an expression.
155
+ *
156
+ * @typeParam I - The input string type
157
+ * @typeParam F - The format to validate against
158
+ * @param input - The string to validate
159
+ * @param format - The format name to validate against
160
+ * @returns The input typed as the format type
161
+ * @throws {TypeError} If the string doesn't match the format
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const did = asStringFormat(userInput, 'did')
166
+ * // did is typed as DidString
167
+ * ```
168
+ */
49
169
  /*@__NO_SIDE_EFFECTS__*/
50
170
  function asStringFormat(input, format) {
51
171
  assertStringFormat(input, format);
52
172
  return input;
53
173
  }
174
+ /**
175
+ * Returns the string as the format type if valid, otherwise returns `undefined`.
176
+ *
177
+ * This is useful for optional validation where you want to handle invalid values
178
+ * without throwing.
179
+ *
180
+ * @typeParam I - The input string type
181
+ * @typeParam F - The format to validate against
182
+ * @param input - The string to validate
183
+ * @param format - The format name to validate against
184
+ * @returns The typed string if valid, otherwise `undefined`
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const did = ifStringFormat(maybeInvalid, 'did')
189
+ * if (did) {
190
+ * // did is typed as DidString
191
+ * }
192
+ * ```
193
+ */
54
194
  /*@__NO_SIDE_EFFECTS__*/
55
195
  function ifStringFormat(input, format) {
56
196
  return isStringFormat(input, format) ? input : undefined;
57
197
  }
198
+ /**
199
+ * Array of all valid string format names.
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * for (const format of STRING_FORMATS) {
204
+ * console.log(format) // 'at-identifier', 'at-uri', 'cid', ...
205
+ * }
206
+ * ```
207
+ */
58
208
  exports.STRING_FORMATS = Object.freeze(
59
209
  /*#__PURE__*/ Object.keys(stringFormatVerifiers));
60
210
  //# sourceMappingURL=string-format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"string-format.js","sourceRoot":"","sources":["../../src/core/string-format.ts"],"names":[],"mappings":";;;AAoGA,wCASC;AAGD,gDAOC;AAGD,wCAMC;AAGD,wCAKC;AAxID,gDAAqD;AACrD,4CAoBwB;AAMX,QAAA,oBAAoB,GAAgC,4BAAW,CAAA;AAG/D,QAAA,aAAa,GAAyB,qBAAY,CAAA;AAGlD,QAAA,WAAW,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,4BAAiB,EAAC,CAAC,CAAC,CAAuB,CAAA;AAGjE,QAAA,gBAAgB,GAA4B,wBAAe,CAAA;AAG3D,QAAA,WAAW,GAAuB,mBAAU,CAAA;AAG5C,QAAA,cAAc,GAA0B,s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AAA;AACd,CAAC;AAED,wBAAwB;AACxB,SAAgB,cAAc,CAC5B,KAAQ,EACR,MAAS;IAET,OAAO,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1D,CAAC;AAEY,QAAA,cAAc,GAAiB,MAAM,CAAC,MAAM;AACvD,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CACtB,CAAA","sourcesContent":["import { validateCidString } from '@atproto/lex-data'\nimport {\n AtIdentifierString,\n AtUriString,\n DatetimeString,\n DidString,\n HandleString,\n NsidString,\n RecordKeyString,\n TidString,\n UriString,\n isValidAtIdentifier as isValidAtId,\n isValidAtUri,\n isValidDatetime,\n isValidDid,\n isValidHandle,\n isValidLanguage,\n isValidNsid,\n isValidRecordKey,\n isValidTid,\n isValidUri,\n} from '@atproto/syntax'\nimport { CheckFn } from '../util/assertion-util.js'\n\n// Expose all individual string format types and type guards\n\nexport type { AtIdentifierString }\nexport const isAtIdentifierString: CheckFn<AtIdentifierString> = isValidAtId\n\nexport type { AtUriString }\nexport const isAtUriString: CheckFn<AtUriString> = isValidAtUri\n\nexport type CidString = string\nexport const isCidString = ((v) => validateCidString(v)) as CheckFn<CidString>\n\nexport type { DatetimeString }\nexport const isDatetimeString: CheckFn<DatetimeString> = isValidDatetime\n\nexport type { DidString }\nexport const isDidString: CheckFn<DidString> = isValidDid\n\nexport type { HandleString }\nexport const isHandleString: CheckFn<HandleString> = isValidHandle\n\nexport type LanguageString = string\nexport const isLanguageString = isValidLanguage as CheckFn<LanguageString>\n\nexport type { NsidString }\nexport const isNsidString: CheckFn<NsidString> = isValidNsid\n\nexport type { RecordKeyString }\nexport const isRecordKeyString: CheckFn<RecordKeyString> = isValidRecordKey\n\nexport type { TidString }\nexport const isTidString: CheckFn<TidString> = isValidTid\n\nexport type { UriString }\nexport const isUriString: CheckFn<UriString> = isValidUri\n\n// String format registry (maps format names to their types and type guards)\n\ntype StringFormats = {\n 'at-identifier': AtIdentifierString\n 'at-uri': AtUriString\n cid: CidString\n datetime: DatetimeString\n did: DidString\n handle: HandleString\n language: LanguageString\n nsid: NsidString\n 'record-key': RecordKeyString\n tid: TidString\n uri: UriString\n}\n\nexport type StringFormat = Extract<keyof StringFormats, string>\n\nconst stringFormatVerifiers: {\n readonly [K in StringFormat]: CheckFn<StringFormats[K]>\n} = /*#__PURE__*/ Object.freeze({\n __proto__: null,\n\n 'at-identifier': isAtIdentifierString,\n 'at-uri': isAtUriString,\n cid: isCidString,\n datetime: isDatetimeString,\n did: isDidString,\n handle: isHandleString,\n language: isLanguageString,\n nsid: isNsidString,\n 'record-key': isRecordKeyString,\n tid: isTidString,\n uri: isUriString,\n})\n\nexport type InferStringFormat<F extends StringFormat> = F extends StringFormat\n ? StringFormats[F]\n : never\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function isStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): input is I & StringFormats[F] {\n const formatVerifier = stringFormatVerifiers[format]\n // Fool-proof\n if (!formatVerifier) throw new TypeError(`Unknown string format: ${format}`)\n\n return formatVerifier(input)\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function assertStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): asserts input is I & StringFormats[F] {\n if (!isStringFormat(input, format)) {\n throw new TypeError(`Invalid string format (${format}): ${input}`)\n }\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function asStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): I & StringFormats[F] {\n assertStringFormat(input, format)\n return input\n}\n\n/*@__NO_SIDE_EFFECTS__*/\nexport function ifStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): undefined | (I & StringFormats[F]) {\n return isStringFormat(input, format) ? input : undefined\n}\n\nexport const STRING_FORMATS = /*#__PURE__*/ Object.freeze(\n /*#__PURE__*/ Object.keys(stringFormatVerifiers),\n) as readonly StringFormat[]\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B,GAAG,EAAE,mBAAW;IAChB,GAAG,EAAE,mBAAW;CACjB,CAAC,CAAA;AAiBF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAwB;AACxB,SAAgB,cAAc,CAC5B,KAAQ,EACR,MAAS;IAET,MAAM,cAAc,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAA;IACpD,aAAa;IACb,IAAI,CAAC,cAAc;QAAE,MAAM,IAAI,SAAS,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAA;IAE5E,OAAO,cAAc,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAwB;AACxB,SAAgB,kBAAkB,CAChC,KAAQ,EACR,MAAS;IAET,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,SAAS,CAAC,0BAA0B,MAAM,MAAM,KAAK,EAAE,CAAC,CAAA;IACpE,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAwB;AACxB,SAAgB,cAAc,CAC5B,KAAQ,EACR,MAAS;IAET,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACjC,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAwB;AACxB,SAAgB,cAAc,CAC5B,KAAQ,EACR,MAAS;IAET,OAAO,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACU,QAAA,cAAc,GAAiB,MAAM,CAAC,MAAM;AACvD,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CACtB,CAAA","sourcesContent":["import { validateCidString } from '@atproto/lex-data'\nimport {\n AtIdentifierString,\n AtUriString,\n DatetimeString,\n DidString,\n HandleString,\n NsidString,\n RecordKeyString,\n TidString,\n UriString,\n isValidAtIdentifier as isValidAtId,\n isValidAtUri,\n isValidDatetime,\n isValidDid,\n isValidHandle,\n isValidLanguage,\n isValidNsid,\n isValidRecordKey,\n isValidTid,\n isValidUri,\n} from '@atproto/syntax'\nimport { CheckFn } from '../util/assertion-util.js'\n\n// -----------------------------------------------------------------------------\n// Individual string format types and type guards\n// -----------------------------------------------------------------------------\n\n/**\n * Type guard that checks if a value is a valid AT identifier (DID or handle).\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid AT identifier\n */\nexport const isAtIdentifierString: CheckFn<AtIdentifierString> = isValidAtId\nexport type {\n /**\n * An AT identifier string - either a DID or a handle.\n *\n * @example `\"did:plc:1234...\"` or `\"alice.bsky.social\"`\n */\n AtIdentifierString,\n}\n\n/**\n * Type guard that checks if a value is a valid AT URI.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid AT URI\n */\nexport const isAtUriString: CheckFn<AtUriString> = isValidAtUri\nexport type {\n /**\n * An AT URI string pointing to a resource in the AT Protocol network.\n *\n * @example `\"at://did:plc:1234.../app.bsky.feed.post/3k2...\"`\n */\n AtUriString,\n}\n\n/**\n * Type guard that checks if a value is a valid CID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid CID string\n */\nexport const isCidString = ((v) => validateCidString(v)) as CheckFn<CidString>\n/**\n * A Content Identifier (CID) string.\n *\n * CIDs are self-describing content addresses used to identify data by its hash.\n *\n * @example `\"bafyreig...\"`\n */\nexport type CidString = string\n\n/**\n * Type guard that checks if a value is a valid datetime string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid datetime string\n */\nexport const isDatetimeString: CheckFn<DatetimeString> = isValidDatetime\nexport type {\n /**\n * An ISO 8601 datetime string.\n *\n * @example `\"2024-01-15T12:30:00.000Z\"`\n */\n DatetimeString,\n}\n\n/**\n * Type guard that checks if a value is a valid DID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid DID string\n */\nexport const isDidString: CheckFn<DidString> = isValidDid\nexport type {\n /**\n * A Decentralized Identifier (DID) string.\n *\n * DIDs are globally unique identifiers that don't require a central authority.\n *\n * @example `\"did:plc:1234abcd...\"` or `\"did:web:example.com\"`\n */\n DidString,\n}\n\n/**\n * Type guard that checks if a value is a valid handle string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid handle string\n */\nexport const isHandleString: CheckFn<HandleString> = isValidHandle\nexport type {\n /**\n * A handle string - a human-readable identifier for users.\n *\n * @example `\"alice.bsky.social\"` or `\"bob.example.com\"`\n */\n HandleString,\n}\n\n/**\n * Type guard that checks if a value is a valid BCP-47 language tag.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid language string\n */\nexport const isLanguageString = isValidLanguage as CheckFn<LanguageString>\n/**\n * A BCP-47 language tag string.\n *\n * @example `\"en\"`, `\"en-US\"`, `\"zh-Hans\"`\n */\nexport type LanguageString = string\n\n/**\n * Type guard that checks if a value is a valid NSID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid NSID string\n */\nexport const isNsidString: CheckFn<NsidString> = isValidNsid\nexport type {\n /**\n * A Namespaced Identifier (NSID) string identifying a lexicon.\n *\n * NSIDs use reverse-domain notation to identify schemas.\n *\n * @example `\"app.bsky.feed.post\"`, `\"com.atproto.repo.createRecord\"`\n */\n NsidString,\n}\n\n/**\n * Type guard that checks if a value is a valid record key string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid record key string\n */\nexport const isRecordKeyString: CheckFn<RecordKeyString> = isValidRecordKey\nexport type {\n /**\n * A record key string identifying a record within a collection.\n *\n * @example `\"3k2...\"` (TID format) or `\"self\"` (literal key)\n */\n RecordKeyString,\n}\n\n/**\n * Type guard that checks if a value is a valid TID string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid TID string\n */\nexport const isTidString: CheckFn<TidString> = isValidTid\nexport type {\n /**\n * A Timestamp Identifier (TID) string.\n *\n * TIDs are time-based identifiers used for record keys.\n *\n * @example `\"3k2...\"`\n */\n TidString,\n}\n\n/**\n * Type guard that checks if a value is a valid URI string.\n *\n * @param value - The value to check\n * @returns `true` if the value is a valid URI string\n */\nexport const isUriString: CheckFn<UriString> = isValidUri\nexport type {\n /**\n * A standard URI string.\n *\n * @example `\"https://example.com/path\"`\n */\n UriString,\n}\n\n// -----------------------------------------------------------------------------\n// String format registry\n// -----------------------------------------------------------------------------\n\ntype StringFormats = {\n 'at-identifier': AtIdentifierString\n 'at-uri': AtUriString\n cid: CidString\n datetime: DatetimeString\n did: DidString\n handle: HandleString\n language: LanguageString\n nsid: NsidString\n 'record-key': RecordKeyString\n tid: TidString\n uri: UriString\n}\n\n/**\n * Union type of all valid string format names.\n */\nexport type StringFormat = Extract<keyof StringFormats, string>\n\nconst stringFormatVerifiers: {\n readonly [K in StringFormat]: CheckFn<StringFormats[K]>\n} = /*#__PURE__*/ Object.freeze({\n __proto__: null,\n\n 'at-identifier': isAtIdentifierString,\n 'at-uri': isAtUriString,\n cid: isCidString,\n datetime: isDatetimeString,\n did: isDidString,\n handle: isHandleString,\n language: isLanguageString,\n nsid: isNsidString,\n 'record-key': isRecordKeyString,\n tid: isTidString,\n uri: isUriString,\n})\n\n/**\n * Infers the string type for a given format name.\n *\n * @typeParam F - The format name\n *\n * @example\n * ```typescript\n * type Did = InferStringFormat<'did'>\n * // Result: DidString\n * ```\n */\nexport type InferStringFormat<F extends StringFormat> = F extends StringFormat\n ? StringFormats[F]\n : never\n\n/**\n * Type guard that checks if a string matches a specific format.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to check\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns `true` if the string matches the format\n *\n * @example\n * ```typescript\n * const value: string = 'did:plc:1234...'\n * if (isStringFormat(value, 'did')) {\n * // value is typed as DidString\n * console.log('Valid DID:', value)\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function isStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): input is I & StringFormats[F] {\n const formatVerifier = stringFormatVerifiers[format]\n // Fool-proof\n if (!formatVerifier) throw new TypeError(`Unknown string format: ${format}`)\n\n return formatVerifier(input)\n}\n\n/**\n * Asserts that a string matches a specific format, throwing if invalid.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to check\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @throws {TypeError} If the string doesn't match the format\n *\n * @example\n * ```typescript\n * assertStringFormat(value, 'handle')\n * // value is now typed as HandleString\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function assertStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): asserts input is I & StringFormats[F] {\n if (!isStringFormat(input, format)) {\n throw new TypeError(`Invalid string format (${format}): ${input}`)\n }\n}\n\n/**\n * Validates and returns a string as the specified format type, throwing if invalid.\n *\n * This is useful when you need to convert a string to a format type in an expression.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to validate against\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns The input typed as the format type\n * @throws {TypeError} If the string doesn't match the format\n *\n * @example\n * ```typescript\n * const did = asStringFormat(userInput, 'did')\n * // did is typed as DidString\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function asStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): I & StringFormats[F] {\n assertStringFormat(input, format)\n return input\n}\n\n/**\n * Returns the string as the format type if valid, otherwise returns `undefined`.\n *\n * This is useful for optional validation where you want to handle invalid values\n * without throwing.\n *\n * @typeParam I - The input string type\n * @typeParam F - The format to validate against\n * @param input - The string to validate\n * @param format - The format name to validate against\n * @returns The typed string if valid, otherwise `undefined`\n *\n * @example\n * ```typescript\n * const did = ifStringFormat(maybeInvalid, 'did')\n * if (did) {\n * // did is typed as DidString\n * }\n * ```\n */\n/*@__NO_SIDE_EFFECTS__*/\nexport function ifStringFormat<I extends string, F extends StringFormat>(\n input: I,\n format: F,\n): undefined | (I & StringFormats[F]) {\n return isStringFormat(input, format) ? input : undefined\n}\n\n/**\n * Array of all valid string format names.\n *\n * @example\n * ```typescript\n * for (const format of STRING_FORMATS) {\n * console.log(format) // 'at-identifier', 'at-uri', 'cid', ...\n * }\n * ```\n */\nexport const STRING_FORMATS = /*#__PURE__*/ Object.freeze(\n /*#__PURE__*/ Object.keys(stringFormatVerifiers),\n) as readonly StringFormat[]\n"]}
@@ -1,28 +1,115 @@
1
1
  /**
2
- * Same as {@link string} but prevents TypeScript allowing union types to
2
+ * Same as `string` but prevents TypeScript from allowing union types to
3
3
  * be widened to `string` in IDEs.
4
+ *
5
+ * This is useful when you want autocompletion for known string values
6
+ * while still allowing arbitrary strings.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // With plain string, union is widened:
11
+ * type Status1 = 'active' | 'inactive' | string // just becomes "string"
12
+ *
13
+ * // With UnknownString, union is preserved:
14
+ * type Status2 = 'active' | 'inactive' | UnknownString
15
+ * // Autocomplete will suggest 'active' and 'inactive'
16
+ * ```
4
17
  */
5
18
  export type UnknownString = string & NonNullable<unknown>;
19
+ /**
20
+ * Simplifies a type by expanding intersections and mapped types.
21
+ *
22
+ * This improves IDE tooltips by showing the actual shape of a type
23
+ * rather than complex intersections.
24
+ *
25
+ * @typeParam T - The type to simplify
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * type Complex = { a: string } & { b: number }
30
+ * type Simple = Simplify<Complex>
31
+ * // Hover shows: { a: string; b: number }
32
+ * ```
33
+ */
6
34
  export type Simplify<T> = {
7
35
  [K in keyof T]: T[K];
8
36
  } & NonNullable<unknown>;
37
+ /**
38
+ * Internal symbol for branding restricted types.
39
+ * @internal
40
+ */
9
41
  declare const __restricted: unique symbol;
10
42
  /**
11
43
  * A type that represents a value that cannot be used, with a custom
12
44
  * message explaining the restriction.
45
+ *
46
+ * This is useful for creating "never use this" types that provide
47
+ * helpful error messages when someone tries to use them.
48
+ *
49
+ * @typeParam Message - A string literal type containing the error message
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * type DeprecatedField = Restricted<'This field has been deprecated. Use newField instead.'>
54
+ *
55
+ * interface MyType {
56
+ * oldField?: DeprecatedField
57
+ * newField: string
58
+ * }
59
+ *
60
+ * const obj: MyType = {
61
+ * oldField: 'value', // Error: Type 'string' is not assignable to type 'Restricted<...>'
62
+ * newField: 'value'
63
+ * }
64
+ * ```
13
65
  */
14
66
  export type Restricted<Message extends string> = typeof __restricted & {
15
67
  [__restricted]: Message;
16
68
  };
17
69
  /**
18
- * Converts all properties of `P` that are optional (i.e. may be `undefined`)
19
- * into actual optional properties on the resulting type.
70
+ * Converts all properties of `P` that may be `undefined` into actual
71
+ * optional properties on the resulting type.
72
+ *
73
+ * This is useful when working with types where some properties are typed as
74
+ * `T | undefined` but should really be optional (`T?`).
75
+ *
76
+ * @typeParam P - The object type to transform
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * type Input = {
81
+ * required: string
82
+ * optional: string | undefined
83
+ * }
84
+ *
85
+ * type Output = WithOptionalProperties<Input>
86
+ * // Result: {
87
+ * // required: string
88
+ * // optional?: string | undefined
89
+ * // }
90
+ * ```
20
91
  */
21
92
  export type WithOptionalProperties<P> = Simplify<{
22
93
  -readonly [K in keyof P as undefined extends P[K] ? never : K]-?: P[K];
23
94
  } & {
24
95
  -readonly [K in keyof P as undefined extends P[K] ? K : never]?: P[K];
25
96
  }>;
97
+ /**
98
+ * Creates a type by omitting a specific key from an object type.
99
+ *
100
+ * Similar to TypeScript's built-in `Omit`, but preserves the type structure
101
+ * more accurately in some edge cases.
102
+ *
103
+ * @typeParam T - The object type to transform
104
+ * @typeParam K - The key to omit (must be a key of T)
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * type Person = { name: string; age: number; email: string }
109
+ * type PersonWithoutEmail = OmitKey<Person, 'email'>
110
+ * // Result: { name: string; age: number }
111
+ * ```
112
+ */
26
113
  export type OmitKey<T, K extends keyof T> = {
27
114
  [K2 in keyof T as K2 extends K ? never : K2]: T[K2];
28
115
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],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AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;AAEzE;;;GAGG;AACH,OAAO,CAAC,MAAM,YAAY,EAAE,OAAO,MAAM,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,MAAM,IAAI,OAAO,YAAY,GAAG;IACrE,CAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,QAAQ,CAC9C;IACE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACvE,GAAG;IACF,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACtE,CACF,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI;KACzC,EAAE,IAAI,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;CACpD,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Same as {@link string} but prevents TypeScript allowing union types to\n * be widened to `string` in IDEs.\n */\nexport type UnknownString = string & NonNullable<unknown>\n\nexport type Simplify<T> = { [K in keyof T]: T[K] } & NonNullable<unknown>\n\ndeclare const __restricted: unique symbol\n/**\n * A type that represents a value that cannot be used, with a custom\n * message explaining the restriction.\n */\nexport type Restricted<Message extends string> = typeof __restricted & {\n [__restricted]: Message\n}\n\n/**\n * Converts all properties of `P` that are optional (i.e. may be `undefined`)\n * into actual optional properties on the resulting type.\n */\nexport type WithOptionalProperties<P> = Simplify<\n {\n -readonly [K in keyof P as undefined extends P[K] ? never : K]-?: P[K]\n } & {\n -readonly [K in keyof P as undefined extends P[K] ? K : never]?: P[K]\n }\n>\n\nexport type OmitKey<T, K extends keyof T> = {\n [K2 in keyof T as K2 extends K ? never : K2]: T[K2]\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Same as `string` but prevents TypeScript from allowing union types to\n * be widened to `string` in IDEs.\n *\n * This is useful when you want autocompletion for known string values\n * while still allowing arbitrary strings.\n *\n * @example\n * ```typescript\n * // With plain string, union is widened:\n * type Status1 = 'active' | 'inactive' | string // just becomes \"string\"\n *\n * // With UnknownString, union is preserved:\n * type Status2 = 'active' | 'inactive' | UnknownString\n * // Autocomplete will suggest 'active' and 'inactive'\n * ```\n */\nexport type UnknownString = string & NonNullable<unknown>\n\n/**\n * Simplifies a type by expanding intersections and mapped types.\n *\n * This improves IDE tooltips by showing the actual shape of a type\n * rather than complex intersections.\n *\n * @typeParam T - The type to simplify\n *\n * @example\n * ```typescript\n * type Complex = { a: string } & { b: number }\n * type Simple = Simplify<Complex>\n * // Hover shows: { a: string; b: number }\n * ```\n */\nexport type Simplify<T> = { [K in keyof T]: T[K] } & NonNullable<unknown>\n\n/**\n * Internal symbol for branding restricted types.\n * @internal\n */\ndeclare const __restricted: unique symbol\n\n/**\n * A type that represents a value that cannot be used, with a custom\n * message explaining the restriction.\n *\n * This is useful for creating \"never use this\" types that provide\n * helpful error messages when someone tries to use them.\n *\n * @typeParam Message - A string literal type containing the error message\n *\n * @example\n * ```typescript\n * type DeprecatedField = Restricted<'This field has been deprecated. Use newField instead.'>\n *\n * interface MyType {\n * oldField?: DeprecatedField\n * newField: string\n * }\n *\n * const obj: MyType = {\n * oldField: 'value', // Error: Type 'string' is not assignable to type 'Restricted<...>'\n * newField: 'value'\n * }\n * ```\n */\nexport type Restricted<Message extends string> = typeof __restricted & {\n [__restricted]: Message\n}\n\n/**\n * Converts all properties of `P` that may be `undefined` into actual\n * optional properties on the resulting type.\n *\n * This is useful when working with types where some properties are typed as\n * `T | undefined` but should really be optional (`T?`).\n *\n * @typeParam P - The object type to transform\n *\n * @example\n * ```typescript\n * type Input = {\n * required: string\n * optional: string | undefined\n * }\n *\n * type Output = WithOptionalProperties<Input>\n * // Result: {\n * // required: string\n * // optional?: string | undefined\n * // }\n * ```\n */\nexport type WithOptionalProperties<P> = Simplify<\n {\n -readonly [K in keyof P as undefined extends P[K] ? never : K]-?: P[K]\n } & {\n -readonly [K in keyof P as undefined extends P[K] ? K : never]?: P[K]\n }\n>\n\n/**\n * Creates a type by omitting a specific key from an object type.\n *\n * Similar to TypeScript's built-in `Omit`, but preserves the type structure\n * more accurately in some edge cases.\n *\n * @typeParam T - The object type to transform\n * @typeParam K - The key to omit (must be a key of T)\n *\n * @example\n * ```typescript\n * type Person = { name: string; age: number; email: string }\n * type PersonWithoutEmail = OmitKey<Person, 'email'>\n * // Result: { name: string; age: number }\n * ```\n */\nexport type OmitKey<T, K extends keyof T> = {\n [K2 in keyof T as K2 extends K ? never : K2]: T[K2]\n}\n"]}