@bessemer/cornerstone 0.5.113 → 0.5.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/dist/array.d.ts.map +1 -1
  2. package/dist/array.js +28 -28
  3. package/dist/array.js.map +1 -1
  4. package/dist/aspect-ratio.d.ts +3 -3
  5. package/dist/aspect-ratio.d.ts.map +1 -1
  6. package/dist/aspect-ratio.js +13 -12
  7. package/dist/aspect-ratio.js.map +1 -1
  8. package/dist/assertion.d.ts.map +1 -1
  9. package/dist/assertion.js +5 -5
  10. package/dist/assertion.js.map +1 -1
  11. package/dist/async-value.js +2 -2
  12. package/dist/async-value.js.map +1 -1
  13. package/dist/async.d.ts.map +1 -1
  14. package/dist/async.js +2 -2
  15. package/dist/async.js.map +1 -1
  16. package/dist/cache.d.ts.map +1 -1
  17. package/dist/cache.js +11 -12
  18. package/dist/cache.js.map +1 -1
  19. package/dist/combinable.js +5 -5
  20. package/dist/combinable.js.map +1 -1
  21. package/dist/comparator.js +8 -8
  22. package/dist/comparator.js.map +1 -1
  23. package/dist/data-size.d.ts +2 -1
  24. package/dist/data-size.d.ts.map +1 -1
  25. package/dist/data-size.js +3 -3
  26. package/dist/data-size.js.map +1 -1
  27. package/dist/either.js +5 -5
  28. package/dist/either.js.map +1 -1
  29. package/dist/equalitor.d.ts.map +1 -1
  30. package/dist/equalitor.js +2 -2
  31. package/dist/equalitor.js.map +1 -1
  32. package/dist/error/error-cause.d.ts.map +1 -1
  33. package/dist/error/error-cause.js +14 -14
  34. package/dist/error/error-cause.js.map +1 -1
  35. package/dist/error/error-code.js +2 -2
  36. package/dist/error/error-code.js.map +1 -1
  37. package/dist/error/error-event.d.ts +3 -2
  38. package/dist/error/error-event.d.ts.map +1 -1
  39. package/dist/error/error-event.js +28 -28
  40. package/dist/error/error-event.js.map +1 -1
  41. package/dist/error/error-type.d.ts +2 -1
  42. package/dist/error/error-type.d.ts.map +1 -1
  43. package/dist/error/error-type.js +2 -2
  44. package/dist/error/error-type.js.map +1 -1
  45. package/dist/error/error.js +5 -5
  46. package/dist/error/error.js.map +1 -1
  47. package/dist/expression/array-expression.js +3 -3
  48. package/dist/expression/array-expression.js.map +1 -1
  49. package/dist/expression/core-expression.d.ts.map +1 -1
  50. package/dist/expression/core-expression.js +19 -19
  51. package/dist/expression/core-expression.js.map +1 -1
  52. package/dist/expression/expression-evaluator.js +2 -2
  53. package/dist/expression/expression-evaluator.js.map +1 -1
  54. package/dist/expression/expression-mapper.js +4 -4
  55. package/dist/expression/expression-mapper.js.map +1 -1
  56. package/dist/expression/internal.js +3 -3
  57. package/dist/expression/internal.js.map +1 -1
  58. package/dist/expression/numeric-expression.js +13 -13
  59. package/dist/expression/numeric-expression.js.map +1 -1
  60. package/dist/expression/string-expression.js +4 -4
  61. package/dist/expression/string-expression.js.map +1 -1
  62. package/dist/expression.d.ts +17 -1
  63. package/dist/expression.d.ts.map +1 -1
  64. package/dist/expression.js.map +1 -1
  65. package/dist/glob.d.ts +3 -3
  66. package/dist/glob.d.ts.map +1 -1
  67. package/dist/glob.js +11 -12
  68. package/dist/glob.js.map +1 -1
  69. package/dist/global-variable.d.ts.map +1 -1
  70. package/dist/global-variable.js +5 -5
  71. package/dist/global-variable.js.map +1 -1
  72. package/dist/hex-code.d.ts +3 -3
  73. package/dist/hex-code.d.ts.map +1 -1
  74. package/dist/hex-code.js +11 -10
  75. package/dist/hex-code.js.map +1 -1
  76. package/dist/index.d.ts +311 -1
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +4 -0
  79. package/dist/index.js.map +1 -1
  80. package/dist/intl/country-code.d.ts +3 -3
  81. package/dist/intl/country-code.d.ts.map +1 -1
  82. package/dist/intl/country-code.js +9 -10
  83. package/dist/intl/country-code.js.map +1 -1
  84. package/dist/intl/country-subdivision-code.d.ts +3 -3
  85. package/dist/intl/country-subdivision-code.d.ts.map +1 -1
  86. package/dist/intl/country-subdivision-code.js +13 -11
  87. package/dist/intl/country-subdivision-code.js.map +1 -1
  88. package/dist/intl/currency-code.d.ts +3 -3
  89. package/dist/intl/currency-code.d.ts.map +1 -1
  90. package/dist/intl/currency-code.js +9 -10
  91. package/dist/intl/currency-code.js.map +1 -1
  92. package/dist/intl/language-code.d.ts +3 -3
  93. package/dist/intl/language-code.d.ts.map +1 -1
  94. package/dist/intl/language-code.js +9 -10
  95. package/dist/intl/language-code.js.map +1 -1
  96. package/dist/intl/locale.d.ts +3 -3
  97. package/dist/intl/locale.d.ts.map +1 -1
  98. package/dist/intl/locale.js +18 -19
  99. package/dist/intl/locale.js.map +1 -1
  100. package/dist/json.d.ts.map +1 -1
  101. package/dist/json.js +2 -2
  102. package/dist/json.js.map +1 -1
  103. package/dist/logger.d.ts.map +1 -1
  104. package/dist/logger.js +12 -12
  105. package/dist/logger.js.map +1 -1
  106. package/dist/map.d.ts +306 -0
  107. package/dist/map.d.ts.map +1 -1
  108. package/dist/map.js +8 -8
  109. package/dist/map.js.map +1 -1
  110. package/dist/mime-type.d.ts +3 -3
  111. package/dist/mime-type.d.ts.map +1 -1
  112. package/dist/mime-type.js +9 -10
  113. package/dist/mime-type.js.map +1 -1
  114. package/dist/misc.js +4 -4
  115. package/dist/misc.js.map +1 -1
  116. package/dist/monetary-amount.d.ts +3 -2
  117. package/dist/monetary-amount.d.ts.map +1 -1
  118. package/dist/monetary-amount.js +16 -16
  119. package/dist/monetary-amount.js.map +1 -1
  120. package/dist/net/content-type.d.ts +2 -1
  121. package/dist/net/content-type.d.ts.map +1 -1
  122. package/dist/net/content-type.js +2 -2
  123. package/dist/net/content-type.js.map +1 -1
  124. package/dist/net/domain-name.d.ts +3 -3
  125. package/dist/net/domain-name.d.ts.map +1 -1
  126. package/dist/net/domain-name.js +10 -11
  127. package/dist/net/domain-name.js.map +1 -1
  128. package/dist/net/http-method.d.ts.map +1 -1
  129. package/dist/net/http-method.js +9 -9
  130. package/dist/net/http-method.js.map +1 -1
  131. package/dist/net/ipv4-address.d.ts +3 -3
  132. package/dist/net/ipv4-address.d.ts.map +1 -1
  133. package/dist/net/ipv4-address.js +10 -11
  134. package/dist/net/ipv4-address.js.map +1 -1
  135. package/dist/net/ipv6-address.d.ts +3 -3
  136. package/dist/net/ipv6-address.d.ts.map +1 -1
  137. package/dist/net/ipv6-address.js +10 -11
  138. package/dist/net/ipv6-address.js.map +1 -1
  139. package/dist/net/uri-host-name.d.ts +3 -3
  140. package/dist/net/uri-host-name.d.ts.map +1 -1
  141. package/dist/net/uri-host-name.js +15 -16
  142. package/dist/net/uri-host-name.js.map +1 -1
  143. package/dist/net/uri.d.ts +1 -2
  144. package/dist/net/uri.d.ts.map +1 -1
  145. package/dist/net/uri.js +5 -3
  146. package/dist/net/uri.js.map +1 -1
  147. package/dist/net/url.d.ts.map +1 -1
  148. package/dist/net/url.js +6 -7
  149. package/dist/net/url.js.map +1 -1
  150. package/dist/object/object-path.d.ts.map +1 -1
  151. package/dist/object/object-path.js +23 -28
  152. package/dist/object/object-path.js.map +1 -1
  153. package/dist/object/type-path.js +19 -19
  154. package/dist/object/type-path.js.map +1 -1
  155. package/dist/patch.js +4 -4
  156. package/dist/patch.js.map +1 -1
  157. package/dist/promise.js +2 -2
  158. package/dist/promise.js.map +1 -1
  159. package/dist/property.d.ts.map +1 -1
  160. package/dist/property.js +7 -7
  161. package/dist/property.js.map +1 -1
  162. package/dist/proxy.js +2 -2
  163. package/dist/proxy.js.map +1 -1
  164. package/dist/range.js +2 -2
  165. package/dist/range.js.map +1 -1
  166. package/dist/reference.d.ts +2 -1
  167. package/dist/reference.d.ts.map +1 -1
  168. package/dist/reference.js +13 -13
  169. package/dist/reference.js.map +1 -1
  170. package/dist/resource-key.js +2 -2
  171. package/dist/resource-key.js.map +1 -1
  172. package/dist/result.js +5 -5
  173. package/dist/result.js.map +1 -1
  174. package/dist/retry.d.ts.map +1 -1
  175. package/dist/retry.js +12 -12
  176. package/dist/retry.js.map +1 -1
  177. package/dist/rich-text.js +2 -2
  178. package/dist/rich-text.js.map +1 -1
  179. package/dist/signature.d.ts.map +1 -1
  180. package/dist/signature.js +9 -9
  181. package/dist/signature.js.map +1 -1
  182. package/dist/sql/sql-expression-parser.js +2 -2
  183. package/dist/sql/sql-expression-parser.js.map +1 -1
  184. package/dist/sql.d.ts +5 -1
  185. package/dist/sql.d.ts.map +1 -1
  186. package/dist/sql.js.map +1 -1
  187. package/dist/store.d.ts.map +1 -1
  188. package/dist/store.js +9 -9
  189. package/dist/store.js.map +1 -1
  190. package/dist/string.js +4 -4
  191. package/dist/string.js.map +1 -1
  192. package/dist/tag.d.ts.map +1 -1
  193. package/dist/tag.js +10 -10
  194. package/dist/tag.js.map +1 -1
  195. package/dist/temporal/clock.d.ts +13 -13
  196. package/dist/temporal/clock.d.ts.map +1 -1
  197. package/dist/temporal/clock.js +10 -10
  198. package/dist/temporal/clock.js.map +1 -1
  199. package/dist/temporal/duration.d.ts +15 -9
  200. package/dist/temporal/duration.d.ts.map +1 -1
  201. package/dist/temporal/duration.js +30 -31
  202. package/dist/temporal/duration.js.map +1 -1
  203. package/dist/temporal/instant.d.ts +18 -15
  204. package/dist/temporal/instant.d.ts.map +1 -1
  205. package/dist/temporal/instant.js +42 -43
  206. package/dist/temporal/instant.js.map +1 -1
  207. package/dist/temporal/plain-date-time.d.ts +16 -13
  208. package/dist/temporal/plain-date-time.d.ts.map +1 -1
  209. package/dist/temporal/plain-date-time.js +36 -38
  210. package/dist/temporal/plain-date-time.js.map +1 -1
  211. package/dist/temporal/plain-date.d.ts +16 -13
  212. package/dist/temporal/plain-date.d.ts.map +1 -1
  213. package/dist/temporal/plain-date.js +35 -37
  214. package/dist/temporal/plain-date.js.map +1 -1
  215. package/dist/temporal/plain-month-day.d.ts +37 -0
  216. package/dist/temporal/plain-month-day.d.ts.map +1 -0
  217. package/dist/temporal/plain-month-day.js +84 -0
  218. package/dist/temporal/plain-month-day.js.map +1 -0
  219. package/dist/temporal/plain-time.d.ts +19 -17
  220. package/dist/temporal/plain-time.d.ts.map +1 -1
  221. package/dist/temporal/plain-time.js +43 -42
  222. package/dist/temporal/plain-time.js.map +1 -1
  223. package/dist/temporal/plain-year-month.d.ts +57 -0
  224. package/dist/temporal/plain-year-month.d.ts.map +1 -0
  225. package/dist/temporal/plain-year-month.js +109 -0
  226. package/dist/temporal/plain-year-month.js.map +1 -0
  227. package/dist/temporal/time-zone-id.d.ts +5 -4
  228. package/dist/temporal/time-zone-id.d.ts.map +1 -1
  229. package/dist/temporal/time-zone-id.js +11 -11
  230. package/dist/temporal/time-zone-id.js.map +1 -1
  231. package/dist/temporal/time-zone-offset.d.ts +12 -11
  232. package/dist/temporal/time-zone-offset.d.ts.map +1 -1
  233. package/dist/temporal/time-zone-offset.js +42 -50
  234. package/dist/temporal/time-zone-offset.js.map +1 -1
  235. package/dist/temporal/zoned-date-time.d.ts +16 -13
  236. package/dist/temporal/zoned-date-time.d.ts.map +1 -1
  237. package/dist/temporal/zoned-date-time.js +35 -36
  238. package/dist/temporal/zoned-date-time.js.map +1 -1
  239. package/dist/uuid/ulid.d.ts +3 -3
  240. package/dist/uuid/ulid.d.ts.map +1 -1
  241. package/dist/uuid/ulid.js +9 -10
  242. package/dist/uuid/ulid.js.map +1 -1
  243. package/dist/uuid/uuid-v4.d.ts +3 -3
  244. package/dist/uuid/uuid-v4.d.ts.map +1 -1
  245. package/dist/uuid/uuid-v4.js +13 -14
  246. package/dist/uuid/uuid-v4.js.map +1 -1
  247. package/dist/uuid/uuid-v7.d.ts +1 -2
  248. package/dist/uuid/uuid-v7.d.ts.map +1 -1
  249. package/dist/uuid/uuid-v7.js +1 -2
  250. package/dist/uuid/uuid-v7.js.map +1 -1
  251. package/dist/zod-util.d.ts +4 -3
  252. package/dist/zod-util.d.ts.map +1 -1
  253. package/dist/zod-util.js +21 -11
  254. package/dist/zod-util.js.map +1 -1
  255. package/package.json +6 -4
@@ -1,16 +1,16 @@
1
1
  // src/object/type-path.ts
2
- import { assert } from "@bessemer/cornerstone/assertion";
2
+ import * as Assertions from "@bessemer/cornerstone/assertion";
3
3
  import Zod from "zod";
4
- import { isNil, isObject } from "@bessemer/cornerstone/object";
5
- import { isNumber } from "@bessemer/cornerstone/math";
6
- import { contains, containsAll, isEmpty, only } from "@bessemer/cornerstone/array";
4
+ import * as Objects from "@bessemer/cornerstone/object";
5
+ import * as Maths from "@bessemer/cornerstone/math";
6
+ import * as Arrays from "@bessemer/cornerstone/array";
7
7
  import * as Results from "@bessemer/cornerstone/result";
8
8
  var of = (value) => {
9
9
  return value;
10
10
  };
11
11
  var TypePathRegex = /^(?:[a-zA-Z_$][a-zA-Z0-9_$]*|\*|\d+|\[\s*(?:\*|\d+(?:\s*,\s*\d+)*)\s*])(?:\.(?:[a-zA-Z_$][a-zA-Z0-9_$]*|\*|\d+)|\[\s*(?:\*|\d+(?:\s*,\s*\d+)*)\s*])*$|^$/;
12
12
  var from = (path) => {
13
- assert(TypePathRegex.test(path), () => `Unable to parse TypePath from string: ${path}`);
13
+ Assertions.assert(TypePathRegex.test(path), () => `Unable to parse TypePath from string: ${path}`);
14
14
  if (path === "") {
15
15
  return [];
16
16
  }
@@ -72,7 +72,7 @@ var getValue = (path, object) => {
72
72
  let current = object;
73
73
  let collectorMode = false;
74
74
  for (const selector of path) {
75
- if (isNil(current)) {
75
+ if (Objects.isNil(current)) {
76
76
  return void 0;
77
77
  }
78
78
  if (collectorMode) {
@@ -108,10 +108,10 @@ var evaluateSelector = (selector, current) => {
108
108
  var evaluateNameSelector = (selector, current) => {
109
109
  if (Array.isArray(current)) {
110
110
  const numberSelector = Number(selector);
111
- assert(isNumber(numberSelector), () => `Can't apply non-numeric selector: ${selector} to array: ${current}`);
111
+ Assertions.assert(Maths.isNumber(numberSelector), () => `Can't apply non-numeric selector: ${selector} to array: ${current}`);
112
112
  return evaluateIndexSelector([numberSelector], current);
113
113
  }
114
- if (!isObject(current)) {
114
+ if (!Objects.isObject(current)) {
115
115
  return [void 0, false];
116
116
  }
117
117
  return [current[selector], false];
@@ -120,7 +120,7 @@ var evaluateWildcardSelector = (current) => {
120
120
  if (Array.isArray(current)) {
121
121
  return [current, true];
122
122
  }
123
- if (isObject(current)) {
123
+ if (Objects.isObject(current)) {
124
124
  throw new Error("Wildcard operations on Objects is not yet supported");
125
125
  }
126
126
  throw new Error(`Unable to apply wildcard operator to value: ${current}`);
@@ -130,7 +130,7 @@ var evaluateIndexSelector = (selector, current) => {
130
130
  throw new Error(`Unable to apply index operator to value: ${current}`);
131
131
  }
132
132
  if (selector.length === 1) {
133
- return [current[only(selector)], false];
133
+ return [current[Arrays.only(selector)], false];
134
134
  }
135
135
  const indexSelector = selector;
136
136
  const result = indexSelector.map((it) => current[it]);
@@ -146,18 +146,18 @@ var matches = (targetPath, matchingPath) => {
146
146
  let index = 0;
147
147
  for (const targetPathSelector of targetPath) {
148
148
  const matchingPathSelector = matchingPath[index];
149
- if (isNil(matchingPathSelector)) {
149
+ if (Objects.isNil(matchingPathSelector)) {
150
150
  return true;
151
151
  } else if (isWildcardSelector(matchingPathSelector)) {
152
152
  } else if (isWildcardSelector(targetPathSelector)) {
153
153
  return false;
154
154
  } else if (Array.isArray(matchingPathSelector)) {
155
155
  if (Array.isArray(targetPathSelector)) {
156
- if (!containsAll(matchingPathSelector, targetPathSelector)) {
156
+ if (!Arrays.containsAll(matchingPathSelector, targetPathSelector)) {
157
157
  return false;
158
158
  }
159
159
  } else {
160
- if (!contains(matchingPathSelector, Number(targetPathSelector))) {
160
+ if (!Arrays.contains(matchingPathSelector, Number(targetPathSelector))) {
161
161
  return false;
162
162
  }
163
163
  }
@@ -166,7 +166,7 @@ var matches = (targetPath, matchingPath) => {
166
166
  if (targetPathSelector.length !== 1) {
167
167
  return false;
168
168
  }
169
- const targetPathSelectorIndex = only(targetPathSelector);
169
+ const targetPathSelectorIndex = Arrays.only(targetPathSelector);
170
170
  if (targetPathSelectorIndex !== Number(matchingPathSelector)) {
171
171
  return false;
172
172
  }
@@ -189,7 +189,7 @@ var intersectAny = (targetPath, intersectingPath) => {
189
189
  for (const targetPathSelector of targetPath) {
190
190
  const intersectingPathSelector = intersectingPath[index];
191
191
  const makeError = () => new Error(`Path mismatch when intersecting. targetPath: ${targetPathSelector} does not match intersectingPath: ${intersectingPathSelector}`);
192
- if (isNil(intersectingPathSelector)) {
192
+ if (Objects.isNil(intersectingPathSelector)) {
193
193
  return Results.success(of(result));
194
194
  } else if (isWildcardSelector(intersectingPathSelector)) {
195
195
  result.push(targetPathSelector);
@@ -197,13 +197,13 @@ var intersectAny = (targetPath, intersectingPath) => {
197
197
  return Results.failure(makeError());
198
198
  } else if (Array.isArray(intersectingPathSelector)) {
199
199
  if (Array.isArray(targetPathSelector)) {
200
- const filteredTargetPaths = targetPathSelector.filter((it) => contains(intersectingPathSelector, it));
201
- if (isEmpty(filteredTargetPaths)) {
200
+ const filteredTargetPaths = targetPathSelector.filter((it) => Arrays.contains(intersectingPathSelector, it));
201
+ if (Arrays.isEmpty(filteredTargetPaths)) {
202
202
  return Results.failure(makeError());
203
203
  }
204
204
  result.push(filteredTargetPaths);
205
205
  } else {
206
- if (!contains(intersectingPathSelector, Number(targetPathSelector))) {
206
+ if (!Arrays.contains(intersectingPathSelector, Number(targetPathSelector))) {
207
207
  return Results.failure(makeError());
208
208
  }
209
209
  result.push(targetPathSelector);
@@ -213,7 +213,7 @@ var intersectAny = (targetPath, intersectingPath) => {
213
213
  if (targetPathSelector.length !== 1) {
214
214
  return Results.failure(makeError());
215
215
  }
216
- const targetPathSelectorIndex = only(targetPathSelector);
216
+ const targetPathSelectorIndex = Arrays.only(targetPathSelector);
217
217
  if (targetPathSelectorIndex !== Number(intersectingPathSelector)) {
218
218
  return Results.failure(makeError());
219
219
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/type-path.ts"],"sourcesContent":["import { TaggedType } from '@bessemer/cornerstone/types'\nimport { assert } from '@bessemer/cornerstone/assertion'\nimport Zod from 'zod'\nimport {\n IndexSelector,\n InferTypePath,\n NameSelector,\n ParseTypePath,\n TypePathConcreteType,\n TypePathGet,\n TypePathSelector,\n TypePathType,\n WildcardSelector,\n} from '@bessemer/cornerstone/object/type-path-type'\nimport { isNil, isObject } from '@bessemer/cornerstone/object'\nimport { isNumber } from '@bessemer/cornerstone/math'\nimport { contains, containsAll, isEmpty, only } from '@bessemer/cornerstone/array'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\n\n// JOHN this probably should be brought into the structured transform regime\nexport type TypePath<T extends TypePathType = TypePathType> = TaggedType<TypePathConcreteType, ['TypePath', T]>\n\nexport const of = <T extends TypePathConcreteType>(value: T): TypePath<InferTypePath<T>> => {\n return value as TypePath<InferTypePath<T>>\n}\n\nconst TypePathRegex =\n /^(?:[a-zA-Z_$][a-zA-Z0-9_$]*|\\*|\\d+|\\[\\s*(?:\\*|\\d+(?:\\s*,\\s*\\d+)*)\\s*])(?:\\.(?:[a-zA-Z_$][a-zA-Z0-9_$]*|\\*|\\d+)|\\[\\s*(?:\\*|\\d+(?:\\s*,\\s*\\d+)*)\\s*])*$|^$/\n\nexport const from = <T extends string>(path: T): TypePath<ParseTypePath<T>> => {\n assert(TypePathRegex.test(path), () => `Unable to parse TypePath from string: ${path}`)\n\n if (path === '') {\n return [] as TypePath<ParseTypePath<T>>\n }\n\n const segments: Array<string | Array<string | number>> = []\n let current = ''\n let i = 0\n\n while (i < path.length) {\n const char = path[i]\n\n if (char === '.') {\n if (current) {\n segments.push(current)\n current = ''\n }\n i++\n } else if (char === '[') {\n if (current) {\n segments.push(current)\n current = ''\n }\n\n // Find the matching closing bracket\n let bracketContent = ''\n i++ // Skip opening bracket\n let depth = 1\n\n while (i < path.length && depth > 0) {\n const bracketChar = path[i]\n if (bracketChar === '[') {\n depth++\n } else if (bracketChar === ']') {\n depth--\n }\n\n if (depth > 0) {\n bracketContent += bracketChar\n }\n i++\n }\n\n if (bracketContent === '*') {\n segments.push('*')\n } else {\n const indices = bracketContent\n .split(',')\n .map((s) => s.trim())\n .map((s) => parseInt(s, 10))\n\n segments.push(indices)\n }\n } else {\n current += char\n i++\n }\n }\n\n // Add any remaining current segment\n if (current) {\n segments.push(current)\n }\n\n return segments as TypePath<ParseTypePath<T>>\n}\n\nexport const Schema = Zod.union([Zod.array(Zod.string()), Zod.string()]).transform((it) => {\n if (Array.isArray(it)) {\n return of(it)\n } else {\n return from(it)\n }\n})\n\nexport const getValue = <T extends TypePathType, N>(path: TypePath<T>, object: N): TypePathGet<T, N> => {\n let current: unknown = object\n let collectorMode = false\n\n for (const selector of path) {\n if (isNil(current)) {\n return undefined as TypePathGet<T, N>\n }\n\n if (collectorMode) {\n if (!Array.isArray(current)) {\n throw new Error('Illegal State - in collectorMode but current value is not an Array')\n }\n\n const result = current.flatMap((it) => {\n const [value, isCollecting] = evaluateSelector(selector, it)\n if (isCollecting) {\n return value\n } else {\n return [value]\n }\n })\n\n current = result\n } else {\n const [result, isCollecting] = evaluateSelector(selector, current)\n current = result\n collectorMode = isCollecting\n }\n }\n\n return current as TypePathGet<T, N>\n}\n\nconst evaluateSelector = (selector: TypePathSelector, current: unknown): [unknown, boolean] => {\n if (isWildcardSelector(selector)) {\n return evaluateWildcardSelector(current)\n }\n\n if (Array.isArray(selector)) {\n return evaluateIndexSelector(selector as IndexSelector, current)\n }\n\n return evaluateNameSelector(selector, current)\n}\n\nconst evaluateNameSelector = (selector: NameSelector, current: unknown): [unknown, boolean] => {\n if (Array.isArray(current)) {\n const numberSelector = Number(selector)\n assert(isNumber(numberSelector), () => `Can't apply non-numeric selector: ${selector} to array: ${current}`)\n return evaluateIndexSelector([numberSelector], current)\n }\n\n if (!isObject(current)) {\n return [undefined, false]\n }\n\n return [current[selector], false]\n}\n\nconst evaluateWildcardSelector = (current: unknown): [unknown, boolean] => {\n if (Array.isArray(current)) {\n return [current, true]\n }\n\n if (isObject(current)) {\n throw new Error('Wildcard operations on Objects is not yet supported')\n }\n\n throw new Error(`Unable to apply wildcard operator to value: ${current}`)\n}\n\nconst evaluateIndexSelector = (selector: IndexSelector, current: unknown): [unknown, boolean] => {\n if (!Array.isArray(current)) {\n throw new Error(`Unable to apply index operator to value: ${current}`)\n }\n\n if (selector.length === 1) {\n return [current[only(selector)], false]\n }\n\n const indexSelector = selector as IndexSelector\n const result = indexSelector.map((it) => current[it])\n return [result, true]\n}\n\nexport const isWildcardSelector = (selector: TypePathSelector): selector is WildcardSelector => {\n return selector === '*'\n}\n\nexport const matches = <MatchingPath extends TypePathType>(\n targetPath: TypePath,\n matchingPath: TypePath<MatchingPath>\n): targetPath is TypePath<MatchingPath> => {\n if (targetPath.length < matchingPath.length) {\n return false\n }\n\n let index = 0\n for (const targetPathSelector of targetPath) {\n const matchingPathSelector = matchingPath[index]\n\n if (isNil(matchingPathSelector)) {\n return true\n } else if (isWildcardSelector(matchingPathSelector)) {\n // Matching path wildcards always match - they're wild\n } else if (isWildcardSelector(targetPathSelector)) {\n return false\n } else if (Array.isArray(matchingPathSelector)) {\n if (Array.isArray(targetPathSelector)) {\n if (!containsAll(matchingPathSelector, targetPathSelector)) {\n return false\n }\n } else {\n if (!contains(matchingPathSelector, Number(targetPathSelector))) {\n return false\n }\n }\n } else {\n if (Array.isArray(targetPathSelector)) {\n if (targetPathSelector.length !== 1) {\n return false\n }\n\n const targetPathSelectorIndex = only(targetPathSelector)\n if (targetPathSelectorIndex !== Number(matchingPathSelector)) {\n return false\n }\n } else {\n if (targetPathSelector !== matchingPathSelector) {\n return false\n }\n }\n }\n\n index++\n }\n\n return true\n}\n\nexport const intersectAny = (targetPath: TypePath, intersectingPath: TypePath): Result<TypePath> => {\n if (targetPath.length < intersectingPath.length) {\n return Results.failure(new Error(`TypePath: ${intersectingPath} can't intersect target TypePath: ${targetPath}`))\n }\n\n let index = 0\n let result: TypePathConcreteType = []\n for (const targetPathSelector of targetPath) {\n const intersectingPathSelector = intersectingPath[index]\n const makeError = () =>\n new Error(`Path mismatch when intersecting. targetPath: ${targetPathSelector} does not match intersectingPath: ${intersectingPathSelector}`)\n\n if (isNil(intersectingPathSelector)) {\n return Results.success(of(result))\n } else if (isWildcardSelector(intersectingPathSelector)) {\n result.push(targetPathSelector)\n } else if (isWildcardSelector(targetPathSelector)) {\n return Results.failure(makeError())\n } else if (Array.isArray(intersectingPathSelector)) {\n if (Array.isArray(targetPathSelector)) {\n const filteredTargetPaths = targetPathSelector.filter((it) => contains(intersectingPathSelector, it))\n if (isEmpty(filteredTargetPaths)) {\n return Results.failure(makeError())\n }\n\n result.push(filteredTargetPaths)\n } else {\n if (!contains(intersectingPathSelector, Number(targetPathSelector))) {\n return Results.failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n } else {\n if (Array.isArray(targetPathSelector)) {\n if (targetPathSelector.length !== 1) {\n return Results.failure(makeError())\n }\n\n const targetPathSelectorIndex = only(targetPathSelector)\n if (targetPathSelectorIndex !== Number(intersectingPathSelector)) {\n return Results.failure(makeError())\n }\n\n result.push(targetPathSelector)\n } else {\n if (targetPathSelector !== intersectingPathSelector) {\n return Results.failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n }\n\n index++\n }\n\n return Results.success(of(result))\n}\n\n// JOHN this needs to do a type resolution step...\nexport const intersect = <TargetPath extends TypePathType, IntersectingPath extends TypePathType>(\n targetPath: TypePath<TargetPath>,\n intersectingPath: TypePath<IntersectingPath>\n): TypePath => {\n const result = intersectAny(targetPath, intersectingPath)\n Results.assertSuccess(result)\n return result\n}\n"],"mappings":";AACA,SAAS,cAAc;AACvB,OAAO,SAAS;AAYhB,SAAS,OAAO,gBAAgB;AAChC,SAAS,gBAAgB;AACzB,SAAS,UAAU,aAAa,SAAS,YAAY;AACrD,YAAY,aAAa;AAMlB,IAAM,KAAK,CAAiC,UAAyC;AAC1F,SAAO;AACT;AAEA,IAAM,gBACJ;AAEK,IAAM,OAAO,CAAmB,SAAwC;AAC7E,SAAO,cAAc,KAAK,IAAI,GAAG,MAAM,yCAAyC,IAAI,EAAE;AAEtF,MAAI,SAAS,IAAI;AACf,WAAO,CAAC;AAAA,E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UAAU,CAAC;AAAA,QACpC;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC;AAAA,IACF,OAAO;AACL,UAAI,MAAM,QAAQ,kBAAkB,GAAG;AACrC,YAAI,mBAAmB,WAAW,GAAG;AACnC,iBAAe,gBAAQ,UAAU,CAAC;AAAA,QACpC;AAEA,cAAM,0BAA0B,KAAK,kBAAkB;AACvD,YAAI,4BAA4B,OAAO,wBAAwB,GAAG;AAChE,iBAAe,gBAAQ,UAAU,CAAC;AAAA,QACpC;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC,OAAO;AACL,YAAI,uBAAuB,0BAA0B;AACnD,iBAAe,gBAAQ,UAAU,CAAC;AAAA,QACpC;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC;AAAA,IACF;AAEA;AAAA,EACF;AAEA,SAAe,gBAAQ,GAAG,MAAM,CAAC;AACnC;AAGO,IAAM,YAAY,CACvB,YACA,qBACa;AACb,QAAM,SAAS,aAAa,YAAY,gBAAgB;AACxD,EAAQ,sBAAc,MAAM;AAC5B,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/object/type-path.ts"],"sourcesContent":["import { TaggedType } from '@bessemer/cornerstone/types'\nimport * as Assertions from '@bessemer/cornerstone/assertion'\nimport Zod from 'zod'\nimport {\n IndexSelector,\n InferTypePath,\n NameSelector,\n ParseTypePath,\n TypePathConcreteType,\n TypePathGet,\n TypePathSelector,\n TypePathType,\n WildcardSelector,\n} from '@bessemer/cornerstone/object/type-path-type'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport * as Maths from '@bessemer/cornerstone/math'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\n\n// JOHN this probably should be brought into the structured transform regime\nexport type TypePath<T extends TypePathType = TypePathType> = TaggedType<TypePathConcreteType, ['TypePath', T]>\n\nexport const of = <T extends TypePathConcreteType>(value: T): TypePath<InferTypePath<T>> => {\n return value as TypePath<InferTypePath<T>>\n}\n\nconst TypePathRegex =\n /^(?:[a-zA-Z_$][a-zA-Z0-9_$]*|\\*|\\d+|\\[\\s*(?:\\*|\\d+(?:\\s*,\\s*\\d+)*)\\s*])(?:\\.(?:[a-zA-Z_$][a-zA-Z0-9_$]*|\\*|\\d+)|\\[\\s*(?:\\*|\\d+(?:\\s*,\\s*\\d+)*)\\s*])*$|^$/\n\nexport const from = <T extends string>(path: T): TypePath<ParseTypePath<T>> => {\n Assertions.assert(TypePathRegex.test(path), () => `Unable to parse TypePath from string: ${path}`)\n\n if (path === '') {\n return [] as TypePath<ParseTypePath<T>>\n }\n\n const segments: Array<string | Array<string | number>> = []\n let current = ''\n let i = 0\n\n while (i < path.length) {\n const char = path[i]\n\n if (char === '.') {\n if (current) {\n segments.push(current)\n current = ''\n }\n i++\n } else if (char === '[') {\n if (current) {\n segments.push(current)\n current = ''\n }\n\n // Find the matching closing bracket\n let bracketContent = ''\n i++ // Skip opening bracket\n let depth = 1\n\n while (i < path.length && depth > 0) {\n const bracketChar = path[i]\n if (bracketChar === '[') {\n depth++\n } else if (bracketChar === ']') {\n depth--\n }\n\n if (depth > 0) {\n bracketContent += bracketChar\n }\n i++\n }\n\n if (bracketContent === '*') {\n segments.push('*')\n } else {\n const indices = bracketContent\n .split(',')\n .map((s) => s.trim())\n .map((s) => parseInt(s, 10))\n\n segments.push(indices)\n }\n } else {\n current += char\n i++\n }\n }\n\n // Add any remaining current segment\n if (current) {\n segments.push(current)\n }\n\n return segments as TypePath<ParseTypePath<T>>\n}\n\nexport const Schema = Zod.union([Zod.array(Zod.string()), Zod.string()]).transform((it) => {\n if (Array.isArray(it)) {\n return of(it)\n } else {\n return from(it)\n }\n})\n\nexport const getValue = <T extends TypePathType, N>(path: TypePath<T>, object: N): TypePathGet<T, N> => {\n let current: unknown = object\n let collectorMode = false\n\n for (const selector of path) {\n if (Objects.isNil(current)) {\n return undefined as TypePathGet<T, N>\n }\n\n if (collectorMode) {\n if (!Array.isArray(current)) {\n throw new Error('Illegal State - in collectorMode but current value is not an Array')\n }\n\n const result = current.flatMap((it) => {\n const [value, isCollecting] = evaluateSelector(selector, it)\n if (isCollecting) {\n return value\n } else {\n return [value]\n }\n })\n\n current = result\n } else {\n const [result, isCollecting] = evaluateSelector(selector, current)\n current = result\n collectorMode = isCollecting\n }\n }\n\n return current as TypePathGet<T, N>\n}\n\nconst evaluateSelector = (selector: TypePathSelector, current: unknown): [unknown, boolean] => {\n if (isWildcardSelector(selector)) {\n return evaluateWildcardSelector(current)\n }\n\n if (Array.isArray(selector)) {\n return evaluateIndexSelector(selector as IndexSelector, current)\n }\n\n return evaluateNameSelector(selector, current)\n}\n\nconst evaluateNameSelector = (selector: NameSelector, current: unknown): [unknown, boolean] => {\n if (Array.isArray(current)) {\n const numberSelector = Number(selector)\n Assertions.assert(Maths.isNumber(numberSelector), () => `Can't apply non-numeric selector: ${selector} to array: ${current}`)\n return evaluateIndexSelector([numberSelector], current)\n }\n\n if (!Objects.isObject(current)) {\n return [undefined, false]\n }\n\n return [current[selector], false]\n}\n\nconst evaluateWildcardSelector = (current: unknown): [unknown, boolean] => {\n if (Array.isArray(current)) {\n return [current, true]\n }\n\n if (Objects.isObject(current)) {\n throw new Error('Wildcard operations on Objects is not yet supported')\n }\n\n throw new Error(`Unable to apply wildcard operator to value: ${current}`)\n}\n\nconst evaluateIndexSelector = (selector: IndexSelector, current: unknown): [unknown, boolean] => {\n if (!Array.isArray(current)) {\n throw new Error(`Unable to apply index operator to value: ${current}`)\n }\n\n if (selector.length === 1) {\n return [current[Arrays.only(selector)], false]\n }\n\n const indexSelector = selector as IndexSelector\n const result = indexSelector.map((it) => current[it])\n return [result, true]\n}\n\nexport const isWildcardSelector = (selector: TypePathSelector): selector is WildcardSelector => {\n return selector === '*'\n}\n\nexport const matches = <MatchingPath extends TypePathType>(\n targetPath: TypePath,\n matchingPath: TypePath<MatchingPath>\n): targetPath is TypePath<MatchingPath> => {\n if (targetPath.length < matchingPath.length) {\n return false\n }\n\n let index = 0\n for (const targetPathSelector of targetPath) {\n const matchingPathSelector = matchingPath[index]\n\n if (Objects.isNil(matchingPathSelector)) {\n return true\n } else if (isWildcardSelector(matchingPathSelector)) {\n // Matching path wildcards always match - they're wild\n } else if (isWildcardSelector(targetPathSelector)) {\n return false\n } else if (Array.isArray(matchingPathSelector)) {\n if (Array.isArray(targetPathSelector)) {\n if (!Arrays.containsAll(matchingPathSelector, targetPathSelector)) {\n return false\n }\n } else {\n if (!Arrays.contains(matchingPathSelector, Number(targetPathSelector))) {\n return false\n }\n }\n } else {\n if (Array.isArray(targetPathSelector)) {\n if (targetPathSelector.length !== 1) {\n return false\n }\n\n const targetPathSelectorIndex = Arrays.only(targetPathSelector)\n if (targetPathSelectorIndex !== Number(matchingPathSelector)) {\n return false\n }\n } else {\n if (targetPathSelector !== matchingPathSelector) {\n return false\n }\n }\n }\n\n index++\n }\n\n return true\n}\n\nexport const intersectAny = (targetPath: TypePath, intersectingPath: TypePath): Result<TypePath> => {\n if (targetPath.length < intersectingPath.length) {\n return Results.failure(new Error(`TypePath: ${intersectingPath} can't intersect target TypePath: ${targetPath}`))\n }\n\n let index = 0\n let result: TypePathConcreteType = []\n for (const targetPathSelector of targetPath) {\n const intersectingPathSelector = intersectingPath[index]\n const makeError = () =>\n new Error(`Path mismatch when intersecting. targetPath: ${targetPathSelector} does not match intersectingPath: ${intersectingPathSelector}`)\n\n if (Objects.isNil(intersectingPathSelector)) {\n return Results.success(of(result))\n } else if (isWildcardSelector(intersectingPathSelector)) {\n result.push(targetPathSelector)\n } else if (isWildcardSelector(targetPathSelector)) {\n return Results.failure(makeError())\n } else if (Array.isArray(intersectingPathSelector)) {\n if (Array.isArray(targetPathSelector)) {\n const filteredTargetPaths = targetPathSelector.filter((it) => Arrays.contains(intersectingPathSelector, it))\n if (Arrays.isEmpty(filteredTargetPaths)) {\n return Results.failure(makeError())\n }\n\n result.push(filteredTargetPaths)\n } else {\n if (!Arrays.contains(intersectingPathSelector, Number(targetPathSelector))) {\n return Results.failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n } else {\n if (Array.isArray(targetPathSelector)) {\n if (targetPathSelector.length !== 1) {\n return Results.failure(makeError())\n }\n\n const targetPathSelectorIndex = Arrays.only(targetPathSelector)\n if (targetPathSelectorIndex !== Number(intersectingPathSelector)) {\n return Results.failure(makeError())\n }\n\n result.push(targetPathSelector)\n } else {\n if (targetPathSelector !== intersectingPathSelector) {\n return Results.failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n }\n\n index++\n }\n\n return Results.success(of(result))\n}\n\n// JOHN this needs to do a type resolution step...\nexport const intersect = <TargetPath extends TypePathType, IntersectingPath extends TypePathType>(\n targetPath: TypePath<TargetPath>,\n intersectingPath: TypePath<IntersectingPath>\n): TypePath => {\n const result = intersectAny(targetPath, intersectingPath)\n Results.assertSuccess(result)\n return result\n}\n"],"mappings":";AACA,YAAY,gBAAgB;AAC5B,OAAO,SAAS;AAYhB,YAAY,aAAa;AACzB,YAAY,WAAW;AACvB,YAAY,YAAY;AACxB,YAAY,aAAa;AAMlB,IAAM,KAAK,CAAiC,UAAyC;AAC1F,SAAO;AACT;AAEA,IAAM,gBACJ;AAEK,IAAM,OAAO,CAAmB,SAAwC;AAC7E,EAAW,kBAAO,cAAc,KAAK,IAAI,GAAG,MAAM,yCAAyC,IAAI,EAAE;AAEjG,MAAI,SAAS,IAAI;AACf,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,WAAmD,CAAC;AAC1D,MAAI,UAAU;AACd,MAAI,IAAI;AAER,SAAO,IAAI,KAAK,QAAQ;AACtB,UAAM,OAAO,KAAK,CAAC;AAEnB,QAAI,SAAS,KAAK;AAChB,UAAI,SAAS;AACX,iBAAS,KAAK,OAAO;AACrB,kBAAU;AAAA,MACZ;AACA;AAAA,IACF,WAAW,SAAS,KAAK;AACvB,UAAI,SAAS;AACX,iBAAS,KAAK,OAAO;AACrB,kBAAU;AAAA,MACZ;AAGA,UAAI,iBA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,QACpC;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC,OAAO;AACL,YAAI,uBAAuB,0BAA0B;AACnD,iBAAe,gBAAQ,UAAU,CAAC;AAAA,QACpC;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC;AAAA,IACF;AAEA;AAAA,EACF;AAEA,SAAe,gBAAQ,GAAG,MAAM,CAAC;AACnC;AAGO,IAAM,YAAY,CACvB,YACA,qBACa;AACb,QAAM,SAAS,aAAa,YAAY,gBAAgB;AACxD,EAAQ,sBAAc,MAAM;AAC5B,SAAO;AACT;","names":[]}
package/dist/patch.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  Expressions,
5
5
  NumericExpressions
6
6
  } from "@bessemer/cornerstone/expression";
7
- import { deepMergeWith, isNil, isObject } from "@bessemer/cornerstone/object";
7
+ import * as Objects from "@bessemer/cornerstone/object";
8
8
  var PatchType = /* @__PURE__ */ ((PatchType2) => {
9
9
  PatchType2["Set"] = "Set";
10
10
  PatchType2["Apply"] = "Apply";
@@ -63,11 +63,11 @@ var resolve = (value, patches, evaluate) => {
63
63
  return resolveWithDetails(value, patches, evaluate).value;
64
64
  };
65
65
  var applyPatch = (value, patch2, evaluate) => {
66
- return deepMergeWith(value, patch2, (value2, patch3) => {
67
- if (isNil(patch3)) {
66
+ return Objects.deepMergeWith(value, patch2, (value2, patch3) => {
67
+ if (Objects.isNil(patch3)) {
68
68
  return value2;
69
69
  }
70
- if (!isObject(patch3) || !("_PatchType" in patch3)) {
70
+ if (!Objects.isObject(patch3) || !("_PatchType" in patch3)) {
71
71
  return void 0;
72
72
  }
73
73
  return evaluate(resolve(value2, [patch3], evaluate));
package/dist/patch.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/patch.ts"],"sourcesContent":["import {\n ArrayExpressions,\n EvaluateExpression,\n Expression,\n Expressions,\n NumericExpressions,\n ReducingExpression,\n} from '@bessemer/cornerstone/expression'\nimport { UnknownRecord } from 'type-fest'\nimport { deepMergeWith, isNil, isObject } from '@bessemer/cornerstone/object'\n\nexport enum PatchType {\n Set = 'Set',\n Apply = 'Apply',\n Patch = 'Patch',\n}\n\nexport type SetPatch<T> = {\n _PatchType: PatchType.Set\n value: Expression<T>\n}\n\nexport type ApplyPatch<T> = {\n _PatchType: PatchType.Apply\n value: Expression<T>\n reducer: ReducingExpression<T, T>\n}\n\nexport type PatchPatch<T> = {\n _PatchType: PatchType.Patch\n patch: Patchable<T>\n}\n\nexport type Patch<T> = SetPatch<T> | ApplyPatch<T> | PatchPatch<T>\n\nexport type PatchValue<T> = {\n value: T\n patch: Patch<T>\n}\n\nexport type Patchable<T> = {\n [P in keyof T]?: T[P] extends Array<infer U>\n ? Patch<U[]> | Patchable<U[]>\n : T[P] extends object | undefined\n ? Patch<T[P]> | Patchable<T[P]>\n : Patch<T[P]> | T[P]\n}\n\nexport const set = <T>(value: Expression<T>): Patch<T> => {\n return {\n _PatchType: PatchType.Set,\n value: value as any,\n }\n}\n\nexport const apply = <T>(value: Expression<T>, reducer: ReducingExpression<T, T>): Patch<T> => {\n return {\n _PatchType: PatchType.Apply,\n value,\n reducer,\n }\n}\n\nexport const patch = <T extends UnknownRecord, N extends Patchable<T> = Patchable<T>>(patch: N): Patch<T> => {\n return {\n _PatchType: PatchType.Patch,\n patch,\n }\n}\n\nexport const sum = (value: Expression<number>): Patch<number> => {\n return apply(value, Expressions.reference(NumericExpressions.SumExpression))\n}\n\nexport const multiply = (value: Expression<number>): Patch<number> => {\n return apply(value, Expressions.reference(NumericExpressions.MultiplyExpression))\n}\n\nexport const concatenate = <T extends Array<Expression<unknown>>>(value: Expression<T>): Patch<T> => {\n return apply(value, Expressions.reference(ArrayExpressions.ConcatenateExpression)) as Patch<T>\n}\n\nexport type ResolvePatchesResult<T> = {\n value: T\n patchValues: Array<PatchValue<T>>\n}\n\nexport const resolveWithDetails = <T>(value: T, patches: Array<Patch<T>>, evaluate: EvaluateExpression): ResolvePatchesResult<T> => {\n let currentValue: T = value\n\n const patchValues = patches.map((patch) => {\n switch (patch._PatchType) {\n case PatchType.Set:\n currentValue = evaluate(patch.value)\n break\n case PatchType.Apply:\n currentValue = evaluate(Expressions.dereference(patch.reducer, [currentValue, patch.value]))\n break\n case PatchType.Patch:\n currentValue = applyPatch(currentValue, patch.patch, evaluate)\n break\n default:\n throw new Error(`Unrecognized PatchType for value: ${JSON.stringify(it)}`)\n }\n\n return { value: currentValue, patch }\n })\n\n return { value: currentValue, patchValues }\n}\n\nexport const resolve = <T>(value: T, patches: Array<Patch<T>>, evaluate: EvaluateExpression): T => {\n return resolveWithDetails(value, patches, evaluate).value\n}\n\nconst applyPatch = <T>(value: T, patch: Patchable<T>, evaluate: EvaluateExpression): T => {\n return deepMergeWith(value, patch, (value, patch) => {\n if (isNil(patch)) {\n return value\n }\n\n if (!isObject(patch) || !('_PatchType' in patch)) {\n return undefined\n }\n\n return evaluate(resolve(value, [patch as Patch<T>], evaluate))\n })\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,eAAe,OAAO,gBAAgB;AAExC,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,SAAM;AACN,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AAqCL,IAAM,MAAM,CAAI,UAAmC;AACxD,SAAO;AAAA,IACL,YAAY;AAAA,IACZ;AAAA,EACF;AACF;AAEO,IAAM,QAAQ,CAAI,OAAsB,YAAgD;AAC7F,SAAO;AAAA,IACL,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AACF;AAEO,IAAM,QAAQ,CAAiEC,WAAuB;AAC3G,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAAA;AAAA,EACF;AACF;AAEO,IAAM,MAAM,CAAC,UAA6C;AAC/D,SAAO,MAAM,OAAO,YAAY,UAAU,mBAAmB,aAAa,CAAC;AAC7E;AAEO,IAAM,WAAW,CAAC,UAA6C;AACpE,SAAO,MAAM,OAAO,YAAY,UAAU,mBAAmB,kBAAkB,CAAC;AAClF;AAEO,IAAM,cAAc,CAAuC,UAAmC;AACnG,SAAO,MAAM,OAAO,YAAY,UAAU,iBAAiB,qBAAqB,CAAC;AACnF;AAOO,IAAM,qBAAqB,CAAI,OAAU,SAA0B,aAA0D;AAClI,MAAI,eAAkB;AAEtB,QAAM,cAAc,QAAQ,IAAI,CAACA,WAAU;AACzC,YAAQA,OAAM,YAAY;AAAA,MACxB,KAAK;AACH,uBAAe,SAASA,OAAM,KAAK;AACnC;AAAA,MACF,KAAK;AACH,uBAAe,SAAS,YAAY,YAAYA,OAAM,SAAS,CAAC,cAAcA,OAAM,KAAK,CAAC,CAAC;AAC3F;AAAA,MACF,KAAK;AACH,uBAAe,WAAW,cAAcA,OAAM,OAAO,QAAQ;AAC7D;AAAA,MACF;AACE,cAAM,IAAI,MAAM,qCAAqC,KAAK,UAAU,EAAE,CAAC,EAAE;AAAA,IAC7E;AAEA,WAAO,EAAE,OAAO,cAAc,OAAAA,OAAM;AAAA,EACtC,CAAC;AAED,SAAO,EAAE,OAAO,cAAc,YAAY;AAC5C;AAEO,IAAM,UAAU,CAAI,OAAU,SAA0B,aAAoC;AACjG,SAAO,mBAAmB,OAAO,SAAS,QAAQ,EAAE;AACtD;AAEA,IAAM,aAAa,CAAI,OAAUA,QAAqB,aAAoC;AACxF,SAAO,cAAc,OAAOA,QAAO,CAACC,QAAOD,WAAU;AACnD,QAAI,MAAMA,MAAK,GAAG;AAChB,aAAOC;AAAA,IACT;AAEA,QAAI,CAAC,SAASD,MAAK,KAAK,EAAE,gBAAgBA,SAAQ;AAChD,aAAO;AAAA,IACT;AAEA,WAAO,SAAS,QAAQC,QAAO,CAACD,MAAiB,GAAG,QAAQ,CAAC;AAAA,EAC/D,CAAC;AACH;","names":["PatchType","patch","value"]}
1
+ {"version":3,"sources":["../src/patch.ts"],"sourcesContent":["import {\n ArrayExpressions,\n EvaluateExpression,\n Expression,\n Expressions,\n NumericExpressions,\n ReducingExpression,\n} from '@bessemer/cornerstone/expression'\nimport { UnknownRecord } from 'type-fest'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport enum PatchType {\n Set = 'Set',\n Apply = 'Apply',\n Patch = 'Patch',\n}\n\nexport type SetPatch<T> = {\n _PatchType: PatchType.Set\n value: Expression<T>\n}\n\nexport type ApplyPatch<T> = {\n _PatchType: PatchType.Apply\n value: Expression<T>\n reducer: ReducingExpression<T, T>\n}\n\nexport type PatchPatch<T> = {\n _PatchType: PatchType.Patch\n patch: Patchable<T>\n}\n\nexport type Patch<T> = SetPatch<T> | ApplyPatch<T> | PatchPatch<T>\n\nexport type PatchValue<T> = {\n value: T\n patch: Patch<T>\n}\n\nexport type Patchable<T> = {\n [P in keyof T]?: T[P] extends Array<infer U>\n ? Patch<U[]> | Patchable<U[]>\n : T[P] extends object | undefined\n ? Patch<T[P]> | Patchable<T[P]>\n : Patch<T[P]> | T[P]\n}\n\nexport const set = <T>(value: Expression<T>): Patch<T> => {\n return {\n _PatchType: PatchType.Set,\n value: value as any,\n }\n}\n\nexport const apply = <T>(value: Expression<T>, reducer: ReducingExpression<T, T>): Patch<T> => {\n return {\n _PatchType: PatchType.Apply,\n value,\n reducer,\n }\n}\n\nexport const patch = <T extends UnknownRecord, N extends Patchable<T> = Patchable<T>>(patch: N): Patch<T> => {\n return {\n _PatchType: PatchType.Patch,\n patch,\n }\n}\n\nexport const sum = (value: Expression<number>): Patch<number> => {\n return apply(value, Expressions.reference(NumericExpressions.SumExpression))\n}\n\nexport const multiply = (value: Expression<number>): Patch<number> => {\n return apply(value, Expressions.reference(NumericExpressions.MultiplyExpression))\n}\n\nexport const concatenate = <T extends Array<Expression<unknown>>>(value: Expression<T>): Patch<T> => {\n return apply(value, Expressions.reference(ArrayExpressions.ConcatenateExpression)) as Patch<T>\n}\n\nexport type ResolvePatchesResult<T> = {\n value: T\n patchValues: Array<PatchValue<T>>\n}\n\nexport const resolveWithDetails = <T>(value: T, patches: Array<Patch<T>>, evaluate: EvaluateExpression): ResolvePatchesResult<T> => {\n let currentValue: T = value\n\n const patchValues = patches.map((patch) => {\n switch (patch._PatchType) {\n case PatchType.Set:\n currentValue = evaluate(patch.value)\n break\n case PatchType.Apply:\n currentValue = evaluate(Expressions.dereference(patch.reducer, [currentValue, patch.value]))\n break\n case PatchType.Patch:\n currentValue = applyPatch(currentValue, patch.patch, evaluate)\n break\n default:\n throw new Error(`Unrecognized PatchType for value: ${JSON.stringify(it)}`)\n }\n\n return { value: currentValue, patch }\n })\n\n return { value: currentValue, patchValues }\n}\n\nexport const resolve = <T>(value: T, patches: Array<Patch<T>>, evaluate: EvaluateExpression): T => {\n return resolveWithDetails(value, patches, evaluate).value\n}\n\nconst applyPatch = <T>(value: T, patch: Patchable<T>, evaluate: EvaluateExpression): T => {\n return Objects.deepMergeWith(value, patch, (value, patch) => {\n if (Objects.isNil(patch)) {\n return value\n }\n\n if (!Objects.isObject(patch) || !('_PatchType' in patch)) {\n return undefined\n }\n\n return evaluate(resolve(value, [patch as Patch<T>], evaluate))\n })\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OAEK;AAEP,YAAY,aAAa;AAElB,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,SAAM;AACN,EAAAA,WAAA,WAAQ;AACR,EAAAA,WAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AAqCL,IAAM,MAAM,CAAI,UAAmC;AACxD,SAAO;AAAA,IACL,YAAY;AAAA,IACZ;AAAA,EACF;AACF;AAEO,IAAM,QAAQ,CAAI,OAAsB,YAAgD;AAC7F,SAAO;AAAA,IACL,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF;AACF;AAEO,IAAM,QAAQ,CAAiEC,WAAuB;AAC3G,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAAA;AAAA,EACF;AACF;AAEO,IAAM,MAAM,CAAC,UAA6C;AAC/D,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chType","patch","value"]}
package/dist/promise.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // src/promise.ts
2
- import { isNil } from "@bessemer/cornerstone/object";
2
+ import * as Objects from "@bessemer/cornerstone/object";
3
3
  import { executeAsync } from "@bessemer/cornerstone/internal";
4
4
  var isPromise = (element) => {
5
- if (isNil(element)) {
5
+ if (Objects.isNil(element)) {
6
6
  return false;
7
7
  }
8
8
  return typeof element.then === "function";
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/promise.ts"],"sourcesContent":["import { isNil } from '@bessemer/cornerstone/object'\nimport { Promisable } from 'type-fest'\nimport { executeAsync } from '@bessemer/cornerstone/internal'\n\nexport type PromiseContext<T> = { promise: Promise<T>; resolve: (value: T) => void; reject: (reason?: any) => void }\n\nexport const isPromise = <T>(element: Promisable<T>): element is PromiseLike<T> => {\n if (isNil(element)) {\n return false\n }\n\n return typeof (element as Promise<T>).then === 'function'\n}\n\nexport const map = <T, N>(value: Promisable<T>, mapper: (value: T) => N): Promisable<N> => {\n if (isPromise(value)) {\n return executeAsync(async () => mapper(await value))\n } else {\n return mapper(value)\n }\n}\n\nexport const toPromise = <T>(element: T | Promise<T>): Promise<T> => {\n if (isPromise(element)) {\n return element\n }\n\n const { resolve, promise } = create<T>()\n resolve(element)\n return promise\n}\n\nexport const create = <T>(): PromiseContext<T> => {\n let resolveVar\n let rejectVar\n const promise = new Promise<T>((resolve, reject) => {\n resolveVar = resolve\n rejectVar = reject\n })\n\n return { promise, resolve: resolveVar!, reject: rejectVar! }\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAEtB,SAAS,oBAAoB;AAItB,IAAM,YAAY,CAAI,YAAsD;AACjF,MAAI,MAAM,OAAO,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,SAAO,OAAQ,QAAuB,SAAS;AACjD;AAEO,IAAM,MAAM,CAAO,OAAsB,WAA2C;AACzF,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO,aAAa,YAAY,OAAO,MAAM,KAAK,CAAC;AAAA,EACrD,OAAO;AACL,WAAO,OAAO,KAAK;AAAA,EACrB;AACF;AAEO,IAAM,YAAY,CAAI,YAAwC;AACnE,MAAI,UAAU,OAAO,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,SAAS,QAAQ,IAAI,OAAU;AACvC,UAAQ,OAAO;AACf,SAAO;AACT;AAEO,IAAM,SAAS,MAA4B;AAChD,MAAI;AACJ,MAAI;AACJ,QAAM,UAAU,IAAI,QAAW,CAAC,SAAS,WAAW;AAClD,iBAAa;AACb,gBAAY;AAAA,EACd,CAAC;AAED,SAAO,EAAE,SAAS,SAAS,YAAa,QAAQ,UAAW;AAC7D;","names":[]}
1
+ {"version":3,"sources":["../src/promise.ts"],"sourcesContent":["import * as Objects from '@bessemer/cornerstone/object'\nimport { Promisable } from 'type-fest'\nimport { executeAsync } from '@bessemer/cornerstone/internal'\n\nexport type PromiseContext<T> = { promise: Promise<T>; resolve: (value: T) => void; reject: (reason?: any) => void }\n\nexport const isPromise = <T>(element: Promisable<T>): element is PromiseLike<T> => {\n if (Objects.isNil(element)) {\n return false\n }\n\n return typeof (element as Promise<T>).then === 'function'\n}\n\nexport const map = <T, N>(value: Promisable<T>, mapper: (value: T) => N): Promisable<N> => {\n if (isPromise(value)) {\n return executeAsync(async () => mapper(await value))\n } else {\n return mapper(value)\n }\n}\n\nexport const toPromise = <T>(element: T | Promise<T>): Promise<T> => {\n if (isPromise(element)) {\n return element\n }\n\n const { resolve, promise } = create<T>()\n resolve(element)\n return promise\n}\n\nexport const create = <T>(): PromiseContext<T> => {\n let resolveVar\n let rejectVar\n const promise = new Promise<T>((resolve, reject) => {\n resolveVar = resolve\n rejectVar = reject\n })\n\n return { promise, resolve: resolveVar!, reject: rejectVar! }\n}\n"],"mappings":";AAAA,YAAY,aAAa;AAEzB,SAAS,oBAAoB;AAItB,IAAM,YAAY,CAAI,YAAsD;AACjF,MAAY,cAAM,OAAO,GAAG;AAC1B,WAAO;AAAA,EACT;AAEA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AAM,OAAO,GAAI,CAAC,SAAS,aAAa,EAAE,YAAY,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,KAAG,CAGlG,CAAA"}
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../src/property.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAGtD,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,aAAa,IAAI;IACpD,MAAM,EAAE,CAAC,CAAA;IACT,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAA;CACvD,CAAA;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7D,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,aAAa,EAAE,QAAQ,CAAC,EAAE,YAAY,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,CAAC,CAWvH,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,aAAa,EAAE,YAAY,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,KAAG,CAGlG,CAAA"}
package/dist/property.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // src/property.ts
2
- import { resolve as resolveTag, serializeTags } from "@bessemer/cornerstone/tag";
3
- import { deepMergeAll } from "@bessemer/cornerstone/object";
2
+ import * as Tags from "@bessemer/cornerstone/tag";
3
+ import * as Objects from "@bessemer/cornerstone/object";
4
4
  var properties = (values, overrides) => {
5
5
  const propertyOverrideEntries = (overrides ?? []).map((override) => {
6
- return [serializeTags(override.tags), override];
6
+ return [Tags.serializeTags(override.tags), override];
7
7
  });
8
8
  const propertyOverrides = Object.fromEntries(propertyOverrideEntries);
9
9
  return {
@@ -11,12 +11,12 @@ var properties = (values, overrides) => {
11
11
  overrides: propertyOverrides
12
12
  };
13
13
  };
14
- var resolve = (properties2, tags) => {
15
- const overrides = resolveTag(Object.values(properties2.overrides), tags);
16
- return deepMergeAll([properties2.values, ...overrides.reverse()]);
14
+ var resolve2 = (properties2, tags) => {
15
+ const overrides = Tags.resolve(Object.values(properties2.overrides), tags);
16
+ return Objects.deepMergeAll([properties2.values, ...overrides.reverse()]);
17
17
  };
18
18
  export {
19
19
  properties,
20
- resolve
20
+ resolve2 as resolve
21
21
  };
22
22
  //# sourceMappingURL=property.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/property.ts"],"sourcesContent":["import { resolve as resolveTag, SerializedTags, serializeTags, Tag, TaggedValue } from '@bessemer/cornerstone/tag'\nimport { PartialDeep, UnknownRecord } from 'type-fest'\nimport { deepMergeAll } from '@bessemer/cornerstone/object'\n\nexport type PropertyRecord<T extends UnknownRecord> = {\n values: T\n overrides: Record<SerializedTags, PropertyOverride<T>>\n}\n\nexport type PropertyOverride<T> = TaggedValue<PartialDeep<T>>\n\nexport const properties = <T extends UnknownRecord>(values: T, overrides?: Array<PropertyOverride<T>>): PropertyRecord<T> => {\n const propertyOverrideEntries = (overrides ?? []).map((override) => {\n return [serializeTags(override.tags), override]\n })\n\n const propertyOverrides: Record<SerializedTags, PropertyOverride<T>> = Object.fromEntries(propertyOverrideEntries)\n\n return {\n values,\n overrides: propertyOverrides,\n }\n}\n\nexport const resolve = <T extends UnknownRecord>(properties: PropertyRecord<T>, tags: Array<Tag>): T => {\n const overrides = resolveTag(Object.values(properties.overrides), tags)\n return deepMergeAll([properties.values, ...overrides.reverse()]) as T\n}\n"],"mappings":";AAAA,SAAS,WAAW,YAA4B,qBAAuC;AAEvF,SAAS,oBAAoB;AAStB,IAAM,aAAa,CAA0B,QAAW,cAA8D;AAC3H,QAAM,2BAA2B,aAAa,CAAC,GAAG,IAAI,CAAC,aAAa;AAClE,WAAO,CAAC,cAAc,SAAS,IAAI,GAAG,QAAQ;AAAA,EAChD,CAAC;AAED,QAAM,oBAAiE,OAAO,YAAY,uBAAuB;AAEjH,SAAO;AAAA,IACL;AAAA,IACA,WAAW;AAAA,EACb;AACF;AAEO,IAAM,UAAU,CAA0BA,aAA+B,SAAwB;AACtG,QAAM,YAAY,WAAW,OAAO,OAAOA,YAAW,SAAS,GAAG,IAAI;AACtE,SAAO,aAAa,CAACA,YAAW,QAAQ,GAAG,UAAU,QAAQ,CAAC,CAAC;AACjE;","names":["properties"]}
1
+ {"version":3,"sources":["../src/property.ts"],"sourcesContent":["import * as Tags from '@bessemer/cornerstone/tag'\nimport { SerializedTags, Tag, TaggedValue } from '@bessemer/cornerstone/tag'\nimport { PartialDeep, UnknownRecord } from 'type-fest'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport type PropertyRecord<T extends UnknownRecord> = {\n values: T\n overrides: Record<SerializedTags, PropertyOverride<T>>\n}\n\nexport type PropertyOverride<T> = TaggedValue<PartialDeep<T>>\n\nexport const properties = <T extends UnknownRecord>(values: T, overrides?: Array<PropertyOverride<T>>): PropertyRecord<T> => {\n const propertyOverrideEntries = (overrides ?? []).map((override) => {\n return [Tags.serializeTags(override.tags), override]\n })\n\n const propertyOverrides: Record<SerializedTags, PropertyOverride<T>> = Object.fromEntries(propertyOverrideEntries)\n\n return {\n values,\n overrides: propertyOverrides,\n }\n}\n\nexport const resolve = <T extends UnknownRecord>(properties: PropertyRecord<T>, tags: Array<Tag>): T => {\n const overrides = Tags.resolve(Object.values(properties.overrides), tags)\n return Objects.deepMergeAll([properties.values, ...overrides.reverse()]) as T\n}\n"],"mappings":";AAAA,YAAY,UAAU;AAGtB,YAAY,aAAa;AASlB,IAAM,aAAa,CAA0B,QAAW,cAA8D;AAC3H,QAAM,2BAA2B,aAAa,CAAC,GAAG,IAAI,CAAC,aAAa;AAClE,WAAO,CAAM,mBAAc,SAAS,IAAI,GAAG,QAAQ;AAAA,EACrD,CAAC;AAED,QAAM,oBAAiE,OAAO,YAAY,uBAAuB;AAEjH,SAAO;AAAA,IACL;AAAA,IACA,WAAW;AAAA,EACb;AACF;AAEO,IAAMA,WAAU,CAA0BC,aAA+B,SAAwB;AACtG,QAAM,YAAiB,aAAQ,OAAO,OAAOA,YAAW,SAAS,GAAG,IAAI;AACxE,SAAe,qBAAa,CAACA,YAAW,QAAQ,GAAG,UAAU,QAAQ,CAAC,CAAC;AACzE;","names":["resolve","properties"]}
package/dist/proxy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/proxy.ts
2
- import { isFunction } from "@bessemer/cornerstone/function";
2
+ import * as Functions from "@bessemer/cornerstone/function";
3
3
  var extend = (target, extensions) => {
4
4
  return new Proxy(target, {
5
5
  get(target2, prop, receiver) {
@@ -7,7 +7,7 @@ var extend = (target, extensions) => {
7
7
  return extensions[prop];
8
8
  }
9
9
  const value = Reflect.get(target2, prop, receiver);
10
- if (isFunction(value)) {
10
+ if (Functions.isFunction(value)) {
11
11
  return value.bind(target2);
12
12
  }
13
13
  return value;
package/dist/proxy.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/proxy.ts"],"sourcesContent":["import { isFunction } from '@bessemer/cornerstone/function'\n\nexport const extend = <Target extends object, E extends Record<string, unknown>>(target: Target, extensions: E): Target & E => {\n return new Proxy(target, {\n get(target, prop, receiver) {\n if (prop in extensions) {\n return extensions[prop as string]\n }\n\n const value = Reflect.get(target, prop, receiver)\n if (isFunction(value)) {\n return value.bind(target)\n }\n\n return value\n },\n }) as Target & E\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAEpB,IAAM,SAAS,CAA2D,QAAgB,eAA8B;AAC7H,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,IAAIA,SAAQ,MAAM,UAAU;AAC1B,UAAI,QAAQ,YAAY;AACtB,eAAO,WAAW,IAAc;AAAA,MAClC;AAEA,YAAM,QAAQ,QAAQ,IAAIA,SAAQ,MAAM,QAAQ;AAChD,UAAI,WAAW,KAAK,GAAG;AACrB,eAAO,MAAM,KAAKA,OAAM;AAAA,MAC1B;AAEA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":["target"]}
1
+ {"version":3,"sources":["../src/proxy.ts"],"sourcesContent":["import * as Functions from '@bessemer/cornerstone/function'\n\nexport const extend = <Target extends object, E extends Record<string, unknown>>(target: Target, extensions: E): Target & E => {\n return new Proxy(target, {\n get(target, prop, receiver) {\n if (prop in extensions) {\n return extensions[prop as string]\n }\n\n const value = Reflect.get(target, prop, receiver)\n if (Functions.isFunction(value)) {\n return value.bind(target)\n }\n\n return value\n },\n }) as Target & E\n}\n"],"mappings":";AAAA,YAAY,eAAe;AAEpB,IAAM,SAAS,CAA2D,QAAgB,eAA8B;AAC7H,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,IAAIA,SAAQ,MAAM,UAAU;AAC1B,UAAI,QAAQ,YAAY;AACtB,eAAO,WAAW,IAAc;AAAA,MAClC;AAEA,YAAM,QAAQ,QAAQ,IAAIA,SAAQ,MAAM,QAAQ;AAChD,UAAc,qBAAW,KAAK,GAAG;AAC/B,eAAO,MAAM,KAAKA,OAAM;AAAA,MAC1B;AAEA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":["target"]}
package/dist/range.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // src/range.ts
2
2
  import Zod from "zod";
3
- import { isUndefined } from "@bessemer/cornerstone/object";
3
+ import * as Objects from "@bessemer/cornerstone/object";
4
4
  var schema = (type) => {
5
5
  return Zod.tuple([type.nullable(), type.nullable()]);
6
6
  };
7
7
  var NumericSchema = schema(Zod.number());
8
8
  var of = (bounds) => {
9
- if (isUndefined(bounds[1])) {
9
+ if (Objects.isUndefined(bounds[1])) {
10
10
  return [bounds[0], null];
11
11
  }
12
12
  return bounds;
package/dist/range.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/range.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { isUndefined } from '@bessemer/cornerstone/object'\n\n// JOHN bounds are still a mess! what about finite bounds ???\nexport type Bounds<T> = NominalType<[T | null, T | null], 'Bounds'>\nexport type BoundsInput<T> = [lower: T | null, upper?: T | null] | Bounds<T>\n\nexport const schema = <T extends ZodType>(type: T): ZodType<Bounds<Zod.infer<T>>, Bounds<Zod.infer<T>>> => {\n return Zod.tuple([type.nullable(), type.nullable()]) as any\n}\n\nexport type NumericBounds = Bounds<number>\nexport const NumericSchema = schema(Zod.number())\n\nexport type FiniteBounds<T> = [T, T]\n\nexport const of = <T>(bounds: BoundsInput<T>): Bounds<T> => {\n if (isUndefined(bounds[1])) {\n return [bounds[0], null] as Bounds<T>\n }\n\n return bounds as Bounds<T>\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAE7B,SAAS,mBAAmB;AAMrB,IAAM,SAAS,CAAoB,SAAiE;AACzG,SAAO,IAAI,MAAM,CAAC,KAAK,SAAS,GAAG,KAAK,SAAS,CAAC,CAAC;AACrD;AAGO,IAAM,gBAAgB,OAAO,IAAI,OAAO,CAAC;AAIzC,IAAM,KAAK,CAAI,WAAsC;AAC1D,MAAI,YAAY,OAAO,CAAC,CAAC,GAAG;AAC1B,WAAO,CAAC,OAAO,CAAC,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/range.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport * as Objects from '@bessemer/cornerstone/object'\n\n// JOHN bounds are still a mess! what about finite bounds ???\nexport type Bounds<T> = NominalType<[T | null, T | null], 'Bounds'>\nexport type BoundsInput<T> = [lower: T | null, upper?: T | null] | Bounds<T>\n\nexport const schema = <T extends ZodType>(type: T): ZodType<Bounds<Zod.infer<T>>, Bounds<Zod.infer<T>>> => {\n return Zod.tuple([type.nullable(), type.nullable()]) as any\n}\n\nexport type NumericBounds = Bounds<number>\nexport const NumericSchema = schema(Zod.number())\n\nexport type FiniteBounds<T> = [T, T]\n\nexport const of = <T>(bounds: BoundsInput<T>): Bounds<T> => {\n if (Objects.isUndefined(bounds[1])) {\n return [bounds[0], null] as Bounds<T>\n }\n\n return bounds as Bounds<T>\n}\n"],"mappings":";AAAA,OAAO,SAAsB;AAE7B,YAAY,aAAa;AAMlB,IAAM,SAAS,CAAoB,SAAiE;AACzG,SAAO,IAAI,MAAM,CAAC,KAAK,SAAS,GAAG,KAAK,SAAS,CAAC,CAAC;AACrD;AAGO,IAAM,gBAAgB,OAAO,IAAI,OAAO,CAAC;AAIzC,IAAM,KAAK,CAAI,WAAsC;AAC1D,MAAY,oBAAY,OAAO,CAAC,CAAC,GAAG;AAClC,WAAO,CAAC,OAAO,CAAC,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
@@ -1,5 +1,6 @@
1
1
  import { Comparator } from '@bessemer/cornerstone/comparator';
2
2
  import { TaggedType } from '@bessemer/cornerstone/types';
3
+ import * as Equalitors from '@bessemer/cornerstone/equalitor';
3
4
  export type ReferenceId<T extends string> = TaggedType<string, ['ReferenceId', T]>;
4
5
  export type Reference<T extends string> = {
5
6
  id: ReferenceId<T>;
@@ -17,5 +18,5 @@ export declare const isReference: (element: unknown) => element is Reference<str
17
18
  export declare const getReference: <T extends Reference<string>>(reference: ReferencableType<T>) => T;
18
19
  export declare const equals: <T extends string>(first: Reference<T>, second: Reference<T>) => boolean;
19
20
  export declare const comparator: <T extends string>() => Comparator<Reference<T>>;
20
- export declare const equalitor: () => import("@bessemer/cornerstone/equalitor").Equalitor<Reference<string>>;
21
+ export declare const equalitor: () => Equalitors.Equalitor<Reference<string>>;
21
22
  //# sourceMappingURL=reference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../src/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MA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AAM,CAAC,EAAE,OAAO,MAAM,KAAG,SAAS,CAAC,OAAO,IAAI,CAUnI,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,SAAS,OAAO,KAAG,OAAO,IAAI,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAO1F,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,SAAS,OAAO,KAAG,OAAO,IAAI,SAAS,CAAC,MAAM,CAOzE,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,gBAAgB,CAAC,CAAC,CAAC,KAAG,CAO1F,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,MAAM,EAAE,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,SAAS,CAAC,CAAC,CAAC,KAAG,OAEpF,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,OAAK,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAEtE,CAAA;AAED,eAAO,MAAM,SAAS,+CAAgD,CAAA"}
package/dist/reference.js CHANGED
@@ -1,35 +1,35 @@
1
1
  // src/reference.ts
2
- import { compareBy, natural } from "@bessemer/cornerstone/comparator";
3
- import { isString } from "@bessemer/cornerstone/string";
4
- import { isObject, isPresent, isUndefined } from "@bessemer/cornerstone/object";
5
- import { fromComparator } from "@bessemer/cornerstone/equalitor";
2
+ import * as Comparators from "@bessemer/cornerstone/comparator";
3
+ import * as Strings from "@bessemer/cornerstone/string";
4
+ import * as Objects from "@bessemer/cornerstone/object";
5
+ import * as Equalitors from "@bessemer/cornerstone/equalitor";
6
6
  var reference = (reference2, type, note) => {
7
- if (!isString(reference2)) {
7
+ if (!Strings.isString(reference2)) {
8
8
  return reference2;
9
9
  }
10
10
  return {
11
11
  id: reference2,
12
12
  type,
13
- ...isPresent(note) ? { note } : {}
13
+ ...Objects.isPresent(note) ? { note } : {}
14
14
  };
15
15
  };
16
16
  var isReferencable = (element) => {
17
- if (!isObject(element)) {
17
+ if (!Objects.isObject(element)) {
18
18
  return false;
19
19
  }
20
20
  const referencable = element;
21
- return !isUndefined(referencable.reference);
21
+ return !Objects.isUndefined(referencable.reference);
22
22
  };
23
23
  var isReference = (element) => {
24
- if (!isObject(element)) {
24
+ if (!Objects.isObject(element)) {
25
25
  return false;
26
26
  }
27
27
  const referencable = element;
28
- return !isUndefined(referencable.id) && !isUndefined(referencable.type) && !isUndefined(referencable.note);
28
+ return !Objects.isUndefined(referencable.id) && !Objects.isUndefined(referencable.type) && !Objects.isUndefined(referencable.note);
29
29
  };
30
30
  var getReference = (reference2) => {
31
31
  const referencable = reference2;
32
- if (isPresent(referencable.reference)) {
32
+ if (Objects.isPresent(referencable.reference)) {
33
33
  return referencable.reference;
34
34
  } else {
35
35
  return reference2;
@@ -39,9 +39,9 @@ var equals = (first, second) => {
39
39
  return first.id === second.id;
40
40
  };
41
41
  var comparator = () => {
42
- return compareBy((it) => it.id, natural());
42
+ return Comparators.compareBy((it) => it.id, Comparators.natural());
43
43
  };
44
- var equalitor = () => fromComparator(comparator());
44
+ var equalitor = () => Equalitors.fromComparator(comparator());
45
45
  export {
46
46
  comparator,
47
47
  equalitor,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/reference.ts"],"sourcesContent":["import { Comparator, compareBy, natural } from '@bessemer/cornerstone/comparator'\nimport { TaggedType } from '@bessemer/cornerstone/types'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isObject, isPresent, isUndefined } from '@bessemer/cornerstone/object'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\n\n// JOHN i, unfortunately, think the reference system is kinda dumb\nexport type ReferenceId<T extends string> = TaggedType<string, ['ReferenceId', T]>\n\nexport type Reference<T extends string> = {\n id: ReferenceId<T>\n type: T\n note?: string\n}\n\nexport type ReferenceType<T extends Reference<string>> = T | T['id']\n\nexport interface Referencable<T extends Reference<string>> {\n reference: T\n}\n\nexport type ReferencableType<T extends Reference<string>> = T | Referencable<T>\n\nexport const reference = <T extends string>(reference: Reference<T> | ReferenceId<T>, type: T, note?: string): Reference<typeof type> => {\n if (!isString(reference)) {\n return reference\n }\n\n return {\n id: reference,\n type,\n ...(isPresent(note) ? { note: note } : {}),\n }\n}\n\nexport const isReferencable = (element: unknown): element is Referencable<Reference<string>> => {\n if (!isObject(element)) {\n return false\n }\n\n const referencable = element as unknown as Referencable<Reference<string>>\n return !isUndefined(referencable.reference)\n}\n\nexport const isReference = (element: unknown): element is Reference<string> => {\n if (!isObject(element)) {\n return false\n }\n\n const referencable = element as Reference<string>\n return !isUndefined(referencable.id) && !isUndefined(referencable.type) && !isUndefined(referencable.note)\n}\n\nexport const getReference = <T extends Reference<string>>(reference: ReferencableType<T>): T => {\n const referencable = reference as Referencable<T>\n if (isPresent(referencable.reference)) {\n return referencable.reference\n } else {\n return reference as T\n }\n}\n\nexport const equals = <T extends string>(first: Reference<T>, second: Reference<T>): boolean => {\n return first.id === second.id\n}\n\nexport const comparator = <T extends string>(): Comparator<Reference<T>> => {\n return compareBy((it) => it.id, natural())\n}\n\nexport const equalitor = () => fromComparator(comparator())\n"],"mappings":";AAAA,SAAqB,WAAW,eAAe;AAE/C,SAAS,gBAAgB;AACzB,SAAS,UAAU,WAAW,mBAAmB;AACjD,SAAS,sBAAsB;AAmBxB,IAAM,YAAY,CAAmBA,YAA0C,MAAS,SAA0C;AACvI,MAAI,CAAC,SAASA,UAAS,GAAG;AACxB,WAAOA;AAAA,EACT;AAEA,SAAO;AAAA,IACL,IAAIA;AAAA,IACJ;AAAA,IACA,GAAI,UAAU,IAAI,IAAI,EAAE,KAAW,IAAI,CAAC;AAAA,EAC1C;AACF;AAEO,IAAM,iBAAiB,CAAC,YAAiE;AAC9F,MAAI,CAAC,SAAS,OAAO,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,eAAe;AACrB,SAAO,CAAC,YAAY,aAAa,SAAS;AAC5C;AAEO,IAAM,cAAc,CAAC,YAAmD;AAC7E,MAAI,CAAC,SAAS,OAAO,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,eAAe;AACrB,SAAO,CAAC,YAAY,aAAa,EAAE,KAAK,CAAC,YAAY,aAAa,IAAI,KAAK,CAAC,YAAY,aAAa,IAAI;AAC3G;AAEO,IAAM,eAAe,CAA8BA,eAAsC;AAC9F,QAAM,eAAeA;AACrB,MAAI,UAAU,aAAa,SAAS,GAAG;AACrC,WAAO,aAAa;AAAA,EACtB,OAAO;AACL,WAAOA;AAAA,EACT;AACF;AAEO,IAAM,SAAS,CAAmB,OAAqB,WAAkC;AAC9F,SAAO,MAAM,OAAO,OAAO;AAC7B;AAEO,IAAM,aAAa,MAAkD;AAC1E,SAAO,UAAU,CAAC,OAAO,GAAG,IAAI,QAAQ,CAAC;AAC3C;AAEO,IAAM,YAAY,MAAM,eAAe,WAAW,CAAC;","names":["reference"]}
1
+ {"version":3,"sources":["../src/reference.ts"],"sourcesContent":["import * as Comparators from '@bessemer/cornerstone/comparator'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { TaggedType } from '@bessemer/cornerstone/types'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\n\n// JOHN i, unfortunately, think the reference system is kinda dumb\nexport type ReferenceId<T extends string> = TaggedType<string, ['ReferenceId', T]>\n\nexport type Reference<T extends string> = {\n id: ReferenceId<T>\n type: T\n note?: string\n}\n\nexport type ReferenceType<T extends Reference<string>> = T | T['id']\n\nexport interface Referencable<T extends Reference<string>> {\n reference: T\n}\n\nexport type ReferencableType<T extends Reference<string>> = T | Referencable<T>\n\nexport const reference = <T extends string>(reference: Reference<T> | ReferenceId<T>, type: T, note?: string): Reference<typeof type> => {\n if (!Strings.isString(reference)) {\n return reference\n }\n\n return {\n id: reference,\n type,\n ...(Objects.isPresent(note) ? { note: note } : {}),\n }\n}\n\nexport const isReferencable = (element: unknown): element is Referencable<Reference<string>> => {\n if (!Objects.isObject(element)) {\n return false\n }\n\n const referencable = element as unknown as Referencable<Reference<string>>\n return !Objects.isUndefined(referencable.reference)\n}\n\nexport const isReference = (element: unknown): element is Reference<string> => {\n if (!Objects.isObject(element)) {\n return false\n }\n\n const referencable = element as Reference<string>\n return !Objects.isUndefined(referencable.id) && !Objects.isUndefined(referencable.type) && !Objects.isUndefined(referencable.note)\n}\n\nexport const getReference = <T extends Reference<string>>(reference: ReferencableType<T>): T => {\n const referencable = reference as Referencable<T>\n if (Objects.isPresent(referencable.reference)) {\n return referencable.reference\n } else {\n return reference as T\n }\n}\n\nexport const equals = <T extends string>(first: Reference<T>, second: Reference<T>): boolean => {\n return first.id === second.id\n}\n\nexport const comparator = <T extends string>(): Comparator<Reference<T>> => {\n return Comparators.compareBy((it) => it.id, Comparators.natural())\n}\n\nexport const equalitor = () => Equalitors.fromComparator(comparator())\n"],"mappings":";AAAA,YAAY,iBAAiB;AAG7B,YAAY,aAAa;AACzB,YAAY,aAAa;AACzB,YAAY,gBAAgB;AAmBrB,IAAM,YAAY,CAAmBA,YAA0C,MAAS,SAA0C;AACvI,MAAI,CAAS,iBAASA,UAAS,GAAG;AAChC,WAAOA;AAAA,EACT;AAEA,SAAO;AAAA,IACL,IAAIA;AAAA,IACJ;AAAA,IACA,GAAY,kBAAU,IAAI,IAAI,EAAE,KAAW,IAAI,CAAC;AAAA,EAClD;AACF;AAEO,IAAM,iBAAiB,CAAC,YAAiE;AAC9F,MAAI,CAAS,iBAAS,OAAO,GAAG;AAC9B,WAAO;AAAA,EACT;AAEA,QAAM,eAAe;AACrB,SAAO,CAAS,oBAAY,aAAa,SAAS;AACpD;AAEO,IAAM,cAAc,CAAC,YAAmD;AAC7E,MAAI,CAAS,iBAAS,OAAO,GAAG;AAC9B,WAAO;AAAA,EACT;AAEA,QAAM,eAAe;AACrB,SAAO,CAAS,oBAAY,aAAa,EAAE,KAAK,CAAS,oBAAY,aAAa,IAAI,KAAK,CAAS,oBAAY,aAAa,IAAI;AACnI;AAEO,IAAM,eAAe,CAA8BA,eAAsC;AAC9F,QAAM,eAAeA;AACrB,MAAY,kBAAU,aAAa,SAAS,GAAG;AAC7C,WAAO,aAAa;AAAA,EACtB,OAAO;AACL,WAAOA;AAAA,EACT;AACF;AAEO,IAAM,SAAS,CAAmB,OAAqB,WAAkC;AAC9F,SAAO,MAAM,OAAO,OAAO;AAC7B;AAEO,IAAM,aAAa,MAAkD;AAC1E,SAAmB,sBAAU,CAAC,OAAO,GAAG,IAAgB,oBAAQ,CAAC;AACnE;AAEO,IAAM,YAAY,MAAiB,0BAAe,WAAW,CAAC;","names":["reference"]}
@@ -1,6 +1,6 @@
1
1
  // src/resource-key.ts
2
2
  import Zod from "zod";
3
- import { isPresent } from "@bessemer/cornerstone/object";
3
+ import * as Objects from "@bessemer/cornerstone/object";
4
4
  var ResourceNamespaceSeparator = "/";
5
5
  var emptyNamespace = () => {
6
6
  return void 0;
@@ -15,7 +15,7 @@ var createNamespace = (value) => {
15
15
  return value;
16
16
  };
17
17
  var createCompositeNamespace = (...names) => {
18
- return names.filter(isPresent).join(ResourceNamespaceSeparator);
18
+ return names.filter(Objects.isPresent).join(ResourceNamespaceSeparator);
19
19
  };
20
20
  var ResourceNamespaceSchema = Zod.string().optional().transform(createNamespace);
21
21
  var namespaceKey = (key, namespace) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/resource-key.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport { isPresent } from '@bessemer/cornerstone/object'\n\nexport type ResourceKey = string\nconst ResourceNamespaceSeparator = '/'\n\nexport type NamespaceKey = string | undefined\nexport type ResourceNamespace<NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<NamespaceType, 'ResourceNamespace'> | undefined\n\nexport type NamespacedKey<KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<\n string,\n ['NamespacedKey', KeyType, NamespaceType]\n>\n\nexport const emptyNamespace = (): ResourceNamespace<undefined> => {\n return undefined\n}\n\nexport const createNamespace = <T extends NamespaceKey>(value: T): ResourceNamespace<T> => {\n if (value === undefined) {\n return value as any as ResourceNamespace<T>\n }\n\n if (!/^[^\\s\\/][^\\s\\/]*(?:\\/[^\\s\\/][^\\s\\/]*)*$/.test(value)) {\n throw new Error(`Unsupported Namespace format: ${value}`)\n }\n\n return value as ResourceNamespace<T>\n}\n\nexport const createCompositeNamespace = (...names: Array<ResourceNamespace>): ResourceNamespace => {\n return names.filter(isPresent).join(ResourceNamespaceSeparator) as ResourceNamespace\n}\n\nexport const ResourceNamespaceSchema = Zod.string().optional().transform(createNamespace)\n\nexport const namespaceKey = <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(\n key: KeyType,\n namespace: ResourceNamespace<NamespaceType>\n): NamespacedKey<KeyType, NamespaceType> => {\n if (namespace === undefined) {\n return encodeKey(key) as NamespacedKey<KeyType, NamespaceType>\n }\n\n return `${namespace}${ResourceNamespaceSeparator}${encodeKey(key)}` as NamespacedKey<KeyType, NamespaceType>\n}\n\nexport const namespaceKeys = <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(\n keys: Array<KeyType>,\n namespace: ResourceNamespace<NamespaceType>\n): Array<NamespacedKey<KeyType, NamespaceType>> => {\n return keys.map((it) => namespaceKey(it, namespace))\n}\n\nexport const destructureKey = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n key: NamespacedKey<KeyType, NamespaceType>\n): [KeyType, ResourceNamespace<NamespaceType>] => {\n const lastIndex = key.lastIndexOf(ResourceNamespaceSeparator)\n\n if (lastIndex !== -1) {\n const namespacePart = key.substring(0, lastIndex)\n const keyPart = key.substring(lastIndex + 1)\n\n return [decodeKey(keyPart) as KeyType, namespacePart as ResourceNamespace<NamespaceType>]\n } else {\n const keyPart = key\n return [decodeKey(keyPart) as KeyType, undefined as ResourceNamespace<NamespaceType>]\n }\n}\n\nexport const getKey = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>\n): KeyType => {\n const [key, _] = destructureKey(namespacedKey)\n return key\n}\n\nexport const getNamespace = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>\n): ResourceNamespace<NamespaceType> => {\n const [_, namespace] = destructureKey(namespacedKey)\n return namespace\n}\n\nexport const extendNamespace = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>,\n additionalNamespace: ResourceNamespace\n): NamespacedKey<KeyType> => {\n const [type, namespace] = destructureKey(namespacedKey)\n const extendedNamespace = createCompositeNamespace(additionalNamespace, namespace)\n return namespaceKey(type, extendedNamespace)\n}\n\nexport const encodeKey = (key: ResourceKey): ResourceKey => {\n return key.replace(/%/g, '%25').replace(/\\//g, '%2F')\n}\n\nexport const decodeKey = (encodedKey: ResourceKey): ResourceKey => {\n return encodedKey.replace(/%2F/g, '/').replace(/%25/g, '%')\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,SAAS,iBAAiB;AAG1B,IAAM,6BAA6B;AAU5B,IAAM,iBAAiB,MAAoC;AAChE,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAyB,UAAmC;AACzF,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,0CAA0C,KAAK,KAAK,GAAG;AAC1D,UAAM,IAAI,MAAM,iCAAiC,KAAK,EAAE;AAAA,EAC1D;AAEA,SAAO;AACT;AAEO,IAAM,2BAA2B,IAAI,UAAuD;AACjG,SAAO,MAAM,OAAO,SAAS,EAAE,KAAK,0BAA0B;AAChE;AAEO,IAAM,0BAA0B,IAAI,OAAO,EAAE,SAAS,EAAE,UAAU,eAAe;AAEjF,IAAM,eAAe,CAC1B,KACA,cAC0C;AAC1C,MAAI,cAAc,QAAW;AAC3B,WAAO,UAAU,GAAG;AAAA,EACtB;AAEA,SAAO,GAAG,SAAS,GAAG,0BAA0B,GAAG,UAAU,GAAG,CAAC;AACnE;AAEO,IAAM,gBAAgB,CAC3B,MACA,cACiD;AACjD,SAAO,KAAK,IAAI,CAAC,OAAO,aAAa,IAAI,SAAS,CAAC;AACrD;AAEO,IAAM,iBAAiB,CAC5B,QACgD;AAChD,QAAM,YAAY,IAAI,YAAY,0BAA0B;AAE5D,MAAI,cAAc,IAAI;AACpB,UAAM,gBAAgB,IAAI,UAAU,GAAG,SAAS;AAChD,UAAM,UAAU,IAAI,UAAU,YAAY,CAAC;AAE3C,WAAO,CAAC,UAAU,OAAO,GAAc,aAAiD;AAAA,EAC1F,OAAO;AACL,UAAM,UAAU;AAChB,WAAO,CAAC,UAAU,OAAO,GAAc,MAA6C;AAAA,EACtF;AACF;AAEO,IAAM,SAAS,CACpB,kBACY;AACZ,QAAM,CAAC,KAAK,CAAC,IAAI,eAAe,aAAa;AAC7C,SAAO;AACT;AAEO,IAAM,eAAe,CAC1B,kBACqC;AACrC,QAAM,CAAC,GAAG,SAAS,IAAI,eAAe,aAAa;AACnD,SAAO;AACT;AAEO,IAAM,kBAAkB,CAC7B,eACA,wBAC2B;AAC3B,QAAM,CAAC,MAAM,SAAS,IAAI,eAAe,aAAa;AACtD,QAAM,oBAAoB,yBAAyB,qBAAqB,SAAS;AACjF,SAAO,aAAa,MAAM,iBAAiB;AAC7C;AAEO,IAAM,YAAY,CAAC,QAAkC;AAC1D,SAAO,IAAI,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,KAAK;AACtD;AAEO,IAAM,YAAY,CAAC,eAAyC;AACjE,SAAO,WAAW,QAAQ,QAAQ,GAAG,EAAE,QAAQ,QAAQ,GAAG;AAC5D;","names":[]}
1
+ {"version":3,"sources":["../src/resource-key.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport type ResourceKey = string\nconst ResourceNamespaceSeparator = '/'\n\nexport type NamespaceKey = string | undefined\nexport type ResourceNamespace<NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<NamespaceType, 'ResourceNamespace'> | undefined\n\nexport type NamespacedKey<KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<\n string,\n ['NamespacedKey', KeyType, NamespaceType]\n>\n\nexport const emptyNamespace = (): ResourceNamespace<undefined> => {\n return undefined\n}\n\nexport const createNamespace = <T extends NamespaceKey>(value: T): ResourceNamespace<T> => {\n if (value === undefined) {\n return value as any as ResourceNamespace<T>\n }\n\n if (!/^[^\\s\\/][^\\s\\/]*(?:\\/[^\\s\\/][^\\s\\/]*)*$/.test(value)) {\n throw new Error(`Unsupported Namespace format: ${value}`)\n }\n\n return value as ResourceNamespace<T>\n}\n\nexport const createCompositeNamespace = (...names: Array<ResourceNamespace>): ResourceNamespace => {\n return names.filter(Objects.isPresent).join(ResourceNamespaceSeparator) as ResourceNamespace\n}\n\nexport const ResourceNamespaceSchema = Zod.string().optional().transform(createNamespace)\n\nexport const namespaceKey = <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(\n key: KeyType,\n namespace: ResourceNamespace<NamespaceType>\n): NamespacedKey<KeyType, NamespaceType> => {\n if (namespace === undefined) {\n return encodeKey(key) as NamespacedKey<KeyType, NamespaceType>\n }\n\n return `${namespace}${ResourceNamespaceSeparator}${encodeKey(key)}` as NamespacedKey<KeyType, NamespaceType>\n}\n\nexport const namespaceKeys = <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(\n keys: Array<KeyType>,\n namespace: ResourceNamespace<NamespaceType>\n): Array<NamespacedKey<KeyType, NamespaceType>> => {\n return keys.map((it) => namespaceKey(it, namespace))\n}\n\nexport const destructureKey = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n key: NamespacedKey<KeyType, NamespaceType>\n): [KeyType, ResourceNamespace<NamespaceType>] => {\n const lastIndex = key.lastIndexOf(ResourceNamespaceSeparator)\n\n if (lastIndex !== -1) {\n const namespacePart = key.substring(0, lastIndex)\n const keyPart = key.substring(lastIndex + 1)\n\n return [decodeKey(keyPart) as KeyType, namespacePart as ResourceNamespace<NamespaceType>]\n } else {\n const keyPart = key\n return [decodeKey(keyPart) as KeyType, undefined as ResourceNamespace<NamespaceType>]\n }\n}\n\nexport const getKey = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>\n): KeyType => {\n const [key, _] = destructureKey(namespacedKey)\n return key\n}\n\nexport const getNamespace = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>\n): ResourceNamespace<NamespaceType> => {\n const [_, namespace] = destructureKey(namespacedKey)\n return namespace\n}\n\nexport const extendNamespace = <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(\n namespacedKey: NamespacedKey<KeyType, NamespaceType>,\n additionalNamespace: ResourceNamespace\n): NamespacedKey<KeyType> => {\n const [type, namespace] = destructureKey(namespacedKey)\n const extendedNamespace = createCompositeNamespace(additionalNamespace, namespace)\n return namespaceKey(type, extendedNamespace)\n}\n\nexport const encodeKey = (key: ResourceKey): ResourceKey => {\n return key.replace(/%/g, '%25').replace(/\\//g, '%2F')\n}\n\nexport const decodeKey = (encodedKey: ResourceKey): ResourceKey => {\n return encodedKey.replace(/%2F/g, '/').replace(/%25/g, '%')\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,YAAY,aAAa;AAGzB,IAAM,6BAA6B;AAU5B,IAAM,iBAAiB,MAAoC;AAChE,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAyB,UAAmC;AACzF,MAAI,UAAU,QAAW;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,0CAA0C,KAAK,KAAK,GAAG;AAC1D,UAAM,IAAI,MAAM,iCAAiC,KAAK,EAAE;AAAA,EAC1D;AAEA,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AAEO,IAAM,YAAY,CAAC,eAAyC;AACjE,SAAO,WAAW,QAAQ,QAAQ,GAAG,EAAE,QAAQ,QAAQ,GAAG;AAC5D;","names":[]}
package/dist/result.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/result.ts
2
- import { isPromise } from "@bessemer/cornerstone/promise";
2
+ import * as Promises from "@bessemer/cornerstone/promise";
3
3
  import * as Eithers from "@bessemer/cornerstone/either";
4
- import { assert } from "@bessemer/cornerstone/assertion";
4
+ import * as Assertions from "@bessemer/cornerstone/assertion";
5
5
  var success = (value) => Eithers.left(value);
6
6
  function failure(failure2) {
7
7
  return Eithers.right(failure2);
@@ -18,7 +18,7 @@ function assertSuccess(value) {
18
18
  }
19
19
  }
20
20
  function assertFailure(value) {
21
- assert(isFailure(value));
21
+ Assertions.assert(isFailure(value));
22
22
  }
23
23
  function map2(value, mapper) {
24
24
  return Eithers.map(value, mapper);
@@ -38,7 +38,7 @@ var split2 = (array) => {
38
38
  function tryValue(resolver) {
39
39
  try {
40
40
  let result = resolver();
41
- if (isPromise(result)) {
41
+ if (Promises.isPromise(result)) {
42
42
  return result.then((it) => success(it)).catch((it) => failure(it));
43
43
  } else {
44
44
  return success(result);
@@ -50,7 +50,7 @@ function tryValue(resolver) {
50
50
  function tryResult(resolver) {
51
51
  try {
52
52
  let result = resolver();
53
- if (isPromise(result)) {
53
+ if (Promises.isPromise(result)) {
54
54
  return result.catch((it) => failure(it));
55
55
  } else {
56
56
  return result;