@bessemer/cornerstone 0.5.114 → 0.5.115

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 (247) hide show
  1. package/dist/array.d.ts.map +1 -1
  2. package/dist/array.js +28 -28
  3. package/dist/array.js.map +1 -1
  4. package/dist/aspect-ratio.d.ts +3 -3
  5. package/dist/aspect-ratio.d.ts.map +1 -1
  6. package/dist/aspect-ratio.js +13 -12
  7. package/dist/aspect-ratio.js.map +1 -1
  8. package/dist/assertion.d.ts.map +1 -1
  9. package/dist/assertion.js +5 -5
  10. package/dist/assertion.js.map +1 -1
  11. package/dist/async-value.js +2 -2
  12. package/dist/async-value.js.map +1 -1
  13. package/dist/async.d.ts.map +1 -1
  14. package/dist/async.js +2 -2
  15. package/dist/async.js.map +1 -1
  16. package/dist/cache.d.ts.map +1 -1
  17. package/dist/cache.js +11 -12
  18. package/dist/cache.js.map +1 -1
  19. package/dist/combinable.js +5 -5
  20. package/dist/combinable.js.map +1 -1
  21. package/dist/comparator.js +8 -8
  22. package/dist/comparator.js.map +1 -1
  23. package/dist/data-size.d.ts +2 -1
  24. package/dist/data-size.d.ts.map +1 -1
  25. package/dist/data-size.js +3 -3
  26. package/dist/data-size.js.map +1 -1
  27. package/dist/either.js +5 -5
  28. package/dist/either.js.map +1 -1
  29. package/dist/equalitor.d.ts.map +1 -1
  30. package/dist/equalitor.js +2 -2
  31. package/dist/equalitor.js.map +1 -1
  32. package/dist/error/error-cause.d.ts.map +1 -1
  33. package/dist/error/error-cause.js +14 -14
  34. package/dist/error/error-cause.js.map +1 -1
  35. package/dist/error/error-code.js +2 -2
  36. package/dist/error/error-code.js.map +1 -1
  37. package/dist/error/error-event.d.ts +3 -2
  38. package/dist/error/error-event.d.ts.map +1 -1
  39. package/dist/error/error-event.js +28 -28
  40. package/dist/error/error-event.js.map +1 -1
  41. package/dist/error/error-type.d.ts +2 -1
  42. package/dist/error/error-type.d.ts.map +1 -1
  43. package/dist/error/error-type.js +2 -2
  44. package/dist/error/error-type.js.map +1 -1
  45. package/dist/error/error.js +5 -5
  46. package/dist/error/error.js.map +1 -1
  47. package/dist/expression/array-expression.js +3 -3
  48. package/dist/expression/array-expression.js.map +1 -1
  49. package/dist/expression/core-expression.d.ts.map +1 -1
  50. package/dist/expression/core-expression.js +19 -19
  51. package/dist/expression/core-expression.js.map +1 -1
  52. package/dist/expression/expression-evaluator.js +2 -2
  53. package/dist/expression/expression-evaluator.js.map +1 -1
  54. package/dist/expression/expression-mapper.js +4 -4
  55. package/dist/expression/expression-mapper.js.map +1 -1
  56. package/dist/expression/internal.js +3 -3
  57. package/dist/expression/internal.js.map +1 -1
  58. package/dist/expression/numeric-expression.js +13 -13
  59. package/dist/expression/numeric-expression.js.map +1 -1
  60. package/dist/expression/string-expression.js +4 -4
  61. package/dist/expression/string-expression.js.map +1 -1
  62. package/dist/glob.d.ts +3 -3
  63. package/dist/glob.d.ts.map +1 -1
  64. package/dist/glob.js +11 -12
  65. package/dist/glob.js.map +1 -1
  66. package/dist/global-variable.d.ts.map +1 -1
  67. package/dist/global-variable.js +5 -5
  68. package/dist/global-variable.js.map +1 -1
  69. package/dist/hex-code.d.ts +3 -3
  70. package/dist/hex-code.d.ts.map +1 -1
  71. package/dist/hex-code.js +11 -10
  72. package/dist/hex-code.js.map +1 -1
  73. package/dist/index.d.ts +10 -0
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +4 -0
  76. package/dist/index.js.map +1 -1
  77. package/dist/intl/country-code.d.ts +3 -3
  78. package/dist/intl/country-code.d.ts.map +1 -1
  79. package/dist/intl/country-code.js +9 -10
  80. package/dist/intl/country-code.js.map +1 -1
  81. package/dist/intl/country-subdivision-code.d.ts +3 -3
  82. package/dist/intl/country-subdivision-code.d.ts.map +1 -1
  83. package/dist/intl/country-subdivision-code.js +13 -11
  84. package/dist/intl/country-subdivision-code.js.map +1 -1
  85. package/dist/intl/currency-code.d.ts +3 -3
  86. package/dist/intl/currency-code.d.ts.map +1 -1
  87. package/dist/intl/currency-code.js +9 -10
  88. package/dist/intl/currency-code.js.map +1 -1
  89. package/dist/intl/language-code.d.ts +3 -3
  90. package/dist/intl/language-code.d.ts.map +1 -1
  91. package/dist/intl/language-code.js +9 -10
  92. package/dist/intl/language-code.js.map +1 -1
  93. package/dist/intl/locale.d.ts +3 -3
  94. package/dist/intl/locale.d.ts.map +1 -1
  95. package/dist/intl/locale.js +18 -19
  96. package/dist/intl/locale.js.map +1 -1
  97. package/dist/json.d.ts.map +1 -1
  98. package/dist/json.js +2 -2
  99. package/dist/json.js.map +1 -1
  100. package/dist/logger.d.ts.map +1 -1
  101. package/dist/logger.js +12 -12
  102. package/dist/logger.js.map +1 -1
  103. package/dist/map.js +8 -8
  104. package/dist/map.js.map +1 -1
  105. package/dist/mime-type.d.ts +3 -3
  106. package/dist/mime-type.d.ts.map +1 -1
  107. package/dist/mime-type.js +9 -10
  108. package/dist/mime-type.js.map +1 -1
  109. package/dist/misc.js +4 -4
  110. package/dist/misc.js.map +1 -1
  111. package/dist/monetary-amount.d.ts +3 -2
  112. package/dist/monetary-amount.d.ts.map +1 -1
  113. package/dist/monetary-amount.js +16 -16
  114. package/dist/monetary-amount.js.map +1 -1
  115. package/dist/net/content-type.d.ts +2 -1
  116. package/dist/net/content-type.d.ts.map +1 -1
  117. package/dist/net/content-type.js +2 -2
  118. package/dist/net/content-type.js.map +1 -1
  119. package/dist/net/domain-name.d.ts +3 -3
  120. package/dist/net/domain-name.d.ts.map +1 -1
  121. package/dist/net/domain-name.js +10 -11
  122. package/dist/net/domain-name.js.map +1 -1
  123. package/dist/net/http-method.d.ts.map +1 -1
  124. package/dist/net/http-method.js +9 -9
  125. package/dist/net/http-method.js.map +1 -1
  126. package/dist/net/ipv4-address.d.ts +3 -3
  127. package/dist/net/ipv4-address.d.ts.map +1 -1
  128. package/dist/net/ipv4-address.js +10 -11
  129. package/dist/net/ipv4-address.js.map +1 -1
  130. package/dist/net/ipv6-address.d.ts +3 -3
  131. package/dist/net/ipv6-address.d.ts.map +1 -1
  132. package/dist/net/ipv6-address.js +10 -11
  133. package/dist/net/ipv6-address.js.map +1 -1
  134. package/dist/net/uri-host-name.d.ts +3 -3
  135. package/dist/net/uri-host-name.d.ts.map +1 -1
  136. package/dist/net/uri-host-name.js +15 -16
  137. package/dist/net/uri-host-name.js.map +1 -1
  138. package/dist/net/uri.d.ts +1 -2
  139. package/dist/net/uri.d.ts.map +1 -1
  140. package/dist/net/uri.js +5 -3
  141. package/dist/net/uri.js.map +1 -1
  142. package/dist/net/url.d.ts.map +1 -1
  143. package/dist/net/url.js +6 -7
  144. package/dist/net/url.js.map +1 -1
  145. package/dist/object/object-path.d.ts.map +1 -1
  146. package/dist/object/object-path.js +23 -28
  147. package/dist/object/object-path.js.map +1 -1
  148. package/dist/object/type-path.js +19 -19
  149. package/dist/object/type-path.js.map +1 -1
  150. package/dist/patch.js +4 -4
  151. package/dist/patch.js.map +1 -1
  152. package/dist/promise.js +2 -2
  153. package/dist/promise.js.map +1 -1
  154. package/dist/property.d.ts.map +1 -1
  155. package/dist/property.js +7 -7
  156. package/dist/property.js.map +1 -1
  157. package/dist/proxy.js +2 -2
  158. package/dist/proxy.js.map +1 -1
  159. package/dist/range.js +2 -2
  160. package/dist/range.js.map +1 -1
  161. package/dist/reference.d.ts +2 -1
  162. package/dist/reference.d.ts.map +1 -1
  163. package/dist/reference.js +13 -13
  164. package/dist/reference.js.map +1 -1
  165. package/dist/resource-key.js +2 -2
  166. package/dist/resource-key.js.map +1 -1
  167. package/dist/result.js +5 -5
  168. package/dist/result.js.map +1 -1
  169. package/dist/retry.d.ts.map +1 -1
  170. package/dist/retry.js +12 -12
  171. package/dist/retry.js.map +1 -1
  172. package/dist/rich-text.js +2 -2
  173. package/dist/rich-text.js.map +1 -1
  174. package/dist/signature.d.ts.map +1 -1
  175. package/dist/signature.js +9 -9
  176. package/dist/signature.js.map +1 -1
  177. package/dist/sql/sql-expression-parser.js +2 -2
  178. package/dist/sql/sql-expression-parser.js.map +1 -1
  179. package/dist/store.d.ts.map +1 -1
  180. package/dist/store.js +9 -9
  181. package/dist/store.js.map +1 -1
  182. package/dist/string.js +4 -4
  183. package/dist/string.js.map +1 -1
  184. package/dist/tag.d.ts.map +1 -1
  185. package/dist/tag.js +10 -10
  186. package/dist/tag.js.map +1 -1
  187. package/dist/temporal/clock.d.ts +13 -13
  188. package/dist/temporal/clock.d.ts.map +1 -1
  189. package/dist/temporal/clock.js +10 -10
  190. package/dist/temporal/clock.js.map +1 -1
  191. package/dist/temporal/duration.d.ts +15 -9
  192. package/dist/temporal/duration.d.ts.map +1 -1
  193. package/dist/temporal/duration.js +30 -31
  194. package/dist/temporal/duration.js.map +1 -1
  195. package/dist/temporal/instant.d.ts +18 -15
  196. package/dist/temporal/instant.d.ts.map +1 -1
  197. package/dist/temporal/instant.js +42 -43
  198. package/dist/temporal/instant.js.map +1 -1
  199. package/dist/temporal/plain-date-time.d.ts +16 -13
  200. package/dist/temporal/plain-date-time.d.ts.map +1 -1
  201. package/dist/temporal/plain-date-time.js +36 -38
  202. package/dist/temporal/plain-date-time.js.map +1 -1
  203. package/dist/temporal/plain-date.d.ts +16 -13
  204. package/dist/temporal/plain-date.d.ts.map +1 -1
  205. package/dist/temporal/plain-date.js +35 -37
  206. package/dist/temporal/plain-date.js.map +1 -1
  207. package/dist/temporal/plain-month-day.d.ts +37 -0
  208. package/dist/temporal/plain-month-day.d.ts.map +1 -0
  209. package/dist/temporal/plain-month-day.js +84 -0
  210. package/dist/temporal/plain-month-day.js.map +1 -0
  211. package/dist/temporal/plain-time.d.ts +19 -17
  212. package/dist/temporal/plain-time.d.ts.map +1 -1
  213. package/dist/temporal/plain-time.js +43 -42
  214. package/dist/temporal/plain-time.js.map +1 -1
  215. package/dist/temporal/plain-year-month.d.ts +57 -0
  216. package/dist/temporal/plain-year-month.d.ts.map +1 -0
  217. package/dist/temporal/plain-year-month.js +109 -0
  218. package/dist/temporal/plain-year-month.js.map +1 -0
  219. package/dist/temporal/time-zone-id.d.ts +5 -4
  220. package/dist/temporal/time-zone-id.d.ts.map +1 -1
  221. package/dist/temporal/time-zone-id.js +11 -11
  222. package/dist/temporal/time-zone-id.js.map +1 -1
  223. package/dist/temporal/time-zone-offset.d.ts +12 -11
  224. package/dist/temporal/time-zone-offset.d.ts.map +1 -1
  225. package/dist/temporal/time-zone-offset.js +42 -50
  226. package/dist/temporal/time-zone-offset.js.map +1 -1
  227. package/dist/temporal/zoned-date-time.d.ts +16 -13
  228. package/dist/temporal/zoned-date-time.d.ts.map +1 -1
  229. package/dist/temporal/zoned-date-time.js +35 -36
  230. package/dist/temporal/zoned-date-time.js.map +1 -1
  231. package/dist/uuid/ulid.d.ts +3 -3
  232. package/dist/uuid/ulid.d.ts.map +1 -1
  233. package/dist/uuid/ulid.js +9 -10
  234. package/dist/uuid/ulid.js.map +1 -1
  235. package/dist/uuid/uuid-v4.d.ts +3 -3
  236. package/dist/uuid/uuid-v4.d.ts.map +1 -1
  237. package/dist/uuid/uuid-v4.js +13 -14
  238. package/dist/uuid/uuid-v4.js.map +1 -1
  239. package/dist/uuid/uuid-v7.d.ts +1 -2
  240. package/dist/uuid/uuid-v7.d.ts.map +1 -1
  241. package/dist/uuid/uuid-v7.js +1 -2
  242. package/dist/uuid/uuid-v7.js.map +1 -1
  243. package/dist/zod-util.d.ts +4 -21
  244. package/dist/zod-util.d.ts.map +1 -1
  245. package/dist/zod-util.js +21 -11
  246. package/dist/zod-util.js.map +1 -1
  247. package/package.json +2 -2
package/dist/map.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/map.ts"],"sourcesContent":["import { Entry } from '@bessemer/cornerstone/entry'\nimport { concatenate as arrayConcatenate } from '@bessemer/cornerstone/array'\nimport { assert, assertPresent } from '@bessemer/cornerstone/assertion'\nimport { Objects } from '@bessemer/cornerstone/index'\nimport { Dictionary } from '@bessemer/cornerstone/types'\n\n/**\n * Creates a Map from a dictionary object (plain object with string keys).\n * Converts an object's key-value pairs into a Map structure.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const user = { name: \"Alice\", age: \"30\", role: \"admin\" }\n * const userMap = Maps.from(user)\n * console.log(userMap.get(\"name\")) // \"Alice\"\n * console.log(userMap.size) // 3\n * ```\n *\n * @category constructors\n */\nexport const from = <ValueType>(record: Dictionary<ValueType>): Map<string, ValueType> => {\n return fromEntries(Object.entries(record))\n}\n\n/**\n * Creates a Map from an array of key-value pair entries.\n * Each entry is a tuple of [key, value] that will be added to the Map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const entries: Array<[string, number]> = [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n * const map = Maps.fromEntries(entries)\n * console.log(map.get(\"b\")) // 2\n * console.log(map.size) // 3\n * ```\n *\n * @category constructors\n */\nexport const fromEntries = <KeyType extends string | number | symbol, ValueType>(\n entries: Array<Entry<KeyType, ValueType>>\n): Map<KeyType, ValueType> => {\n return collect(entries, (it) => it)\n}\n\n/**\n * Groups elements of an iterable by a key extracted using a mapper function.\n * Returns a Map where each key maps to an array of all elements that share that key.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const users = [\n * { name: \"Alice\", role: \"admin\" },\n * { name: \"Bob\", role: \"user\" },\n * { name: \"Charlie\", role: \"admin\" }\n * ]\n *\n * const byRole = Maps.groupBy(users, (user) => user.role)\n * console.log(byRole.get(\"admin\")) // [{ name: \"Alice\", role: \"admin\" }, { name: \"Charlie\", role: \"admin\" }]\n * console.log(byRole.get(\"user\")) // [{ name: \"Bob\", role: \"user\" }]\n * ```\n *\n * @category transformations\n */\nexport const groupBy = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, Array<CollectionType>> => {\n return collect(\n iterable,\n (it) => [mapper(it), [it]],\n (_, first, second) => arrayConcatenate(first, second)\n )\n}\n\n/**\n * Fuses two maps together by using values from the first map as keys to lookup\n * values in the second map. The resulting map has the same keys as the target map,\n * but with values resolved through the valuesMap.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const userRoles = new Map([[\"user1\", \"roleA\"], [\"user2\", \"roleB\"]])\n * const rolePermissions = new Map([[\"roleA\", \"read\"], [\"roleB\", \"write\"]])\n *\n * const userPermissions = Maps.fuse(userRoles, rolePermissions)\n * console.log(userPermissions.get(\"user1\")) // \"read\"\n * console.log(userPermissions.get(\"user2\")) // \"write\"\n * ```\n *\n * @category transformations\n */\nexport const fuse = <KeyType, FuseType, ValueType>(target: Map<KeyType, FuseType>, valuesMap: Map<FuseType, ValueType>): Map<KeyType, ValueType> => {\n return mapValues(target, (value) => {\n const newValue = valuesMap.get(value)\n assertPresent(newValue, () => `Maps.fuse - Encountered missing linkage: ${value}`)\n return newValue\n })\n}\n\n/**\n * Transforms all keys in a map using a mapper function while preserving the values.\n * Returns a new map with transformed keys and the same values.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[1, \"one\"], [2, \"two\"], [3, \"three\"]])\n * const stringKeyMap = Maps.mapKeys(map, (key) => `num_${key}`)\n * console.log(stringKeyMap.get(\"num_1\")) // \"one\"\n * console.log(stringKeyMap.get(\"num_2\")) // \"two\"\n * ```\n *\n * @category transformations\n */\nexport const mapKeys = <KeyType, ValueType, NewKeyType>(\n target: Map<KeyType, ValueType>,\n mapper: (key: KeyType) => NewKeyType\n): Map<NewKeyType, ValueType> => {\n return map(target, ([key, value]) => [mapper(key), value])\n}\n\n/**\n * Transforms all values in a map using a mapper function while preserving the keys.\n * Returns a new map with the same keys and transformed values.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.8], [\"orange\", 1.2]])\n * const doubled = Maps.mapValues(prices, (price) => price * 2)\n * console.log(doubled.get(\"apple\")) // 3.0\n * console.log(doubled.get(\"banana\")) // 1.6\n * ```\n *\n * @category transformations\n */\nexport const mapValues = <KeyType, ValueType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (value: ValueType) => NewValueType\n): Map<KeyType, NewValueType> => {\n return map(target, ([key, value]) => [key, mapper(value)])\n}\n\n/**\n * Transforms both keys and values in a map using a mapper function.\n * Returns a new map with transformed entries. Throws an error if the mapper\n * produces duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * const transformed = Maps.map(map, ([key, value]) => [key * 10, value.toUpperCase()])\n * console.log(transformed.get(10)) // \"A\"\n * console.log(transformed.get(20)) // \"B\"\n * ```\n *\n * @category transformations\n */\nexport const map = <KeyType, ValueType, NewKeyType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (entry: Entry<KeyType, ValueType>) => Entry<NewKeyType, NewValueType>\n): Map<NewKeyType, NewValueType> => {\n return collect(target.entries(), mapper, (key) => {\n throw new Error(`Maps.transform - Encountered illegal duplicate collection value: ${key}`)\n })\n}\n\n/**\n * Creates a map by extracting keys from collection items using a mapper function.\n * Each item becomes a value in the map, keyed by the result of the mapper.\n * Throws an error if the mapper produces duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const users = [\n * { id: 1, name: \"Alice\" },\n * { id: 2, name: \"Bob\" },\n * { id: 3, name: \"Charlie\" }\n * ]\n *\n * const usersById = Maps.collectKeys(users, (user) => user.id)\n * console.log(usersById.get(1)) // { id: 1, name: \"Alice\" }\n * console.log(usersById.get(2)) // { id: 2, name: \"Bob\" }\n * ```\n *\n * @category constructors\n */\nexport const collectKeys = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, CollectionType> => {\n return collect(\n iterable,\n (it) => [mapper(it), it],\n (key) => {\n throw new Error(`Maps.collectKeys - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\n/**\n * Creates a map by extracting values from collection items using a mapper function.\n * Each item becomes a key in the map, with the mapped value as its value.\n * Throws an error if there are duplicate items in the collection.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const userIds = [1, 2, 3]\n * const userNames = Maps.collectValues(userIds, (id) => `User${id}`)\n * console.log(userNames.get(1)) // \"User1\"\n * console.log(userNames.get(2)) // \"User2\"\n * ```\n *\n * @category constructors\n */\nexport const collectValues = <CollectionType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => ValueType\n): Map<CollectionType, ValueType> => {\n return collect(\n iterable,\n (it) => [it, mapper(it)],\n (key) => {\n throw new Error(`Maps.mapValues - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\n/**\n * Collects items from an iterable into a Map by transforming each item into a key-value entry.\n * Optionally accepts a reducer function to handle duplicate keys by combining their values.\n * Without a reducer, throws an error on duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const items = [\"apple\", \"banana\", \"apricot\"]\n * const byFirstLetter = Maps.collect(\n * items,\n * (item) => [item[0], item]\n * )\n * // throws error due to duplicate key 'a'\n *\n * const withReducer = Maps.collect(\n * items,\n * (item) => [item[0], [item]],\n * (key, first, second) => [...first, ...second]\n * )\n * console.log(withReducer.get(\"a\")) // [\"apple\", \"apricot\"]\n * console.log(withReducer.get(\"b\")) // [\"banana\"]\n * ```\n *\n * @category constructors\n */\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer?: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType> {\n const result = new Map<KeyType, ValueType>()\n\n for (const item of iterable) {\n const [key, value] = mapEntry(item)\n\n if (result.has(key)) {\n if (Objects.isNil(reducer)) {\n throw new Error(`Maps.collect - Encountered illegal duplicate collection key: ${key}`)\n }\n\n const existingValue = result.get(key)!\n const reducedValue = reducer(key, existingValue, value)\n result.set(key, reducedValue)\n } else {\n result.set(key, value)\n }\n }\n\n return result\n}\n\n/**\n * Creates a new map with additional entries appended. Throws an error if any\n * of the new entries have keys that already exist in the map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const original = new Map([[\"a\", 1], [\"b\", 2]])\n * const extended = Maps.append(original, [\"c\", 3], [\"d\", 4])\n * console.log(extended.get(\"c\")) // 3\n * console.log(extended.size) // 4\n * console.log(original.size) // 2 (original unchanged)\n * ```\n *\n * @category mutations\n */\nexport const append = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map.entries())\n appendInto(result, ...values)\n return result\n}\n\n/**\n * Mutates a map by appending entries in place. Throws an error if any\n * of the new entries have keys that already exist in the map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[\"a\", 1], [\"b\", 2]])\n * Maps.appendInto(map, [\"c\", 3], [\"d\", 4])\n * console.log(map.get(\"c\")) // 3\n * console.log(map.size) // 4\n * ```\n *\n * @category mutations\n */\nexport const appendInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): void => {\n for (const [key, value] of values) {\n assert(!map.has(key), () => `Maps.append - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n}\n\n/**\n * Creates a new map by concatenating multiple maps together. Throws an error\n * if any duplicate keys are encountered across the maps.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map1 = new Map([[\"a\", 1], [\"b\", 2]])\n * const map2 = new Map([[\"c\", 3]])\n * const map3 = new Map([[\"d\", 4]])\n *\n * const combined = Maps.concatenate(map1, map2, map3)\n * console.log(combined.size) // 4\n * console.log(combined.get(\"c\")) // 3\n * ```\n *\n * @category mutations\n */\nexport const concatenate = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map)\n concatenateInto(result, ...values)\n return result\n}\n\n/**\n * Mutates a map by concatenating other maps into it in place. Throws an error\n * if any duplicate keys are encountered.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map1 = new Map([[\"a\", 1], [\"b\", 2]])\n * const map2 = new Map([[\"c\", 3]])\n *\n * Maps.concatenateInto(map1, map2)\n * console.log(map1.size) // 3\n * console.log(map1.get(\"c\")) // 3\n * ```\n *\n * @category mutations\n */\nexport const concatenateInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): void => {\n for (const otherMap of values) {\n for (const [key, value] of otherMap) {\n assert(!map.has(key), () => `Maps.concatenate - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n }\n}\n\n/**\n * Creates a new map containing only entries that satisfy the predicate function.\n * Returns a filtered copy of the original map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.5], [\"orange\", 2.0]])\n * const expensive = Maps.filter(prices, ([_, price]) => price > 1.0)\n * console.log(expensive.size) // 2\n * console.log(expensive.has(\"banana\")) // false\n * console.log(expensive.get(\"apple\")) // 1.5\n * ```\n *\n * @category filtering\n */\nexport const filter = <KeyType, ValueType>(\n map: Map<KeyType, ValueType>,\n predicate: (entry: Entry<KeyType, ValueType>) => boolean\n): Map<KeyType, ValueType> => {\n const result = new Map(map)\n filterFrom(result, predicate)\n return result\n}\n\n/**\n * Mutates a map by removing entries that don't satisfy the predicate function.\n * Filters the map in place.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.5], [\"orange\", 2.0]])\n * Maps.filterFrom(prices, ([_, price]) => price > 1.0)\n * console.log(prices.size) // 2\n * console.log(prices.has(\"banana\")) // false\n * ```\n *\n * @category filtering\n */\nexport const filterFrom = <KeyType, ValueType>(map: Map<KeyType, ValueType>, predicate: (entry: Entry<KeyType, ValueType>) => boolean): void => {\n for (const entry of map) {\n if (!predicate(entry)) {\n map.delete(entry[0])\n }\n }\n}\n"],"mappings":";AACA,SAAS,eAAe,wBAAwB;AAChD,SAAS,QAAQ,qBAAqB;AACtC,SAAS,eAAe;AAoBjB,IAAM,OAAO,CAAY,WAA0D;AACxF,SAAO,YAAY,OAAO,QAAQ,MAAM,CAAC;AAC3C;AAmBO,IAAM,cAAc,CACzB,YAC4B;AAC5B,SAAO,QAAQ,SAAS,CAAC,OAAO,EAAE;AACpC;AAwBO,IAAM,UAAU,CACrB,UACA,WACwC;AACxC,SAAO;AAAA,IACL;AAAA,IACA,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;AAAA,IACzB,CAAC,GAAG,OAAO,WAAW,iBAAiB,OAAO,MAAM;AAAA,EACtD;AACF;AAsBO,IAAM,OAAO,CAA+B,QAAgC,cAAiE;AAClJ,SAAO,UAAU,QAAQ,CAAC,UAAU;AAClC,UAAM,WAAW,UAAU,IAAI,KAAK;AACpC,kBAAc,UAAU,MAAM,4CAA4C,KAAK,EAAE;AACjF,WAAO;AAAA,EACT,CAAC;AACH;AAmBO,IAAM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;AAAA,IAC9B,OAAO;AACL,aAAO,IAAI,KAAK,KAAK;AAAA,IACvB;AAAA,EACF;AAEA,SAAO;AACT;AAoBO,IAAM,SAAS,CAAqBA,SAAiC,WAAsE;AAChJ,QAAM,SAAS,IAAI,IAAIA,KAAI,QAAQ,CAAC;AACpC,aAAW,QAAQ,GAAG,MAAM;AAC5B,SAAO;AACT;AAmBO,IAAM,aAAa,CAAqBA,SAAiC,WAAmD;AACjI,aAAW,CAAC,KAAK,KAAK,KAAK,QAAQ;AACjC,WAAO,CAACA,KAAI,IAAI,GAAG,GAAG,MAAM,oDAAoD,GAAG,EAAE;AACrF,IAAAA,KAAI,IAAI,KAAK,KAAK;AAAA,EACpB;AACF;AAsBO,IAAM,cAAc,CAAqBA,SAAiC,WAAoE;AACnJ,QAAM,SAAS,IAAI,IAAIA,IAAG;AAC1B,kBAAgB,QAAQ,GAAG,MAAM;AACjC,SAAO;AACT;AAqBO,IAAM,kBAAkB,CAAqBA,SAAiC,WAAiD;AACpI,aAAW,YAAY,QAAQ;AAC7B,eAAW,CAAC,KAAK,KAAK,KAAK,UAAU;AACnC,aAAO,CAACA,KAAI,IAAI,GAAG,GAAG,MAAM,yDAAyD,GAAG,EAAE;AAC1F,MAAAA,KAAI,IAAI,KAAK,KAAK;AAAA,IACpB;AAAA,EACF;AACF;AAoBO,IAAM,SAAS,CACpBA,MACA,cAC4B;AAC5B,QAAM,SAAS,IAAI,IAAIA,IAAG;AAC1B,aAAW,QAAQ,SAAS;AAC5B,SAAO;AACT;AAmBO,IAAM,aAAa,CAAqBA,MAA8B,cAAmE;AAC9I,aAAW,SAASA,MAAK;AACvB,QAAI,CAAC,UAAU,KAAK,GAAG;AACrB,MAAAA,KAAI,OAAO,MAAM,CAAC,CAAC;AAAA,IACrB;AAAA,EACF;AACF;","names":["map"]}
1
+ {"version":3,"sources":["../src/map.ts"],"sourcesContent":["import { Entry } from '@bessemer/cornerstone/entry'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\nimport { Objects } from '@bessemer/cornerstone/index'\nimport { Dictionary } from '@bessemer/cornerstone/types'\n\n/**\n * Creates a Map from a dictionary object (plain object with string keys).\n * Converts an object's key-value pairs into a Map structure.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const user = { name: \"Alice\", age: \"30\", role: \"admin\" }\n * const userMap = Maps.from(user)\n * console.log(userMap.get(\"name\")) // \"Alice\"\n * console.log(userMap.size) // 3\n * ```\n *\n * @category constructors\n */\nexport const from = <ValueType>(record: Dictionary<ValueType>): Map<string, ValueType> => {\n return fromEntries(Object.entries(record))\n}\n\n/**\n * Creates a Map from an array of key-value pair entries.\n * Each entry is a tuple of [key, value] that will be added to the Map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const entries: Array<[string, number]> = [[\"a\", 1], [\"b\", 2], [\"c\", 3]]\n * const map = Maps.fromEntries(entries)\n * console.log(map.get(\"b\")) // 2\n * console.log(map.size) // 3\n * ```\n *\n * @category constructors\n */\nexport const fromEntries = <KeyType extends string | number | symbol, ValueType>(\n entries: Array<Entry<KeyType, ValueType>>\n): Map<KeyType, ValueType> => {\n return collect(entries, (it) => it)\n}\n\n/**\n * Groups elements of an iterable by a key extracted using a mapper function.\n * Returns a Map where each key maps to an array of all elements that share that key.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const users = [\n * { name: \"Alice\", role: \"admin\" },\n * { name: \"Bob\", role: \"user\" },\n * { name: \"Charlie\", role: \"admin\" }\n * ]\n *\n * const byRole = Maps.groupBy(users, (user) => user.role)\n * console.log(byRole.get(\"admin\")) // [{ name: \"Alice\", role: \"admin\" }, { name: \"Charlie\", role: \"admin\" }]\n * console.log(byRole.get(\"user\")) // [{ name: \"Bob\", role: \"user\" }]\n * ```\n *\n * @category transformations\n */\nexport const groupBy = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, Array<CollectionType>> => {\n return collect(\n iterable,\n (it) => [mapper(it), [it]],\n (_, first, second) => Arrays.concatenate(first, second)\n )\n}\n\n/**\n * Fuses two maps together by using values from the first map as keys to lookup\n * values in the second map. The resulting map has the same keys as the target map,\n * but with values resolved through the valuesMap.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const userRoles = new Map([[\"user1\", \"roleA\"], [\"user2\", \"roleB\"]])\n * const rolePermissions = new Map([[\"roleA\", \"read\"], [\"roleB\", \"write\"]])\n *\n * const userPermissions = Maps.fuse(userRoles, rolePermissions)\n * console.log(userPermissions.get(\"user1\")) // \"read\"\n * console.log(userPermissions.get(\"user2\")) // \"write\"\n * ```\n *\n * @category transformations\n */\nexport const fuse = <KeyType, FuseType, ValueType>(target: Map<KeyType, FuseType>, valuesMap: Map<FuseType, ValueType>): Map<KeyType, ValueType> => {\n return mapValues(target, (value) => {\n const newValue = valuesMap.get(value)\n Assertions.assertPresent(newValue, () => `Maps.fuse - Encountered missing linkage: ${value}`)\n return newValue\n })\n}\n\n/**\n * Transforms all keys in a map using a mapper function while preserving the values.\n * Returns a new map with transformed keys and the same values.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[1, \"one\"], [2, \"two\"], [3, \"three\"]])\n * const stringKeyMap = Maps.mapKeys(map, (key) => `num_${key}`)\n * console.log(stringKeyMap.get(\"num_1\")) // \"one\"\n * console.log(stringKeyMap.get(\"num_2\")) // \"two\"\n * ```\n *\n * @category transformations\n */\nexport const mapKeys = <KeyType, ValueType, NewKeyType>(\n target: Map<KeyType, ValueType>,\n mapper: (key: KeyType) => NewKeyType\n): Map<NewKeyType, ValueType> => {\n return map(target, ([key, value]) => [mapper(key), value])\n}\n\n/**\n * Transforms all values in a map using a mapper function while preserving the keys.\n * Returns a new map with the same keys and transformed values.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.8], [\"orange\", 1.2]])\n * const doubled = Maps.mapValues(prices, (price) => price * 2)\n * console.log(doubled.get(\"apple\")) // 3.0\n * console.log(doubled.get(\"banana\")) // 1.6\n * ```\n *\n * @category transformations\n */\nexport const mapValues = <KeyType, ValueType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (value: ValueType) => NewValueType\n): Map<KeyType, NewValueType> => {\n return map(target, ([key, value]) => [key, mapper(value)])\n}\n\n/**\n * Transforms both keys and values in a map using a mapper function.\n * Returns a new map with transformed entries. Throws an error if the mapper\n * produces duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[1, \"a\"], [2, \"b\"], [3, \"c\"]])\n * const transformed = Maps.map(map, ([key, value]) => [key * 10, value.toUpperCase()])\n * console.log(transformed.get(10)) // \"A\"\n * console.log(transformed.get(20)) // \"B\"\n * ```\n *\n * @category transformations\n */\nexport const map = <KeyType, ValueType, NewKeyType, NewValueType>(\n target: Map<KeyType, ValueType>,\n mapper: (entry: Entry<KeyType, ValueType>) => Entry<NewKeyType, NewValueType>\n): Map<NewKeyType, NewValueType> => {\n return collect(target.entries(), mapper, (key) => {\n throw new Error(`Maps.transform - Encountered illegal duplicate collection value: ${key}`)\n })\n}\n\n/**\n * Creates a map by extracting keys from collection items using a mapper function.\n * Each item becomes a value in the map, keyed by the result of the mapper.\n * Throws an error if the mapper produces duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const users = [\n * { id: 1, name: \"Alice\" },\n * { id: 2, name: \"Bob\" },\n * { id: 3, name: \"Charlie\" }\n * ]\n *\n * const usersById = Maps.collectKeys(users, (user) => user.id)\n * console.log(usersById.get(1)) // { id: 1, name: \"Alice\" }\n * console.log(usersById.get(2)) // { id: 2, name: \"Bob\" }\n * ```\n *\n * @category constructors\n */\nexport const collectKeys = <CollectionType, KeyType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => KeyType\n): Map<KeyType, CollectionType> => {\n return collect(\n iterable,\n (it) => [mapper(it), it],\n (key) => {\n throw new Error(`Maps.collectKeys - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\n/**\n * Creates a map by extracting values from collection items using a mapper function.\n * Each item becomes a key in the map, with the mapped value as its value.\n * Throws an error if there are duplicate items in the collection.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const userIds = [1, 2, 3]\n * const userNames = Maps.collectValues(userIds, (id) => `User${id}`)\n * console.log(userNames.get(1)) // \"User1\"\n * console.log(userNames.get(2)) // \"User2\"\n * ```\n *\n * @category constructors\n */\nexport const collectValues = <CollectionType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapper: (it: CollectionType) => ValueType\n): Map<CollectionType, ValueType> => {\n return collect(\n iterable,\n (it) => [it, mapper(it)],\n (key) => {\n throw new Error(`Maps.mapValues - Encountered illegal duplicate collection value: ${key}`)\n }\n )\n}\n\n/**\n * Collects items from an iterable into a Map by transforming each item into a key-value entry.\n * Optionally accepts a reducer function to handle duplicate keys by combining their values.\n * Without a reducer, throws an error on duplicate keys.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const items = [\"apple\", \"banana\", \"apricot\"]\n * const byFirstLetter = Maps.collect(\n * items,\n * (item) => [item[0], item]\n * )\n * // throws error due to duplicate key 'a'\n *\n * const withReducer = Maps.collect(\n * items,\n * (item) => [item[0], [item]],\n * (key, first, second) => [...first, ...second]\n * )\n * console.log(withReducer.get(\"a\")) // [\"apple\", \"apricot\"]\n * console.log(withReducer.get(\"b\")) // [\"banana\"]\n * ```\n *\n * @category constructors\n */\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType>\nexport function collect<CollectionType, KeyType, ValueType>(\n iterable: Iterable<CollectionType>,\n mapEntry: (it: CollectionType) => Entry<KeyType, ValueType>,\n reducer?: (key: KeyType, first: ValueType, second: ValueType) => ValueType\n): Map<KeyType, ValueType> {\n const result = new Map<KeyType, ValueType>()\n\n for (const item of iterable) {\n const [key, value] = mapEntry(item)\n\n if (result.has(key)) {\n if (Objects.isNil(reducer)) {\n throw new Error(`Maps.collect - Encountered illegal duplicate collection key: ${key}`)\n }\n\n const existingValue = result.get(key)!\n const reducedValue = reducer(key, existingValue, value)\n result.set(key, reducedValue)\n } else {\n result.set(key, value)\n }\n }\n\n return result\n}\n\n/**\n * Creates a new map with additional entries appended. Throws an error if any\n * of the new entries have keys that already exist in the map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const original = new Map([[\"a\", 1], [\"b\", 2]])\n * const extended = Maps.append(original, [\"c\", 3], [\"d\", 4])\n * console.log(extended.get(\"c\")) // 3\n * console.log(extended.size) // 4\n * console.log(original.size) // 2 (original unchanged)\n * ```\n *\n * @category mutations\n */\nexport const append = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map.entries())\n appendInto(result, ...values)\n return result\n}\n\n/**\n * Mutates a map by appending entries in place. Throws an error if any\n * of the new entries have keys that already exist in the map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map = new Map([[\"a\", 1], [\"b\", 2]])\n * Maps.appendInto(map, [\"c\", 3], [\"d\", 4])\n * console.log(map.get(\"c\")) // 3\n * console.log(map.size) // 4\n * ```\n *\n * @category mutations\n */\nexport const appendInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Entry<KeyType, ValueType>>): void => {\n for (const [key, value] of values) {\n Assertions.assert(!map.has(key), () => `Maps.append - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n}\n\n/**\n * Creates a new map by concatenating multiple maps together. Throws an error\n * if any duplicate keys are encountered across the maps.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map1 = new Map([[\"a\", 1], [\"b\", 2]])\n * const map2 = new Map([[\"c\", 3]])\n * const map3 = new Map([[\"d\", 4]])\n *\n * const combined = Maps.concatenate(map1, map2, map3)\n * console.log(combined.size) // 4\n * console.log(combined.get(\"c\")) // 3\n * ```\n *\n * @category mutations\n */\nexport const concatenate = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): Map<KeyType, ValueType> => {\n const result = new Map(map)\n concatenateInto(result, ...values)\n return result\n}\n\n/**\n * Mutates a map by concatenating other maps into it in place. Throws an error\n * if any duplicate keys are encountered.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const map1 = new Map([[\"a\", 1], [\"b\", 2]])\n * const map2 = new Map([[\"c\", 3]])\n *\n * Maps.concatenateInto(map1, map2)\n * console.log(map1.size) // 3\n * console.log(map1.get(\"c\")) // 3\n * ```\n *\n * @category mutations\n */\nexport const concatenateInto = <KeyType, ValueType>(map: Map<KeyType, ValueType>, ...values: Array<Map<KeyType, ValueType>>): void => {\n for (const otherMap of values) {\n for (const [key, value] of otherMap) {\n Assertions.assert(!map.has(key), () => `Maps.concatenate - Encountered illegal duplicate key: ${key}`)\n map.set(key, value)\n }\n }\n}\n\n/**\n * Creates a new map containing only entries that satisfy the predicate function.\n * Returns a filtered copy of the original map.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.5], [\"orange\", 2.0]])\n * const expensive = Maps.filter(prices, ([_, price]) => price > 1.0)\n * console.log(expensive.size) // 2\n * console.log(expensive.has(\"banana\")) // false\n * console.log(expensive.get(\"apple\")) // 1.5\n * ```\n *\n * @category filtering\n */\nexport const filter = <KeyType, ValueType>(\n map: Map<KeyType, ValueType>,\n predicate: (entry: Entry<KeyType, ValueType>) => boolean\n): Map<KeyType, ValueType> => {\n const result = new Map(map)\n filterFrom(result, predicate)\n return result\n}\n\n/**\n * Mutates a map by removing entries that don't satisfy the predicate function.\n * Filters the map in place.\n *\n * **Example**\n *\n * ```ts\n * import { Maps } from \"@bessemer/cornerstone\"\n *\n * const prices = new Map([[\"apple\", 1.5], [\"banana\", 0.5], [\"orange\", 2.0]])\n * Maps.filterFrom(prices, ([_, price]) => price > 1.0)\n * console.log(prices.size) // 2\n * console.log(prices.has(\"banana\")) // false\n * ```\n *\n * @category filtering\n */\nexport const filterFrom = <KeyType, ValueType>(map: Map<KeyType, ValueType>, predicate: (entry: Entry<KeyType, ValueType>) => boolean): void => {\n for (const entry of map) {\n if (!predicate(entry)) {\n map.delete(entry[0])\n }\n }\n}\n"],"mappings":";AACA,YAAY,YAAY;AACxB,YAAY,gBAAgB;AAC5B,SAAS,eAAe;AAoBjB,IAAM,OAAO,CAAY,WAA0D;AACxF,SAAO,YAAY,OAAO,QAAQ,MAAM,CAAC;AAC3C;AAmBO,IAAM,cAAc,CACzB,YAC4B;AAC5B,SAAO,QAAQ,SAAS,CAAC,OAAO,EAAE;AACpC;AAwBO,IAAM,UAAU,CACrB,UACA,WACwC;AACxC,SAAO;AAAA,IACL;AAAA,IACA,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;AAAA,IACzB,CAAC,GAAG,OAAO,WAAkB,mBAAY,OAAO,MAAM;AAAA,EACxD;AACF;AAsBO,IAAM,OAAO,CAA+B,QAAgC,cAAiE;AAClJ,SAAO,UAAU,QAAQ,CAAC,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CAAC,CAAC;AAAA,IACrB;AAAA,EACF;AACF;","names":["map","concatenate"]}
@@ -1,12 +1,12 @@
1
1
  import { NominalType } from '@bessemer/cornerstone/types';
2
- import Zod from 'zod';
3
2
  import { Result } from '@bessemer/cornerstone/result';
3
+ import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
4
4
  import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
5
- export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"mime-type">;
5
+ export declare const Namespace: ResourceKeys.ResourceNamespace<"mime-type">;
6
6
  export type MimeLiteral = NominalType<string, typeof Namespace>;
7
7
  export declare const parseString: (initialValue: string) => Result<MimeLiteral, ErrorEvent>;
8
8
  export declare const from: (value: string) => MimeLiteral;
9
- export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<MimeLiteral, string>>;
9
+ export declare const Schema: import("zod").ZodPipe<import("zod").ZodType<MimeLiteral, MimeLiteral, import("zod/v4/core").$ZodTypeInternals<MimeLiteral, MimeLiteral>>, import("zod").ZodTransform<MimeLiteral, MimeLiteral>>;
10
10
  export declare const Jpeg: MimeLiteral;
11
11
  export declare const Png: MimeLiteral;
12
12
  export declare const Gif: MimeLiteral;
@@ -1 +1 @@
1
- {"version":3,"file":"mime-type.d.ts","sourceRoot":"","sources":["../src/mime-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAEvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,eAAO,MAAM,SAAS,6EAA+B,CAAA;AACrD,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE/D,eAAO,MAAM,WAAW,GAAI,cAAc,MAAM,KAAG,MAAM,CAAC,WAAW,EAAE,UAAU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AAgB,eAA2B,CAAA;AAGxD,eAAO,MAAM,QAAQ,EAA4B,WAAW,CAAA;AAC5D,eAAO,MAAM,OAAO,EAA0C,WAAW,CAAA;AACzE,eAAO,MAAM,UAAU,EAA+B,WAAW,CAAA;AACjE,eAAO,MAAM,MAAM,EAAiC,WAAW,CAAA"}
package/dist/mime-type.js CHANGED
@@ -1,21 +1,20 @@
1
1
  // src/mime-type.ts
2
- import Zod from "zod";
3
- import { failure, success } from "@bessemer/cornerstone/result";
4
- import { createNamespace } from "@bessemer/cornerstone/resource-key";
5
- import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
6
- import { structuredTransform } from "@bessemer/cornerstone/zod-util";
7
- var Namespace = createNamespace("mime-type");
2
+ import * as Results from "@bessemer/cornerstone/result";
3
+ import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
4
+ import * as ErrorEvents from "@bessemer/cornerstone/error/error-event";
5
+ import * as ZodUtil from "@bessemer/cornerstone/zod-util";
6
+ var Namespace = ResourceKeys.createNamespace("mime-type");
8
7
  var parseString = (initialValue) => {
9
8
  const value = initialValue.trim().toLowerCase();
10
9
  if (!/^[\w-]+\/[\w.+-]+$/.test(value)) {
11
- return failure(invalidValue(value, { namespace: Namespace, message: `Invalid MIME type format.` }));
10
+ return Results.failure(ErrorEvents.invalidValue(value, { namespace: Namespace, message: `Invalid MIME type format.` }));
12
11
  }
13
- return success(value);
12
+ return Results.success(value);
14
13
  };
15
14
  var from = (value) => {
16
- return unpackResult(parseString(value));
15
+ return ErrorEvents.unpackResult(parseString(value));
17
16
  };
18
- var Schema = structuredTransform(Zod.string(), parseString).meta({
17
+ var Schema = ZodUtil.structuredTransform(ZodUtil.string(), parseString).meta({
19
18
  type: "string",
20
19
  format: Namespace,
21
20
  pattern: "^[\\w-]+\\/[\\w.+-]+$"
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mime-type.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = createNamespace('mime-type')\nexport type MimeLiteral = NominalType<string, typeof Namespace>\n\nexport const parseString = (initialValue: string): Result<MimeLiteral, ErrorEvent> => {\n const value = initialValue.trim().toLowerCase()\n\n if (!/^[\\w-]+\\/[\\w.+-]+$/.test(value)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `Invalid MIME type format.` }))\n }\n\n return success(value as MimeLiteral)\n}\n\nexport const from = (value: string): MimeLiteral => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString).meta({\n type: 'string',\n format: Namespace,\n pattern: '^[\\\\w-]+\\\\/[\\\\w.+-]+$',\n})\n\n// Images\nexport const Jpeg = 'image/jpeg' as MimeLiteral\nexport const Png = 'image/png' as MimeLiteral\nexport const Gif = 'image/gif' as MimeLiteral\nexport const Webp = 'image/webp' as MimeLiteral\nexport const Svg = 'image/svg+xml' as MimeLiteral\nexport const Ico = 'image/x-icon' as MimeLiteral\nexport const Avif = 'image/avif' as MimeLiteral\nexport const ImageTypes = [Jpeg, Png, Gif, Webp, Svg, Ico, Avif]\n\n// Video\nexport const Mp4 = 'video/mp4' as MimeLiteral\nexport const Webm = 'video/webm' as MimeLiteral\nexport const OggVideo = 'video/ogg' as MimeLiteral\nexport const VideoTypes = [Mp4, Webm, OggVideo]\n\n// Audio\nexport const Mp3 = 'audio/mpeg' as MimeLiteral\nexport const OggAudio = 'audio/ogg' as MimeLiteral\nexport const Wav = 'audio/wav' as MimeLiteral\nexport const AudioTypes = [Mp3, OggAudio, Wav]\n\n// Documents\nexport const Pdf = 'application/pdf' as MimeLiteral\nexport const Json = 'application/json' as MimeLiteral\nexport const Csv = 'text/csv' as MimeLiteral\nexport const Text = 'text/plain' as MimeLiteral\nexport const Html = 'text/html' as MimeLiteral\nexport const Xml = 'application/xml' as MimeLiteral\nexport const DocumentTypes = [Pdf, Json, Csv, Text, Html, Xml]\n\n// Fonts\nexport const Woff = 'font/woff' as MimeLiteral\nexport const Woff2 = 'font/woff2' as MimeLiteral\nexport const Ttf = 'font/ttf' as MimeLiteral\nexport const Otf = 'font/otf' as MimeLiteral\nexport const FontTypes = [Woff, Woff2, Ttf, Otf]\n\n// Compression\nexport const Zip = 'application/zip' as MimeLiteral\nexport const Gzip = 'application/gzip' as MimeLiteral\nexport const Tar = 'application/x-tar' as MimeLiteral\nexport const Brotli = 'application/x-brotli' as MimeLiteral\nexport const CompressionTypes = [Zip, Gzip, Tar, Brotli]\n\n// Misc\nexport const FormData = 'multipart/form-data' as MimeLiteral\nexport const FormUrl = 'application/x-www-form-urlencoded' as MimeLiteral\nexport const Javascript = 'application/javascript' as MimeLiteral\nexport const Binary = 'application/octet-stream' as MimeLiteral\n"],"mappings":";AACA,OAAO,SAAS;AAChB,SAAS,SAAiB,eAAe;AACzC,SAAS,uBAAuB;AAChC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,2BAA2B;AAE7B,IAAM,YAAY,gBAAgB,WAAW;AAG7C,IAAM,cAAc,CAAC,iBAA0D;AACpF,QAAM,QAAQ,aAAa,KAAK,EAAE,YAAY;AAE9C,MAAI,CAAC,qBAAqB,KAAK,KAAK,GAAG;AACrC,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,4BAA4B,CAAC,CAAC;AAAA,EACpG;AAEA,SAAO,QAAQ,KAAoB;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AAClD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW,EAAE,KAAK;AAAA,EACxE,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AACX,CAAC;AAGM,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,aAAa,CAAC,MAAM,KAAK,KAAK,MAAM,KAAK,KAAK,IAAI;AAGxD,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,WAAW;AACjB,IAAM,aAAa,CAAC,KAAK,MAAM,QAAQ;AAGvC,IAAM,MAAM;AACZ,IAAM,WAAW;AACjB,IAAM,MAAM;AACZ,IAAM,aAAa,CAAC,KAAK,UAAU,GAAG;AAGtC,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,gBAAgB,CAAC,KAAK,MAAM,KAAK,MAAM,MAAM,GAAG;AAGtD,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,MAAM;AACZ,IAAM,MAAM;AACZ,IAAM,YAAY,CAAC,MAAM,OAAO,KAAK,GAAG;AAGxC,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,SAAS;AACf,IAAM,mBAAmB,CAAC,KAAK,MAAM,KAAK,MAAM;AAGhD,IAAM,WAAW;AACjB,IAAM,UAAU;AAChB,IAAM,aAAa;AACnB,IAAM,SAAS;","names":[]}
1
+ {"version":3,"sources":["../src/mime-type.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\nimport * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport * as ZodUtil from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = ResourceKeys.createNamespace('mime-type')\nexport type MimeLiteral = NominalType<string, typeof Namespace>\n\nexport const parseString = (initialValue: string): Result<MimeLiteral, ErrorEvent> => {\n const value = initialValue.trim().toLowerCase()\n\n if (!/^[\\w-]+\\/[\\w.+-]+$/.test(value)) {\n return Results.failure(ErrorEvents.invalidValue(value, { namespace: Namespace, message: `Invalid MIME type format.` }))\n }\n\n return Results.success(value as MimeLiteral)\n}\n\nexport const from = (value: string): MimeLiteral => {\n return ErrorEvents.unpackResult(parseString(value))\n}\n\nexport const Schema = ZodUtil.structuredTransform<MimeLiteral>(ZodUtil.string(), parseString).meta({\n type: 'string',\n format: Namespace,\n pattern: '^[\\\\w-]+\\\\/[\\\\w.+-]+$',\n})\n\n// Images\nexport const Jpeg = 'image/jpeg' as MimeLiteral\nexport const Png = 'image/png' as MimeLiteral\nexport const Gif = 'image/gif' as MimeLiteral\nexport const Webp = 'image/webp' as MimeLiteral\nexport const Svg = 'image/svg+xml' as MimeLiteral\nexport const Ico = 'image/x-icon' as MimeLiteral\nexport const Avif = 'image/avif' as MimeLiteral\nexport const ImageTypes = [Jpeg, Png, Gif, Webp, Svg, Ico, Avif]\n\n// Video\nexport const Mp4 = 'video/mp4' as MimeLiteral\nexport const Webm = 'video/webm' as MimeLiteral\nexport const OggVideo = 'video/ogg' as MimeLiteral\nexport const VideoTypes = [Mp4, Webm, OggVideo]\n\n// Audio\nexport const Mp3 = 'audio/mpeg' as MimeLiteral\nexport const OggAudio = 'audio/ogg' as MimeLiteral\nexport const Wav = 'audio/wav' as MimeLiteral\nexport const AudioTypes = [Mp3, OggAudio, Wav]\n\n// Documents\nexport const Pdf = 'application/pdf' as MimeLiteral\nexport const Json = 'application/json' as MimeLiteral\nexport const Csv = 'text/csv' as MimeLiteral\nexport const Text = 'text/plain' as MimeLiteral\nexport const Html = 'text/html' as MimeLiteral\nexport const Xml = 'application/xml' as MimeLiteral\nexport const DocumentTypes = [Pdf, Json, Csv, Text, Html, Xml]\n\n// Fonts\nexport const Woff = 'font/woff' as MimeLiteral\nexport const Woff2 = 'font/woff2' as MimeLiteral\nexport const Ttf = 'font/ttf' as MimeLiteral\nexport const Otf = 'font/otf' as MimeLiteral\nexport const FontTypes = [Woff, Woff2, Ttf, Otf]\n\n// Compression\nexport const Zip = 'application/zip' as MimeLiteral\nexport const Gzip = 'application/gzip' as MimeLiteral\nexport const Tar = 'application/x-tar' as MimeLiteral\nexport const Brotli = 'application/x-brotli' as MimeLiteral\nexport const CompressionTypes = [Zip, Gzip, Tar, Brotli]\n\n// Misc\nexport const FormData = 'multipart/form-data' as MimeLiteral\nexport const FormUrl = 'application/x-www-form-urlencoded' as MimeLiteral\nexport const Javascript = 'application/javascript' as MimeLiteral\nexport const Binary = 'application/octet-stream' as MimeLiteral\n"],"mappings":";AACA,YAAY,aAAa;AAEzB,YAAY,kBAAkB;AAC9B,YAAY,iBAAiB;AAE7B,YAAY,aAAa;AAElB,IAAM,YAAyB,6BAAgB,WAAW;AAG1D,IAAM,cAAc,CAAC,iBAA0D;AACpF,QAAM,QAAQ,aAAa,KAAK,EAAE,YAAY;AAE9C,MAAI,CAAC,qBAAqB,KAAK,KAAK,GAAG;AACrC,WAAe,gBAAoB,yBAAa,OAAO,EAAE,WAAW,WAAW,SAAS,4BAA4B,CAAC,CAAC;AAAA,EACxH;AAEA,SAAe,gBAAQ,KAAoB;AAC7C;AAEO,IAAM,OAAO,CAAC,UAA+B;AAClD,SAAmB,yBAAa,YAAY,KAAK,CAAC;AACpD;AAEO,IAAM,SAAiB,4BAAyC,eAAO,GAAG,WAAW,EAAE,KAAK;AAAA,EACjG,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AACX,CAAC;AAGM,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,aAAa,CAAC,MAAM,KAAK,KAAK,MAAM,KAAK,KAAK,IAAI;AAGxD,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,WAAW;AACjB,IAAM,aAAa,CAAC,KAAK,MAAM,QAAQ;AAGvC,IAAM,MAAM;AACZ,IAAM,WAAW;AACjB,IAAM,MAAM;AACZ,IAAM,aAAa,CAAC,KAAK,UAAU,GAAG;AAGtC,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,gBAAgB,CAAC,KAAK,MAAM,KAAK,MAAM,MAAM,GAAG;AAGtD,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,MAAM;AACZ,IAAM,MAAM;AACZ,IAAM,YAAY,CAAC,MAAM,OAAO,KAAK,GAAG;AAGxC,IAAM,MAAM;AACZ,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,SAAS;AACf,IAAM,mBAAmB,CAAC,KAAK,MAAM,KAAK,MAAM;AAGhD,IAAM,WAAW;AACjB,IAAM,UAAU;AAChB,IAAM,aAAa;AACnB,IAAM,SAAS;","names":[]}
package/dist/misc.js CHANGED
@@ -1,14 +1,14 @@
1
1
  // src/misc.ts
2
- import { isPresent } from "@bessemer/cornerstone/object";
3
- import { assert } from "@bessemer/cornerstone/assertion";
2
+ import * as Objects from "@bessemer/cornerstone/object";
3
+ import * as Assertions from "@bessemer/cornerstone/assertion";
4
4
  var doUntilConsistent = (supplier, equals) => {
5
5
  let done = false;
6
6
  let previousValue = null;
7
7
  let attempts = 0;
8
8
  do {
9
- assert(attempts < 10);
9
+ Assertions.assert(attempts < 10);
10
10
  const currentValue = supplier(previousValue);
11
- if (isPresent(previousValue) && equals(previousValue, currentValue)) {
11
+ if (Objects.isPresent(previousValue) && equals(previousValue, currentValue)) {
12
12
  done = true;
13
13
  }
14
14
  previousValue = currentValue;
package/dist/misc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/misc.ts"],"sourcesContent":["import { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport { isPresent } from '@bessemer/cornerstone/object'\nimport { assert } from '@bessemer/cornerstone/assertion'\n\nexport const doUntilConsistent = <T>(supplier: (previous: T | null) => T, equals: Equalitor<T>): T => {\n let done = false\n let previousValue: T | null = null\n let attempts = 0\n do {\n assert(attempts < 10)\n\n const currentValue = supplier(previousValue)\n\n if (isPresent(previousValue) && equals(previousValue, currentValue)) {\n done = true\n }\n\n previousValue = currentValue\n attempts++\n } while (!done)\n\n return previousValue\n}\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AAEhB,IAAM,oBAAoB,CAAI,UAAqC,WAA4B;AACpG,MAAI,OAAO;AACX,MAAI,gBAA0B;AAC9B,MAAI,WAAW;AACf,KAAG;AACD,WAAO,WAAW,EAAE;AAEpB,UAAM,eAAe,SAAS,aAAa;AAE3C,QAAI,UAAU,aAAa,KAAK,OAAO,eAAe,YAAY,GAAG;AACnE,aAAO;AAAA,IACT;AAEA,oBAAgB;AAChB;AAAA,EACF,SAAS,CAAC;AAEV,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/misc.ts"],"sourcesContent":["import { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\n\nexport const doUntilConsistent = <T>(supplier: (previous: T | null) => T, equals: Equalitor<T>): T => {\n let done = false\n let previousValue: T | null = null\n let attempts = 0\n do {\n Assertions.assert(attempts < 10)\n\n const currentValue = supplier(previousValue)\n\n if (Objects.isPresent(previousValue) && equals(previousValue, currentValue)) {\n done = true\n }\n\n previousValue = currentValue\n attempts++\n } while (!done)\n\n return previousValue\n}\n"],"mappings":";AACA,YAAY,aAAa;AACzB,YAAY,gBAAgB;AAErB,IAAM,oBAAoB,CAAI,UAAqC,WAA4B;AACpG,MAAI,OAAO;AACX,MAAI,gBAA0B;AAC9B,MAAI,WAAW;AACf,KAAG;AACD,IAAW,kBAAO,WAAW,EAAE;AAE/B,UAAM,eAAe,SAAS,aAAa;AAE3C,QAAY,kBAAU,aAAa,KAAK,OAAO,eAAe,YAAY,GAAG;AAC3E,aAAO;AAAA,IACT;AAEA,oBAAgB;AAChB;AAAA,EACF,SAAS,CAAC;AAEV,SAAO;AACT;","names":[]}
@@ -1,16 +1,17 @@
1
1
  import { CurrencyCode } from '@bessemer/cornerstone/intl/currency-code';
2
2
  import Zod from 'zod';
3
3
  import { Comparator } from '@bessemer/cornerstone/comparator';
4
+ import * as Equalitors from '@bessemer/cornerstone/equalitor';
4
5
  export type MonetaryAmount = {
5
6
  amount: number;
6
7
  currency: CurrencyCode;
7
8
  };
8
9
  export declare const Schema: Zod.ZodObject<{
9
10
  amount: Zod.ZodNumber;
10
- currency: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<CurrencyCode, string>>;
11
+ currency: Zod.ZodPipe<Zod.ZodType<CurrencyCode, CurrencyCode, Zod.core.$ZodTypeInternals<CurrencyCode, CurrencyCode>>, Zod.ZodTransform<CurrencyCode, CurrencyCode>>;
11
12
  }, Zod.core.$strip>;
12
13
  export declare const CompareBy: Comparator<MonetaryAmount>;
13
- export declare const EqualBy: import("@bessemer/cornerstone/equalitor").Equalitor<MonetaryAmount>;
14
+ export declare const EqualBy: Equalitors.Equalitor<MonetaryAmount>;
14
15
  export declare const of: (amount: number, currency: CurrencyCode) => MonetaryAmount;
15
16
  export declare const zero: (currency: CurrencyCode) => MonetaryAmount;
16
17
  export declare const apply: <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T) => T;
@@ -1 +1 @@
1
- {"version":3,"file":"monetary-amount.d.ts","sourceRoot":"","sources":["../src/monetary-amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgC,MAAM,0CAA0C,CAAA;AACrG,OAAO,GAAG,MAAM,KAAK,CAAA;AAGrB,OAAO,EAAE,UAAU,EAAW,MAAM,kCAAkC,CAAA;AAItE,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,YAAY,CAAA;CACvB,CAAA;AAED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MAAM,QAAQ,GAAI,OAAO,cAAc,EAAE,QAAQ,cAAc,KAAG,OAExE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,OAAO,cAAc,EAAE,QAAQ,cAAc,KAAG,OAElF,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,cAAc,EAAE,QAAQ,cAAc,KAAG,OAE/E,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,QAAQ,cAAc,EAAE,YAAY,MAAM,EAAE,UAAU,2BAA2B,KAAG,MAgB1G,CAAA"}
@@ -1,21 +1,21 @@
1
1
  // src/monetary-amount.ts
2
- import { Schema as CurrencyCodeSchema } from "@bessemer/cornerstone/intl/currency-code";
2
+ import * as CurrencyCodes from "@bessemer/cornerstone/intl/currency-code";
3
3
  import Zod from "zod";
4
- import { isNil } from "@bessemer/cornerstone/object";
5
- import { roundHalfEven } from "@bessemer/cornerstone/math";
6
- import { natural } from "@bessemer/cornerstone/comparator";
7
- import { fromComparator } from "@bessemer/cornerstone/equalitor";
8
- import { assert } from "@bessemer/cornerstone/assertion";
9
- var Schema = Zod.object({
4
+ import * as Objects from "@bessemer/cornerstone/object";
5
+ import * as Maths from "@bessemer/cornerstone/math";
6
+ import * as Comparators from "@bessemer/cornerstone/comparator";
7
+ import * as Equalitors from "@bessemer/cornerstone/equalitor";
8
+ import * as Assertions from "@bessemer/cornerstone/assertion";
9
+ var Schema2 = Zod.object({
10
10
  amount: Zod.number().int(),
11
- currency: CurrencyCodeSchema
11
+ currency: CurrencyCodes.Schema
12
12
  });
13
13
  var CompareBy = (first, second) => {
14
- return apply(first, second, natural());
14
+ return apply(first, second, Comparators.natural());
15
15
  };
16
- var EqualBy = fromComparator(CompareBy);
16
+ var EqualBy = Equalitors.fromComparator(CompareBy);
17
17
  var of = (amount, currency) => {
18
- assert(Number.isInteger(amount));
18
+ Assertions.assert(Number.isInteger(amount));
19
19
  return { amount, currency };
20
20
  };
21
21
  var zero = (currency) => {
@@ -31,10 +31,10 @@ var operate = (first, second, operator) => {
31
31
  return of(apply(first, second, operator), first.currency);
32
32
  };
33
33
  var equal = (first, second) => {
34
- if (isNil(first) && isNil(second)) {
34
+ if (Objects.isNil(first) && Objects.isNil(second)) {
35
35
  return true;
36
36
  }
37
- if (isNil(first) || isNil(second)) {
37
+ if (Objects.isNil(first) || Objects.isNil(second)) {
38
38
  return false;
39
39
  }
40
40
  return apply(first, second, (first2, second2) => first2 === second2);
@@ -46,10 +46,10 @@ var subtract = (first, second) => {
46
46
  return operate(first, second, (first2, second2) => first2 - second2);
47
47
  };
48
48
  var multiply = (money, value) => {
49
- return of(roundHalfEven(money.amount * value, 0), money.currency);
49
+ return of(Maths.roundHalfEven(money.amount * value, 0), money.currency);
50
50
  };
51
51
  var divide = (money, value) => {
52
- return of(roundHalfEven(money.amount / value, 0), money.currency);
52
+ return of(Maths.roundHalfEven(money.amount / value, 0), money.currency);
53
53
  };
54
54
  function sumAll(monetaryAmounts, currency) {
55
55
  const resolvedCurrency = currency ?? monetaryAmounts[0].currency;
@@ -92,7 +92,7 @@ var format = (amount, alpha2Code, options) => {
92
92
  export {
93
93
  CompareBy,
94
94
  EqualBy,
95
- Schema,
95
+ Schema2 as Schema,
96
96
  apply,
97
97
  divide,
98
98
  equal,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/monetary-amount.ts"],"sourcesContent":["import { CurrencyCode, Schema as CurrencyCodeSchema } from '@bessemer/cornerstone/intl/currency-code'\nimport Zod from 'zod'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { roundHalfEven } from '@bessemer/cornerstone/math'\nimport { Comparator, natural } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { assert } from '@bessemer/cornerstone/assertion'\n\nexport type MonetaryAmount = {\n amount: number\n currency: CurrencyCode\n}\n\nexport const Schema = Zod.object({\n amount: Zod.number().int(),\n currency: CurrencyCodeSchema,\n})\n\nexport const CompareBy: Comparator<MonetaryAmount> = (first: MonetaryAmount, second: MonetaryAmount): number => {\n return apply(first, second, natural())\n}\n\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const of = (amount: number, currency: CurrencyCode): MonetaryAmount => {\n assert(Number.isInteger(amount))\n return { amount, currency }\n}\n\nexport const zero = (currency: CurrencyCode): MonetaryAmount => {\n return { amount: 0, currency }\n}\n\nexport const apply = <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T): T => {\n if (first.currency !== second.currency) {\n throw new Error(`Currency mismatch in operation on MonetaryAmount: ${first.currency}, ${second.currency}`)\n }\n\n return operator(first.amount, second.amount)\n}\n\nexport const operate = (first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => number): MonetaryAmount => {\n return of(apply(first, second, operator), first.currency)\n}\n\n/** Determines whether two MonetaryAmounts are considered equivalent */\nexport const equal = (first?: MonetaryAmount | null, second?: MonetaryAmount | null): boolean => {\n if (isNil(first) && isNil(second)) {\n return true\n }\n if (isNil(first) || isNil(second)) {\n return false\n }\n\n return apply(first, second, (first, second) => first === second)\n}\n\nexport const sum = (first: MonetaryAmount, second?: MonetaryAmount | null): MonetaryAmount => {\n return operate(first, second ?? zero(first.currency), (first, second) => first + second)\n}\n\nexport const subtract = (first: MonetaryAmount, second: MonetaryAmount): MonetaryAmount => {\n return operate(first, second, (first, second) => first - second)\n}\n\nexport const multiply = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount * value, 0), money.currency)\n}\n\nexport const divide = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount / value, 0), money.currency)\n}\n\nexport function sumAll(monetaryAmounts: readonly [MonetaryAmount, ...MonetaryAmount[]]): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency: CurrencyCode): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency?: CurrencyCode): MonetaryAmount {\n const resolvedCurrency = currency ?? monetaryAmounts[0]!.currency\n return monetaryAmounts.reduce<MonetaryAmount>((first, second) => sum(second, first), zero(resolvedCurrency))\n}\n\nexport const negate = (monetaryAmount: MonetaryAmount): MonetaryAmount => {\n // Avoid creating a negative 0, which is a real thing!\n if (isZero(monetaryAmount)) {\n return monetaryAmount\n }\n\n return of(-monetaryAmount.amount, monetaryAmount.currency)\n}\n\nexport const isZero = (monetaryAmount: MonetaryAmount): boolean => {\n return monetaryAmount.amount === 0\n}\n\nexport const greaterThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first > second)\n}\n\nexport const lessThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first < second)\n}\n\nexport const greaterThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first >= second)\n}\n\nexport const lessThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first <= second)\n}\n\nexport type MonetaryAmountFormatOptions = {\n hideCents?: boolean\n}\n\nexport const format = (amount: MonetaryAmount, alpha2Code: string, options?: MonetaryAmountFormatOptions): string => {\n const hideCents = options?.hideCents ?? false\n const isWholeNumber = amount.amount % 100 === 0\n\n const formatCurrency = new Intl.NumberFormat(alpha2Code, {\n style: 'currency',\n currency: amount.currency,\n ...(hideCents\n ? {\n minimumFractionDigits: isWholeNumber ? 0 : 2,\n maximumFractionDigits: 2,\n }\n : {}),\n })\n\n return formatCurrency.format(amount.amount / 100)\n}\n"],"mappings":";AAAA,SAAuB,UAAU,0BAA0B;AAC3D,OAAO,SAAS;AAChB,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAqB,eAAe;AACpC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AAOhB,IAAM,SAAS,IAAI,OAAO;AAAA,EAC/B,QAAQ,IAAI,OAAO,EAAE,IAAI;AAAA,E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,uBAAuB,gBAAgB,IAAI;AAAA,MAC3C,uBAAuB;AAAA,IACzB,IACA,CAAC;AAAA,EACP,CAAC;AAED,SAAO,eAAe,OAAO,OAAO,SAAS,GAAG;AAClD;","names":["first","second"]}
1
+ {"version":3,"sources":["../src/monetary-amount.ts"],"sourcesContent":["import { CurrencyCode } from '@bessemer/cornerstone/intl/currency-code'\nimport * as CurrencyCodes from '@bessemer/cornerstone/intl/currency-code'\nimport Zod from 'zod'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport * as Maths from '@bessemer/cornerstone/math'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport * as Comparators from '@bessemer/cornerstone/comparator'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\n\nexport type MonetaryAmount = {\n amount: number\n currency: CurrencyCode\n}\n\nexport const Schema = Zod.object({\n amount: Zod.number().int(),\n currency: CurrencyCodes.Schema,\n})\n\nexport const CompareBy: Comparator<MonetaryAmount> = (first: MonetaryAmount, second: MonetaryAmount): number => {\n return apply(first, second, Comparators.natural())\n}\n\nexport const EqualBy = Equalitors.fromComparator(CompareBy)\n\nexport const of = (amount: number, currency: CurrencyCode): MonetaryAmount => {\n Assertions.assert(Number.isInteger(amount))\n return { amount, currency }\n}\n\nexport const zero = (currency: CurrencyCode): MonetaryAmount => {\n return { amount: 0, currency }\n}\n\nexport const apply = <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T): T => {\n if (first.currency !== second.currency) {\n throw new Error(`Currency mismatch in operation on MonetaryAmount: ${first.currency}, ${second.currency}`)\n }\n\n return operator(first.amount, second.amount)\n}\n\nexport const operate = (first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => number): MonetaryAmount => {\n return of(apply(first, second, operator), first.currency)\n}\n\n/** Determines whether two MonetaryAmounts are considered equivalent */\nexport const equal = (first?: MonetaryAmount | null, second?: MonetaryAmount | null): boolean => {\n if (Objects.isNil(first) && Objects.isNil(second)) {\n return true\n }\n if (Objects.isNil(first) || Objects.isNil(second)) {\n return false\n }\n\n return apply(first, second, (first, second) => first === second)\n}\n\nexport const sum = (first: MonetaryAmount, second?: MonetaryAmount | null): MonetaryAmount => {\n return operate(first, second ?? zero(first.currency), (first, second) => first + second)\n}\n\nexport const subtract = (first: MonetaryAmount, second: MonetaryAmount): MonetaryAmount => {\n return operate(first, second, (first, second) => first - second)\n}\n\nexport const multiply = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(Maths.roundHalfEven(money.amount * value, 0), money.currency)\n}\n\nexport const divide = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(Maths.roundHalfEven(money.amount / value, 0), money.currency)\n}\n\nexport function sumAll(monetaryAmounts: readonly [MonetaryAmount, ...MonetaryAmount[]]): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency: CurrencyCode): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency?: CurrencyCode): MonetaryAmount {\n const resolvedCurrency = currency ?? monetaryAmounts[0]!.currency\n return monetaryAmounts.reduce<MonetaryAmount>((first, second) => sum(second, first), zero(resolvedCurrency))\n}\n\nexport const negate = (monetaryAmount: MonetaryAmount): MonetaryAmount => {\n // Avoid creating a negative 0, which is a real thing!\n if (isZero(monetaryAmount)) {\n return monetaryAmount\n }\n\n return of(-monetaryAmount.amount, monetaryAmount.currency)\n}\n\nexport const isZero = (monetaryAmount: MonetaryAmount): boolean => {\n return monetaryAmount.amount === 0\n}\n\nexport const greaterThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first > second)\n}\n\nexport const lessThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first < second)\n}\n\nexport const greaterThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first >= second)\n}\n\nexport const lessThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first <= second)\n}\n\nexport type MonetaryAmountFormatOptions = {\n hideCents?: boolean\n}\n\nexport const format = (amount: MonetaryAmount, alpha2Code: string, options?: MonetaryAmountFormatOptions): string => {\n const hideCents = options?.hideCents ?? false\n const isWholeNumber = amount.amount % 100 === 0\n\n const formatCurrency = new Intl.NumberFormat(alpha2Code, {\n style: 'currency',\n currency: amount.currency,\n ...(hideCents\n ? {\n minimumFractionDigits: isWholeNumber ? 0 : 2,\n maximumFractionDigits: 2,\n }\n : {}),\n })\n\n return formatCurrency.format(amount.amount / 100)\n}\n"],"mappings":";AACA,YAAY,mBAAmB;AAC/B,OAAO,SAAS;AAChB,YAAY,aAAa;AACzB,YAAY,WAAW;AAEvB,YAAY,iBAAiB;AAC7B,YAAY,gBAAgB;AAC5B,YAAY,gBAAgB;AAOrB,IAAMA,UAAS,IAAI,OAAO;AAAA,EAC/B,QAAQ,IAAI,OAAO,EAAE,IAAI;AAAA,EACzB,UAAwB;AAC1B,CAAC;AAEM,IAAM,YAAwC,CAAC,OAAuB,WAAmC;AAC9G,SAAO,MAAM,OAAO,QAAoB,oBAAQ,CAAC;AACnD;AAEO,IAAM,UAAqB,0BAAe,SAAS;AAEnD,IAAM,KAAK,CAAC,QAAgB,aAA2C;AAC5E,EAAW,kBAAO,OAAO,UAAU,MAAM,CAAC;AAC1C,SAAO,EAAE,QAAQ,SAAS;AAC5B;AAEO,IAAM,OAAO,CAAC,aAA2C;AAC9D,SAAO,EAAE,QAAQ,GAAG,SAAS;AAC/B;AAEO,IAAM,QAAQ,CAAI,OAAuB,QAAwB,aAAsD;AAC5H,MAAI,MAAM,aAAa,OAAO,UAAU;AACtC,UAAM,IAAI,MAAM,qDAAqD,MAAM,QAAQ,KAAK,OAAO,QAAQ,EAAE;AAAA,EAC3G;AAEA,SAAO,SAAS,MAAM,QAAQ,OAAO,MAAM;AAC7C;AAEO,IAAM,UAAU,CAAC,OAAuB,QAAwB,aAAwE;AAC7I,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AM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,SAAQC,OAAM;AAC/D;AAEO,IAAM,WAAW,CAAC,OAAuB,WAAoC;AAClF,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,SAAQC,OAAM;AAC/D;AAEO,IAAM,qBAAqB,CAAC,OAAuB,WAAoC;AAC5F,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,UAASC,OAAM;AAChE;AAEO,IAAM,kBAAkB,CAAC,OAAuB,WAAoC;AACzF,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,UAASC,OAAM;AAChE;AAMO,IAAM,SAAS,CAAC,QAAwB,YAAoB,YAAkD;AACnH,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,gBAAgB,OAAO,SAAS,QAAQ;AAE9C,QAAM,iBAAiB,IAAI,KAAK,aAAa,YAAY;AAAA,IACvD,OAAO;AAAA,IACP,UAAU,OAAO;AAAA,IACjB,GAAI,YACA;AAAA,MACE,uBAAuB,gBAAgB,IAAI;AAAA,MAC3C,uBAAuB;AAAA,IACzB,IACA,CAAC;AAAA,EACP,CAAC;AAED,SAAO,eAAe,OAAO,OAAO,SAAS,GAAG;AAClD;","names":["Schema","first","second"]}
@@ -1,8 +1,9 @@
1
1
  import { Result } from '@bessemer/cornerstone/result';
2
2
  import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
3
+ import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
3
4
  import { Dictionary, NominalType } from '@bessemer/cornerstone/types';
4
5
  import { MimeLiteral } from '@bessemer/cornerstone/mime-type';
5
- export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"content-type">;
6
+ export declare const Namespace: ResourceKeys.ResourceNamespace<"content-type">;
6
7
  export type ContentType = {
7
8
  mimeType: MimeLiteral;
8
9
  parameters: Dictionary<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/net/content-type.ts"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,EAAE,eAAe,GAAG,kBAAkB,CAAA;AACzE,wBAAgB,SAAS,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,GAAG,kBAAkB,GAAG,IAAI,CAAA;AACvF,wBAAgB,SAAS,CAAC,SAAS,EAAE,eAAe,GAAG,SAAS,GAAG,kBAAkB,GAAG,SAAS,CAAA;AACjG,wBAAgB,SAAS,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GAAG,kBAAkB,GAAG,IAAI,GAAG,SAAS,CAAA;AA2B/G,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,WAAW,EAAE,UAAU,CAgGzE,CAAA"}
@@ -1,11 +1,11 @@
1
1
  // src/net/content-type.ts
2
2
  import * as Results from "@bessemer/cornerstone/result";
3
3
  import * as ErrorEvents from "@bessemer/cornerstone/error/error-event";
4
- import { createNamespace } from "@bessemer/cornerstone/resource-key";
4
+ import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
5
5
  import * as MimeTypes from "@bessemer/cornerstone/mime-type";
6
6
  import * as Strings from "@bessemer/cornerstone/string";
7
7
  import * as Objects from "@bessemer/cornerstone/object";
8
- var Namespace = createNamespace("content-type");
8
+ var Namespace = ResourceKeys.createNamespace("content-type");
9
9
  function from(value) {
10
10
  if (Objects.isNil(value)) {
11
11
  return value;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/net/content-type.ts"],"sourcesContent":["import * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { Dictionary, NominalType } from '@bessemer/cornerstone/types'\nimport * as MimeTypes from '@bessemer/cornerstone/mime-type'\nimport { MimeLiteral } from '@bessemer/cornerstone/mime-type'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport const Namespace = createNamespace('content-type')\nexport type ContentType = { mimeType: MimeLiteral; parameters: Dictionary<string> }\nexport type ContentTypeLiteral = NominalType<string, typeof Namespace>\n\nexport type ContentTypeLike = ContentType | ContentTypeLiteral | MimeLiteral\n\nexport function from(value: ContentTypeLike | string): ContentType\nexport function from(value: ContentTypeLike | string | null): ContentType | null\nexport function from(value: ContentTypeLike | string | undefined): ContentType | undefined\nexport function from(value: ContentTypeLike | string | null | undefined): ContentType | null | undefined\nexport function from(value: ContentTypeLike | string | null | undefined): ContentType | null | undefined {\n if (Objects.isNil(value)) {\n return value\n }\n\n if (Strings.isString(value)) {\n return ErrorEvents.unpackResult(parseString(value))\n }\n\n return value\n}\n\nexport function toLiteral(likeValue: ContentTypeLike): ContentTypeLiteral\nexport function toLiteral(likeValue: ContentTypeLike | null): ContentTypeLiteral | null\nexport function toLiteral(likeValue: ContentTypeLike | undefined): ContentTypeLiteral | undefined\nexport function toLiteral(likeValue: ContentTypeLike | null | undefined): ContentTypeLiteral | null | undefined\nexport function toLiteral(likeValue: ContentTypeLike | null | undefined): ContentTypeLiteral | null | undefined {\n if (Objects.isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n\n if (Objects.isEmpty(value.parameters)) {\n return value.mimeType as ContentTypeLiteral\n }\n\n const params = Object.entries(value.parameters).map(([key, val]) => {\n // Quote the value if it contains special characters or spaces\n const needsQuoting = /[ ()<>@,;:\\\\/[\\]?=]/.test(val) || Strings.isEmpty(val)\n const quotedValue = needsQuoting ? `\"${val}\"` : val\n return `${key}=${quotedValue}`\n })\n\n return `${value.mimeType};${params.join(';')}` as ContentTypeLiteral\n}\n\n// RFC 2045 token: 1*<any (US-ASCII) CHAR except SPACE, CTLs, or tspecials>\n// tspecials: ()<>@,;:\\\"/[]?=\nconst TokenKeyRegex = /^[!#$%&'*+\\-.0-9A-Z^_`a-z|~]+$/\n\n// JOHN some of the error messages here should be looked at\nexport const parseString = (value: string): Result<ContentType, ErrorEvent> => {\n const tokens = value.split(';')\n const mimeTypeString = tokens[0]!\n const mimeType = MimeTypes.parseString(mimeTypeString)\n\n if (Results.isFailure(mimeType)) {\n return mimeType\n }\n\n if (tokens.length === 1) {\n return Results.success({ mimeType, parameters: {} })\n }\n\n const parameters: Dictionary<string> = {}\n\n for (const token of tokens.slice(1)) {\n const keyPart = Strings.splitFirst(token, '=')\n\n if (Objects.isNil(keyPart.selection)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter format: [${token}]. Parameters must be in key=value format.`,\n })\n )\n }\n\n const tokenKey = keyPart.selection.trim()\n if (!TokenKeyRegex.test(tokenKey)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter format: [${token}]. Parameters must be in key=value format.`,\n })\n )\n }\n\n let tokenValue = keyPart.rest.trim()\n if (Strings.isEmpty(tokenValue)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: value cant be blank.`,\n })\n )\n }\n\n // Validate token value\n if (tokenValue.startsWith('\"')) {\n // Quoted value: must end with quote and have properly escaped internal quotes\n if (!tokenValue.endsWith('\"')) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: quoted value must end with a quote.`,\n })\n )\n }\n\n // Check for unescaped quotes inside\n const innerValue = tokenValue.slice(1, -1)\n for (let i = 0; i < innerValue.length; i++) {\n if (innerValue[i] === '\"' && (i === 0 || innerValue[i - 1] !== '\\\\')) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: unescaped quote found inside quoted value.`,\n })\n )\n }\n }\n\n tokenValue = Strings.removeStart(Strings.removeEnd(tokenValue, '\"'), '\"').replaceAll('\\\\\"', '\"')\n } else if (tokenValue.includes('\"')) {\n // Unquoted value: cannot contain quotes at all\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: unquoted value cannot contain quotes.`,\n })\n )\n }\n\n if (Objects.isPresent(parameters[tokenKey])) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: duplicate parameter key found.`,\n })\n )\n }\n\n parameters[tokenKey] = tokenValue\n }\n\n return Results.success({ mimeType, parameters })\n}\n"],"mappings":";AAAA,YAAY,aAAa;AAEzB,YAAY,iBAAiB;AAE7B,SAAS,uBAAuB;AAEhC,YAAY,eAAe;AAE3B,YAAY,aAAa;AACzB,YAAY,aAAa;AAElB,IAAM,YAAY,gBAAgB,cAAc;AAUhD,SAAS,KAAK,OAAoF;AACvG,MAAY,cAAM,KAAK,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,MAAY,iBAAS,KAAK,GAAG;AAC3B,WAAmB,yBAAaA,aAAY,KAAK,CAAC;AAAA,EACpD;AAEA,SAAO;AACT;AAMO,SAAS,UAAU,WAAsF;AAC9G,MAAY,cAAM,SAAS,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,KAAK,SAAS;AAE5B,MAAY,gBAAQ,MAAM,UAAU,GAAG;AACrC,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,SAAS,OAAO,QAAQ,MAAM,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM;AAElE,UAAM,eAAe,sBAAsB,KAAK,GAAG,KAAa,gBAAQ,GAAG;AAC3E,UAAM,cAAc,eAAe,IAAI,GAAG,MAAM;AAChD,WAAO,GAAG,GAAG,IAAI,WAAW;AAAA,EAC9B,CAAC;AAED,SAAO,GAAG,MAAM,QAAQ,IAAI,OAAO,KAAK,GAAG,CAAC;AA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AAA,QACH;AAAA,MACF;AAGA,YAAM,aAAa,WAAW,MAAM,GAAG,EAAE;AACzC,eAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,YAAI,WAAW,CAAC,MAAM,QAAQ,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,OAAO;AACpE,iBAAe;AAAA,YACD,yBAAa,OAAO;AAAA,cAC9B,WAAW;AAAA,cACX,SAAS,IAAI,SAAS,gDAAgD,QAAQ;AAAA,YAChF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAEA,mBAAqB,oBAAoB,kBAAU,YAAY,GAAG,GAAG,GAAG,EAAE,WAAW,OAAO,GAAG;AAAA,IACjG,WAAW,WAAW,SAAS,GAAG,GAAG;AAEnC,aAAe;AAAA,QACD,yBAAa,OAAO;AAAA,UAC9B,WAAW;AAAA,UACX,SAAS,IAAI,SAAS,gDAAgD,QAAQ;AAAA,QAChF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,QAAY,kBAAU,WAAW,QAAQ,CAAC,GAAG;AAC3C,aAAe;AAAA,QACD,yBAAa,OAAO;AAAA,UAC9B,WAAW;AAAA,UACX,SAAS,IAAI,SAAS,gDAAgD,QAAQ;AAAA,QAChF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,eAAW,QAAQ,IAAI;AAAA,EACzB;AAEA,SAAe,gBAAQ,EAAE,UAAU,WAAW,CAAC;AACjD;","names":["parseString"]}
1
+ {"version":3,"sources":["../../src/net/content-type.ts"],"sourcesContent":["import * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport { Dictionary, NominalType } from '@bessemer/cornerstone/types'\nimport * as MimeTypes from '@bessemer/cornerstone/mime-type'\nimport { MimeLiteral } from '@bessemer/cornerstone/mime-type'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport const Namespace = ResourceKeys.createNamespace('content-type')\nexport type ContentType = { mimeType: MimeLiteral; parameters: Dictionary<string> }\nexport type ContentTypeLiteral = NominalType<string, typeof Namespace>\n\nexport type ContentTypeLike = ContentType | ContentTypeLiteral | MimeLiteral\n\nexport function from(value: ContentTypeLike | string): ContentType\nexport function from(value: ContentTypeLike | string | null): ContentType | null\nexport function from(value: ContentTypeLike | string | undefined): ContentType | undefined\nexport function from(value: ContentTypeLike | string | null | undefined): ContentType | null | undefined\nexport function from(value: ContentTypeLike | string | null | undefined): ContentType | null | undefined {\n if (Objects.isNil(value)) {\n return value\n }\n\n if (Strings.isString(value)) {\n return ErrorEvents.unpackResult(parseString(value))\n }\n\n return value\n}\n\nexport function toLiteral(likeValue: ContentTypeLike): ContentTypeLiteral\nexport function toLiteral(likeValue: ContentTypeLike | null): ContentTypeLiteral | null\nexport function toLiteral(likeValue: ContentTypeLike | undefined): ContentTypeLiteral | undefined\nexport function toLiteral(likeValue: ContentTypeLike | null | undefined): ContentTypeLiteral | null | undefined\nexport function toLiteral(likeValue: ContentTypeLike | null | undefined): ContentTypeLiteral | null | undefined {\n if (Objects.isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n\n if (Objects.isEmpty(value.parameters)) {\n return value.mimeType as ContentTypeLiteral\n }\n\n const params = Object.entries(value.parameters).map(([key, val]) => {\n // Quote the value if it contains special characters or spaces\n const needsQuoting = /[ ()<>@,;:\\\\/[\\]?=]/.test(val) || Strings.isEmpty(val)\n const quotedValue = needsQuoting ? `\"${val}\"` : val\n return `${key}=${quotedValue}`\n })\n\n return `${value.mimeType};${params.join(';')}` as ContentTypeLiteral\n}\n\n// RFC 2045 token: 1*<any (US-ASCII) CHAR except SPACE, CTLs, or tspecials>\n// tspecials: ()<>@,;:\\\"/[]?=\nconst TokenKeyRegex = /^[!#$%&'*+\\-.0-9A-Z^_`a-z|~]+$/\n\n// JOHN some of the error messages here should be looked at\nexport const parseString = (value: string): Result<ContentType, ErrorEvent> => {\n const tokens = value.split(';')\n const mimeTypeString = tokens[0]!\n const mimeType = MimeTypes.parseString(mimeTypeString)\n\n if (Results.isFailure(mimeType)) {\n return mimeType\n }\n\n if (tokens.length === 1) {\n return Results.success({ mimeType, parameters: {} })\n }\n\n const parameters: Dictionary<string> = {}\n\n for (const token of tokens.slice(1)) {\n const keyPart = Strings.splitFirst(token, '=')\n\n if (Objects.isNil(keyPart.selection)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter format: [${token}]. Parameters must be in key=value format.`,\n })\n )\n }\n\n const tokenKey = keyPart.selection.trim()\n if (!TokenKeyRegex.test(tokenKey)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter format: [${token}]. Parameters must be in key=value format.`,\n })\n )\n }\n\n let tokenValue = keyPart.rest.trim()\n if (Strings.isEmpty(tokenValue)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: value cant be blank.`,\n })\n )\n }\n\n // Validate token value\n if (tokenValue.startsWith('\"')) {\n // Quoted value: must end with quote and have properly escaped internal quotes\n if (!tokenValue.endsWith('\"')) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: quoted value must end with a quote.`,\n })\n )\n }\n\n // Check for unescaped quotes inside\n const innerValue = tokenValue.slice(1, -1)\n for (let i = 0; i < innerValue.length; i++) {\n if (innerValue[i] === '\"' && (i === 0 || innerValue[i - 1] !== '\\\\')) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: unescaped quote found inside quoted value.`,\n })\n )\n }\n }\n\n tokenValue = Strings.removeStart(Strings.removeEnd(tokenValue, '\"'), '\"').replaceAll('\\\\\"', '\"')\n } else if (tokenValue.includes('\"')) {\n // Unquoted value: cannot contain quotes at all\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: unquoted value cannot contain quotes.`,\n })\n )\n }\n\n if (Objects.isPresent(parameters[tokenKey])) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid Content-Type parameter value for [${tokenKey}]: duplicate parameter key found.`,\n })\n )\n }\n\n parameters[tokenKey] = tokenValue\n }\n\n return Results.success({ mimeType, parameters })\n}\n"],"mappings":";AAAA,YAAY,aAAa;AAEzB,YAAY,iBAAiB;AAE7B,YAAY,kBAAkB;AAE9B,YAAY,eAAe;AAE3B,YAAY,aAAa;AACzB,YAAY,aAAa;AAElB,IAAM,YAAyB,6BAAgB,cAAc;AAU7D,SAAS,KAAK,OAAoF;AACvG,MAAY,cAAM,KAAK,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,MAAY,iBAAS,KAAK,GAAG;AAC3B,WAAmB,yBAAaA,aAAY,KAAK,CAAC;AAAA,EACpD;AAEA,SAAO;AACT;AAMO,SAAS,UAAU,WAAsF;AAC9G,MAAY,cAAM,SAAS,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,KAAK,SAAS;AAE5B,MAAY,gBAAQ,MAAM,UAAU,GAAG;AACrC,WAAO,MAAM;AAAA,EACf;AAEA,QAAM,SAAS,OAAO,QAAQ,MAAM,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM;AAElE,UAAM,eAAe,sBAAsB,KAAK,GAAG,KAAa,gBAAQ,GAAG;AAC3E,UAAM,cAAc,eAAe,IAAI,GAAG,MAAM;AAChD,WAAO,GAAG,GAAG,IAAI,WAAW;AAAA,EAC9B,CAAC;AAED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,YACX,SAAS,IAAI,SAAS,gDAAgD,QAAQ;AAAA,UAChF,CAAC;AAAA,QACH;AAAA,MACF;AAGA,YAAM,aAAa,WAAW,MAAM,GAAG,EAAE;AACzC,eAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;AAC1C,YAAI,WAAW,CAAC,MAAM,QAAQ,MAAM,KAAK,WAAW,IAAI,CAAC,MAAM,OAAO;AACpE,iBAAe;AAAA,YACD,yBAAa,OAAO;AAAA,cAC9B,WAAW;AAAA,cACX,SAAS,IAAI,SAAS,gDAAgD,QAAQ;AAAA,YAChF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAEA,mBAAqB,oBAAoB,kBAAU,YAAY,GAAG,GAAG,GAAG,EAAE,WAAW,OAAO,GAAG;AAAA,IACjG,WAAW,WAAW,SAAS,GAAG,GAAG;AAEnC,aAAe;AAAA,QACD,yBAAa,OAAO;AAAA,UAC9B,WAAW;AAAA,UACX,SAAS,IAAI,SAAS,gDAAgD,QAAQ;AAAA,QAChF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,QAAY,kBAAU,WAAW,QAAQ,CAAC,GAAG;AAC3C,aAAe;AAAA,QACD,yBAAa,OAAO;AAAA,UAC9B,WAAW;AAAA,UACX,SAAS,IAAI,SAAS,gDAAgD,QAAQ;AAAA,QAChF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,eAAW,QAAQ,IAAI;AAAA,EACzB;AAEA,SAAe,gBAAQ,EAAE,UAAU,WAAW,CAAC;AACjD;","names":["parseString"]}
@@ -1,10 +1,10 @@
1
- import Zod from 'zod';
2
1
  import { NominalType } from '@bessemer/cornerstone/types';
3
2
  import { Result } from '@bessemer/cornerstone/result';
3
+ import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
4
4
  import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
5
- export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"domain-name">;
5
+ export declare const Namespace: ResourceKeys.ResourceNamespace<"domain-name">;
6
6
  export type DomainName = NominalType<string, typeof Namespace>;
7
7
  export declare const parseString: (value: string) => Result<DomainName, ErrorEvent>;
8
8
  export declare const from: (value: string) => DomainName;
9
- export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<DomainName, string>>;
9
+ export declare const Schema: import("zod").ZodPipe<import("zod").ZodType<DomainName, DomainName, import("zod/v4/core").$ZodTypeInternals<DomainName, DomainName>>, import("zod").ZodTransform<DomainName, DomainName>>;
10
10
  //# sourceMappingURL=domain-name.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"domain-name.d.ts","sourceRoot":"","sources":["../../src/net/domain-name.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAEvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,eAAO,MAAM,SAAS,+EAAiC,CAAA;AACvD,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAK9D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,UAAU,EAAE,UAAU,CAWxE,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,UAEpC,CAAA;AAED,eAAO,MAAM,MAAM,kEAAiD,CAAA"}
1
+ {"version":3,"file":"domain-name.d.ts","sourceRoot":"","sources":["../../src/net/domain-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,KAAK,YAAY,MAAM,oCAAoC,CAAA;AAElE,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAA;AAGpE,eAAO,MAAM,SAAS,+CAA8C,CAAA;AACpE,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAK9D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,UAAU,EAAE,UAAU,CAWxE,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,UAEpC,CAAA;AAED,eAAO,MAAM,MAAM,2LAAyE,CAAA"}
@@ -1,26 +1,25 @@
1
1
  // src/net/domain-name.ts
2
- import Zod from "zod";
3
- import { failure, success } from "@bessemer/cornerstone/result";
4
- import { createNamespace } from "@bessemer/cornerstone/resource-key";
5
- import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
6
- import { structuredTransform } from "@bessemer/cornerstone/zod-util";
7
- var Namespace = createNamespace("domain-name");
2
+ import * as Results from "@bessemer/cornerstone/result";
3
+ import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
4
+ import * as ErrorEvents from "@bessemer/cornerstone/error/error-event";
5
+ import * as ZodUtil from "@bessemer/cornerstone/zod-util";
6
+ var Namespace = ResourceKeys.createNamespace("domain-name");
8
7
  var regex = /^[a-zA-Z0-9\u00a1-\uffff](?:[a-zA-Z0-9\u00a1-\uffff-]{0,61}[a-zA-Z0-9\u00a1-\uffff])?(?:\.[a-zA-Z0-9\u00a1-\uffff](?:[a-zA-Z0-9\u00a1-\uffff-]{0,61}[a-zA-Z0-9\u00a1-\uffff])?)*$/;
9
8
  var parseString = (value) => {
10
9
  if (!regex.test(value)) {
11
- return failure(
12
- invalidValue(value, {
10
+ return Results.failure(
11
+ ErrorEvents.invalidValue(value, {
13
12
  namespace: Namespace,
14
13
  message: `[${Namespace}]: Invalid characters for DomainName in string: [${value}]`
15
14
  })
16
15
  );
17
16
  }
18
- return success(value);
17
+ return Results.success(value);
19
18
  };
20
19
  var from = (value) => {
21
- return unpackResult(parseString(value));
20
+ return ErrorEvents.unpackResult(parseString(value));
22
21
  };
23
- var Schema = structuredTransform(Zod.string(), parseString);
22
+ var Schema = ZodUtil.structuredTransform(ZodUtil.string(), parseString);
24
23
  export {
25
24
  Namespace,
26
25
  Schema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/net/domain-name.ts"],"sourcesContent":["import Zod from 'zod'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = createNamespace('domain-name')\nexport type DomainName = NominalType<string, typeof Namespace>\n\nconst regex =\n /^[a-zA-Z0-9\\u00a1-\\uffff](?:[a-zA-Z0-9\\u00a1-\\uffff-]{0,61}[a-zA-Z0-9\\u00a1-\\uffff])?(?:\\.[a-zA-Z0-9\\u00a1-\\uffff](?:[a-zA-Z0-9\\u00a1-\\uffff-]{0,61}[a-zA-Z0-9\\u00a1-\\uffff])?)*$/\n\nexport const parseString = (value: string): Result<DomainName, ErrorEvent> => {\n if (!regex.test(value)) {\n return failure(\n invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for DomainName in string: [${value}]`,\n })\n )\n }\n\n return success(value as DomainName)\n}\n\nexport const from = (value: string): DomainName => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n"],"mappings":";AAAA,OAAO,SAAS;AAEhB,SAAS,SAAiB,eAAe;AACzC,SAAS,uBAAuB;AAChC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,2BAA2B;AAE7B,IAAM,YAAY,gBAAgB,aAAa;AAGtD,IAAM,QACJ;AAEK,IAAM,cAAc,CAAC,UAAkD;AAC5E,MAAI,CAAC,MAAM,KAAK,KAAK,GAAG;AACtB,WAAO;AAAA,MACL,aAAa,OAAO;AAAA,QAClB,WAAW;AAAA,QACX,SAAS,IAAI,SAAS,oDAAoD,KAAK;AAAA,MACjF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,QAAQ,KAAmB;AACpC;AAEO,IAAM,OAAO,CAAC,UAA8B;AACjD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;","names":[]}
1
+ {"version":3,"sources":["../../src/net/domain-name.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\nimport * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport * as ZodUtil from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = ResourceKeys.createNamespace('domain-name')\nexport type DomainName = NominalType<string, typeof Namespace>\n\nconst regex =\n /^[a-zA-Z0-9\\u00a1-\\uffff](?:[a-zA-Z0-9\\u00a1-\\uffff-]{0,61}[a-zA-Z0-9\\u00a1-\\uffff])?(?:\\.[a-zA-Z0-9\\u00a1-\\uffff](?:[a-zA-Z0-9\\u00a1-\\uffff-]{0,61}[a-zA-Z0-9\\u00a1-\\uffff])?)*$/\n\nexport const parseString = (value: string): Result<DomainName, ErrorEvent> => {\n if (!regex.test(value)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for DomainName in string: [${value}]`,\n })\n )\n }\n\n return Results.success(value as DomainName)\n}\n\nexport const from = (value: string): DomainName => {\n return ErrorEvents.unpackResult(parseString(value))\n}\n\nexport const Schema = ZodUtil.structuredTransform<DomainName>(ZodUtil.string(), parseString)\n"],"mappings":";AACA,YAAY,aAAa;AAEzB,YAAY,kBAAkB;AAC9B,YAAY,iBAAiB;AAE7B,YAAY,aAAa;AAElB,IAAM,YAAyB,6BAAgB,aAAa;AAGnE,IAAM,QACJ;AAEK,IAAM,cAAc,CAAC,UAAkD;AAC5E,MAAI,CAAC,MAAM,KAAK,KAAK,GAAG;AACtB,WAAe;AAAA,MACD,yBAAa,OAAO;AAAA,QAC9B,WAAW;AAAA,QACX,SAAS,IAAI,SAAS,oDAAoD,KAAK;AAAA,MACjF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAe,gBAAQ,KAAmB;AAC5C;AAEO,IAAM,OAAO,CAAC,UAA8B;AACjD,SAAmB,yBAAa,YAAY,KAAK,CAAC;AACpD;AAEO,IAAM,SAAiB,4BAAwC,eAAO,GAAG,WAAW;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"http-method.d.ts","sourceRoot":"","sources":["../../src/net/http-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,eAAO,MAAM,UAAU;;;;;;;;;;CAUb,CAAA;AACV,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,UAAU,CAAC,CAAA;AAEnD,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,UAAU,EAAE,UAAU,CAcxE,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,UAEpC,CAAA"}
1
+ {"version":3,"file":"http-method.d.ts","sourceRoot":"","sources":["../../src/net/http-method.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAA;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,eAAO,MAAM,UAAU;;;;;;;;;;CAUb,CAAA;AACV,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,UAAU,CAAC,CAAA;AAEnD,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,UAAU,EAAE,UAAU,CAcxE,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,UAEpC,CAAA"}
@@ -1,7 +1,7 @@
1
1
  // src/net/http-method.ts
2
- import { failure, success } from "@bessemer/cornerstone/result";
3
- import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
4
- import { Namespace } from "@bessemer/cornerstone/net/domain-name";
2
+ import * as Results from "@bessemer/cornerstone/result";
3
+ import * as ErrorEvents from "@bessemer/cornerstone/error/error-event";
4
+ import * as DomainNames from "@bessemer/cornerstone/net/domain-name";
5
5
  var HttpMethod = {
6
6
  Get: "get",
7
7
  Post: "post",
@@ -17,17 +17,17 @@ var parseString = (value) => {
17
17
  const normalizedValue = value.toLowerCase();
18
18
  const validMethods = Object.values(HttpMethod);
19
19
  if (!validMethods.includes(normalizedValue)) {
20
- return failure(
21
- invalidValue(value, {
22
- namespace: Namespace,
23
- message: `[${Namespace}]: Invalid HttpMethod in string: [${value}]. Valid methods are: ${validMethods.join(", ")}`
20
+ return Results.failure(
21
+ ErrorEvents.invalidValue(value, {
22
+ namespace: DomainNames.Namespace,
23
+ message: `[${DomainNames.Namespace}]: Invalid HttpMethod in string: [${value}]. Valid methods are: ${validMethods.join(", ")}`
24
24
  })
25
25
  );
26
26
  }
27
- return success(normalizedValue);
27
+ return Results.success(normalizedValue);
28
28
  };
29
29
  var from = (value) => {
30
- return unpackResult(parseString(value));
30
+ return ErrorEvents.unpackResult(parseString(value));
31
31
  };
32
32
  export {
33
33
  HttpMethod,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/net/http-method.ts"],"sourcesContent":["import { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { Namespace } from '@bessemer/cornerstone/net/domain-name'\nimport { ValueOf } from 'type-fest'\n\nexport const HttpMethod = {\n Get: 'get',\n Post: 'post',\n Put: 'put',\n Patch: 'patch',\n Delete: 'delete',\n Head: 'head',\n Options: 'options',\n Trace: 'trace',\n Connect: 'connect',\n} as const\nexport type HttpMethod = ValueOf<typeof HttpMethod>\n\nexport const parseString = (value: string): Result<HttpMethod, ErrorEvent> => {\n const normalizedValue = value.toLowerCase()\n const validMethods = Object.values(HttpMethod)\n\n if (!validMethods.includes(normalizedValue as HttpMethod)) {\n return failure(\n invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid HttpMethod in string: [${value}]. Valid methods are: ${validMethods.join(', ')}`,\n })\n )\n }\n\n return success(normalizedValue as HttpMethod)\n}\n\nexport const from = (value: string): HttpMethod => {\n return unpackResult(parseString(value))\n}\n"],"mappings":";AAAA,SAAS,SAAiB,eAAe;AACzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,iBAAiB;AAGnB,IAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACX;AAGO,IAAM,cAAc,CAAC,UAAkD;AAC5E,QAAM,kBAAkB,MAAM,YAAY;AAC1C,QAAM,eAAe,OAAO,OAAO,UAAU;AAE7C,MAAI,CAAC,aAAa,SAAS,eAA6B,GAAG;AACzD,WAAO;AAAA,MACL,aAAa,OAAO;AAAA,QAClB,WAAW;AAAA,QACX,SAAS,IAAI,SAAS,qCAAqC,KAAK,yBAAyB,aAAa,KAAK,IAAI,CAAC;AAAA,MAClH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,QAAQ,eAA6B;AAC9C;AAEO,IAAM,OAAO,CAAC,UAA8B;AACjD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;","names":[]}
1
+ {"version":3,"sources":["../../src/net/http-method.ts"],"sourcesContent":["import * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport * as DomainNames from '@bessemer/cornerstone/net/domain-name'\nimport { ValueOf } from 'type-fest'\n\nexport const HttpMethod = {\n Get: 'get',\n Post: 'post',\n Put: 'put',\n Patch: 'patch',\n Delete: 'delete',\n Head: 'head',\n Options: 'options',\n Trace: 'trace',\n Connect: 'connect',\n} as const\nexport type HttpMethod = ValueOf<typeof HttpMethod>\n\nexport const parseString = (value: string): Result<HttpMethod, ErrorEvent> => {\n const normalizedValue = value.toLowerCase()\n const validMethods = Object.values(HttpMethod)\n\n if (!validMethods.includes(normalizedValue as HttpMethod)) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: DomainNames.Namespace,\n message: `[${DomainNames.Namespace}]: Invalid HttpMethod in string: [${value}]. Valid methods are: ${validMethods.join(', ')}`,\n })\n )\n }\n\n return Results.success(normalizedValue as HttpMethod)\n}\n\nexport const from = (value: string): HttpMethod => {\n return ErrorEvents.unpackResult(parseString(value))\n}\n"],"mappings":";AAAA,YAAY,aAAa;AAEzB,YAAY,iBAAiB;AAE7B,YAAY,iBAAiB;AAGtB,IAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AACX;AAGO,IAAM,cAAc,CAAC,UAAkD;AAC5E,QAAM,kBAAkB,MAAM,YAAY;AAC1C,QAAM,eAAe,OAAO,OAAO,UAAU;AAE7C,MAAI,CAAC,aAAa,SAAS,eAA6B,GAAG;AACzD,WAAe;AAAA,MACD,yBAAa,OAAO;AAAA,QAC9B,WAAuB;AAAA,QACvB,SAAS,IAAgB,qBAAS,qCAAqC,KAAK,yBAAyB,aAAa,KAAK,IAAI,CAAC;AAAA,MAC9H,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAe,gBAAQ,eAA6B;AACtD;AAEO,IAAM,OAAO,CAAC,UAA8B;AACjD,SAAmB,yBAAa,YAAY,KAAK,CAAC;AACpD;","names":[]}
@@ -1,10 +1,10 @@
1
- import Zod from 'zod';
2
1
  import { NominalType } from '@bessemer/cornerstone/types';
3
2
  import { Result } from '@bessemer/cornerstone/result';
3
+ import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
4
4
  import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
5
- export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"ipv4-address">;
5
+ export declare const Namespace: ResourceKeys.ResourceNamespace<"ipv4-address">;
6
6
  export type IpV4Address = NominalType<string, typeof Namespace>;
7
7
  export declare const parseString: (value: string) => Result<IpV4Address, ErrorEvent>;
8
8
  export declare const from: (value: string) => IpV4Address;
9
- export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<IpV4Address, string>>;
9
+ export declare const Schema: import("zod").ZodPipe<import("zod").ZodType<IpV4Address, IpV4Address, import("zod/v4/core").$ZodTypeInternals<IpV4Address, IpV4Address>>, import("zod").ZodTransform<IpV4Address, IpV4Address>>;
10
10
  //# sourceMappingURL=ipv4-address.d.ts.map