@bessemer/cornerstone 0.5.1 → 0.5.4

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 (282) hide show
  1. package/dist/array.d.ts +57 -0
  2. package/dist/array.d.ts.map +1 -0
  3. package/dist/array.js +137 -0
  4. package/dist/array.js.map +1 -0
  5. package/dist/async.d.ts +59 -0
  6. package/dist/async.d.ts.map +1 -0
  7. package/dist/async.js +62 -0
  8. package/dist/async.js.map +1 -0
  9. package/dist/cache.d.ts +106 -0
  10. package/dist/cache.d.ts.map +1 -0
  11. package/dist/cache.js +112 -0
  12. package/dist/cache.js.map +1 -0
  13. package/dist/combinable.d.ts +16 -0
  14. package/dist/combinable.d.ts.map +1 -0
  15. package/dist/combinable.js +31 -0
  16. package/dist/combinable.js.map +1 -0
  17. package/dist/comparator.d.ts +9 -0
  18. package/dist/comparator.d.ts.map +1 -0
  19. package/dist/comparator.js +76 -0
  20. package/dist/comparator.js.map +1 -0
  21. package/dist/content.d.ts +68 -0
  22. package/dist/content.d.ts.map +1 -0
  23. package/dist/content.js +79 -0
  24. package/dist/content.js.map +1 -0
  25. package/dist/context.d.ts +7 -0
  26. package/dist/context.d.ts.map +1 -0
  27. package/dist/context.js +1 -0
  28. package/dist/context.js.map +1 -0
  29. package/dist/crypto.d.ts +3 -0
  30. package/dist/crypto.d.ts.map +1 -0
  31. package/dist/crypto.js +15 -0
  32. package/dist/crypto.js.map +1 -0
  33. package/dist/date.d.ts +10 -0
  34. package/dist/date.d.ts.map +1 -0
  35. package/dist/date.js +24 -0
  36. package/dist/date.js.map +1 -0
  37. package/dist/duration.d.ts +39 -0
  38. package/dist/duration.d.ts.map +1 -0
  39. package/dist/duration.js +52 -0
  40. package/dist/duration.js.map +1 -0
  41. package/dist/either.d.ts +20 -0
  42. package/dist/either.d.ts.map +1 -0
  43. package/dist/either.js +25 -0
  44. package/dist/either.js.map +1 -0
  45. package/dist/entry.d.ts +7 -0
  46. package/dist/entry.d.ts.map +1 -0
  47. package/dist/entry.js +24 -0
  48. package/dist/entry.js.map +1 -0
  49. package/dist/equalitor.d.ts +5 -0
  50. package/dist/equalitor.d.ts.map +1 -0
  51. package/dist/equalitor.js +10 -0
  52. package/dist/equalitor.js.map +1 -0
  53. package/dist/error-event.d.ts +34 -0
  54. package/dist/error-event.d.ts.map +1 -0
  55. package/dist/error-event.js +91 -0
  56. package/dist/error-event.js.map +1 -0
  57. package/dist/error.d.ts +3 -0
  58. package/dist/error.d.ts.map +1 -0
  59. package/dist/error.js +18 -0
  60. package/dist/error.js.map +1 -0
  61. package/dist/expression/array-expression.d.ts +14 -0
  62. package/dist/expression/array-expression.d.ts.map +1 -0
  63. package/dist/expression/array-expression.js +32 -0
  64. package/dist/expression/array-expression.js.map +1 -0
  65. package/dist/expression/expression-evaluator.d.ts +8 -0
  66. package/dist/expression/expression-evaluator.d.ts.map +1 -0
  67. package/dist/expression/expression-evaluator.js +31 -0
  68. package/dist/expression/expression-evaluator.js.map +1 -0
  69. package/dist/expression/expression.d.ts +54 -0
  70. package/dist/expression/expression.d.ts.map +1 -0
  71. package/dist/expression/expression.js +173 -0
  72. package/dist/expression/expression.js.map +1 -0
  73. package/dist/expression/internal.d.ts +10 -0
  74. package/dist/expression/internal.d.ts.map +1 -0
  75. package/dist/expression/internal.js +28 -0
  76. package/dist/expression/internal.js.map +1 -0
  77. package/dist/expression/numeric-expression.d.ts +79 -0
  78. package/dist/expression/numeric-expression.d.ts.map +1 -0
  79. package/dist/expression/numeric-expression.js +177 -0
  80. package/dist/expression/numeric-expression.js.map +1 -0
  81. package/dist/expression/string-expression.d.ts +24 -0
  82. package/dist/expression/string-expression.d.ts.map +1 -0
  83. package/dist/expression/string-expression.js +41 -0
  84. package/dist/expression/string-expression.js.map +1 -0
  85. package/dist/expression.d.ts +35 -0
  86. package/dist/expression.d.ts.map +1 -0
  87. package/dist/expression.js +12 -0
  88. package/dist/expression.js.map +1 -0
  89. package/dist/function.d.ts +2 -0
  90. package/dist/function.d.ts.map +1 -0
  91. package/dist/function.js +7 -0
  92. package/dist/function.js.map +1 -0
  93. package/dist/glob.d.ts +8 -0
  94. package/dist/glob.d.ts.map +1 -0
  95. package/dist/glob.js +20 -0
  96. package/dist/glob.js.map +1 -0
  97. package/dist/global-variable.d.ts +7 -0
  98. package/dist/global-variable.d.ts.map +1 -0
  99. package/dist/global-variable.js +34 -0
  100. package/dist/global-variable.js.map +1 -0
  101. package/dist/hash.d.ts +11 -0
  102. package/dist/hash.d.ts.map +1 -0
  103. package/dist/hash.js +30 -0
  104. package/dist/hash.js.map +1 -0
  105. package/dist/hex-code.d.ts +5 -0
  106. package/dist/hex-code.d.ts.map +1 -0
  107. package/dist/hex-code.js +7 -0
  108. package/dist/hex-code.js.map +1 -0
  109. package/dist/index.d.ts +41 -0
  110. package/dist/index.d.ts.map +1 -0
  111. package/dist/index.js +82 -0
  112. package/dist/index.js.map +1 -0
  113. package/dist/lazy.d.ts +3 -0
  114. package/dist/lazy.d.ts.map +1 -0
  115. package/dist/lazy.js +13 -0
  116. package/dist/lazy.js.map +1 -0
  117. package/dist/logger.d.ts +30 -0
  118. package/dist/logger.d.ts.map +1 -0
  119. package/dist/logger.js +124 -0
  120. package/dist/logger.js.map +1 -0
  121. package/dist/math.d.ts +22 -0
  122. package/dist/math.d.ts.map +1 -0
  123. package/dist/math.js +123 -0
  124. package/dist/math.js.map +1 -0
  125. package/dist/misc.d.ts +3 -0
  126. package/dist/misc.d.ts.map +1 -0
  127. package/dist/misc.js +21 -0
  128. package/dist/misc.js.map +1 -0
  129. package/dist/object.d.ts +62 -0
  130. package/dist/object.d.ts.map +1 -0
  131. package/dist/object.js +170 -0
  132. package/dist/object.js.map +1 -0
  133. package/dist/patch.d.ts +41 -0
  134. package/dist/patch.d.ts.map +1 -0
  135. package/dist/patch.js +87 -0
  136. package/dist/patch.js.map +1 -0
  137. package/dist/precondition.d.ts +8 -0
  138. package/dist/precondition.d.ts.map +1 -0
  139. package/dist/precondition.js +27 -0
  140. package/dist/precondition.js.map +1 -0
  141. package/dist/promise.d.ts +8 -0
  142. package/dist/promise.d.ts.map +1 -0
  143. package/dist/promise.js +18 -0
  144. package/dist/promise.js.map +1 -0
  145. package/dist/property.d.ts +11 -0
  146. package/dist/property.d.ts.map +1 -0
  147. package/dist/property.js +21 -0
  148. package/dist/property.js.map +1 -0
  149. package/dist/reference.d.ts +22 -0
  150. package/dist/reference.d.ts.map +1 -0
  151. package/dist/reference.js +51 -0
  152. package/dist/reference.js.map +1 -0
  153. package/dist/resource.d.ts +13 -0
  154. package/dist/resource.d.ts.map +1 -0
  155. package/dist/resource.js +27 -0
  156. package/dist/resource.js.map +1 -0
  157. package/dist/result.d.ts +18 -0
  158. package/dist/result.d.ts.map +1 -0
  159. package/dist/result.js +50 -0
  160. package/dist/result.js.map +1 -0
  161. package/dist/retry.d.ts +18 -0
  162. package/dist/retry.d.ts.map +1 -0
  163. package/dist/retry.js +51 -0
  164. package/dist/retry.js.map +1 -0
  165. package/dist/rich-text.d.ts +17 -0
  166. package/dist/rich-text.d.ts.map +1 -0
  167. package/dist/rich-text.js +9 -0
  168. package/dist/rich-text.js.map +1 -0
  169. package/dist/set.d.ts +5 -0
  170. package/dist/set.d.ts.map +1 -0
  171. package/dist/set.js +44 -0
  172. package/dist/set.js.map +1 -0
  173. package/dist/signature.d.ts +9 -0
  174. package/dist/signature.d.ts.map +1 -0
  175. package/dist/signature.js +20 -0
  176. package/dist/signature.js.map +1 -0
  177. package/dist/store.d.ts +40 -0
  178. package/dist/store.d.ts.map +1 -0
  179. package/dist/store.js +50 -0
  180. package/dist/store.js.map +1 -0
  181. package/dist/string.d.ts +40 -0
  182. package/dist/string.d.ts.map +1 -0
  183. package/dist/string.js +154 -0
  184. package/dist/string.js.map +1 -0
  185. package/dist/tag.d.ts +24 -0
  186. package/dist/tag.d.ts.map +1 -0
  187. package/dist/tag.js +50 -0
  188. package/dist/tag.js.map +1 -0
  189. package/dist/types.d.ts +16 -0
  190. package/dist/types.d.ts.map +1 -0
  191. package/dist/types.js +1 -0
  192. package/dist/types.js.map +1 -0
  193. package/dist/ulid.d.ts +8 -0
  194. package/dist/ulid.d.ts.map +1 -0
  195. package/dist/ulid.js +28 -0
  196. package/dist/ulid.js.map +1 -0
  197. package/dist/unit.d.ts +4 -0
  198. package/dist/unit.d.ts.map +1 -0
  199. package/dist/unit.js +6 -0
  200. package/dist/unit.js.map +1 -0
  201. package/dist/uri.d.ts +47 -0
  202. package/dist/uri.d.ts.map +1 -0
  203. package/dist/uri.js +211 -0
  204. package/dist/uri.js.map +1 -0
  205. package/dist/url.d.ts +25 -0
  206. package/dist/url.d.ts.map +1 -0
  207. package/dist/url.js +120 -0
  208. package/dist/url.js.map +1 -0
  209. package/dist/uuid.d.ts +8 -0
  210. package/dist/uuid.d.ts.map +1 -0
  211. package/dist/uuid.js +35 -0
  212. package/dist/uuid.js.map +1 -0
  213. package/dist/zod.d.ts +17 -0
  214. package/dist/zod.d.ts.map +1 -0
  215. package/dist/zod.js +31 -0
  216. package/dist/zod.js.map +1 -0
  217. package/package.json +5 -3
  218. package/jest.config.js +0 -3
  219. package/src/array.ts +0 -142
  220. package/src/async.ts +0 -114
  221. package/src/cache.ts +0 -236
  222. package/src/combinable.ts +0 -40
  223. package/src/comparator.ts +0 -78
  224. package/src/content.ts +0 -138
  225. package/src/context.ts +0 -6
  226. package/src/crypto.ts +0 -11
  227. package/src/date.ts +0 -18
  228. package/src/duration.ts +0 -57
  229. package/src/either.ts +0 -29
  230. package/src/entry.ts +0 -21
  231. package/src/equalitor.ts +0 -12
  232. package/src/error-event.ts +0 -126
  233. package/src/error.ts +0 -16
  234. package/src/expression/array-expression.ts +0 -29
  235. package/src/expression/expression-evaluator.ts +0 -34
  236. package/src/expression/expression.ts +0 -188
  237. package/src/expression/internal.ts +0 -34
  238. package/src/expression/numeric-expression.ts +0 -182
  239. package/src/expression/string-expression.ts +0 -38
  240. package/src/expression.ts +0 -48
  241. package/src/function.ts +0 -3
  242. package/src/glob.ts +0 -19
  243. package/src/global-variable.ts +0 -40
  244. package/src/hash.ts +0 -28
  245. package/src/hex-code.ts +0 -6
  246. package/src/index.ts +0 -82
  247. package/src/lazy.ts +0 -11
  248. package/src/logger.ts +0 -144
  249. package/src/math.ts +0 -132
  250. package/src/misc.ts +0 -22
  251. package/src/object.ts +0 -236
  252. package/src/patch.ts +0 -128
  253. package/src/precondition.ts +0 -25
  254. package/src/promise.ts +0 -16
  255. package/src/property.ts +0 -29
  256. package/src/reference.ts +0 -68
  257. package/src/resource.ts +0 -32
  258. package/src/result.ts +0 -66
  259. package/src/retry.ts +0 -70
  260. package/src/rich-text.ts +0 -24
  261. package/src/set.ts +0 -46
  262. package/src/signature.ts +0 -20
  263. package/src/store.ts +0 -91
  264. package/src/string.ts +0 -173
  265. package/src/tag.ts +0 -68
  266. package/src/types.ts +0 -21
  267. package/src/ulid.ts +0 -28
  268. package/src/unit.ts +0 -4
  269. package/src/uri.ts +0 -321
  270. package/src/url.ts +0 -155
  271. package/src/uuid.ts +0 -37
  272. package/src/zod.ts +0 -24
  273. package/test/comparator.test.ts +0 -1
  274. package/test/expression.test.ts +0 -12
  275. package/test/object.test.ts +0 -104
  276. package/test/patch.test.ts +0 -170
  277. package/test/set.test.ts +0 -20
  278. package/test/string.test.ts +0 -22
  279. package/test/uri.test.ts +0 -111
  280. package/test/url.test.ts +0 -174
  281. package/tsconfig.build.json +0 -13
  282. package/tsup.config.ts +0 -4
@@ -0,0 +1,31 @@
1
+ // src/combinable.ts
2
+ import { Arrays, Sets } from "@bessemer/cornerstone";
3
+ var CombinabilityType = /* @__PURE__ */ ((CombinabilityType2) => {
4
+ CombinabilityType2["Stackable"] = "Stackable";
5
+ CombinabilityType2["Singleton"] = "Singleton";
6
+ CombinabilityType2["Totalitarian"] = "Totalitarian";
7
+ return CombinabilityType2;
8
+ })(CombinabilityType || {});
9
+ var DefaultCombinability = {
10
+ type: "Stackable" /* Stackable */,
11
+ class: null
12
+ };
13
+ var combinations = (combinables) => {
14
+ const classMap = Arrays.groupBy(combinables, (it) => it.combinability.class);
15
+ const classCombinations = Object.entries(classMap).map(([_, values]) => {
16
+ const totalitarianCombinations = values.filter((it) => it.combinability.type === "Totalitarian" /* Totalitarian */).map((it) => [it]);
17
+ if (!Arrays.isEmpty(totalitarianCombinations)) {
18
+ return totalitarianCombinations;
19
+ }
20
+ const singletonCombinations = values.filter((it) => it.combinability.type === "Singleton" /* Singleton */).map((it) => [it]);
21
+ const stackableCombination = values.filter((it) => it.combinability.type === "Stackable" /* Stackable */);
22
+ return [stackableCombination, ...singletonCombinations];
23
+ });
24
+ return Sets.cartesianProduct(...classCombinations).flatMap((it) => it);
25
+ };
26
+ export {
27
+ CombinabilityType,
28
+ DefaultCombinability,
29
+ combinations
30
+ };
31
+ //# sourceMappingURL=combinable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/combinable.ts"],"sourcesContent":["import { Arrays, Sets } from '@bessemer/cornerstone'\n\nexport interface Combinable {\n combinability: Combinability\n}\n\nexport type Combinability = {\n type: CombinabilityType\n class: CombinabilityClass\n}\n\nexport enum CombinabilityType {\n Stackable = 'Stackable',\n Singleton = 'Singleton',\n Totalitarian = 'Totalitarian',\n}\n\nexport type CombinabilityClass = string | null\n\nexport const DefaultCombinability: Combinability = {\n type: CombinabilityType.Stackable,\n class: null,\n}\n\nexport const combinations = <T extends Combinable>(combinables: Array<T>): Array<Array<T>> => {\n const classMap = Arrays.groupBy(combinables, (it) => it.combinability.class)\n\n const classCombinations: Array<Array<Array<T>>> = Object.entries(classMap).map(([_, values]) => {\n const totalitarianCombinations = values.filter((it) => it.combinability.type === CombinabilityType.Totalitarian).map((it) => [it])\n if (!Arrays.isEmpty(totalitarianCombinations)) {\n return totalitarianCombinations\n }\n\n const singletonCombinations = values.filter((it) => it.combinability.type === CombinabilityType.Singleton).map((it) => [it])\n const stackableCombination = values.filter((it) => it.combinability.type === CombinabilityType.Stackable)\n return [stackableCombination, ...singletonCombinations]\n })\n\n return Sets.cartesianProduct(...classCombinations).flatMap((it) => it)\n}\n"],"mappings":";AAAA,SAAS,QAAQ,YAAY;AAWtB,IAAK,oBAAL,kBAAKA,uBAAL;AACL,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,kBAAe;AAHL,SAAAA;AAAA,GAAA;AAQL,IAAM,uBAAsC;AAAA,EACjD,MAAM;AAAA,EACN,OAAO;AACT;AAEO,IAAM,eAAe,CAAuB,gBAA2C;AAC5F,QAAM,WAAW,OAAO,QAAQ,aAAa,CAAC,OAAO,GAAG,cAAc,KAAK;AAE3E,QAAM,oBAA4C,OAAO,QAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,MAAM;AAC9F,UAAM,2BAA2B,OAAO,OAAO,CAAC,OAAO,GAAG,cAAc,SAAS,iCAA8B,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AACjI,QAAI,CAAC,OAAO,QAAQ,wBAAwB,GAAG;AAC7C,aAAO;AAAA,IACT;AAEA,UAAM,wBAAwB,OAAO,OAAO,CAAC,OAAO,GAAG,cAAc,SAAS,2BAA2B,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AAC3H,UAAM,uBAAuB,OAAO,OAAO,CAAC,OAAO,GAAG,cAAc,SAAS,2BAA2B;AACxG,WAAO,CAAC,sBAAsB,GAAG,qBAAqB;AAAA,EACxD,CAAC;AAED,SAAO,KAAK,iBAAiB,GAAG,iBAAiB,EAAE,QAAQ,CAAC,OAAO,EAAE;AACvE;","names":["CombinabilityType"]}
@@ -0,0 +1,9 @@
1
+ export type Comparator<T> = (first: T, second: T) => number;
2
+ export declare const aggregate: <T>(comparators: Array<Comparator<T>>) => Comparator<T>;
3
+ export declare const compareBy: <T, N>(mapper: (element: T) => N, comparator: Comparator<N>) => Comparator<T>;
4
+ export declare const reverse: <T>(comparator: Comparator<T>) => Comparator<T>;
5
+ export declare const trueFirst: () => Comparator<boolean>;
6
+ export declare const natural: () => Comparator<string | number | null>;
7
+ export declare function matchedFirst<T>(target: T): Comparator<T | null>;
8
+ export declare const nullsLast: <T>() => Comparator<T>;
9
+ //# sourceMappingURL=comparator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../src/comparator.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,MAAM,CAAA;AAE3D,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,aAAa,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAe5E,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,YAAY,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAElG,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,YAAY,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAElE,CAAA;AAED,eAAO,MAAM,SAAS,QAAO,UAAU,CAAC,OAAO,CAE9C,CAAA;AAED,eAAO,MAAM,OAAO,QAAO,UAAU,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAgB3D,CAAA;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAa/D;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,OAAK,UAAU,CAAC,CAAC,CAW3C,CAAA"}
@@ -0,0 +1,76 @@
1
+ // src/comparator.ts
2
+ import { Maths, Strings } from "@bessemer/cornerstone";
3
+ var aggregate = (comparators) => {
4
+ return (first, second) => {
5
+ if (first === second) {
6
+ return 0;
7
+ }
8
+ for (const comparator of comparators) {
9
+ const result = comparator(first, second);
10
+ if (result !== 0) {
11
+ return result;
12
+ }
13
+ }
14
+ return 0;
15
+ };
16
+ };
17
+ var compareBy = (mapper, comparator) => {
18
+ return (first, second) => comparator(mapper(first), mapper(second));
19
+ };
20
+ var reverse = (comparator) => {
21
+ return (first, second) => -comparator(first, second);
22
+ };
23
+ var trueFirst = () => {
24
+ return (first, second) => natural()(first ? 1 : 0, second ? 1 : 0);
25
+ };
26
+ var natural = () => {
27
+ return aggregate([
28
+ nullsLast(),
29
+ (first, second) => {
30
+ if (Strings.isString(first) && Strings.isString(second)) {
31
+ return first.localeCompare(second);
32
+ } else if (Maths.isNumber(first) && Maths.isNumber(second)) {
33
+ return first - second;
34
+ } else if (Maths.isNumber(first)) {
35
+ return -1;
36
+ } else {
37
+ return 1;
38
+ }
39
+ }
40
+ ]);
41
+ };
42
+ function matchedFirst(target) {
43
+ return aggregate([
44
+ nullsLast(),
45
+ (first, second) => {
46
+ if (first === target && second !== target) {
47
+ return -1;
48
+ } else if (first !== target && second === target) {
49
+ return 1;
50
+ } else {
51
+ return 0;
52
+ }
53
+ }
54
+ ]);
55
+ }
56
+ var nullsLast = () => {
57
+ return (first, second) => {
58
+ if (first === null) {
59
+ return 1;
60
+ }
61
+ if (second === null) {
62
+ return -1;
63
+ }
64
+ return 0;
65
+ };
66
+ };
67
+ export {
68
+ aggregate,
69
+ compareBy,
70
+ matchedFirst,
71
+ natural,
72
+ nullsLast,
73
+ reverse,
74
+ trueFirst
75
+ };
76
+ //# sourceMappingURL=comparator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/comparator.ts"],"sourcesContent":["import { Maths, Strings } from '@bessemer/cornerstone'\n\nexport type Comparator<T> = (first: T, second: T) => number\n\nexport const aggregate = <T>(comparators: Array<Comparator<T>>): Comparator<T> => {\n return (first, second) => {\n if (first === second) {\n return 0\n }\n\n for (const comparator of comparators) {\n const result = comparator(first, second)\n if (result !== 0) {\n return result\n }\n }\n\n return 0\n }\n}\n\nexport const compareBy = <T, N>(mapper: (element: T) => N, comparator: Comparator<N>): Comparator<T> => {\n return (first, second) => comparator(mapper(first), mapper(second))\n}\n\nexport const reverse = <T>(comparator: Comparator<T>): Comparator<T> => {\n return (first, second) => -comparator(first, second)\n}\n\nexport const trueFirst = (): Comparator<boolean> => {\n return (first, second) => natural()(first ? 1 : 0, second ? 1 : 0)\n}\n\nexport const natural = (): Comparator<string | number | null> => {\n // Comparing by nulls first allows us to assume the elements are non-null for future comparisons\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (Strings.isString(first) && Strings.isString(second)) {\n return first.localeCompare(second)\n } else if (Maths.isNumber(first) && Maths.isNumber(second)) {\n return first! - second!\n } else if (Maths.isNumber(first)) {\n return -1\n } else {\n return 1\n }\n },\n ])\n}\n\nexport function matchedFirst<T>(target: T): Comparator<T | null> {\n return aggregate([\n nullsLast(),\n (first, second) => {\n if (first === target && second !== target) {\n return -1\n } else if (first !== target && second === target) {\n return 1\n } else {\n return 0\n }\n },\n ])\n}\n\nexport const nullsLast = <T>(): Comparator<T> => {\n return (first, second) => {\n if (first === null) {\n return 1\n }\n if (second === null) {\n return -1\n }\n\n return 0\n }\n}\n"],"mappings":";AAAA,SAAS,OAAO,eAAe;AAIxB,IAAM,YAAY,CAAI,gBAAqD;AAChF,SAAO,CAAC,OAAO,WAAW;AACxB,QAAI,UAAU,QAAQ;AACpB,aAAO;AAAA,IACT;AAEA,eAAW,cAAc,aAAa;AACpC,YAAM,SAAS,WAAW,OAAO,MAAM;AACvC,UAAI,WAAW,GAAG;AAChB,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,IAAM,YAAY,CAAO,QAA2B,eAA6C;AACtG,SAAO,CAAC,OAAO,WAAW,WAAW,OAAO,KAAK,GAAG,OAAO,MAAM,CAAC;AACpE;AAEO,IAAM,UAAU,CAAI,eAA6C;AACtE,SAAO,CAAC,OAAO,WAAW,CAAC,WAAW,OAAO,MAAM;AACrD;AAEO,IAAM,YAAY,MAA2B;AAClD,SAAO,CAAC,OAAO,WAAW,QAAQ,EAAE,QAAQ,IAAI,GAAG,SAAS,IAAI,CAAC;AACnE;AAEO,IAAM,UAAU,MAA0C;AAE/D,SAAO,UAAU;AAAA,IACf,UAAU;AAAA,IACV,CAAC,OAAO,WAAW;AACjB,UAAI,QAAQ,SAAS,KAAK,KAAK,QAAQ,SAAS,MAAM,GAAG;AACvD,eAAO,MAAM,cAAc,MAAM;AAAA,MACnC,WAAW,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,MAAM,GAAG;AAC1D,eAAO,QAAS;AAAA,MAClB,WAAW,MAAM,SAAS,KAAK,GAAG;AAChC,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,SAAS,aAAgB,QAAiC;AAC/D,SAAO,UAAU;AAAA,IACf,UAAU;AAAA,IACV,CAAC,OAAO,WAAW;AACjB,UAAI,UAAU,UAAU,WAAW,QAAQ;AACzC,eAAO;AAAA,MACT,WAAW,UAAU,UAAU,WAAW,QAAQ;AAChD,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,IAAM,YAAY,MAAwB;AAC/C,SAAO,CAAC,OAAO,WAAW;AACxB,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,QAAI,WAAW,MAAM;AACnB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,68 @@
1
+ import { Referencable, Reference, ReferenceType } from '@bessemer/cornerstone/reference';
2
+ import { NominalType } from '@bessemer/cornerstone/types';
3
+ import { AbstractApplicationContext } from '@bessemer/cornerstone/context';
4
+ import { RichTextJson } from '@bessemer/cornerstone/rich-text';
5
+ import { Tag } from '@bessemer/cornerstone/tag';
6
+ import { ZodType } from 'zod';
7
+ export type ContentSector = NominalType<string, 'ContentSector'>;
8
+ export declare const ContentSectorSchema: ZodType<ContentSector>;
9
+ export type ContentKey = NominalType<string, 'ContentKey'>;
10
+ export declare const ContentKeySchema: ZodType<ContentKey>;
11
+ export type ContentType<Data = unknown> = NominalType<string, ['ContentType', Data]>;
12
+ export declare const ContentTypeSchema: ZodType<ContentType>;
13
+ export type ContentReference = Reference<'Content'>;
14
+ type ContentDataType<Type> = Type extends ContentType<infer Data> ? Data : never;
15
+ export declare const ContentDataSchema: import("zod").ZodObject<{
16
+ key: ZodType<ContentKey, import("zod").ZodTypeDef, ContentKey>;
17
+ type: ZodType<ContentType<unknown>, import("zod").ZodTypeDef, ContentType<unknown>>;
18
+ data: import("zod").ZodUnknown;
19
+ sector: import("zod").ZodNullable<ZodType<ContentSector, import("zod").ZodTypeDef, ContentSector>>;
20
+ }, "strip", import("zod").ZodTypeAny, {
21
+ key: string & import("@bessemer/cornerstone/types").NominalTyping<"ContentKey">;
22
+ type: string & import("@bessemer/cornerstone/types").NominalTyping<["ContentType", unknown]>;
23
+ sector: ContentSector | null;
24
+ data?: unknown;
25
+ }, {
26
+ key: string & import("@bessemer/cornerstone/types").NominalTyping<"ContentKey">;
27
+ type: string & import("@bessemer/cornerstone/types").NominalTyping<["ContentType", unknown]>;
28
+ sector: ContentSector | null;
29
+ data?: unknown;
30
+ }>;
31
+ export type ContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = Referencable<ContentReference> & {
32
+ key: ContentKey;
33
+ type: Type;
34
+ data: Data;
35
+ sector: ContentSector | null;
36
+ };
37
+ export type ContentTypeConstructor<Content extends ContentData> = Content['type'];
38
+ export type ContentDisplayType = NominalType<string, 'ContentDisplayType'>;
39
+ export declare namespace ContentDisplayTypes {
40
+ const Default: ContentDisplayType;
41
+ const Label: ContentDisplayType;
42
+ const Desktop: ContentDisplayType;
43
+ const Mobile: ContentDisplayType;
44
+ const Modal: ContentDisplayType;
45
+ const Tooltip: ContentDisplayType;
46
+ }
47
+ export declare const TextContentType: ContentType<RichTextJson>;
48
+ export type TextContent = ContentData<typeof TextContentType>;
49
+ export interface ContentProvider<ContextType extends AbstractApplicationContext = AbstractApplicationContext> {
50
+ fetchContentByIds: (references: Array<ReferenceType<ContentReference>>, context: ContextType) => Promise<Array<ContentData>>;
51
+ fetchContentByKeys: (keys: Array<ContentKey>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>;
52
+ fetchContentBySectors: (sectors: Array<ContentSector>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>;
53
+ }
54
+ export type ContentNormalizer<ApplicationContext extends AbstractApplicationContext = AbstractApplicationContext, Type extends ContentData = ContentData> = {
55
+ type: Type['type'];
56
+ normalize: (data: Array<ContentData>, context: ApplicationContext) => Promise<Array<Type>>;
57
+ };
58
+ export declare const normalizeContent: <ApplicationContext extends AbstractApplicationContext>(content: Array<ContentData>, normalizers: Array<ContentNormalizer<ApplicationContext>>, context: ApplicationContext) => Promise<Array<ContentData>>;
59
+ export type StaticContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = ContentData<Type, Data> & {
60
+ tags: Array<Tag>;
61
+ };
62
+ export declare const staticData: <Type extends ContentType = ContentType, Data = ContentDataType<Type>>(key: ContentKey, type: Type, data: Data, options?: {
63
+ tags?: Array<Tag>;
64
+ sector?: ContentSector;
65
+ }) => StaticContentData<Type, Data>;
66
+ export declare const staticProvider: <ApplicationContext extends AbstractApplicationContext>(content: Array<StaticContentData>, normalizers?: Array<ContentNormalizer<ApplicationContext>>) => ContentProvider<ApplicationContext>;
67
+ export {};
68
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+B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IAClB,SAAS,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;CAC3F,CAAA;AAGD,eAAO,MAAM,gBAAgB,GAAU,kBAAkB,SAAS,0BAA0B,EAC1F,SAAS,KAAK,CAAC,WAAW,CAAC,EAC3B,aAAa,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,EACzD,SAAS,kBAAkB,KAC1B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAa5B,CAAA;AAED,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,WAAW,GAAG,WAAW,EAAE,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG;IAC9H,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,IAAI,SAAS,WAAW,GAAG,WAAW,EAAE,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,EAC7F,KAAK,UAAU,EACf,MAAM,IAAI,EACV,MAAM,IAAI,EACV,UAAU;IAAE,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAAC,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,KACtD,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAS9B,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,kBAAkB,SAAS,0BAA0B,EAClF,SAAS,KAAK,CAAC,iBAAiB,CAAC,EACjC,cAAc,KAAK,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,KACzD,eAAe,CAAC,kBAAkB,CA2BpC,CAAA"}
@@ -0,0 +1,79 @@
1
+ // src/content.ts
2
+ import { Arrays, Objects, References, Tags, Ulids, Zod } from "@bessemer/cornerstone";
3
+ var ContentSectorSchema = Zod.string();
4
+ var ContentKeySchema = Zod.string();
5
+ var ContentTypeSchema = Zod.string();
6
+ var ContentDataSchema = Zod.object({
7
+ key: ContentKeySchema,
8
+ type: ContentTypeSchema,
9
+ data: Zod.unknown(),
10
+ sector: ContentSectorSchema.nullable()
11
+ });
12
+ var ContentDisplayTypes;
13
+ ((ContentDisplayTypes2) => {
14
+ ContentDisplayTypes2.Default = "Default";
15
+ ContentDisplayTypes2.Label = "Label";
16
+ ContentDisplayTypes2.Desktop = "Desktop";
17
+ ContentDisplayTypes2.Mobile = "Mobile";
18
+ ContentDisplayTypes2.Modal = "Modal";
19
+ ContentDisplayTypes2.Tooltip = "Tooltip";
20
+ })(ContentDisplayTypes || (ContentDisplayTypes = {}));
21
+ var TextContentType = "Text";
22
+ var normalizeContent = async (content, normalizers, context) => {
23
+ const groupedContent = Arrays.groupBy(content, (it) => it.type);
24
+ const normalizedGroupedContent = Object.entries(groupedContent).map(async ([type, values]) => {
25
+ const normalizer = normalizers.find((it) => it.type === type);
26
+ if (Objects.isNil(normalizer)) {
27
+ return values;
28
+ }
29
+ return await normalizer.normalize(values, context);
30
+ });
31
+ const normalizedContent = (await Promise.all(normalizedGroupedContent)).flatMap((it) => it);
32
+ return normalizedContent;
33
+ };
34
+ var staticData = (key, type, data, options) => {
35
+ return {
36
+ reference: References.reference(Ulids.generateString(), "Content"),
37
+ key,
38
+ type,
39
+ data,
40
+ tags: options?.tags ?? [],
41
+ sector: options?.sector ?? null
42
+ };
43
+ };
44
+ var staticProvider = (content, normalizers) => {
45
+ return {
46
+ async fetchContentByIds(references, context) {
47
+ const matchingContent = content.filter((it) => Arrays.contains(references, it.reference));
48
+ return normalizeContent(matchingContent, normalizers ?? [], context);
49
+ },
50
+ async fetchContentByKeys(keys, tags, context) {
51
+ const matchingContent = content.filter((it) => Arrays.contains(keys, it.key));
52
+ const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {
53
+ const resolvedContent2 = Tags.resolveBy(it, (it2) => it2.tags ?? [], tags);
54
+ return Arrays.first(resolvedContent2);
55
+ });
56
+ return normalizeContent(resolvedContent, normalizers ?? [], context);
57
+ },
58
+ async fetchContentBySectors(sectors, tags, context) {
59
+ const matchingContent = content.filter((it) => Objects.isPresent(it.sector)).filter((it) => Arrays.contains(sectors, it.sector));
60
+ const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {
61
+ const resolvedContent2 = Tags.resolveBy(it, (it2) => it2.tags ?? [], tags);
62
+ return Arrays.first(resolvedContent2);
63
+ });
64
+ return normalizeContent(resolvedContent, normalizers ?? [], context);
65
+ }
66
+ };
67
+ };
68
+ export {
69
+ ContentDataSchema,
70
+ ContentDisplayTypes,
71
+ ContentKeySchema,
72
+ ContentSectorSchema,
73
+ ContentTypeSchema,
74
+ TextContentType,
75
+ normalizeContent,
76
+ staticData,
77
+ staticProvider
78
+ };
79
+ //# sourceMappingURL=content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/content.ts"],"sourcesContent":["import { Referencable, Reference, ReferenceType } from '@bessemer/cornerstone/reference'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { AbstractApplicationContext } from '@bessemer/cornerstone/context'\nimport { Arrays, Objects, References, Tags, Ulids, Zod } from '@bessemer/cornerstone'\nimport { RichTextJson } from '@bessemer/cornerstone/rich-text'\nimport { Tag } from '@bessemer/cornerstone/tag'\nimport { ZodType } from 'zod'\n\nexport type ContentSector = NominalType<string, 'ContentSector'>\nexport const ContentSectorSchema: ZodType<ContentSector> = Zod.string()\n\nexport type ContentKey = NominalType<string, 'ContentKey'>\nexport const ContentKeySchema: ZodType<ContentKey> = Zod.string()\n\nexport type ContentType<Data = unknown> = NominalType<string, ['ContentType', Data]>\nexport const ContentTypeSchema: ZodType<ContentType> = Zod.string()\n\nexport type ContentReference = Reference<'Content'>\n\ntype ContentDataType<Type> = Type extends ContentType<infer Data> ? Data : never\n\nexport const ContentDataSchema = Zod.object({\n key: ContentKeySchema,\n type: ContentTypeSchema,\n data: Zod.unknown(),\n sector: ContentSectorSchema.nullable(),\n})\n\nexport type ContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = Referencable<ContentReference> & {\n key: ContentKey\n type: Type\n data: Data\n sector: ContentSector | null\n}\n\nexport type ContentTypeConstructor<Content extends ContentData> = Content['type']\n\nexport type ContentDisplayType = NominalType<string, 'ContentDisplayType'>\n\nexport namespace ContentDisplayTypes {\n export const Default: ContentDisplayType = 'Default'\n export const Label: ContentDisplayType = 'Label'\n export const Desktop: ContentDisplayType = 'Desktop'\n export const Mobile: ContentDisplayType = 'Mobile'\n export const Modal: ContentDisplayType = 'Modal'\n export const Tooltip: ContentDisplayType = 'Tooltip'\n}\n\nexport const TextContentType: ContentType<RichTextJson> = 'Text'\nexport type TextContent = ContentData<typeof TextContentType>\n\nexport interface ContentProvider<ContextType extends AbstractApplicationContext = AbstractApplicationContext> {\n fetchContentByIds: (references: Array<ReferenceType<ContentReference>>, context: ContextType) => Promise<Array<ContentData>>\n\n fetchContentByKeys: (keys: Array<ContentKey>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>\n\n fetchContentBySectors: (sectors: Array<ContentSector>, tags: Array<Tag>, context: ContextType) => Promise<Array<ContentData>>\n}\n\nexport type ContentNormalizer<\n ApplicationContext extends AbstractApplicationContext = AbstractApplicationContext,\n Type extends ContentData = ContentData\n> = {\n type: Type['type']\n normalize: (data: Array<ContentData>, context: ApplicationContext) => Promise<Array<Type>>\n}\n\n// TODO might be more efficient to put the normalizers in a map at some point\nexport const normalizeContent = async <ApplicationContext extends AbstractApplicationContext>(\n content: Array<ContentData>,\n normalizers: Array<ContentNormalizer<ApplicationContext>>,\n context: ApplicationContext\n): Promise<Array<ContentData>> => {\n const groupedContent = Arrays.groupBy(content, (it) => it.type)\n const normalizedGroupedContent = Object.entries(groupedContent).map(async ([type, values]) => {\n const normalizer = normalizers.find((it) => it.type === type)\n if (Objects.isNil(normalizer)) {\n return values\n }\n\n return await normalizer.normalize(values, context)\n })\n\n const normalizedContent = (await Promise.all(normalizedGroupedContent)).flatMap((it) => it)\n return normalizedContent\n}\n\nexport type StaticContentData<Type extends ContentType = ContentType, Data = ContentDataType<Type>> = ContentData<Type, Data> & {\n tags: Array<Tag>\n}\n\nexport const staticData = <Type extends ContentType = ContentType, Data = ContentDataType<Type>>(\n key: ContentKey,\n type: Type,\n data: Data,\n options?: { tags?: Array<Tag>; sector?: ContentSector }\n): StaticContentData<Type, Data> => {\n return {\n reference: References.reference(Ulids.generateString(), 'Content'),\n key,\n type,\n data,\n tags: options?.tags ?? [],\n sector: options?.sector ?? null,\n }\n}\n\nexport const staticProvider = <ApplicationContext extends AbstractApplicationContext>(\n content: Array<StaticContentData>,\n normalizers?: Array<ContentNormalizer<ApplicationContext>>\n): ContentProvider<ApplicationContext> => {\n return {\n async fetchContentByIds(references: Array<ReferenceType<ContentReference>>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Arrays.contains(references, it.reference))\n return normalizeContent(matchingContent, normalizers ?? [], context)\n },\n async fetchContentByKeys(keys: Array<ContentKey>, tags: Array<Tag>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Arrays.contains(keys, it.key))\n\n const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {\n const resolvedContent = Tags.resolveBy(it, (it) => it.tags ?? [], tags)\n return Arrays.first(resolvedContent)!\n })\n\n return normalizeContent(resolvedContent, normalizers ?? [], context)\n },\n async fetchContentBySectors(sectors: Array<ContentSector>, tags: Array<Tag>, context: ApplicationContext): Promise<Array<ContentData>> {\n const matchingContent = content.filter((it) => Objects.isPresent(it.sector)).filter((it) => Arrays.contains(sectors, it.sector!))\n\n const resolvedContent = Object.values(Arrays.groupBy(matchingContent, (it) => it.key)).map((it) => {\n const resolvedContent = Tags.resolveBy(it, (it) => it.tags ?? [], tags)\n return Arrays.first(resolvedContent)!\n })\n\n return normalizeContent(resolvedContent, normalizers ?? [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olvedContent","it"]}
@@ -0,0 +1,7 @@
1
+ export type AbstractApplicationContext = {
2
+ global: {};
3
+ client: {
4
+ runtime: {};
5
+ };
6
+ };
7
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,EAAE,CAAA;IACV,MAAM,EAAE;QACN,OAAO,EAAE,EAAE,CAAA;KACZ,CAAA;CACF,CAAA"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,3 @@
1
+ export declare const getRandomBytes: (length: number) => Uint8Array;
2
+ export declare const getRandomHex: (length: number) => string;
3
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,UAE/C,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,MAM7C,CAAA"}
package/dist/crypto.js ADDED
@@ -0,0 +1,15 @@
1
+ // src/crypto.ts
2
+ var getRandomBytes = (length) => {
3
+ return crypto.getRandomValues(new Uint8Array(length));
4
+ };
5
+ var getRandomHex = (length) => {
6
+ const bytes = getRandomBytes(length);
7
+ const hashArray = Array.from(bytes);
8
+ const hexString = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
9
+ return hexString;
10
+ };
11
+ export {
12
+ getRandomBytes,
13
+ getRandomHex
14
+ };
15
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/crypto.ts"],"sourcesContent":["export const getRandomBytes = (length: number): Uint8Array => {\n return crypto.getRandomValues(new Uint8Array(length))\n}\n\nexport const getRandomHex = (length: number): string => {\n const bytes = getRandomBytes(length)\n // JOHN should Uint8Array to Hex String be a utility?\n const hashArray = Array.from(bytes)\n const hexString = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')\n return hexString\n}\n"],"mappings":";AAAO,IAAM,iBAAiB,CAAC,WAA+B;AAC5D,SAAO,OAAO,gBAAgB,IAAI,WAAW,MAAM,CAAC;AACtD;AAEO,IAAM,eAAe,CAAC,WAA2B;AACtD,QAAM,QAAQ,eAAe,MAAM;AAEnC,QAAM,YAAY,MAAM,KAAK,KAAK;AAClC,QAAM,YAAY,UAAU,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC/E,SAAO;AACT;","names":[]}
package/dist/date.d.ts ADDED
@@ -0,0 +1,10 @@
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
+ export declare const now: () => Date;
4
+ export declare const of: (dateString: string) => Date;
5
+ export declare const addMilliseconds: typeof _addMilliseconds;
6
+ export declare const addHours: typeof _addHours;
7
+ export declare const isBefore: typeof _isBefore;
8
+ export declare const isAfter: typeof _isAfter;
9
+ export declare const addDuration: (date: Date, duration: Duration) => Date;
10
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
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,EAAE,MAAM,gCAAgC,CAAA;AAGzD,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;AAE/B,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,EAAE,UAAU,QAAQ,KAAG,IAAiE,CAAA"}
package/dist/date.js ADDED
@@ -0,0 +1,24 @@
1
+ // src/date.ts
2
+ import { addHours as _addHours, addMilliseconds as _addMilliseconds, isAfter as _isAfter, isBefore as _isBefore, parseISO } from "date-fns";
3
+ import { Durations } from "@bessemer/cornerstone/index";
4
+ var now = () => {
5
+ return /* @__PURE__ */ new Date();
6
+ };
7
+ var of = (dateString) => {
8
+ return parseISO(dateString);
9
+ };
10
+ var addMilliseconds = _addMilliseconds;
11
+ var addHours = _addHours;
12
+ var isBefore = _isBefore;
13
+ var isAfter = _isAfter;
14
+ var addDuration = (date, duration) => addMilliseconds(date, Durations.inMilliseconds(duration));
15
+ export {
16
+ addDuration,
17
+ addHours,
18
+ addMilliseconds,
19
+ isAfter,
20
+ isBefore,
21
+ now,
22
+ of
23
+ };
24
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/date.ts"],"sourcesContent":["import { addHours as _addHours, addMilliseconds as _addMilliseconds, isAfter as _isAfter, isBefore as _isBefore, parseISO } from 'date-fns'\nimport { Duration } from '@bessemer/cornerstone/duration'\nimport { Durations } from '@bessemer/cornerstone/index'\n\nexport const now = (): Date => {\n return new Date()\n}\n\nexport const of = (dateString: string): Date => {\n return parseISO(dateString)\n}\n\nexport const addMilliseconds = _addMilliseconds\nexport const addHours = _addHours\nexport const isBefore = _isBefore\nexport const isAfter = _isAfter\n\nexport const addDuration = (date: Date, duration: Duration): Date => addMilliseconds(date, Durations.inMilliseconds(duration))\n"],"mappings":";AAAA,SAAS,YAAY,WAAW,mBAAmB,kBAAkB,WAAW,UAAU,YAAY,WAAW,gBAAgB;AAEjI,SAAS,iBAAiB;AAEnB,IAAM,MAAM,MAAY;AAC7B,SAAO,oBAAI,KAAK;AAClB;AAEO,IAAM,KAAK,CAAC,eAA6B;AAC9C,SAAO,SAAS,UAAU;AAC5B;AAEO,IAAM,kBAAkB;AACxB,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,UAAU;AAEhB,IAAM,cAAc,CAAC,MAAY,aAA6B,gBAAgB,MAAM,UAAU,eAAe,QAAQ,CAAC;","names":[]}
@@ -0,0 +1,39 @@
1
+ import { NominalType } from '@bessemer/cornerstone/types';
2
+ export type Millisecond = NominalType<number, 'Millisecond'>;
3
+ export type Second = NominalType<number, 'Second'>;
4
+ export type Minute = NominalType<number, 'Minute'>;
5
+ export type Hour = NominalType<number, 'Hour'>;
6
+ export type Day = NominalType<number, 'Day'>;
7
+ export type Duration = {
8
+ value: Millisecond;
9
+ };
10
+ export declare const ofMilliseconds: (value: Millisecond) => {
11
+ value: Millisecond;
12
+ };
13
+ export declare const inMilliseconds: (duration: Duration) => Millisecond;
14
+ export declare const ofSeconds: (value: Second) => {
15
+ value: Millisecond;
16
+ };
17
+ export declare const inSeconds: (duration: Duration) => number;
18
+ export declare const ofMinutes: (value: Minute) => {
19
+ value: Millisecond;
20
+ };
21
+ export declare const inMinutes: (duration: Duration) => number;
22
+ export declare const ofHours: (value: Hour) => {
23
+ value: Millisecond;
24
+ };
25
+ export declare const inHours: (duration: Duration) => number;
26
+ export declare const ofDays: (value: Day) => {
27
+ value: Millisecond;
28
+ };
29
+ export declare const inDays: (duration: Duration) => number;
30
+ export declare const Zero: {
31
+ value: Millisecond;
32
+ };
33
+ export declare const OneDay: {
34
+ value: Millisecond;
35
+ };
36
+ export declare const OneHour: {
37
+ value: Millisecond;
38
+ };
39
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA,OAA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6
+ };
7
+ var inMilliseconds = (duration) => {
8
+ return duration.value;
9
+ };
10
+ var ofSeconds = (value) => {
11
+ return ofMilliseconds(value * 1e3);
12
+ };
13
+ var inSeconds = (duration) => {
14
+ return inMilliseconds(duration) / 1e3;
15
+ };
16
+ var ofMinutes = (value) => {
17
+ return ofSeconds(value * 60);
18
+ };
19
+ var inMinutes = (duration) => {
20
+ return inSeconds(duration) / 60;
21
+ };
22
+ var ofHours = (value) => {
23
+ return ofMinutes(value * 60);
24
+ };
25
+ var inHours = (duration) => {
26
+ return inMinutes(duration) / 60;
27
+ };
28
+ var ofDays = (value) => {
29
+ return ofHours(value * 24);
30
+ };
31
+ var inDays = (duration) => {
32
+ return inHours(duration) / 24;
33
+ };
34
+ var Zero = ofMilliseconds(0);
35
+ var OneDay = ofDays(1);
36
+ var OneHour = ofHours(1);
37
+ export {
38
+ OneDay,
39
+ OneHour,
40
+ Zero,
41
+ inDays,
42
+ inHours,
43
+ inMilliseconds,
44
+ inMinutes,
45
+ inSeconds,
46
+ ofDays,
47
+ ofHours,
48
+ ofMilliseconds,
49
+ ofMinutes,
50
+ ofSeconds
51
+ };
52
+ //# sourceMappingURL=duration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/duration.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\n\nexport type Millisecond = NominalType<number, 'Millisecond'>\nexport type Second = NominalType<number, 'Second'>\nexport type Minute = NominalType<number, 'Minute'>\nexport type Hour = NominalType<number, 'Hour'>\nexport type Day = NominalType<number, 'Day'>\n\nexport type Duration = {\n value: Millisecond\n}\n\nexport const ofMilliseconds = (value: Millisecond) => {\n return {\n value,\n }\n}\n\nexport const inMilliseconds = (duration: Duration) => {\n return duration.value\n}\n\nexport const ofSeconds = (value: Second) => {\n return ofMilliseconds(value * 1000)\n}\n\nexport const inSeconds = (duration: Duration) => {\n return inMilliseconds(duration) / 1000\n}\n\nexport const ofMinutes = (value: Minute) => {\n return ofSeconds(value * 60)\n}\n\nexport const inMinutes = (duration: Duration) => {\n return inSeconds(duration) / 60\n}\n\nexport const ofHours = (value: Hour) => {\n return ofMinutes(value * 60)\n}\n\nexport const inHours = (duration: Duration) => {\n return inMinutes(duration) / 60\n}\n\nexport const ofDays = (value: Day) => {\n return ofHours(value * 24)\n}\n\nexport const inDays = (duration: Duration) => {\n return inHours(duration) / 24\n}\n\nexport const Zero = ofMilliseconds(0)\nexport const OneDay = ofDays(1)\nexport const OneHour = ofHours(1)\n"],"mappings":";AAYO,IAAM,iBAAiB,CAAC,UAAuB;AACpD,SAAO;AAAA,IACL;AAAA,EACF;AACF;AAEO,IAAM,iBAAiB,CAAC,aAAuB;AACpD,SAAO,SAAS;AAClB;AAEO,IAAM,YAAY,CAAC,UAAkB;AAC1C,SAAO,eAAe,QAAQ,GAAI;AACpC;AAEO,IAAM,YAAY,CAAC,aAAuB;AAC/C,SAAO,eAAe,QAAQ,IAAI;AACpC;AAEO,IAAM,YAAY,CAAC,UAAkB;AAC1C,SAAO,UAAU,QAAQ,EAAE;AAC7B;AAEO,IAAM,YAAY,CAAC,aAAuB;AAC/C,SAAO,UAAU,QAAQ,IAAI;AAC/B;AAEO,IAAM,UAAU,CAAC,UAAgB;AACtC,SAAO,UAAU,QAAQ,EAAE;AAC7B;AAEO,IAAM,UAAU,CAAC,aAAuB;AAC7C,SAAO,UAAU,QAAQ,IAAI;AAC/B;AAEO,IAAM,SAAS,CAAC,UAAe;AACpC,SAAO,QAAQ,QAAQ,EAAE;AAC3B;AAEO,IAAM,SAAS,CAAC,aAAuB;AAC5C,SAAO,QAAQ,QAAQ,IAAI;AAC7B;AAEO,IAAM,OAAO,eAAe,CAAC;AAC7B,IAAM,SAAS,OAAO,CAAC;AACvB,IAAM,UAAU,QAAQ,CAAC;","names":[]}
@@ -0,0 +1,20 @@
1
+ import { Eithers } from '@bessemer/cornerstone/index';
2
+ export declare enum EitherType {
3
+ Left = "Left",
4
+ Right = "Right"
5
+ }
6
+ export type Left<T> = {
7
+ type: EitherType.Left;
8
+ value: T;
9
+ };
10
+ export type Right<N> = {
11
+ type: EitherType.Right;
12
+ value: N;
13
+ };
14
+ export type Either<T, N> = Left<T> | Right<N>;
15
+ export declare const left: <T>(value: T) => Left<T>;
16
+ export declare const right: <N>(value: N) => Right<N>;
17
+ export declare const isLeft: <T, N>(either: Either<T, N>) => either is Left<T>;
18
+ export declare const isRight: <T, N>(either: Either<T, N>) => either is Right<N>;
19
+ export declare const split: <L, R>(array: Array<Either<L, R>>) => [Array<L>, Array<R>];
20
+ //# sourceMappingURL=either.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../src/either.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAErD,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,IAAI,EAAE,UAAU,CAAC,IAAI,CAAA;IACrB,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AACD,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IACrB,IAAI,EAAE,UAAU,CAAC,KAAK,CAAA;IACtB,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;AAE7C,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,IAAI,CAAC,CAAC,CAAuC,CAAA;AAChF,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,CAAC,CAAC,CAAwC,CAAA;AAEnF,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAoC,CAAA;AACxG,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,IAAI,KAAK,CAAC,CAAC,CAAqC,CAAA;AAE3G,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAI3E,CAAA"}
package/dist/either.js ADDED
@@ -0,0 +1,25 @@
1
+ // src/either.ts
2
+ import { Eithers } from "@bessemer/cornerstone/index";
3
+ var EitherType = /* @__PURE__ */ ((EitherType2) => {
4
+ EitherType2["Left"] = "Left";
5
+ EitherType2["Right"] = "Right";
6
+ return EitherType2;
7
+ })(EitherType || {});
8
+ var left = (value) => ({ type: "Left" /* Left */, value });
9
+ var right = (value) => ({ type: "Right" /* Right */, value });
10
+ var isLeft = (either) => either.type === "Left" /* Left */;
11
+ var isRight = (either) => either.type === "Right" /* Right */;
12
+ var split = (array) => {
13
+ const lefts = array.filter(Eithers.isLeft).map((it) => it.value);
14
+ const rights = array.filter(Eithers.isRight).map((it) => it.value);
15
+ return [lefts, rights];
16
+ };
17
+ export {
18
+ EitherType,
19
+ isLeft,
20
+ isRight,
21
+ left,
22
+ right,
23
+ split
24
+ };
25
+ //# sourceMappingURL=either.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/either.ts"],"sourcesContent":["import { Eithers } from '@bessemer/cornerstone/index'\n\nexport enum EitherType {\n Left = 'Left',\n Right = 'Right',\n}\n\nexport type Left<T> = {\n type: EitherType.Left\n value: T\n}\nexport type Right<N> = {\n type: EitherType.Right\n value: N\n}\n\nexport type Either<T, N> = Left<T> | Right<N>\n\nexport const left = <T>(value: T): Left<T> => ({ type: EitherType.Left, value })\nexport const right = <N>(value: N): Right<N> => ({ type: EitherType.Right, value })\n\nexport const isLeft = <T, N>(either: Either<T, N>): either is Left<T> => either.type === EitherType.Left\nexport const isRight = <T, N>(either: Either<T, N>): either is Right<N> => either.type === EitherType.Right\n\nexport const split = <L, R>(array: Array<Either<L, R>>): [Array<L>, Array<R>] => {\n const lefts = array.filter(Eithers.isLeft).map((it) => it.value)\n const rights = array.filter(Eithers.isRight).map((it) => it.value)\n return [lefts, rights]\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAEjB,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAgBL,IAAM,OAAO,CAAI,WAAuB,EAAE,MAAM,mBAAiB,MAAM;AACvE,IAAM,QAAQ,CAAI,WAAwB,EAAE,MAAM,qBAAkB,MAAM;AAE1E,IAAM,SAAS,CAAO,WAA4C,OAAO,SAAS;AAClF,IAAM,UAAU,CAAO,WAA6C,OAAO,SAAS;AAEpF,IAAM,QAAQ,CAAO,UAAqD;AAC/E,QAAM,QAAQ,MAAM,OAAO,QAAQ,MAAM,EAAE,IAAI,CAAC,OAAO,GAAG,KAAK;AAC/D,QAAM,SAAS,MAAM,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,KAAK;AACjE,SAAO,CAAC,OAAO,MAAM;AACvB;","names":["EitherType"]}
@@ -0,0 +1,7 @@
1
+ export type Entry<Value, Key = string> = [Key, Value];
2
+ export declare const of: <Value, Key = string>(key: Key, value: Value) => Entry<Value, Key>;
3
+ export declare const keys: <Key>(entries: Array<Entry<unknown, Key>>) => Array<Key>;
4
+ export declare const values: <T>(entries: Array<Entry<T>>) => Array<T>;
5
+ export declare const mapKeys: <Value, Key, NewKey>(entries: Array<Entry<Value, Key>>, mapper: (key: Key) => NewKey) => Array<Entry<Value, NewKey>>;
6
+ export declare const mapValues: <Value, Key, NewValue>(entries: Array<Entry<Value, Key>>, mapper: (key: Value) => NewValue) => Array<Entry<NewValue, Key>>;
7
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAErD,eAAO,MAAM,EAAE,GAAI,KAAK,EAAE,GAAG,GAAG,MAAM,EAAE,KAAK,GAAG,EAAE,OAAO,KAAK,KAAG,KAAK,CAAC,KAAK,EAAE,GAAG,CAEhF,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,GAAG,EAAE,SAAS,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAG,KAAK,CAAC,GAAG,CAExE,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,SAAS,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,CAE3D,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAEvI,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,KAAK,QAAQ,KAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAE/I,CAAA"}
package/dist/entry.js ADDED
@@ -0,0 +1,24 @@
1
+ // src/entry.ts
2
+ var of = (key, value) => {
3
+ return [key, value];
4
+ };
5
+ var keys = (entries) => {
6
+ return entries.map((it) => it[0]);
7
+ };
8
+ var values = (entries) => {
9
+ return entries.map((it) => it[1]);
10
+ };
11
+ var mapKeys = (entries, mapper) => {
12
+ return entries.map(([key, value]) => of(mapper(key), value));
13
+ };
14
+ var mapValues = (entries, mapper) => {
15
+ return entries.map(([key, value]) => of(key, mapper(value)));
16
+ };
17
+ export {
18
+ keys,
19
+ mapKeys,
20
+ mapValues,
21
+ of,
22
+ values
23
+ };
24
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/entry.ts"],"sourcesContent":["export type Entry<Value, Key = string> = [Key, Value]\n\nexport const of = <Value, Key = string>(key: Key, value: Value): Entry<Value, Key> => {\n return [key, value]\n}\n\nexport const keys = <Key>(entries: Array<Entry<unknown, Key>>): Array<Key> => {\n return entries.map((it) => it[0])\n}\n\nexport const values = <T>(entries: Array<Entry<T>>): Array<T> => {\n return entries.map((it) => it[1])\n}\n\nexport const mapKeys = <Value, Key, NewKey>(entries: Array<Entry<Value, Key>>, mapper: (key: Key) => NewKey): Array<Entry<Value, NewKey>> => {\n return entries.map(([key, value]) => of(mapper(key), value))\n}\n\nexport const mapValues = <Value, Key, NewValue>(entries: Array<Entry<Value, Key>>, mapper: (key: Value) => NewValue): Array<Entry<NewValue, Key>> => {\n return entries.map(([key, value]) => of(key, mapper(value)))\n}\n"],"mappings":";AAEO,IAAM,KAAK,CAAsB,KAAU,UAAoC;AACpF,SAAO,CAAC,KAAK,KAAK;AACpB;AAEO,IAAM,OAAO,CAAM,YAAoD;AAC5E,SAAO,QAAQ,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;AAClC;AAEO,IAAM,SAAS,CAAI,YAAuC;AAC/D,SAAO,QAAQ,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;AAClC;AAEO,IAAM,UAAU,CAAqB,SAAmC,WAA8D;AAC3I,SAAO,QAAQ,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,OAAO,GAAG,GAAG,KAAK,CAAC;AAC7D;AAEO,IAAM,YAAY,CAAuB,SAAmC,WAAkE;AACnJ,SAAO,QAAQ,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,KAAK,OAAO,KAAK,CAAC,CAAC;AAC7D;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { Comparator } from '@bessemer/cornerstone/comparator';
2
+ export type Equalitor<T> = (first: T, second: T) => boolean;
3
+ export declare const fromComparator: <T>(comparator: Comparator<T>) => Equalitor<T>;
4
+ export declare const reference: <T>() => Equalitor<T>;
5
+ //# sourceMappingURL=equalitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"equalitor.d.ts","sourceRoot":"","sources":["../src/equalitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,OAAO,CAAA;AAE3D,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,YAAY,UAAU,CAAC,CAAC,CAAC,KAAG,SAAS,CAAC,CAAC,CAExE,CAAA;AAED,eAAO,MAAM,SAAS,GACnB,CAAC,OAAK,SAAS,CAAC,CAAC,CAEA,CAAA"}