@bessemer/cornerstone 0.5.101 → 0.5.106
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.
- package/dist/array.d.ts +1 -1
- package/dist/array.d.ts.map +1 -1
- package/dist/array.js.map +1 -1
- package/dist/either.d.ts +43 -12
- package/dist/either.d.ts.map +1 -1
- package/dist/either.js +81 -8
- package/dist/either.js.map +1 -1
- package/dist/json.d.ts +0 -1
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +2 -6
- package/dist/json.js.map +1 -1
- package/dist/net/uri.d.ts.map +1 -1
- package/dist/net/uri.js +3 -3
- package/dist/net/uri.js.map +1 -1
- package/dist/net/url.d.ts.map +1 -1
- package/dist/net/url.js +2 -2
- package/dist/net/url.js.map +1 -1
- package/dist/promise.d.ts +1 -0
- package/dist/promise.d.ts.map +1 -1
- package/dist/promise.js +10 -1
- package/dist/promise.js.map +1 -1
- package/dist/result.d.ts +13 -5
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +48 -21
- package/dist/result.js.map +1 -1
- package/dist/temporal/duration.d.ts.map +1 -1
- package/dist/temporal/duration.js +2 -2
- package/dist/temporal/duration.js.map +1 -1
- package/dist/temporal/instant.d.ts.map +1 -1
- package/dist/temporal/instant.js +2 -2
- package/dist/temporal/instant.js.map +1 -1
- package/dist/temporal/plain-date-time.d.ts.map +1 -1
- package/dist/temporal/plain-date-time.js +2 -2
- package/dist/temporal/plain-date-time.js.map +1 -1
- package/dist/temporal/plain-date.d.ts.map +1 -1
- package/dist/temporal/plain-date.js +2 -2
- package/dist/temporal/plain-date.js.map +1 -1
- package/dist/temporal/plain-time.d.ts.map +1 -1
- package/dist/temporal/plain-time.js +2 -2
- package/dist/temporal/plain-time.js.map +1 -1
- package/dist/temporal/zoned-date-time.d.ts.map +1 -1
- package/dist/temporal/zoned-date-time.js +2 -2
- package/dist/temporal/zoned-date-time.js.map +1 -1
- package/dist/zod-util.d.ts +0 -1
- package/dist/zod-util.d.ts.map +1 -1
- package/dist/zod-util.js +2 -6
- package/dist/zod-util.js.map +1 -1
- package/package.json +3 -3
package/dist/array.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export declare function groupBy<T, N extends string | number | symbol>(array: Ar
|
|
|
103
103
|
export declare const rest: <T>(array: Array<T>, elementsToSkip?: number) => Array<T>;
|
|
104
104
|
export declare const filterInPlace: <T>(array: Array<T>, predicate: (value: T, index: number, array: Array<T>) => boolean) => void;
|
|
105
105
|
export declare const clear: (array: Array<unknown>) => void;
|
|
106
|
-
export declare const bisect: <T,
|
|
106
|
+
export declare const bisect: <T, RightType, LeftType>(array: Array<T>, bisector: (element: T, index: number) => Either<RightType, LeftType>) => [Array<LeftType>, Array<RightType>];
|
|
107
107
|
export declare const toArray: <T>(array: Arrayable<T>) => Array<T>;
|
|
108
108
|
export declare const flatten: <T>(array: Array<Array<T>>) => Array<T>;
|
|
109
109
|
//# sourceMappingURL=array.d.ts.map
|
package/dist/array.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAA8B,MAAM,iCAAiC,CAAA;AACpH,OAAO,EAAQ,QAAQ,EAAa,MAAM,iCAAiC,CAAA;AAC3E,OAAO,EAAE,MAAM,EAAS,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,UAAU,EAA2C,MAAM,kCAAkC,CAAA;AACtG,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAGjE,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,KAAG,KAAK,CAAC,CAAC,CAOjE,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,cAAc,mBAAmB,KAAG,KAAK,CAAC,MAAM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AC,CAAC,CAAC,CAAC,CAW3H;AAED,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,iBAAgB,MAAU,KAAG,KAAK,CAAC,CAAC,CAE5E,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,KAAG,IAOpH,CAAA;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,KAAK,CAAC,OAAO,CAAC,KAAG,IAE7C,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAC3C,OAAO,KAAK,CAAC,CAAC,CAAC,EACf,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,KACnE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAEpC,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,SAAS,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,CAMvD,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,CAE1D,CAAA"}
|
package/dist/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/array.ts"],"sourcesContent":["import { equalBy as equalitorEqualBy, Equalitor, natural as naturalEquality } from '@bessemer/cornerstone/equalitor'\nimport { sign, Signable, Signature } from '@bessemer/cornerstone/signature'\nimport { Either, split } from '@bessemer/cornerstone/either'\nimport { Comparator, compareBy, natural as naturalComparison } from '@bessemer/cornerstone/comparator'\nimport { Arrayable } from 'type-fest'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { FiniteNumericBounds } from '@bessemer/cornerstone/range'\nimport { assert } from '@bessemer/cornerstone/assertion'\n\nexport const makeBy = <T>(n: number, f: (i: number) => T): Array<T> => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out\n}\n\nexport const range = ([start, end]: FiniteNumericBounds): Array<number> => {\n return start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n}\n\nexport const repeat = <T>(a: T, n: number): Array<T> => {\n return makeBy(n, () => a)\n}\n\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> => {\n return Array.isArray(collection) ? collection : Array.from(collection)\n}\n\nexport const take = <T>(array: Array<T>, elementsToSkip: number = 1): Array<T> => {\n return array.slice(elementsToSkip)\n}\n\n/**\n * Determines if two arrays are equal by comparing each element using an Equalitor.\n * Returns `true` if all corresponding elements are equal according to the provided\n * equalitor function in both arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Arrays } from \"@bessemer/cornerstone\"\n *\n * const users1 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n * const users2 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n *\n * const result = Arrays.equalWith(users1, users2, (a, b) => a.id === b.id && a.name === b.name)\n * console.log(result) // true\n *\n * const numbers1 = [1.1, 2.2, 3.3]\n * const numbers2 = [1.0, 2.0, 3.0]\n *\n * const closeEnough = Arrays.equalWith(numbers1, numbers2, (a, b) => Math.abs(a - b) < 0.5)\n * console.log(closeEnough) // false\n * ```\n *\n * @category comparison\n */\nexport const equalWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): boolean => {\n if (first.length !== second.length) {\n return false\n }\n\n return first.every((element, index) => equalitor(element, second[index]!))\n}\n\n/**\n * Determines if two arrays are equal by comparing mapped values from each element.\n * Returns `true` if all corresponding mapped values are equal according to the\n * provided Equalitor or natural equality.\n *\n * **Example**\n *\n * ```ts\n * import { Arrays } from \"@bessemer/cornerstone\"\n *\n * const users1 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n * const users2 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n *\n * // Compare by mapped property using natural equality\n * const result = Arrays.equalBy(users1, users2, user => user.id)\n * console.log(result) // true\n *\n * // Compare by mapped property using custom Equalitor\n * const products1 = [{ name: \"Apple\", price: 1.99 }, { name: \"Orange\", price: 2.49 }]\n * const products2 = [{ name: \"Apple\", price: 2.00 }, { name: \"Orange\", price: 2.50 }]\n *\n * const closeEnough = Arrays.equalBy(\n * products1,\n * products2,\n * product => product.price,\n * (a, b) => Math.abs(a - b) < 0.1\n * )\n * console.log(closeEnough) // true\n * ```\n *\n * @category comparison\n */\nexport function equalBy<T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): boolean\nexport function equalBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): boolean\nexport function equalBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): boolean {\n if (isNil(equalitor)) {\n return equalWith(\n first,\n second,\n equalitorEqualBy((it) => sign(mapper(it) as Signable), naturalEquality())\n )\n } else {\n return equalWith(first, second, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const equal = <T extends Signable>(first: Array<T>, second: Array<T>): boolean => {\n return equalBy(first, second, sign)\n}\n\nexport const differenceWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): Array<T> => {\n return first.filter((firstItem) => !second.some((it) => equalitor(firstItem, it)))\n}\n\nexport function differenceBy<T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): Array<T>\nexport function differenceBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): Array<T>\nexport function differenceBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): Array<T> {\n if (isNil(equalitor)) {\n return differenceWith(\n first,\n second,\n equalitorEqualBy((it) => sign(mapper(it) as Signable), naturalEquality())\n )\n } else {\n return differenceWith(first, second, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const difference = <T extends Signable>(first: Array<T>, second: Array<T>): Array<T> => {\n return differenceBy(first, second, sign)\n}\n\nexport const removeWith = <T>(array: Array<T>, element: T, equalitor: Equalitor<T>): Array<T> => {\n return differenceWith(array, [element], equalitor)\n}\n\nexport function removeBy<T>(array: Array<T>, element: T, mapper: (element: T) => Signable): Array<T>\nexport function removeBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor: Equalitor<N>): Array<T>\nexport function removeBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor?: Equalitor<N>): Array<T> {\n return differenceBy(array, [element], mapper, equalitor as any)\n}\n\nexport const remove = <T extends Signable>(array: Array<T>, element: T): Array<T> => {\n return difference(array, [element])\n}\n\nexport const containsWith = <T>(array: Array<T>, element: T, equalitor: Equalitor<T>): boolean => {\n return array.some((it) => equalitor(it, element))\n}\n\nexport function containsBy<T>(array: Array<T>, element: T, mapper: (element: T) => Signable): boolean\nexport function containsBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor: Equalitor<N>): boolean\nexport function containsBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor?: Equalitor<N>): boolean {\n if (isNil(equalitor)) {\n return containsWith(\n array,\n element,\n equalitorEqualBy((it) => sign(mapper(it) as Signable), naturalEquality())\n )\n } else {\n return containsWith(array, element, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const contains = <T extends Signable>(array: Array<T>, element: T): boolean => containsBy(array, element, sign)\n\nexport const containsAllWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): boolean =>\n isEmpty(differenceWith(second, first, equalitor))\n\nexport function containsAllBy<T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): boolean\nexport function containsAllBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): boolean\nexport function containsAllBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): boolean {\n return isEmpty(differenceBy(second, first, mapper, equalitor as any))\n}\n\nexport const containsAll = <T extends Signable>(first: Array<T>, second: Array<T>): boolean => isEmpty(difference(second, first))\n\nexport const dedupeWith = <T>(array: Array<T>, equalitor: Equalitor<T>): Array<T> => {\n const result: Array<T> = []\n\n for (const element of array) {\n const isDuplicate = result.some((existing) => equalitor(existing, element))\n if (!isDuplicate) {\n result.push(element)\n }\n }\n\n return result\n}\n\nexport function dedupeBy<T>(array: Array<T>, mapper: (element: T) => Signable): Array<T>\nexport function dedupeBy<T, N>(array: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): Array<T>\nexport function dedupeBy<T, N>(array: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): Array<T> {\n if (isNil(equalitor)) {\n return dedupeWith(array, equalitorEqualBy(mapper as any, naturalEquality()))\n } else {\n return dedupeWith(array, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const dedupe = <T extends Signable>(array: Array<T>): Array<T> => {\n return dedupeBy(array, sign)\n}\n\nexport const sortWith = <T>(array: Array<T>, comparator: Comparator<T>): Array<T> => {\n return [...array].sort(comparator)\n}\n\nexport function sortBy<T>(array: Array<T>, mapper: (element: T) => Signable): Array<T>\nexport function sortBy<T, N>(array: Array<T>, mapper: (element: T) => N, comparator: Comparator<N>): Array<T>\nexport function sortBy<T, N>(array: Array<T>, mapper: (element: T) => N, comparator?: Comparator<N>): Array<T> {\n if (isNil(comparator)) {\n return sortWith(\n array,\n compareBy((it) => sign(mapper(it as any) as Signature), naturalComparison())\n )\n } else {\n return sortWith(array, compareBy(mapper, comparator))\n }\n}\n\nexport const sort = <T extends Signable>(array: Array<T>): Array<T> => sortBy(array, sign)\n\nexport const concatenate = <T>(array: Array<T>, ...values: Array<T | Array<T>>): Array<T> => {\n const result = [...array]\n\n for (const value of values) {\n if (Array.isArray(value)) {\n result.push(...value)\n } else {\n result.push(value)\n }\n }\n\n return result\n}\n\nexport const first = <T>(array: Array<T>): T | undefined => {\n return array.length > 0 ? array[0] : undefined\n}\n\nexport const only = <T>(array: Array<T>): T => {\n assert(array.length === 1)\n return first(array)!\n}\n\nexport const last = <T>(array: Array<T>): T | undefined => {\n return array.length > 0 ? array[array.length - 1] : undefined\n}\n\nexport const isEmpty = <T>(array: Array<T>): boolean => {\n return array.length === 0\n}\n\n// JOHN i don't think this function should exist here... maybe examine the use cases more thoroughly\nexport function groupBy<T, N extends string | number | symbol>(array: Array<T>, iteratee: (it: T) => N): Record<N, Array<T>> {\n return array.reduce<Record<N, Array<T>>>((result, value) => {\n const key = iteratee(value)\n\n if (!result[key]) {\n result[key] = []\n }\n\n result[key].push(value)\n return result\n }, {} as any)\n}\n\nexport const rest = <T>(array: Array<T>, elementsToSkip: number = 1): Array<T> => {\n return array.slice(elementsToSkip)\n}\n\nexport const filterInPlace = <T>(array: Array<T>, predicate: (value: T, index: number, array: Array<T>) => boolean): void => {\n for (let i = array.length - 1; i >= 0; i--) {\n const value = array[i]\n if (value !== undefined && !predicate(value, i, array)) {\n array.splice(i, 1)\n }\n }\n}\n\nexport const clear = (array: Array<unknown>): void => {\n filterInPlace(array, () => false)\n}\n\nexport const bisect = <T, L, R>(array: Array<T>, bisector: (element: T, index: number) => Either<L, R>): [Array<L>, Array<R>] => {\n return split(array.map(bisector))\n}\n\nexport const toArray = <T>(array: Arrayable<T>): Array<T> => {\n if (Array.isArray(array)) {\n return array\n }\n\n return [array]\n}\n\nexport const flatten = <T>(array: Array<Array<T>>): Array<T> => {\n return array.flatMap((it) => it)\n}\n"],"mappings":";AAAA,SAAS,WAAW,kBAA6B,WAAW,uBAAuB;AACnF,SAAS,YAAiC;AAC1C,SAAiB,aAAa;AAC9B,SAAqB,WAAW,WAAW,yBAAyB;AAEpE,SAAS,aAAa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CAAC;AAAA,IACnB;AAAA,EACF;AACF;AAEO,IAAM,QAAQ,CAAC,UAAgC;AACpD,gBAAc,OAAO,MAAM,KAAK;AAClC;AAEO,IAAM,SAAS,CAAU,OAAiB,aAAgF;AAC/H,SAAO,MAAM,MAAM,IAAI,QAAQ,CAAC;AAClC;AAEO,IAAM,UAAU,CAAI,UAAkC;AAC3D,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,KAAK;AACf;AAEO,IAAM,UAAU,CAAI,UAAqC;AAC9D,SAAO,MAAM,QAAQ,CAAC,OAAO,EAAE;AACjC;","names":["first"]}
|
|
1
|
+
{"version":3,"sources":["../src/array.ts"],"sourcesContent":["import { equalBy as equalitorEqualBy, Equalitor, natural as naturalEquality } from '@bessemer/cornerstone/equalitor'\nimport { sign, Signable, Signature } from '@bessemer/cornerstone/signature'\nimport { Either, split } from '@bessemer/cornerstone/either'\nimport { Comparator, compareBy, natural as naturalComparison } from '@bessemer/cornerstone/comparator'\nimport { Arrayable } from 'type-fest'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { FiniteNumericBounds } from '@bessemer/cornerstone/range'\nimport { assert } from '@bessemer/cornerstone/assertion'\n\nexport const makeBy = <T>(n: number, f: (i: number) => T): Array<T> => {\n const max = Math.max(1, Math.floor(n))\n const out = new Array(max)\n for (let i = 0; i < max; i++) {\n out[i] = f(i)\n }\n return out\n}\n\nexport const range = ([start, end]: FiniteNumericBounds): Array<number> => {\n return start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]\n}\n\nexport const repeat = <T>(a: T, n: number): Array<T> => {\n return makeBy(n, () => a)\n}\n\nexport const fromIterable = <A>(collection: Iterable<A>): Array<A> => {\n return Array.isArray(collection) ? collection : Array.from(collection)\n}\n\nexport const take = <T>(array: Array<T>, elementsToSkip: number = 1): Array<T> => {\n return array.slice(elementsToSkip)\n}\n\n/**\n * Determines if two arrays are equal by comparing each element using an Equalitor.\n * Returns `true` if all corresponding elements are equal according to the provided\n * equalitor function in both arrays.\n *\n * **Example**\n *\n * ```ts\n * import { Arrays } from \"@bessemer/cornerstone\"\n *\n * const users1 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n * const users2 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n *\n * const result = Arrays.equalWith(users1, users2, (a, b) => a.id === b.id && a.name === b.name)\n * console.log(result) // true\n *\n * const numbers1 = [1.1, 2.2, 3.3]\n * const numbers2 = [1.0, 2.0, 3.0]\n *\n * const closeEnough = Arrays.equalWith(numbers1, numbers2, (a, b) => Math.abs(a - b) < 0.5)\n * console.log(closeEnough) // false\n * ```\n *\n * @category comparison\n */\nexport const equalWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): boolean => {\n if (first.length !== second.length) {\n return false\n }\n\n return first.every((element, index) => equalitor(element, second[index]!))\n}\n\n/**\n * Determines if two arrays are equal by comparing mapped values from each element.\n * Returns `true` if all corresponding mapped values are equal according to the\n * provided Equalitor or natural equality.\n *\n * **Example**\n *\n * ```ts\n * import { Arrays } from \"@bessemer/cornerstone\"\n *\n * const users1 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n * const users2 = [{ id: 1, name: \"Alice\" }, { id: 2, name: \"Bob\" }]\n *\n * // Compare by mapped property using natural equality\n * const result = Arrays.equalBy(users1, users2, user => user.id)\n * console.log(result) // true\n *\n * // Compare by mapped property using custom Equalitor\n * const products1 = [{ name: \"Apple\", price: 1.99 }, { name: \"Orange\", price: 2.49 }]\n * const products2 = [{ name: \"Apple\", price: 2.00 }, { name: \"Orange\", price: 2.50 }]\n *\n * const closeEnough = Arrays.equalBy(\n * products1,\n * products2,\n * product => product.price,\n * (a, b) => Math.abs(a - b) < 0.1\n * )\n * console.log(closeEnough) // true\n * ```\n *\n * @category comparison\n */\nexport function equalBy<T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): boolean\nexport function equalBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): boolean\nexport function equalBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): boolean {\n if (isNil(equalitor)) {\n return equalWith(\n first,\n second,\n equalitorEqualBy((it) => sign(mapper(it) as Signable), naturalEquality())\n )\n } else {\n return equalWith(first, second, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const equal = <T extends Signable>(first: Array<T>, second: Array<T>): boolean => {\n return equalBy(first, second, sign)\n}\n\nexport const differenceWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): Array<T> => {\n return first.filter((firstItem) => !second.some((it) => equalitor(firstItem, it)))\n}\n\nexport function differenceBy<T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): Array<T>\nexport function differenceBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): Array<T>\nexport function differenceBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): Array<T> {\n if (isNil(equalitor)) {\n return differenceWith(\n first,\n second,\n equalitorEqualBy((it) => sign(mapper(it) as Signable), naturalEquality())\n )\n } else {\n return differenceWith(first, second, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const difference = <T extends Signable>(first: Array<T>, second: Array<T>): Array<T> => {\n return differenceBy(first, second, sign)\n}\n\nexport const removeWith = <T>(array: Array<T>, element: T, equalitor: Equalitor<T>): Array<T> => {\n return differenceWith(array, [element], equalitor)\n}\n\nexport function removeBy<T>(array: Array<T>, element: T, mapper: (element: T) => Signable): Array<T>\nexport function removeBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor: Equalitor<N>): Array<T>\nexport function removeBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor?: Equalitor<N>): Array<T> {\n return differenceBy(array, [element], mapper, equalitor as any)\n}\n\nexport const remove = <T extends Signable>(array: Array<T>, element: T): Array<T> => {\n return difference(array, [element])\n}\n\nexport const containsWith = <T>(array: Array<T>, element: T, equalitor: Equalitor<T>): boolean => {\n return array.some((it) => equalitor(it, element))\n}\n\nexport function containsBy<T>(array: Array<T>, element: T, mapper: (element: T) => Signable): boolean\nexport function containsBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor: Equalitor<N>): boolean\nexport function containsBy<T, N>(array: Array<T>, element: T, mapper: (element: T) => N, equalitor?: Equalitor<N>): boolean {\n if (isNil(equalitor)) {\n return containsWith(\n array,\n element,\n equalitorEqualBy((it) => sign(mapper(it) as Signable), naturalEquality())\n )\n } else {\n return containsWith(array, element, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const contains = <T extends Signable>(array: Array<T>, element: T): boolean => containsBy(array, element, sign)\n\nexport const containsAllWith = <T>(first: Array<T>, second: Array<T>, equalitor: Equalitor<T>): boolean =>\n isEmpty(differenceWith(second, first, equalitor))\n\nexport function containsAllBy<T>(first: Array<T>, second: Array<T>, mapper: (element: T) => Signable): boolean\nexport function containsAllBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): boolean\nexport function containsAllBy<T, N>(first: Array<T>, second: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): boolean {\n return isEmpty(differenceBy(second, first, mapper, equalitor as any))\n}\n\nexport const containsAll = <T extends Signable>(first: Array<T>, second: Array<T>): boolean => isEmpty(difference(second, first))\n\nexport const dedupeWith = <T>(array: Array<T>, equalitor: Equalitor<T>): Array<T> => {\n const result: Array<T> = []\n\n for (const element of array) {\n const isDuplicate = result.some((existing) => equalitor(existing, element))\n if (!isDuplicate) {\n result.push(element)\n }\n }\n\n return result\n}\n\nexport function dedupeBy<T>(array: Array<T>, mapper: (element: T) => Signable): Array<T>\nexport function dedupeBy<T, N>(array: Array<T>, mapper: (element: T) => N, equalitor: Equalitor<N>): Array<T>\nexport function dedupeBy<T, N>(array: Array<T>, mapper: (element: T) => N, equalitor?: Equalitor<N>): Array<T> {\n if (isNil(equalitor)) {\n return dedupeWith(array, equalitorEqualBy(mapper as any, naturalEquality()))\n } else {\n return dedupeWith(array, equalitorEqualBy(mapper, equalitor))\n }\n}\n\nexport const dedupe = <T extends Signable>(array: Array<T>): Array<T> => {\n return dedupeBy(array, sign)\n}\n\nexport const sortWith = <T>(array: Array<T>, comparator: Comparator<T>): Array<T> => {\n return [...array].sort(comparator)\n}\n\nexport function sortBy<T>(array: Array<T>, mapper: (element: T) => Signable): Array<T>\nexport function sortBy<T, N>(array: Array<T>, mapper: (element: T) => N, comparator: Comparator<N>): Array<T>\nexport function sortBy<T, N>(array: Array<T>, mapper: (element: T) => N, comparator?: Comparator<N>): Array<T> {\n if (isNil(comparator)) {\n return sortWith(\n array,\n compareBy((it) => sign(mapper(it as any) as Signature), naturalComparison())\n )\n } else {\n return sortWith(array, compareBy(mapper, comparator))\n }\n}\n\nexport const sort = <T extends Signable>(array: Array<T>): Array<T> => sortBy(array, sign)\n\nexport const concatenate = <T>(array: Array<T>, ...values: Array<T | Array<T>>): Array<T> => {\n const result = [...array]\n\n for (const value of values) {\n if (Array.isArray(value)) {\n result.push(...value)\n } else {\n result.push(value)\n }\n }\n\n return result\n}\n\nexport const first = <T>(array: Array<T>): T | undefined => {\n return array.length > 0 ? array[0] : undefined\n}\n\nexport const only = <T>(array: Array<T>): T => {\n assert(array.length === 1)\n return first(array)!\n}\n\nexport const last = <T>(array: Array<T>): T | undefined => {\n return array.length > 0 ? array[array.length - 1] : undefined\n}\n\nexport const isEmpty = <T>(array: Array<T>): boolean => {\n return array.length === 0\n}\n\n// JOHN i don't think this function should exist here... maybe examine the use cases more thoroughly\nexport function groupBy<T, N extends string | number | symbol>(array: Array<T>, iteratee: (it: T) => N): Record<N, Array<T>> {\n return array.reduce<Record<N, Array<T>>>((result, value) => {\n const key = iteratee(value)\n\n if (!result[key]) {\n result[key] = []\n }\n\n result[key].push(value)\n return result\n }, {} as any)\n}\n\nexport const rest = <T>(array: Array<T>, elementsToSkip: number = 1): Array<T> => {\n return array.slice(elementsToSkip)\n}\n\nexport const filterInPlace = <T>(array: Array<T>, predicate: (value: T, index: number, array: Array<T>) => boolean): void => {\n for (let i = array.length - 1; i >= 0; i--) {\n const value = array[i]\n if (value !== undefined && !predicate(value, i, array)) {\n array.splice(i, 1)\n }\n }\n}\n\nexport const clear = (array: Array<unknown>): void => {\n filterInPlace(array, () => false)\n}\n\nexport const bisect = <T, RightType, LeftType>(\n array: Array<T>,\n bisector: (element: T, index: number) => Either<RightType, LeftType>\n): [Array<LeftType>, Array<RightType>] => {\n return split(array.map(bisector))\n}\n\nexport const toArray = <T>(array: Arrayable<T>): Array<T> => {\n if (Array.isArray(array)) {\n return array\n }\n\n return [array]\n}\n\nexport const flatten = <T>(array: Array<Array<T>>): Array<T> => {\n return array.flatMap((it) => it)\n}\n"],"mappings":";AAAA,SAAS,WAAW,kBAA6B,WAAW,uBAAuB;AACnF,SAAS,YAAiC;AAC1C,SAAiB,aAAa;AAC9B,SAAqB,WAAW,WAAW,yBAAyB;AAEpE,SAAS,aAAa;AAEtB,SAAS,cAAc;AAEhB,IAAM,SAAS,CAAI,GAAW,MAAkC;AACrE,QAAM,MAAM,KAAK,IAAI,GAAG,KAAK,MAAM,CAAC,CAAC;AACrC,QAAM,MAAM,IAAI,MAAM,GAAG;AACzB,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,QAAI,CAAC,IAAI,EAAE,CAAC;AAAA,EACd;AACA,SAAO;AACT;AAEO,IAAM,QAAQ,CAAC,CAAC,OAAO,GAAG,MAA0C;AACzE,SAAO,SAAS,MAAM,OAAO,MAAM,QAAQ,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,KAAK;AAC1E;AAEO,IAAM,SAAS,CAAI,GAAM,MAAwB;AACtD,SAAO,OAAO,GAAG,MAAM,CAAC;AAC1B;AAEO,IAAM,eAAe,CAAI,eAAsC;AACpE,SAAO,MAAM,QAAQ,UAAU,IAAI,aAAa,M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M,MAAM,SAAS,CAAC,IAAI;AACtD;AAEO,IAAM,UAAU,CAAI,UAA6B;AACtD,SAAO,MAAM,WAAW;AAC1B;AAGO,SAAS,QAA+C,OAAiB,UAA6C;AAC3H,SAAO,MAAM,OAA4B,CAAC,QAAQ,UAAU;AAC1D,UAAM,MAAM,SAAS,KAAK;AAE1B,QAAI,CAAC,OAAO,GAAG,GAAG;AAChB,aAAO,GAAG,IAAI,CAAC;AAAA,IACjB;AAEA,WAAO,GAAG,EAAE,KAAK,KAAK;AACtB,WAAO;AAAA,EACT,GAAG,CAAC,CAAQ;AACd;AAEO,IAAM,OAAO,CAAI,OAAiB,iBAAyB,MAAgB;AAChF,SAAO,MAAM,MAAM,cAAc;AACnC;AAEO,IAAM,gBAAgB,CAAI,OAAiB,cAA2E;AAC3H,WAAS,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC1C,UAAM,QAAQ,MAAM,CAAC;AACrB,QAAI,UAAU,UAAa,CAAC,UAAU,OAAO,GAAG,KAAK,GAAG;AACtD,YAAM,OAAO,GAAG,CAAC;AAAA,IACnB;AAAA,EACF;AACF;AAEO,IAAM,QAAQ,CAAC,UAAgC;AACpD,gBAAc,OAAO,MAAM,KAAK;AAClC;AAEO,IAAM,SAAS,CACpB,OACA,aACwC;AACxC,SAAO,MAAM,MAAM,IAAI,QAAQ,CAAC;AAClC;AAEO,IAAM,UAAU,CAAI,UAAkC;AAC3D,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,KAAK;AACf;AAEO,IAAM,UAAU,CAAI,UAAqC;AAC9D,SAAO,MAAM,QAAQ,CAAC,OAAO,EAAE;AACjC;","names":["first"]}
|
package/dist/either.d.ts
CHANGED
|
@@ -2,18 +2,49 @@ export declare enum EitherType {
|
|
|
2
2
|
Left = "Left",
|
|
3
3
|
Right = "Right"
|
|
4
4
|
}
|
|
5
|
-
export type
|
|
6
|
-
type: EitherType.Left;
|
|
7
|
-
value: T;
|
|
8
|
-
};
|
|
9
|
-
export type Right<N> = {
|
|
5
|
+
export type Right<RightType> = {
|
|
10
6
|
type: EitherType.Right;
|
|
11
|
-
value:
|
|
7
|
+
value: RightType;
|
|
8
|
+
isRight: true;
|
|
9
|
+
isLeft: false;
|
|
10
|
+
map: <T>(mapper: (element: RightType) => T) => Right<T>;
|
|
11
|
+
mapLeft: () => Right<RightType>;
|
|
12
|
+
[Symbol.iterator](): Generator<Either<RightType, never>, RightType>;
|
|
13
|
+
};
|
|
14
|
+
export type Left<LeftType> = {
|
|
15
|
+
type: EitherType.Left;
|
|
16
|
+
value: LeftType;
|
|
17
|
+
isRight: false;
|
|
18
|
+
isLeft: true;
|
|
19
|
+
map: () => Left<LeftType>;
|
|
20
|
+
mapLeft: <T>(mapper: (element: LeftType) => T) => Left<T>;
|
|
21
|
+
[Symbol.iterator](): Generator<Either<never, LeftType>, never>;
|
|
12
22
|
};
|
|
13
|
-
export type Either<
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
export type Either<RightType, LeftType> = Left<LeftType> | Right<RightType>;
|
|
24
|
+
export declare class RightImpl<RightType> implements Right<RightType> {
|
|
25
|
+
readonly value: RightType;
|
|
26
|
+
readonly type: EitherType.Right;
|
|
27
|
+
readonly isRight = true;
|
|
28
|
+
readonly isLeft = false;
|
|
29
|
+
constructor(value: RightType);
|
|
30
|
+
map: <T>(mapper: (element: RightType) => T) => Right<T>;
|
|
31
|
+
mapLeft: () => Right<RightType>;
|
|
32
|
+
[Symbol.iterator](): Generator<Either<RightType, never>, RightType>;
|
|
33
|
+
}
|
|
34
|
+
export declare class LeftImpl<LeftType> implements Left<LeftType> {
|
|
35
|
+
readonly value: LeftType;
|
|
36
|
+
readonly type = EitherType.Left;
|
|
37
|
+
readonly isRight = false;
|
|
38
|
+
readonly isLeft = true;
|
|
39
|
+
constructor(value: LeftType);
|
|
40
|
+
map: () => Left<LeftType>;
|
|
41
|
+
mapLeft: <T>(mapper: (element: LeftType) => T) => Left<T>;
|
|
42
|
+
[Symbol.iterator](): Generator<Either<never, LeftType>, never>;
|
|
43
|
+
}
|
|
44
|
+
export declare const left: <LeftType>(value: LeftType) => Left<LeftType>;
|
|
45
|
+
export declare const right: <RightType>(value: RightType) => Right<RightType>;
|
|
46
|
+
export declare const split: <RightType, LeftType>(array: Array<Either<RightType, LeftType>>) => [Array<LeftType>, Array<RightType>];
|
|
47
|
+
export declare const buildGenerator: <EitherType extends Either<any, any>, TGen extends () => Generator<EitherType> | AsyncGenerator<EitherType>>(lift: (val: any) => EitherType) => ((generatorFn: TGen) => TGen extends () => Generator<EitherType, infer R> ? EitherType : TGen extends () => AsyncGenerator<EitherType, infer R> ? Promise<EitherType> : never);
|
|
48
|
+
export declare function gen<TGen extends () => Generator<Either<any, any>>>(generatorFn: TGen): TGen extends () => Generator<Either<any, infer L>, infer R> ? Either<R, L> : never;
|
|
49
|
+
export declare function gen<TGen extends () => AsyncGenerator<Either<any, any>>>(generatorFn: TGen): Promise<TGen extends () => AsyncGenerator<Either<any, infer L>, infer R> ? Either<R, L> : never>;
|
|
19
50
|
//# sourceMappingURL=either.d.ts.map
|
package/dist/either.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../src/either.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../src/either.ts"],"names":[],"mappings":"AAEA,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,KAAK,CAAC,SAAS,IAAI;IAC7B,IAAI,EAAE,UAAU,CAAC,KAAK,CAAA;IACtB,KAAK,EAAE,SAAS,CAAA;IAChB,OAAO,EAAE,IAAI,CAAA;IACb,MAAM,EAAE,KAAK,CAAA;IACb,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO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S,MAAM,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,GAClD,UAAU,GACV,IAAI,SAAS,MAAM,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,GACtD,OAAO,CAAC,UAAU,CAAC,GACnB,KAAK,CA8BR,CAAA;AAID,wBAAgB,GAAG,CAAC,IAAI,SAAS,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAChE,WAAW,EAAE,IAAI,GAChB,IAAI,SAAS,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAA;AACrF,wBAAgB,GAAG,CAAC,IAAI,SAAS,MAAM,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EACrE,WAAW,EAAE,IAAI,GAChB,OAAO,CAAC,IAAI,SAAS,MAAM,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAA"}
|
package/dist/either.js
CHANGED
|
@@ -1,22 +1,95 @@
|
|
|
1
1
|
// src/either.ts
|
|
2
|
+
import { isPromise } from "@bessemer/cornerstone/promise";
|
|
2
3
|
var EitherType = /* @__PURE__ */ ((EitherType2) => {
|
|
3
4
|
EitherType2["Left"] = "Left";
|
|
4
5
|
EitherType2["Right"] = "Right";
|
|
5
6
|
return EitherType2;
|
|
6
7
|
})(EitherType || {});
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
var RightImpl = class {
|
|
9
|
+
constructor(value) {
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
type = "Right" /* Right */;
|
|
13
|
+
isRight = true;
|
|
14
|
+
isLeft = false;
|
|
15
|
+
map = (mapper) => {
|
|
16
|
+
return right(mapper(this.value));
|
|
17
|
+
};
|
|
18
|
+
mapLeft = () => {
|
|
19
|
+
return this;
|
|
20
|
+
};
|
|
21
|
+
[Symbol.iterator]() {
|
|
22
|
+
return function* () {
|
|
23
|
+
return this.value;
|
|
24
|
+
}.call(this);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var LeftImpl = class {
|
|
28
|
+
constructor(value) {
|
|
29
|
+
this.value = value;
|
|
30
|
+
}
|
|
31
|
+
type = "Left" /* Left */;
|
|
32
|
+
isRight = false;
|
|
33
|
+
isLeft = true;
|
|
34
|
+
map = () => {
|
|
35
|
+
return this;
|
|
36
|
+
};
|
|
37
|
+
mapLeft = (mapper) => {
|
|
38
|
+
return left(mapper(this.value));
|
|
39
|
+
};
|
|
40
|
+
[Symbol.iterator]() {
|
|
41
|
+
return function* () {
|
|
42
|
+
yield this;
|
|
43
|
+
throw new Error("Illegal State");
|
|
44
|
+
}.call(this);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var left = (value) => new LeftImpl(value);
|
|
48
|
+
var right = (value) => new RightImpl(value);
|
|
11
49
|
var split = (array) => {
|
|
12
|
-
const lefts = array.filter(isLeft).map((it) => it.value);
|
|
13
|
-
const rights = array.filter(isRight).map((it) => it.value);
|
|
50
|
+
const lefts = array.filter((it) => it.isLeft).map((it) => it.value);
|
|
51
|
+
const rights = array.filter((it) => it.isRight).map((it) => it.value);
|
|
14
52
|
return [lefts, rights];
|
|
15
53
|
};
|
|
54
|
+
var buildGenerator = (lift) => {
|
|
55
|
+
return (generatorFn) => {
|
|
56
|
+
const generator2 = generatorFn();
|
|
57
|
+
const firstNext = generator2.next();
|
|
58
|
+
if (isPromise(firstNext)) {
|
|
59
|
+
return (async () => {
|
|
60
|
+
let current = await firstNext;
|
|
61
|
+
while (!current.done) {
|
|
62
|
+
const result = current.value;
|
|
63
|
+
if (result.isLeft) {
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
current = await generator2.next(result.value);
|
|
67
|
+
}
|
|
68
|
+
return lift(current.value);
|
|
69
|
+
})();
|
|
70
|
+
} else {
|
|
71
|
+
let current = firstNext;
|
|
72
|
+
while (!current.done) {
|
|
73
|
+
const result = current.value;
|
|
74
|
+
if (result.isLeft) {
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
current = generator2.next(result.value);
|
|
78
|
+
}
|
|
79
|
+
return lift(current.value);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
var generator = buildGenerator((it) => right(it));
|
|
84
|
+
function gen(generatorFn) {
|
|
85
|
+
return generator(generatorFn);
|
|
86
|
+
}
|
|
16
87
|
export {
|
|
17
88
|
EitherType,
|
|
18
|
-
|
|
19
|
-
|
|
89
|
+
LeftImpl,
|
|
90
|
+
RightImpl,
|
|
91
|
+
buildGenerator,
|
|
92
|
+
gen,
|
|
20
93
|
left,
|
|
21
94
|
right,
|
|
22
95
|
split
|
package/dist/either.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/either.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/either.ts"],"sourcesContent":["import { isPromise } from '@bessemer/cornerstone/promise'\n\nexport enum EitherType {\n Left = 'Left',\n Right = 'Right',\n}\n\nexport type Right<RightType> = {\n type: EitherType.Right\n value: RightType\n isRight: true\n isLeft: false\n map: <T>(mapper: (element: RightType) => T) => Right<T>\n mapLeft: () => Right<RightType>\n [Symbol.iterator](): Generator<Either<RightType, never>, RightType>\n}\n\nexport type Left<LeftType> = {\n type: EitherType.Left\n value: LeftType\n isRight: false\n isLeft: true\n map: () => Left<LeftType>\n mapLeft: <T>(mapper: (element: LeftType) => T) => Left<T>\n [Symbol.iterator](): Generator<Either<never, LeftType>, never>\n}\n\nexport type Either<RightType, LeftType> = Left<LeftType> | Right<RightType>\n\nexport class RightImpl<RightType> implements Right<RightType> {\n public readonly type: EitherType.Right = EitherType.Right\n public readonly isRight = true\n public readonly isLeft = false\n\n constructor(public readonly value: RightType) {}\n\n map = <T>(mapper: (element: RightType) => T): Right<T> => {\n return right(mapper(this.value))\n }\n\n mapLeft = (): Right<RightType> => {\n return this\n };\n\n [Symbol.iterator](): Generator<Either<RightType, never>, RightType> {\n return function* (this: Right<RightType>) {\n return this.value\n }.call(this)\n }\n}\n\nexport class LeftImpl<LeftType> implements Left<LeftType> {\n public readonly type = EitherType.Left\n public readonly isRight = false\n public readonly isLeft = true\n\n constructor(public readonly value: LeftType) {}\n\n map = (): Left<LeftType> => {\n return this\n }\n\n mapLeft = <T>(mapper: (element: LeftType) => T): Left<T> => {\n return left(mapper(this.value))\n };\n\n [Symbol.iterator](): Generator<Either<never, LeftType>, never> {\n return function* (this: Left<LeftType>) {\n yield this as any\n throw new Error('Illegal State')\n }.call(this)\n }\n}\n\nexport const left = <LeftType>(value: LeftType): Left<LeftType> => new LeftImpl(value)\nexport const right = <RightType>(value: RightType): Right<RightType> => new RightImpl(value)\n\nexport const split = <RightType, LeftType>(array: Array<Either<RightType, LeftType>>): [Array<LeftType>, Array<RightType>] => {\n const lefts = array.filter((it) => it.isLeft).map((it) => it.value)\n const rights = array.filter((it) => it.isRight).map((it) => it.value)\n return [lefts, rights]\n}\n\nexport const buildGenerator = <EitherType extends Either<any, any>, TGen extends () => Generator<EitherType> | AsyncGenerator<EitherType>>(\n lift: (val: any) => EitherType\n): ((\n generatorFn: TGen\n) => TGen extends () => Generator<EitherType, infer R>\n ? EitherType\n : TGen extends () => AsyncGenerator<EitherType, infer R>\n ? Promise<EitherType>\n : never) => {\n return (generatorFn) => {\n const generator = generatorFn()\n const firstNext = generator.next()\n if (isPromise(firstNext)) {\n return (async () => {\n let current = await firstNext\n while (!current.done) {\n const result = current.value\n if (result.isLeft) {\n return result\n }\n current = await generator.next(result.value)\n }\n return lift(current.value)\n })() as any\n } else {\n let current = firstNext\n while (!current.done) {\n const result = current.value\n if (result.isLeft) {\n return result\n }\n\n current = generator.next(result.value) as IteratorResult<EitherType>\n }\n\n return lift(current.value)\n }\n }\n}\n\nconst generator = buildGenerator((it) => right(it) as Either<any, any>)\n\nexport function gen<TGen extends () => Generator<Either<any, any>>>(\n generatorFn: TGen\n): TGen extends () => Generator<Either<any, infer L>, infer R> ? Either<R, L> : never\nexport function gen<TGen extends () => AsyncGenerator<Either<any, any>>>(\n generatorFn: TGen\n): Promise<TGen extends () => AsyncGenerator<Either<any, infer L>, infer R> ? Either<R, L> : never>\nexport function gen<TGen extends () => Generator<Either<any, any>> | AsyncGenerator<Either<any, any>>>(\n generatorFn: TGen\n): TGen extends () => Generator<Either<any, infer L>, infer R>\n ? Either<R, L>\n : TGen extends () => AsyncGenerator<Either<any, infer L>, infer R>\n ? Promise<Either<R, L>>\n : never {\n return generator(generatorFn)\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,UAAO;AACP,EAAAA,YAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AA2BL,IAAM,YAAN,MAAuD;AAAA,EAK5D,YAA4B,OAAkB;AAAlB;AAAA,EAAmB;AAAA,EAJ/B,OAAyB;AAAA,EACzB,UAAU;AAAA,EACV,SAAS;AAAA,EAIzB,MAAM,CAAI,WAAgD;AACxD,WAAO,MAAM,OAAO,KAAK,KAAK,CAAC;AAAA,EACjC;AAAA,EAEA,UAAU,MAAwB;AAChC,WAAO;AAAA,EACT;AAAA,EAEA,CAAC,OAAO,QAAQ,IAAoD;AAClE,WAAO,aAAmC;AACxC,aAAO,KAAK;AAAA,IACd,EAAE,KAAK,IAAI;AAAA,EACb;AACF;AAEO,IAAM,WAAN,MAAmD;AAAA,EAKxD,YAA4B,OAAiB;AAAjB;AAAA,EAAkB;AAAA,EAJ9B,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EAIzB,MAAM,MAAsB;AAC1B,WAAO;AAAA,EACT;AA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;AACF;AAEA,IAAM,YAAY,eAAe,CAAC,OAAO,MAAM,EAAE,CAAqB;AAQ/D,SAAS,IACd,aAKQ;AACR,SAAO,UAAU,WAAW;AAC9B;","names":["EitherType","generator"]}
|
package/dist/json.d.ts
CHANGED
package/dist/json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAY,MAAM,8BAA8B,CAAA;AAE/D,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,KAAG,MAAM,CAAC,GAAG,CAE9C,CAAA"}
|
package/dist/json.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
// src/json.ts
|
|
2
|
-
import {
|
|
2
|
+
import { tryValue } from "@bessemer/cornerstone/result";
|
|
3
3
|
var parse = (data) => {
|
|
4
4
|
return tryValue(() => JSON.parse(data));
|
|
5
5
|
};
|
|
6
|
-
var parseOrThrow = (data) => {
|
|
7
|
-
return getValueOrThrow(parse(data));
|
|
8
|
-
};
|
|
9
6
|
export {
|
|
10
|
-
parse
|
|
11
|
-
parseOrThrow
|
|
7
|
+
parse
|
|
12
8
|
};
|
|
13
9
|
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/json.ts"],"sourcesContent":["import { JsonValue } from 'type-fest'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/json.ts"],"sourcesContent":["import { JsonValue } from 'type-fest'\nimport { Result, tryValue } from '@bessemer/cornerstone/result'\n\nexport const parse = (data: string): Result<any> => {\n return tryValue(() => JSON.parse(data) as JsonValue)\n}\n"],"mappings":";AACA,SAAiB,gBAAgB;AAE1B,IAAM,QAAQ,CAAC,SAA8B;AAClD,SAA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MAAM,GAAI,cAAc,YAAY,WAEhD,CAAA"}
|
package/dist/net/uri.js
CHANGED
|
@@ -28,7 +28,7 @@ var parseString3 = (value) => {
|
|
|
28
28
|
return Results.failure(
|
|
29
29
|
ErrorEvents.invalidValue(value, {
|
|
30
30
|
namespace: Namespace,
|
|
31
|
-
message: `[${Namespace}]: Unable to parse Uri from
|
|
31
|
+
message: `[${Namespace}]: Unable to parse Uri from string: [${value}]`,
|
|
32
32
|
causes: schemeResult.value.causes
|
|
33
33
|
})
|
|
34
34
|
);
|
|
@@ -39,7 +39,7 @@ var parseString3 = (value) => {
|
|
|
39
39
|
return Results.failure(
|
|
40
40
|
ErrorEvents.invalidValue(value, {
|
|
41
41
|
namespace: Namespace,
|
|
42
|
-
message: `[${Namespace}]: Unable to parse Uri from
|
|
42
|
+
message: `[${Namespace}]: Unable to parse Uri from string: [${value}]`,
|
|
43
43
|
causes: authorityPartResult.value.causes
|
|
44
44
|
})
|
|
45
45
|
);
|
|
@@ -77,7 +77,7 @@ function toLiteral(likeValue) {
|
|
|
77
77
|
const value = from2(likeValue);
|
|
78
78
|
return format(value);
|
|
79
79
|
}
|
|
80
|
-
var SchemaLiteral = structuredTransform(Zod.string(), (it) =>
|
|
80
|
+
var SchemaLiteral = structuredTransform(Zod.string(), (it) => parseString3(it).map((it2) => toLiteral(it2)));
|
|
81
81
|
var isUri = (value) => {
|
|
82
82
|
if (!Objects.isObject(value)) {
|
|
83
83
|
return false;
|
package/dist/net/uri.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/net/uri.ts"],"sourcesContent":["import { NominalType, TaggedType } from '@bessemer/cornerstone/types'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport { StringSplitResult } from '@bessemer/cornerstone/string'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result, success } from '@bessemer/cornerstone/result'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport * as IpV6Addresses from '@bessemer/cornerstone/net/ipv6-address'\nimport { ValueOf } from 'type-fest'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\nimport { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport * as UriHostNames from '@bessemer/cornerstone/net/uri-host-name'\nimport { UriHostName } from '@bessemer/cornerstone/net/uri-host-name'\n\nexport type UriString = TaggedType<string, 'UriString'>\nexport type UriComponent = string\n\nexport type UriScheme = string\n\nexport type UriAuthentication = {\n principal: string\n password: string | null\n}\n\nexport type UriHost = {\n value: UriHostName\n port: number | null\n}\n\nexport interface UriLocation {\n path: string | null\n query: string | null\n fragment: string | null\n}\n\nexport const Namespace = ResourceKeys.createNamespace('uri')\nexport const UrlNamespace = ResourceKeys.createNamespace('url')\nexport const EqualBy: Equalitor<Uri> = Equalitors.deepNatural()\n\nexport type UriLiteral = NominalType<string, typeof Namespace>\n\nexport interface UriStructure {\n _type: typeof Namespace | typeof UrlNamespace\n scheme: UriScheme | null\n host: UriHost | null\n authentication: UriAuthentication | null\n location: UriLocation\n}\n\nexport interface Uri extends UriStructure {\n href: UriLiteral\n}\n\ntype UriBuilderAuthentication =\n | {\n principal: string\n password?: string | null\n }\n | string\n\ntype UriBuilderHost =\n | {\n value: string\n port?: number | null\n }\n | string\n\ntype UriBuilderLocation =\n | {\n path?: string | null\n query?: string | null\n fragment?: string | null\n }\n | string\n\nexport type UriBuilder = {\n scheme?: string | null | undefined\n authentication?: UriBuilderAuthentication | null | undefined\n host?: UriBuilderHost | null | undefined\n location?: UriBuilderLocation | null | undefined\n}\n\nexport type UriLike = Uri | UriLiteral | UriBuilder\n\n/**\n * Parses a string into a Uri object, handling all URI components including scheme,\n * authority (host and authentication), and location (path, query, fragment).\n * Returns a Result containing either the parsed Uri or an ErrorEvent on failure.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Parse a complete HTTPS URI\n * const result = Uris.parseString('https://user:pass@example.com:8080/api/v1?q=test#section')\n * if (result.isSuccess) {\n * console.log(result.value.scheme) // 'https'\n * console.log(result.value.host?.value) // 'example.com'\n * console.log(result.value.authentication?.principal) // 'user'\n * }\n *\n * // Parse a simple URI without authority\n * const urnResult = Uris.parseString('urn:isbn:0451450523')\n * if (urnResult.isSuccess) {\n * console.log(urnResult.value.scheme) // 'urn'\n * console.log(urnResult.value.location.path) // 'isbn:0451450523'\n * }\n * ```\n *\n * @category parsing\n */\nexport const parseString = (value: string): Result<Uri, ErrorEvent> => {\n // JOHN we want to improve the syntax burden of handling a series of Result objects like this\n if (Strings.isBlank(value)) {\n return Results.failure(\n ErrorEvents.required({\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Uri from empty string.`,\n })\n )\n }\n\n const schemeResult = parseSchemePart(value)\n if (!schemeResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Uri from uri string: [${value}]`,\n causes: schemeResult.value.causes,\n })\n )\n }\n\n const [scheme, rest1] = schemeResult.value\n\n const authorityPartResult = parseAuthorityPart(rest1)\n if (!authorityPartResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Uri from uri string: [${value}]`,\n causes: authorityPartResult.value.causes,\n })\n )\n }\n const [authority, rest2] = authorityPartResult.value\n\n const location = parseLocation(rest2)\n\n const structure: UriStructure = {\n _type: Namespace,\n scheme,\n host: authority.host,\n authentication: authority.authentication,\n location,\n }\n\n return Results.success({\n ...structure,\n href: formatInternal(structure),\n })\n}\n\n/**\n * Converts various URI-like inputs into a Uri object. Handles Uri instances,\n * string literals, and builder objects, returning them as-is when already a Uri\n * or converting them appropriately.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // String literal parsed into Uri\n * const fromString = Uris.from('https://api.example.com/v1')\n * console.log(fromString.scheme) // 'https'\n * console.log(fromString.host?.value) // 'api.example.com'\n *\n * // Builder object converted to Uri\n * const fromBuilder = Uris.from({\n * scheme: 'https',\n * host: { value: 'example.com', port: 8080 },\n * location: { path: '/api' }\n * })\n * console.log(fromBuilder.host?.port) // 8080\n *\n * @category conversion\n */\nexport function from(value: UriLike | string): Uri\nexport function from(value: UriLike | string | null): Uri | null\nexport function from(value: UriLike | string | undefined): Uri | undefined\nexport function from(value: UriLike | string | null | undefined): Uri | null | undefined\nexport function from(value: UriLike | string | null | undefined): Uri | null | undefined {\n if (Objects.isNil(value)) {\n return value\n }\n if (isUri(value)) {\n return value\n }\n if (Strings.isString(value)) {\n return ErrorEvents.unpackResult(parseString(value))\n }\n\n return build(value as UriBuilder)\n}\n\n/**\n * Converts various URI-like inputs into a normalized string literal representation.\n * Takes any URI-like value and returns its canonical string form\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Convert Uri instance to string literal\n * const uri = Uris.build({ scheme: 'https', host: 'example.com', location: { path: '/api' } })\n * const literal = Uris.toLiteral(uri)\n * console.log(literal) // \"https://example.com/api\"\n *\n * // Convert builder object to string literal\n * const fromBuilder = Uris.toLiteral({\n * scheme: 'https',\n * host: { value: 'api.example.com', port: 8080 },\n * authentication: { principal: 'user', password: 'pass' },\n * location: { path: '/v1', parameters: { q: 'search' } }\n * })\n * console.log(fromBuilder) // \"https://user:pass@api.example.com:8080/v1?q=search\"\n * ```\n *\n * @category serialization\n */\nexport function toLiteral(likeValue: UriLike): UriLiteral\nexport function toLiteral(likeValue: UriLike | null): UriLiteral | null\nexport function toLiteral(likeValue: UriLike | undefined): UriLiteral | undefined\nexport function toLiteral(likeValue: UriLike | null | undefined): UriLiteral | null | undefined\nexport function toLiteral(likeValue: UriLike | null | undefined): UriLiteral | null | undefined {\n if (Objects.isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return format(value) as UriLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => Results.mapResult(parseString(it), (it) => toLiteral(it)))\n// JOHN need a schema for the object version...\n// export const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\n/**\n * Tests if the provided value is a Uri.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Check if unknown value is a Uri\n * function processValue(value: unknown) {\n * if (Uris.isUri(value)) {\n * console.log(value.scheme) // Type-safe access\n * console.log(value.location.path)\n * }\n * }\n * ```\n *\n * @category type-guards\n */\nexport const isUri = (value: unknown): value is Uri => {\n if (!Objects.isObject(value)) {\n return false\n }\n\n const uriValue = value as any as Uri\n return uriValue._type === Namespace || uriValue._type === UrlNamespace\n}\n\n/**\n * Merges an existing URI with partial changes to create a new URI instance.\n * Allows selective updates without replacing the entire URI.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Start with a base URI\n * const baseUri = Uris.build({\n * scheme: 'https',\n * host: { value: 'api.example.com', port: 443 },\n * authentication: { principal: 'user', password: 'pass' },\n * location: { path: '/v1', parameters: { format: 'json' } }\n * })\n *\n * // Change just the host and add query parameter\n * const updatedUri = Uris.merge(baseUri, {\n * host: { value: 'api.production.com' }, // Port preserved from original\n * location: {\n * parameters: { version: '2.0' } // Merges with existing parameters\n * }\n * })\n *\n * console.log(updatedUri.host?.value) // 'api.production.com'\n * console.log(updatedUri.host?.port) // 443 (preserved)\n * console.log(updatedUri.location.parameters) // { format: 'json', version: '2.0' }\n * ```\n *\n * @category transformation\n */\nexport const merge = (element: UriLike, builder: UriBuilder): Uri => {\n const uri = from(element)\n\n let location: UriBuilderLocation | null | undefined\n if (Strings.isString(builder.location) || Objects.isNull(builder.location)) {\n location = builder.location\n } else {\n location = { ...uri.location, ...(builder.location ?? {}) }\n }\n\n const uriBuilder: UriBuilder = {\n scheme: Objects.isUndefined(builder.scheme) ? uri.scheme : builder.scheme,\n host: Objects.isUndefined(builder.host) ? uri.host : builder.host,\n authentication: Objects.isUndefined(builder.authentication) ? uri.authentication : builder.authentication,\n location,\n }\n\n return from(uriBuilder)\n}\n\nconst parseSchemePart = (url: UriComponent): Result<[UriScheme | null, UriComponent], ErrorEvent> => {\n // Search for the colon or double slash\n const schemeMatch = Strings.splitFirst(url, /(\\/\\/|:)/)\n\n // If we don't find either, or we hit the double slash before finding a colon, there is no scheme\n if (Objects.isNil(schemeMatch.selection) || schemeMatch.separator === '//') {\n return Results.success([null, url])\n }\n\n // This means the string started with :, so no protocol\n if (Strings.isEmpty(schemeMatch.selection)) {\n return Results.success([null, ':' + schemeMatch.rest])\n } else {\n const schemeResult = parseScheme(schemeMatch.selection)\n if (!schemeResult.isSuccess) {\n return schemeResult\n }\n\n return Results.success([schemeResult.value, schemeMatch.rest])\n }\n}\n\nconst parseScheme = (scheme: UriComponent): Result<UriScheme, ErrorEvent> => {\n // RFC 3986: scheme = ALPHA *( ALPHA / DIGIT / \"+\" / \"-\" / \".\" )\n const schemeRegex = /^[a-zA-Z][a-zA-Z0-9+.-]*$/\n if (!schemeRegex.test(scheme)) {\n return Results.failure(\n ErrorEvents.invalidValue(scheme, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters in Scheme.`,\n })\n )\n }\n\n return Results.success(scheme)\n}\n\nconst parseAuthorityPart = (\n initialUrl: UriComponent\n): Result<[{ host: UriHost | null; authentication: UriAuthentication | null }, UriComponent], ErrorEvent> => {\n if (!initialUrl.startsWith('//')) {\n return success([{ host: null, authentication: null }, initialUrl])\n }\n\n const url = Strings.removeStart(initialUrl, '//')\n\n const authenticationPartResult = parseAuthenticationPart(url)\n if (!authenticationPartResult.isSuccess) {\n return authenticationPartResult\n }\n const [authentication, rest1] = authenticationPartResult.value\n\n const hostPartResult = parseHostPart(rest1)\n if (!hostPartResult.isSuccess) {\n return hostPartResult\n }\n const [host, rest2] = hostPartResult.value\n\n return success([{ host, authentication }, rest2])\n}\n\nconst parseAuthenticationPart = (url: UriComponent): Result<[UriAuthentication | null, UriComponent], ErrorEvent> => {\n let targetPart = url\n const queryMatch = Strings.splitFirst(targetPart, '?')\n const fragmentMatch = Strings.splitFirst(targetPart, '#')\n if (Objects.isPresent(queryMatch.selection)) {\n targetPart = queryMatch.selection\n } else if (Objects.isPresent(fragmentMatch.selection)) {\n targetPart = fragmentMatch.selection\n }\n\n const { selection: authentication } = Strings.splitFirst(targetPart, '@')\n\n // If there is no @, then we don't have an authentication\n if (Objects.isNil(authentication)) {\n return Results.success([null, url])\n }\n\n const { rest } = Strings.splitFirst(url, '@')\n\n const authenticationParseResult = parseAuthentication(authentication)\n if (!authenticationParseResult.isSuccess) {\n return authenticationParseResult\n }\n\n return Results.success([authenticationParseResult.value, rest])\n}\n\nconst parseAuthentication = (authentication: UriComponent): Result<UriAuthentication, ErrorEvent> => {\n const { selection: principal, rest: authenticationRest } = Strings.splitFirst(authentication, ':')\n\n // If there isn't a colon, then there is no password but there is a username\n if (Objects.isNil(principal)) {\n if (!isAuthenticationComponentValid(authenticationRest)) {\n return Results.failure(\n ErrorEvents.invalidValue(authenticationRest, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for UriAuthentication in principal string: [${authenticationRest}]`,\n })\n )\n }\n\n return Results.success({ principal: decode(authenticationRest), password: null })\n }\n\n // The authentication section started with a :, don't know what to make of this... password but no username?\n if (Strings.isEmpty(principal)) {\n return Results.failure(\n ErrorEvents.invalidValue(authentication, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse UriAuthentication from authentication string: [${authentication}]`,\n })\n )\n }\n\n if (!isAuthenticationComponentValid(principal)) {\n return Results.failure(\n ErrorEvents.invalidValue(principal, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for UriAuthentication in principal string: [${principal}]`,\n })\n )\n }\n\n if (!isAuthenticationComponentValid(authenticationRest)) {\n return Results.failure(\n ErrorEvents.invalidValue(authenticationRest, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for UriAuthentication in password string: [${authenticationRest}]`,\n })\n )\n }\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n return Results.success({ principal: decode(principal), password: decode(authenticationRest) })\n}\n\nconst isAuthenticationComponentValid = (component: UriComponent): boolean => {\n const userinfoRegex = /^[A-Za-z0-9\\-._~!$&'()*+,;=%]*$/\n\n if (component.includes('%')) {\n const percentEncodingRegex = /%[0-9A-Fa-f]{2}/g\n const percentMatches = component.match(/%/g) || []\n const validEncodingMatches = component.match(percentEncodingRegex) || []\n\n if (percentMatches.length !== validEncodingMatches.length) {\n return false\n }\n }\n\n return userinfoRegex.test(component)\n}\n\nconst parseHostPart = (url: UriComponent): Result<[UriHost | null, UriComponent], ErrorEvent> => {\n // Check if the host is starting with reserved characters, if so we should just bail on trying to parse\n if (url.startsWith('?') || url.startsWith('#')) {\n return Results.success([null, url])\n }\n\n // Lets grab everything to the left of the first / ? or #, this is the remainder of our authority (if any)\n const urlMatch = Strings.splitFirst(url, /[\\/?#]/)\n let host = urlMatch.rest\n let rest = ''\n\n if (Objects.isPresent(urlMatch.selection)) {\n host = urlMatch.selection\n rest = urlMatch.separator + urlMatch.rest\n }\n\n if (Strings.isEmpty(host)) {\n return Results.success([null, rest])\n }\n\n const parseHostResult = parseHost(host)\n if (!parseHostResult.isSuccess) {\n return parseHostResult\n }\n\n return Results.success([parseHostResult.value, rest])\n}\n\nconst parseHost = (host: UriComponent): Result<UriHost, ErrorEvent> => {\n // Try to see if we have an ipv6 address like the form [2001:db8::7] and handle it\n if (host.startsWith('[')) {\n const ipMatch = Strings.splitFirst(Strings.removeStart(host, '['), ']')\n\n if (Objects.isPresent(ipMatch.selection)) {\n const ipV6Result = IpV6Addresses.parseString(ipMatch.selection)\n if (!ipV6Result.isSuccess) {\n return ipV6Result\n }\n\n const portMatch = Strings.splitFirst(ipMatch.rest, ':')\n if (Objects.isPresent(portMatch.selection) && Strings.isEmpty(portMatch.selection)) {\n if (!Strings.isNumber(portMatch.rest)) {\n return Results.failure(ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host: [${host}]` }))\n }\n\n return Results.success({ value: `[${ipMatch.selection}]` as UriHostName, port: Number(portMatch.rest) })\n } else {\n return Results.success({ value: `[${ipMatch.selection}]` as UriHostName, port: null })\n }\n }\n }\n\n let hostMatch: StringSplitResult = Strings.splitFirst(host, ':')\n\n // We have no :, which means no port, so treat the rest as the hostname\n if (Objects.isNil(hostMatch.selection)) {\n const hostNameResult = UriHostNames.parseString(hostMatch.rest)\n if (!hostNameResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(host, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Host from host string: [${host}]`,\n causes: hostNameResult.value.causes,\n })\n )\n }\n\n return Results.success({ value: hostNameResult.value, port: null })\n }\n\n // The host started with a :, this is odd\n if (Strings.isEmpty(hostMatch.selection)) {\n return Results.failure(\n ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host from host string: [${host}]` })\n )\n }\n\n const hostName = hostMatch.selection\n\n if (!Strings.isNumber(hostMatch.rest)) {\n return Results.failure(\n ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host from host string: [${host}]` })\n )\n }\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n const hostNameResult = UriHostNames.parseString(hostName)\n if (!hostNameResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(host, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Host from host string: [${host}]`,\n causes: hostNameResult.value.causes,\n })\n )\n }\n\n return Results.success({ value: hostNameResult.value, port: Number(hostMatch.rest) })\n}\n\nconst parseLocation = (url: UriComponent): UriLocation => {\n const location: UriLocation = { path: null, query: null, fragment: null }\n\n // Lets see if we have a fragment and parse it off the end\n const fragmentMatch = Strings.splitFirst(url, '#')\n if (Objects.isPresent(fragmentMatch.selection) && !Strings.isEmpty(fragmentMatch.rest)) {\n location.fragment = encodeWhitespace(fragmentMatch.rest)\n }\n\n // Lets see if we have a query string and parse it off the remainder\n const queryMatch = Strings.splitFirst(fragmentMatch.selection ?? fragmentMatch.rest, '?')\n if (Objects.isPresent(queryMatch.selection) && !Strings.isEmpty(queryMatch.rest)) {\n location.query = encodeWhitespace(queryMatch.rest)\n }\n\n const path = Strings.emptyToNull(queryMatch.selection ?? queryMatch.rest)\n if (Objects.isPresent(path)) {\n location.path = encodeWhitespace(path)\n }\n return location\n}\n\nconst build = (builder: UriBuilder): Uri => {\n const scheme = Objects.isPresent(builder.scheme) ? ErrorEvents.unpackResult(parseScheme(builder.scheme)) : null\n let host: UriHost | null = null\n let authentication: UriAuthentication | null = null\n\n if (Objects.isPresent(builder.host)) {\n if (Strings.isString(builder.host)) {\n host = ErrorEvents.unpackResult(parseHost(builder.host))\n } else {\n host = {\n value: UriHostNames.from(builder.host.value),\n port: builder.host.port ?? null,\n }\n }\n\n if (Objects.isPresent(builder.authentication)) {\n if (Strings.isString(builder.authentication)) {\n authentication = ErrorEvents.unpackResult(parseAuthentication(builder.authentication))\n } else {\n authentication = {\n principal: builder.authentication.principal,\n password: builder.authentication.password ?? null,\n }\n }\n }\n }\n\n let location: UriLocation = {\n path: null,\n query: null,\n fragment: null,\n }\n\n if (Objects.isPresent(builder.location)) {\n if (Strings.isString(builder.location)) {\n let locationString = builder.location\n if (Objects.isPresent(builder.host) && !locationString.startsWith('/') && !locationString.startsWith('?') && !locationString.startsWith('#')) {\n locationString = '/' + locationString\n }\n\n location = parseLocation(locationString)\n } else {\n let path = builder.location.path ?? null\n if (Objects.isPresent(path) && !path.startsWith('/') && Objects.isPresent(builder.host)) {\n path = '/' + path\n }\n\n location = {\n path: Objects.isPresent(path) ? encodeWhitespace(path) : null,\n query: Objects.isPresent(builder.location.query) ? encodeWhitespace(builder.location.query) : null,\n fragment: Objects.isPresent(builder.location.fragment) ? encodeWhitespace(builder.location.fragment) : null,\n }\n }\n }\n\n const structure: UriStructure = {\n _type: Namespace,\n scheme,\n host,\n authentication,\n location,\n }\n\n return {\n ...structure,\n href: formatInternal(structure),\n }\n}\n\nexport const UriComponentType = {\n Scheme: 'Scheme',\n Authentication: 'Authentication',\n Host: 'Host',\n Location: 'Location',\n Path: 'Path',\n Query: 'Query',\n Fragment: 'Fragment',\n} as const\n\nexport type UriComponentType = ValueOf<typeof UriComponentType>\n\n/**\n * Converts a URI object into its string representation, with optional exclusion of specific URI components.\n *\n * **Example**\n *\n * ```ts\n * import { Uris, UriComponentType } from \"@bessemer/cornerstone\"\n *\n * const uri = Uris.build({\n * scheme: 'https',\n * authentication: { principal: 'user', password: 'secret' },\n * host: { value: 'api.example.com', port: 8080 },\n * location: { path: '/v1/data', parameters: { format: 'json' }, fragment: 'results' }\n * })\n *\n * // Format complete URI\n * const fullUri = Uris.format(uri)\n * console.log(fullUri) // \"https://user:secret@api.example.com:8080/v1/data?format=json#results\"\n *\n * // Exclude authentication for public sharing\n * const publicUri = Uris.format(uri, [UriComponentType.Authentication])\n * console.log(publicUri) // \"https://api.example.com:8080/v1/data?format=json#results\"\n *\n * // Format path-only URI\n * const pathOnly = Uris.format(uri, [\n * UriComponentType.Scheme,\n * UriComponentType.Host,\n * UriComponentType.Authentication\n * ])\n * console.log(pathOnly) // \"/v1/data?format=json#results\"\n * ```\n *\n * @category serialization\n */\nexport const format = (uriLike: UriLike, excludedUriComponents: Array<UriComponentType> = []): UriLiteral => {\n return formatInternal(from(uriLike), excludedUriComponents)\n}\n\nconst formatInternal = (uri: UriStructure, excludedUriComponents: Array<UriComponentType> = []): UriLiteral => {\n let urlString = ''\n if (Objects.isPresent(uri.scheme) && !Arrays.contains(excludedUriComponents, UriComponentType.Scheme)) {\n urlString = urlString + uri.scheme + ':'\n }\n\n if (Objects.isPresent(uri.host) && !Arrays.contains(excludedUriComponents, UriComponentType.Host)) {\n urlString = urlString + '//'\n\n if (Objects.isPresent(uri.authentication) && !Arrays.contains(excludedUriComponents, UriComponentType.Authentication)) {\n urlString = urlString + encode(uri.authentication.principal)\n\n if (Objects.isPresent(uri.authentication.password)) {\n urlString = urlString + ':' + encode(uri.authentication.password)\n }\n\n urlString = urlString + '@'\n }\n\n urlString = urlString + uri.host.value\n if (Objects.isPresent(uri.host.port)) {\n urlString = urlString + ':' + uri.host.port\n }\n }\n\n if (!Arrays.contains(excludedUriComponents, UriComponentType.Location)) {\n urlString = urlString + formatLocation(uri.location, excludedUriComponents)\n }\n\n return urlString as UriLiteral\n}\n\nconst formatLocation = (location: UriLocation, excludedUriComponents: Array<UriComponentType> = []): string => {\n let urlString = ''\n\n if (Objects.isPresent(location.path) && !Arrays.contains(excludedUriComponents, UriComponentType.Path)) {\n urlString = urlString + location.path\n }\n\n if (Objects.isPresent(location.query) && !Arrays.contains(excludedUriComponents, UriComponentType.Query)) {\n urlString = urlString + '?' + location.query\n }\n\n if (Objects.isPresent(location.fragment) && !Arrays.contains(excludedUriComponents, UriComponentType.Fragment)) {\n urlString = urlString + '#' + location.fragment\n }\n\n return urlString\n}\n\nconst encodeWhitespace = (uriComponent: UriComponent) => {\n return uriComponent.replaceAll(' ', '%20')\n}\n\nexport const encode = (uriComponent: UriComponent) => {\n return encodeURIComponent(uriComponent)\n}\n\nexport const decode = (uriComponent: UriComponent) => {\n return decodeURIComponent(uriComponent)\n}\n"],"mappings":";AACA,YAAY,aAAa;AAEzB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,kBAAkB;AAC9B,YAAY,aAAa;AACzB,SAAiB,WAAAA,gBAAe;AAChC,YAAY,iBAAiB;AAE7B,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,YAAY,mBAAmB;AAE/B,YAAY,gBAAgB;AAE5B,YAAY,kBAAkB;AAwBvB,IAAM,YAAyB,6BAAgB,KAAK;AACpD,IAAM,eAA4B,6BAAgB,KAAK;AACvD,IAAM,UAAqC,uBAA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AS,uBAAuB,iBAAiB,QAAQ,GAAG;AACtE,gBAAY,YAAY,eAAe,IAAI,UAAU,qBAAqB;AAAA,EAC5E;AAEA,SAAO;AACT;AAEA,IAAM,iBAAiB,CAAC,UAAuB,wBAAiD,CAAC,MAAc;AAC7G,MAAI,YAAY;AAEhB,MAAY,kBAAU,SAAS,IAAI,KAAK,CAAQ,gBAAS,uBAAuB,iBAAiB,IAAI,GAAG;AACtG,gBAAY,YAAY,SAAS;AAAA,EACnC;AAEA,MAAY,kBAAU,SAAS,KAAK,KAAK,CAAQ,gBAAS,uBAAuB,iBAAiB,KAAK,GAAG;AACxG,gBAAY,YAAY,MAAM,SAAS;AAAA,EACzC;AAEA,MAAY,kBAAU,SAAS,QAAQ,KAAK,CAAQ,gBAAS,uBAAuB,iBAAiB,QAAQ,GAAG;AAC9G,gBAAY,YAAY,MAAM,SAAS;AAAA,EACzC;AAEA,SAAO;AACT;AAEA,IAAM,mBAAmB,CAAC,iBAA+B;AACvD,SAAO,aAAa,WAAW,KAAK,KAAK;AAC3C;AAEO,IAAM,SAAS,CAAC,iBAA+B;AACpD,SAAO,mBAAmB,YAAY;AACxC;AAEO,IAAM,SAAS,CAAC,iBAA+B;AACpD,SAAO,mBAAmB,YAAY;AACxC;","names":["success","parseString","from","it","hostNameResult"]}
|
|
1
|
+
{"version":3,"sources":["../../src/net/uri.ts"],"sourcesContent":["import { NominalType, TaggedType } from '@bessemer/cornerstone/types'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport { StringSplitResult } from '@bessemer/cornerstone/string'\nimport * as Objects from '@bessemer/cornerstone/object'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport * as ResourceKeys from '@bessemer/cornerstone/resource-key'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result, success } from '@bessemer/cornerstone/result'\nimport * as ErrorEvents from '@bessemer/cornerstone/error/error-event'\nimport { ErrorEvent } from '@bessemer/cornerstone/error/error-event'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport * as IpV6Addresses from '@bessemer/cornerstone/net/ipv6-address'\nimport { ValueOf } from 'type-fest'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\nimport { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport * as UriHostNames from '@bessemer/cornerstone/net/uri-host-name'\nimport { UriHostName } from '@bessemer/cornerstone/net/uri-host-name'\n\nexport type UriString = TaggedType<string, 'UriString'>\nexport type UriComponent = string\n\nexport type UriScheme = string\n\nexport type UriAuthentication = {\n principal: string\n password: string | null\n}\n\nexport type UriHost = {\n value: UriHostName\n port: number | null\n}\n\nexport interface UriLocation {\n path: string | null\n query: string | null\n fragment: string | null\n}\n\nexport const Namespace = ResourceKeys.createNamespace('uri')\nexport const UrlNamespace = ResourceKeys.createNamespace('url')\nexport const EqualBy: Equalitor<Uri> = Equalitors.deepNatural()\n\nexport type UriLiteral = NominalType<string, typeof Namespace>\n\nexport interface UriStructure {\n _type: typeof Namespace | typeof UrlNamespace\n scheme: UriScheme | null\n host: UriHost | null\n authentication: UriAuthentication | null\n location: UriLocation\n}\n\nexport interface Uri extends UriStructure {\n href: UriLiteral\n}\n\ntype UriBuilderAuthentication =\n | {\n principal: string\n password?: string | null\n }\n | string\n\ntype UriBuilderHost =\n | {\n value: string\n port?: number | null\n }\n | string\n\ntype UriBuilderLocation =\n | {\n path?: string | null\n query?: string | null\n fragment?: string | null\n }\n | string\n\nexport type UriBuilder = {\n scheme?: string | null | undefined\n authentication?: UriBuilderAuthentication | null | undefined\n host?: UriBuilderHost | null | undefined\n location?: UriBuilderLocation | null | undefined\n}\n\nexport type UriLike = Uri | UriLiteral | UriBuilder\n\n/**\n * Parses a string into a Uri object, handling all URI components including scheme,\n * authority (host and authentication), and location (path, query, fragment).\n * Returns a Result containing either the parsed Uri or an ErrorEvent on failure.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Parse a complete HTTPS URI\n * const result = Uris.parseString('https://user:pass@example.com:8080/api/v1?q=test#section')\n * if (result.isSuccess) {\n * console.log(result.value.scheme) // 'https'\n * console.log(result.value.host?.value) // 'example.com'\n * console.log(result.value.authentication?.principal) // 'user'\n * }\n *\n * // Parse a simple URI without authority\n * const urnResult = Uris.parseString('urn:isbn:0451450523')\n * if (urnResult.isSuccess) {\n * console.log(urnResult.value.scheme) // 'urn'\n * console.log(urnResult.value.location.path) // 'isbn:0451450523'\n * }\n * ```\n *\n * @category parsing\n */\nexport const parseString = (value: string): Result<Uri, ErrorEvent> => {\n // JOHN we want to improve the syntax burden of handling a series of Result objects like this\n if (Strings.isBlank(value)) {\n return Results.failure(\n ErrorEvents.required({\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Uri from empty string.`,\n })\n )\n }\n\n const schemeResult = parseSchemePart(value)\n if (!schemeResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Uri from string: [${value}]`,\n causes: schemeResult.value.causes,\n })\n )\n }\n\n const [scheme, rest1] = schemeResult.value\n\n const authorityPartResult = parseAuthorityPart(rest1)\n if (!authorityPartResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(value, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Uri from string: [${value}]`,\n causes: authorityPartResult.value.causes,\n })\n )\n }\n const [authority, rest2] = authorityPartResult.value\n\n const location = parseLocation(rest2)\n\n const structure: UriStructure = {\n _type: Namespace,\n scheme,\n host: authority.host,\n authentication: authority.authentication,\n location,\n }\n\n return Results.success({\n ...structure,\n href: formatInternal(structure),\n })\n}\n\n/**\n * Converts various URI-like inputs into a Uri object. Handles Uri instances,\n * string literals, and builder objects, returning them as-is when already a Uri\n * or converting them appropriately.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // String literal parsed into Uri\n * const fromString = Uris.from('https://api.example.com/v1')\n * console.log(fromString.scheme) // 'https'\n * console.log(fromString.host?.value) // 'api.example.com'\n *\n * // Builder object converted to Uri\n * const fromBuilder = Uris.from({\n * scheme: 'https',\n * host: { value: 'example.com', port: 8080 },\n * location: { path: '/api' }\n * })\n * console.log(fromBuilder.host?.port) // 8080\n *\n * @category conversion\n */\nexport function from(value: UriLike | string): Uri\nexport function from(value: UriLike | string | null): Uri | null\nexport function from(value: UriLike | string | undefined): Uri | undefined\nexport function from(value: UriLike | string | null | undefined): Uri | null | undefined\nexport function from(value: UriLike | string | null | undefined): Uri | null | undefined {\n if (Objects.isNil(value)) {\n return value\n }\n if (isUri(value)) {\n return value\n }\n if (Strings.isString(value)) {\n return ErrorEvents.unpackResult(parseString(value))\n }\n\n return build(value as UriBuilder)\n}\n\n/**\n * Converts various URI-like inputs into a normalized string literal representation.\n * Takes any URI-like value and returns its canonical string form\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Convert Uri instance to string literal\n * const uri = Uris.build({ scheme: 'https', host: 'example.com', location: { path: '/api' } })\n * const literal = Uris.toLiteral(uri)\n * console.log(literal) // \"https://example.com/api\"\n *\n * // Convert builder object to string literal\n * const fromBuilder = Uris.toLiteral({\n * scheme: 'https',\n * host: { value: 'api.example.com', port: 8080 },\n * authentication: { principal: 'user', password: 'pass' },\n * location: { path: '/v1', parameters: { q: 'search' } }\n * })\n * console.log(fromBuilder) // \"https://user:pass@api.example.com:8080/v1?q=search\"\n * ```\n *\n * @category serialization\n */\nexport function toLiteral(likeValue: UriLike): UriLiteral\nexport function toLiteral(likeValue: UriLike | null): UriLiteral | null\nexport function toLiteral(likeValue: UriLike | undefined): UriLiteral | undefined\nexport function toLiteral(likeValue: UriLike | null | undefined): UriLiteral | null | undefined\nexport function toLiteral(likeValue: UriLike | null | undefined): UriLiteral | null | undefined {\n if (Objects.isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return format(value) as UriLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => parseString(it).map((it) => toLiteral(it)))\n// JOHN need a schema for the object version...\n// export const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\n/**\n * Tests if the provided value is a Uri.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Check if unknown value is a Uri\n * function processValue(value: unknown) {\n * if (Uris.isUri(value)) {\n * console.log(value.scheme) // Type-safe access\n * console.log(value.location.path)\n * }\n * }\n * ```\n *\n * @category type-guards\n */\nexport const isUri = (value: unknown): value is Uri => {\n if (!Objects.isObject(value)) {\n return false\n }\n\n const uriValue = value as any as Uri\n return uriValue._type === Namespace || uriValue._type === UrlNamespace\n}\n\n/**\n * Merges an existing URI with partial changes to create a new URI instance.\n * Allows selective updates without replacing the entire URI.\n *\n * **Example**\n *\n * ```ts\n * import { Uris } from \"@bessemer/cornerstone\"\n *\n * // Start with a base URI\n * const baseUri = Uris.build({\n * scheme: 'https',\n * host: { value: 'api.example.com', port: 443 },\n * authentication: { principal: 'user', password: 'pass' },\n * location: { path: '/v1', parameters: { format: 'json' } }\n * })\n *\n * // Change just the host and add query parameter\n * const updatedUri = Uris.merge(baseUri, {\n * host: { value: 'api.production.com' }, // Port preserved from original\n * location: {\n * parameters: { version: '2.0' } // Merges with existing parameters\n * }\n * })\n *\n * console.log(updatedUri.host?.value) // 'api.production.com'\n * console.log(updatedUri.host?.port) // 443 (preserved)\n * console.log(updatedUri.location.parameters) // { format: 'json', version: '2.0' }\n * ```\n *\n * @category transformation\n */\nexport const merge = (element: UriLike, builder: UriBuilder): Uri => {\n const uri = from(element)\n\n let location: UriBuilderLocation | null | undefined\n if (Strings.isString(builder.location) || Objects.isNull(builder.location)) {\n location = builder.location\n } else {\n location = { ...uri.location, ...(builder.location ?? {}) }\n }\n\n const uriBuilder: UriBuilder = {\n scheme: Objects.isUndefined(builder.scheme) ? uri.scheme : builder.scheme,\n host: Objects.isUndefined(builder.host) ? uri.host : builder.host,\n authentication: Objects.isUndefined(builder.authentication) ? uri.authentication : builder.authentication,\n location,\n }\n\n return from(uriBuilder)\n}\n\nconst parseSchemePart = (url: UriComponent): Result<[UriScheme | null, UriComponent], ErrorEvent> => {\n // Search for the colon or double slash\n const schemeMatch = Strings.splitFirst(url, /(\\/\\/|:)/)\n\n // If we don't find either, or we hit the double slash before finding a colon, there is no scheme\n if (Objects.isNil(schemeMatch.selection) || schemeMatch.separator === '//') {\n return Results.success([null, url])\n }\n\n // This means the string started with :, so no protocol\n if (Strings.isEmpty(schemeMatch.selection)) {\n return Results.success([null, ':' + schemeMatch.rest])\n } else {\n const schemeResult = parseScheme(schemeMatch.selection)\n if (!schemeResult.isSuccess) {\n return schemeResult\n }\n\n return Results.success([schemeResult.value, schemeMatch.rest])\n }\n}\n\nconst parseScheme = (scheme: UriComponent): Result<UriScheme, ErrorEvent> => {\n // RFC 3986: scheme = ALPHA *( ALPHA / DIGIT / \"+\" / \"-\" / \".\" )\n const schemeRegex = /^[a-zA-Z][a-zA-Z0-9+.-]*$/\n if (!schemeRegex.test(scheme)) {\n return Results.failure(\n ErrorEvents.invalidValue(scheme, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters in Scheme.`,\n })\n )\n }\n\n return Results.success(scheme)\n}\n\nconst parseAuthorityPart = (\n initialUrl: UriComponent\n): Result<[{ host: UriHost | null; authentication: UriAuthentication | null }, UriComponent], ErrorEvent> => {\n if (!initialUrl.startsWith('//')) {\n return success([{ host: null, authentication: null }, initialUrl])\n }\n\n const url = Strings.removeStart(initialUrl, '//')\n\n const authenticationPartResult = parseAuthenticationPart(url)\n if (!authenticationPartResult.isSuccess) {\n return authenticationPartResult\n }\n const [authentication, rest1] = authenticationPartResult.value\n\n const hostPartResult = parseHostPart(rest1)\n if (!hostPartResult.isSuccess) {\n return hostPartResult\n }\n const [host, rest2] = hostPartResult.value\n\n return success([{ host, authentication }, rest2])\n}\n\nconst parseAuthenticationPart = (url: UriComponent): Result<[UriAuthentication | null, UriComponent], ErrorEvent> => {\n let targetPart = url\n const queryMatch = Strings.splitFirst(targetPart, '?')\n const fragmentMatch = Strings.splitFirst(targetPart, '#')\n if (Objects.isPresent(queryMatch.selection)) {\n targetPart = queryMatch.selection\n } else if (Objects.isPresent(fragmentMatch.selection)) {\n targetPart = fragmentMatch.selection\n }\n\n const { selection: authentication } = Strings.splitFirst(targetPart, '@')\n\n // If there is no @, then we don't have an authentication\n if (Objects.isNil(authentication)) {\n return Results.success([null, url])\n }\n\n const { rest } = Strings.splitFirst(url, '@')\n\n const authenticationParseResult = parseAuthentication(authentication)\n if (!authenticationParseResult.isSuccess) {\n return authenticationParseResult\n }\n\n return Results.success([authenticationParseResult.value, rest])\n}\n\nconst parseAuthentication = (authentication: UriComponent): Result<UriAuthentication, ErrorEvent> => {\n const { selection: principal, rest: authenticationRest } = Strings.splitFirst(authentication, ':')\n\n // If there isn't a colon, then there is no password but there is a username\n if (Objects.isNil(principal)) {\n if (!isAuthenticationComponentValid(authenticationRest)) {\n return Results.failure(\n ErrorEvents.invalidValue(authenticationRest, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for UriAuthentication in principal string: [${authenticationRest}]`,\n })\n )\n }\n\n return Results.success({ principal: decode(authenticationRest), password: null })\n }\n\n // The authentication section started with a :, don't know what to make of this... password but no username?\n if (Strings.isEmpty(principal)) {\n return Results.failure(\n ErrorEvents.invalidValue(authentication, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse UriAuthentication from authentication string: [${authentication}]`,\n })\n )\n }\n\n if (!isAuthenticationComponentValid(principal)) {\n return Results.failure(\n ErrorEvents.invalidValue(principal, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for UriAuthentication in principal string: [${principal}]`,\n })\n )\n }\n\n if (!isAuthenticationComponentValid(authenticationRest)) {\n return Results.failure(\n ErrorEvents.invalidValue(authenticationRest, {\n namespace: Namespace,\n message: `[${Namespace}]: Invalid characters for UriAuthentication in password string: [${authenticationRest}]`,\n })\n )\n }\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n return Results.success({ principal: decode(principal), password: decode(authenticationRest) })\n}\n\nconst isAuthenticationComponentValid = (component: UriComponent): boolean => {\n const userinfoRegex = /^[A-Za-z0-9\\-._~!$&'()*+,;=%]*$/\n\n if (component.includes('%')) {\n const percentEncodingRegex = /%[0-9A-Fa-f]{2}/g\n const percentMatches = component.match(/%/g) || []\n const validEncodingMatches = component.match(percentEncodingRegex) || []\n\n if (percentMatches.length !== validEncodingMatches.length) {\n return false\n }\n }\n\n return userinfoRegex.test(component)\n}\n\nconst parseHostPart = (url: UriComponent): Result<[UriHost | null, UriComponent], ErrorEvent> => {\n // Check if the host is starting with reserved characters, if so we should just bail on trying to parse\n if (url.startsWith('?') || url.startsWith('#')) {\n return Results.success([null, url])\n }\n\n // Lets grab everything to the left of the first / ? or #, this is the remainder of our authority (if any)\n const urlMatch = Strings.splitFirst(url, /[\\/?#]/)\n let host = urlMatch.rest\n let rest = ''\n\n if (Objects.isPresent(urlMatch.selection)) {\n host = urlMatch.selection\n rest = urlMatch.separator + urlMatch.rest\n }\n\n if (Strings.isEmpty(host)) {\n return Results.success([null, rest])\n }\n\n const parseHostResult = parseHost(host)\n if (!parseHostResult.isSuccess) {\n return parseHostResult\n }\n\n return Results.success([parseHostResult.value, rest])\n}\n\nconst parseHost = (host: UriComponent): Result<UriHost, ErrorEvent> => {\n // Try to see if we have an ipv6 address like the form [2001:db8::7] and handle it\n if (host.startsWith('[')) {\n const ipMatch = Strings.splitFirst(Strings.removeStart(host, '['), ']')\n\n if (Objects.isPresent(ipMatch.selection)) {\n const ipV6Result = IpV6Addresses.parseString(ipMatch.selection)\n if (!ipV6Result.isSuccess) {\n return ipV6Result\n }\n\n const portMatch = Strings.splitFirst(ipMatch.rest, ':')\n if (Objects.isPresent(portMatch.selection) && Strings.isEmpty(portMatch.selection)) {\n if (!Strings.isNumber(portMatch.rest)) {\n return Results.failure(ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host: [${host}]` }))\n }\n\n return Results.success({ value: `[${ipMatch.selection}]` as UriHostName, port: Number(portMatch.rest) })\n } else {\n return Results.success({ value: `[${ipMatch.selection}]` as UriHostName, port: null })\n }\n }\n }\n\n let hostMatch: StringSplitResult = Strings.splitFirst(host, ':')\n\n // We have no :, which means no port, so treat the rest as the hostname\n if (Objects.isNil(hostMatch.selection)) {\n const hostNameResult = UriHostNames.parseString(hostMatch.rest)\n if (!hostNameResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(host, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Host from host string: [${host}]`,\n causes: hostNameResult.value.causes,\n })\n )\n }\n\n return Results.success({ value: hostNameResult.value, port: null })\n }\n\n // The host started with a :, this is odd\n if (Strings.isEmpty(hostMatch.selection)) {\n return Results.failure(\n ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host from host string: [${host}]` })\n )\n }\n\n const hostName = hostMatch.selection\n\n if (!Strings.isNumber(hostMatch.rest)) {\n return Results.failure(\n ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host from host string: [${host}]` })\n )\n }\n\n // Otherwise, we have both, so return the complete authentication object and the rest\n const hostNameResult = UriHostNames.parseString(hostName)\n if (!hostNameResult.isSuccess) {\n return Results.failure(\n ErrorEvents.invalidValue(host, {\n namespace: Namespace,\n message: `[${Namespace}]: Unable to parse Host from host string: [${host}]`,\n causes: hostNameResult.value.causes,\n })\n )\n }\n\n return Results.success({ value: hostNameResult.value, port: Number(hostMatch.rest) })\n}\n\nconst parseLocation = (url: UriComponent): UriLocation => {\n const location: UriLocation = { path: null, query: null, fragment: null }\n\n // Lets see if we have a fragment and parse it off the end\n const fragmentMatch = Strings.splitFirst(url, '#')\n if (Objects.isPresent(fragmentMatch.selection) && !Strings.isEmpty(fragmentMatch.rest)) {\n location.fragment = encodeWhitespace(fragmentMatch.rest)\n }\n\n // Lets see if we have a query string and parse it off the remainder\n const queryMatch = Strings.splitFirst(fragmentMatch.selection ?? fragmentMatch.rest, '?')\n if (Objects.isPresent(queryMatch.selection) && !Strings.isEmpty(queryMatch.rest)) {\n location.query = encodeWhitespace(queryMatch.rest)\n }\n\n const path = Strings.emptyToNull(queryMatch.selection ?? queryMatch.rest)\n if (Objects.isPresent(path)) {\n location.path = encodeWhitespace(path)\n }\n return location\n}\n\nconst build = (builder: UriBuilder): Uri => {\n const scheme = Objects.isPresent(builder.scheme) ? ErrorEvents.unpackResult(parseScheme(builder.scheme)) : null\n let host: UriHost | null = null\n let authentication: UriAuthentication | null = null\n\n if (Objects.isPresent(builder.host)) {\n if (Strings.isString(builder.host)) {\n host = ErrorEvents.unpackResult(parseHost(builder.host))\n } else {\n host = {\n value: UriHostNames.from(builder.host.value),\n port: builder.host.port ?? null,\n }\n }\n\n if (Objects.isPresent(builder.authentication)) {\n if (Strings.isString(builder.authentication)) {\n authentication = ErrorEvents.unpackResult(parseAuthentication(builder.authentication))\n } else {\n authentication = {\n principal: builder.authentication.principal,\n password: builder.authentication.password ?? null,\n }\n }\n }\n }\n\n let location: UriLocation = {\n path: null,\n query: null,\n fragment: null,\n }\n\n if (Objects.isPresent(builder.location)) {\n if (Strings.isString(builder.location)) {\n let locationString = builder.location\n if (Objects.isPresent(builder.host) && !locationString.startsWith('/') && !locationString.startsWith('?') && !locationString.startsWith('#')) {\n locationString = '/' + locationString\n }\n\n location = parseLocation(locationString)\n } else {\n let path = builder.location.path ?? null\n if (Objects.isPresent(path) && !path.startsWith('/') && Objects.isPresent(builder.host)) {\n path = '/' + path\n }\n\n location = {\n path: Objects.isPresent(path) ? encodeWhitespace(path) : null,\n query: Objects.isPresent(builder.location.query) ? encodeWhitespace(builder.location.query) : null,\n fragment: Objects.isPresent(builder.location.fragment) ? encodeWhitespace(builder.location.fragment) : null,\n }\n }\n }\n\n const structure: UriStructure = {\n _type: Namespace,\n scheme,\n host,\n authentication,\n location,\n }\n\n return {\n ...structure,\n href: formatInternal(structure),\n }\n}\n\nexport const UriComponentType = {\n Scheme: 'Scheme',\n Authentication: 'Authentication',\n Host: 'Host',\n Location: 'Location',\n Path: 'Path',\n Query: 'Query',\n Fragment: 'Fragment',\n} as const\n\nexport type UriComponentType = ValueOf<typeof UriComponentType>\n\n/**\n * Converts a URI object into its string representation, with optional exclusion of specific URI components.\n *\n * **Example**\n *\n * ```ts\n * import { Uris, UriComponentType } from \"@bessemer/cornerstone\"\n *\n * const uri = Uris.build({\n * scheme: 'https',\n * authentication: { principal: 'user', password: 'secret' },\n * host: { value: 'api.example.com', port: 8080 },\n * location: { path: '/v1/data', parameters: { format: 'json' }, fragment: 'results' }\n * })\n *\n * // Format complete URI\n * const fullUri = Uris.format(uri)\n * console.log(fullUri) // \"https://user:secret@api.example.com:8080/v1/data?format=json#results\"\n *\n * // Exclude authentication for public sharing\n * const publicUri = Uris.format(uri, [UriComponentType.Authentication])\n * console.log(publicUri) // \"https://api.example.com:8080/v1/data?format=json#results\"\n *\n * // Format path-only URI\n * const pathOnly = Uris.format(uri, [\n * UriComponentType.Scheme,\n * UriComponentType.Host,\n * UriComponentType.Authentication\n * ])\n * console.log(pathOnly) // \"/v1/data?format=json#results\"\n * ```\n *\n * @category serialization\n */\nexport const format = (uriLike: UriLike, excludedUriComponents: Array<UriComponentType> = []): UriLiteral => {\n return formatInternal(from(uriLike), excludedUriComponents)\n}\n\nconst formatInternal = (uri: UriStructure, excludedUriComponents: Array<UriComponentType> = []): UriLiteral => {\n let urlString = ''\n if (Objects.isPresent(uri.scheme) && !Arrays.contains(excludedUriComponents, UriComponentType.Scheme)) {\n urlString = urlString + uri.scheme + ':'\n }\n\n if (Objects.isPresent(uri.host) && !Arrays.contains(excludedUriComponents, UriComponentType.Host)) {\n urlString = urlString + '//'\n\n if (Objects.isPresent(uri.authentication) && !Arrays.contains(excludedUriComponents, UriComponentType.Authentication)) {\n urlString = urlString + encode(uri.authentication.principal)\n\n if (Objects.isPresent(uri.authentication.password)) {\n urlString = urlString + ':' + encode(uri.authentication.password)\n }\n\n urlString = urlString + '@'\n }\n\n urlString = urlString + uri.host.value\n if (Objects.isPresent(uri.host.port)) {\n urlString = urlString + ':' + uri.host.port\n }\n }\n\n if (!Arrays.contains(excludedUriComponents, UriComponentType.Location)) {\n urlString = urlString + formatLocation(uri.location, excludedUriComponents)\n }\n\n return urlString as UriLiteral\n}\n\nconst formatLocation = (location: UriLocation, excludedUriComponents: Array<UriComponentType> = []): string => {\n let urlString = ''\n\n if (Objects.isPresent(location.path) && !Arrays.contains(excludedUriComponents, UriComponentType.Path)) {\n urlString = urlString + location.path\n }\n\n if (Objects.isPresent(location.query) && !Arrays.contains(excludedUriComponents, UriComponentType.Query)) {\n urlString = urlString + '?' + location.query\n }\n\n if (Objects.isPresent(location.fragment) && !Arrays.contains(excludedUriComponents, UriComponentType.Fragment)) {\n urlString = urlString + '#' + location.fragment\n }\n\n return urlString\n}\n\nconst encodeWhitespace = (uriComponent: UriComponent) => {\n return uriComponent.replaceAll(' ', '%20')\n}\n\nexport const encode = (uriComponent: UriComponent) => {\n return encodeURIComponent(uriComponent)\n}\n\nexport const decode = (uriComponent: UriComponent) => {\n return decodeURIComponent(uriComponent)\n}\n"],"mappings":";AACA,YAAY,aAAa;AAEzB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,kBAAkB;AAC9B,YAAY,aAAa;AACzB,SAAiB,WAAAA,gBAAe;AAChC,YAAY,iBAAiB;AAE7B,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,YAAY,mBAAmB;AAE/B,YAAY,gBAAgB;AAE5B,YAAY,kBAAkB;AAwBvB,IAAM,YAAyB,6BAAgB,KAAK;AACpD,IAAM,eAA4B,6BAAgB,KAAK;AACvD,IAAM,UAAqC,uBAAY;AA2EvD,IAAMC,eAAc,CAAC,UAA2C;AAErE,MAAY,gBAAQ,KAAK,GAAG;AAC1B,WAAe;AAAA,MACD,qBAAS;AAAA,QACnB,WAAW;AAAA,QACX,SAAS,IAAI,SAAS;AAAA,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