@bessemer/cornerstone 0.5.85 → 0.5.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/aspect-ratio.d.ts +7 -4
  2. package/dist/aspect-ratio.d.ts.map +1 -1
  3. package/dist/aspect-ratio.js +16 -7
  4. package/dist/aspect-ratio.js.map +1 -1
  5. package/dist/async.d.ts +1 -1
  6. package/dist/async.d.ts.map +1 -1
  7. package/dist/async.js +1 -1
  8. package/dist/async.js.map +1 -1
  9. package/dist/cache.d.ts +9 -8
  10. package/dist/cache.d.ts.map +1 -1
  11. package/dist/cache.js +14 -14
  12. package/dist/cache.js.map +1 -1
  13. package/dist/comparator.js +1 -1
  14. package/dist/comparator.js.map +1 -1
  15. package/dist/content.d.ts +5 -5
  16. package/dist/content.d.ts.map +1 -1
  17. package/dist/content.js.map +1 -1
  18. package/dist/data-size.d.ts +2 -2
  19. package/dist/data-size.d.ts.map +1 -1
  20. package/dist/data-size.js.map +1 -1
  21. package/dist/{error-event.d.ts → error/error-event.d.ts} +42 -23
  22. package/dist/error/error-event.d.ts.map +1 -0
  23. package/dist/{error-event.js → error/error-event.js} +82 -60
  24. package/dist/error/error-event.js.map +1 -0
  25. package/dist/error/error-type.d.ts +11 -0
  26. package/dist/error/error-type.d.ts.map +1 -0
  27. package/dist/error/error-type.js +20 -0
  28. package/dist/error/error-type.js.map +1 -0
  29. package/dist/error/error.d.ts.map +1 -0
  30. package/dist/{error.js → error/error.js} +1 -1
  31. package/dist/error/error.js.map +1 -0
  32. package/dist/expression.d.ts +2 -2
  33. package/dist/expression.d.ts.map +1 -1
  34. package/dist/expression.js.map +1 -1
  35. package/dist/glob.d.ts +7 -3
  36. package/dist/glob.d.ts.map +1 -1
  37. package/dist/glob.js +23 -15
  38. package/dist/glob.js.map +1 -1
  39. package/dist/hash.d.ts +2 -2
  40. package/dist/hash.d.ts.map +1 -1
  41. package/dist/hash.js.map +1 -1
  42. package/dist/hex-code.d.ts +7 -4
  43. package/dist/hex-code.d.ts.map +1 -1
  44. package/dist/hex-code.js +19 -5
  45. package/dist/hex-code.js.map +1 -1
  46. package/dist/index.d.ts +12 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +18 -4
  49. package/dist/index.js.map +1 -1
  50. package/dist/intl/country-code.d.ts +7 -4
  51. package/dist/intl/country-code.d.ts.map +1 -1
  52. package/dist/intl/country-code.js +52 -43
  53. package/dist/intl/country-code.js.map +1 -1
  54. package/dist/intl/country-subdivision-code.d.ts +7 -4
  55. package/dist/intl/country-subdivision-code.d.ts.map +1 -1
  56. package/dist/intl/country-subdivision-code.js +16 -5
  57. package/dist/intl/country-subdivision-code.js.map +1 -1
  58. package/dist/intl/currency-code.d.ts +7 -4
  59. package/dist/intl/currency-code.d.ts.map +1 -1
  60. package/dist/intl/currency-code.js +20 -11
  61. package/dist/intl/currency-code.js.map +1 -1
  62. package/dist/intl/language-code.d.ts +7 -4
  63. package/dist/intl/language-code.d.ts.map +1 -1
  64. package/dist/intl/language-code.js +39 -30
  65. package/dist/intl/language-code.js.map +1 -1
  66. package/dist/intl/locale.d.ts +8 -5
  67. package/dist/intl/locale.d.ts.map +1 -1
  68. package/dist/intl/locale.js +37 -30
  69. package/dist/intl/locale.js.map +1 -1
  70. package/dist/math.d.ts +2 -0
  71. package/dist/math.d.ts.map +1 -1
  72. package/dist/math.js +12 -1
  73. package/dist/math.js.map +1 -1
  74. package/dist/mime-type.d.ts +7 -4
  75. package/dist/mime-type.d.ts.map +1 -1
  76. package/dist/mime-type.js +44 -35
  77. package/dist/mime-type.js.map +1 -1
  78. package/dist/monetary-amount.d.ts +3 -3
  79. package/dist/monetary-amount.d.ts.map +1 -1
  80. package/dist/monetary-amount.js +4 -4
  81. package/dist/monetary-amount.js.map +1 -1
  82. package/dist/object/object-path.d.ts +2 -2
  83. package/dist/object/object-path.d.ts.map +1 -1
  84. package/dist/object/object-path.js.map +1 -1
  85. package/dist/object/type-path.d.ts +2 -2
  86. package/dist/object/type-path.d.ts.map +1 -1
  87. package/dist/object/type-path.js.map +1 -1
  88. package/dist/object.d.ts +2 -2
  89. package/dist/object.d.ts.map +1 -1
  90. package/dist/object.js +3 -2
  91. package/dist/object.js.map +1 -1
  92. package/dist/range.d.ts +2 -2
  93. package/dist/range.d.ts.map +1 -1
  94. package/dist/range.js.map +1 -1
  95. package/dist/reference.d.ts +2 -2
  96. package/dist/reference.d.ts.map +1 -1
  97. package/dist/reference.js.map +1 -1
  98. package/dist/resource-key.d.ts +17 -8
  99. package/dist/resource-key.d.ts.map +1 -1
  100. package/dist/resource-key.js +42 -13
  101. package/dist/resource-key.js.map +1 -1
  102. package/dist/result.d.ts +6 -5
  103. package/dist/result.d.ts.map +1 -1
  104. package/dist/result.js +4 -4
  105. package/dist/result.js.map +1 -1
  106. package/dist/retry.d.ts +1 -1
  107. package/dist/retry.d.ts.map +1 -1
  108. package/dist/retry.js +1 -1
  109. package/dist/retry.js.map +1 -1
  110. package/dist/rich-text.d.ts +2 -2
  111. package/dist/rich-text.d.ts.map +1 -1
  112. package/dist/rich-text.js.map +1 -1
  113. package/dist/signature.d.ts.map +1 -1
  114. package/dist/signature.js +5 -1
  115. package/dist/signature.js.map +1 -1
  116. package/dist/sql.d.ts +2 -2
  117. package/dist/sql.d.ts.map +1 -1
  118. package/dist/sql.js.map +1 -1
  119. package/dist/tag.d.ts +3 -3
  120. package/dist/tag.d.ts.map +1 -1
  121. package/dist/tag.js.map +1 -1
  122. package/dist/temporal/chrono.d.ts +34 -0
  123. package/dist/temporal/chrono.d.ts.map +1 -0
  124. package/dist/temporal/chrono.js +34 -0
  125. package/dist/temporal/chrono.js.map +1 -0
  126. package/dist/temporal/clock.d.ts +21 -0
  127. package/dist/temporal/clock.d.ts.map +1 -0
  128. package/dist/temporal/clock.js +76 -0
  129. package/dist/temporal/clock.js.map +1 -0
  130. package/dist/temporal/date.d.ts +2 -0
  131. package/dist/temporal/date.d.ts.map +1 -0
  132. package/dist/temporal/date.js +8 -0
  133. package/dist/temporal/date.js.map +1 -0
  134. package/dist/temporal/duration.d.ts +54 -0
  135. package/dist/temporal/duration.d.ts.map +1 -0
  136. package/dist/temporal/duration.js +162 -0
  137. package/dist/temporal/duration.js.map +1 -0
  138. package/dist/temporal/instant.d.ts +35 -0
  139. package/dist/temporal/instant.d.ts.map +1 -0
  140. package/dist/temporal/instant.js +91 -0
  141. package/dist/temporal/instant.js.map +1 -0
  142. package/dist/temporal/plain-time.d.ts +49 -0
  143. package/dist/temporal/plain-time.d.ts.map +1 -0
  144. package/dist/temporal/plain-time.js +110 -0
  145. package/dist/temporal/plain-time.js.map +1 -0
  146. package/dist/temporal/time-zone-id.d.ts +12 -0
  147. package/dist/temporal/time-zone-id.d.ts.map +1 -0
  148. package/dist/temporal/time-zone-id.js +35 -0
  149. package/dist/temporal/time-zone-id.js.map +1 -0
  150. package/dist/temporal/time-zone-offset.d.ts +22 -0
  151. package/dist/temporal/time-zone-offset.d.ts.map +1 -0
  152. package/dist/temporal/time-zone-offset.js +145 -0
  153. package/dist/temporal/time-zone-offset.js.map +1 -0
  154. package/dist/types.d.ts +12 -12
  155. package/dist/types.d.ts.map +1 -1
  156. package/dist/ulid.d.ts +7 -4
  157. package/dist/ulid.d.ts.map +1 -1
  158. package/dist/ulid.js +14 -5
  159. package/dist/ulid.js.map +1 -1
  160. package/dist/unit.d.ts +2 -2
  161. package/dist/unit.d.ts.map +1 -1
  162. package/dist/unit.js.map +1 -1
  163. package/dist/uri.d.ts +2 -2
  164. package/dist/uri.d.ts.map +1 -1
  165. package/dist/uri.js.map +1 -1
  166. package/dist/uuid.d.ts +7 -4
  167. package/dist/uuid.d.ts.map +1 -1
  168. package/dist/uuid.js +14 -5
  169. package/dist/uuid.js.map +1 -1
  170. package/dist/zod-util.d.ts +5 -0
  171. package/dist/zod-util.d.ts.map +1 -1
  172. package/dist/zod-util.js +28 -2
  173. package/dist/zod-util.js.map +1 -1
  174. package/package.json +2 -2
  175. package/dist/date.d.ts +0 -13
  176. package/dist/date.d.ts.map +0 -1
  177. package/dist/date.js +0 -40
  178. package/dist/date.js.map +0 -1
  179. package/dist/duration.d.ts +0 -18
  180. package/dist/duration.d.ts.map +0 -1
  181. package/dist/duration.js +0 -53
  182. package/dist/duration.js.map +0 -1
  183. package/dist/error-event.d.ts.map +0 -1
  184. package/dist/error-event.js.map +0 -1
  185. package/dist/error.d.ts.map +0 -1
  186. package/dist/error.js.map +0 -1
  187. /package/dist/{error.d.ts → error/error.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/monetary-amount.ts"],"sourcesContent":["import { CurrencyCode, Schema as CurrencyCodeSchema } from '@bessemer/cornerstone/intl/currency-code'\nimport Zod from 'zod'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { roundHalfEven } from '@bessemer/cornerstone/math'\nimport { Comparator as IComparator, natural } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { assert } from '@bessemer/cornerstone/assertion'\n\nexport type MonetaryAmount = {\n amount: number\n currency: CurrencyCode\n}\n\nexport const Schema = Zod.object({\n amount: Zod.number().int(),\n currency: CurrencyCodeSchema,\n})\n\nexport const Comparator: IComparator<MonetaryAmount> = (first: MonetaryAmount, second: MonetaryAmount): number => {\n return apply(first, second, natural())\n}\n\nexport const Equalitor = fromComparator(Comparator)\n\nexport const of = (amount: number, currency: CurrencyCode): MonetaryAmount => {\n assert(Number.isInteger(amount))\n return { amount, currency }\n}\n\nexport const zero = (currency: CurrencyCode): MonetaryAmount => {\n return { amount: 0, currency }\n}\n\nexport const apply = <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T): T => {\n if (first.currency !== second.currency) {\n throw new Error(`Currency mismatch in operation on MonetaryAmount: ${first.currency}, ${second.currency}`)\n }\n\n return operator(first.amount, second.amount)\n}\n\nexport const operate = (first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => number): MonetaryAmount => {\n return of(apply(first, second, operator), first.currency)\n}\n\n/** Determines whether two MonetaryAmounts are considered equivalent */\nexport const equal = (first?: MonetaryAmount | null, second?: MonetaryAmount | null): boolean => {\n if (isNil(first) && isNil(second)) {\n return true\n }\n if (isNil(first) || isNil(second)) {\n return false\n }\n\n return apply(first, second, (first, second) => first === second)\n}\n\nexport const sum = (first: MonetaryAmount, second?: MonetaryAmount | null): MonetaryAmount => {\n return operate(first, second ?? zero(first.currency), (first, second) => first + second)\n}\n\nexport const subtract = (first: MonetaryAmount, second: MonetaryAmount): MonetaryAmount => {\n return operate(first, second, (first, second) => first - second)\n}\n\nexport const multiply = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount * value, 0), money.currency)\n}\n\nexport const divide = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount / value, 0), money.currency)\n}\n\nexport function sumAll(monetaryAmounts: readonly [MonetaryAmount, ...MonetaryAmount[]]): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency: CurrencyCode): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency?: CurrencyCode): MonetaryAmount {\n const resolvedCurrency = currency ?? monetaryAmounts[0]!.currency\n return monetaryAmounts.reduce<MonetaryAmount>((first, second) => sum(second, first), zero(resolvedCurrency))\n}\n\nexport const negate = (monetaryAmount: MonetaryAmount): MonetaryAmount => {\n // Avoid creating a negative 0, which is a real thing!\n if (isZero(monetaryAmount)) {\n return monetaryAmount\n }\n\n return of(-monetaryAmount.amount, monetaryAmount.currency)\n}\n\nexport const isZero = (monetaryAmount: MonetaryAmount): boolean => {\n return monetaryAmount.amount === 0\n}\n\nexport const greaterThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first > second)\n}\n\nexport const lessThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first < second)\n}\n\nexport const greaterThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first >= second)\n}\n\nexport const lessThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first <= second)\n}\n\nexport type MonetaryAmountFormatOptions = {\n hideCents?: boolean\n}\n\nexport const format = (amount: MonetaryAmount, alpha2Code: string, options?: MonetaryAmountFormatOptions): string => {\n const hideCents = options?.hideCents ?? false\n const isWholeNumber = amount.amount % 100 === 0\n\n const formatCurrency = new Intl.NumberFormat(alpha2Code, {\n style: 'currency',\n currency: amount.currency,\n ...(hideCents\n ? {\n minimumFractionDigits: isWholeNumber ? 0 : 2,\n maximumFractionDigits: 2,\n }\n : {}),\n })\n\n return formatCurrency.format(amount.amount / 100)\n}\n"],"mappings":";AAAA,SAAuB,UAAU,0BAA0B;AAC3D,OAAO,SAAS;AAChB,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAoC,eAAe;AACnD,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AAOhB,IAAM,SAAS,IAAI,OAAO;AAAA,EAC/B,QAAQ,IAAI,OAAO,EAAE,IAAI;AAAA,EACzB,UAAU;AACZ,CAAC;AAEM,IAAM,aAA0C,CAAC,OAAuB,WAAmC;AAChH,SAAO,MAAM,OAAO,QAAQ,QAAQ,CAAC;AACvC;AAEO,IAAM,YAAY,eAAe,UAAU;AAE3C,IAAM,KAAK,CAAC,QAAgB,aAA2C;AAC5E,SAAO,OAAO,UAAU,MAAM,CAAC;AAC/B,SAAO,EAAE,QAAQ,SAAS;AAC5B;AAEO,IAAM,OAAO,CAAC,aAA2C;AAC9D,SAAO,EAAE,QAAQ,GAAG,SAAS;AAC/B;AAEO,IAAM,QAAQ,CAAI,OAAuB,QAAwB,aAAsD;AAC5H,MAAI,MAAM,aAAa,OAAO,UAAU;AACtC,UAAM,IAAI,MAAM,qDAAqD,MAAM,QAAQ,KAAK,OAAO,QAAQ,EAAE;AAAA,EAC3G;AAEA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AAC,mBAA4C;AACjE,SAAO,eAAe,WAAW;AACnC;AAEO,IAAM,cAAc,CAAC,OAAuB,WAAoC;AACrF,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,SAAQC,OAAM;AAC/D;AAEO,IAAM,WAAW,CAAC,OAAuB,WAAoC;AAClF,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,SAAQC,OAAM;AAC/D;AAEO,IAAM,qBAAqB,CAAC,OAAuB,WAAoC;AAC5F,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,UAASC,OAAM;AAChE;AAEO,IAAM,kBAAkB,CAAC,OAAuB,WAAoC;AACzF,SAAO,MAAM,OAAO,QAAQ,CAACD,QAAOC,YAAWD,UAASC,OAAM;AAChE;AAMO,IAAM,SAAS,CAAC,QAAwB,YAAoB,YAAkD;AACnH,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,gBAAgB,OAAO,SAAS,QAAQ;AAE9C,QAAM,iBAAiB,IAAI,KAAK,aAAa,YAAY;AAAA,IACvD,OAAO;AAAA,IACP,UAAU,OAAO;AAAA,IACjB,GAAI,YACA;AAAA,MACE,uBAAuB,gBAAgB,IAAI;AAAA,MAC3C,uBAAuB;AAAA,IACzB,IACA,CAAC;AAAA,EACP,CAAC;AAED,SAAO,eAAe,OAAO,OAAO,SAAS,GAAG;AAClD;","names":["first","second"]}
1
+ {"version":3,"sources":["../src/monetary-amount.ts"],"sourcesContent":["import { CurrencyCode, Schema as CurrencyCodeSchema } from '@bessemer/cornerstone/intl/currency-code'\nimport Zod from 'zod'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { roundHalfEven } from '@bessemer/cornerstone/math'\nimport { Comparator, natural } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { assert } from '@bessemer/cornerstone/assertion'\n\nexport type MonetaryAmount = {\n amount: number\n currency: CurrencyCode\n}\n\nexport const Schema = Zod.object({\n amount: Zod.number().int(),\n currency: CurrencyCodeSchema,\n})\n\nexport const CompareBy: Comparator<MonetaryAmount> = (first: MonetaryAmount, second: MonetaryAmount): number => {\n return apply(first, second, natural())\n}\n\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const of = (amount: number, currency: CurrencyCode): MonetaryAmount => {\n assert(Number.isInteger(amount))\n return { amount, currency }\n}\n\nexport const zero = (currency: CurrencyCode): MonetaryAmount => {\n return { amount: 0, currency }\n}\n\nexport const apply = <T>(first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => T): T => {\n if (first.currency !== second.currency) {\n throw new Error(`Currency mismatch in operation on MonetaryAmount: ${first.currency}, ${second.currency}`)\n }\n\n return operator(first.amount, second.amount)\n}\n\nexport const operate = (first: MonetaryAmount, second: MonetaryAmount, operator: (first: number, second: number) => number): MonetaryAmount => {\n return of(apply(first, second, operator), first.currency)\n}\n\n/** Determines whether two MonetaryAmounts are considered equivalent */\nexport const equal = (first?: MonetaryAmount | null, second?: MonetaryAmount | null): boolean => {\n if (isNil(first) && isNil(second)) {\n return true\n }\n if (isNil(first) || isNil(second)) {\n return false\n }\n\n return apply(first, second, (first, second) => first === second)\n}\n\nexport const sum = (first: MonetaryAmount, second?: MonetaryAmount | null): MonetaryAmount => {\n return operate(first, second ?? zero(first.currency), (first, second) => first + second)\n}\n\nexport const subtract = (first: MonetaryAmount, second: MonetaryAmount): MonetaryAmount => {\n return operate(first, second, (first, second) => first - second)\n}\n\nexport const multiply = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount * value, 0), money.currency)\n}\n\nexport const divide = (money: MonetaryAmount, value: number): MonetaryAmount => {\n return of(roundHalfEven(money.amount / value, 0), money.currency)\n}\n\nexport function sumAll(monetaryAmounts: readonly [MonetaryAmount, ...MonetaryAmount[]]): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency: CurrencyCode): MonetaryAmount\nexport function sumAll(monetaryAmounts: readonly MonetaryAmount[], currency?: CurrencyCode): MonetaryAmount {\n const resolvedCurrency = currency ?? monetaryAmounts[0]!.currency\n return monetaryAmounts.reduce<MonetaryAmount>((first, second) => sum(second, first), zero(resolvedCurrency))\n}\n\nexport const negate = (monetaryAmount: MonetaryAmount): MonetaryAmount => {\n // Avoid creating a negative 0, which is a real thing!\n if (isZero(monetaryAmount)) {\n return monetaryAmount\n }\n\n return of(-monetaryAmount.amount, monetaryAmount.currency)\n}\n\nexport const isZero = (monetaryAmount: MonetaryAmount): boolean => {\n return monetaryAmount.amount === 0\n}\n\nexport const greaterThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first > second)\n}\n\nexport const lessThan = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first < second)\n}\n\nexport const greaterThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first >= second)\n}\n\nexport const lessThanOrEqual = (first: MonetaryAmount, second: MonetaryAmount): boolean => {\n return apply(first, second, (first, second) => first <= second)\n}\n\nexport type MonetaryAmountFormatOptions = {\n hideCents?: boolean\n}\n\nexport const format = (amount: MonetaryAmount, alpha2Code: string, options?: MonetaryAmountFormatOptions): string => {\n const hideCents = options?.hideCents ?? false\n const isWholeNumber = amount.amount % 100 === 0\n\n const formatCurrency = new Intl.NumberFormat(alpha2Code, {\n style: 'currency',\n currency: amount.currency,\n ...(hideCents\n ? {\n minimumFractionDigits: isWholeNumber ? 0 : 2,\n maximumFractionDigits: 2,\n }\n : {}),\n })\n\n return formatCurrency.format(amount.amount / 100)\n}\n"],"mappings":";AAAA,SAAuB,UAAU,0BAA0B;AAC3D,OAAO,SAAS;AAChB,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAqB,eAAe;AACpC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AAOhB,IAAM,SAAS,IAAI,OAAO;AAAA,EAC/B,QAAQ,IAAI,OAAO,EAAE,IAAI;AAAA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ACE,uBAAuB,gBAAgB,IAAI;AAAA,MAC3C,uBAAuB;AAAA,IACzB,IACA,CAAC;AAAA,EACP,CAAC;AAED,SAAO,eAAe,OAAO,OAAO,SAAS,GAAG;AAClD;","names":["first","second"]}
@@ -1,8 +1,8 @@
1
1
  import Zod from 'zod';
2
- import { NominalType } from '@bessemer/cornerstone/types';
2
+ import { TaggedType } from '@bessemer/cornerstone/types';
3
3
  import { InferObjectPath, ObjectPathConcreteType, ObjectPathType, ParseObjectPath, TypePathGet, TypePathType } from '@bessemer/cornerstone/object/type-path-type';
4
4
  import { TypePath } from '@bessemer/cornerstone/object/type-path';
5
- export type ObjectPath<T extends TypePathType = TypePathType> = NominalType<ObjectPathConcreteType, ['TypePath', T]>;
5
+ export type ObjectPath<T extends TypePathType = TypePathType> = TaggedType<ObjectPathConcreteType, ['TypePath', T]>;
6
6
  export declare const of: <T extends ObjectPathConcreteType>(value: T) => ObjectPath<InferObjectPath<T>>;
7
7
  export declare const fromString: <T extends string>(path: T) => ObjectPath<ParseObjectPath<T>>;
8
8
  export declare const Schema: Zod.ZodPipe<Zod.ZodUnion<readonly [Zod.ZodArray<Zod.ZodString>, Zod.ZodString]>, Zod.ZodTransform<ObjectPath<ObjectPathType>, string | string[]>>;
@@ -1 +1 @@
1
- {"version":3,"file":"object-path.d.ts","sourceRoot":"","sources":["../../src/object/object-path.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAAM,6CAA6C,CAAA;AACpD,OAAO,EAKL,QAAQ,EACT,MAAM,wCAAwC,CAAA;AAM/C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI,WAAW,CAAC,sBAAsB,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CA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,YAAY,EAC9F,YAAY,UAAU,CAAC,UAAU,CAAC,EAClC,kBAAkB,QAAQ,CAAC,gBAAgB,CAAC,KAC3C,UAEF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/object-path.ts"],"sourcesContent":["import Zod from 'zod'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport {\n InferObjectPath,\n ObjectPathConcreteType,\n ObjectPathType,\n ParseObjectPath,\n TypePathGet,\n TypePathType,\n} from '@bessemer/cornerstone/object/type-path-type'\nimport {\n fromString as typePathFromString,\n getValue as typePathGetValue,\n intersect as typePathIntersect,\n matches as typePathMatches,\n TypePath,\n} from '@bessemer/cornerstone/object/type-path'\nimport { isEmpty, only } from '@bessemer/cornerstone/array'\nimport { assert } from '@bessemer/cornerstone/assertion'\nimport { produce } from 'immer'\nimport { isObject } from '@bessemer/cornerstone/object'\n\nexport type ObjectPath<T extends TypePathType = TypePathType> = NominalType<ObjectPathConcreteType, ['TypePath', T]>\n\nexport const of = <T extends ObjectPathConcreteType>(value: T): ObjectPath<InferObjectPath<T>> => {\n return value as ObjectPath<InferObjectPath<T>>\n}\n\nexport const fromString = <T extends string>(path: T): ObjectPath<ParseObjectPath<T>> => {\n const typePath = typePathFromString(path)\n\n typePath.forEach((it) => {\n assert(it !== '*', () => 'ObjectPaths do not allow for wildcard selectors')\n\n if (Array.isArray(it)) {\n assert(it.length === 1, () => 'ObjectPaths do not allow for multiple index selectors or array slices')\n }\n })\n\n return typePath as ObjectPath<ParseObjectPath<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 fromString(it)\n }\n})\n\nexport const getValue = <T extends ObjectPathType, N>(path: ObjectPath<T>, object: N): TypePathGet<T, N> => {\n return typePathGetValue(path, object)\n}\n\nexport const applyValue = <T extends ObjectPathType, N>(path: ObjectPath<T>, object: N, valueToApply: TypePathGet<T, N>): N => {\n return applyAnyValue(path, object, valueToApply) as N\n}\n\nexport const applyAnyValue = (path: ObjectPath, object: unknown, valueToApply: unknown): unknown => {\n if (isEmpty(path)) {\n return valueToApply\n }\n\n return produce(object, (draft) => {\n const rest = path.slice(0, -1)\n const last = path[path.length - 1]!\n const parent = getValue(of(rest), draft) as any\n\n assert(isObject(parent) || Array.isArray(parent), () => `Unable to apply value: ${valueToApply} at ObjectPath: ${path} against object: ${object}`)\n if (Array.isArray(last)) {\n const index = only(last)\n parent[index] = valueToApply\n } else {\n parent[last] = valueToApply\n }\n })\n}\n\nexport const matches = <MatchingPath extends TypePathType>(\n targetPath: ObjectPath,\n matchingPath: TypePath<MatchingPath>\n): targetPath is ObjectPath<MatchingPath> => {\n return typePathMatches(targetPath, matchingPath)\n}\n\nexport const intersect = <TargetPath extends TypePathType, IntersectingPath extends TypePathType>(\n targetPath: ObjectPath<TargetPath>,\n intersectingPath: TypePath<IntersectingPath>\n): ObjectPath => {\n return typePathIntersect(targetPath, intersectingPath) as ObjectPath\n}\n"],"mappings":";AAAA,OAAO,SAAS;AAUhB;AAAA,EACE,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,WAAW;AAAA,OAEN;AACP,SAAS,SAAS,YAAY;AAC9B,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAIlB,IAAM,KAAK,CAAmC,UAA6C;AAChG,SAAO;AACT;AAEO,IAAM,aAAa,CAAmB,SAA4C;AACvF,QAAM,WAAW,mBAAmB,IAAI;AAExC,WAAS,QAAQ,CAAC,OAAO;AACvB,WAAO,OAAO,KAAK,MAAM,iDAAiD;AAE1E,QAAI,MAAM,QAAQ,EAAE,GAAG;AACrB,aAAO,GAAG,WAAW,GAAG,MAAM,uEAAuE;AAAA,IACvG;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEO,IAAM,SAAS,IAAI,MAAM,CAAC,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO;AACzF,MAAI,MAAM,QAAQ,EAAE,GAAG;AACrB,WAAO,GAAG,EAAE;AAAA,EACd,OAAO;AACL,WAAO,WAAW,EAAE;AAAA,EACtB;AACF,CAAC;AAEM,IAAM,WAAW,CAA8B,MAAqB,WAAiC;AAC1G,SAAO,iBAAiB,MAAM,MAAM;AACtC;AAEO,IAAM,aAAa,CAA8B,MAAqB,QAAW,iBAAuC;AAC7H,SAAO,cAAc,MAAM,QAAQ,YAAY;AACjD;AAEO,IAAM,gBAAgB,CAAC,MAAkB,QAAiB,iBAAmC;AAClG,MAAI,QAAQ,IAAI,GAAG;AACjB,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,QAAQ,CAAC,UAAU;AAChC,UAAM,OAAO,KAAK,MAAM,GAAG,EAAE;AAC7B,UAAM,OAAO,KAAK,KAAK,SAAS,CAAC;AACjC,UAAM,SAAS,SAAS,GAAG,IAAI,GAAG,KAAK;AAEvC,WAAO,SAAS,MAAM,KAAK,MAAM,QAAQ,MAAM,GAAG,MAAM,0BAA0B,YAAY,mBAAmB,IAAI,oBAAoB,MAAM,EAAE;AACjJ,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,YAAM,QAAQ,KAAK,IAAI;AACvB,aAAO,KAAK,IAAI;AAAA,IAClB,OAAO;AACL,aAAO,IAAI,IAAI;AAAA,IACjB;AAAA,EACF,CAAC;AACH;AAEO,IAAM,UAAU,CACrB,YACA,iBAC2C;AAC3C,SAAO,gBAAgB,YAAY,YAAY;AACjD;AAEO,IAAM,YAAY,CACvB,YACA,qBACe;AACf,SAAO,kBAAkB,YAAY,gBAAgB;AACvD;","names":[]}
1
+ {"version":3,"sources":["../../src/object/object-path.ts"],"sourcesContent":["import Zod from 'zod'\nimport { TaggedType } from '@bessemer/cornerstone/types'\nimport {\n InferObjectPath,\n ObjectPathConcreteType,\n ObjectPathType,\n ParseObjectPath,\n TypePathGet,\n TypePathType,\n} from '@bessemer/cornerstone/object/type-path-type'\nimport {\n fromString as typePathFromString,\n getValue as typePathGetValue,\n intersect as typePathIntersect,\n matches as typePathMatches,\n TypePath,\n} from '@bessemer/cornerstone/object/type-path'\nimport { isEmpty, only } from '@bessemer/cornerstone/array'\nimport { assert } from '@bessemer/cornerstone/assertion'\nimport { produce } from 'immer'\nimport { isObject } from '@bessemer/cornerstone/object'\n\n// JOHN this probably should be brought into the structured transform regime\nexport type ObjectPath<T extends TypePathType = TypePathType> = TaggedType<ObjectPathConcreteType, ['TypePath', T]>\n\nexport const of = <T extends ObjectPathConcreteType>(value: T): ObjectPath<InferObjectPath<T>> => {\n return value as ObjectPath<InferObjectPath<T>>\n}\n\nexport const fromString = <T extends string>(path: T): ObjectPath<ParseObjectPath<T>> => {\n const typePath = typePathFromString(path)\n\n typePath.forEach((it) => {\n assert(it !== '*', () => 'ObjectPaths do not allow for wildcard selectors')\n\n if (Array.isArray(it)) {\n assert(it.length === 1, () => 'ObjectPaths do not allow for multiple index selectors or array slices')\n }\n })\n\n return typePath as ObjectPath<ParseObjectPath<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 fromString(it)\n }\n})\n\nexport const getValue = <T extends ObjectPathType, N>(path: ObjectPath<T>, object: N): TypePathGet<T, N> => {\n return typePathGetValue(path, object)\n}\n\nexport const applyValue = <T extends ObjectPathType, N>(path: ObjectPath<T>, object: N, valueToApply: TypePathGet<T, N>): N => {\n return applyAnyValue(path, object, valueToApply) as N\n}\n\nexport const applyAnyValue = (path: ObjectPath, object: unknown, valueToApply: unknown): unknown => {\n if (isEmpty(path)) {\n return valueToApply\n }\n\n return produce(object, (draft) => {\n const rest = path.slice(0, -1)\n const last = path[path.length - 1]!\n const parent = getValue(of(rest), draft) as any\n\n assert(isObject(parent) || Array.isArray(parent), () => `Unable to apply value: ${valueToApply} at ObjectPath: ${path} against object: ${object}`)\n if (Array.isArray(last)) {\n const index = only(last)\n parent[index] = valueToApply\n } else {\n parent[last] = valueToApply\n }\n })\n}\n\nexport const matches = <MatchingPath extends TypePathType>(\n targetPath: ObjectPath,\n matchingPath: TypePath<MatchingPath>\n): targetPath is ObjectPath<MatchingPath> => {\n return typePathMatches(targetPath, matchingPath)\n}\n\nexport const intersect = <TargetPath extends TypePathType, IntersectingPath extends TypePathType>(\n targetPath: ObjectPath<TargetPath>,\n intersectingPath: TypePath<IntersectingPath>\n): ObjectPath => {\n return typePathIntersect(targetPath, intersectingPath) as ObjectPath\n}\n"],"mappings":";AAAA,OAAO,SAAS;AAUhB;AAAA,EACE,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,WAAW;AAAA,OAEN;AACP,SAAS,SAAS,YAAY;AAC9B,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAKlB,IAAM,KAAK,CAAmC,UAA6C;AAChG,SAAO;AACT;AAEO,IAAM,aAAa,CAAmB,SAA4C;AACvF,QAAM,WAAW,mBAAmB,IAAI;AAExC,WAAS,QAAQ,CAAC,OAAO;AACvB,WAAO,OAAO,KAAK,MAAM,iDAAiD;AAE1E,QAAI,MAAM,QAAQ,EAAE,GAAG;AACrB,aAAO,GAAG,WAAW,GAAG,MAAM,uEAAuE;AAAA,IACvG;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEO,IAAM,SAAS,IAAI,MAAM,CAAC,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO;AACzF,MAAI,MAAM,QAAQ,EAAE,GAAG;AACrB,WAAO,GAAG,EAAE;AAAA,EACd,OAAO;AACL,WAAO,WAAW,EAAE;AAAA,EACtB;AACF,CAAC;AAEM,IAAM,WAAW,CAA8B,MAAqB,WAAiC;AAC1G,SAAO,iBAAiB,MAAM,MAAM;AACtC;AAEO,IAAM,aAAa,CAA8B,MAAqB,QAAW,iBAAuC;AAC7H,SAAO,cAAc,MAAM,QAAQ,YAAY;AACjD;AAEO,IAAM,gBAAgB,CAAC,MAAkB,QAAiB,iBAAmC;AAClG,MAAI,QAAQ,IAAI,GAAG;AACjB,WAAO;AAAA,EACT;AAEA,SAAO,QAAQ,QAAQ,CAAC,UAAU;AAChC,UAAM,OAAO,KAAK,MAAM,GAAG,EAAE;AAC7B,UAAM,OAAO,KAAK,KAAK,SAAS,CAAC;AACjC,UAAM,SAAS,SAAS,GAAG,IAAI,GAAG,KAAK;AAEvC,WAAO,SAAS,MAAM,KAAK,MAAM,QAAQ,MAAM,GAAG,MAAM,0BAA0B,YAAY,mBAAmB,IAAI,oBAAoB,MAAM,EAAE;AACjJ,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,YAAM,QAAQ,KAAK,IAAI;AACvB,aAAO,KAAK,IAAI;AAAA,IAClB,OAAO;AACL,aAAO,IAAI,IAAI;AAAA,IACjB;AAAA,EACF,CAAC;AACH;AAEO,IAAM,UAAU,CACrB,YACA,iBAC2C;AAC3C,SAAO,gBAAgB,YAAY,YAAY;AACjD;AAEO,IAAM,YAAY,CACvB,YACA,qBACe;AACf,SAAO,kBAAkB,YAAY,gBAAgB;AACvD;","names":[]}
@@ -1,8 +1,8 @@
1
- import { NominalType } from '@bessemer/cornerstone/types';
1
+ import { TaggedType } from '@bessemer/cornerstone/types';
2
2
  import Zod from 'zod';
3
3
  import { InferTypePath, ParseTypePath, TypePathConcreteType, TypePathGet, TypePathSelector, TypePathType, WildcardSelector } from '@bessemer/cornerstone/object/type-path-type';
4
4
  import { Result } from '@bessemer/cornerstone/result';
5
- export type TypePath<T extends TypePathType = TypePathType> = NominalType<TypePathConcreteType, ['TypePath', T]>;
5
+ export type TypePath<T extends TypePathType = TypePathType> = TaggedType<TypePathConcreteType, ['TypePath', T]>;
6
6
  export declare const of: <T extends TypePathConcreteType>(value: T) => TypePath<InferTypePath<T>>;
7
7
  export declare const fromString: <T extends string>(path: T) => TypePath<ParseTypePath<T>>;
8
8
  export declare const Schema: Zod.ZodPipe<Zod.ZodUnion<readonly [Zod.ZodArray<Zod.ZodString>, Zod.ZodString]>, Zod.ZodTransform<TypePath<TypePathType>, string | string[]>>;
@@ -1 +1 @@
1
- {"version":3,"file":"type-path.d.ts","sourceRoot":"","sources":["../../src/object/type-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAEL,aAAa,EAEb,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EACjB,MAAM,6CAA6C,CAAA;AAIpD,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAEvE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI,WAAW,CAAC,oBAAoB,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA;AAEhH,eAAO,MAAM,EAAE,GAAI,CAAC,SAAS,oBAAoB,EAAE,OAAO,CAAC,KAAG,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAEtF,CAAA;AAKD,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,MAAM,EAAE,MAAM,CAAC,KAAG,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAmE/E,CAAA;AAED,eAAO,MAAM,MAAM,+IAMjB,CAAA;AAEF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAgClG,CAAA;AAsDD,eAAO,MAAM,kBAAkB,GAAI,UAAU,gBAAgB,KAAG,QAAQ,IAAI,gBAE3E,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,YAAY,SAAS,YAAY,EACvD,YAAY,QAAQ,EACpB,cAAc,QAAQ,CAAC,YAAY,CA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AC,CAAC,EAAE,CAAC,CAgClG,CAAA;AAsDD,eAAO,MAAM,kBAAkB,GAAI,UAAU,gBAAgB,KAAG,QAAQ,IAAI,gBAE3E,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,YAAY,SAAS,YAAY,EACvD,YAAY,QAAQ,EACpB,cAAc,QAAQ,CAAC,YAAY,CAAC,KACnC,UAAU,IAAI,QAAQ,CAAC,YAAY,CA8CrC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,YAAY,QAAQ,EAAE,kBAAkB,QAAQ,KAAG,MAAM,CAAC,QAAQ,CA0D9F,CAAA;AAGD,eAAO,MAAM,SAAS,GAAI,UAAU,SAAS,YAAY,EAAE,gBAAgB,SAAS,YAAY,EAC9F,YAAY,QAAQ,CAAC,UAAU,CAAC,EAChC,kBAAkB,QAAQ,CAAC,gBAAgB,CAAC,KAC3C,QAOF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/type-path.ts"],"sourcesContent":["import { NominalType } 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 { failure, Result, success } from '@bessemer/cornerstone/result'\n\nexport type TypePath<T extends TypePathType = TypePathType> = NominalType<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 fromString = <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 fromString(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 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 success(of(result))\n } else if (isWildcardSelector(intersectingPathSelector)) {\n result.push(targetPathSelector)\n } else if (isWildcardSelector(targetPathSelector)) {\n return 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 failure(makeError())\n }\n\n result.push(filteredTargetPaths)\n } else {\n if (!contains(intersectingPathSelector, Number(targetPathSelector))) {\n return failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n } else {\n if (Array.isArray(targetPathSelector)) {\n if (targetPathSelector.length !== 1) {\n return failure(makeError())\n }\n\n const targetPathSelectorIndex = only(targetPathSelector)\n if (targetPathSelectorIndex !== Number(intersectingPathSelector)) {\n return failure(makeError())\n }\n\n result.push(targetPathSelector)\n } else {\n if (targetPathSelector !== intersectingPathSelector) {\n return failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n }\n\n index++\n }\n\n return 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 if (!result.isSuccess) {\n throw result.value\n }\n\n return result.value\n}\n"],"mappings":";AACA,SAAS,cAAc;AACvB,OAAO,SAAS;AAYhB,SAAS,OAAO,gBAAgB;AAChC,SAAS,gBAAgB;AACzB,SAAS,UAAU,aAAa,SAAS,YAAY;AACrD,SAAS,SAAiB,eAAe;AAIlC,IAAM,KAAK,CAAiC,UAAyC;AAC1F,SAAO;AACT;AAEA,IAAM,gBACJ;AAEK,IAAM,aAAa,CAAmB,SAAwC;AACnF,SAAO,cAAc,KAAK,IAAI,GAAG,MAAM,yCAAyC,IAAI,EAAE;AAEtF,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,iBAAiB;AACrB;AACA,UAAI,QAAQ;AAEZ,aAAO,IAAI,KAAK,UAAU,QAAQ,GAAG;AACnC,cAAM,cAAc,KAAK,CAAC;AAC1B,YAAI,gBAAgB,KAAK;AACvB;AAAA,QACF,WAAW,gBAAgB,KAAK;AAC9B;AAAA,QACF;AAEA,YAAI,QAAQ,GAAG;AACb,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,IAAM,YAAY,CACvB,YACA,qBACa;AACb,QAAM,SAAS,aAAa,YAAY,gBAAgB;AACxD,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,OAAO;AAAA,EACf;AAEA,SAAO,OAAO;AAChB;","names":[]}
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 { failure, Result, success } 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 fromString = <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 fromString(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 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 success(of(result))\n } else if (isWildcardSelector(intersectingPathSelector)) {\n result.push(targetPathSelector)\n } else if (isWildcardSelector(targetPathSelector)) {\n return 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 failure(makeError())\n }\n\n result.push(filteredTargetPaths)\n } else {\n if (!contains(intersectingPathSelector, Number(targetPathSelector))) {\n return failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n } else {\n if (Array.isArray(targetPathSelector)) {\n if (targetPathSelector.length !== 1) {\n return failure(makeError())\n }\n\n const targetPathSelectorIndex = only(targetPathSelector)\n if (targetPathSelectorIndex !== Number(intersectingPathSelector)) {\n return failure(makeError())\n }\n\n result.push(targetPathSelector)\n } else {\n if (targetPathSelector !== intersectingPathSelector) {\n return failure(makeError())\n }\n\n result.push(targetPathSelector)\n }\n }\n\n index++\n }\n\n return 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 if (!result.isSuccess) {\n throw result.value\n }\n\n return result.value\n}\n"],"mappings":";AACA,SAAS,cAAc;AACvB,OAAO,SAAS;AAYhB,SAAS,OAAO,gB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AAM,QAAQ,kBAAkB,GAAG;AACrC,cAAM,sBAAsB,mBAAmB,OAAO,CAAC,OAAO,SAAS,0BAA0B,EAAE,CAAC;AACpG,YAAI,QAAQ,mBAAmB,GAAG;AAChC,iBAAO,QAAQ,UAAU,CAAC;AAAA,QAC5B;AAEA,eAAO,KAAK,mBAAmB;AAAA,MACjC,OAAO;AACL,YAAI,CAAC,SAAS,0BAA0B,OAAO,kBAAkB,CAAC,GAAG;AACnE,iBAAO,QAAQ,UAAU,CAAC;AAAA,QAC5B;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC;AAAA,IACF,OAAO;AACL,UAAI,MAAM,QAAQ,kBAAkB,GAAG;AACrC,YAAI,mBAAmB,WAAW,GAAG;AACnC,iBAAO,QAAQ,UAAU,CAAC;AAAA,QAC5B;AAEA,cAAM,0BAA0B,KAAK,kBAAkB;AACvD,YAAI,4BAA4B,OAAO,wBAAwB,GAAG;AAChE,iBAAO,QAAQ,UAAU,CAAC;AAAA,QAC5B;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC,OAAO;AACL,YAAI,uBAAuB,0BAA0B;AACnD,iBAAO,QAAQ,UAAU,CAAC;AAAA,QAC5B;AAEA,eAAO,KAAK,kBAAkB;AAAA,MAChC;AAAA,IACF;AAEA;AAAA,EACF;AAEA,SAAO,QAAQ,GAAG,MAAM,CAAC;AAC3B;AAGO,IAAM,YAAY,CACvB,YACA,qBACa;AACb,QAAM,SAAS,aAAa,YAAY,gBAAgB;AACxD,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,OAAO;AAAA,EACf;AAEA,SAAO,OAAO;AAChB;","names":[]}
package/dist/object.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { mergeWith as unsafeMergeWith } from 'lodash-es';
2
- import { BasicType, Dictionary, NominalType } from '@bessemer/cornerstone/types';
2
+ import { BasicType, Dictionary, TaggedType } from '@bessemer/cornerstone/types';
3
3
  import { Primitive, UnknownRecord } from 'type-fest';
4
4
  export declare const isUndefined: (value: unknown) => value is undefined;
5
5
  export declare const isNil: (value: unknown) => value is null | undefined;
@@ -47,7 +47,7 @@ export declare function fieldsPresent<T extends object, K extends keyof T>(objec
47
47
  export declare const isPrimitive: (value: any) => value is Primitive;
48
48
  export declare const isBasic: (value: any) => value is BasicType;
49
49
  export declare const isBoolean: (value: unknown) => value is boolean;
50
- export type RecordAttribute<Type = unknown, Class extends string = 'RecordAttribute'> = NominalType<string, [Type, Class]>;
50
+ export type RecordAttribute<Type = unknown, Class extends string = 'RecordAttribute'> = TaggedType<string, [Type, Class]>;
51
51
  type RecordAttributeType<Attribute> = Attribute extends RecordAttribute<infer Type, string> ? Type : never;
52
52
  export declare const getAttribute: <T extends RecordAttribute<unknown, string>>(record: UnknownRecord, attribute: T) => RecordAttributeType<T> | undefined;
53
53
  export declare const coerceNil: <T>(value: T | null | undefined) => T | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2F,SAAS,IAAI,eAAe,EAAE,MAAM,WAAW,CAAA;AAEjJ,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAChF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAKpD,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAErD,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAAI,GAAG,SAEtD,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,IAAI,WAAW,CAAC,CAAC,CAE7D,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,QAAQ,GAAG,KAAG,KAAK,IAAI,UAAU,CAAC,OAAO,CAOjE,CAAA;AAGD,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,CAAC,MAAM,GAAG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;AAE1G,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,QAAQ,aAAa,EAAE,WAAW,CAAC,KAAG,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAEvI,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,KAAG,CAAC,GAAG,SAE9D,CAAA"}
package/dist/object.js CHANGED
@@ -2,7 +2,8 @@
2
2
  import { clone as _clone, cloneDeep as _cloneDeep, mapValues as _mapValues, merge as unsafeMerge, mergeWith as unsafeMergeWith } from "lodash-es";
3
3
  import { isNumber } from "@bessemer/cornerstone/math";
4
4
  import { isString } from "@bessemer/cornerstone/string";
5
- import { isDate } from "@bessemer/cornerstone/date";
5
+ import { isDate } from "@bessemer/cornerstone/temporal/date";
6
+ import { _isInstant } from "@bessemer/cornerstone/temporal/chrono";
6
7
  var isUndefined = (value) => {
7
8
  return value === void 0;
8
9
  };
@@ -112,7 +113,7 @@ var isPrimitive = (value) => {
112
113
  return value === null || typeof value !== "object" && typeof value !== "function";
113
114
  };
114
115
  var isBasic = (value) => {
115
- return isNumber(value) || isString(value) || isDate(value) || isBoolean(value);
116
+ return isNumber(value) || isString(value) || isDate(value) || isBoolean(value) || _isInstant(value);
116
117
  };
117
118
  var isBoolean = (value) => {
118
119
  return typeof value === "boolean";
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/object.ts"],"sourcesContent":["import { clone as _clone, cloneDeep as _cloneDeep, mapValues as _mapValues, merge as unsafeMerge, mergeWith as unsafeMergeWith } from 'lodash-es'\n\nimport { BasicType, Dictionary, NominalType } from '@bessemer/cornerstone/types'\nimport { Primitive, UnknownRecord } from 'type-fest'\nimport { isNumber } from '@bessemer/cornerstone/math'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isDate } from '@bessemer/cornerstone/date'\n\nexport const isUndefined = (value: unknown): value is undefined => {\n return value === undefined\n}\n\nexport const isNil = (value: unknown): value is null | undefined => {\n return value === null || value === undefined\n}\n\nexport const isPresent = <T>(value: T): value is NonNullable<T> => {\n return !isNil(value)\n}\n\nexport const isObject = (value?: any): value is Dictionary<unknown> => {\n if (value === null || value === undefined || typeof value !== 'object') {\n return false\n }\n\n const proto = Object.getPrototypeOf(value)\n return proto !== null && Object.getPrototypeOf(proto) === null\n}\n\n// JOHN should this also check for the nil case?\nexport const isEmpty = (value: Record<string | number | symbol, unknown>): boolean => {\n return Object.keys(value).length === 0\n}\n\nexport const deepEqual = (value1: unknown, value2: unknown): boolean => {\n if (value1 === value2) {\n return true\n }\n\n // If either value is null or undefined, they're not equal (since we already checked ===)\n if (isNil(value1) || isNil(value2)) {\n return false\n }\n\n if (isDate(value1) && isDate(value2)) {\n return value1.getTime() === value2.getTime()\n }\n\n if (value1 instanceof RegExp && value2 instanceof RegExp) {\n return value1.toString() === value2.toString()\n }\n\n if (typeof value1 !== typeof value2) {\n return false\n }\n\n if (Array.isArray(value1) && Array.isArray(value2)) {\n if (value1.length !== value2.length) {\n return false\n }\n\n for (let i = 0; i < value1.length; i++) {\n if (!deepEqual(value1[i], value2[i])) {\n return false\n }\n }\n\n return true\n }\n\n if (isObject(value1) && isObject(value2)) {\n const keys1 = Object.keys(value1)\n const keys2 = Object.keys(value2)\n\n if (keys1.length !== keys2.length) {\n return false\n }\n\n for (const key of keys1) {\n if (!deepEqual(value1[key], value2[key])) {\n return false\n }\n }\n\n return true\n }\n\n return false\n}\n\nexport const mapValues = _mapValues\n\nexport const clone = _clone\nexport const cloneDeep = _cloneDeep\n\nexport function deepMerge<TObject, TSource>(object: TObject, source: TSource): TObject & TSource\nexport function deepMerge<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2\nexport function deepMerge<TObject, TSource1, TSource2, TSource3>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3\n): TObject & TSource1 & TSource2 & TSource3\nexport function deepMerge<TObject, TSource1, TSource2, TSource3, TSource4>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3,\n source4: TSource4\n): TObject & TSource1 & TSource2 & TSource3 & TSource4\nexport function deepMerge(object: any, ...otherArgs: any[]): any {\n return unsafeMerge({}, object, ...otherArgs)\n}\n\nexport const deepMergeAll = <T>(objects: Array<T>): T => {\n return objects.reduce((x, y) => deepMerge(x, y))\n}\n\nexport function deepMergeInto<Source1, Source2>(source: Source1, values: Source2): asserts source is Source1 & Source2 {\n unsafeMerge(source, values)\n}\n\nexport const deepMergeWith: typeof unsafeMergeWith = (...args: Array<any>) => {\n const clone = cloneDeep(args[0])\n return unsafeMergeWith.apply(null, [clone, ...args.slice(1)])\n}\n\nexport type ObjectDiffResult = {\n elementsUpdated: Record<string, { originalValue: unknown; updatedValue: unknown }>\n elementsAdded: UnknownRecord\n elementsRemoved: UnknownRecord\n}\n\nexport function diffShallow(original: UnknownRecord, updated: UnknownRecord): ObjectDiffResult {\n const result: ObjectDiffResult = {\n elementsUpdated: {},\n elementsAdded: {},\n elementsRemoved: {},\n }\n\n for (const [key, originalValue] of Object.entries(original)) {\n const updatedValue = updated[key]\n if (updatedValue === undefined) {\n result.elementsRemoved[key] = originalValue\n } else if (!deepEqual(originalValue, updatedValue)) {\n result.elementsUpdated[key] = { originalValue: originalValue, updatedValue: updatedValue }\n }\n }\n\n for (const [key, updatedValue] of Object.entries(updated)) {\n const originalValue = original[key]\n if (originalValue === undefined) {\n result.elementsAdded[key] = updatedValue\n }\n }\n return result\n}\n\nexport const isValidKey = (field: PropertyKey, obj: object): field is keyof typeof obj => {\n return field in obj\n}\n\n/** Determines if the list of fields are present on the object (not null or undefined), with type inference */\nexport function fieldsPresent<T extends object, K extends keyof T>(\n object: T,\n fields: Array<K>\n): object is Exclude<T, K> & Required<{ [P in K]: NonNullable<T[P]> }> {\n return fields.every((field) => isPresent(object[field]))\n}\n\nexport const isPrimitive = (value: any): value is Primitive => {\n return value === null || (typeof value !== 'object' && typeof value !== 'function')\n}\n\nexport const isBasic = (value: any): value is BasicType => {\n return isNumber(value) || isString(value) || isDate(value) || isBoolean(value)\n}\n\nexport const isBoolean = (value: unknown): value is boolean => {\n return typeof value === 'boolean'\n}\n\ntype TransformFunction = (value: any, path: (string | number)[], key: string | number, parent: any) => any\n\nconst walk = (value: any, transform: TransformFunction, path: (string | number)[] = []): any => {\n if (isNil(value) || isPrimitive(value)) {\n return value\n }\n\n if (Array.isArray(value)) {\n return value.map((value, index) => {\n const currentPath = [...path, index]\n return walk(transform(value, currentPath, index, value), transform, currentPath)\n })\n }\n\n const result: any = {}\n for (const key in value) {\n if (Object.prototype.hasOwnProperty.call(value, key)) {\n const currentPath = [...path, key]\n const transformedValue = transform(value[key], currentPath, key, value)\n result[key] = walk(transformedValue, transform, currentPath)\n }\n }\n\n return result\n}\n\nexport type RecordAttribute<Type = unknown, Class extends string = 'RecordAttribute'> = NominalType<string, [Type, Class]>\ntype RecordAttributeType<Attribute> = Attribute extends RecordAttribute<infer Type, string> ? Type : never\n\nexport const getAttribute = <T extends RecordAttribute<unknown, string>>(record: UnknownRecord, attribute: T): RecordAttributeType<T> | undefined => {\n return record[attribute] as RecordAttributeType<T> | undefined\n}\n\nexport const coerceNil = <T>(value: T | null | undefined): T | undefined => {\n return isNil(value) ? undefined : value\n}\n"],"mappings":";AAAA,SAAS,SAAS,QAAQ,aAAa,YAAY,aAAa,YAAY,SAAS,aAAa,aAAa,uBAAuB;AAItI,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEhB,IAAM,cAAc,CAAC,UAAuC;AACjE,SAAO,UAAU;AACnB;AAEO,IAAM,QAAQ,CAAC,UAA8C;AAClE,SAAO,UAAU,QAAQ,UAAU;AACrC;AAEO,IAAM,YAAY,CAAI,UAAsC;AACjE,SAAO,CAAC,MAAM,KAAK;AACrB;AAEO,IAAM,WAAW,CAAC,UAA8C;AACrE,MAAI,UAAU,QAAQ,UAAU,UAAa,OAA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;AACrE,SAAO,OAAO,MAAM,CAAC,UAAU,UAAU,OAAO,KAAK,CAAC,CAAC;AACzD;AAEO,IAAM,cAAc,CAAC,UAAmC;AAC7D,SAAO,UAAU,QAAS,OAAO,UAAU,YAAY,OAAO,UAAU;AAC1E;AAEO,IAAM,UAAU,CAAC,UAAmC;AACzD,SAAO,SAAS,KAAK,KAAK,SAAS,KAAK,KAAK,OAAO,KAAK,KAAK,UAAU,KAAK;AAC/E;AAEO,IAAM,YAAY,CAAC,UAAqC;AAC7D,SAAO,OAAO,UAAU;AAC1B;AA+BO,IAAM,eAAe,CAA6C,QAAuB,cAAqD;AACnJ,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,YAAY,CAAI,UAA+C;AAC1E,SAAO,MAAM,KAAK,IAAI,SAAY;AACpC;","names":["clone"]}
1
+ {"version":3,"sources":["../src/object.ts"],"sourcesContent":["import { clone as _clone, cloneDeep as _cloneDeep, mapValues as _mapValues, merge as unsafeMerge, mergeWith as unsafeMergeWith } from 'lodash-es'\n\nimport { BasicType, Dictionary, TaggedType } from '@bessemer/cornerstone/types'\nimport { Primitive, UnknownRecord } from 'type-fest'\nimport { isNumber } from '@bessemer/cornerstone/math'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isDate } from '@bessemer/cornerstone/temporal/date'\nimport { _isInstant } from '@bessemer/cornerstone/temporal/chrono'\n\nexport const isUndefined = (value: unknown): value is undefined => {\n return value === undefined\n}\n\nexport const isNil = (value: unknown): value is null | undefined => {\n return value === null || value === undefined\n}\n\nexport const isPresent = <T>(value: T): value is NonNullable<T> => {\n return !isNil(value)\n}\n\nexport const isObject = (value?: any): value is Dictionary<unknown> => {\n if (value === null || value === undefined || typeof value !== 'object') {\n return false\n }\n\n const proto = Object.getPrototypeOf(value)\n return proto !== null && Object.getPrototypeOf(proto) === null\n}\n\n// JOHN should this also check for the nil case?\nexport const isEmpty = (value: Record<string | number | symbol, unknown>): boolean => {\n return Object.keys(value).length === 0\n}\n\nexport const deepEqual = (value1: unknown, value2: unknown): boolean => {\n if (value1 === value2) {\n return true\n }\n\n // If either value is null or undefined, they're not equal (since we already checked ===)\n if (isNil(value1) || isNil(value2)) {\n return false\n }\n\n if (isDate(value1) && isDate(value2)) {\n return value1.getTime() === value2.getTime()\n }\n\n if (value1 instanceof RegExp && value2 instanceof RegExp) {\n return value1.toString() === value2.toString()\n }\n\n if (typeof value1 !== typeof value2) {\n return false\n }\n\n if (Array.isArray(value1) && Array.isArray(value2)) {\n if (value1.length !== value2.length) {\n return false\n }\n\n for (let i = 0; i < value1.length; i++) {\n if (!deepEqual(value1[i], value2[i])) {\n return false\n }\n }\n\n return true\n }\n\n if (isObject(value1) && isObject(value2)) {\n const keys1 = Object.keys(value1)\n const keys2 = Object.keys(value2)\n\n if (keys1.length !== keys2.length) {\n return false\n }\n\n for (const key of keys1) {\n if (!deepEqual(value1[key], value2[key])) {\n return false\n }\n }\n\n return true\n }\n\n return false\n}\n\nexport const mapValues = _mapValues\n\nexport const clone = _clone\nexport const cloneDeep = _cloneDeep\n\nexport function deepMerge<TObject, TSource>(object: TObject, source: TSource): TObject & TSource\nexport function deepMerge<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2\nexport function deepMerge<TObject, TSource1, TSource2, TSource3>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3\n): TObject & TSource1 & TSource2 & TSource3\nexport function deepMerge<TObject, TSource1, TSource2, TSource3, TSource4>(\n object: TObject,\n source1: TSource1,\n source2: TSource2,\n source3: TSource3,\n source4: TSource4\n): TObject & TSource1 & TSource2 & TSource3 & TSource4\nexport function deepMerge(object: any, ...otherArgs: any[]): any {\n return unsafeMerge({}, object, ...otherArgs)\n}\n\nexport const deepMergeAll = <T>(objects: Array<T>): T => {\n return objects.reduce((x, y) => deepMerge(x, y))\n}\n\nexport function deepMergeInto<Source1, Source2>(source: Source1, values: Source2): asserts source is Source1 & Source2 {\n unsafeMerge(source, values)\n}\n\nexport const deepMergeWith: typeof unsafeMergeWith = (...args: Array<any>) => {\n const clone = cloneDeep(args[0])\n return unsafeMergeWith.apply(null, [clone, ...args.slice(1)])\n}\n\nexport type ObjectDiffResult = {\n elementsUpdated: Record<string, { originalValue: unknown; updatedValue: unknown }>\n elementsAdded: UnknownRecord\n elementsRemoved: UnknownRecord\n}\n\nexport function diffShallow(original: UnknownRecord, updated: UnknownRecord): ObjectDiffResult {\n const result: ObjectDiffResult = {\n elementsUpdated: {},\n elementsAdded: {},\n elementsRemoved: {},\n }\n\n for (const [key, originalValue] of Object.entries(original)) {\n const updatedValue = updated[key]\n if (updatedValue === undefined) {\n result.elementsRemoved[key] = originalValue\n } else if (!deepEqual(originalValue, updatedValue)) {\n result.elementsUpdated[key] = { originalValue: originalValue, updatedValue: updatedValue }\n }\n }\n\n for (const [key, updatedValue] of Object.entries(updated)) {\n const originalValue = original[key]\n if (originalValue === undefined) {\n result.elementsAdded[key] = updatedValue\n }\n }\n return result\n}\n\nexport const isValidKey = (field: PropertyKey, obj: object): field is keyof typeof obj => {\n return field in obj\n}\n\n/** Determines if the list of fields are present on the object (not null or undefined), with type inference */\nexport function fieldsPresent<T extends object, K extends keyof T>(\n object: T,\n fields: Array<K>\n): object is Exclude<T, K> & Required<{ [P in K]: NonNullable<T[P]> }> {\n return fields.every((field) => isPresent(object[field]))\n}\n\nexport const isPrimitive = (value: any): value is Primitive => {\n return value === null || (typeof value !== 'object' && typeof value !== 'function')\n}\n\nexport const isBasic = (value: any): value is BasicType => {\n return isNumber(value) || isString(value) || isDate(value) || isBoolean(value) || _isInstant(value)\n}\n\nexport const isBoolean = (value: unknown): value is boolean => {\n return typeof value === 'boolean'\n}\n\ntype TransformFunction = (value: any, path: (string | number)[], key: string | number, parent: any) => any\n\nconst walk = (value: any, transform: TransformFunction, path: (string | number)[] = []): any => {\n if (isNil(value) || isPrimitive(value)) {\n return value\n }\n\n if (Array.isArray(value)) {\n return value.map((value, index) => {\n const currentPath = [...path, index]\n return walk(transform(value, currentPath, index, value), transform, currentPath)\n })\n }\n\n const result: any = {}\n for (const key in value) {\n if (Object.prototype.hasOwnProperty.call(value, key)) {\n const currentPath = [...path, key]\n const transformedValue = transform(value[key], currentPath, key, value)\n result[key] = walk(transformedValue, transform, currentPath)\n }\n }\n\n return result\n}\n\nexport type RecordAttribute<Type = unknown, Class extends string = 'RecordAttribute'> = TaggedType<string, [Type, Class]>\ntype RecordAttributeType<Attribute> = Attribute extends RecordAttribute<infer Type, string> ? Type : never\n\nexport const getAttribute = <T extends RecordAttribute<unknown, string>>(record: UnknownRecord, attribute: T): RecordAttributeType<T> | undefined => {\n return record[attribute] as RecordAttributeType<T> | undefined\n}\n\nexport const coerceNil = <T>(value: T | null | undefined): T | undefined => {\n return isNil(value) ? undefined : value\n}\n"],"mappings":";AAAA,SAAS,SAAS,QAAQ,aAAa,YAAY,aAAa,YAAY,SAAS,aAAa,aAAa,uBAAuB;AAItI,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAEpB,IAAM,cAAc,CAAC,UAAuC;AACjE,SAAO,UAAU;AACnB;AAEO,IAAM,QAAQ,CAAC,UAA8C;AAClE,SAAO,UAAU,QAAQ,UAAU;AACrC;AAEO,IAAM,YAAY,CAAI,UAAsC;AACjE,SAAO,CAAC,MAAM,KAAK;AACrB;AAEO,IAAM,WAAW,CAAC,UAA8C;AACrE,MAAI,UAAU,QAAQ,UAAU,UAAa,OAAO,UAAU,UAAU;AACtE,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,SAAO,UAAU,QAAQ,OAAO,eAAe,KAAK,MAAM;AAC5D;AAGO,IAAM,UAAU,CAAC,UAA8D;AACpF,SAAO,OAAO,KAAK,KAAK,EAAE,WAAW;AACvC;AAEO,IAAM,YAAY,CAAC,QAAiB,WAA6B;AACtE,MAAI,WAAW,QAAQ;AACrB,WAAO;AAAA,EACT;AAGA,MA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,IAAM,YAAY,CAAC,UAAqC;AAC7D,SAAO,OAAO,UAAU;AAC1B;AA+BO,IAAM,eAAe,CAA6C,QAAuB,cAAqD;AACnJ,SAAO,OAAO,SAAS;AACzB;AAEO,IAAM,YAAY,CAAI,UAA+C;AAC1E,SAAO,MAAM,KAAK,IAAI,SAAY;AACpC;","names":["clone"]}
package/dist/range.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Zod, { ZodType } from 'zod';
2
- import { TaggedType } from '@bessemer/cornerstone/types';
3
- export type Bounds<T> = TaggedType<[T | null, T | null], 'Bounds'>;
2
+ import { NominalType } from '@bessemer/cornerstone/types';
3
+ export type Bounds<T> = NominalType<[T | null, T | null], 'Bounds'>;
4
4
  export type BoundsInput<T> = [lower: T | null, upper?: T | null] | Bounds<T>;
5
5
  export declare const schema: <T extends ZodType>(type: T) => ZodType<Bounds<Zod.infer<T>>, Bounds<Zod.infer<T>>>;
6
6
  export type NumericBounds = Bounds<number>;
@@ -1 +1 @@
1
- {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAIxD,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAA;AAClE,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;AAE5E,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAA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CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACpC,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAA;AAEtD,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,QAAQ,WAAW,CAAC,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,CAMtD,CAAA"}
package/dist/range.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/range.ts"],"sourcesContent":["import Zod, { ZodType } from 'zod'\nimport { TaggedType } 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> = TaggedType<[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]\nexport type FiniteNumericBounds = FiniteBounds<number>\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;AAKzC,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 { 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]\nexport type FiniteNumericBounds = FiniteBounds<number>\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;AAKzC,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,6 +1,6 @@
1
1
  import { Comparator } from '@bessemer/cornerstone/comparator';
2
- import { NominalType } from '@bessemer/cornerstone/types';
3
- export type ReferenceId<T extends string> = NominalType<string, ['ReferenceId', T]>;
2
+ import { TaggedType } from '@bessemer/cornerstone/types';
3
+ export type ReferenceId<T extends string> = TaggedType<string, ['ReferenceId', T]>;
4
4
  export type Reference<T extends string> = {
5
5
  id: ReferenceId<T>;
6
6
  type: T;
@@ -1 +1 @@
1
- {"version":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AAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,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,8EAAqC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/reference.ts"],"sourcesContent":["import { Comparator, compareBy, natural } from '@bessemer/cornerstone/comparator'\nimport { NominalType } 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\nexport type ReferenceId<T extends string> = NominalType<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;AAkBxB,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 { 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,12 +1,21 @@
1
- import { TaggedType } from '@bessemer/cornerstone/types';
1
+ import { NominalType } from '@bessemer/cornerstone/types';
2
2
  import Zod from 'zod';
3
3
  export type ResourceKey = string;
4
- export type ResourceNamespace = TaggedType<string, 'ResourceNamespace'>;
5
- export declare const namespace: (value: string) => ResourceNamespace;
6
- export declare const ResourceNamespaceSchema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<ResourceNamespace, string>>;
7
- export declare const applyNamespace: (name: ResourceNamespace, key: ResourceKey) => ResourceKey;
8
- export declare const applyNamespaceAll: (name: ResourceNamespace, keys: Array<ResourceKey>) => Array<ResourceKey>;
9
- export declare const stripNamespace: (name: ResourceNamespace, key: ResourceKey) => ResourceKey;
10
- export declare const stripNamespaceAll: (name: ResourceNamespace, keys: Array<ResourceKey>) => Array<ResourceKey>;
4
+ export type NamespaceKey = string | undefined;
5
+ export type ResourceNamespace<NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<NamespaceType, 'ResourceNamespace'> | undefined;
6
+ export type NamespacedKey<KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey> = NominalType<string, [
7
+ 'NamespacedKey',
8
+ KeyType,
9
+ NamespaceType
10
+ ]>;
11
+ export declare const emptyNamespace: () => ResourceNamespace<undefined>;
12
+ export declare const namespace: <T extends NamespaceKey>(value: T) => ResourceNamespace<T>;
13
+ export declare const ResourceNamespaceSchema: Zod.ZodPipe<Zod.ZodOptional<Zod.ZodString>, Zod.ZodTransform<(string & import("@bessemer/cornerstone/types").NominalTyping<"ResourceNamespace">) | undefined, string | undefined>>;
14
+ export declare const applyNamespace: <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(key: KeyType, namespace: ResourceNamespace<NamespaceType>) => NamespacedKey<KeyType, NamespaceType>;
15
+ export declare const applyNamespaceAll: <KeyType extends ResourceKey = ResourceKey, NamespaceType extends NamespaceKey = NamespaceKey>(keys: Array<KeyType>, namespace: ResourceNamespace<NamespaceType>) => Array<NamespacedKey<KeyType, NamespaceType>>;
16
+ export declare const splitNamespace: <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(key: NamespacedKey<KeyType, NamespaceType>) => [KeyType, ResourceNamespace<NamespaceType>];
17
+ export declare const getKey: <KeyType extends ResourceKey, NamespaceType extends NamespaceKey>(namespacedKey: NamespacedKey<KeyType, NamespaceType>) => KeyType;
11
18
  export declare const extendNamespace: (...names: Array<ResourceNamespace>) => ResourceNamespace;
19
+ export declare const encodeKey: (key: ResourceKey) => ResourceKey;
20
+ export declare const decodeKey: (encodedKey: ResourceKey) => ResourceKey;
12
21
  //# sourceMappingURL=resource-key.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource-key.d.ts","sourceRoot":"","sources":["../src/resource-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,GAAG,MAAM,KAAK,CAAA;AAGrB,MAAM,MAAM,WAAW,GAAG,MAAM,CAAA;AAIhC,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;AAEvE,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,iBAEzC,CAAA;AAED,eAAO,MAAM,uBAAuB,yEAAoC,CAAA;AAExE,eAAO,MAAM,cAAc,GAAI,MAAM,iBAAiB,EAAE,KAAK,WAAW,KAAG,WAE1E,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,MAAM,iBAAiB,EAAE,MAAM,KAAK,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EACZ,WAAW,iBAAiB,CAAC,aAAa,CAAC,KAC1C,aAAa,CAAC,OAAO,EAAE,aAAa,CAMtC,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,aAAa,SAAS,YAAY,GAAG,YAAY,EAC5H,MAAM,KAAK,CAAC,OAAO,CAAC,EACpB,WAAW,iBAAiB,CAAC,aAAa,CAAC,KAC1C,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,CAE7C,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,WAAW,EAAE,aAAa,SAAS,YAAY,EAC5F,KAAK,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,KACzC,CAAC,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAY5C,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,OAAO,SAAS,WAAW,EAAE,aAAa,SAAS,YAAY,EACpF,eAAe,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,KACnD,OAGF,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,GAAG,OAAO,KAAK,CAAC,iBAAiB,CAAC,KAAG,iBAEpE,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,WAAW,KAAG,WAE5C,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,YAAY,WAAW,KAAG,WAEnD,CAAA"}
@@ -1,33 +1,62 @@
1
1
  // src/resource-key.ts
2
2
  import Zod from "zod";
3
- import { removeStart } from "@bessemer/cornerstone/string";
4
3
  var ResourceNamespaceSeparator = "/";
4
+ var emptyNamespace = () => {
5
+ return void 0;
6
+ };
5
7
  var namespace = (value) => {
8
+ if (value === void 0) {
9
+ return value;
10
+ }
11
+ if (!/^[^\s\/][^\s\/]*(?:\/[^\s\/][^\s\/]*)*$/.test(value)) {
12
+ throw new Error(`Unsupported Namespace format: ${value}`);
13
+ }
6
14
  return value;
7
15
  };
8
- var ResourceNamespaceSchema = Zod.string().transform(namespace);
9
- var applyNamespace = (name, key) => {
10
- return `${name}${ResourceNamespaceSeparator}${key}`;
16
+ var ResourceNamespaceSchema = Zod.string().optional().transform(namespace);
17
+ var applyNamespace = (key, namespace2) => {
18
+ if (namespace2 === void 0) {
19
+ return encodeKey(key);
20
+ }
21
+ return `${namespace2}${ResourceNamespaceSeparator}${encodeKey(key)}`;
11
22
  };
12
- var applyNamespaceAll = (name, keys) => {
13
- return keys.map((it) => applyNamespace(name, it));
23
+ var applyNamespaceAll = (keys, namespace2) => {
24
+ return keys.map((it) => applyNamespace(it, namespace2));
14
25
  };
15
- var stripNamespace = (name, key) => {
16
- return removeStart(key, `${name}${ResourceNamespaceSeparator}`);
26
+ var splitNamespace = (key) => {
27
+ const lastIndex = key.lastIndexOf(ResourceNamespaceSeparator);
28
+ if (lastIndex !== -1) {
29
+ const namespacePart = key.substring(0, lastIndex);
30
+ const keyPart = key.substring(lastIndex + 1);
31
+ return [decodeKey(keyPart), namespacePart];
32
+ } else {
33
+ const keyPart = key;
34
+ return [decodeKey(keyPart), void 0];
35
+ }
17
36
  };
18
- var stripNamespaceAll = (name, keys) => {
19
- return keys.map((it) => stripNamespace(name, it));
37
+ var getKey = (namespacedKey) => {
38
+ const [key, _] = splitNamespace(namespacedKey);
39
+ return key;
20
40
  };
21
41
  var extendNamespace = (...names) => {
22
- return namespace(names.join(ResourceNamespaceSeparator));
42
+ return names.join(ResourceNamespaceSeparator);
43
+ };
44
+ var encodeKey = (key) => {
45
+ return key.replace(/%/g, "%25").replace(/\//g, "%2F");
46
+ };
47
+ var decodeKey = (encodedKey) => {
48
+ return encodedKey.replace(/%2F/g, "/").replace(/%25/g, "%");
23
49
  };
24
50
  export {
25
51
  ResourceNamespaceSchema,
26
52
  applyNamespace,
27
53
  applyNamespaceAll,
54
+ decodeKey,
55
+ emptyNamespace,
56
+ encodeKey,
28
57
  extendNamespace,
58
+ getKey,
29
59
  namespace,
30
- stripNamespace,
31
- stripNamespaceAll
60
+ splitNamespace
32
61
  };
33
62
  //# sourceMappingURL=resource-key.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/resource-key.ts"],"sourcesContent":["import { TaggedType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\nimport { removeStart } from '@bessemer/cornerstone/string'\n\nexport type ResourceKey = string\n\nconst ResourceNamespaceSeparator = '/'\n\nexport type ResourceNamespace = TaggedType<string, 'ResourceNamespace'>\n\nexport const namespace = (value: string): ResourceNamespace => {\n return value as ResourceNamespace\n}\n\nexport const ResourceNamespaceSchema = Zod.string().transform(namespace)\n\nexport const applyNamespace = (name: ResourceNamespace, key: ResourceKey): ResourceKey => {\n return `${name}${ResourceNamespaceSeparator}${key}`\n}\n\nexport const applyNamespaceAll = (name: ResourceNamespace, keys: Array<ResourceKey>): Array<ResourceKey> => {\n return keys.map((it) => applyNamespace(name, it))\n}\n\nexport const stripNamespace = (name: ResourceNamespace, key: ResourceKey): ResourceKey => {\n return removeStart(key, `${name}${ResourceNamespaceSeparator}`)\n}\n\nexport const stripNamespaceAll = (name: ResourceNamespace, keys: Array<ResourceKey>): Array<ResourceKey> => {\n return keys.map((it) => stripNamespace(name, it))\n}\n\nexport const extendNamespace = (...names: Array<ResourceNamespace>): ResourceNamespace => {\n return namespace(names.join(ResourceNamespaceSeparator))\n}\n"],"mappings":";AACA,OAAO,SAAS;AAChB,SAAS,mBAAmB;AAI5B,IAAM,6BAA6B;AAI5B,IAAM,YAAY,CAAC,UAAqC;AAC7D,SAAO;AACT;AAEO,IAAM,0BAA0B,IAAI,OAAO,EAAE,UAAU,SAAS;AAEhE,IAAM,iBAAiB,CAAC,MAAyB,QAAkC;AACxF,SAAO,GAAG,IAAI,GAAG,0BAA0B,GAAG,GAAG;AACnD;AAEO,IAAM,oBAAoB,CAAC,MAAyB,SAAiD;AAC1G,SAAO,KAAK,IAAI,CAAC,OAAO,eAAe,MAAM,EAAE,CAAC;AAClD;AAEO,IAAM,iBAAiB,CAAC,MAAyB,QAAkC;AACxF,SAAO,YAAY,KAAK,GAAG,IAAI,GAAG,0BAA0B,EAAE;AAChE;AAEO,IAAM,oBAAoB,CAAC,MAAyB,SAAiD;AAC1G,SAAO,KAAK,IAAI,CAAC,OAAO,eAAe,MAAM,EAAE,CAAC;AAClD;AAEO,IAAM,kBAAkB,IAAI,UAAuD;AACxF,SAAO,UAAU,MAAM,KAAK,0BAA0B,CAAC;AACzD;","names":[]}
1
+ {"version":3,"sources":["../src/resource-key.ts"],"sourcesContent":["import { NominalType } from '@bessemer/cornerstone/types'\nimport Zod from 'zod'\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 namespace = <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 ResourceNamespaceSchema = Zod.string().optional().transform(namespace)\n\nexport const applyNamespace = <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 applyNamespaceAll = <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) => applyNamespace(it, namespace))\n}\n\nexport const splitNamespace = <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, _] = splitNamespace(namespacedKey)\n return key\n}\n\nexport const extendNamespace = (...names: Array<ResourceNamespace>): ResourceNamespace => {\n return names.join(ResourceNamespaceSeparator) as ResourceNamespace\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;AAGhB,IAAM,6BAA6B;AAU5B,IAAM,iBAAiB,MAAoC;AAChE,SAAO;AACT;AAEO,IAAM,YAAY,CAAyB,UAAmC;AACnF,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,0BAA0B,IAAI,OAAO,EAAE,SAAS,EAAE,UAAU,SAAS;AAE3E,IAAM,iBAAiB,CAC5B,KACAA,eAC0C;AAC1C,MAAIA,eAAc,QAAW;AAC3B,WAAO,UAAU,GAAG;AAAA,EACtB;AAEA,SAAO,GAAGA,UAAS,GAAG,0BAA0B,GAAG,UAAU,GAAG,CAAC;AACnE;AAEO,IAAM,oBAAoB,CAC/B,MACAA,eACiD;AACjD,SAAO,KAAK,IAAI,CAAC,OAAO,eAAe,IAAIA,UAAS,CAAC;AACvD;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,kBAAkB,IAAI,UAAuD;AACxF,SAAO,MAAM,KAAK,0BAA0B;AAC9C;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":["namespace"]}
package/dist/result.d.ts CHANGED
@@ -3,17 +3,18 @@ import { Throwable } from '@bessemer/cornerstone/types';
3
3
  export type Success<T> = Right<T> & {
4
4
  isSuccess: true;
5
5
  };
6
- export type Failure = Left<Throwable | null> & {
6
+ export type Failure<N = Throwable> = Left<N> & {
7
7
  isSuccess: false;
8
8
  };
9
- export type Result<T> = Success<T> | Failure;
10
- export type AsyncResult<T> = Promise<Result<T>>;
9
+ export type Result<T, N = Throwable> = Success<T> | Failure<N>;
10
+ export type AsyncResult<T, N = Throwable> = Promise<Result<T, N>>;
11
11
  export declare const success: <T>(value: T) => Success<T>;
12
- export declare const failure: (failure?: Throwable) => Failure;
12
+ export declare function failure(): Failure<never>;
13
+ export declare function failure<N>(failure: N): Failure<N>;
13
14
  export declare const getValueOrThrow: <T>(result: Result<T>) => T;
14
15
  export declare function tryValue<SOURCE_VALUE>(resolver: () => Promise<SOURCE_VALUE>): AsyncResult<SOURCE_VALUE>;
15
16
  export declare function tryValue<SOURCE_VALUE>(resolver: () => SOURCE_VALUE): Result<SOURCE_VALUE>;
16
17
  export declare function tryResult<SOURCE_VALUE>(resolver: () => Result<SOURCE_VALUE>): Result<SOURCE_VALUE>;
17
18
  export declare function tryResult<SOURCE_VALUE>(resolver: () => AsyncResult<SOURCE_VALUE>): AsyncResult<SOURCE_VALUE>;
18
- export declare function map<SOURCE_VALUE, TARGET_VALUE>(result: Result<SOURCE_VALUE>, valueMapper: (element: SOURCE_VALUE) => TARGET_VALUE): Result<TARGET_VALUE>;
19
+ export declare function mapResult<SourceType, TargetType, ErrorType>(result: Result<SourceType, ErrorType>, valueMapper: (element: SourceType) => TargetType): Result<TargetType, ErrorType>;
19
20
  //# sourceMappingURL=result.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,IAAI,EAAS,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAGvD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG;IAClC,SAAS,EAAE,IAAI,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG;IAC7C,SA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YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC,YAAY,CAAC,GAAG,WAAW,CAAC,YAAY,CAAC,CAAA;AAc7G,wBAAgB,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EACzD,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,EACrC,WAAW,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,UAAU,GAC/C,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,CAS/B"}
package/dist/result.js CHANGED
@@ -4,9 +4,9 @@ import { isPromise } from "@bessemer/cornerstone/promise";
4
4
  var success = (value) => {
5
5
  return { ...right(value), isSuccess: true };
6
6
  };
7
- var failure = (failure2) => {
7
+ function failure(failure2) {
8
8
  return { ...left(failure2 ?? null), isSuccess: false };
9
- };
9
+ }
10
10
  var getValueOrThrow = (result) => {
11
11
  if (result.isSuccess) {
12
12
  return result.value;
@@ -38,7 +38,7 @@ function tryResult(resolver) {
38
38
  return failure(e);
39
39
  }
40
40
  }
41
- function map(result, valueMapper) {
41
+ function mapResult(result, valueMapper) {
42
42
  if (result.isSuccess) {
43
43
  return {
44
44
  ...result,
@@ -51,7 +51,7 @@ function map(result, valueMapper) {
51
51
  export {
52
52
  failure,
53
53
  getValueOrThrow,
54
- map,
54
+ mapResult,
55
55
  success,
56
56
  tryResult,
57
57
  tryValue