@bessemer/cornerstone 0.5.97 → 0.5.99

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 (189) hide show
  1. package/dist/array.d.ts +62 -1
  2. package/dist/array.d.ts.map +1 -1
  3. package/dist/array.js +24 -11
  4. package/dist/array.js.map +1 -1
  5. package/dist/aspect-ratio.d.ts +1 -1
  6. package/dist/aspect-ratio.d.ts.map +1 -1
  7. package/dist/aspect-ratio.js +4 -4
  8. package/dist/aspect-ratio.js.map +1 -1
  9. package/dist/async-value.d.ts +10 -2
  10. package/dist/async-value.d.ts.map +1 -1
  11. package/dist/async-value.js +33 -2
  12. package/dist/async-value.js.map +1 -1
  13. package/dist/cache.js +1 -1
  14. package/dist/cache.js.map +1 -1
  15. package/dist/equalitor.d.ts +1 -0
  16. package/dist/equalitor.d.ts.map +1 -1
  17. package/dist/equalitor.js +3 -0
  18. package/dist/equalitor.js.map +1 -1
  19. package/dist/error/error-cause.d.ts +35 -0
  20. package/dist/error/error-cause.d.ts.map +1 -0
  21. package/dist/error/error-cause.js +97 -0
  22. package/dist/error/error-cause.js.map +1 -0
  23. package/dist/error/error-code.d.ts +17 -0
  24. package/dist/error/error-code.d.ts.map +1 -0
  25. package/dist/error/error-code.js +32 -0
  26. package/dist/error/error-code.js.map +1 -0
  27. package/dist/error/error-event.d.ts +29 -48
  28. package/dist/error/error-event.d.ts.map +1 -1
  29. package/dist/error/error-event.js +62 -151
  30. package/dist/error/error-event.js.map +1 -1
  31. package/dist/error/error-type.d.ts +1 -0
  32. package/dist/error/error-type.d.ts.map +1 -1
  33. package/dist/error/error-type.js +4 -2
  34. package/dist/error/error-type.js.map +1 -1
  35. package/dist/function.d.ts +1 -1
  36. package/dist/function.d.ts.map +1 -1
  37. package/dist/function.js +3 -2
  38. package/dist/function.js.map +1 -1
  39. package/dist/glob.d.ts +1 -1
  40. package/dist/glob.d.ts.map +1 -1
  41. package/dist/glob.js +4 -4
  42. package/dist/glob.js.map +1 -1
  43. package/dist/hex-code.d.ts +1 -1
  44. package/dist/hex-code.d.ts.map +1 -1
  45. package/dist/hex-code.js +4 -4
  46. package/dist/hex-code.js.map +1 -1
  47. package/dist/index.d.ts +10 -5
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +15 -5
  50. package/dist/index.js.map +1 -1
  51. package/dist/intl/country-code.d.ts +1 -1
  52. package/dist/intl/country-code.d.ts.map +1 -1
  53. package/dist/intl/country-code.js +4 -4
  54. package/dist/intl/country-code.js.map +1 -1
  55. package/dist/intl/country-subdivision-code.d.ts +1 -1
  56. package/dist/intl/country-subdivision-code.d.ts.map +1 -1
  57. package/dist/intl/country-subdivision-code.js +4 -4
  58. package/dist/intl/country-subdivision-code.js.map +1 -1
  59. package/dist/intl/currency-code.d.ts +1 -1
  60. package/dist/intl/currency-code.d.ts.map +1 -1
  61. package/dist/intl/currency-code.js +4 -4
  62. package/dist/intl/currency-code.js.map +1 -1
  63. package/dist/intl/language-code.d.ts +1 -1
  64. package/dist/intl/language-code.d.ts.map +1 -1
  65. package/dist/intl/language-code.js +4 -4
  66. package/dist/intl/language-code.js.map +1 -1
  67. package/dist/intl/locale.d.ts +1 -1
  68. package/dist/intl/locale.d.ts.map +1 -1
  69. package/dist/intl/locale.js +6 -6
  70. package/dist/intl/locale.js.map +1 -1
  71. package/dist/mime-type.d.ts +1 -1
  72. package/dist/mime-type.d.ts.map +1 -1
  73. package/dist/mime-type.js +4 -4
  74. package/dist/mime-type.js.map +1 -1
  75. package/dist/net/domain-name.d.ts +10 -0
  76. package/dist/net/domain-name.d.ts.map +1 -0
  77. package/dist/net/domain-name.js +30 -0
  78. package/dist/net/domain-name.js.map +1 -0
  79. package/dist/net/ipv4-address.d.ts +10 -0
  80. package/dist/net/ipv4-address.d.ts.map +1 -0
  81. package/dist/net/ipv4-address.js +30 -0
  82. package/dist/net/ipv4-address.js.map +1 -0
  83. package/dist/net/ipv6-address.d.ts +10 -0
  84. package/dist/net/ipv6-address.d.ts.map +1 -0
  85. package/dist/net/ipv6-address.js +30 -0
  86. package/dist/net/ipv6-address.js.map +1 -0
  87. package/dist/net/uri-host-name.d.ts +12 -0
  88. package/dist/net/uri-host-name.d.ts.map +1 -0
  89. package/dist/net/uri-host-name.js +44 -0
  90. package/dist/net/uri-host-name.js.map +1 -0
  91. package/dist/net/uri.d.ts +249 -0
  92. package/dist/net/uri.d.ts.map +1 -0
  93. package/dist/net/uri.js +444 -0
  94. package/dist/net/uri.js.map +1 -0
  95. package/dist/net/url.d.ts +58 -0
  96. package/dist/net/url.d.ts.map +1 -0
  97. package/dist/net/url.js +211 -0
  98. package/dist/net/url.js.map +1 -0
  99. package/dist/object/object-path.d.ts +1 -1
  100. package/dist/object/object-path.d.ts.map +1 -1
  101. package/dist/object/object-path.js +4 -4
  102. package/dist/object/object-path.js.map +1 -1
  103. package/dist/object/type-path.d.ts +1 -1
  104. package/dist/object/type-path.d.ts.map +1 -1
  105. package/dist/object/type-path.js +3 -3
  106. package/dist/object/type-path.js.map +1 -1
  107. package/dist/object.d.ts +1 -1
  108. package/dist/object.d.ts.map +1 -1
  109. package/dist/object.js +8 -6
  110. package/dist/object.js.map +1 -1
  111. package/dist/property.d.ts +2 -3
  112. package/dist/property.d.ts.map +1 -1
  113. package/dist/property.js.map +1 -1
  114. package/dist/resource-key.d.ts +7 -5
  115. package/dist/resource-key.d.ts.map +1 -1
  116. package/dist/resource-key.js +27 -15
  117. package/dist/resource-key.js.map +1 -1
  118. package/dist/result.d.ts.map +1 -1
  119. package/dist/result.js +3 -3
  120. package/dist/result.js.map +1 -1
  121. package/dist/string.d.ts +10 -21
  122. package/dist/string.d.ts.map +1 -1
  123. package/dist/string.js +54 -25
  124. package/dist/string.js.map +1 -1
  125. package/dist/tag.d.ts +2 -2
  126. package/dist/tag.d.ts.map +1 -1
  127. package/dist/tag.js +11 -12
  128. package/dist/tag.js.map +1 -1
  129. package/dist/temporal/duration.d.ts +4 -5
  130. package/dist/temporal/duration.d.ts.map +1 -1
  131. package/dist/temporal/duration.js +3 -7
  132. package/dist/temporal/duration.js.map +1 -1
  133. package/dist/temporal/instant.d.ts +4 -5
  134. package/dist/temporal/instant.d.ts.map +1 -1
  135. package/dist/temporal/instant.js +3 -7
  136. package/dist/temporal/instant.js.map +1 -1
  137. package/dist/temporal/plain-date-time.d.ts +4 -5
  138. package/dist/temporal/plain-date-time.d.ts.map +1 -1
  139. package/dist/temporal/plain-date-time.js +3 -7
  140. package/dist/temporal/plain-date-time.js.map +1 -1
  141. package/dist/temporal/plain-date.d.ts +8 -9
  142. package/dist/temporal/plain-date.d.ts.map +1 -1
  143. package/dist/temporal/plain-date.js +3 -7
  144. package/dist/temporal/plain-date.js.map +1 -1
  145. package/dist/temporal/plain-time.d.ts +6 -7
  146. package/dist/temporal/plain-time.d.ts.map +1 -1
  147. package/dist/temporal/plain-time.js +4 -8
  148. package/dist/temporal/plain-time.js.map +1 -1
  149. package/dist/temporal/time-zone-id.d.ts +1 -1
  150. package/dist/temporal/time-zone-id.d.ts.map +1 -1
  151. package/dist/temporal/time-zone-id.js +4 -4
  152. package/dist/temporal/time-zone-id.js.map +1 -1
  153. package/dist/temporal/time-zone-offset.d.ts +1 -1
  154. package/dist/temporal/time-zone-offset.d.ts.map +1 -1
  155. package/dist/temporal/time-zone-offset.js +4 -4
  156. package/dist/temporal/time-zone-offset.js.map +1 -1
  157. package/dist/temporal/zoned-date-time.d.ts +51 -0
  158. package/dist/temporal/zoned-date-time.d.ts.map +1 -0
  159. package/dist/temporal/zoned-date-time.js +106 -0
  160. package/dist/temporal/zoned-date-time.js.map +1 -0
  161. package/dist/types.d.ts +2 -2
  162. package/dist/types.d.ts.map +1 -1
  163. package/dist/{ulid.d.ts → uuid/ulid.d.ts} +2 -2
  164. package/dist/uuid/ulid.d.ts.map +1 -0
  165. package/dist/uuid/ulid.js +29 -0
  166. package/dist/uuid/ulid.js.map +1 -0
  167. package/dist/uuid/uuid-v4.d.ts +11 -0
  168. package/dist/uuid/uuid-v4.d.ts.map +1 -0
  169. package/dist/{uuid.js → uuid/uuid-v4.js} +11 -11
  170. package/dist/uuid/uuid-v4.js.map +1 -0
  171. package/dist/uuid/uuid-v7.d.ts +18 -0
  172. package/dist/uuid/uuid-v7.d.ts.map +1 -0
  173. package/dist/uuid/uuid-v7.js +44 -0
  174. package/dist/uuid/uuid-v7.js.map +1 -0
  175. package/package.json +1 -1
  176. package/dist/ulid.d.ts.map +0 -1
  177. package/dist/ulid.js +0 -29
  178. package/dist/ulid.js.map +0 -1
  179. package/dist/uri.d.ts +0 -52
  180. package/dist/uri.d.ts.map +0 -1
  181. package/dist/uri.js +0 -222
  182. package/dist/uri.js.map +0 -1
  183. package/dist/url.d.ts +0 -26
  184. package/dist/url.d.ts.map +0 -1
  185. package/dist/url.js +0 -120
  186. package/dist/url.js.map +0 -1
  187. package/dist/uuid.d.ts +0 -11
  188. package/dist/uuid.d.ts.map +0 -1
  189. package/dist/uuid.js.map +0 -1
@@ -1,22 +1,22 @@
1
- // src/uuid.ts
1
+ // src/uuid/uuid-v4.ts
2
2
  import Zod from "zod";
3
3
  import { isNil } from "@bessemer/cornerstone/object";
4
4
  import { padStart } from "@bessemer/cornerstone/string";
5
5
  import { failure, success } from "@bessemer/cornerstone/result";
6
6
  import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
7
- import { namespace } from "@bessemer/cornerstone/resource-key";
7
+ import { createNamespace } from "@bessemer/cornerstone/resource-key";
8
8
  import { structuredTransform } from "@bessemer/cornerstone/zod-util";
9
- var Namespace = namespace("uuid");
10
- var parseString = (value) => {
9
+ var Namespace = createNamespace("uuid-v4");
10
+ var parse = (value) => {
11
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.` }));
12
+ return failure(invalidValue(value, { namespace: Namespace, message: `[${Namespace}]: Invalid UuidV4 format: [${value}]` }));
13
13
  }
14
14
  return success(value.toLowerCase());
15
15
  };
16
- var fromString = (value) => {
17
- return unpackResult(parseString(value));
16
+ var from = (value) => {
17
+ return unpackResult(parse(value));
18
18
  };
19
- var Schema = structuredTransform(Zod.string(), parseString);
19
+ var Schema = structuredTransform(Zod.string(), parse);
20
20
  var generate = () => {
21
21
  if (isNil(crypto.randomUUID)) {
22
22
  return `${randomHex(8)}-${randomHex(4)}-${randomHex(4)}-${randomHex(4)}-${randomHex(12)}`;
@@ -31,8 +31,8 @@ var randomHex = (characters) => {
31
31
  export {
32
32
  Namespace,
33
33
  Schema,
34
- fromString,
34
+ from,
35
35
  generate,
36
- parseString
36
+ parse
37
37
  };
38
- //# sourceMappingURL=uuid.js.map
38
+ //# sourceMappingURL=uuid-v4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/uuid/uuid-v4.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 { createNamespace } from '@bessemer/cornerstone/resource-key'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = createNamespace('uuid-v4')\nexport type UuidV4 = NominalType<string, typeof Namespace>\n\nexport const parse = (value: string): Result<UuidV4, 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: `[${Namespace}]: Invalid UuidV4 format: [${value}]` }))\n }\n\n return success(value.toLowerCase() as UuidV4)\n}\n\nexport const from = (value: string): UuidV4 => {\n return unpackResult(parse(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parse)\n\nexport const generate = (): UuidV4 => {\n if (isNil(crypto.randomUUID)) {\n return `${randomHex(8)}-${randomHex(4)}-${randomHex(4)}-${randomHex(4)}-${randomHex(12)}` as UuidV4\n } else {\n return crypto.randomUUID() as UuidV4\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,uBAAuB;AAChC,SAAS,2BAA2B;AAE7B,IAAM,YAAY,gBAAgB,SAAS;AAG3C,IAAM,QAAQ,CAAC,UAA8C;AAClE,MAAI,CAAC,6EAA6E,KAAK,KAAK,GAAG;AAC7F,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,IAAI,SAAS,8BAA8B,KAAK,IAAI,CAAC,CAAC;AAAA,EAC5H;AAEA,SAAO,QAAQ,MAAM,YAAY,CAAW;AAC9C;AAEO,IAAM,OAAO,CAAC,UAA0B;AAC7C,SAAO,aAAa,MAAM,KAAK,CAAC;AAClC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,KAAK;AAEtD,IAAM,WAAW,MAAc;AACpC,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":[]}
@@ -0,0 +1,18 @@
1
+ import { NominalType } from '@bessemer/cornerstone/types';
2
+ import Zod from 'zod';
3
+ import { Result } from '@bessemer/cornerstone/result';
4
+ import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
5
+ import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
6
+ import * as Clocks from '@bessemer/cornerstone/temporal/clock';
7
+ import * as Instants from '@bessemer/cornerstone/temporal/instant';
8
+ export declare const Namespace: ResourceKeys.ResourceNamespace<"uuid-v7">;
9
+ export type UuidV7 = NominalType<string, typeof Namespace>;
10
+ export declare const parse: (value: string) => Result<UuidV7, ErrorEvent>;
11
+ export declare const from: (value: string) => UuidV7;
12
+ export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<UuidV7, string>>;
13
+ export declare const generate: (clock?: {
14
+ readonly zone: import("../temporal/time-zone-id").TimeZoneId;
15
+ instant(): Instants.Instant;
16
+ withZone(zone: import("../temporal/time-zone-id").TimeZoneId): Clocks.Clock;
17
+ }) => UuidV7;
18
+ //# sourceMappingURL=uuid-v7.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid-v7.d.ts","sourceRoot":"","sources":["../../src/uuid/uuid-v7.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAA;AACpE,OAAO,KAAK,YAAY,MAAM,oCAAoC,CAAA;AAElE,OAAO,KAAK,MAAM,MAAM,sCAAsC,CAAA;AAC9D,OAAO,KAAK,QAAQ,MAAM,wCAAwC,CAAA;AAGlE,eAAO,MAAM,SAAS,2CAA0C,CAAA;AAChE,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE1D,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAM9D,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,MAEpC,CAAA;AAED,eAAO,MAAM,MAAM,8DAAmD,CAAA;AAEtE,eAAO,MAAM,QAAQ,GAAI;;;;CAAsB,KAAG,MAyBjD,CAAA"}
@@ -0,0 +1,44 @@
1
+ // src/uuid/uuid-v7.ts
2
+ import Zod from "zod";
3
+ import * as Results from "@bessemer/cornerstone/result";
4
+ import * as ErrorEvents from "@bessemer/cornerstone/error/error-event";
5
+ import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
6
+ import * as ZodUtil from "@bessemer/cornerstone/zod-util";
7
+ import * as Clocks from "@bessemer/cornerstone/temporal/clock";
8
+ import * as Instants from "@bessemer/cornerstone/temporal/instant";
9
+ import * as Strings from "@bessemer/cornerstone/string";
10
+ var Namespace = ResourceKeys.createNamespace("uuid-v7");
11
+ var parse = (value) => {
12
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) {
13
+ return Results.failure(ErrorEvents.invalidValue(value, { namespace: Namespace, message: `[${Namespace}]: Invalid UuidV7 format: [${value}]` }));
14
+ }
15
+ return Results.success(value.toLowerCase());
16
+ };
17
+ var from = (value) => {
18
+ return ErrorEvents.unpackResult(parse(value));
19
+ };
20
+ var Schema = ZodUtil.structuredTransform(Zod.string(), parse);
21
+ var generate = (clock = Clocks.Default) => {
22
+ const timestamp = Instants.now(clock).epochMilliseconds;
23
+ const timestampHex = Strings.padStart(timestamp.toString(16), 12, "0");
24
+ const randomA = Math.floor(Math.random() * 4096);
25
+ const versionAndRandom = 28672 | randomA;
26
+ const versionAndRandomHex = Strings.padStart(versionAndRandom.toString(16), 4, "0");
27
+ const clockSeq = Math.floor(Math.random() * 16384);
28
+ const variantAndClockSeq = 32768 | clockSeq;
29
+ const variantAndClockSeqHex = Strings.padStart(variantAndClockSeq.toString(16), 4, "0");
30
+ const nodeHex = randomHex(12);
31
+ return `${timestampHex.slice(0, 8)}-${timestampHex.slice(8, 12)}-${versionAndRandomHex}-${variantAndClockSeqHex}-${nodeHex}`;
32
+ };
33
+ var randomHex = (characters) => {
34
+ const randomNum = Math.floor(Math.random() * (16 ** characters - 1));
35
+ return Strings.padStart(randomNum.toString(16), characters, "0");
36
+ };
37
+ export {
38
+ Namespace,
39
+ Schema,
40
+ from,
41
+ generate,
42
+ parse
43
+ };
44
+ //# sourceMappingURL=uuid-v7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/uuid/uuid-v7.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport * 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 * as ZodUtil from '@bessemer/cornerstone/zod-util'\nimport * as Clocks from '@bessemer/cornerstone/temporal/clock'\nimport * as Instants from '@bessemer/cornerstone/temporal/instant'\nimport * as Strings from '@bessemer/cornerstone/string'\n\nexport const Namespace = ResourceKeys.createNamespace('uuid-v7')\nexport type UuidV7 = NominalType<string, typeof Namespace>\n\nexport const parse = (value: string): Result<UuidV7, ErrorEvent> => {\n if (!/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) {\n return Results.failure(ErrorEvents.invalidValue(value, { namespace: Namespace, message: `[${Namespace}]: Invalid UuidV7 format: [${value}]` }))\n }\n\n return Results.success(value.toLowerCase() as UuidV7)\n}\n\nexport const from = (value: string): UuidV7 => {\n return ErrorEvents.unpackResult(parse(value))\n}\n\nexport const Schema = ZodUtil.structuredTransform(Zod.string(), parse)\n\nexport const generate = (clock = Clocks.Default): UuidV7 => {\n const timestamp = Instants.now(clock).epochMilliseconds\n\n // Convert timestamp to 48-bit (12 hex characters)\n const timestampHex = Strings.padStart(timestamp.toString(16), 12, '0')\n\n // Generate 12 bits of random data for sub-millisecond precision\n const randomA = Math.floor(Math.random() * 0x1000) // 12 bits\n\n // Set version (7) in the most significant 4 bits\n const versionAndRandom = 0x7000 | randomA\n const versionAndRandomHex = Strings.padStart(versionAndRandom.toString(16), 4, '0')\n\n // Generate 14 bits of random data for clock sequence\n const clockSeq = Math.floor(Math.random() * 0x4000) // 14 bits\n\n // Set variant bits (10xx) in the most significant 2 bits\n const variantAndClockSeq = 0x8000 | clockSeq\n const variantAndClockSeqHex = Strings.padStart(variantAndClockSeq.toString(16), 4, '0')\n\n // Generate 48 bits (12 hex characters) of random data for node\n const nodeHex = randomHex(12)\n\n // Format as UUID: xxxxxxxx-xxxx-7xxx-xxxx-xxxxxxxxxxxx\n return `${timestampHex.slice(0, 8)}-${timestampHex.slice(8, 12)}-${versionAndRandomHex}-${variantAndClockSeqHex}-${nodeHex}` as UuidV7\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 Strings.padStart(randomNum.toString(16), characters, '0')\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,YAAY,aAAa;AAEzB,YAAY,iBAAiB;AAE7B,YAAY,kBAAkB;AAC9B,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,cAAc;AAC1B,YAAY,aAAa;AAElB,IAAM,YAAyB,6BAAgB,SAAS;AAGxD,IAAM,QAAQ,CAAC,UAA8C;AAClE,MAAI,CAAC,yEAAyE,KAAK,KAAK,GAAG;AACzF,WAAe,gBAAoB,yBAAa,OAAO,EAAE,WAAW,WAAW,SAAS,IAAI,SAAS,8BAA8B,KAAK,IAAI,CAAC,CAAC;AAAA,EAChJ;AAEA,SAAe,gBAAQ,MAAM,YAAY,CAAW;AACtD;AAEO,IAAM,OAAO,CAAC,UAA0B;AAC7C,SAAmB,yBAAa,MAAM,KAAK,CAAC;AAC9C;AAEO,IAAM,SAAiB,4BAAoB,IAAI,OAAO,GAAG,KAAK;AAE9D,IAAM,WAAW,CAAC,QAAe,mBAAoB;AAC1D,QAAM,YAAqB,aAAI,KAAK,EAAE;AAGtC,QAAM,eAAuB,iBAAS,UAAU,SAAS,EAAE,GAAG,IAAI,GAAG;AAGrE,QAAM,UAAU,KAAK,MAAM,KAAK,OAAO,IAAI,IAAM;AAGjD,QAAM,mBAAmB,QAAS;AAClC,QAAM,sBAA8B,iBAAS,iBAAiB,SAAS,EAAE,GAAG,GAAG,GAAG;AAGlF,QAAM,WAAW,KAAK,MAAM,KAAK,OAAO,IAAI,KAAM;AAGlD,QAAM,qBAAqB,QAAS;AACpC,QAAM,wBAAgC,iBAAS,mBAAmB,SAAS,EAAE,GAAG,GAAG,GAAG;AAGtF,QAAM,UAAU,UAAU,EAAE;AAG5B,SAAO,GAAG,aAAa,MAAM,GAAG,CAAC,CAAC,IAAI,aAAa,MAAM,GAAG,EAAE,CAAC,IAAI,mBAAmB,IAAI,qBAAqB,IAAI,OAAO;AAC5H;AAEA,IAAM,YAAY,CAAC,eAAuB;AAExC,QAAM,YAAY,KAAK,MAAM,KAAK,OAAO,KAAK,MAAM,aAAa,EAAE;AACnE,SAAe,iBAAS,UAAU,SAAS,EAAE,GAAG,YAAY,GAAG;AACjE;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bessemer/cornerstone",
3
3
  "type": "module",
4
- "version": "0.5.97",
4
+ "version": "0.5.99",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "sideEffects": false,
@@ -1 +0,0 @@
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 DELETED
@@ -1,29 +0,0 @@
1
- // src/ulid.ts
2
- import { ulid } from "ulid";
3
- import Zod from "zod";
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);
14
- };
15
- var fromString = (value) => {
16
- return unpackResult(parseString(value));
17
- };
18
- var Schema = structuredTransform(Zod.string(), parseString);
19
- var generate = () => {
20
- return ulid();
21
- };
22
- export {
23
- Namespace,
24
- Schema,
25
- fromString,
26
- generate,
27
- parseString
28
- };
29
- //# sourceMappingURL=ulid.js.map
package/dist/ulid.js.map DELETED
@@ -1 +0,0 @@
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/uri.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import { TaggedType } from '@bessemer/cornerstone/types';
2
- export declare const encode: (uriComponent: UriComponent) => string;
3
- export declare const decode: (uriComponent: UriComponent) => string;
4
- export type UriString = TaggedType<string, 'UriString'>;
5
- export type UriComponent = string;
6
- export type UriScheme = string;
7
- export type UriAuthentication = {
8
- principal: string;
9
- password: string | null;
10
- };
11
- export type UriHost = {
12
- value: string;
13
- port: number | null;
14
- };
15
- export interface UriLocation {
16
- path: string;
17
- query: string | null;
18
- fragment: string | null;
19
- }
20
- export interface Uri {
21
- scheme: UriScheme | null;
22
- host: UriHost | null;
23
- authentication: UriAuthentication | null;
24
- location: UriLocation;
25
- }
26
- export declare const parse: (urlString: UriString) => Uri;
27
- export declare const emptyLocation: () => UriLocation;
28
- export type UriBuilder = {
29
- scheme?: string;
30
- host?: {
31
- value: string;
32
- port?: number;
33
- } | string;
34
- authentication?: {
35
- principal: string;
36
- password?: string;
37
- } | string;
38
- location?: {
39
- path: string;
40
- query?: string;
41
- fragment?: string;
42
- } | string;
43
- };
44
- export declare const build: (builder: UriBuilder) => Uri;
45
- export declare enum UriComponentType {
46
- Scheme = "Scheme",
47
- Host = "Host",
48
- Location = "Location"
49
- }
50
- export declare const format: (uri: Uri, format?: Array<UriComponentType>) => UriString;
51
- export declare const buildString: (builder: UriBuilder) => UriString;
52
- //# sourceMappingURL=uri.d.ts.map
package/dist/uri.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"uri.d.ts","sourceRoot":"","sources":["../src/uri.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAKxD,eAAO,MAAM,MAAM,GAAI,cAAc,YAAY,WAEhD,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,cAAc,YAAY,WAEhD,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AACvD,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,E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AK,CAAC,gBAAgB,CAAmC,KAAG,SAgCpG,CAAA;AAoBD,eAAO,MAAM,WAAW,GAAI,SAAS,UAAU,KAAG,SAEjD,CAAA"}
package/dist/uri.js DELETED
@@ -1,222 +0,0 @@
1
- // src/uri.ts
2
- import { isEmpty, isString, removeStart, splitFirst, startsWith } from "@bessemer/cornerstone/string";
3
- import { isNil, isPresent } from "@bessemer/cornerstone/object";
4
- import { contains } from "@bessemer/cornerstone/array";
5
- var encode = (uriComponent) => {
6
- return encodeURIComponent(uriComponent);
7
- };
8
- var decode = (uriComponent) => {
9
- return decodeURIComponent(uriComponent);
10
- };
11
- var parseSchemePart = (url) => {
12
- const schemeMatch = splitFirst(url, /(\/\/|:)/);
13
- if (isNil(schemeMatch.selection) || schemeMatch.separator === "//") {
14
- return [null, url];
15
- }
16
- if (isEmpty(schemeMatch.selection)) {
17
- return [null, schemeMatch.rest];
18
- } else {
19
- return [schemeMatch.selection, schemeMatch.rest];
20
- }
21
- };
22
- var parseAuthenticationPart = (url) => {
23
- let targetPart = url;
24
- const queryMatch = splitFirst(targetPart, "?");
25
- const fragmentMatch = splitFirst(targetPart, "#");
26
- if (isPresent(queryMatch.selection)) {
27
- targetPart = queryMatch.selection;
28
- } else if (isPresent(fragmentMatch.selection)) {
29
- targetPart = fragmentMatch.selection;
30
- }
31
- const { selection: authentication } = splitFirst(targetPart, "@");
32
- if (isNil(authentication)) {
33
- return [null, url];
34
- }
35
- const { rest } = splitFirst(url, "@");
36
- return [parseAuthentication(removeStart(authentication, "//")), "//" + rest];
37
- };
38
- var parseAuthentication = (authentication) => {
39
- const { selection: principal, rest: authenticationRest } = splitFirst(authentication, ":");
40
- if (isNil(principal)) {
41
- return { principal: authenticationRest, password: null };
42
- }
43
- if (isEmpty(principal)) {
44
- throw new Error(`Unable to parse Authentication: ${authentication}`);
45
- }
46
- return { principal, password: authenticationRest };
47
- };
48
- var parseHostPart = (url) => {
49
- if (startsWith(url, "?") || startsWith(url, "#")) {
50
- return [null, url];
51
- }
52
- let hostRequired = startsWith(url, "//");
53
- if (!hostRequired) {
54
- return [null, url];
55
- }
56
- url = removeStart(url, "//");
57
- const urlMatch = splitFirst(url, /[\/?#]/);
58
- let host = urlMatch.rest;
59
- let rest = "";
60
- if (isPresent(urlMatch.selection)) {
61
- host = urlMatch.selection;
62
- rest = urlMatch.separator + urlMatch.rest;
63
- }
64
- if (isEmpty(host)) {
65
- return [null, rest];
66
- }
67
- return [parseHost(host), rest];
68
- };
69
- var parseHost = (host) => {
70
- if (startsWith(host, "[")) {
71
- const ipMatch = splitFirst(host, "]");
72
- if (isPresent(ipMatch.selection)) {
73
- const portMatch = splitFirst(ipMatch.rest, ":");
74
- if (isPresent(portMatch.selection)) {
75
- if (isEmpty(portMatch.selection)) {
76
- return { value: ipMatch.selection + "]", port: Number(portMatch.rest) };
77
- }
78
- } else {
79
- return { value: ipMatch.selection + "]", port: null };
80
- }
81
- }
82
- }
83
- let hostMatch = splitFirst(host, ":");
84
- if (isNil(hostMatch.selection)) {
85
- return { value: hostMatch.rest, port: null };
86
- }
87
- if (isEmpty(hostMatch.selection)) {
88
- throw new Error(`Unable to parse Host: ${host}`);
89
- }
90
- const hostName = hostMatch.selection;
91
- return { value: hostName, port: Number(hostMatch.rest) };
92
- };
93
- var parseLocation = (url) => {
94
- const location = { path: "", query: null, fragment: null };
95
- const fragmentMatch = splitFirst(url, "#");
96
- if (isPresent(fragmentMatch.selection) && !isEmpty(fragmentMatch.rest)) {
97
- location.fragment = fragmentMatch.rest;
98
- }
99
- const queryMatch = splitFirst(fragmentMatch.selection ?? fragmentMatch.rest, "?");
100
- if (isPresent(queryMatch.selection) && !isEmpty(queryMatch.rest)) {
101
- location.query = queryMatch.rest;
102
- }
103
- location.path = queryMatch.selection ?? queryMatch.rest;
104
- return location;
105
- };
106
- var parse = (urlString) => {
107
- const [scheme, rest1] = parseSchemePart(urlString);
108
- const [authentication, rest2] = parseAuthenticationPart(rest1);
109
- const [host, rest3] = parseHostPart(rest2);
110
- const location = parseLocation(rest3);
111
- const url = { scheme, host, authentication, location };
112
- return url;
113
- };
114
- var emptyLocation = () => {
115
- return {
116
- path: "",
117
- query: null,
118
- fragment: null
119
- };
120
- };
121
- var build = (builder) => {
122
- const scheme = builder.scheme ?? null;
123
- let host = null;
124
- if (isPresent(builder.host)) {
125
- if (isString(builder.host)) {
126
- host = parseHost(builder.host);
127
- } else {
128
- host = {
129
- value: builder.host.value,
130
- port: builder.host.port ?? null
131
- };
132
- }
133
- }
134
- let authentication = null;
135
- if (isPresent(builder.authentication)) {
136
- if (isString(builder.authentication)) {
137
- authentication = parseAuthentication(builder.authentication);
138
- } else {
139
- authentication = {
140
- principal: builder.authentication.principal,
141
- password: builder.authentication.password ?? null
142
- };
143
- }
144
- }
145
- let location = emptyLocation();
146
- if (isPresent(builder.location)) {
147
- if (isString(builder.location)) {
148
- location = parseLocation(builder.location);
149
- } else {
150
- location = {
151
- path: builder.location.path,
152
- query: builder.location.query ?? null,
153
- fragment: builder.location.fragment ?? null
154
- };
155
- }
156
- }
157
- return {
158
- scheme,
159
- host,
160
- authentication,
161
- location
162
- };
163
- };
164
- var UriComponentType = /* @__PURE__ */ ((UriComponentType2) => {
165
- UriComponentType2["Scheme"] = "Scheme";
166
- UriComponentType2["Host"] = "Host";
167
- UriComponentType2["Location"] = "Location";
168
- return UriComponentType2;
169
- })(UriComponentType || {});
170
- var format = (uri, format2 = Object.values(UriComponentType)) => {
171
- let urlString = "";
172
- if (isPresent(uri.scheme) && contains(format2, "Scheme" /* Scheme */)) {
173
- urlString = urlString + uri.scheme;
174
- }
175
- if (isPresent(uri.host) && contains(format2, "Host" /* Host */)) {
176
- if (isPresent(uri.scheme)) {
177
- urlString = urlString + "://";
178
- }
179
- if (isPresent(uri.authentication)) {
180
- urlString = urlString + uri.authentication.principal;
181
- if (isPresent(uri.authentication.password)) {
182
- urlString = urlString + ":" + uri.authentication.password;
183
- }
184
- urlString = urlString + "@";
185
- }
186
- urlString = urlString + uri.host.value;
187
- if (isPresent(uri.host.port)) {
188
- urlString = urlString + ":" + uri.host.port;
189
- }
190
- }
191
- if (contains(format2, "Location" /* Location */)) {
192
- urlString = urlString + formatLocation(uri.location, format2);
193
- }
194
- return urlString;
195
- };
196
- var formatLocation = (location, format2) => {
197
- let urlString = "";
198
- if (!isEmpty(location.path)) {
199
- urlString = urlString + location.path;
200
- }
201
- if (!isEmpty(location.query)) {
202
- urlString = urlString + "?" + location.query;
203
- }
204
- if (!isEmpty(location.fragment)) {
205
- urlString = urlString + "#" + encode(location.fragment);
206
- }
207
- return urlString;
208
- };
209
- var buildString = (builder) => {
210
- return format(build(builder));
211
- };
212
- export {
213
- UriComponentType,
214
- build,
215
- buildString,
216
- decode,
217
- emptyLocation,
218
- encode,
219
- format,
220
- parse
221
- };
222
- //# sourceMappingURL=uri.js.map
package/dist/uri.js.map DELETED
@@ -1 +0,0 @@
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,aAAa;AACjB,QAAM,aAAa,WAAW,YAAY,GAAG;AAC7C,QAAM,gBAAgB,WAAW,YAAY,GAAG;AAChD,MAAI,UAAU,WAAW,SAAS,GAAG;AACnC,iBAAa,WAAW;AAAA,EAC1B,WAAW,UAAU,cAAc,SAAS,GAAG;AAC7C,iBAAa,cAAc;AAAA,EAC7B;AAEA,QAAM,EAAE,WAAW,eAAe,IAAI,WAAW,YAAY,GAAG;AAGhE,MAAI,MAAM,cAAc,GAAG;AACzB,WAAO,CAAC,MAAM,GAAG;AAAA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AM,OAAO,CAAC;AAC9B;","names":["UriComponentType","format"]}
package/dist/url.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { Uris } from '@bessemer/cornerstone';
2
- import { Dictionary } from '@bessemer/cornerstone/types';
3
- import { Uri, UriBuilder, UriComponent, UriLocation, UriString } from '@bessemer/cornerstone/uri';
4
- export declare const encode: (uriComponent: UriComponent) => string;
5
- export declare const decode: (uriComponent: UriComponent) => string;
6
- export interface UrlLocation extends UriLocation {
7
- pathSegments: Array<string>;
8
- parameters: Dictionary<string | Array<string>>;
9
- }
10
- export interface Url extends Uri {
11
- location: UrlLocation;
12
- }
13
- export type UrlLike = Url | UriString;
14
- export declare const parse: (urlString: UriString, normalize?: boolean) => Url;
15
- export declare const format: (uri: Uri, format?: Array<Uris.UriComponentType>) => UriString;
16
- export type UrlBuilder = UriBuilder & {
17
- location?: {
18
- parameters?: Dictionary<string | Array<string>>;
19
- };
20
- };
21
- export declare const build: (builder: UrlBuilder) => Url;
22
- export declare const buildString: (builder: UrlBuilder) => UriString;
23
- export declare const reify: (blah: UrlLike) => Url;
24
- export declare const getParameter: (url: UrlLike, name: string) => string | undefined;
25
- export declare const getJsonParameter: <T>(url: UrlLike, name: string) => T | undefined;
26
- //# sourceMappingURL=url.d.ts.map
package/dist/url.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAEjG,eAAO,MAAM,MAAM,wCAAc,CAAA;AAEjC,eAAO,MAAM,MAAM,wCAAc,CAAA;AAEjC,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC3B,UAAU,EAAE,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;CAC/C;AAED,MAAM,WAAW,GAAI,SAAQ,GAAG;IAC9B,QAAQ,EAAE,WAAW,CAAA;CACtB;AAED,MAAM,MAAM,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;AA8CrC,eAAO,MAAM,KAAK,GAAI,WAAW,SAAS,EAAE,YAAW,OAAc,KAAG,GAkBvE,CAAA;AAED,eAAO,MAAM,MAAM,gEAAc,CAAA;AAuBjC,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG;IACpC,QAAQ,CAAC,EAAE;QACT,UAAU,CAAC,EAAE,UAAU,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;KAChD,CAAA;CACF,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,SAAS,UAAU,KAAG,GAa3C,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,SAAS,UAAU,KAAG,SAEjD,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,MAAM,OAAO,KAAG,GAMrC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,OAAO,EAAE,MAAM,MAAM,KAAG,MAAM,GAAG,SAWlE,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,KAAG,CAAC,GAAG,SAGpE,CAAA"}
package/dist/url.js DELETED
@@ -1,120 +0,0 @@
1
- // src/url.ts
2
- import { Arrays, Objects, Strings, Uris } from "@bessemer/cornerstone";
3
- var encode = Uris.encode;
4
- var decode = Uris.decode;
5
- var augmentUriLocation = (uriLocation, normalize) => {
6
- const pathSegments = [];
7
- const parameters = {};
8
- if (!Strings.isBlank(uriLocation.path)) {
9
- Strings.removeStart(uriLocation.path, "/").split("/").forEach((urlPathPart) => {
10
- if (!Strings.isBlank(urlPathPart) || !normalize) {
11
- pathSegments.push(decode(urlPathPart));
12
- }
13
- });
14
- }
15
- if (Objects.isPresent(uriLocation.query)) {
16
- uriLocation.query.split("&").forEach((parameterPair) => {
17
- let splitParameters = parameterPair.split("=");
18
- if (!Strings.isBlank(Arrays.first(splitParameters))) {
19
- let key = decode(splitParameters[0]);
20
- let value = "";
21
- if (splitParameters.length === 2) {
22
- value = splitParameters[1];
23
- }
24
- if (Objects.isNil(parameters[key])) {
25
- parameters[key] = decode(value);
26
- } else if (!Array.isArray(parameters[key])) {
27
- let paramList = [parameters[key]];
28
- paramList.push(decode(value));
29
- parameters[key] = paramList;
30
- } else {
31
- parameters[key].push(decode(value));
32
- }
33
- }
34
- });
35
- }
36
- return {
37
- ...uriLocation,
38
- pathSegments,
39
- parameters
40
- };
41
- };
42
- var parse = (urlString, normalize = true) => {
43
- const uri = Uris.parse(urlString);
44
- const location = augmentUriLocation(uri.location, normalize);
45
- if (normalize) {
46
- if (!Arrays.isEmpty(location.pathSegments)) {
47
- location.path = (Strings.startsWith(location.path, "/") ? "/" : "") + formatPathSegments(location.pathSegments);
48
- } else {
49
- location.path = "";
50
- }
51
- location.query = formatQueryParameters(location.parameters);
52
- }
53
- return {
54
- ...uri,
55
- location
56
- };
57
- };
58
- var format = Uris.format;
59
- var formatPathSegments = (pathSegments) => {
60
- return pathSegments.map((it) => encode(it)).join("/");
61
- };
62
- var formatQueryParameters = (parameters) => {
63
- const parameterEntries = Object.entries(parameters);
64
- if (Arrays.isEmpty(parameterEntries)) {
65
- return null;
66
- }
67
- return Object.entries(parameters).flatMap(([key, value]) => {
68
- if (Array.isArray(value)) {
69
- return value.map((it) => `${encode(key)}=${encode(it)}`);
70
- } else {
71
- return [`${encode(key)}=${encode(value)}`];
72
- }
73
- }).join("&");
74
- };
75
- var build = (builder) => {
76
- const uri = Uris.build(builder);
77
- if (Objects.isPresent(builder.location?.parameters)) {
78
- uri.location.query = formatQueryParameters(builder.location.parameters);
79
- }
80
- const urlLocation = augmentUriLocation(uri.location, false);
81
- return {
82
- ...uri,
83
- location: urlLocation
84
- };
85
- };
86
- var buildString = (builder) => {
87
- return format(build(builder));
88
- };
89
- var reify = (blah) => {
90
- if (!Strings.isString(blah)) {
91
- return blah;
92
- }
93
- return parse(blah);
94
- };
95
- var getParameter = (url, name) => {
96
- const parameter = reify(url).location.parameters[name];
97
- if (Objects.isNil(parameter)) {
98
- return void 0;
99
- }
100
- if (Array.isArray(parameter)) {
101
- throw new Error(`Expected a single parameter value but found multiple for parameter: ${name}`);
102
- }
103
- return parameter;
104
- };
105
- var getJsonParameter = (url, name) => {
106
- const value = getParameter(url, name);
107
- return Objects.isPresent(value) ? JSON.parse(value) : void 0;
108
- };
109
- export {
110
- build,
111
- buildString,
112
- decode,
113
- encode,
114
- format,
115
- getJsonParameter,
116
- getParameter,
117
- parse,
118
- reify
119
- };
120
- //# sourceMappingURL=url.js.map