@bessemer/cornerstone 0.5.85 → 0.5.88

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 (187) hide show
  1. package/dist/aspect-ratio.d.ts +7 -4
  2. package/dist/aspect-ratio.d.ts.map +1 -1
  3. package/dist/aspect-ratio.js +16 -7
  4. package/dist/aspect-ratio.js.map +1 -1
  5. package/dist/async.d.ts +1 -1
  6. package/dist/async.d.ts.map +1 -1
  7. package/dist/async.js +1 -1
  8. package/dist/async.js.map +1 -1
  9. package/dist/cache.d.ts +9 -8
  10. package/dist/cache.d.ts.map +1 -1
  11. package/dist/cache.js +14 -14
  12. package/dist/cache.js.map +1 -1
  13. package/dist/comparator.js +1 -1
  14. package/dist/comparator.js.map +1 -1
  15. package/dist/content.d.ts +5 -5
  16. package/dist/content.d.ts.map +1 -1
  17. package/dist/content.js.map +1 -1
  18. package/dist/data-size.d.ts +2 -2
  19. package/dist/data-size.d.ts.map +1 -1
  20. package/dist/data-size.js.map +1 -1
  21. package/dist/{error-event.d.ts → error/error-event.d.ts} +42 -23
  22. package/dist/error/error-event.d.ts.map +1 -0
  23. package/dist/{error-event.js → error/error-event.js} +82 -60
  24. package/dist/error/error-event.js.map +1 -0
  25. package/dist/error/error-type.d.ts +11 -0
  26. package/dist/error/error-type.d.ts.map +1 -0
  27. package/dist/error/error-type.js +20 -0
  28. package/dist/error/error-type.js.map +1 -0
  29. package/dist/error/error.d.ts.map +1 -0
  30. package/dist/{error.js → error/error.js} +1 -1
  31. package/dist/error/error.js.map +1 -0
  32. package/dist/expression.d.ts +2 -2
  33. package/dist/expression.d.ts.map +1 -1
  34. package/dist/expression.js.map +1 -1
  35. package/dist/glob.d.ts +7 -3
  36. package/dist/glob.d.ts.map +1 -1
  37. package/dist/glob.js +23 -15
  38. package/dist/glob.js.map +1 -1
  39. package/dist/hash.d.ts +2 -2
  40. package/dist/hash.d.ts.map +1 -1
  41. package/dist/hash.js.map +1 -1
  42. package/dist/hex-code.d.ts +7 -4
  43. package/dist/hex-code.d.ts.map +1 -1
  44. package/dist/hex-code.js +19 -5
  45. package/dist/hex-code.js.map +1 -1
  46. package/dist/index.d.ts +12 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +18 -4
  49. package/dist/index.js.map +1 -1
  50. package/dist/intl/country-code.d.ts +7 -4
  51. package/dist/intl/country-code.d.ts.map +1 -1
  52. package/dist/intl/country-code.js +52 -43
  53. package/dist/intl/country-code.js.map +1 -1
  54. package/dist/intl/country-subdivision-code.d.ts +7 -4
  55. package/dist/intl/country-subdivision-code.d.ts.map +1 -1
  56. package/dist/intl/country-subdivision-code.js +16 -5
  57. package/dist/intl/country-subdivision-code.js.map +1 -1
  58. package/dist/intl/currency-code.d.ts +7 -4
  59. package/dist/intl/currency-code.d.ts.map +1 -1
  60. package/dist/intl/currency-code.js +20 -11
  61. package/dist/intl/currency-code.js.map +1 -1
  62. package/dist/intl/language-code.d.ts +7 -4
  63. package/dist/intl/language-code.d.ts.map +1 -1
  64. package/dist/intl/language-code.js +39 -30
  65. package/dist/intl/language-code.js.map +1 -1
  66. package/dist/intl/locale.d.ts +8 -5
  67. package/dist/intl/locale.d.ts.map +1 -1
  68. package/dist/intl/locale.js +37 -30
  69. package/dist/intl/locale.js.map +1 -1
  70. package/dist/math.d.ts +2 -0
  71. package/dist/math.d.ts.map +1 -1
  72. package/dist/math.js +12 -1
  73. package/dist/math.js.map +1 -1
  74. package/dist/mime-type.d.ts +7 -4
  75. package/dist/mime-type.d.ts.map +1 -1
  76. package/dist/mime-type.js +44 -35
  77. package/dist/mime-type.js.map +1 -1
  78. package/dist/monetary-amount.d.ts +3 -3
  79. package/dist/monetary-amount.d.ts.map +1 -1
  80. package/dist/monetary-amount.js +4 -4
  81. package/dist/monetary-amount.js.map +1 -1
  82. package/dist/object/object-path.d.ts +2 -2
  83. package/dist/object/object-path.d.ts.map +1 -1
  84. package/dist/object/object-path.js.map +1 -1
  85. package/dist/object/type-path.d.ts +2 -2
  86. package/dist/object/type-path.d.ts.map +1 -1
  87. package/dist/object/type-path.js.map +1 -1
  88. package/dist/object.d.ts +2 -2
  89. package/dist/object.d.ts.map +1 -1
  90. package/dist/object.js +3 -2
  91. package/dist/object.js.map +1 -1
  92. package/dist/range.d.ts +2 -2
  93. package/dist/range.d.ts.map +1 -1
  94. package/dist/range.js.map +1 -1
  95. package/dist/reference.d.ts +2 -2
  96. package/dist/reference.d.ts.map +1 -1
  97. package/dist/reference.js.map +1 -1
  98. package/dist/resource-key.d.ts +17 -8
  99. package/dist/resource-key.d.ts.map +1 -1
  100. package/dist/resource-key.js +42 -13
  101. package/dist/resource-key.js.map +1 -1
  102. package/dist/result.d.ts +6 -5
  103. package/dist/result.d.ts.map +1 -1
  104. package/dist/result.js +4 -4
  105. package/dist/result.js.map +1 -1
  106. package/dist/retry.d.ts +1 -1
  107. package/dist/retry.d.ts.map +1 -1
  108. package/dist/retry.js +1 -1
  109. package/dist/retry.js.map +1 -1
  110. package/dist/rich-text.d.ts +2 -2
  111. package/dist/rich-text.d.ts.map +1 -1
  112. package/dist/rich-text.js.map +1 -1
  113. package/dist/signature.d.ts.map +1 -1
  114. package/dist/signature.js +5 -1
  115. package/dist/signature.js.map +1 -1
  116. package/dist/sql.d.ts +2 -2
  117. package/dist/sql.d.ts.map +1 -1
  118. package/dist/sql.js.map +1 -1
  119. package/dist/tag.d.ts +3 -3
  120. package/dist/tag.d.ts.map +1 -1
  121. package/dist/tag.js.map +1 -1
  122. package/dist/temporal/chrono.d.ts +34 -0
  123. package/dist/temporal/chrono.d.ts.map +1 -0
  124. package/dist/temporal/chrono.js +34 -0
  125. package/dist/temporal/chrono.js.map +1 -0
  126. package/dist/temporal/clock.d.ts +21 -0
  127. package/dist/temporal/clock.d.ts.map +1 -0
  128. package/dist/temporal/clock.js +76 -0
  129. package/dist/temporal/clock.js.map +1 -0
  130. package/dist/temporal/date.d.ts +2 -0
  131. package/dist/temporal/date.d.ts.map +1 -0
  132. package/dist/temporal/date.js +8 -0
  133. package/dist/temporal/date.js.map +1 -0
  134. package/dist/temporal/duration.d.ts +54 -0
  135. package/dist/temporal/duration.d.ts.map +1 -0
  136. package/dist/temporal/duration.js +162 -0
  137. package/dist/temporal/duration.js.map +1 -0
  138. package/dist/temporal/instant.d.ts +35 -0
  139. package/dist/temporal/instant.d.ts.map +1 -0
  140. package/dist/temporal/instant.js +91 -0
  141. package/dist/temporal/instant.js.map +1 -0
  142. package/dist/temporal/plain-time.d.ts +49 -0
  143. package/dist/temporal/plain-time.d.ts.map +1 -0
  144. package/dist/temporal/plain-time.js +110 -0
  145. package/dist/temporal/plain-time.js.map +1 -0
  146. package/dist/temporal/time-zone-id.d.ts +12 -0
  147. package/dist/temporal/time-zone-id.d.ts.map +1 -0
  148. package/dist/temporal/time-zone-id.js +35 -0
  149. package/dist/temporal/time-zone-id.js.map +1 -0
  150. package/dist/temporal/time-zone-offset.d.ts +22 -0
  151. package/dist/temporal/time-zone-offset.d.ts.map +1 -0
  152. package/dist/temporal/time-zone-offset.js +145 -0
  153. package/dist/temporal/time-zone-offset.js.map +1 -0
  154. package/dist/types.d.ts +12 -12
  155. package/dist/types.d.ts.map +1 -1
  156. package/dist/ulid.d.ts +7 -4
  157. package/dist/ulid.d.ts.map +1 -1
  158. package/dist/ulid.js +14 -5
  159. package/dist/ulid.js.map +1 -1
  160. package/dist/unit.d.ts +2 -2
  161. package/dist/unit.d.ts.map +1 -1
  162. package/dist/unit.js.map +1 -1
  163. package/dist/uri.d.ts +2 -2
  164. package/dist/uri.d.ts.map +1 -1
  165. package/dist/uri.js.map +1 -1
  166. package/dist/uuid.d.ts +7 -4
  167. package/dist/uuid.d.ts.map +1 -1
  168. package/dist/uuid.js +14 -5
  169. package/dist/uuid.js.map +1 -1
  170. package/dist/zod-util.d.ts +5 -0
  171. package/dist/zod-util.d.ts.map +1 -1
  172. package/dist/zod-util.js +28 -2
  173. package/dist/zod-util.js.map +1 -1
  174. package/package.json +2 -2
  175. package/dist/date.d.ts +0 -13
  176. package/dist/date.d.ts.map +0 -1
  177. package/dist/date.js +0 -40
  178. package/dist/date.js.map +0 -1
  179. package/dist/duration.d.ts +0 -18
  180. package/dist/duration.d.ts.map +0 -1
  181. package/dist/duration.js +0 -53
  182. package/dist/duration.js.map +0 -1
  183. package/dist/error-event.d.ts.map +0 -1
  184. package/dist/error-event.js.map +0 -1
  185. package/dist/error.d.ts.map +0 -1
  186. package/dist/error.js.map +0 -1
  187. /package/dist/{error.d.ts → error/error.d.ts} +0 -0
@@ -0,0 +1,145 @@
1
+ // src/temporal/time-zone-offset.ts
2
+ import {
3
+ from as _fromDuration,
4
+ fromHours,
5
+ fromMilliseconds,
6
+ fromMinutes as durationFromMinutes,
7
+ isGreater,
8
+ isLess,
9
+ toMinutes
10
+ } from "@bessemer/cornerstone/temporal/duration";
11
+ import { fromDuration as plainTimeFromDuration, toLiteral as plainTimeToLiteral } from "@bessemer/cornerstone/temporal/plain-time";
12
+ import { failure, success } from "@bessemer/cornerstone/result";
13
+ import Zod from "zod";
14
+ import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
15
+ import { namespace } from "@bessemer/cornerstone/resource-key";
16
+ import { structuredTransform } from "@bessemer/cornerstone/zod-util";
17
+ var Namespace = namespace("time-zone-offset");
18
+ var EighteenHours = fromHours(18);
19
+ var parseMinutes = (value) => {
20
+ if (!Number.isInteger(value)) {
21
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must be a round number of minutes.` }));
22
+ }
23
+ if (value < toMinutes(EighteenHours.negated()) || value > toMinutes(EighteenHours)) {
24
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must be between -18:00 and +18:00 inclusive.` }));
25
+ }
26
+ return success(value);
27
+ };
28
+ var parseDuration = (value) => {
29
+ return parseMinutes(toMinutes(value));
30
+ };
31
+ var fromMinutes = (value) => {
32
+ return unpackResult(parseMinutes(value));
33
+ };
34
+ var fromDuration = (value) => {
35
+ return unpackResult(parseDuration(_fromDuration(value)));
36
+ };
37
+ var fromTimeZone = (timeZone, instant) => {
38
+ const instantWithoutMs = new Date(Math.floor(instant.epochMilliseconds / 1e3) * 1e3);
39
+ const formatter = new Intl.DateTimeFormat("en-CA", {
40
+ timeZone,
41
+ year: "numeric",
42
+ month: "2-digit",
43
+ day: "2-digit",
44
+ hour: "2-digit",
45
+ minute: "2-digit",
46
+ second: "2-digit",
47
+ hour12: false
48
+ });
49
+ const formatted = formatter.format(instantWithoutMs);
50
+ const localTime = (/* @__PURE__ */ new Date(formatted + "Z")).getTime();
51
+ const offsetMs = localTime - instantWithoutMs.getTime();
52
+ return fromDuration({ milliseconds: offsetMs });
53
+ };
54
+ var parseString = (value) => {
55
+ if (value === "Z") {
56
+ return success(0);
57
+ }
58
+ if (!value.startsWith("+") && !value.startsWith("-")) {
59
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must start with +, -, or be Z.` }));
60
+ }
61
+ const sign = value[0] === "+" ? 1 : -1;
62
+ const offsetStr = value.slice(1);
63
+ let hours = 0;
64
+ let minutes = 0;
65
+ if (offsetStr.length === 1) {
66
+ hours = parseInt(offsetStr, 10);
67
+ if (isNaN(hours)) {
68
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid hour value in time zone offset.` }));
69
+ }
70
+ } else if (offsetStr.length === 2) {
71
+ hours = parseInt(offsetStr, 10);
72
+ if (isNaN(hours)) {
73
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid hour value in time zone offset.` }));
74
+ }
75
+ } else if (offsetStr.includes(":")) {
76
+ const parts = offsetStr.split(":");
77
+ if (parts.length < 2 || parts.length > 3) {
78
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time zone offset format.` }));
79
+ }
80
+ hours = parseInt(parts[0], 10);
81
+ minutes = parseInt(parts[1], 10);
82
+ if (parts.length === 3) {
83
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time values in time zone offset.` }));
84
+ }
85
+ if (isNaN(hours) || isNaN(minutes)) {
86
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time values in time zone offset.` }));
87
+ }
88
+ } else if (offsetStr.length === 4) {
89
+ hours = parseInt(offsetStr.slice(0, 2), 10);
90
+ minutes = parseInt(offsetStr.slice(2, 4), 10);
91
+ if (isNaN(hours) || isNaN(minutes)) {
92
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time values in time zone offset.` }));
93
+ }
94
+ } else {
95
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time zone offset format.` }));
96
+ }
97
+ if (minutes >= 60) {
98
+ return failure(
99
+ invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid minutes in time zone offset: must be less than 60.` })
100
+ );
101
+ }
102
+ let duration = _fromDuration({ hours, minutes });
103
+ if (sign === -1) {
104
+ duration = duration.negated();
105
+ }
106
+ if (isLess(duration, EighteenHours.negated()) || isGreater(duration, EighteenHours)) {
107
+ return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must be between -18:00 and +18:00 inclusive.` }));
108
+ }
109
+ return success(toMinutes(duration));
110
+ };
111
+ var fromString = (value) => {
112
+ return unpackResult(parseString(value));
113
+ };
114
+ var Schema = Zod.union([structuredTransform(Zod.number(), parseMinutes), structuredTransform(Zod.string(), parseString)]);
115
+ var toDuration = (offset) => {
116
+ return fromMilliseconds(offset);
117
+ };
118
+ var toMilliseconds = (offset) => {
119
+ return offset;
120
+ };
121
+ var toString = (offset) => {
122
+ if (offset === 0) {
123
+ return "Z";
124
+ }
125
+ const sign = offset > 0 ? "+" : "-";
126
+ const time = plainTimeFromDuration(durationFromMinutes(Math.abs(offset)));
127
+ return `${sign}${plainTimeToLiteral(time)}`;
128
+ };
129
+ var Utc = 0;
130
+ export {
131
+ Namespace,
132
+ Schema,
133
+ Utc,
134
+ fromDuration,
135
+ fromMinutes,
136
+ fromString,
137
+ fromTimeZone,
138
+ parseDuration,
139
+ parseMinutes,
140
+ parseString,
141
+ toDuration,
142
+ toMilliseconds,
143
+ toString
144
+ };
145
+ //# sourceMappingURL=time-zone-offset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/temporal/time-zone-offset.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport {\n Duration,\n DurationInput,\n from as _fromDuration,\n fromHours,\n fromMilliseconds,\n fromMinutes as durationFromMinutes,\n isGreater,\n isLess,\n toMinutes,\n} from '@bessemer/cornerstone/temporal/duration'\nimport { fromDuration as plainTimeFromDuration, toLiteral as plainTimeToLiteral } from '@bessemer/cornerstone/temporal/plain-time'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport Zod from 'zod'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport { Instant } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\n\nexport const Namespace = namespace('time-zone-offset')\nexport type TimeZoneOffset = NominalType<number, typeof Namespace>\n\nconst EighteenHours = fromHours(18)\n\nexport const parseMinutes = (value: number): Result<TimeZoneOffset, ErrorEvent> => {\n if (!Number.isInteger(value)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must be a round number of minutes.` }))\n }\n\n if (value < toMinutes(EighteenHours.negated()) || value > toMinutes(EighteenHours)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must be between -18:00 and +18:00 inclusive.` }))\n }\n\n return success(value as TimeZoneOffset)\n}\n\nexport const parseDuration = (value: Duration): Result<TimeZoneOffset, ErrorEvent> => {\n return parseMinutes(toMinutes(value))\n}\n\nexport const fromMinutes = (value: number): TimeZoneOffset => {\n return unpackResult(parseMinutes(value))\n}\n\nexport const fromDuration = (value: DurationInput): TimeZoneOffset => {\n return unpackResult(parseDuration(_fromDuration(value)))\n}\n\nexport const fromTimeZone = (timeZone: TimeZoneId, instant: Instant): TimeZoneOffset => {\n const instantWithoutMs = new Date(Math.floor(instant.epochMilliseconds / 1000) * 1000)\n\n // Note: We use 'en-CA' locale because it produces ISO 8601 format (YYYY-MM-DD, HH:MM:SS)\n // which is predictable and easily parseable. The locale only affects the output format,\n // not the timezone conversion - that's handled by the timeZone parameter.\n const formatter = new Intl.DateTimeFormat('en-CA', {\n timeZone: timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: false,\n })\n\n const formatted = formatter.format(instantWithoutMs)\n const localTime = new Date(formatted + 'Z').getTime()\n\n const offsetMs = localTime - instantWithoutMs.getTime()\n return fromDuration({ milliseconds: offsetMs })\n}\n\n// JOHN maybe this parsing could be consolidated with LocalTime?\nexport const parseString = (value: string): Result<TimeZoneOffset, ErrorEvent> => {\n if (value === 'Z') {\n return success(0 as TimeZoneOffset)\n }\n\n if (!value.startsWith('+') && !value.startsWith('-')) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must start with +, -, or be Z.` }))\n }\n\n const sign = value[0] === '+' ? 1 : -1\n const offsetStr = value.slice(1)\n\n let hours = 0\n let minutes = 0\n\n // Parse different formats\n if (offsetStr.length === 1) {\n // +h format\n hours = parseInt(offsetStr, 10)\n if (isNaN(hours)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid hour value in time zone offset.` }))\n }\n } else if (offsetStr.length === 2) {\n // +hh format\n hours = parseInt(offsetStr, 10)\n if (isNaN(hours)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid hour value in time zone offset.` }))\n }\n } else if (offsetStr.includes(':')) {\n // Formats with colons: +hh:mm or +hh:mm:ss\n const parts = offsetStr.split(':')\n if (parts.length < 2 || parts.length > 3) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time zone offset format.` }))\n }\n\n hours = parseInt(parts[0]!, 10)\n minutes = parseInt(parts[1]!, 10)\n\n if (parts.length === 3) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time values in time zone offset.` }))\n }\n\n if (isNaN(hours) || isNaN(minutes)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time values in time zone offset.` }))\n }\n } else if (offsetStr.length === 4) {\n // +hhmm format\n hours = parseInt(offsetStr.slice(0, 2), 10)\n minutes = parseInt(offsetStr.slice(2, 4), 10)\n\n if (isNaN(hours) || isNaN(minutes)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time values in time zone offset.` }))\n }\n } else {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid time zone offset format.` }))\n }\n\n if (minutes >= 60) {\n return failure(\n invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset - Invalid minutes in time zone offset: must be less than 60.` })\n )\n }\n\n let duration = _fromDuration({ hours, minutes })\n if (sign === -1) {\n duration = duration.negated()\n }\n\n if (isLess(duration, EighteenHours.negated()) || isGreater(duration, EighteenHours)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `TimeZoneOffset must be between -18:00 and +18:00 inclusive.` }))\n }\n\n return success(toMinutes(duration) as TimeZoneOffset)\n}\n\nexport const fromString = (value: string): TimeZoneOffset => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = Zod.union([structuredTransform(Zod.number(), parseMinutes), structuredTransform(Zod.string(), parseString)])\n\nexport const toDuration = (offset: TimeZoneOffset): Duration => {\n return fromMilliseconds(offset)\n}\n\nexport const toMilliseconds = (offset: TimeZoneOffset): number => {\n return offset\n}\n\nexport const toString = (offset: TimeZoneOffset): string => {\n if (offset === 0) {\n return 'Z'\n }\n\n const sign = offset > 0 ? '+' : '-'\n\n const time = plainTimeFromDuration(durationFrom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KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,IAAI,MAAM,CAAC,oBAAoB,IAAI,OAAO,GAAG,YAAY,GAAG,oBAAoB,IAAI,OAAO,GAAG,WAAW,CAAC,CAAC;AAE1H,IAAM,aAAa,CAAC,WAAqC;AAC9D,SAAO,iBAAiB,MAAM;AAChC;AAEO,IAAM,iBAAiB,CAAC,WAAmC;AAChE,SAAO;AACT;AAEO,IAAM,WAAW,CAAC,WAAmC;AAC1D,MAAI,WAAW,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,SAAS,IAAI,MAAM;AAEhC,QAAM,OAAO,sBAAsB,oBAAoB,KAAK,IAAI,MAAM,CAAC,CAAC;AACxE,SAAO,GAAG,IAAI,GAAG,mBAAmB,IAAI,CAAC;AAC3C;AAEO,IAAM,MAAM;","names":[]}
package/dist/types.d.ts CHANGED
@@ -1,25 +1,25 @@
1
- import { $brand } from 'zod';
2
- export interface NominalTyping<NominalTypingT> {
3
- _type?: NominalTypingT;
4
- }
5
- export type NominalType<T, NominalTypingT> = T & NominalTyping<NominalTypingT>;
6
- export type Alias<T> = NominalType<T, any>;
7
- export type TaggedTyping<TaggedTypingT extends string | number | symbol> = {
8
- [$brand]: {
9
- [k in TaggedTypingT]: true;
10
- };
1
+ import { Instant } from '@bessemer/cornerstone/temporal/instant';
2
+ declare const __type: unique symbol;
3
+ export type NominalTyping<NominalType> = {
4
+ [__type]: NominalType;
11
5
  };
12
- export type TaggedType<T, TaggedTypingT extends string | number | symbol> = T & TaggedTyping<TaggedTypingT>;
6
+ export type NominalType<ConcreteType, NominalType> = ConcreteType & NominalTyping<NominalType>;
7
+ export type TaggedTyping<NominalType> = {
8
+ [__type]?: NominalType;
9
+ };
10
+ export type TaggedType<ConcreteType, NominalType> = ConcreteType & TaggedTyping<NominalType>;
11
+ export type Alias<T> = TaggedType<T, any>;
13
12
  export type Throwable = unknown;
14
13
  export type Dictionary<T> = Record<string, T>;
15
14
  export type Nil = null | undefined;
16
15
  export type DeepPartial<T> = {
17
16
  [P in keyof T]?: T[P] extends Array<infer U> ? DeepPartial<U>[] : T[P] extends object | undefined ? DeepPartial<T[P]> : T[P];
18
17
  };
19
- export type BasicType = string | number | boolean | Date;
18
+ export type BasicType = string | number | boolean | Date | Instant;
20
19
  export type ToString<T> = T extends string | number ? `${T}` : never;
21
20
  export type ToStringArray<T extends Array<string | number>> = {
22
21
  [K in keyof T]: T[K] extends string | number ? `${T[K]}` : never;
23
22
  };
24
23
  export type JoinPath<T extends readonly string[]> = T extends readonly [infer First, ...infer Rest] ? First extends string ? Rest extends readonly string[] ? Rest['length'] extends 0 ? First : `${First}.${JoinPath<Rest>}` : never : never : '';
24
+ export {};
25
25
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAA;AAE5B,MAAM,WAAW,aAAa,CAAC,cAAc;IAC3C,KAAK,CAAC,EAAE,cAAc,CAAA;CACvB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,cAAc,IAAI,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,CAAA;AAE9E,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAE1C,MAAM,MAAM,YAAY,CAAC,aAAa,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI;IACzE,CAAC,MAAM,CAAC,EAAE;SACP,CAAC,IAAI,aAAa,GAAG,IAAI;KAC3B,CAAA;CACF,CAAA;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,aAAa,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;AAE3G,MAAM,MAAM,SAAS,GAAG,OAAO,CAAA;AAE/B,MAAM,MAAM,UAAU,CAAC,CA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AAO,CAAA;AAElE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,KAAK,CAAA;AAEpE,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI;KAC3D,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK;CACjE,CAAA;AAED,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAC/F,KAAK,SAAS,MAAM,GAClB,IAAI,SAAS,SAAS,MAAM,EAAE,GAC5B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GACtB,KAAK,GACL,GAAG,KAAK,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,GAC9B,KAAK,GACP,KAAK,GACP,EAAE,CAAA"}
package/dist/ulid.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import { TaggedType } from '@bessemer/cornerstone/types';
1
+ import { NominalType } from '@bessemer/cornerstone/types';
2
2
  import Zod from 'zod';
3
- export type Ulid = TaggedType<string, 'Ulid'>;
4
- export declare const of: (value: string) => Ulid;
5
- export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<Ulid, string>>;
3
+ import { Result } from '@bessemer/cornerstone/result';
4
+ import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
5
+ export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"ulid">;
6
+ export type Ulid = NominalType<string, typeof Namespace>;
7
+ export declare const parseString: (value: string) => Result<Ulid, ErrorEvent>;
6
8
  export declare const fromString: (value: string) => Ulid;
9
+ export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<Ulid, string>>;
7
10
  export declare const generate: () => Ulid;
8
11
  //# sourceMappingURL=ulid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ulid.d.ts","sourceRoot":"","sources":["../src/ulid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7C,eAAO,MAAM,EAAE,GAAI,OAAO,MAAM,KAAG,IAElC,CAAA;AAED,eAAO,MAAM,MAAM,4DAEH,CAAA;AAEhB,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,IAE1C,CAAA;AAED,eAAO,MAAM,QAAQ,QAAO,IAE3B,CAAA"}
1
+ {"version":3,"file":"ulid.d.ts","sourceRoot":"","sources":["../src/ulid.ts"],"names":[],"mappings":"AACA,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,wEAAoB,CAAA;AAC1C,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAExD,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,IAAI,EAAE,UAAU,CAMlE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,IAE1C,CAAA;AAED,eAAO,MAAM,MAAM,4DAAiD,CAAA;AAEpE,eAAO,MAAM,QAAQ,QAAO,IAE3B,CAAA"}
package/dist/ulid.js CHANGED
@@ -1,20 +1,29 @@
1
1
  // src/ulid.ts
2
2
  import { ulid } from "ulid";
3
3
  import Zod from "zod";
4
- var of = (value) => {
5
- return value;
4
+ import { failure, success } from "@bessemer/cornerstone/result";
5
+ import { namespace } from "@bessemer/cornerstone/resource-key";
6
+ import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
7
+ import { structuredTransform } from "@bessemer/cornerstone/zod-util";
8
+ var Namespace = namespace("ulid");
9
+ var parseString = (value) => {
10
+ if (!/^[0-9A-HJKMNP-TV-Z]{26}$/.test(value)) {
11
+ return failure(invalidValue(value, { namespace: Namespace, message: `Invalid ULID format.` }));
12
+ }
13
+ return success(value);
6
14
  };
7
- var Schema = Zod.string().regex(/^[0-9A-HJKMNP-TV-Z]{26}$/, "Invalid ULID format").transform(of);
8
15
  var fromString = (value) => {
9
- return Schema.parse(value);
16
+ return unpackResult(parseString(value));
10
17
  };
18
+ var Schema = structuredTransform(Zod.string(), parseString);
11
19
  var generate = () => {
12
20
  return ulid();
13
21
  };
14
22
  export {
23
+ Namespace,
15
24
  Schema,
16
25
  fromString,
17
26
  generate,
18
- of
27
+ parseString
19
28
  };
20
29
  //# sourceMappingURL=ulid.js.map
package/dist/ulid.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ulid.ts"],"sourcesContent":["import { ulid } from 'ulid'\nimport { TaggedType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\n\nexport type Ulid = TaggedType<string, 'Ulid'>\n\nexport const of = (value: string): Ulid => {\n return value as Ulid\n}\n\nexport const Schema = Zod.string()\n .regex(/^[0-9A-HJKMNP-TV-Z]{26}$/, 'Invalid ULID format')\n .transform(of)\n\nexport const fromString = (value: string): Ulid => {\n return Schema.parse(value)\n}\n\nexport const generate = (): Ulid => {\n return ulid() as Ulid\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAErB,OAAO,SAAS;AAIT,IAAM,KAAK,CAAC,UAAwB;AACzC,SAAO;AACT;AAEO,IAAM,SAAS,IAAI,OAAO,EAC9B,MAAM,4BAA4B,qBAAqB,EACvD,UAAU,EAAE;AAER,IAAM,aAAa,CAAC,UAAwB;AACjD,SAAO,OAAO,MAAM,KAAK;AAC3B;AAEO,IAAM,WAAW,MAAY;AAClC,SAAO,KAAK;AACd;","names":[]}
1
+ {"version":3,"sources":["../src/ulid.ts"],"sourcesContent":["import { ulid } from 'ulid'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { namespace } 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 = namespace('ulid')\nexport type Ulid = NominalType<string, typeof Namespace>\n\nexport const parseString = (value: string): Result<Ulid, ErrorEvent> => {\n if (!/^[0-9A-HJKMNP-TV-Z]{26}$/.test(value)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `Invalid ULID format.` }))\n }\n\n return success(value as Ulid)\n}\n\nexport const fromString = (value: string): Ulid => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n\nexport const generate = (): Ulid => {\n return ulid() as Ulid\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAErB,OAAO,SAAS;AAChB,SAAS,SAAiB,eAAe;AACzC,SAAS,iBAAiB;AAC1B,SAAqB,cAAc,oBAAoB;AACvD,SAAS,2BAA2B;AAE7B,IAAM,YAAY,UAAU,MAAM;AAGlC,IAAM,cAAc,CAAC,UAA4C;AACtE,MAAI,CAAC,2BAA2B,KAAK,KAAK,GAAG;AAC3C,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,uBAAuB,CAAC,CAAC;AAAA,EAC/F;AAEA,SAAO,QAAQ,KAAa;AAC9B;AAEO,IAAM,aAAa,CAAC,UAAwB;AACjD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;AAE5D,IAAM,WAAW,MAAY;AAClC,SAAO,KAAK;AACd;","names":[]}
package/dist/unit.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NominalType } from '@bessemer/cornerstone/types';
2
- export type Unit = NominalType<null, 'Unit'>;
1
+ import { TaggedType } from '@bessemer/cornerstone/types';
2
+ export type Unit = TaggedType<null, 'Unit'>;
3
3
  export declare const Unit: Unit;
4
4
  //# sourceMappingURL=unit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../src/unit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC5C,eAAO,MAAM,IAAI,EAAE,IAAoB,CAAA"}
1
+ {"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../src/unit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC3C,eAAO,MAAM,IAAI,EAAE,IAAoB,CAAA"}
package/dist/unit.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/unit.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\n\nexport type Unit = NominalType<null, 'Unit'>\nexport const Unit: Unit = null as never\n"],"mappings":";AAGO,IAAM,OAAa;","names":[]}
1
+ {"version":3,"sources":["../src/unit.ts"],"sourcesContent":["import { TaggedType } from '@bessemer/cornerstone/types'\n\nexport type Unit = TaggedType<null, 'Unit'>\nexport const Unit: Unit = null as never\n"],"mappings":";AAGO,IAAM,OAAa;","names":[]}
package/dist/uri.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { NominalType } from '@bessemer/cornerstone/types';
1
+ import { TaggedType } from '@bessemer/cornerstone/types';
2
2
  export declare const encode: (uriComponent: UriComponent) => string;
3
3
  export declare const decode: (uriComponent: UriComponent) => string;
4
- export type UriString = NominalType<string, 'UriString'>;
4
+ export type UriString = TaggedType<string, 'UriString'>;
5
5
  export type UriComponent = string;
6
6
  export type UriScheme = string;
7
7
  export type UriAuthentication = {
package/dist/uri.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"uri.d.ts","sourceRoot":"","sources":["../src/uri.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAKzD,eAAO,MAAM,MAAM,GAAI,cAAc,YAAY,WAEhD,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,cAAc,YAAY,WAEhD,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AACxD,MAAM,MAAM,YAAY,GAAG,MAAM,CAAA;AAEjC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAE9B,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB,CAAA;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAA;IACxB,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;IACpB,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;IACxC,QAAQ,EAAE,WAAW,CAAA;CACtB;AA8ID,eAAO,MAAM,KAAK,GAAI,WAAW,SAAS,KAAG,GAO5C,CAAA;AAED,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AAG,EAAE,SAAQ,KAAK,CAAC,gBAAgB,CAAmC,KAAG,SAgCpG,CAAA;AAoBD,eAAO,MAAM,WAAW,GAAI,SAAS,UAAU,KAAG,SAEjD,CAAA"}
package/dist/uri.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/uri.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport { isEmpty, isString, removeStart, splitFirst, startsWith, StringSplitResult } from '@bessemer/cornerstone/string'\nimport { isNil, isPresent } from '@bessemer/cornerstone/object'\nimport { contains } from '@bessemer/cornerstone/array'\n\nexport const encode = (uriComponent: UriComponent) => {\n return encodeURIComponent(uriComponent)\n}\n\nexport const decode = (uriComponent: UriComponent) => {\n return decodeURIComponent(uriComponent)\n}\n\nexport type UriString = NominalType<string, 'UriString'>\nexport type UriComponent = string\n\nexport type UriScheme = string\n\nexport type UriAuthentication = {\n principal: string\n password: string | null\n}\n\nexport type UriHost = {\n value: string\n port: number | null\n}\n\nexport interface UriLocation {\n path: string\n query: string | null\n fragment: string | null\n}\n\nexport interface Uri {\n scheme: UriScheme | null\n host: UriHost | null\n authentication: UriAuthentication | null\n location: UriLocation\n}\n\nconst parseSchemePart = (url: UriComponent): [UriScheme | null, UriComponent] => {\n // Search for the colon or double slash\n const schemeMatch = splitFirst(url, /(\\/\\/|:)/)\n\n // If we don't find either, or we hit the double slash before finding a colon, there is no scheme\n if (isNil(schemeMatch.selection) || schemeMatch.separator === '//') {\n return [null, url]\n }\n\n // This means the string started with :, so no protocol. We'll go ahead and remove the : from consideration\n if (isEmpty(schemeMatch.selection)) {\n return [null, schemeMatch.rest]\n } else {\n return [schemeMatch.selection, schemeMatch.rest]\n }\n}\n\nconst parseAuthenticationPart = (url: UriComponent): [UriAuthentication | null, UriComponent] => {\n let targetPart = url\n const queryMatch = splitFirst(targetPart, '?')\n const fragmentMatch = splitFirst(targetPart, '#')\n if (isPresent(queryMatch.selection)) {\n targetPart = queryMatch.selection\n } else if (isPresent(fragmentMatch.selection)) {\n targetPart = fragmentMatch.selection\n }\n\n const { selection: authentication } = splitFirst(targetPart, '@')\n\n // If there is no @, then we don't have an authentication\n if (isNil(authentication)) {\n return [null, url]\n }\n\n const { rest } = splitFirst(url, '@')\n\n return [parseAuthentication(removeStart(authentication, '//')), '//' + rest]\n}\n\nconst parseAuthentication = (authentication: UriComponent): UriAuthentication => {\n const { selection: principal, rest: authenticationRest } = splitFirst(authentication, ':')\n\n // If there isn't a colon, then there is no password but there is a username\n if (isNil(principal)) {\n return { principal: authenticationRest, password: null }\n }\n\n // The authentication section started with a :, don't know what to make of this... password but no username?\n if (isEmpty(principal)) {\n throw new Error(`Unable to parse Authentication: ${authentication}`)\n }\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n return { principal, password: authenticationRest }\n}\n\nconst parseHostPart = (url: UriComponent): [UriHost | null, UriComponent] => {\n // Check if the host is starting with reserved characters, if so we should just bail on trying to parse\n if (startsWith(url, '?') || startsWith(url, '#')) {\n return [null, url]\n }\n\n let hostRequired = startsWith(url, '//')\n if (!hostRequired) {\n return [null, url]\n }\n\n url = removeStart(url, '//')\n\n // Lets grab everything to the left of the first / ? or #, this is the remainder of our authority (if any)\n const urlMatch = splitFirst(url, /[\\/?#]/)\n let host = urlMatch.rest\n let rest = ''\n\n if (isPresent(urlMatch.selection)) {\n host = urlMatch.selection\n rest = urlMatch.separator + urlMatch.rest\n }\n\n if (isEmpty(host)) {\n return [null, rest]\n }\n\n return [parseHost(host), rest]\n}\n\nconst parseHost = (host: UriComponent): UriHost => {\n // Try to see if we have an ipv6 address like the form [2001:db8::7] and handle it\n if (startsWith(host, '[')) {\n const ipMatch = splitFirst(host, ']')\n\n if (isPresent(ipMatch.selection)) {\n const portMatch = splitFirst(ipMatch.rest, ':')\n if (isPresent(portMatch.selection)) {\n if (isEmpty(portMatch.selection)) {\n return { value: ipMatch.selection + ']', port: Number(portMatch.rest) }\n }\n } else {\n return { value: ipMatch.selection + ']', port: null }\n }\n }\n }\n\n let hostMatch: StringSplitResult = splitFirst(host, ':')\n\n // We have no :, which means no port, so treat the rest as the hostname\n if (isNil(hostMatch.selection)) {\n return { value: hostMatch.rest, port: null }\n }\n\n // The host started with a :, this is odd\n if (isEmpty(hostMatch.selection)) {\n throw new Error(`Unable to parse Host: ${host}`)\n }\n\n const hostName = hostMatch.selection\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n return { value: hostName, port: Number(hostMatch.rest) }\n}\n\nconst parseLocation = (url: UriComponent): UriLocation => {\n const location: UriLocation = { path: '', query: null, fragment: null }\n\n // Lets see if we have a fragment and parse it off the end\n const fragmentMatch = splitFirst(url, '#')\n if (isPresent(fragmentMatch.selection) && !isEmpty(fragmentMatch.rest)) {\n location.fragment = fragmentMatch.rest\n }\n\n // Lets see if we have a query string and parse it off the remainder\n const queryMatch = splitFirst(fragmentMatch.selection ?? fragmentMatch.rest, '?')\n if (isPresent(queryMatch.selection) && !isEmpty(queryMatch.rest)) {\n location.query = queryMatch.rest\n }\n\n location.path = queryMatch.selection ?? queryMatch.rest\n return location\n}\n\nexport const parse = (urlString: UriString): Uri => {\n const [scheme, rest1] = parseSchemePart(urlString)\n const [authentication, rest2] = parseAuthenticationPart(rest1)\n const [host, rest3] = parseHostPart(rest2)\n const location = parseLocation(rest3)\n const url: Uri = { scheme, host, authentication, location }\n return url\n}\n\nexport const emptyLocation = (): UriLocation => {\n return {\n path: '',\n query: null,\n fragment: null,\n }\n}\n\nexport type UriBuilder = {\n scheme?: string\n host?:\n | {\n value: string\n port?: number\n }\n | string\n authentication?:\n | {\n principal: string\n password?: string\n }\n | string\n location?:\n | {\n path: string\n query?: string\n fragment?: string\n }\n | string\n}\n\nexport const build = (builder: UriBuilder): Uri => {\n const scheme = builder.scheme ?? null\n\n let host: UriHost | null = null\n if (isPresent(builder.host)) {\n if (isString(builder.host)) {\n host = parseHost(builder.host)\n } else {\n host = {\n value: builder.host.value,\n port: builder.host.port ?? null,\n }\n }\n }\n\n let authentication: UriAuthentication | null = null\n if (isPresent(builder.authentication)) {\n if (isString(builder.authentication)) {\n authentication = parseAuthentication(builder.authentication)\n } else {\n authentication = {\n principal: builder.authentication.principal,\n password: builder.authentication.password ?? null,\n }\n }\n }\n\n let location: UriLocation = emptyLocation()\n if (isPresent(builder.location)) {\n if (isString(builder.location)) {\n location = parseLocation(builder.location)\n } else {\n location = {\n path: builder.location.path,\n query: builder.location.query ?? null,\n fragment: builder.location.fragment ?? null,\n }\n }\n }\n\n return {\n scheme,\n host,\n authentication,\n location,\n }\n}\n\nexport enum UriComponentType {\n Scheme = 'Scheme',\n Host = 'Host',\n Location = 'Location',\n}\n\nexport const format = (uri: Uri, format: Array<UriComponentType> = Object.values(UriComponentType)): UriString => {\n let urlString = ''\n if (isPresent(uri.scheme) && contains(format, UriComponentType.Scheme)) {\n urlString = urlString + uri.scheme\n }\n\n if (isPresent(uri.host) && contains(format, UriComponentType.Host)) {\n if (isPresent(uri.scheme)) {\n urlString = urlString + '://'\n }\n\n if (isPresent(uri.authentication)) {\n urlString = urlString + uri.authentication.principal\n\n if (isPresent(uri.authentication.password)) {\n urlString = urlString + ':' + uri.authentication.password\n }\n\n urlString = urlString + '@'\n }\n\n urlString = urlString + uri.host.value\n\n if (isPresent(uri.host.port)) {\n urlString = urlString + ':' + uri.host.port\n }\n }\n\n if (contains(format, UriComponentType.Location)) {\n urlString = urlString + formatLocation(uri.location, format)\n }\n return urlString\n}\n\nconst formatLocation = (location: UriLocation, format: Array<UriComponentType>): string => {\n let urlString = ''\n\n if (!isEmpty(location.path)) {\n urlString = urlString + location.path\n }\n\n if (!isEmpty(location.query)) {\n urlString = urlString + '?' + location.query\n }\n\n if (!isEmpty(location.fragment)) {\n urlString = urlString + '#' + encode(location.fragment!)\n }\n\n return urlString\n}\n\nexport const buildString = (builder: UriBuilder): UriString => {\n return format(build(builder))\n}\n"],"mappings":";AACA,SAAS,SAAS,UAAU,aAAa,YAAY,kBAAqC;AAC1F,SAAS,OAAO,iBAAiB;AACjC,S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A,QAAI,UAAU,IAAI,cAAc,GAAG;AACjC,kBAAY,YAAY,IAAI,eAAe;AAE3C,UAAI,UAAU,IAAI,eAAe,QAAQ,GAAG;AAC1C,oBAAY,YAAY,MAAM,IAAI,eAAe;AAAA,MACnD;AAEA,kBAAY,YAAY;AAAA,IAC1B;AAEA,gBAAY,YAAY,IAAI,KAAK;AAEjC,QAAI,UAAU,IAAI,KAAK,IAAI,GAAG;AAC5B,kBAAY,YAAY,MAAM,IAAI,KAAK;AAAA,IACzC;AAAA,EACF;AAEA,MAAI,SAASA,SAAQ,yBAAyB,GAAG;AAC/C,gBAAY,YAAY,eAAe,IAAI,UAAUA,OAAM;AAAA,EAC7D;AACA,SAAO;AACT;AAEA,IAAM,iBAAiB,CAAC,UAAuBA,YAA4C;AACzF,MAAI,YAAY;AAEhB,MAAI,CAAC,QAAQ,SAAS,IAAI,GAAG;AAC3B,gBAAY,YAAY,SAAS;AAAA,EACnC;AAEA,MAAI,CAAC,QAAQ,SAAS,KAAK,GAAG;AAC5B,gBAAY,YAAY,MAAM,SAAS;AAAA,EACzC;AAEA,MAAI,CAAC,QAAQ,SAAS,QAAQ,GAAG;AAC/B,gBAAY,YAAY,MAAM,OAAO,SAAS,QAAS;AAAA,EACzD;AAEA,SAAO;AACT;AAEO,IAAM,cAAc,CAAC,YAAmC;AAC7D,SAAO,OAAO,MAAM,OAAO,CAAC;AAC9B;","names":["UriComponentType","format"]}
1
+ {"version":3,"sources":["../src/uri.ts"],"sourcesContent":["import { TaggedType } from '@bessemer/cornerstone/types'\nimport { isEmpty, isString, removeStart, splitFirst, startsWith, StringSplitResult } from '@bessemer/cornerstone/string'\nimport { isNil, isPresent } from '@bessemer/cornerstone/object'\nimport { contains } from '@bessemer/cornerstone/array'\n\nexport const encode = (uriComponent: UriComponent) => {\n return encodeURIComponent(uriComponent)\n}\n\nexport const decode = (uriComponent: UriComponent) => {\n return decodeURIComponent(uriComponent)\n}\n\nexport type UriString = TaggedType<string, 'UriString'>\nexport type UriComponent = string\n\nexport type UriScheme = string\n\nexport type UriAuthentication = {\n principal: string\n password: string | null\n}\n\nexport type UriHost = {\n value: string\n port: number | null\n}\n\nexport interface UriLocation {\n path: string\n query: string | null\n fragment: string | null\n}\n\nexport interface Uri {\n scheme: UriScheme | null\n host: UriHost | null\n authentication: UriAuthentication | null\n location: UriLocation\n}\n\nconst parseSchemePart = (url: UriComponent): [UriScheme | null, UriComponent] => {\n // Search for the colon or double slash\n const schemeMatch = splitFirst(url, /(\\/\\/|:)/)\n\n // If we don't find either, or we hit the double slash before finding a colon, there is no scheme\n if (isNil(schemeMatch.selection) || schemeMatch.separator === '//') {\n return [null, url]\n }\n\n // This means the string started with :, so no protocol. We'll go ahead and remove the : from consideration\n if (isEmpty(schemeMatch.selection)) {\n return [null, schemeMatch.rest]\n } else {\n return [schemeMatch.selection, schemeMatch.rest]\n }\n}\n\nconst parseAuthenticationPart = (url: UriComponent): [UriAuthentication | null, UriComponent] => {\n let targetPart = url\n const queryMatch = splitFirst(targetPart, '?')\n const fragmentMatch = splitFirst(targetPart, '#')\n if (isPresent(queryMatch.selection)) {\n targetPart = queryMatch.selection\n } else if (isPresent(fragmentMatch.selection)) {\n targetPart = fragmentMatch.selection\n }\n\n const { selection: authentication } = splitFirst(targetPart, '@')\n\n // If there is no @, then we don't have an authentication\n if (isNil(authentication)) {\n return [null, url]\n }\n\n const { rest } = splitFirst(url, '@')\n\n return [parseAuthentication(removeStart(authentication, '//')), '//' + rest]\n}\n\nconst parseAuthentication = (authentication: UriComponent): UriAuthentication => {\n const { selection: principal, rest: authenticationRest } = splitFirst(authentication, ':')\n\n // If there isn't a colon, then there is no password but there is a username\n if (isNil(principal)) {\n return { principal: authenticationRest, password: null }\n }\n\n // The authentication section started with a :, don't know what to make of this... password but no username?\n if (isEmpty(principal)) {\n throw new Error(`Unable to parse Authentication: ${authentication}`)\n }\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n return { principal, password: authenticationRest }\n}\n\nconst parseHostPart = (url: UriComponent): [UriHost | null, UriComponent] => {\n // Check if the host is starting with reserved characters, if so we should just bail on trying to parse\n if (startsWith(url, '?') || startsWith(url, '#')) {\n return [null, url]\n }\n\n let hostRequired = startsWith(url, '//')\n if (!hostRequired) {\n return [null, url]\n }\n\n url = removeStart(url, '//')\n\n // Lets grab everything to the left of the first / ? or #, this is the remainder of our authority (if any)\n const urlMatch = splitFirst(url, /[\\/?#]/)\n let host = urlMatch.rest\n let rest = ''\n\n if (isPresent(urlMatch.selection)) {\n host = urlMatch.selection\n rest = urlMatch.separator + urlMatch.rest\n }\n\n if (isEmpty(host)) {\n return [null, rest]\n }\n\n return [parseHost(host), rest]\n}\n\nconst parseHost = (host: UriComponent): UriHost => {\n // Try to see if we have an ipv6 address like the form [2001:db8::7] and handle it\n if (startsWith(host, '[')) {\n const ipMatch = splitFirst(host, ']')\n\n if (isPresent(ipMatch.selection)) {\n const portMatch = splitFirst(ipMatch.rest, ':')\n if (isPresent(portMatch.selection)) {\n if (isEmpty(portMatch.selection)) {\n return { value: ipMatch.selection + ']', port: Number(portMatch.rest) }\n }\n } else {\n return { value: ipMatch.selection + ']', port: null }\n }\n }\n }\n\n let hostMatch: StringSplitResult = splitFirst(host, ':')\n\n // We have no :, which means no port, so treat the rest as the hostname\n if (isNil(hostMatch.selection)) {\n return { value: hostMatch.rest, port: null }\n }\n\n // The host started with a :, this is odd\n if (isEmpty(hostMatch.selection)) {\n throw new Error(`Unable to parse Host: ${host}`)\n }\n\n const hostName = hostMatch.selection\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n return { value: hostName, port: Number(hostMatch.rest) }\n}\n\nconst parseLocation = (url: UriComponent): UriLocation => {\n const location: UriLocation = { path: '', query: null, fragment: null }\n\n // Lets see if we have a fragment and parse it off the end\n const fragmentMatch = splitFirst(url, '#')\n if (isPresent(fragmentMatch.selection) && !isEmpty(fragmentMatch.rest)) {\n location.fragment = fragmentMatch.rest\n }\n\n // Lets see if we have a query string and parse it off the remainder\n const queryMatch = splitFirst(fragmentMatch.selection ?? fragmentMatch.rest, '?')\n if (isPresent(queryMatch.selection) && !isEmpty(queryMatch.rest)) {\n location.query = queryMatch.rest\n }\n\n location.path = queryMatch.selection ?? queryMatch.rest\n return location\n}\n\nexport const parse = (urlString: UriString): Uri => {\n const [scheme, rest1] = parseSchemePart(urlString)\n const [authentication, rest2] = parseAuthenticationPart(rest1)\n const [host, rest3] = parseHostPart(rest2)\n const location = parseLocation(rest3)\n const url: Uri = { scheme, host, authentication, location }\n return url\n}\n\nexport const emptyLocation = (): UriLocation => {\n return {\n path: '',\n query: null,\n fragment: null,\n }\n}\n\nexport type UriBuilder = {\n scheme?: string\n host?:\n | {\n value: string\n port?: number\n }\n | string\n authentication?:\n | {\n principal: string\n password?: string\n }\n | string\n location?:\n | {\n path: string\n query?: string\n fragment?: string\n }\n | string\n}\n\nexport const build = (builder: UriBuilder): Uri => {\n const scheme = builder.scheme ?? null\n\n let host: UriHost | null = null\n if (isPresent(builder.host)) {\n if (isString(builder.host)) {\n host = parseHost(builder.host)\n } else {\n host = {\n value: builder.host.value,\n port: builder.host.port ?? null,\n }\n }\n }\n\n let authentication: UriAuthentication | null = null\n if (isPresent(builder.authentication)) {\n if (isString(builder.authentication)) {\n authentication = parseAuthentication(builder.authentication)\n } else {\n authentication = {\n principal: builder.authentication.principal,\n password: builder.authentication.password ?? null,\n }\n }\n }\n\n let location: UriLocation = emptyLocation()\n if (isPresent(builder.location)) {\n if (isString(builder.location)) {\n location = parseLocation(builder.location)\n } else {\n location = {\n path: builder.location.path,\n query: builder.location.query ?? null,\n fragment: builder.location.fragment ?? null,\n }\n }\n }\n\n return {\n scheme,\n host,\n authentication,\n location,\n }\n}\n\nexport enum UriComponentType {\n Scheme = 'Scheme',\n Host = 'Host',\n Location = 'Location',\n}\n\nexport const format = (uri: Uri, format: Array<UriComponentType> = Object.values(UriComponentType)): UriString => {\n let urlString = ''\n if (isPresent(uri.scheme) && contains(format, UriComponentType.Scheme)) {\n urlString = urlString + uri.scheme\n }\n\n if (isPresent(uri.host) && contains(format, UriComponentType.Host)) {\n if (isPresent(uri.scheme)) {\n urlString = urlString + '://'\n }\n\n if (isPresent(uri.authentication)) {\n urlString = urlString + uri.authentication.principal\n\n if (isPresent(uri.authentication.password)) {\n urlString = urlString + ':' + uri.authentication.password\n }\n\n urlString = urlString + '@'\n }\n\n urlString = urlString + uri.host.value\n\n if (isPresent(uri.host.port)) {\n urlString = urlString + ':' + uri.host.port\n }\n }\n\n if (contains(format, UriComponentType.Location)) {\n urlString = urlString + formatLocation(uri.location, format)\n }\n return urlString\n}\n\nconst formatLocation = (location: UriLocation, format: Array<UriComponentType>): string => {\n let urlString = ''\n\n if (!isEmpty(location.path)) {\n urlString = urlString + location.path\n }\n\n if (!isEmpty(location.query)) {\n urlString = urlString + '?' + location.query\n }\n\n if (!isEmpty(location.fragment)) {\n urlString = urlString + '#' + encode(location.fragment!)\n }\n\n return urlString\n}\n\nexport const buildString = (builder: UriBuilder): UriString => {\n return format(build(builder))\n}\n"],"mappings":";AACA,SAAS,SAAS,UAAU,aAAa,YAAY,kBAAqC;AAC1F,SAAS,OAAO,iBAAiB;AACjC,SAAS,gBAAgB;AAElB,IAAM,SAAS,CAAC,iBAA+B;AACpD,SAAO,mBAAmB,YAAY;AACxC;AAEO,IAAM,SAAS,CAAC,iBAA+B;AACpD,SAAO,mBAAmB,YAAY;AACxC;AA8BA,IAAM,kBAAkB,CAAC,QAAwD;AAE/E,QAAM,cAAc,WAAW,KAAK,UAAU;AAG9C,MAAI,MAAM,YAAY,SAAS,KAAK,YAAY,cAAc,MAAM;AAClE,WAAO,CAAC,MAAM,GAAG;AAAA,EACnB;AAGA,MAAI,QAAQ,YAAY,SAAS,GAAG;AAClC,WAAO,CAAC,MAAM,YAAY,IAAI;AAAA,EAChC,OAAO;AACL,WAAO,CAAC,YAAY,WAAW,YAAY,IAAI;AAAA,EACjD;AACF;AAEA,IAAM,0BAA0B,CAAC,QAAgE;AAC/F,MAAI,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MAAI,CAAC,QAAQ,SAAS,IAAI,GAAG;AAC3B,gBAAY,YAAY,SAAS;AAAA,EACnC;AAEA,MAAI,CAAC,QAAQ,SAAS,KAAK,GAAG;AAC5B,gBAAY,YAAY,MAAM,SAAS;AAAA,EACzC;AAEA,MAAI,CAAC,QAAQ,SAAS,QAAQ,GAAG;AAC/B,gBAAY,YAAY,MAAM,OAAO,SAAS,QAAS;AAAA,EACzD;AAEA,SAAO;AACT;AAEO,IAAM,cAAc,CAAC,YAAmC;AAC7D,SAAO,OAAO,MAAM,OAAO,CAAC;AAC9B;","names":["UriComponentType","format"]}
package/dist/uuid.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import { TaggedType } from '@bessemer/cornerstone/types';
1
+ import { NominalType } from '@bessemer/cornerstone/types';
2
2
  import Zod from 'zod';
3
- export type Uuid = TaggedType<string, 'Uuid'>;
4
- export declare const of: (value: string) => Uuid;
5
- export declare const Schema: Zod.ZodPipe<Zod.ZodUUID, Zod.ZodTransform<Uuid, string>>;
3
+ import { Result } from '@bessemer/cornerstone/result';
4
+ import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
5
+ export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"uuid">;
6
+ export type Uuid = NominalType<string, typeof Namespace>;
7
+ export declare const parseString: (value: string) => Result<Uuid, ErrorEvent>;
6
8
  export declare const fromString: (value: string) => Uuid;
9
+ export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<Uuid, string>>;
7
10
  export declare const generate: () => Uuid;
8
11
  //# sourceMappingURL=uuid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,GAAG,MAAM,KAAK,CAAA;AAIrB,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE7C,eAAO,MAAM,EAAE,GAAI,OAAO,MAAM,KAAG,IAElC,CAAA;AAED,eAAO,MAAM,MAAM,0DAA2B,CAAA;AAE9C,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,IAE1C,CAAA;AAED,eAAO,MAAM,QAAQ,QAAO,IAM3B,CAAA"}
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;AAGrB,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAIhG,eAAO,MAAM,SAAS,wEAAoB,CAAA;AAC1C,MAAM,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAExD,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,IAAI,EAAE,UAAU,CAMlE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,IAE1C,CAAA;AAED,eAAO,MAAM,MAAM,4DAAiD,CAAA;AAEpE,eAAO,MAAM,QAAQ,QAAO,IAM3B,CAAA"}
package/dist/uuid.js CHANGED
@@ -2,13 +2,21 @@
2
2
  import Zod from "zod";
3
3
  import { isNil } from "@bessemer/cornerstone/object";
4
4
  import { padStart } from "@bessemer/cornerstone/string";
5
- var of = (value) => {
6
- return value;
5
+ import { failure, success } from "@bessemer/cornerstone/result";
6
+ import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
7
+ import { namespace } from "@bessemer/cornerstone/resource-key";
8
+ import { structuredTransform } from "@bessemer/cornerstone/zod-util";
9
+ var Namespace = namespace("uuid");
10
+ var parseString = (value) => {
11
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) {
12
+ return failure(invalidValue(value, { namespace: Namespace, message: `Invalid Uuid format.` }));
13
+ }
14
+ return success(value.toLowerCase());
7
15
  };
8
- var Schema = Zod.uuid().transform(of);
9
16
  var fromString = (value) => {
10
- return Schema.parse(value);
17
+ return unpackResult(parseString(value));
11
18
  };
19
+ var Schema = structuredTransform(Zod.string(), parseString);
12
20
  var generate = () => {
13
21
  if (isNil(crypto.randomUUID)) {
14
22
  return `${randomHex(8)}-${randomHex(4)}-${randomHex(4)}-${randomHex(4)}-${randomHex(12)}`;
@@ -21,9 +29,10 @@ var randomHex = (characters) => {
21
29
  return padStart(randomNum.toString(16), characters, "0");
22
30
  };
23
31
  export {
32
+ Namespace,
24
33
  Schema,
25
34
  fromString,
26
35
  generate,
27
- of
36
+ parseString
28
37
  };
29
38
  //# sourceMappingURL=uuid.js.map
package/dist/uuid.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/uuid.ts"],"sourcesContent":["import { TaggedType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { padStart } from '@bessemer/cornerstone/string'\n\nexport type Uuid = TaggedType<string, 'Uuid'>\n\nexport const of = (value: string): Uuid => {\n return value as Uuid\n}\n\nexport const Schema = Zod.uuid().transform(of)\n\nexport const fromString = (value: string): Uuid => {\n return Schema.parse(value)\n}\n\nexport const generate = (): Uuid => {\n if (isNil(crypto.randomUUID)) {\n return `${randomHex(8)}-${randomHex(4)}-${randomHex(4)}-${randomHex(4)}-${randomHex(12)}` as Uuid\n } else {\n return crypto.randomUUID() as Uuid\n }\n}\n\nconst randomHex = (characters: number) => {\n // Generates a random number between 0x0..0 and 0xF..F for the target number of characters\n const randomNum = Math.floor(Math.random() * (16 ** characters - 1))\n return padStart(randomNum.toString(16), characters, '0')\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,SAAS,aAAa;AACtB,SAAS,gBAAgB;AAIlB,IAAM,KAAK,CAAC,UAAwB;AACzC,SAAO;AACT;AAEO,IAAM,SAAS,IAAI,KAAK,EAAE,UAAU,EAAE;AAEtC,IAAM,aAAa,CAAC,UAAwB;AACjD,SAAO,OAAO,MAAM,KAAK;AAC3B;AAEO,IAAM,WAAW,MAAY;AAClC,MAAI,MAAM,OAAO,UAAU,GAAG;AAC5B,WAAO,GAAG,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;AAAA,EACzF,OAAO;AACL,WAAO,OAAO,WAAW;AAAA,EAC3B;AACF;AAEA,IAAM,YAAY,CAAC,eAAuB;AAExC,QAAM,YAAY,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,aAAa,EAAE;AACnE,SAAO,SAAS,UAAU,SAAS,EAAE,GAAG,YAAY,GAAG;AACzD;","names":[]}
1
+ {"version":3,"sources":["../src/uuid.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { padStart } from '@bessemer/cornerstone/string'\nimport { failure, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = namespace('uuid')\nexport type Uuid = NominalType<string, typeof Namespace>\n\nexport const parseString = (value: string): Result<Uuid, ErrorEvent> => {\n if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) {\n return failure(invalidValue(value, { namespace: Namespace, message: `Invalid Uuid format.` }))\n }\n\n return success(value.toLowerCase() as Uuid)\n}\n\nexport const fromString = (value: string): Uuid => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n\nexport const generate = (): Uuid => {\n if (isNil(crypto.randomUUID)) {\n return `${randomHex(8)}-${randomHex(4)}-${randomHex(4)}-${randomHex(4)}-${randomHex(12)}` as Uuid\n } else {\n return crypto.randomUUID() as Uuid\n }\n}\n\nconst randomHex = (characters: number) => {\n // Generates a random number between 0x0..0 and 0xF..F for the target number of characters\n const randomNum = Math.floor(Math.random() * (16 ** characters - 1))\n return padStart(randomNum.toString(16), characters, '0')\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,SAAiB,eAAe;AACzC,SAAqB,cAAc,oBAAoB;AACvD,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AAE7B,IAAM,YAAY,UAAU,MAAM;AAGlC,IAAM,cAAc,CAAC,UAA4C;AACtE,MAAI,CAAC,6EAA6E,KAAK,KAAK,GAAG;AAC7F,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,uBAAuB,CAAC,CAAC;AAAA,EAC/F;AAEA,SAAO,QAAQ,MAAM,YAAY,CAAS;AAC5C;AAEO,IAAM,aAAa,CAAC,UAAwB;AACjD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;AAE5D,IAAM,WAAW,MAAY;AAClC,MAAI,MAAM,OAAO,UAAU,GAAG;AAC5B,WAAO,GAAG,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;AAAA,EACzF,OAAO;AACL,WAAO,OAAO,WAAW;AAAA,EAC3B;AACF;AAEA,IAAM,YAAY,CAAC,eAAuB;AAExC,QAAM,YAAY,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,aAAa,EAAE;AACnE,SAAO,SAAS,UAAU,SAAS,EAAE,GAAG,YAAY,GAAG;AACzD;","names":[]}
@@ -1,10 +1,15 @@
1
1
  import Zod, { ZodType } from 'zod';
2
2
  import { ResourceKey } from '@bessemer/cornerstone/resource-key';
3
3
  import { Result } from '@bessemer/cornerstone/result';
4
+ import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
5
+ import { $RefinementCtx } from 'zod/v4/core';
4
6
  export declare const parse: <T extends ZodType>(type: T, data: unknown) => Result<Zod.infer<T>>;
5
7
  export declare const parseOrThrow: <T extends ZodType>(type: T, data: unknown) => Zod.infer<T>;
6
8
  export declare const parseJson: <T extends ZodType>(type: T, data: string) => Result<Zod.infer<T>>;
7
9
  export declare const parseJsonOrThrow: <T extends ZodType>(type: T, data: string) => Zod.infer<T>;
8
10
  export declare const arrayable: <T>(type: ZodType<T>) => Zod.ZodUnion<readonly [Zod.ZodType<T, unknown, Zod.core.$ZodTypeInternals<T, unknown>>, Zod.ZodArray<Zod.ZodType<T, unknown, Zod.core.$ZodTypeInternals<T, unknown>>>]>;
9
11
  export declare const key: () => ZodType<ResourceKey>;
12
+ export type StructuredTransformer<InputType, OutputType> = (value: InputType) => Result<OutputType, ErrorEvent>;
13
+ export declare const structuredTransform: <InputType, OutputType, SchemaType extends ZodType<InputType, InputType>>(schema: SchemaType, transformer: StructuredTransformer<InputType, OutputType>) => Zod.ZodPipe<SchemaType, Zod.ZodTransform<Awaited<OutputType>, Zod.core.output<SchemaType>>>;
14
+ export declare const refineResult: <InputType>(transformer: StructuredTransformer<InputType, unknown>) => ((value: InputType, context: $RefinementCtx<InputType>) => void);
10
15
  //# sourceMappingURL=zod-util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"zod-util.d.ts","sourceRoot":"","sources":["../src/zod-util.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAEhE,OAAO,EAA4B,MAAM,EAAW,MAAM,8BAA8B,CA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GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,OAAO,KAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAEnF,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,KAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAOvF,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,KAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAItF,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,4KAE5C,CAAA;AAED,eAAO,MAAM,GAAG,QAAO,OAAO,CAAC,WAAW,CAEzC,CAAA;AAED,MAAM,MAAM,qBAAqB,CAAC,SAAS,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE,SAAS,KAAK,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;AAE/G,eAAO,MAAM,mBAAmB,GAAI,SAAS,EAAE,UAAU,EAAE,UAAU,SAAS,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,EACzG,QAAQ,UAAU,EAClB,aAAa,qBAAqB,CAAC,SAAS,EAAE,UAAU,CAAC,gGAM1D,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,SAAS,EACpC,aAAa,qBAAqB,CAAC,SAAS,EAAE,OAAO,CAAC,KACrD,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,KAAK,IAAI,CAkBjE,CAAA"}
package/dist/zod-util.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import Zod from "zod";
3
3
  import { parse as jsonParse } from "@bessemer/cornerstone/json";
4
4
  import { failure, getValueOrThrow, success } from "@bessemer/cornerstone/result";
5
- import { Assertions } from "@bessemer/cornerstone/index";
5
+ import { unpackResult } from "@bessemer/cornerstone/error/error-event";
6
+ import * as Assertions from "@bessemer/cornerstone/assertion";
6
7
  var parse = (type, data) => {
7
8
  const result = type.safeParse(data);
8
9
  if (result.success) {
@@ -32,12 +33,37 @@ var arrayable = (type) => {
32
33
  var key = () => {
33
34
  return Zod.string();
34
35
  };
36
+ var structuredTransform = (schema, transformer) => {
37
+ return schema.superRefine(refineResult(transformer)).transform((it) => {
38
+ const result = transformer(it);
39
+ return unpackResult(result);
40
+ });
41
+ };
42
+ var refineResult = (transformer) => {
43
+ return (value, context) => {
44
+ const result = transformer(value);
45
+ if (!result.isSuccess) {
46
+ const error = result.value;
47
+ error.causes.forEach((cause) => {
48
+ context.addIssue({
49
+ code: "custom",
50
+ message: cause.message,
51
+ input: value,
52
+ error,
53
+ cause
54
+ });
55
+ });
56
+ }
57
+ };
58
+ };
35
59
  export {
36
60
  arrayable,
37
61
  key,
38
62
  parse,
39
63
  parseJson,
40
64
  parseJsonOrThrow,
41
- parseOrThrow
65
+ parseOrThrow,
66
+ refineResult,
67
+ structuredTransform
42
68
  };
43
69
  //# sourceMappingURL=zod-util.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/zod-util.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { ResourceKey } from '@bessemer/cornerstone/resource-key'\nimport { parse as jsonParse } from '@bessemer/cornerstone/json'\nimport { failure, getValueOrThrow, Result, success } from '@bessemer/cornerstone/result'\nimport { Assertions } from '@bessemer/cornerstone/index'\n\nexport const parse = <T extends ZodType>(type: T, data: unknown): Result<Zod.infer<T>> => {\n const result = type.safeParse(data)\n if (result.success) {\n return success(result.data)\n } else {\n return failure(result.error)\n }\n}\n\nexport const parseOrThrow = <T extends ZodType>(type: T, data: unknown): Zod.infer<T> => {\n return getValueOrThrow(parse(type, data))\n}\n\nexport const parseJson = <T extends ZodType>(type: T, data: string): Result<Zod.infer<T>> => {\n const result = jsonParse(data)\n if (!result.isSuccess) {\n return result\n }\n\n return parse(type, result.value)\n}\n\nexport const parseJsonOrThrow = <T extends ZodType>(type: T, data: string): Zod.infer<T> => {\n const result = parseJson(type, data)\n Assertions.assert(result.isSuccess)\n return result.value\n}\n\nexport const arrayable = <T>(type: ZodType<T>) => {\n return Zod.union([type, Zod.array(type)])\n}\n\nexport const key = (): ZodType<ResourceKey> => {\n return Zod.string()\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAE7B,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,iBAAyB,eAAe;AAC1D,SAAS,kBAAkB;AAEpB,IAAM,QAAQ,CAAoB,MAAS,SAAwC;AACxF,QAAM,SAAS,KAAK,UAAU,IAAI;AAClC,MAAI,OAAO,SAAS;AAClB,WAAO,QAAQ,OAAO,IAAI;AAAA,EAC5B,OAAO;AACL,WAAO,QAAQ,OAAO,KAAK;AAAA,EAC7B;AACF;AAEO,IAAM,eAAe,CAAoB,MAAS,SAAgC;AACvF,SAAO,gBAAgB,MAAM,MAAM,IAAI,CAAC;AAC1C;AAEO,IAAM,YAAY,CAAoB,MAAS,SAAuC;AAC3F,QAAM,SAAS,UAAU,IAAI;AAC7B,MAAI,CAAC,OAAO,WAAW;AACrB,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,MAAM,OAAO,KAAK;AACjC;AAEO,IAAM,mBAAmB,CAAoB,MAAS,SAA+B;AAC1F,QAAM,SAAS,UAAU,MAAM,IAAI;AACnC,aAAW,OAAO,OAAO,SAAS;AAClC,SAAO,OAAO;AAChB;AAEO,IAAM,YAAY,CAAI,SAAqB;AAChD,SAAO,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM,IAAI,CAAC,CAAC;AAC1C;AAEO,IAAM,MAAM,MAA4B;AAC7C,SAAO,IAAI,OAAO;AACpB;","names":[]}
1
+ {"version":3,"sources":["../src/zod-util.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { ResourceKey } from '@bessemer/cornerstone/resource-key'\nimport { parse as jsonParse } from '@bessemer/cornerstone/json'\nimport { failure, getValueOrThrow, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { $RefinementCtx } from 'zod/v4/core'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\n\nexport const parse = <T extends ZodType>(type: T, data: unknown): Result<Zod.infer<T>> => {\n const result = type.safeParse(data)\n if (result.success) {\n return success(result.data)\n } else {\n return failure(result.error)\n }\n}\n\nexport const parseOrThrow = <T extends ZodType>(type: T, data: unknown): Zod.infer<T> => {\n return getValueOrThrow(parse(type, data))\n}\n\nexport const parseJson = <T extends ZodType>(type: T, data: string): Result<Zod.infer<T>> => {\n const result = jsonParse(data)\n if (!result.isSuccess) {\n return result\n }\n\n return parse(type, result.value)\n}\n\nexport const parseJsonOrThrow = <T extends ZodType>(type: T, data: string): Zod.infer<T> => {\n const result = parseJson(type, data)\n Assertions.assert(result.isSuccess)\n return result.value\n}\n\nexport const arrayable = <T>(type: ZodType<T>) => {\n return Zod.union([type, Zod.array(type)])\n}\n\nexport const key = (): ZodType<ResourceKey> => {\n return Zod.string()\n}\n\nexport type StructuredTransformer<InputType, OutputType> = (value: InputType) => Result<OutputType, ErrorEvent>\n\nexport const structuredTransform = <InputType, OutputType, SchemaType extends ZodType<InputType, InputType>>(\n schema: SchemaType,\n transformer: StructuredTransformer<InputType, OutputType>\n) => {\n return schema.superRefine(refineResult(transformer)).transform((it) => {\n const result = transformer(it)\n return unpackResult(result)\n })\n}\n\nexport const refineResult = <InputType>(\n transformer: StructuredTransformer<InputType, unknown>\n): ((value: InputType, context: $RefinementCtx<InputType>) => void) => {\n return (value, context) => {\n const result = transformer(value)\n\n if (!result.isSuccess) {\n const error = result.value\n\n error.causes.forEach((cause) => {\n context.addIssue({\n code: 'custom',\n message: cause.message,\n input: value,\n error,\n cause,\n })\n })\n }\n }\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAE7B,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,iBAAyB,eA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,UACf,OAAO;AAAA,UACP;AAAA,UACA;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bessemer/cornerstone",
3
3
  "type": "module",
4
- "version": "0.5.85",
4
+ "version": "0.5.88",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "sideEffects": false,
@@ -22,8 +22,8 @@
22
22
  "clean": "rm -rf dist && rm -rf .turbo"
23
23
  },
24
24
  "dependencies": {
25
+ "@js-temporal/polyfill": "0.5.1",
25
26
  "@types/lodash-es": "4.17.12",
26
- "date-fns": "4.1.0",
27
27
  "immer": "10.1.1",
28
28
  "lodash-es": "4.17.21",
29
29
  "minimatch": "10.0.1",
package/dist/date.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import { addHours as _addHours, addMilliseconds as _addMilliseconds, isAfter as _isAfter, isBefore as _isBefore } from 'date-fns';
2
- import { Duration } from '@bessemer/cornerstone/duration';
3
- import Zod from 'zod';
4
- export declare const Schema: Zod.ZodPipe<Zod.ZodUnion<readonly [Zod.ZodString, Zod.ZodDate]>, Zod.ZodTransform<Date, string | Date>>;
5
- export declare const isDate: (value: unknown) => value is Date;
6
- export declare const now: () => Date;
7
- export declare const of: (dateString: string) => Date;
8
- export declare const addMilliseconds: typeof _addMilliseconds;
9
- export declare const addHours: typeof _addHours;
10
- export declare const isBefore: typeof _isBefore;
11
- export declare const isAfter: typeof _isAfter;
12
- export declare const addDuration: (date: Date, duration: Duration) => Date;
13
- //# sourceMappingURL=date.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,eAAe,IAAI,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,QAAQ,IAAI,SAAS,EAAY,MAAM,UAAU,CAAA;AAC3I,OAAO,EAAE,QAAQ,EAAkB,MAAM,gCAAgC,CAAA;AACzE,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,eAAO,MAAM,MAAM,yGAYjB,CAAA;AAEF,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAEhD,CAAA;AAED,eAAO,MAAM,GAAG,QAAO,IAEtB,CAAA;AAED,eAAO,MAAM,EAAE,GAAI,YAAY,MAAM,KAAG,IAEvC,CAAA;AAED,eAAO,MAAM,eAAe,yBAAmB,CAAA;AAC/C,eAAO,MAAM,QAAQ,kBAAY,CAAA;AACjC,eAAO,MAAM,QAAQ,kBAAY,CAAA;AACjC,eAAO,MAAM,OAAO,iBAAW,CAAA;AAC/B,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,EAAE,UAAU,QAAQ,KAAG,IAAuD,CAAA"}