@bessemer/cornerstone 0.5.109 → 0.5.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/array.d.ts +2 -1
  2. package/dist/array.d.ts.map +1 -1
  3. package/dist/array.js +11 -0
  4. package/dist/array.js.map +1 -1
  5. package/dist/either.d.ts +23 -40
  6. package/dist/either.d.ts.map +1 -1
  7. package/dist/either.js +50 -88
  8. package/dist/either.js.map +1 -1
  9. package/dist/error/error-event.d.ts.map +1 -1
  10. package/dist/error/error-event.js +3 -2
  11. package/dist/error/error-event.js.map +1 -1
  12. package/dist/error/error.d.ts +10 -0
  13. package/dist/error/error.d.ts.map +1 -1
  14. package/dist/error/error.js +21 -2
  15. package/dist/error/error.js.map +1 -1
  16. package/dist/generators.d.ts +2 -0
  17. package/dist/generators.d.ts.map +1 -0
  18. package/dist/generators.js +14 -0
  19. package/dist/generators.js.map +1 -0
  20. package/dist/index.d.ts +6 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +10 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/json.d.ts +2 -1
  25. package/dist/json.d.ts.map +1 -1
  26. package/dist/json.js.map +1 -1
  27. package/dist/math.d.ts +2 -0
  28. package/dist/math.d.ts.map +1 -1
  29. package/dist/math.js +9 -1
  30. package/dist/math.js.map +1 -1
  31. package/dist/mime-type.d.ts +4 -3
  32. package/dist/mime-type.d.ts.map +1 -1
  33. package/dist/mime-type.js +9 -6
  34. package/dist/mime-type.js.map +1 -1
  35. package/dist/net/content-type.d.ts +21 -0
  36. package/dist/net/content-type.d.ts.map +1 -0
  37. package/dist/net/content-type.js +120 -0
  38. package/dist/net/content-type.js.map +1 -0
  39. package/dist/net/fetch.d.ts +18 -0
  40. package/dist/net/fetch.d.ts.map +1 -0
  41. package/dist/net/fetch.js +65 -0
  42. package/dist/net/fetch.js.map +1 -0
  43. package/dist/net/http-method.d.ts +18 -0
  44. package/dist/net/http-method.d.ts.map +1 -0
  45. package/dist/net/http-method.js +37 -0
  46. package/dist/net/http-method.js.map +1 -0
  47. package/dist/net/http-request.d.ts +12 -0
  48. package/dist/net/http-request.d.ts.map +1 -0
  49. package/dist/net/http-request.js +1 -0
  50. package/dist/net/http-request.js.map +1 -0
  51. package/dist/net/uri-host-name.d.ts +1 -1
  52. package/dist/net/uri-host-name.d.ts.map +1 -1
  53. package/dist/net/uri-host-name.js +6 -6
  54. package/dist/net/uri-host-name.js.map +1 -1
  55. package/dist/net/uri.d.ts +12 -4
  56. package/dist/net/uri.d.ts.map +1 -1
  57. package/dist/net/uri.js +87 -36
  58. package/dist/net/uri.js.map +1 -1
  59. package/dist/net/url.d.ts +9 -6
  60. package/dist/net/url.d.ts.map +1 -1
  61. package/dist/net/url.js +58 -21
  62. package/dist/net/url.js.map +1 -1
  63. package/dist/object/object-diff.d.ts.map +1 -1
  64. package/dist/object/object-diff.js.map +1 -1
  65. package/dist/object/type-path.d.ts.map +1 -1
  66. package/dist/object/type-path.js +12 -14
  67. package/dist/object/type-path.js.map +1 -1
  68. package/dist/object.d.ts +2 -0
  69. package/dist/object.d.ts.map +1 -1
  70. package/dist/object.js +17 -1
  71. package/dist/object.js.map +1 -1
  72. package/dist/promise.d.ts +3 -1
  73. package/dist/promise.d.ts.map +1 -1
  74. package/dist/promise.js +9 -0
  75. package/dist/promise.js.map +1 -1
  76. package/dist/proxy.d.ts +2 -0
  77. package/dist/proxy.d.ts.map +1 -0
  78. package/dist/proxy.js +20 -0
  79. package/dist/proxy.js.map +1 -0
  80. package/dist/result.d.ts +18 -20
  81. package/dist/result.d.ts.map +1 -1
  82. package/dist/result.js +41 -61
  83. package/dist/result.js.map +1 -1
  84. package/dist/retry.d.ts.map +1 -1
  85. package/dist/retry.js +3 -3
  86. package/dist/retry.js.map +1 -1
  87. package/dist/sql/sql-expression-parser.d.ts.map +1 -1
  88. package/dist/sql/sql-expression-parser.js +5 -5
  89. package/dist/sql/sql-expression-parser.js.map +1 -1
  90. package/dist/string.d.ts +1 -0
  91. package/dist/string.d.ts.map +1 -1
  92. package/dist/string.js +4 -0
  93. package/dist/string.js.map +1 -1
  94. package/dist/temporal/duration.d.ts.map +1 -1
  95. package/dist/temporal/duration.js +2 -1
  96. package/dist/temporal/duration.js.map +1 -1
  97. package/dist/temporal/instant.d.ts.map +1 -1
  98. package/dist/temporal/instant.js +2 -1
  99. package/dist/temporal/instant.js.map +1 -1
  100. package/dist/temporal/plain-date-time.d.ts.map +1 -1
  101. package/dist/temporal/plain-date-time.js +2 -1
  102. package/dist/temporal/plain-date-time.js.map +1 -1
  103. package/dist/temporal/plain-date.d.ts.map +1 -1
  104. package/dist/temporal/plain-date.js +2 -1
  105. package/dist/temporal/plain-date.js.map +1 -1
  106. package/dist/temporal/plain-time.d.ts.map +1 -1
  107. package/dist/temporal/plain-time.js +2 -1
  108. package/dist/temporal/plain-time.js.map +1 -1
  109. package/dist/temporal/zoned-date-time.d.ts.map +1 -1
  110. package/dist/temporal/zoned-date-time.js +2 -1
  111. package/dist/temporal/zoned-date-time.js.map +1 -1
  112. package/dist/types.d.ts +23 -0
  113. package/dist/types.d.ts.map +1 -1
  114. package/dist/types.js +6 -0
  115. package/dist/types.js.map +1 -1
  116. package/dist/zod-util.d.ts +55 -6
  117. package/dist/zod-util.d.ts.map +1 -1
  118. package/dist/zod-util.js +99 -11
  119. package/dist/zod-util.js.map +1 -1
  120. package/package.json +2 -2
@@ -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 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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,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 } 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, mode: UriParseMode = UriParseMode.Strict): 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.success(empty())\n }\n\n const schemeResult = parseSchemePart(value)\n if (Results.isFailure(schemeResult)) {\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\n\n const authorityPartResult = parseAuthorityPart(rest1, mode)\n if (Results.isFailure(authorityPartResult)) {\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\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\nexport const UriParseMode = {\n // Normal href-style url parsing\n Strict: 'strict',\n // Will parse 'www.google.com' as a hostname rather than a path, but loses support for relative urls\n Permissive: 'permissive',\n} as const\nexport type UriParseMode = ValueOf<typeof UriParseMode>\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.map(parseString(it), (it) => toLiteral(it)))\n// JOHN need a schema for the object version...\n// export const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const empty = (): Uri => {\n return {\n _type: Namespace,\n href: '' as UriLiteral,\n scheme: null,\n authentication: null,\n host: null,\n location: {\n path: null,\n query: null,\n fragment: null,\n },\n }\n}\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 * Updates 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.update(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 update = (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 = {\n path: Objects.isUndefined(builder.location?.path) ? uri.location.path : builder.location?.path,\n query: Objects.isUndefined(builder.location?.query) ? uri.location.query : builder.location?.query,\n fragment: Objects.isUndefined(builder.location?.fragment) ? uri.location.fragment : builder.location?.fragment,\n }\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\nexport const merge = (...uris: Array<UriLike>): Uri => {\n if (uris.length === 0) {\n return empty()\n }\n if (uris.length === 1) {\n return from(uris[0]!)\n }\n\n return uris.reduce<Uri>((aggregate, next) => {\n const nextUri = from(next)\n\n const builder: UriBuilder = {\n scheme: nextUri.scheme ?? undefined,\n host: nextUri.host ?? undefined,\n authentication: nextUri.authentication ?? undefined,\n location: {\n path: nextUri.location.path ?? undefined,\n query: nextUri.location.query ?? undefined,\n fragment: nextUri.location.fragment ?? undefined,\n },\n }\n\n const uri = update(aggregate, builder)\n return uri\n }, from(uris[0]!))\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 (Results.isFailure(schemeResult)) {\n return schemeResult\n }\n\n return Results.success([schemeResult, 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 mode: UriParseMode\n): Result<[{ host: UriHost | null; authentication: UriAuthentication | null }, UriComponent], ErrorEvent> => {\n if (mode === UriParseMode.Strict && !initialUrl.startsWith('//')) {\n return Results.success([{ host: null, authentication: null }, initialUrl])\n }\n if (mode === UriParseMode.Permissive && initialUrl.startsWith('/')) {\n return Results.success([{ host: null, authentication: null }, initialUrl])\n }\n\n const url = Strings.removeStart(initialUrl, '//')\n\n const authenticationPartResult = parseAuthenticationPart(url)\n if (Results.isFailure(authenticationPartResult)) {\n return authenticationPartResult\n }\n const [authentication, rest1] = authenticationPartResult\n\n const hostPartResult = parseHostPart(rest1)\n if (Results.isFailure(hostPartResult)) {\n return hostPartResult\n }\n const [host, rest2] = hostPartResult\n\n return Results.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 (Results.isFailure(authenticationParseResult)) {\n return authenticationParseResult\n }\n\n return Results.success([authenticationParseResult, 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 (Results.isFailure(parseHostResult)) {\n return parseHostResult\n }\n\n return Results.success([parseHostResult, 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 (Results.isFailure(ipV6Result)) {\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 (Results.isFailure(hostNameResult)) {\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, 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 (Results.isFailure(hostNameResult)) {\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, 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\nexport const isComplete = (uri: Uri): boolean => {\n return Objects.isPresent(uri.scheme) && Objects.isPresent(uri.host)\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;AAEzB,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,IAAMA,eAAc,CAAC,OAAe,OAAqB,aAAa,WAAoC;AAE/G,MAAY,gBAAQ,KAAK,GAAG;AAC1B,WAAe,gBAAQ,MAAM,CAAC;AAAA,EAChC;AAEA,QAAM,eAAe,gBAAgB,KAAK;AAC1C,MAAY,kBAAU,YAAY,GAAG;AACnC,WAAe;AAAA,MACD,yBAAa,OAAO;AAAA,QAC9B,WAAW;AAAA,QACX,SAAS,IAAI,SAAS,wCAAwC,KAAK;AAAA,QACnE,QAAQ,aAAa,MAAM;AAAA,MAC7B,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,CAAC,QAAQ,KAAK,IAAI;AAExB,QAAM,sBAAsB,mBAAmB,OAAO,IAAI;AAC1D,MAAY,kBAAU,mBAAmB,GAAG;AAC1C,WAAe;AAAA,MACD,yBAAa,OAAO;AAAA,QAC9B,WAAW;AAAA,QACX,SAAS,IAAI,S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G;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":["parseString","from","it","hostNameResult"]}
package/dist/net/url.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Dictionary, NominalType } from '@bessemer/cornerstone/types';
2
2
  import * as Uris from '@bessemer/cornerstone/net/uri';
3
- import { Uri, UriBuilder, UriComponent, UriLiteral, UriLocation } from '@bessemer/cornerstone/net/uri';
3
+ import { Uri, UriBuilder, UriComponent, UriLiteral, UriLocation, UriParseMode } from '@bessemer/cornerstone/net/uri';
4
4
  import { Result } from '@bessemer/cornerstone/result';
5
5
  import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
6
6
  import Zod from 'zod';
@@ -10,7 +10,6 @@ export declare const encode: (uriComponent: UriComponent) => string;
10
10
  export declare const decode: (uriComponent: UriComponent) => string;
11
11
  export type UrlLiteral = NominalType<UriLiteral, typeof Namespace>;
12
12
  export interface UrlLocation extends UriLocation {
13
- relative: boolean;
14
13
  pathSegments: Array<string>;
15
14
  parameters: Dictionary<string | Array<string>>;
16
15
  }
@@ -18,6 +17,7 @@ export interface Url extends Uri {
18
17
  _type: typeof Namespace;
19
18
  location: UrlLocation;
20
19
  href: UrlLiteral;
20
+ relative: boolean;
21
21
  }
22
22
  export declare const Namespace: import("../resource-key").ResourceNamespace<"url">;
23
23
  export declare const EqualBy: Equalitor<Url>;
@@ -25,7 +25,6 @@ type UrlBuilderPathPart = MergeExclusive<{
25
25
  path?: string | null;
26
26
  }, {
27
27
  pathSegments?: Array<string>;
28
- relative?: boolean;
29
28
  }>;
30
29
  type UrlBuilderQueryPart = MergeExclusive<{
31
30
  query?: string | null;
@@ -37,9 +36,10 @@ type UrlBuilderLocationPart = UrlBuilderPathPart & UrlBuilderQueryPart & {
37
36
  };
38
37
  export type UrlBuilder = UriBuilder & {
39
38
  location?: UrlBuilderLocationPart | null | undefined;
39
+ relative?: boolean;
40
40
  };
41
- export type UrlLike = Url | Uri | UriLiteral | UrlLiteral | UrlBuilder;
42
- export declare const parseString: (value: string) => Result<Url, ErrorEvent>;
41
+ export type UrlLike = Url | Uri | UrlBuilder | UriLiteral | UrlLiteral;
42
+ export declare const parseString: (value: string, mode?: UriParseMode) => Result<Url, ErrorEvent>;
43
43
  export declare function from(value: UrlLike | string): Url;
44
44
  export declare function from(value: UrlLike | string | null): Url | null;
45
45
  export declare function from(value: UrlLike | string | undefined): Url | undefined;
@@ -49,9 +49,12 @@ export declare function toLiteral(likeValue: UrlLike | null): UrlLiteral | null;
49
49
  export declare function toLiteral(likeValue: UrlLike | undefined): UrlLiteral | undefined;
50
50
  export declare function toLiteral(likeValue: UrlLike | null | undefined): UrlLiteral | null | undefined;
51
51
  export declare const SchemaLiteral: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<UrlLiteral, string>>;
52
+ export declare const empty: () => Url;
52
53
  export declare const isUrl: (value: unknown) => value is Url;
53
- export declare const merge: (element: UrlLike, builder: UrlBuilder) => Url;
54
+ export declare const update: (element: UrlLike, builder: UrlBuilder) => Url;
55
+ export declare const navigate: (base: UrlLike, next: UrlLike) => Url;
54
56
  export declare const format: (uriLike: Uris.UriLike, excludedUriComponents?: Array<Uris.UriComponentType>) => UriLiteral;
57
+ export declare const isComplete: (uri: Uri) => boolean;
55
58
  export declare const getParameter: (url: UrlLike, name: string) => string | undefined;
56
59
  export declare const getJsonParameter: <T>(url: UrlLike, name: string) => T | undefined;
57
60
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/net/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,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,EAAE,MAAM,MAAM,KAAG,MAAM,GAAG,SAWlE,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,KAAG,CAAC,GAAG,SAGpE,CAAA"}
package/dist/net/url.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/net/url.ts
2
2
  import * as Uris from "@bessemer/cornerstone/net/uri";
3
- import { success } from "@bessemer/cornerstone/result";
3
+ import { UriParseMode } from "@bessemer/cornerstone/net/uri";
4
+ import * as Results from "@bessemer/cornerstone/result";
4
5
  import { unpackResult } from "@bessemer/cornerstone/error/error-event";
5
6
  import * as Strings from "@bessemer/cornerstone/string";
6
7
  import * as Arrays from "@bessemer/cornerstone/array";
@@ -13,12 +14,8 @@ var encode2 = Uris.encode;
13
14
  var decode2 = Uris.decode;
14
15
  var Namespace = Uris.UrlNamespace;
15
16
  var EqualBy = Equalitors.deepNatural();
16
- var parseString2 = (value) => {
17
- const result = Uris.parseString(value);
18
- if (!result.isSuccess) {
19
- return result;
20
- }
21
- return success(fromUri(result.value));
17
+ var parseString2 = (value, mode = UriParseMode.Strict) => {
18
+ return Results.map(Uris.parseString(value, mode), (it) => Results.success(fromUri(it)));
22
19
  };
23
20
  function from2(value) {
24
21
  if (Objects.isNil(value)) {
@@ -42,7 +39,21 @@ function toLiteral(likeValue) {
42
39
  const value = from2(likeValue);
43
40
  return format2(value);
44
41
  }
45
- var SchemaLiteral = structuredTransform(Zod.string(), (it) => parseString2(it).map((it2) => toLiteral(it2)));
42
+ var SchemaLiteral = structuredTransform(Zod.string(), (it) => Results.map(parseString2(it), (it2) => toLiteral(it2)));
43
+ var empty2 = () => {
44
+ const result = Uris.empty();
45
+ return {
46
+ ...result,
47
+ _type: Namespace,
48
+ href: result.href,
49
+ location: {
50
+ ...result.location,
51
+ pathSegments: [],
52
+ parameters: {}
53
+ },
54
+ relative: true
55
+ };
56
+ };
46
57
  var isUrl = (value) => {
47
58
  if (!Objects.isObject(value)) {
48
59
  return false;
@@ -50,8 +61,9 @@ var isUrl = (value) => {
50
61
  const uriValue = value;
51
62
  return uriValue._type === Namespace;
52
63
  };
53
- var merge = (element, builder) => {
64
+ var update = (element, builder) => {
54
65
  const url = from2(element);
66
+ const buildRelative = builder.relative === true;
55
67
  let location;
56
68
  if (Strings.isString(builder.location) || Objects.isNull(builder.location)) {
57
69
  location = builder.location;
@@ -65,16 +77,35 @@ var merge = (element, builder) => {
65
77
  };
66
78
  }
67
79
  const uriBuilder = {
68
- scheme: Objects.isUndefined(builder.scheme) ? url.scheme : builder.scheme,
69
- host: Objects.isUndefined(builder.host) ? url.host : builder.host,
70
- authentication: Objects.isUndefined(builder.authentication) ? url.authentication : builder.authentication,
71
- location
80
+ scheme: Objects.isUndefined(builder.scheme) && !buildRelative ? url.scheme : builder.scheme,
81
+ host: Objects.isUndefined(builder.host) && !buildRelative ? url.host : builder.host,
82
+ authentication: Objects.isUndefined(builder.authentication) && !buildRelative ? url.authentication : builder.authentication,
83
+ location,
84
+ relative: buildRelative
72
85
  };
73
86
  return from2(uriBuilder);
74
87
  };
88
+ var navigate = (base, next) => {
89
+ const baseUrl = from2(base);
90
+ const nextUrl = from2(next);
91
+ const isOnlyFragment = nextUrl.relative && Objects.isNil(nextUrl.location.path) && Objects.isNil(nextUrl.location.query);
92
+ const builder = {
93
+ scheme: nextUrl.scheme ?? void 0,
94
+ host: nextUrl.host ?? void 0,
95
+ authentication: Objects.isPresent(nextUrl.host) ? nextUrl.authentication : void 0,
96
+ location: {
97
+ pathSegments: nextUrl.relative ? [...baseUrl.location.pathSegments, ...nextUrl.location.pathSegments] : nextUrl.location.pathSegments,
98
+ query: isOnlyFragment ? void 0 : nextUrl.location.query,
99
+ fragment: nextUrl.location.fragment
100
+ }
101
+ };
102
+ const uri = update(baseUrl, builder);
103
+ return uri;
104
+ };
75
105
  var format2 = Uris.format;
106
+ var isComplete2 = Uris.isComplete;
76
107
  var build = (builder) => {
77
- if ((builder.location?.relative ?? false) && Objects.isPresent(builder.host)) {
108
+ if ((builder.relative ?? false) && Objects.isPresent(builder.host)) {
78
109
  throw new Error(`[${Namespace}]: Unable to construct a relative url with a non-null host: ${builder}`);
79
110
  }
80
111
  const uriBuilder = convertUrlBuilderToUriBuilder(builder);
@@ -86,13 +117,16 @@ var convertUrlBuilderToUriBuilder = (builder) => {
86
117
  if (Objects.isNil(builder.host)) {
87
118
  return {
88
119
  ...builder,
89
- location: { path: "/" }
120
+ location: { path: builder.relative === true ? "" : "/" }
90
121
  };
91
122
  }
92
123
  return builder;
93
124
  }
94
- const relative = builder.location.relative ?? false;
95
- let path = builder.location.path;
125
+ if (Strings.isString(builder.location)) {
126
+ return builder;
127
+ }
128
+ const relative = builder.relative ?? false;
129
+ let path = relative ? Strings.removeStart(builder.location.path ?? "", "/") : builder.location.path;
96
130
  if (Objects.isPresent(builder.location.pathSegments)) {
97
131
  path = formatPathSegments(builder.location.pathSegments, Objects.isPresent(builder.host), relative);
98
132
  }
@@ -145,13 +179,13 @@ var fromUri = (uri) => {
145
179
  _type: Namespace,
146
180
  location: {
147
181
  path: formatPathSegments(pathSegments, Objects.isPresent(uri.host), relative),
148
- relative,
149
182
  pathSegments,
150
183
  query: formatQueryParameters(parameters),
151
184
  parameters,
152
185
  fragment: uri.location.fragment
153
186
  },
154
- href: uri.href
187
+ href: uri.href,
188
+ relative
155
189
  };
156
190
  url.href = format2(url);
157
191
  return url;
@@ -198,14 +232,17 @@ export {
198
232
  Namespace,
199
233
  SchemaLiteral,
200
234
  decode2 as decode,
235
+ empty2 as empty,
201
236
  encode2 as encode,
202
237
  format2 as format,
203
238
  from2 as from,
204
239
  getJsonParameter,
205
240
  getParameter,
241
+ isComplete2 as isComplete,
206
242
  isUrl,
207
- merge,
243
+ navigate,
208
244
  parseString2 as parseString,
209
- toLiteral
245
+ toLiteral,
246
+ update
210
247
  };
211
248
  //# sourceMappingURL=url.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/net/url.ts"],"sourcesContent":["import { Dictionary, NominalType } from '@bessemer/cornerstone/types'\nimport * as Uris from '@bessemer/cornerstone/net/uri'\nimport { Uri, UriBuilder, UriComponent, UriLiteral, UriLocation } from '@bessemer/cornerstone/net/uri'\nimport { Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport { first, isEmpty } from '@bessemer/cornerstone/array'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\nimport { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport { MergeExclusive } from 'type-fest'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport const encode = Uris.encode\n\nexport const decode = Uris.decode\n\nexport type UrlLiteral = NominalType<UriLiteral, typeof Namespace>\n\nexport interface UrlLocation extends UriLocation {\n relative: boolean\n pathSegments: Array<string>\n parameters: Dictionary<string | Array<string>>\n}\n\nexport interface Url extends Uri {\n _type: typeof Namespace\n location: UrlLocation\n href: UrlLiteral\n}\n\nexport const Namespace = Uris.UrlNamespace\nexport const EqualBy: Equalitor<Url> = Equalitors.deepNatural()\n\ntype UrlBuilderPathPart = MergeExclusive<{ path?: string | null }, { pathSegments?: Array<string>; relative?: boolean }>\ntype UrlBuilderQueryPart = MergeExclusive<{ query?: string | null }, { parameters?: Dictionary<string | Array<string>> }>\ntype UrlBuilderLocationPart = UrlBuilderPathPart &\n UrlBuilderQueryPart & {\n fragment?: string | null\n }\n\nexport type UrlBuilder = UriBuilder & {\n location?: UrlBuilderLocationPart | null | undefined\n}\n\nexport type UrlLike = Url | Uri | UriLiteral | UrlLiteral | UrlBuilder\n\nexport const parseString = (value: string): Result<Url, ErrorEvent> => {\n const result = Uris.parseString(value)\n if (!result.isSuccess) {\n return result\n }\n\n return success(fromUri(result.value))\n}\n\nexport function from(value: UrlLike | string): Url\nexport function from(value: UrlLike | string | null): Url | null\nexport function from(value: UrlLike | string | undefined): Url | undefined\nexport function from(value: UrlLike | string | null | undefined): Url | null | undefined\nexport function from(value: UrlLike | string | null | undefined): Url | null | undefined {\n if (Objects.isNil(value)) {\n return value\n }\n if (isUrl(value)) {\n return value\n }\n if (Uris.isUri(value)) {\n return fromUri(value)\n }\n if (Strings.isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return build(value as UrlBuilder)\n}\n\nexport function toLiteral(likeValue: UrlLike): UrlLiteral\nexport function toLiteral(likeValue: UrlLike | null): UrlLiteral | null\nexport function toLiteral(likeValue: UrlLike | undefined): UrlLiteral | undefined\nexport function toLiteral(likeValue: UrlLike | null | undefined): UrlLiteral | null | undefined\nexport function toLiteral(likeValue: UrlLike | null | undefined): UrlLiteral | null | undefined {\n if (Objects.isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return format(value) as UrlLiteral\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\nexport const isUrl = (value: unknown): value is Url => {\n if (!Objects.isObject(value)) {\n return false\n }\n\n const uriValue = value as any as Url\n return uriValue._type === Namespace\n}\n\nexport const merge = (element: UrlLike, builder: UrlBuilder): Url => {\n const url = from(element)\n\n let location: UrlBuilderLocationPart | null | undefined\n if (Strings.isString(builder.location) || Objects.isNull(builder.location)) {\n location = builder.location\n } else {\n const usePathSegments = !Objects.isUndefined(builder.location?.pathSegments)\n const useParameters = !Objects.isUndefined(builder.location?.parameters)\n\n location = {\n ...(usePathSegments\n ? { pathSegments: builder.location?.pathSegments }\n : { path: Objects.isUndefined(builder.location?.path) ? url.location.path : builder.location.path }),\n ...(useParameters\n ? { parameters: builder.location?.parameters }\n : { query: Objects.isUndefined(builder.location?.query) ? url.location.query : builder.location.query }),\n fragment: Objects.isUndefined(builder.location?.fragment) ? url.location.fragment : builder.location.fragment,\n }\n }\n\n const uriBuilder: UriBuilder = {\n scheme: Objects.isUndefined(builder.scheme) ? url.scheme : builder.scheme,\n host: Objects.isUndefined(builder.host) ? url.host : builder.host,\n authentication: Objects.isUndefined(builder.authentication) ? url.authentication : builder.authentication,\n location,\n }\n\n return from(uriBuilder)\n}\n\nexport const format = Uris.format\n\nconst build = (builder: UrlBuilder): Url => {\n if ((builder.location?.relative ?? false) && Objects.isPresent(builder.host)) {\n throw new Error(`[${Namespace}]: Unable to construct a relative url with a non-null host: ${builder}`)\n }\n\n const uriBuilder = convertUrlBuilderToUriBuilder(builder)\n const uri = Uris.from(uriBuilder)\n return fromUri(uri)\n}\n\nconst convertUrlBuilderToUriBuilder = (builder: UrlBuilder): UriBuilder => {\n if (Objects.isNil(builder.location)) {\n if (Objects.isNil(builder.host)) {\n return {\n ...builder,\n location: { path: '/' },\n }\n }\n\n return builder\n }\n\n const relative = builder.location.relative ?? false\n\n let path = builder.location.path\n if (Objects.isPresent(builder.location.pathSegments)) {\n path = formatPathSegments(builder.location.pathSegments, Objects.isPresent(builder.host), relative)\n }\n\n let query = builder.location.query\n if (Objects.isPresent(builder.location.parameters)) {\n query = formatQueryParameters(builder.location.parameters)\n }\n\n return {\n ...builder,\n location: { path, query, fragment: builder.location.fragment },\n }\n}\n\nconst fromUri = (uri: Uri): Url => {\n let relative: boolean = false\n let pathSegments: Array<string> = []\n const parameters: Dictionary<string | Array<string>> = {}\n\n if (Objects.isPresent(uri.location.path)) {\n if (!uri.location.path.startsWith('/')) {\n relative = true\n }\n\n pathSegments = Strings.removeStart(uri.location.path, '/')\n .split('/')\n .filter((it) => !Strings.isBlank(it))\n .map((urlPathPart) => decode(urlPathPart))\n } else {\n if (Objects.isNil(uri.host)) {\n relative = true\n }\n }\n\n if (Objects.isPresent(uri.location.query)) {\n uri.location.query.split('&').forEach((parameterPair) => {\n let splitParameters = parameterPair.split('=')\n\n if (!Strings.isBlank(first(splitParameters))) {\n let key = decode(splitParameters[0]!)\n let value = ''\n if (splitParameters.length === 2) {\n value = splitParameters[1]!\n }\n if (Objects.isNil(parameters[key])) {\n parameters[key] = decode(value)\n } else if (!Array.isArray(parameters[key])) {\n let paramList = [parameters[key]]\n paramList.push(decode(value))\n parameters[key] = paramList\n } else {\n parameters[key].push(decode(value))\n }\n }\n })\n }\n\n const url: Url = {\n ...uri,\n _type: Namespace,\n location: {\n path: formatPathSegments(pathSegments, Objects.isPresent(uri.host), relative),\n relative,\n pathSegments,\n query: formatQueryParameters(parameters),\n parameters,\n fragment: uri.location.fragment,\n },\n href: uri.href as UrlLiteral,\n }\n\n url.href = format(url) as UrlLiteral\n return url\n}\n\nconst formatPathSegments = (pathSegments: Array<string>, hasHost: boolean, relative: boolean): UriComponent | null => {\n if (Arrays.isEmpty(pathSegments)) {\n if (!hasHost && !relative) {\n return '/'\n } else {\n return null\n }\n }\n\n return (relative ? '' : '/') + pathSegments.map((it) => encode(it)).join('/')\n}\n\nconst formatQueryParameters = (parameters: Dictionary<string | Array<string>>): UriComponent | null => {\n const parameterEntries = Object.entries(parameters)\n if (isEmpty(parameterEntries)) {\n return null\n }\n\n return Object.entries(parameters)\n .flatMap(([key, value]) => {\n if (Array.isArray(value)) {\n return value.map((it) => `${encode(key)}=${encode(it)}`)\n } else {\n return [`${encode(key)}=${encode(value)}`]\n }\n })\n .join('&')\n}\n\n// JOHN I don't know about these two methods...\nexport const getParameter = (url: UrlLike, name: string): string | undefined => {\n const parameter = from(url).location.parameters[name]\n if (Objects.isNil(parameter)) {\n return undefined\n }\n\n if (Array.isArray(parameter)) {\n throw new Error(`Expected a single parameter value but found multiple for parameter: ${name}`)\n }\n\n return parameter\n}\n\nexport const getJsonParameter = <T>(url: UrlLike, name: string): T | undefined => {\n const value = getParameter(url, name)\n return Objects.isPresent(value) ? JSON.parse(value) : undefined\n}\n"],"mappings":";AACA,YAAY,UAAU;AAEtB,SAAiB,eAAe;AAChC,SAAqB,oBAAoB;AACzC,YAAY,aAAa;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A,EACT;AAEA,SAAO,OAAO,QAAQ,UAAU,EAC7B,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzB,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,aAAO,MAAM,IAAI,CAAC,OAAO,GAAGC,QAAO,GAAG,CAAC,IAAIA,QAAO,EAAE,CAAC,EAAE;AAAA,IACzD,OAAO;AACL,aAAO,CAAC,GAAGA,QAAO,GAAG,CAAC,IAAIA,QAAO,KAAK,CAAC,EAAE;AAAA,IAC3C;AAAA,EACF,CAAC,EACA,KAAK,GAAG;AACb;AAGO,IAAM,eAAe,CAAC,KAAc,SAAqC;AAC9E,QAAM,YAAYG,MAAK,GAAG,EAAE,SAAS,WAAW,IAAI;AACpD,MAAY,cAAM,SAAS,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,SAAS,GAAG;AAC5B,UAAM,IAAI,MAAM,uEAAuE,IAAI,EAAE;AAAA,EAC/F;AAEA,SAAO;AACT;AAEO,IAAM,mBAAmB,CAAI,KAAc,SAAgC;AAChF,QAAM,QAAQ,aAAa,KAAK,IAAI;AACpC,SAAe,kBAAU,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI;AACxD;","names":["isEmpty","encode","decode","parseString","from","format","it"]}
1
+ {"version":3,"sources":["../../src/net/url.ts"],"sourcesContent":["import { Dictionary, NominalType } from '@bessemer/cornerstone/types'\nimport * as Uris from '@bessemer/cornerstone/net/uri'\nimport { Uri, UriBuilder, UriComponent, UriLiteral, UriLocation, UriParseMode } from '@bessemer/cornerstone/net/uri'\nimport * as Results from '@bessemer/cornerstone/result'\nimport { Result } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport * as Strings from '@bessemer/cornerstone/string'\nimport * as Arrays from '@bessemer/cornerstone/array'\nimport { first, isEmpty } from '@bessemer/cornerstone/array'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport * as Equalitors from '@bessemer/cornerstone/equalitor'\nimport { Equalitor } from '@bessemer/cornerstone/equalitor'\nimport { MergeExclusive } from 'type-fest'\nimport * as Objects from '@bessemer/cornerstone/object'\n\nexport const encode = Uris.encode\n\nexport const decode = Uris.decode\n\nexport type UrlLiteral = NominalType<UriLiteral, typeof Namespace>\n\nexport interface UrlLocation extends UriLocation {\n pathSegments: Array<string>\n parameters: Dictionary<string | Array<string>>\n}\n\nexport interface Url extends Uri {\n _type: typeof Namespace\n location: UrlLocation\n href: UrlLiteral\n relative: boolean\n}\n\nexport const Namespace = Uris.UrlNamespace\nexport const EqualBy: Equalitor<Url> = Equalitors.deepNatural()\n\ntype UrlBuilderPathPart = MergeExclusive<{ path?: string | null }, { pathSegments?: Array<string> }>\ntype UrlBuilderQueryPart = MergeExclusive<{ query?: string | null }, { parameters?: Dictionary<string | Array<string>> }>\ntype UrlBuilderLocationPart = UrlBuilderPathPart &\n UrlBuilderQueryPart & {\n fragment?: string | null\n }\n\nexport type UrlBuilder = UriBuilder & {\n location?: UrlBuilderLocationPart | null | undefined\n relative?: boolean\n}\n\nexport type UrlLike = Url | Uri | UrlBuilder | UriLiteral | UrlLiteral\n\nexport const parseString = (value: string, mode: UriParseMode = UriParseMode.Strict): Result<Url, ErrorEvent> => {\n return Results.map(Uris.parseString(value, mode), (it) => Results.success(fromUri(it)))\n}\n\nexport function from(value: UrlLike | string): Url\nexport function from(value: UrlLike | string | null): Url | null\nexport function from(value: UrlLike | string | undefined): Url | undefined\nexport function from(value: UrlLike | string | null | undefined): Url | null | undefined\nexport function from(value: UrlLike | string | null | undefined): Url | null | undefined {\n if (Objects.isNil(value)) {\n return value\n }\n if (isUrl(value)) {\n return value\n }\n if (Uris.isUri(value)) {\n return fromUri(value)\n }\n if (Strings.isString(value)) {\n return unpackResult(parseString(value))\n }\n\n return build(value as UrlBuilder)\n}\n\nexport function toLiteral(likeValue: UrlLike): UrlLiteral\nexport function toLiteral(likeValue: UrlLike | null): UrlLiteral | null\nexport function toLiteral(likeValue: UrlLike | undefined): UrlLiteral | undefined\nexport function toLiteral(likeValue: UrlLike | null | undefined): UrlLiteral | null | undefined\nexport function toLiteral(likeValue: UrlLike | null | undefined): UrlLiteral | null | undefined {\n if (Objects.isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return format(value) as UrlLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => Results.map(parseString(it), (it) => toLiteral(it)))\n// JOHN need a schema for the object version...\n// export const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const empty = (): Url => {\n const result = Uris.empty()\n\n return {\n ...result,\n _type: Namespace,\n href: result.href as UrlLiteral,\n location: {\n ...result.location,\n pathSegments: [],\n parameters: {},\n },\n relative: true,\n }\n}\n\nexport const isUrl = (value: unknown): value is Url => {\n if (!Objects.isObject(value)) {\n return false\n }\n\n const uriValue = value as any as Url\n return uriValue._type === Namespace\n}\n\nexport const update = (element: UrlLike, builder: UrlBuilder): Url => {\n const url = from(element)\n\n const buildRelative = builder.relative === true\n\n let location: UrlBuilderLocationPart | null | undefined\n if (Strings.isString(builder.location) || Objects.isNull(builder.location)) {\n location = builder.location\n } else {\n const usePathSegments = !Objects.isUndefined(builder.location?.pathSegments)\n const useParameters = !Objects.isUndefined(builder.location?.parameters)\n\n location = {\n ...(usePathSegments\n ? { pathSegments: builder.location?.pathSegments }\n : { path: Objects.isUndefined(builder.location?.path) ? url.location.path : builder.location.path }),\n ...(useParameters\n ? { parameters: builder.location?.parameters }\n : { query: Objects.isUndefined(builder.location?.query) ? url.location.query : builder.location.query }),\n fragment: Objects.isUndefined(builder.location?.fragment) ? url.location.fragment : builder.location.fragment,\n }\n }\n\n const uriBuilder: UrlBuilder = {\n scheme: Objects.isUndefined(builder.scheme) && !buildRelative ? url.scheme : builder.scheme,\n host: Objects.isUndefined(builder.host) && !buildRelative ? url.host : builder.host,\n authentication: Objects.isUndefined(builder.authentication) && !buildRelative ? url.authentication : builder.authentication,\n location,\n relative: buildRelative,\n }\n\n return from(uriBuilder)\n}\n\nexport const navigate = (base: UrlLike, next: UrlLike): Url => {\n const baseUrl = from(base)\n const nextUrl = from(next)\n\n const isOnlyFragment = nextUrl.relative && Objects.isNil(nextUrl.location.path) && Objects.isNil(nextUrl.location.query)\n\n const builder: UrlBuilder = {\n scheme: nextUrl.scheme ?? undefined,\n host: nextUrl.host ?? undefined,\n authentication: Objects.isPresent(nextUrl.host) ? nextUrl.authentication : undefined,\n location: {\n pathSegments: nextUrl.relative ? [...baseUrl.location.pathSegments, ...nextUrl.location.pathSegments] : nextUrl.location.pathSegments,\n query: isOnlyFragment ? undefined : nextUrl.location.query,\n fragment: nextUrl.location.fragment,\n },\n }\n\n const uri = update(baseUrl, builder)\n return uri\n}\n\nexport const format = Uris.format\nexport const isComplete = Uris.isComplete\n\nconst build = (builder: UrlBuilder): Url => {\n if ((builder.relative ?? false) && Objects.isPresent(builder.host)) {\n throw new Error(`[${Namespace}]: Unable to construct a relative url with a non-null host: ${builder}`)\n }\n\n const uriBuilder = convertUrlBuilderToUriBuilder(builder)\n const uri = Uris.from(uriBuilder)\n return fromUri(uri)\n}\n\nconst convertUrlBuilderToUriBuilder = (builder: UrlBuilder): UriBuilder => {\n if (Objects.isNil(builder.location)) {\n if (Objects.isNil(builder.host)) {\n return {\n ...builder,\n location: { path: builder.relative === true ? '' : '/' },\n }\n }\n\n return builder\n }\n\n if (Strings.isString(builder.location)) {\n return builder\n }\n\n const relative = builder.relative ?? false\n let path = relative ? Strings.removeStart(builder.location.path ?? '', '/') : builder.location.path\n if (Objects.isPresent(builder.location.pathSegments)) {\n path = formatPathSegments(builder.location.pathSegments, Objects.isPresent(builder.host), relative)\n }\n\n let query = builder.location.query\n if (Objects.isPresent(builder.location.parameters)) {\n query = formatQueryParameters(builder.location.parameters)\n }\n\n return {\n ...builder,\n location: { path, query, fragment: builder.location.fragment },\n }\n}\n\nconst fromUri = (uri: Uri): Url => {\n let relative: boolean = false\n let pathSegments: Array<string> = []\n const parameters: Dictionary<string | Array<string>> = {}\n\n if (Objects.isPresent(uri.location.path)) {\n if (!uri.location.path.startsWith('/')) {\n relative = true\n }\n\n pathSegments = Strings.removeStart(uri.location.path, '/')\n .split('/')\n .filter((it) => !Strings.isBlank(it))\n .map((urlPathPart) => decode(urlPathPart))\n } else {\n if (Objects.isNil(uri.host)) {\n relative = true\n }\n }\n\n if (Objects.isPresent(uri.location.query)) {\n uri.location.query.split('&').forEach((parameterPair) => {\n let splitParameters = parameterPair.split('=')\n\n if (!Strings.isBlank(first(splitParameters))) {\n let key = decode(splitParameters[0]!)\n let value = ''\n if (splitParameters.length === 2) {\n value = splitParameters[1]!\n }\n if (Objects.isNil(parameters[key])) {\n parameters[key] = decode(value)\n } else if (!Array.isArray(parameters[key])) {\n let paramList = [parameters[key]]\n paramList.push(decode(value))\n parameters[key] = paramList\n } else {\n parameters[key].push(decode(value))\n }\n }\n })\n }\n\n const url: Url = {\n ...uri,\n _type: Namespace,\n location: {\n path: formatPathSegments(pathSegments, Objects.isPresent(uri.host), relative),\n pathSegments,\n query: formatQueryParameters(parameters),\n parameters,\n fragment: uri.location.fragment,\n },\n href: uri.href as UrlLiteral,\n relative,\n }\n\n url.href = format(url) as UrlLiteral\n return url\n}\n\nconst formatPathSegments = (pathSegments: Array<string>, hasHost: boolean, relative: boolean): UriComponent | null => {\n if (Arrays.isEmpty(pathSegments)) {\n if (!hasHost && !relative) {\n return '/'\n } else {\n return null\n }\n }\n\n return (relative ? '' : '/') + pathSegments.map((it) => encode(it)).join('/')\n}\n\nconst formatQueryParameters = (parameters: Dictionary<string | Array<string>>): UriComponent | null => {\n const parameterEntries = Object.entries(parameters)\n if (isEmpty(parameterEntries)) {\n return null\n }\n\n return Object.entries(parameters)\n .flatMap(([key, value]) => {\n if (Array.isArray(value)) {\n return value.map((it) => `${encode(key)}=${encode(it)}`)\n } else {\n return [`${encode(key)}=${encode(value)}`]\n }\n })\n .join('&')\n}\n\n// JOHN I don't know about these two methods...\nexport const getParameter = (url: UrlLike, name: string): string | undefined => {\n const parameter = from(url).location.parameters[name]\n if (Objects.isNil(parameter)) {\n return undefined\n }\n\n if (Array.isArray(parameter)) {\n throw new Error(`Expected a single parameter value but found multiple for parameter: ${name}`)\n }\n\n return parameter\n}\n\nexport const getJsonParameter = <T>(url: UrlLike, name: string): T | undefined => {\n const value = getParameter(url, name)\n return Objects.isPresent(value) ? JSON.parse(value) : undefined\n}\n"],"mappings":";AACA,YAAY,UAAU;AACtB,SAAiE,oBAAoB;AACrF,YAAY,aAAa;AAEzB,SAAqB,oBAAoB;AACzC,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,SAAS,OAAO,WAAAA,gBAAe;AAC/B,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,YAAY,gBAAgB;AAG5B,YAAY,aAAa;AAElB,IAAMC,UAAc;AAEpB,IAAMC,UAAc;AAgBpB,IAAM,YAAiB;AACvB,IAAM,UAAqC,uBAAY;AAgBvD,IAAMC,eAAc,CAAC,OAAe,OAAqB,aAAa,WAAoC;AAC/G,SAAe,YAAS,iBAAY,OAAO,IAAI,GAAG,CAAC,OAAe,gBAAQ,QAAQ,EAAE,CAAC,CAAC;AACxF;AAMO,SAASC,MAAK,OAAoE;AACvF,MAAY,cAAM,KAAK,GAAG;AACxB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AACA,MAAS,WAAM,KAAK,GAAG;AACrB,WAAO,QAAQ,KAAK;AAAA,EACtB;AACA,MAAY,iBAAS,KAAK,GAAG;AAC3B,WAAO,aAAaD,aAAY,KAAK,CAAC;AAAA,EACxC;AAEA,SAAO,MAAM,KAAmB;AAClC;AAMO,SAAS,UAAU,WAAsE;AAC9F,MAAY,cAAM,SAAS,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,QAAQC,MAAK,SAAS;AAC5B,SAAOC,QAAO,KAAK;AACrB;AAEO,IAAM,gBAAgB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O;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAEA,UAAQ,WAAW,KAAK,OAAO,aAAa,IAAI,CAAC,OAAOJ,QAAO,EAAE,CAAC,EAAE,KAAK,GAAG;AAC9E;AAEA,IAAM,wBAAwB,CAAC,eAAwE;AACrG,QAAM,mBAAmB,OAAO,QAAQ,UAAU;AAClD,MAAID,SAAQ,gBAAgB,GAAG;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,QAAQ,UAAU,EAC7B,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzB,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,aAAO,MAAM,IAAI,CAAC,OAAO,GAAGC,QAAO,GAAG,CAAC,IAAIA,QAAO,EAAE,CAAC,EAAE;AAAA,IACzD,OAAO;AACL,aAAO,CAAC,GAAGA,QAAO,GAAG,CAAC,IAAIA,QAAO,KAAK,CAAC,EAAE;AAAA,IAC3C;AAAA,EACF,CAAC,EACA,KAAK,GAAG;AACb;AAGO,IAAM,eAAe,CAAC,KAAc,SAAqC;AAC9E,QAAM,YAAYG,MAAK,GAAG,EAAE,SAAS,WAAW,IAAI;AACpD,MAAY,cAAM,SAAS,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,SAAS,GAAG;AAC5B,UAAM,IAAI,MAAM,uEAAuE,IAAI,EAAE;AAAA,EAC/F;AAEA,SAAO;AACT;AAEO,IAAM,mBAAmB,CAAI,KAAc,SAAgC;AAChF,QAAM,QAAQ,aAAa,KAAK,IAAI;AACpC,SAAe,kBAAU,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI;AACxD;","names":["isEmpty","encode","decode","parseString","from","format","it","empty","isComplete"]}
@@ -1 +1 @@
1
- {"version":3,"file":"object-diff.d.ts","sourceRoot":"","sources":["../../src/object/object-diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,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AC,CAAC,KAC/B,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAEvB,CAAA;AAEH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,YAAY,SAAS,YAAY,EAC9D,MAAM,eAAe,CAAC,CAAC,CAAC,EACxB,MAAM,QAAQ,CAAC,YAAY,CAAC,KAC3B,IAAI,IAAI,eAAe,CAAC,CAAC,EAAE,YAAY,CAEzC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/object-diff.ts"],"sourcesContent":["import { ObjectPath } from '@bessemer/cornerstone/object/object-path'\nimport { ConstrainTypePath, ObjectPathType, TypePathGet, TypePathType } from '@bessemer/cornerstone/object/type-path-type'\nimport { matches as typePathMatches, TypePath } from '@bessemer/cornerstone/object/type-path'\n\nexport enum ObjectDiffType {\n Add = 'Add',\n Remove = 'Remove',\n Update = 'Update',\n Move = 'Move',\n}\n\nexport type AddObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Add\n path: ObjectPath<T>\n value: TypePathGet<T, N>\n}\n\nexport type RemoveObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Remove\n path: ObjectPath<T>\n originalValue: TypePathGet<T, N>\n}\n\nexport type UpdateObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Update\n path: ObjectPath<T>\n value: TypePathGet<T, N>\n originalValue: TypePathGet<T, N>\n}\n\nexport type MoveObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Move\n path: ObjectPath<T>\n value: TypePathGet<T, N>\n position: number\n originalPosition: number\n}\n\nexport type ObjectDiffEntry<N, T extends TypePathType = TypePathType> =\n | AddObjectDiff<N, T>\n | RemoveObjectDiff<N, T>\n | UpdateObjectDiff<N, T>\n | MoveObjectDiff<N, T>\n\nexport type ObjectDiff<N> = Array<ObjectDiffEntry<N>>\n\nexport const add =\n <N>() =>\n <T extends ObjectPathType>(path: ObjectPath<ConstrainTypePath<T, N>>, value: TypePathGet<T, N>): AddObjectDiff<N, T> => {\n return { type: ObjectDiffType.Add, path, value }\n }\n\nexport const remove =\n <N>() =>\n <T extends ObjectPathType>(path: ObjectPath<ConstrainTypePath<T, N>>, originalValue: TypePathGet<T, N>): RemoveObjectDiff<N, T> => {\n return { type: ObjectDiffType.Remove, path, originalValue }\n }\n\nexport const update =\n <N>() =>\n <T extends ObjectPathType>(\n path: ObjectPath<ConstrainTypePath<T, N>>,\n value: TypePathGet<T, N>,\n originalValue: TypePathGet<T, N>\n ): UpdateObjectDiff<N, T> => {\n return { type: ObjectDiffType.Update, path, value, originalValue }\n }\n\nexport const matchesPath = <N, MatchingPath extends TypePathType>(\n diff: ObjectDiffEntry<N>,\n path: TypePath<MatchingPath>\n): diff is ObjectDiffEntry<N, MatchingPath> => {\n return typePathMatches(diff.path, path)\n}\n"],"mappings":";AAEA,SAAS,WAAW,uBAAiC;AAE9C,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,YAAS;AACT,EAAAA,gBAAA,YAAS;AACT,EAAAA,gBAAA,UAAO;AAJG,SAAAA;AAAA,GAAA;AA0CL,IAAM,MACX,MACA,CAA2B,MAA2C,UAAkD;AACtH,SAAO,EAAE,MAAM,iBAAoB,MAAM,MAAM;AACjD;AAEK,IAAM,SACX,MACA,CAA2B,MAA2C,kBAA6D;AACjI,SAAO,EAAE,MAAM,uBAAuB,MAAM,cAAc;AAC5D;AAEK,IAAM,SACX,MACA,CACE,MACA,OACA,kBAC2B;AAC3B,SAAO,EAAE,MAAM,uBAAuB,MAAM,OAAO,cAAc;AACnE;AAEK,IAAM,cAAc,CACzB,MACA,SAC6C;AAC7C,SAAO,gBAAgB,KAAK,MAAM,IAAI;AACxC;","names":["ObjectDiffType"]}
1
+ {"version":3,"sources":["../../src/object/object-diff.ts"],"sourcesContent":["import { ObjectPath } from '@bessemer/cornerstone/object/object-path'\nimport { ConstrainTypePath, ObjectPathType, TypePathGet, TypePathType } from '@bessemer/cornerstone/object/type-path-type'\nimport { matches as typePathMatches, TypePath } from '@bessemer/cornerstone/object/type-path'\n\n// JOHN CHECK JSON PATCH INSTEAD!!! https://jsonpatch.com/\n\nexport enum ObjectDiffType {\n Add = 'Add',\n Remove = 'Remove',\n Update = 'Update',\n Move = 'Move',\n}\n\nexport type AddObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Add\n path: ObjectPath<T>\n value: TypePathGet<T, N>\n}\n\nexport type RemoveObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Remove\n path: ObjectPath<T>\n originalValue: TypePathGet<T, N>\n}\n\nexport type UpdateObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Update\n path: ObjectPath<T>\n value: TypePathGet<T, N>\n originalValue: TypePathGet<T, N>\n}\n\nexport type MoveObjectDiff<N, T extends TypePathType> = {\n type: ObjectDiffType.Move\n path: ObjectPath<T>\n value: TypePathGet<T, N>\n position: number\n originalPosition: number\n}\n\nexport type ObjectDiffEntry<N, T extends TypePathType = TypePathType> =\n | AddObjectDiff<N, T>\n | RemoveObjectDiff<N, T>\n | UpdateObjectDiff<N, T>\n | MoveObjectDiff<N, T>\n\nexport type ObjectDiff<N> = Array<ObjectDiffEntry<N>>\n\nexport const add =\n <N>() =>\n <T extends ObjectPathType>(path: ObjectPath<ConstrainTypePath<T, N>>, value: TypePathGet<T, N>): AddObjectDiff<N, T> => {\n return { type: ObjectDiffType.Add, path, value }\n }\n\nexport const remove =\n <N>() =>\n <T extends ObjectPathType>(path: ObjectPath<ConstrainTypePath<T, N>>, originalValue: TypePathGet<T, N>): RemoveObjectDiff<N, T> => {\n return { type: ObjectDiffType.Remove, path, originalValue }\n }\n\nexport const update =\n <N>() =>\n <T extends ObjectPathType>(\n path: ObjectPath<ConstrainTypePath<T, N>>,\n value: TypePathGet<T, N>,\n originalValue: TypePathGet<T, N>\n ): UpdateObjectDiff<N, T> => {\n return { type: ObjectDiffType.Update, path, value, originalValue }\n }\n\nexport const matchesPath = <N, MatchingPath extends TypePathType>(\n diff: ObjectDiffEntry<N>,\n path: TypePath<MatchingPath>\n): diff is ObjectDiffEntry<N, MatchingPath> => {\n return typePathMatches(diff.path, path)\n}\n"],"mappings":";AAEA,SAAS,WAAW,uBAAiC;AAI9C,IAAK,iBAAL,kBAAKA,oBAAL;AACL,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,YAAS;AACT,EAAAA,gBAAA,YAAS;AACT,EAAAA,gBAAA,UAAO;AAJG,SAAAA;AAAA,GAAA;AA0CL,IAAM,MACX,MACA,CAA2B,MAA2C,UAAkD;AACtH,SAAO,EAAE,MAAM,iBAAoB,MAAM,MAAM;AACjD;AAEK,IAAM,SACX,MACA,CAA2B,MAA2C,kBAA6D;AACjI,SAAO,EAAE,MAAM,uBAAuB,MAAM,cAAc;AAC5D;AAEK,IAAM,SACX,MACA,CACE,MACA,OACA,kBAC2B;AAC3B,SAAO,EAAE,MAAM,uBAAuB,MAAM,OAAO,cAAc;AACnE;AAEK,IAAM,cAAc,CACzB,MACA,SAC6C;AAC7C,SAAO,gBAAgB,KAAK,MAAM,IAAI;AACxC;","names":["ObjectDiffType"]}
@@ -1 +1 @@
1
- {"version":3,"file":"type-path.d.ts","sourceRoot":"","sources":["../../src/object/type-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAEL,aAAa,EAEb,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EACjB,MAAM,6CAA6C,CAAA;AAIpD,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAGvE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI,UAAU,CAAC,oBAAoB,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA;AAE/G,eAAO,MAAM,EAAE,GAAI,CAAC,S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ber } from "@bessemer/cornerstone/math";
6
6
  import { contains, containsAll, isEmpty, only } from "@bessemer/cornerstone/array";
7
- import { failure, success } from "@bessemer/cornerstone/result";
7
+ import * as Results from "@bessemer/cornerstone/result";
8
8
  var of = (value) => {
9
9
  return value;
10
10
  };
@@ -182,7 +182,7 @@ var matches = (targetPath, matchingPath) => {
182
182
  };
183
183
  var intersectAny = (targetPath, intersectingPath) => {
184
184
  if (targetPath.length < intersectingPath.length) {
185
- return failure(new Error(`TypePath: ${intersectingPath} can't intersect target TypePath: ${targetPath}`));
185
+ return Results.failure(new Error(`TypePath: ${intersectingPath} can't intersect target TypePath: ${targetPath}`));
186
186
  }
187
187
  let index = 0;
188
188
  let result = [];
@@ -190,51 +190,49 @@ var intersectAny = (targetPath, intersectingPath) => {
190
190
  const intersectingPathSelector = intersectingPath[index];
191
191
  const makeError = () => new Error(`Path mismatch when intersecting. targetPath: ${targetPathSelector} does not match intersectingPath: ${intersectingPathSelector}`);
192
192
  if (isNil(intersectingPathSelector)) {
193
- return success(of(result));
193
+ return Results.success(of(result));
194
194
  } else if (isWildcardSelector(intersectingPathSelector)) {
195
195
  result.push(targetPathSelector);
196
196
  } else if (isWildcardSelector(targetPathSelector)) {
197
- return failure(makeError());
197
+ return Results.failure(makeError());
198
198
  } else if (Array.isArray(intersectingPathSelector)) {
199
199
  if (Array.isArray(targetPathSelector)) {
200
200
  const filteredTargetPaths = targetPathSelector.filter((it) => contains(intersectingPathSelector, it));
201
201
  if (isEmpty(filteredTargetPaths)) {
202
- return failure(makeError());
202
+ return Results.failure(makeError());
203
203
  }
204
204
  result.push(filteredTargetPaths);
205
205
  } else {
206
206
  if (!contains(intersectingPathSelector, Number(targetPathSelector))) {
207
- return failure(makeError());
207
+ return Results.failure(makeError());
208
208
  }
209
209
  result.push(targetPathSelector);
210
210
  }
211
211
  } else {
212
212
  if (Array.isArray(targetPathSelector)) {
213
213
  if (targetPathSelector.length !== 1) {
214
- return failure(makeError());
214
+ return Results.failure(makeError());
215
215
  }
216
216
  const targetPathSelectorIndex = only(targetPathSelector);
217
217
  if (targetPathSelectorIndex !== Number(intersectingPathSelector)) {
218
- return failure(makeError());
218
+ return Results.failure(makeError());
219
219
  }
220
220
  result.push(targetPathSelector);
221
221
  } else {
222
222
  if (targetPathSelector !== intersectingPathSelector) {
223
- return failure(makeError());
223
+ return Results.failure(makeError());
224
224
  }
225
225
  result.push(targetPathSelector);
226
226
  }
227
227
  }
228
228
  index++;
229
229
  }
230
- return success(of(result));
230
+ return Results.success(of(result));
231
231
  };
232
232
  var intersect = (targetPath, intersectingPath) => {
233
233
  const result = intersectAny(targetPath, intersectingPath);
234
- if (!result.isSuccess) {
235
- throw result.value;
236
- }
237
- return result.value;
234
+ Results.assertSuccess(result);
235
+ return result;
238
236
  };
239
237
  export {
240
238
  Schema,