@wener/common 2.0.3 → 2.0.6

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 (312) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/qwen3vl/utils.js.map +1 -1
  4. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  5. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  6. package/lib/ai/vision/index.js +2 -2
  7. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  8. package/lib/cn/ChineseResidentIdNo.js +55 -41
  9. package/lib/cn/ChineseResidentIdNo.js.map +1 -1
  10. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  11. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  12. package/lib/cn/DivisionCode.js +220 -235
  13. package/lib/cn/DivisionCode.mod.js +6 -1
  14. package/lib/cn/DivisionCode.test.js +92 -121
  15. package/lib/cn/Mod11.js +18 -37
  16. package/lib/cn/Mod11.js.map +1 -1
  17. package/lib/cn/Mod31.js +23 -41
  18. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  19. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  20. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  21. package/lib/cn/formatChineseAmount.js +46 -71
  22. package/lib/cn/index.js +6 -6
  23. package/lib/cn/mod.js +5 -3
  24. package/lib/cn/parseChineseNumber.js +81 -85
  25. package/lib/cn/parseChineseNumber.test.js +183 -261
  26. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  27. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  28. package/lib/cn/pinyin/loader.js +13 -11
  29. package/lib/cn/pinyin/preload.js +2 -1
  30. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  31. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  32. package/lib/cn/pinyin/transform.js +11 -11
  33. package/lib/cn/types.d.js +2 -2
  34. package/lib/consola/createStandardConsolaReporter.js +14 -15
  35. package/lib/consola/formatLogObject.js +149 -133
  36. package/lib/consola/formatLogObject.js.map +1 -1
  37. package/lib/consola/formatLogObject.test.js +167 -178
  38. package/lib/consola/index.js +2 -2
  39. package/lib/data/formatSort.js +14 -12
  40. package/lib/data/formatSort.test.js +33 -33
  41. package/lib/data/index.js +3 -3
  42. package/lib/data/maybeNumber.js +23 -23
  43. package/lib/data/maybeNumber.js.map +1 -1
  44. package/lib/data/parseSort.js +75 -68
  45. package/lib/data/parseSort.test.js +196 -187
  46. package/lib/data/resolvePagination.js +38 -39
  47. package/lib/data/resolvePagination.test.js +228 -218
  48. package/lib/data/types.d.js +2 -2
  49. package/lib/data/types.d.js.map +1 -1
  50. package/lib/dayjs/dayjs.js +20 -20
  51. package/lib/dayjs/formatDuration.js +56 -56
  52. package/lib/dayjs/formatDuration.js.map +1 -1
  53. package/lib/dayjs/formatDuration.test.js +63 -77
  54. package/lib/dayjs/index.js +4 -4
  55. package/lib/dayjs/parseDuration.js +21 -26
  56. package/lib/dayjs/parseRelativeTime.js +65 -66
  57. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  58. package/lib/dayjs/resolveRelativeTime.js +74 -144
  59. package/lib/dayjs/resolveRelativeTime.js.map +1 -1
  60. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  61. package/lib/decimal/index.js +1 -1
  62. package/lib/decimal/parseDecimal.js +12 -12
  63. package/lib/drain3/Drain.js +321 -0
  64. package/lib/drain3/Drain.js.map +1 -0
  65. package/lib/drain3/LogCluster.js +38 -0
  66. package/lib/drain3/LogCluster.js.map +1 -0
  67. package/lib/drain3/Node.js +39 -0
  68. package/lib/drain3/Node.js.map +1 -0
  69. package/lib/drain3/TemplateMiner.js +205 -0
  70. package/lib/drain3/TemplateMiner.js.map +1 -0
  71. package/lib/drain3/index.js +31 -0
  72. package/lib/drain3/index.js.map +1 -0
  73. package/lib/drain3/persistence/FilePersistence.js +24 -0
  74. package/lib/drain3/persistence/FilePersistence.js.map +1 -0
  75. package/lib/drain3/persistence/MemoryPersistence.js +18 -0
  76. package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
  77. package/lib/drain3/persistence/PersistenceHandler.js +5 -0
  78. package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
  79. package/lib/drain3/types.js +7 -0
  80. package/lib/drain3/types.js.map +1 -0
  81. package/lib/emittery/emitter.js +7 -7
  82. package/lib/emittery/index.js +1 -1
  83. package/lib/foundation/schema/SexType.js +15 -12
  84. package/lib/foundation/schema/index.js +1 -1
  85. package/lib/foundation/schema/parseSexType.js +15 -16
  86. package/lib/foundation/schema/types.js +8 -6
  87. package/lib/fs/FileSystemError.js +18 -18
  88. package/lib/fs/IFileSystem.d.js +2 -2
  89. package/lib/fs/IFileSystem.d.js.map +1 -1
  90. package/lib/fs/MemoryFileSystem.test.js +172 -181
  91. package/lib/fs/createBrowserFileSystem.js +222 -233
  92. package/lib/fs/createBrowserFileSystem.js.map +1 -1
  93. package/lib/fs/createMemoryFileSystem.js +473 -510
  94. package/lib/fs/createMemoryFileSystem.js.map +1 -1
  95. package/lib/fs/createSandboxFileSystem.js +102 -101
  96. package/lib/fs/createSandboxFileSystem.js.map +1 -1
  97. package/lib/fs/createWebDavFileSystem.js +162 -132
  98. package/lib/fs/createWebDavFileSystem.js.map +1 -1
  99. package/lib/fs/createWebFileSystem.js +202 -0
  100. package/lib/fs/createWebFileSystem.js.map +1 -0
  101. package/lib/fs/findMimeType.js +14 -14
  102. package/lib/fs/findMimeType.js.map +1 -1
  103. package/lib/fs/index.js +7 -7
  104. package/lib/fs/index.js.map +1 -1
  105. package/lib/fs/minio/createMinioFileSystem.js +977 -0
  106. package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
  107. package/lib/fs/minio/index.js +2 -0
  108. package/lib/fs/minio/index.js.map +1 -0
  109. package/lib/fs/orpc/FileSystemContract.js +57 -57
  110. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  111. package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
  112. package/lib/fs/orpc/index.js +2 -2
  113. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  114. package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
  115. package/lib/fs/orpc/server/index.js +1 -1
  116. package/lib/fs/s3/createS3MiniFileSystem.js +756 -689
  117. package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
  118. package/lib/fs/s3/index.js +1 -1
  119. package/lib/fs/s3/s3mini.test.js +524 -553
  120. package/lib/fs/scandir.js +56 -56
  121. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  122. package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
  123. package/lib/fs/server/createNodeFileSystem.js +407 -380
  124. package/lib/fs/server/createNodeFileSystem.js.map +1 -1
  125. package/lib/fs/server/dbfs.test.js +201 -214
  126. package/lib/fs/server/index.js +1 -1
  127. package/lib/fs/server/loadTestDatabase.js +40 -43
  128. package/lib/fs/tests/runFileSystemTest.js +352 -315
  129. package/lib/fs/tests/runFileSystemTest.js.map +1 -1
  130. package/lib/fs/types.js +17 -20
  131. package/lib/fs/utils/getFileUrl.js +24 -30
  132. package/lib/fs/utils.js +17 -17
  133. package/lib/fs/utils.js.map +1 -1
  134. package/lib/fs/webdav/index.js +2 -0
  135. package/lib/fs/webdav/index.js.map +1 -0
  136. package/lib/index.js +2 -2
  137. package/lib/jsonschema/JsonSchema.js +216 -155
  138. package/lib/jsonschema/JsonSchema.js.map +1 -1
  139. package/lib/jsonschema/JsonSchema.test.js +123 -124
  140. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  141. package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
  142. package/lib/jsonschema/index.js +2 -2
  143. package/lib/jsonschema/types.d.js +2 -2
  144. package/lib/jsonschema/types.d.js.map +1 -1
  145. package/lib/meta/defineFileType.js +32 -38
  146. package/lib/meta/defineInit.js +39 -35
  147. package/lib/meta/defineMetadata.js +37 -34
  148. package/lib/meta/defineMetadata.js.map +1 -1
  149. package/lib/meta/defineMetadata.test.js +13 -12
  150. package/lib/meta/index.js +3 -3
  151. package/lib/orpc/createOpenApiContractClient.js +26 -24
  152. package/lib/orpc/createOpenApiContractClient.js.map +1 -1
  153. package/lib/orpc/createRpcContractClient.js +37 -31
  154. package/lib/orpc/index.js +2 -2
  155. package/lib/orpc/resolveLinkPlugins.js +25 -25
  156. package/lib/password/PHC.js +187 -189
  157. package/lib/password/PHC.js.map +1 -1
  158. package/lib/password/PHC.test.js +517 -535
  159. package/lib/password/Password.js +85 -80
  160. package/lib/password/Password.test.js +330 -364
  161. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  162. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
  163. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  164. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
  165. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  166. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
  167. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  168. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
  169. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  170. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
  171. package/lib/password/index.js +5 -5
  172. package/lib/password/server/index.js +1 -1
  173. package/lib/resource/Identifiable.js +2 -2
  174. package/lib/resource/ListQuery.js +42 -42
  175. package/lib/resource/ListQuery.js.map +1 -1
  176. package/lib/resource/getTitleOfResource.js +5 -5
  177. package/lib/resource/index.js +2 -2
  178. package/lib/resource/index.js.map +1 -1
  179. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  180. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  181. package/lib/resource/schema/ResourceActionType.js +117 -115
  182. package/lib/resource/schema/ResourceStatus.js +94 -92
  183. package/lib/resource/schema/ResourceType.js +25 -23
  184. package/lib/resource/schema/index.js +5 -5
  185. package/lib/resource/schema/types.js +86 -55
  186. package/lib/resource/schema/types.test.js +16 -13
  187. package/lib/s3/formatS3Url.js +60 -60
  188. package/lib/s3/formatS3Url.js.map +1 -1
  189. package/lib/s3/formatS3Url.test.js +238 -261
  190. package/lib/s3/index.js +2 -2
  191. package/lib/s3/parseS3Url.js +61 -60
  192. package/lib/s3/parseS3Url.js.map +1 -1
  193. package/lib/s3/parseS3Url.test.js +270 -269
  194. package/lib/schema/SchemaRegistry.js +41 -42
  195. package/lib/schema/SchemaRegistry.js.map +1 -1
  196. package/lib/schema/SchemaRegistry.mod.js +1 -1
  197. package/lib/schema/TypeSchema.d.js +2 -2
  198. package/lib/schema/TypeSchema.d.js.map +1 -1
  199. package/lib/schema/createSchemaData.js +113 -67
  200. package/lib/schema/createSchemaData.js.map +1 -1
  201. package/lib/schema/findJsonSchemaByPath.js +28 -23
  202. package/lib/schema/findJsonSchemaByPath.js.map +1 -1
  203. package/lib/schema/formatZodError.js +113 -134
  204. package/lib/schema/formatZodError.js.map +1 -1
  205. package/lib/schema/formatZodError.test.js +192 -195
  206. package/lib/schema/getSchemaCache.js +7 -7
  207. package/lib/schema/getSchemaOptions.js +17 -16
  208. package/lib/schema/index.js +6 -6
  209. package/lib/schema/toJsonSchema.js +196 -190
  210. package/lib/schema/toJsonSchema.js.map +1 -1
  211. package/lib/schema/toJsonSchema.test.js +34 -26
  212. package/lib/schema/validate.js +106 -97
  213. package/lib/schema/validate.js.map +1 -1
  214. package/lib/tools/generateSchema.js +40 -40
  215. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  216. package/lib/utils/buildBaseUrl.js +8 -8
  217. package/lib/utils/buildRedactorFormSchema.js +55 -54
  218. package/lib/utils/buildRedactorFormSchema.js.map +1 -1
  219. package/lib/utils/getEstimateProcessTime.js +24 -19
  220. package/lib/utils/index.js +3 -3
  221. package/lib/utils/resolveFeatureOptions.js +9 -9
  222. package/package.json +37 -18
  223. package/src/ai/qwen3vl/utils.ts +1 -1
  224. package/src/ai/vision/index.ts +2 -2
  225. package/src/cn/ChineseResidentIdNo.ts +1 -1
  226. package/src/cn/Mod11.ts +1 -1
  227. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
  228. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
  229. package/src/cn/index.ts +1 -2
  230. package/src/cn/parseChineseNumber.test.ts +4 -4
  231. package/src/consola/formatLogObject.ts +6 -6
  232. package/src/consola/index.ts +1 -1
  233. package/src/data/index.ts +3 -4
  234. package/src/data/maybeNumber.ts +1 -1
  235. package/src/data/parseSort.test.ts +0 -1
  236. package/src/data/resolvePagination.ts +2 -2
  237. package/src/data/types.d.ts +2 -2
  238. package/src/dayjs/formatDuration.ts +10 -11
  239. package/src/dayjs/index.ts +1 -1
  240. package/src/dayjs/parseRelativeTime.ts +1 -1
  241. package/src/dayjs/resolveRelativeTime.ts +11 -14
  242. package/src/drain3/Drain.test.ts +378 -0
  243. package/src/drain3/Drain.ts +394 -0
  244. package/src/drain3/LogCluster.ts +46 -0
  245. package/src/drain3/Node.ts +53 -0
  246. package/src/drain3/TemplateMiner.ts +246 -0
  247. package/src/drain3/index.ts +34 -0
  248. package/src/drain3/persistence/FilePersistence.ts +24 -0
  249. package/src/drain3/persistence/MemoryPersistence.ts +23 -0
  250. package/src/drain3/persistence/PersistenceHandler.ts +19 -0
  251. package/src/drain3/types.ts +75 -0
  252. package/src/fs/IFileSystem.d.ts +1 -2
  253. package/src/fs/createBrowserFileSystem.ts +7 -5
  254. package/src/fs/createMemoryFileSystem.ts +9 -13
  255. package/src/fs/createSandboxFileSystem.ts +1 -1
  256. package/src/fs/createWebDavFileSystem.ts +30 -17
  257. package/src/fs/createWebFileSystem.ts +242 -0
  258. package/src/fs/findMimeType.ts +1 -4
  259. package/src/fs/index.ts +5 -5
  260. package/src/fs/minio/createMinioFileSystem.ts +1148 -0
  261. package/src/fs/minio/index.ts +1 -0
  262. package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
  263. package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
  264. package/src/fs/s3/createS3MiniFileSystem.ts +120 -79
  265. package/src/fs/s3/s3fs.test.ts +441 -0
  266. package/src/fs/s3/s3mini.test.ts +2 -2
  267. package/src/fs/server/createDatabaseFileSystem.ts +78 -114
  268. package/src/fs/server/createNodeFileSystem.ts +32 -13
  269. package/src/fs/server/dbfs.test.ts +13 -8
  270. package/src/fs/server/index.ts +1 -0
  271. package/src/fs/server/loadTestDatabase.ts +8 -119
  272. package/src/fs/tests/runFileSystemTest.ts +29 -28
  273. package/src/fs/utils.ts +1 -1
  274. package/src/fs/webdav/index.ts +1 -0
  275. package/src/jsonschema/JsonSchema.ts +5 -5
  276. package/src/jsonschema/forEachJsonSchema.ts +1 -1
  277. package/src/jsonschema/index.ts +1 -1
  278. package/src/jsonschema/types.d.ts +1 -1
  279. package/src/meta/defineMetadata.ts +1 -1
  280. package/src/meta/index.ts +2 -3
  281. package/src/orm/createSqliteDialect.ts +17 -0
  282. package/src/orm/index.ts +1 -0
  283. package/src/orpc/createOpenApiContractClient.ts +3 -3
  284. package/src/orpc/index.ts +1 -1
  285. package/src/password/PHC.ts +3 -3
  286. package/src/password/createArgon2PasswordAlgorithm.ts +2 -2
  287. package/src/password/createBase64PasswordAlgorithm.ts +2 -2
  288. package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
  289. package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
  290. package/src/password/createScryptPasswordAlgorithm.ts +4 -4
  291. package/src/password/index.ts +2 -2
  292. package/src/resource/ListQuery.ts +4 -1
  293. package/src/resource/index.ts +3 -3
  294. package/src/resource/schema/index.ts +4 -4
  295. package/src/s3/formatS3Url.test.ts +1 -1
  296. package/src/s3/formatS3Url.ts +2 -2
  297. package/src/s3/index.ts +1 -1
  298. package/src/s3/parseS3Url.ts +1 -1
  299. package/src/schema/SchemaRegistry.ts +2 -2
  300. package/src/schema/TypeSchema.d.ts +6 -6
  301. package/src/schema/createSchemaData.ts +5 -5
  302. package/src/schema/findJsonSchemaByPath.ts +5 -5
  303. package/src/schema/formatZodError.test.ts +2 -1
  304. package/src/schema/formatZodError.ts +50 -62
  305. package/src/schema/index.ts +5 -5
  306. package/src/schema/toJsonSchema.ts +6 -6
  307. package/src/schema/validate.ts +2 -2
  308. package/src/utils/buildRedactorFormSchema.ts +4 -4
  309. package/src/utils/formatNumber.ts +18 -0
  310. package/src/utils/formatPercent.ts +17 -0
  311. package/src/utils/index.ts +3 -3
  312. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,148 +1,78 @@
1
- import dayjs from "dayjs";
2
- import duration from "dayjs/plugin/duration";
3
- import quarterOfYear from "dayjs/plugin/quarterOfYear";
4
- import weekOfYear from "dayjs/plugin/weekOfYear";
1
+ import { parseDate } from '@wener/utils';
2
+ import dayjs from 'dayjs';
3
+ import duration from 'dayjs/plugin/duration';
4
+ import quarterOfYear from 'dayjs/plugin/quarterOfYear';
5
+ import weekOfYear from 'dayjs/plugin/weekOfYear';
6
+
5
7
  dayjs.extend(duration);
6
8
  dayjs.extend(quarterOfYear);
7
9
  dayjs.extend(weekOfYear);
8
- /**
9
- * Resolves a Grafana-style relative time string and returns the corresponding Date.
10
- *
11
- * @param s - The relative time string to parse (must start with "now")
12
- * @param now - Optional reference date. If undefined, uses current time
13
- * @returns The calculated Date based on the relative time expression
14
- *
15
- * @throws {Error} When the format is invalid or contains unsupported operators/units
16
- *
17
- * ## Syntax
18
- *
19
- * All expressions must start with `now` followed by optional operations:
20
- *
21
- * ### Operators
22
- * - `-` - Subtraction (e.g., `now-1h` for one hour ago)
23
- * - `+` - Addition (e.g., `now+1d` for one day from now)
24
- * - `/` - Truncation to beginning of time unit (e.g., `now/d` for start of current day)
25
- * - `\` - Truncation to end of time unit (e.g., `now\d` for end of current day)
26
- *
27
- * ### Time Units
28
- * - `s` - seconds
29
- * - `m` - minutes
30
- * - `h` - hours
31
- * - `d` - days
32
- * - `w` - weeks
33
- * - `M` - months
34
- * - `Q` - quarters
35
- * - `y` - years
36
- *
37
- * ### Operations
38
- * Operations are processed sequentially from left to right:
39
- * - **Addition/Subtraction**: `now±{count}{unit}` (e.g., `now-24h`, `now+1d`)
40
- * - **Truncation to start**: `now/{unit}` (e.g., `now/d`, `now/M`)
41
- * - **Truncation to end**: `now\{unit}` (e.g., `now\d`, `now\M`)
42
- * - **Complex**: Multiple operations can be chained (e.g., `now-1M/M`, `now\d`, `now-1y\y`)
43
- *
44
- * @example
45
- * ```typescript
46
- * // Basic usage
47
- * resolveRelativeTime('now') // Current time
48
- * resolveRelativeTime('now-1h') // One hour ago
49
- * resolveRelativeTime('now+1d') // One day from now
50
- * resolveRelativeTime('now/d') // Start of current day
51
- * resolveRelativeTime('now\\d') // End of current day
52
- *
53
- * // Common patterns
54
- * resolveRelativeTime('now-24h') // Last 24 hours
55
- * resolveRelativeTime('now-7d') // Last 7 days
56
- * resolveRelativeTime('now/M') // Start of current month
57
- * resolveRelativeTime('now\\M') // End of current month
58
- * resolveRelativeTime('now-1M/M') // Start of previous month
59
- * resolveRelativeTime('now-1M\\M') // End of previous month
60
- * resolveRelativeTime('now/w') // Start of current week
61
- * resolveRelativeTime('now\\w') // End of current week
62
- * resolveRelativeTime('now/y') // Start of current year
63
- * resolveRelativeTime('now\\y') // End of current year
64
- *
65
- * // Complex expressions
66
- * resolveRelativeTime('now/d+1d-1s') // End of current day (alternative method)
67
- * resolveRelativeTime('now\\d') // End of current day (direct method)
68
- * resolveRelativeTime('now-1w+2d-3h') // 1 week ago, plus 2 days, minus 3 hours
69
- *
70
- * // With reference date
71
- * const refDate = new Date('2024-03-15T14:30:45.123Z');
72
- * resolveRelativeTime('now-1h', refDate); // One hour before reference date
73
- * resolveRelativeTime('now\\d', refDate); // End of reference day
74
- * ```
75
- */ export function resolveRelativeTime(s, now) {
76
- {
77
- let out;
78
- if (!s) {} else if (s instanceof Date) {
79
- out = s;
80
- } else if (typeof s === 'number') {
81
- out = new Date(s);
82
- } else if (!s.startsWith('now')) {
83
- out = new Date(s);
84
- }
85
- if (out) {
86
- if (isNaN(out.getTime())) {
87
- throw new Error(`Invalid date: ${s}`);
88
- }
89
- return out;
90
- }
91
- }
92
- if (typeof s !== 'string' || !s.startsWith('now')) {
93
- throw new Error(`Invalid relative time format: ${s}`);
94
- }
95
- let current = dayjs(now);
96
- const remaining = s.slice(3); // Remove 'now'
97
- if (!remaining) {
98
- return current.toDate();
99
- }
100
- // Split by operators while keeping them in the result
101
- const parts = remaining.split(/([+\-/\\])/).filter((part)=>part !== '');
102
- for(let i = 0; i < parts.length; i += 2){
103
- const operator = parts[i];
104
- const operand = parts[i + 1];
105
- if (!operator || !operand) {
106
- throw new Error(`Invalid relative time format: ${s}`);
107
- }
108
- if (operator === '/') {
109
- // Truncation to start operation
110
- checkDurationUnit(operand);
111
- current = current.startOf(operand);
112
- } else if (operator === '\\') {
113
- // Truncation to end operation
114
- checkDurationUnit(operand);
115
- current = current.endOf(operand);
116
- } else {
117
- // Addition or subtraction operation
118
- const match = operand.match(/^(\d+)([smhdwMQy])$/);
119
- if (!match) {
120
- throw new Error(`Invalid time operand: ${operand}`);
121
- }
122
- const [, amountStr, unit] = match;
123
- checkDurationUnit(unit);
124
- const amount = parseInt(amountStr, 10);
125
- if (operator === '+') {
126
- current = current.add(amount, unit);
127
- } else if (operator === '-') {
128
- current = current.subtract(amount, unit);
129
- } else {
130
- throw new Error(`Invalid operator: ${operator}`);
131
- }
132
- }
133
- }
134
- return current.toDate();
10
+ export function resolveRelativeTime(s, now) {
11
+ {
12
+ let out = parseDate(s);
13
+ if (out) {
14
+ return out;
15
+ }
16
+ if (s == null) {
17
+ return;
18
+ }
19
+ }
20
+ if (typeof s === 'string' && s.startsWith('now')) {
21
+ // valid
22
+ } else {
23
+ throw new Error(`Invalid relative time format: ${s}`);
24
+ }
25
+ let current = dayjs(now);
26
+ const remaining = s.slice(3); // Remove 'now'
27
+ if (!remaining) {
28
+ return current.toDate();
29
+ }
30
+ // Split by operators while keeping them in the result
31
+ const parts = remaining.split(/([+\-/\\])/).filter((part) => part !== '');
32
+ for (let i = 0; i < parts.length; i += 2) {
33
+ const operator = parts[i];
34
+ const operand = parts[i + 1];
35
+ if (!operator || !operand) {
36
+ throw new Error(`Invalid relative time format: ${s}`);
37
+ }
38
+ if (operator === '/') {
39
+ // Truncation to start operation
40
+ checkDurationUnit(operand);
41
+ current = current.startOf(operand);
42
+ } else if (operator === '\\') {
43
+ // Truncation to end operation
44
+ checkDurationUnit(operand);
45
+ current = current.endOf(operand);
46
+ } else {
47
+ // Addition or subtraction operation
48
+ const match = operand.match(/^(\d+)([smhdwMQy])$/);
49
+ if (!match) {
50
+ throw new Error(`Invalid time operand: ${operand}`);
51
+ }
52
+ const [, amountStr, unit] = match;
53
+ checkDurationUnit(unit);
54
+ const amount = parseInt(amountStr, 10);
55
+ if (operator === '+') {
56
+ current = current.add(amount, unit);
57
+ } else if (operator === '-') {
58
+ current = current.subtract(amount, unit);
59
+ } else {
60
+ throw new Error(`Invalid operator: ${operator}`);
61
+ }
62
+ }
63
+ }
64
+ return current.toDate();
135
65
  }
136
66
  /** Array of all valid time units */ export const RelativeDurationUnits = [
137
- 'ms',
138
- 's',
139
- 'm',
140
- 'h',
141
- 'd',
142
- 'w',
143
- 'M',
144
- 'Q',
145
- 'y'
67
+ 'ms',
68
+ 's',
69
+ 'm',
70
+ 'h',
71
+ 'd',
72
+ 'w',
73
+ 'M',
74
+ 'Q',
75
+ 'y',
146
76
  ];
147
77
  /**
148
78
  * Type guard to validate and assert that a string is a valid time unit.
@@ -150,9 +80,9 @@ dayjs.extend(weekOfYear);
150
80
  * @param u - The string to check
151
81
  * @throws {Error} When the unit is not supported
152
82
  */ export function checkDurationUnit(u) {
153
- if (!RelativeDurationUnits.includes(u)) {
154
- throw new Error(`Invalid unit: ${u}`);
155
- }
83
+ if (!RelativeDurationUnits.includes(u)) {
84
+ throw new Error(`Invalid unit: ${u}`);
85
+ }
156
86
  }
157
87
 
158
- //# sourceMappingURL=resolveRelativeTime.js.map
88
+ //# sourceMappingURL=resolveRelativeTime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/dayjs/resolveRelativeTime.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport duration from 'dayjs/plugin/duration';\nimport quarterOfYear from 'dayjs/plugin/quarterOfYear';\nimport weekOfYear from 'dayjs/plugin/weekOfYear';\n\ndayjs.extend(duration);\ndayjs.extend(quarterOfYear);\ndayjs.extend(weekOfYear);\n\n/**\n * Resolves a Grafana-style relative time string and returns the corresponding Date.\n *\n * @param s - The relative time string to parse (must start with \"now\")\n * @param now - Optional reference date. If undefined, uses current time\n * @returns The calculated Date based on the relative time expression\n *\n * @throws {Error} When the format is invalid or contains unsupported operators/units\n *\n * ## Syntax\n *\n * All expressions must start with `now` followed by optional operations:\n *\n * ### Operators\n * - `-` - Subtraction (e.g., `now-1h` for one hour ago)\n * - `+` - Addition (e.g., `now+1d` for one day from now)\n * - `/` - Truncation to beginning of time unit (e.g., `now/d` for start of current day)\n * - `\\` - Truncation to end of time unit (e.g., `now\\d` for end of current day)\n *\n * ### Time Units\n * - `s` - seconds\n * - `m` - minutes\n * - `h` - hours\n * - `d` - days\n * - `w` - weeks\n * - `M` - months\n * - `Q` - quarters\n * - `y` - years\n *\n * ### Operations\n * Operations are processed sequentially from left to right:\n * - **Addition/Subtraction**: `now±{count}{unit}` (e.g., `now-24h`, `now+1d`)\n * - **Truncation to start**: `now/{unit}` (e.g., `now/d`, `now/M`)\n * - **Truncation to end**: `now\\{unit}` (e.g., `now\\d`, `now\\M`)\n * - **Complex**: Multiple operations can be chained (e.g., `now-1M/M`, `now\\d`, `now-1y\\y`)\n *\n * @example\n * ```typescript\n * // Basic usage\n * resolveRelativeTime('now') // Current time\n * resolveRelativeTime('now-1h') // One hour ago\n * resolveRelativeTime('now+1d') // One day from now\n * resolveRelativeTime('now/d') // Start of current day\n * resolveRelativeTime('now\\\\d') // End of current day\n *\n * // Common patterns\n * resolveRelativeTime('now-24h') // Last 24 hours\n * resolveRelativeTime('now-7d') // Last 7 days\n * resolveRelativeTime('now/M') // Start of current month\n * resolveRelativeTime('now\\\\M') // End of current month\n * resolveRelativeTime('now-1M/M') // Start of previous month\n * resolveRelativeTime('now-1M\\\\M') // End of previous month\n * resolveRelativeTime('now/w') // Start of current week\n * resolveRelativeTime('now\\\\w') // End of current week\n * resolveRelativeTime('now/y') // Start of current year\n * resolveRelativeTime('now\\\\y') // End of current year\n *\n * // Complex expressions\n * resolveRelativeTime('now/d+1d-1s') // End of current day (alternative method)\n * resolveRelativeTime('now\\\\d') // End of current day (direct method)\n * resolveRelativeTime('now-1w+2d-3h') // 1 week ago, plus 2 days, minus 3 hours\n *\n * // With reference date\n * const refDate = new Date('2024-03-15T14:30:45.123Z');\n * resolveRelativeTime('now-1h', refDate); // One hour before reference date\n * resolveRelativeTime('now\\\\d', refDate); // End of reference day\n * ```\n */\nexport function resolveRelativeTime(s: string | Date | number, now?: Date | undefined): Date {\n\t{\n\t\tlet out: Date | undefined;\n\t\tif (!s) {\n\t\t} else if (s instanceof Date) {\n\t\t\tout = s;\n\t\t} else if (typeof s === 'number') {\n\t\t\tout = new Date(s);\n\t\t} else if (!s.startsWith('now')) {\n\t\t\tout = new Date(s);\n\t\t}\n\t\tif (out) {\n\t\t\tif (isNaN(out.getTime())) {\n\t\t\t\tthrow new Error(`Invalid date: ${s}`);\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t}\n\n\tif (typeof s !== 'string' || !s.startsWith('now')) {\n\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t}\n\n\tlet current = dayjs(now);\n\tconst remaining = s.slice(3); // Remove 'now'\n\n\tif (!remaining) {\n\t\treturn current.toDate();\n\t}\n\n\t// Split by operators while keeping them in the result\n\tconst parts = remaining.split(/([+\\-/\\\\])/).filter((part) => part !== '');\n\n\tfor (let i = 0; i < parts.length; i += 2) {\n\t\tconst operator = parts[i];\n\t\tconst operand = parts[i + 1];\n\n\t\tif (!operator || !operand) {\n\t\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t\t}\n\n\t\tif (operator === '/') {\n\t\t\t// Truncation to start operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.startOf(operand);\n\t\t} else if (operator === '\\\\') {\n\t\t\t// Truncation to end operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.endOf(operand);\n\t\t} else {\n\t\t\t// Addition or subtraction operation\n\t\t\tconst match = operand.match(/^(\\d+)([smhdwMQy])$/);\n\t\t\tif (!match) {\n\t\t\t\tthrow new Error(`Invalid time operand: ${operand}`);\n\t\t\t}\n\n\t\t\tconst [, amountStr, unit] = match;\n\t\t\tcheckDurationUnit(unit);\n\t\t\tconst amount = parseInt(amountStr, 10);\n\n\t\t\tif (operator === '+') {\n\t\t\t\tcurrent = current.add(amount, unit as 'w');\n\t\t\t} else if (operator === '-') {\n\t\t\t\tcurrent = current.subtract(amount, unit as 'Q');\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Invalid operator: ${operator}`);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn current.toDate();\n}\n\n/** Array of all valid time units */\nexport const RelativeDurationUnits = ['ms', 's', 'm', 'h', 'd', 'w', 'M', 'Q', 'y'] as const;\n\n/** Valid time units for relative time expressions */\nexport type RelativeDurationUnit = (typeof RelativeDurationUnits)[number];\n\n/**\n * Type guard to validate and assert that a string is a valid time unit.\n *\n * @param u - The string to check\n * @throws {Error} When the unit is not supported\n */\nexport function checkDurationUnit(u: string): asserts u is RelativeDurationUnit {\n\tif (!RelativeDurationUnits.includes(u as RelativeDurationUnit)) {\n\t\tthrow new Error(`Invalid unit: ${u}`);\n\t}\n}\n"],"names":["dayjs","duration","quarterOfYear","weekOfYear","extend","resolveRelativeTime","s","now","out","Date","startsWith","isNaN","getTime","Error","current","remaining","slice","toDate","parts","split","filter","part","i","length","operator","operand","checkDurationUnit","startOf","endOf","match","amountStr","unit","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UP,KAAK,CAACI,IAAI,EAAE;QAE5B,IAAI,CAACE,YAAY,CAACC,SAAS;YAC1B,MAAM,IAAIZ,MAAM,CAAC,8BAA8B,EAAEP,GAAG;QACrD;QAEA,IAAIkB,aAAa,KAAK;YACrB,gCAAgC;YAChCE,kBAAkBD;YAClBX,UAAUA,QAAQa,OAAO,CAACF;QAC3B,OAAO,IAAID,aAAa,MAAM;YAC7B,8BAA8B;YAC9BE,kBAAkBD;YAClBX,UAAUA,QAAQc,KAAK,CAACH;QACzB,OAAO;YACN,oCAAoC;YACpC,MAAMI,QAAQJ,QAAQI,KAAK,CAAC;YAC5B,IAAI,CAACA,OAAO;gBACX,MAAM,IAAIhB,MAAM,CAAC,sBAAsB,EAAEY,SAAS;YACnD;YAEA,MAAM,GAAGK,WAAWC,KAAK,GAAGF;YAC5BH,kBAAkBK;YAClB,MAAMC,SAASC,SAASH,WAAW;YAEnC,IAAIN,aAAa,KAAK;gBACrBV,UAAUA,QAAQoB,GAAG,CAACF,QAAQD;YAC/B,OAAO,IAAIP,aAAa,KAAK;gBAC5BV,UAAUA,QAAQqB,QAAQ,CAACH,QAAQD;YACpC,OAAO;gBACN,MAAM,IAAIlB,MAAM,CAAC,kBAAkB,EAAEW,UAAU;YAChD;QACD;IACD;IAEA,OAAOV,QAAQG,MAAM;AACtB;AAEA,kCAAkC,GAClC,OAAO,MAAMmB,wBAAwB;IAAC;IAAM;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;IAAK;CAAI,CAAU;AAK7F;;;;;CAKC,GACD,OAAO,SAASV,kBAAkBW,CAAS;IAC1C,IAAI,CAACD,sBAAsBE,QAAQ,CAACD,IAA4B;QAC/D,MAAM,IAAIxB,MAAM,CAAC,cAAc,EAAEwB,GAAG;IACrC;AACD"}
1
+ {"version":3,"sources":["../../src/dayjs/resolveRelativeTime.ts"],"sourcesContent":["import { parseDate, type MaybeDate } from '@wener/utils';\nimport dayjs from 'dayjs';\nimport duration from 'dayjs/plugin/duration';\nimport quarterOfYear from 'dayjs/plugin/quarterOfYear';\nimport weekOfYear from 'dayjs/plugin/weekOfYear';\n\ndayjs.extend(duration);\ndayjs.extend(quarterOfYear);\ndayjs.extend(weekOfYear);\n\n/**\n * Resolves a Grafana-style relative time string and returns the corresponding Date.\n *\n * @param s - The relative time string to parse (must start with \"now\")\n * @param now - Optional reference date. If undefined, uses current time\n * @returns The calculated Date based on the relative time expression\n *\n * @throws {Error} When the format is invalid or contains unsupported operators/units\n *\n * ## Syntax\n *\n * All expressions must start with `now` followed by optional operations:\n *\n * ### Operators\n * - `-` - Subtraction (e.g., `now-1h` for one hour ago)\n * - `+` - Addition (e.g., `now+1d` for one day from now)\n * - `/` - Truncation to beginning of time unit (e.g., `now/d` for start of current day)\n * - `\\` - Truncation to end of time unit (e.g., `now\\d` for end of current day)\n *\n * ### Time Units\n * - `s` - seconds\n * - `m` - minutes\n * - `h` - hours\n * - `d` - days\n * - `w` - weeks\n * - `M` - months\n * - `Q` - quarters\n * - `y` - years\n *\n * ### Operations\n * Operations are processed sequentially from left to right:\n * - **Addition/Subtraction**: `now±{count}{unit}` (e.g., `now-24h`, `now+1d`)\n * - **Truncation to start**: `now/{unit}` (e.g., `now/d`, `now/M`)\n * - **Truncation to end**: `now\\{unit}` (e.g., `now\\d`, `now\\M`)\n * - **Complex**: Multiple operations can be chained (e.g., `now-1M/M`, `now\\d`, `now-1y\\y`)\n *\n * @example\n * ```typescript\n * // Basic usage\n * resolveRelativeTime('now') // Current time\n * resolveRelativeTime('now-1h') // One hour ago\n * resolveRelativeTime('now+1d') // One day from now\n * resolveRelativeTime('now/d') // Start of current day\n * resolveRelativeTime('now\\\\d') // End of current day\n *\n * // Common patterns\n * resolveRelativeTime('now-24h') // Last 24 hours\n * resolveRelativeTime('now-7d') // Last 7 days\n * resolveRelativeTime('now/M') // Start of current month\n * resolveRelativeTime('now\\\\M') // End of current month\n * resolveRelativeTime('now-1M/M') // Start of previous month\n * resolveRelativeTime('now-1M\\\\M') // End of previous month\n * resolveRelativeTime('now/w') // Start of current week\n * resolveRelativeTime('now\\\\w') // End of current week\n * resolveRelativeTime('now/y') // Start of current year\n * resolveRelativeTime('now\\\\y') // End of current year\n *\n * // Complex expressions\n * resolveRelativeTime('now/d+1d-1s') // End of current day (alternative method)\n * resolveRelativeTime('now\\\\d') // End of current day (direct method)\n * resolveRelativeTime('now-1w+2d-3h') // 1 week ago, plus 2 days, minus 3 hours\n *\n * // With reference date\n * const refDate = new Date('2024-03-15T14:30:45.123Z');\n * resolveRelativeTime('now-1h', refDate); // One hour before reference date\n * resolveRelativeTime('now\\\\d', refDate); // End of reference day\n * ```\n */\nexport function resolveRelativeTime(s: string | Date | number, now?: Date | undefined): Date;\nexport function resolveRelativeTime(s: MaybeDate, now?: Date | undefined): Date | undefined;\nexport function resolveRelativeTime(s: MaybeDate, now?: Date | undefined): Date | undefined {\n\t{\n\t\tlet out = parseDate(s);\n\t\tif (out) {\n\t\t\treturn out;\n\t\t}\n\t\tif (s == null) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tif (typeof s === 'string' && s.startsWith('now')) {\n\t\t// valid\n\t} else {\n\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t}\n\n\tlet current = dayjs(now);\n\tconst remaining = s.slice(3); // Remove 'now'\n\n\tif (!remaining) {\n\t\treturn current.toDate();\n\t}\n\n\t// Split by operators while keeping them in the result\n\tconst parts = remaining.split(/([+\\-/\\\\])/).filter((part) => part !== '');\n\n\tfor (let i = 0; i < parts.length; i += 2) {\n\t\tconst operator = parts[i];\n\t\tconst operand = parts[i + 1];\n\n\t\tif (!operator || !operand) {\n\t\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t\t}\n\n\t\tif (operator === '/') {\n\t\t\t// Truncation to start operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.startOf(operand);\n\t\t} else if (operator === '\\\\') {\n\t\t\t// Truncation to end operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.endOf(operand);\n\t\t} else {\n\t\t\t// Addition or subtraction operation\n\t\t\tconst match = operand.match(/^(\\d+)([smhdwMQy])$/);\n\t\t\tif (!match) {\n\t\t\t\tthrow new Error(`Invalid time operand: ${operand}`);\n\t\t\t}\n\n\t\t\tconst [, amountStr, unit] = match;\n\t\t\tcheckDurationUnit(unit);\n\t\t\tconst amount = parseInt(amountStr, 10);\n\n\t\t\tif (operator === '+') {\n\t\t\t\tcurrent = current.add(amount, unit as 'w');\n\t\t\t} else if (operator === '-') {\n\t\t\t\tcurrent = current.subtract(amount, unit as 'Q');\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Invalid operator: ${operator}`);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn current.toDate();\n}\n\n/** Array of all valid time units */\nexport const RelativeDurationUnits = ['ms', 's', 'm', 'h', 'd', 'w', 'M', 'Q', 'y'] as const;\n\n/** Valid time units for relative time expressions */\nexport type RelativeDurationUnit = (typeof RelativeDurationUnits)[number];\n\n/**\n * Type guard to validate and assert that a string is a valid time unit.\n *\n * @param u - The string to check\n * @throws {Error} When the unit is not supported\n */\nexport function checkDurationUnit(u: string): asserts u is RelativeDurationUnit {\n\tif (!RelativeDurationUnits.includes(u as RelativeDurationUnit)) {\n\t\tthrow new Error(`Invalid unit: ${u}`);\n\t}\n}\n"],"names":["parseDate","dayjs","duration","quarterOfYear","weekOfYear","extend","resolveRelativeTime","s","now","out","startsWith","Error","current","remaining","slice","toDate","parts","split","filter","part","i","length","operator","operand","checkDurationUnit","startOf","endOf","match","amountStr","unit","amount","parseInt","add","subtract","RelativeDurationUnits","u","includes"],"mappings":"AAAA,SAASA,SAAS,QAAwB,eAAe;AACzD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,wBAAwB;AAC7C,OAAOC,mBAAmB,6BAA6B;AACvD,OAAOC,gBAAgB,0BAA0B;AAEjDH,MAAMI,MAAM,CAACH;AACbD,MAAMI,MAAM,CAACF;AACbF,MAAMI,MAAM,CAACD;AAwEb,O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