@bessemer/cornerstone 0.5.98 → 0.5.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.d.ts +62 -1
- package/dist/array.d.ts.map +1 -1
- package/dist/array.js +24 -11
- package/dist/array.js.map +1 -1
- package/dist/aspect-ratio.d.ts +1 -1
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +4 -4
- package/dist/aspect-ratio.js.map +1 -1
- package/dist/async-value.d.ts +7 -1
- package/dist/async-value.d.ts.map +1 -1
- package/dist/async-value.js +26 -1
- package/dist/async-value.js.map +1 -1
- package/dist/cache.js +1 -1
- package/dist/cache.js.map +1 -1
- package/dist/equalitor.d.ts +1 -0
- package/dist/equalitor.d.ts.map +1 -1
- package/dist/equalitor.js +3 -0
- package/dist/equalitor.js.map +1 -1
- package/dist/error/error-cause.d.ts +35 -0
- package/dist/error/error-cause.d.ts.map +1 -0
- package/dist/error/error-cause.js +97 -0
- package/dist/error/error-cause.js.map +1 -0
- package/dist/error/error-code.d.ts +17 -0
- package/dist/error/error-code.d.ts.map +1 -0
- package/dist/error/error-code.js +32 -0
- package/dist/error/error-code.js.map +1 -0
- package/dist/error/error-event.d.ts +29 -48
- package/dist/error/error-event.d.ts.map +1 -1
- package/dist/error/error-event.js +62 -151
- package/dist/error/error-event.js.map +1 -1
- package/dist/error/error-type.d.ts +1 -0
- package/dist/error/error-type.d.ts.map +1 -1
- package/dist/error/error-type.js +4 -2
- package/dist/error/error-type.js.map +1 -1
- package/dist/function.d.ts +1 -1
- package/dist/function.d.ts.map +1 -1
- package/dist/function.js +3 -2
- package/dist/function.js.map +1 -1
- package/dist/glob.d.ts +1 -1
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +4 -4
- package/dist/glob.js.map +1 -1
- package/dist/hex-code.d.ts +1 -1
- package/dist/hex-code.d.ts.map +1 -1
- package/dist/hex-code.js +4 -4
- package/dist/hex-code.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/intl/country-code.d.ts +1 -1
- package/dist/intl/country-code.d.ts.map +1 -1
- package/dist/intl/country-code.js +4 -4
- package/dist/intl/country-code.js.map +1 -1
- package/dist/intl/country-subdivision-code.d.ts +1 -1
- package/dist/intl/country-subdivision-code.d.ts.map +1 -1
- package/dist/intl/country-subdivision-code.js +4 -4
- package/dist/intl/country-subdivision-code.js.map +1 -1
- package/dist/intl/currency-code.d.ts +1 -1
- package/dist/intl/currency-code.d.ts.map +1 -1
- package/dist/intl/currency-code.js +4 -4
- package/dist/intl/currency-code.js.map +1 -1
- package/dist/intl/language-code.d.ts +1 -1
- package/dist/intl/language-code.d.ts.map +1 -1
- package/dist/intl/language-code.js +4 -4
- package/dist/intl/language-code.js.map +1 -1
- package/dist/intl/locale.d.ts +1 -1
- package/dist/intl/locale.d.ts.map +1 -1
- package/dist/intl/locale.js +6 -6
- package/dist/intl/locale.js.map +1 -1
- package/dist/mime-type.d.ts +1 -1
- package/dist/mime-type.d.ts.map +1 -1
- package/dist/mime-type.js +4 -4
- package/dist/mime-type.js.map +1 -1
- package/dist/net/domain-name.d.ts +10 -0
- package/dist/net/domain-name.d.ts.map +1 -0
- package/dist/net/domain-name.js +30 -0
- package/dist/net/domain-name.js.map +1 -0
- package/dist/net/ipv4-address.d.ts +10 -0
- package/dist/net/ipv4-address.d.ts.map +1 -0
- package/dist/net/ipv4-address.js +30 -0
- package/dist/net/ipv4-address.js.map +1 -0
- package/dist/net/ipv6-address.d.ts +10 -0
- package/dist/net/ipv6-address.d.ts.map +1 -0
- package/dist/net/ipv6-address.js +30 -0
- package/dist/net/ipv6-address.js.map +1 -0
- package/dist/net/uri-host-name.d.ts +12 -0
- package/dist/net/uri-host-name.d.ts.map +1 -0
- package/dist/net/uri-host-name.js +44 -0
- package/dist/net/uri-host-name.js.map +1 -0
- package/dist/net/uri.d.ts +249 -0
- package/dist/net/uri.d.ts.map +1 -0
- package/dist/net/uri.js +444 -0
- package/dist/net/uri.js.map +1 -0
- package/dist/net/url.d.ts +58 -0
- package/dist/net/url.d.ts.map +1 -0
- package/dist/net/url.js +211 -0
- package/dist/net/url.js.map +1 -0
- package/dist/object/object-path.d.ts +1 -1
- package/dist/object/object-path.d.ts.map +1 -1
- package/dist/object/object-path.js +4 -4
- package/dist/object/object-path.js.map +1 -1
- package/dist/object/type-path.d.ts +1 -1
- package/dist/object/type-path.d.ts.map +1 -1
- package/dist/object/type-path.js +3 -3
- package/dist/object/type-path.js.map +1 -1
- package/dist/object.d.ts +1 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +8 -6
- package/dist/object.js.map +1 -1
- package/dist/property.d.ts +2 -3
- package/dist/property.d.ts.map +1 -1
- package/dist/property.js.map +1 -1
- package/dist/resource-key.d.ts +7 -5
- package/dist/resource-key.d.ts.map +1 -1
- package/dist/resource-key.js +27 -15
- package/dist/resource-key.js.map +1 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +3 -3
- package/dist/result.js.map +1 -1
- package/dist/string.d.ts +10 -21
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +54 -25
- package/dist/string.js.map +1 -1
- package/dist/tag.d.ts +2 -2
- package/dist/tag.d.ts.map +1 -1
- package/dist/tag.js +11 -12
- package/dist/tag.js.map +1 -1
- package/dist/temporal/duration.d.ts +4 -5
- package/dist/temporal/duration.d.ts.map +1 -1
- package/dist/temporal/duration.js +3 -7
- package/dist/temporal/duration.js.map +1 -1
- package/dist/temporal/instant.d.ts +4 -5
- package/dist/temporal/instant.d.ts.map +1 -1
- package/dist/temporal/instant.js +3 -7
- package/dist/temporal/instant.js.map +1 -1
- package/dist/temporal/plain-date-time.d.ts +4 -5
- package/dist/temporal/plain-date-time.d.ts.map +1 -1
- package/dist/temporal/plain-date-time.js +3 -7
- package/dist/temporal/plain-date-time.js.map +1 -1
- package/dist/temporal/plain-date.d.ts +8 -9
- package/dist/temporal/plain-date.d.ts.map +1 -1
- package/dist/temporal/plain-date.js +3 -7
- package/dist/temporal/plain-date.js.map +1 -1
- package/dist/temporal/plain-time.d.ts +6 -7
- package/dist/temporal/plain-time.d.ts.map +1 -1
- package/dist/temporal/plain-time.js +4 -8
- package/dist/temporal/plain-time.js.map +1 -1
- package/dist/temporal/time-zone-id.d.ts +1 -1
- package/dist/temporal/time-zone-id.d.ts.map +1 -1
- package/dist/temporal/time-zone-id.js +4 -4
- package/dist/temporal/time-zone-id.js.map +1 -1
- package/dist/temporal/time-zone-offset.d.ts +1 -1
- package/dist/temporal/time-zone-offset.d.ts.map +1 -1
- package/dist/temporal/time-zone-offset.js +4 -4
- package/dist/temporal/time-zone-offset.js.map +1 -1
- package/dist/temporal/zoned-date-time.d.ts +51 -0
- package/dist/temporal/zoned-date-time.d.ts.map +1 -0
- package/dist/temporal/zoned-date-time.js +106 -0
- package/dist/temporal/zoned-date-time.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/{ulid.d.ts → uuid/ulid.d.ts} +2 -2
- package/dist/uuid/ulid.d.ts.map +1 -0
- package/dist/uuid/ulid.js +29 -0
- package/dist/uuid/ulid.js.map +1 -0
- package/dist/uuid/uuid-v4.d.ts +11 -0
- package/dist/uuid/uuid-v4.d.ts.map +1 -0
- package/dist/{uuid.js → uuid/uuid-v4.js} +11 -11
- package/dist/uuid/uuid-v4.js.map +1 -0
- package/dist/uuid/uuid-v7.d.ts +18 -0
- package/dist/uuid/uuid-v7.d.ts.map +1 -0
- package/dist/uuid/uuid-v7.js +44 -0
- package/dist/uuid/uuid-v7.js.map +1 -0
- package/package.json +1 -1
- package/dist/ulid.d.ts.map +0 -1
- package/dist/ulid.js +0 -29
- package/dist/ulid.js.map +0 -1
- package/dist/uri.d.ts +0 -52
- package/dist/uri.d.ts.map +0 -1
- package/dist/uri.js +0 -222
- package/dist/uri.js.map +0 -1
- package/dist/url.d.ts +0 -26
- package/dist/url.d.ts.map +0 -1
- package/dist/url.js +0 -120
- package/dist/url.js.map +0 -1
- package/dist/uuid.d.ts +0 -11
- package/dist/uuid.d.ts.map +0 -1
- package/dist/uuid.js.map +0 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { NominalType, TaggedType } from '@bessemer/cornerstone/types';
|
|
2
|
+
import * as ResourceKeys from '@bessemer/cornerstone/resource-key';
|
|
3
|
+
import { Result } from '@bessemer/cornerstone/result';
|
|
4
|
+
import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
|
|
5
|
+
import Zod from 'zod';
|
|
6
|
+
import { ValueOf } from 'type-fest';
|
|
7
|
+
import { Equalitor } from '@bessemer/cornerstone/equalitor';
|
|
8
|
+
import { UriHostName } from '@bessemer/cornerstone/net/uri-host-name';
|
|
9
|
+
export type UriString = TaggedType<string, 'UriString'>;
|
|
10
|
+
export type UriComponent = string;
|
|
11
|
+
export type UriScheme = string;
|
|
12
|
+
export type UriAuthentication = {
|
|
13
|
+
principal: string;
|
|
14
|
+
password: string | null;
|
|
15
|
+
};
|
|
16
|
+
export type UriHost = {
|
|
17
|
+
value: UriHostName;
|
|
18
|
+
port: number | null;
|
|
19
|
+
};
|
|
20
|
+
export interface UriLocation {
|
|
21
|
+
path: string | null;
|
|
22
|
+
query: string | null;
|
|
23
|
+
fragment: string | null;
|
|
24
|
+
}
|
|
25
|
+
export declare const Namespace: ResourceKeys.ResourceNamespace<"uri">;
|
|
26
|
+
export declare const UrlNamespace: ResourceKeys.ResourceNamespace<"url">;
|
|
27
|
+
export declare const EqualBy: Equalitor<Uri>;
|
|
28
|
+
export type UriLiteral = NominalType<string, typeof Namespace>;
|
|
29
|
+
export interface UriStructure {
|
|
30
|
+
_type: typeof Namespace | typeof UrlNamespace;
|
|
31
|
+
scheme: UriScheme | null;
|
|
32
|
+
host: UriHost | null;
|
|
33
|
+
authentication: UriAuthentication | null;
|
|
34
|
+
location: UriLocation;
|
|
35
|
+
}
|
|
36
|
+
export interface Uri extends UriStructure {
|
|
37
|
+
href: UriLiteral;
|
|
38
|
+
}
|
|
39
|
+
type UriBuilderAuthentication = {
|
|
40
|
+
principal: string;
|
|
41
|
+
password?: string | null;
|
|
42
|
+
} | string;
|
|
43
|
+
type UriBuilderHost = {
|
|
44
|
+
value: string;
|
|
45
|
+
port?: number | null;
|
|
46
|
+
} | string;
|
|
47
|
+
type UriBuilderLocation = {
|
|
48
|
+
path?: string | null;
|
|
49
|
+
query?: string | null;
|
|
50
|
+
fragment?: string | null;
|
|
51
|
+
} | string;
|
|
52
|
+
export type UriBuilder = {
|
|
53
|
+
scheme?: string | null | undefined;
|
|
54
|
+
authentication?: UriBuilderAuthentication | null | undefined;
|
|
55
|
+
host?: UriBuilderHost | null | undefined;
|
|
56
|
+
location?: UriBuilderLocation | null | undefined;
|
|
57
|
+
};
|
|
58
|
+
export type UriLike = Uri | UriLiteral | UriBuilder;
|
|
59
|
+
/**
|
|
60
|
+
* Parses a string into a Uri object, handling all URI components including scheme,
|
|
61
|
+
* authority (host and authentication), and location (path, query, fragment).
|
|
62
|
+
* Returns a Result containing either the parsed Uri or an ErrorEvent on failure.
|
|
63
|
+
*
|
|
64
|
+
* **Example**
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { Uris } from "@bessemer/cornerstone"
|
|
68
|
+
*
|
|
69
|
+
* // Parse a complete HTTPS URI
|
|
70
|
+
* const result = Uris.parseString('https://user:pass@example.com:8080/api/v1?q=test#section')
|
|
71
|
+
* if (result.isSuccess) {
|
|
72
|
+
* console.log(result.value.scheme) // 'https'
|
|
73
|
+
* console.log(result.value.host?.value) // 'example.com'
|
|
74
|
+
* console.log(result.value.authentication?.principal) // 'user'
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* // Parse a simple URI without authority
|
|
78
|
+
* const urnResult = Uris.parseString('urn:isbn:0451450523')
|
|
79
|
+
* if (urnResult.isSuccess) {
|
|
80
|
+
* console.log(urnResult.value.scheme) // 'urn'
|
|
81
|
+
* console.log(urnResult.value.location.path) // 'isbn:0451450523'
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @category parsing
|
|
86
|
+
*/
|
|
87
|
+
export declare const parseString: (value: string) => Result<Uri, ErrorEvent>;
|
|
88
|
+
/**
|
|
89
|
+
* Converts various URI-like inputs into a Uri object. Handles Uri instances,
|
|
90
|
+
* string literals, and builder objects, returning them as-is when already a Uri
|
|
91
|
+
* or converting them appropriately.
|
|
92
|
+
*
|
|
93
|
+
* **Example**
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { Uris } from "@bessemer/cornerstone"
|
|
97
|
+
*
|
|
98
|
+
* // String literal parsed into Uri
|
|
99
|
+
* const fromString = Uris.from('https://api.example.com/v1')
|
|
100
|
+
* console.log(fromString.scheme) // 'https'
|
|
101
|
+
* console.log(fromString.host?.value) // 'api.example.com'
|
|
102
|
+
*
|
|
103
|
+
* // Builder object converted to Uri
|
|
104
|
+
* const fromBuilder = Uris.from({
|
|
105
|
+
* scheme: 'https',
|
|
106
|
+
* host: { value: 'example.com', port: 8080 },
|
|
107
|
+
* location: { path: '/api' }
|
|
108
|
+
* })
|
|
109
|
+
* console.log(fromBuilder.host?.port) // 8080
|
|
110
|
+
*
|
|
111
|
+
* @category conversion
|
|
112
|
+
*/
|
|
113
|
+
export declare function from(value: UriLike | string): Uri;
|
|
114
|
+
export declare function from(value: UriLike | string | null): Uri | null;
|
|
115
|
+
export declare function from(value: UriLike | string | undefined): Uri | undefined;
|
|
116
|
+
export declare function from(value: UriLike | string | null | undefined): Uri | null | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Converts various URI-like inputs into a normalized string literal representation.
|
|
119
|
+
* Takes any URI-like value and returns its canonical string form
|
|
120
|
+
*
|
|
121
|
+
* **Example**
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { Uris } from "@bessemer/cornerstone"
|
|
125
|
+
*
|
|
126
|
+
* // Convert Uri instance to string literal
|
|
127
|
+
* const uri = Uris.build({ scheme: 'https', host: 'example.com', location: { path: '/api' } })
|
|
128
|
+
* const literal = Uris.toLiteral(uri)
|
|
129
|
+
* console.log(literal) // "https://example.com/api"
|
|
130
|
+
*
|
|
131
|
+
* // Convert builder object to string literal
|
|
132
|
+
* const fromBuilder = Uris.toLiteral({
|
|
133
|
+
* scheme: 'https',
|
|
134
|
+
* host: { value: 'api.example.com', port: 8080 },
|
|
135
|
+
* authentication: { principal: 'user', password: 'pass' },
|
|
136
|
+
* location: { path: '/v1', parameters: { q: 'search' } }
|
|
137
|
+
* })
|
|
138
|
+
* console.log(fromBuilder) // "https://user:pass@api.example.com:8080/v1?q=search"
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @category serialization
|
|
142
|
+
*/
|
|
143
|
+
export declare function toLiteral(likeValue: UriLike): UriLiteral;
|
|
144
|
+
export declare function toLiteral(likeValue: UriLike | null): UriLiteral | null;
|
|
145
|
+
export declare function toLiteral(likeValue: UriLike | undefined): UriLiteral | undefined;
|
|
146
|
+
export declare function toLiteral(likeValue: UriLike | null | undefined): UriLiteral | null | undefined;
|
|
147
|
+
export declare const SchemaLiteral: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<UriLiteral, string>>;
|
|
148
|
+
/**
|
|
149
|
+
* Tests if the provided value is a Uri.
|
|
150
|
+
*
|
|
151
|
+
* **Example**
|
|
152
|
+
*
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { Uris } from "@bessemer/cornerstone"
|
|
155
|
+
*
|
|
156
|
+
* // Check if unknown value is a Uri
|
|
157
|
+
* function processValue(value: unknown) {
|
|
158
|
+
* if (Uris.isUri(value)) {
|
|
159
|
+
* console.log(value.scheme) // Type-safe access
|
|
160
|
+
* console.log(value.location.path)
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @category type-guards
|
|
166
|
+
*/
|
|
167
|
+
export declare const isUri: (value: unknown) => value is Uri;
|
|
168
|
+
/**
|
|
169
|
+
* Merges an existing URI with partial changes to create a new URI instance.
|
|
170
|
+
* Allows selective updates without replacing the entire URI.
|
|
171
|
+
*
|
|
172
|
+
* **Example**
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { Uris } from "@bessemer/cornerstone"
|
|
176
|
+
*
|
|
177
|
+
* // Start with a base URI
|
|
178
|
+
* const baseUri = Uris.build({
|
|
179
|
+
* scheme: 'https',
|
|
180
|
+
* host: { value: 'api.example.com', port: 443 },
|
|
181
|
+
* authentication: { principal: 'user', password: 'pass' },
|
|
182
|
+
* location: { path: '/v1', parameters: { format: 'json' } }
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* // Change just the host and add query parameter
|
|
186
|
+
* const updatedUri = Uris.merge(baseUri, {
|
|
187
|
+
* host: { value: 'api.production.com' }, // Port preserved from original
|
|
188
|
+
* location: {
|
|
189
|
+
* parameters: { version: '2.0' } // Merges with existing parameters
|
|
190
|
+
* }
|
|
191
|
+
* })
|
|
192
|
+
*
|
|
193
|
+
* console.log(updatedUri.host?.value) // 'api.production.com'
|
|
194
|
+
* console.log(updatedUri.host?.port) // 443 (preserved)
|
|
195
|
+
* console.log(updatedUri.location.parameters) // { format: 'json', version: '2.0' }
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @category transformation
|
|
199
|
+
*/
|
|
200
|
+
export declare const merge: (element: UriLike, builder: UriBuilder) => Uri;
|
|
201
|
+
export declare const UriComponentType: {
|
|
202
|
+
readonly Scheme: "Scheme";
|
|
203
|
+
readonly Authentication: "Authentication";
|
|
204
|
+
readonly Host: "Host";
|
|
205
|
+
readonly Location: "Location";
|
|
206
|
+
readonly Path: "Path";
|
|
207
|
+
readonly Query: "Query";
|
|
208
|
+
readonly Fragment: "Fragment";
|
|
209
|
+
};
|
|
210
|
+
export type UriComponentType = ValueOf<typeof UriComponentType>;
|
|
211
|
+
/**
|
|
212
|
+
* Converts a URI object into its string representation, with optional exclusion of specific URI components.
|
|
213
|
+
*
|
|
214
|
+
* **Example**
|
|
215
|
+
*
|
|
216
|
+
* ```ts
|
|
217
|
+
* import { Uris, UriComponentType } from "@bessemer/cornerstone"
|
|
218
|
+
*
|
|
219
|
+
* const uri = Uris.build({
|
|
220
|
+
* scheme: 'https',
|
|
221
|
+
* authentication: { principal: 'user', password: 'secret' },
|
|
222
|
+
* host: { value: 'api.example.com', port: 8080 },
|
|
223
|
+
* location: { path: '/v1/data', parameters: { format: 'json' }, fragment: 'results' }
|
|
224
|
+
* })
|
|
225
|
+
*
|
|
226
|
+
* // Format complete URI
|
|
227
|
+
* const fullUri = Uris.format(uri)
|
|
228
|
+
* console.log(fullUri) // "https://user:secret@api.example.com:8080/v1/data?format=json#results"
|
|
229
|
+
*
|
|
230
|
+
* // Exclude authentication for public sharing
|
|
231
|
+
* const publicUri = Uris.format(uri, [UriComponentType.Authentication])
|
|
232
|
+
* console.log(publicUri) // "https://api.example.com:8080/v1/data?format=json#results"
|
|
233
|
+
*
|
|
234
|
+
* // Format path-only URI
|
|
235
|
+
* const pathOnly = Uris.format(uri, [
|
|
236
|
+
* UriComponentType.Scheme,
|
|
237
|
+
* UriComponentType.Host,
|
|
238
|
+
* UriComponentType.Authentication
|
|
239
|
+
* ])
|
|
240
|
+
* console.log(pathOnly) // "/v1/data?format=json#results"
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @category serialization
|
|
244
|
+
*/
|
|
245
|
+
export declare const format: (uriLike: UriLike, excludedUriComponents?: Array<UriComponentType>) => UriLiteral;
|
|
246
|
+
export declare const encode: (uriComponent: UriComponent) => string;
|
|
247
|
+
export declare const decode: (uriComponent: UriComponent) => string;
|
|
248
|
+
export {};
|
|
249
|
+
//# sourceMappingURL=uri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri.d.ts","sourceRoot":"","sources":["../../src/net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;;;;;;;;GAiCG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,OAAO,EAAE,wBAAuB,KAAK,CAAC,gBAAgB,CAAM,KAAG,UAE9F,CAAA;AAwDD,eAAO,MAAM,MAAM,GAAI,cAAc,YAAY,WAEhD,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,cAAc,YAAY,WAEhD,CAAA"}
|
package/dist/net/uri.js
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
// src/net/uri.ts
|
|
2
|
+
import * as Strings from "@bessemer/cornerstone/string";
|
|
3
|
+
import * as Objects from "@bessemer/cornerstone/object";
|
|
4
|
+
import * as Arrays from "@bessemer/cornerstone/array";
|
|
5
|
+
import * as ResourceKeys from "@bessemer/cornerstone/resource-key";
|
|
6
|
+
import * as Results from "@bessemer/cornerstone/result";
|
|
7
|
+
import { success as success2 } from "@bessemer/cornerstone/result";
|
|
8
|
+
import * as ErrorEvents from "@bessemer/cornerstone/error/error-event";
|
|
9
|
+
import { structuredTransform } from "@bessemer/cornerstone/zod-util";
|
|
10
|
+
import Zod from "zod";
|
|
11
|
+
import * as IpV6Addresses from "@bessemer/cornerstone/net/ipv6-address";
|
|
12
|
+
import * as Equalitors from "@bessemer/cornerstone/equalitor";
|
|
13
|
+
import * as UriHostNames from "@bessemer/cornerstone/net/uri-host-name";
|
|
14
|
+
var Namespace = ResourceKeys.createNamespace("uri");
|
|
15
|
+
var UrlNamespace = ResourceKeys.createNamespace("url");
|
|
16
|
+
var EqualBy = Equalitors.deepNatural();
|
|
17
|
+
var parseString3 = (value) => {
|
|
18
|
+
if (Strings.isBlank(value)) {
|
|
19
|
+
return Results.failure(
|
|
20
|
+
ErrorEvents.required({
|
|
21
|
+
namespace: Namespace,
|
|
22
|
+
message: `[${Namespace}]: Unable to parse Uri from empty string.`
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const schemeResult = parseSchemePart(value);
|
|
27
|
+
if (!schemeResult.isSuccess) {
|
|
28
|
+
return Results.failure(
|
|
29
|
+
ErrorEvents.invalidValue(value, {
|
|
30
|
+
namespace: Namespace,
|
|
31
|
+
message: `[${Namespace}]: Unable to parse Uri from uri string: [${value}]`,
|
|
32
|
+
causes: schemeResult.value.causes
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const [scheme, rest1] = schemeResult.value;
|
|
37
|
+
const authorityPartResult = parseAuthorityPart(rest1);
|
|
38
|
+
if (!authorityPartResult.isSuccess) {
|
|
39
|
+
return Results.failure(
|
|
40
|
+
ErrorEvents.invalidValue(value, {
|
|
41
|
+
namespace: Namespace,
|
|
42
|
+
message: `[${Namespace}]: Unable to parse Uri from uri string: [${value}]`,
|
|
43
|
+
causes: authorityPartResult.value.causes
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const [authority, rest2] = authorityPartResult.value;
|
|
48
|
+
const location = parseLocation(rest2);
|
|
49
|
+
const structure = {
|
|
50
|
+
_type: Namespace,
|
|
51
|
+
scheme,
|
|
52
|
+
host: authority.host,
|
|
53
|
+
authentication: authority.authentication,
|
|
54
|
+
location
|
|
55
|
+
};
|
|
56
|
+
return Results.success({
|
|
57
|
+
...structure,
|
|
58
|
+
href: formatInternal(structure)
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
function from2(value) {
|
|
62
|
+
if (Objects.isNil(value)) {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (isUri(value)) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
if (Strings.isString(value)) {
|
|
69
|
+
return ErrorEvents.unpackResult(parseString3(value));
|
|
70
|
+
}
|
|
71
|
+
return build(value);
|
|
72
|
+
}
|
|
73
|
+
function toLiteral(likeValue) {
|
|
74
|
+
if (Objects.isNil(likeValue)) {
|
|
75
|
+
return likeValue;
|
|
76
|
+
}
|
|
77
|
+
const value = from2(likeValue);
|
|
78
|
+
return format(value);
|
|
79
|
+
}
|
|
80
|
+
var SchemaLiteral = structuredTransform(Zod.string(), (it) => Results.mapResult(parseString3(it), (it2) => toLiteral(it2)));
|
|
81
|
+
var isUri = (value) => {
|
|
82
|
+
if (!Objects.isObject(value)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const uriValue = value;
|
|
86
|
+
return uriValue._type === Namespace || uriValue._type === UrlNamespace;
|
|
87
|
+
};
|
|
88
|
+
var merge = (element, builder) => {
|
|
89
|
+
const uri = from2(element);
|
|
90
|
+
let location;
|
|
91
|
+
if (Strings.isString(builder.location) || Objects.isNull(builder.location)) {
|
|
92
|
+
location = builder.location;
|
|
93
|
+
} else {
|
|
94
|
+
location = { ...uri.location, ...builder.location ?? {} };
|
|
95
|
+
}
|
|
96
|
+
const uriBuilder = {
|
|
97
|
+
scheme: Objects.isUndefined(builder.scheme) ? uri.scheme : builder.scheme,
|
|
98
|
+
host: Objects.isUndefined(builder.host) ? uri.host : builder.host,
|
|
99
|
+
authentication: Objects.isUndefined(builder.authentication) ? uri.authentication : builder.authentication,
|
|
100
|
+
location
|
|
101
|
+
};
|
|
102
|
+
return from2(uriBuilder);
|
|
103
|
+
};
|
|
104
|
+
var parseSchemePart = (url) => {
|
|
105
|
+
const schemeMatch = Strings.splitFirst(url, /(\/\/|:)/);
|
|
106
|
+
if (Objects.isNil(schemeMatch.selection) || schemeMatch.separator === "//") {
|
|
107
|
+
return Results.success([null, url]);
|
|
108
|
+
}
|
|
109
|
+
if (Strings.isEmpty(schemeMatch.selection)) {
|
|
110
|
+
return Results.success([null, ":" + schemeMatch.rest]);
|
|
111
|
+
} else {
|
|
112
|
+
const schemeResult = parseScheme(schemeMatch.selection);
|
|
113
|
+
if (!schemeResult.isSuccess) {
|
|
114
|
+
return schemeResult;
|
|
115
|
+
}
|
|
116
|
+
return Results.success([schemeResult.value, schemeMatch.rest]);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var parseScheme = (scheme) => {
|
|
120
|
+
const schemeRegex = /^[a-zA-Z][a-zA-Z0-9+.-]*$/;
|
|
121
|
+
if (!schemeRegex.test(scheme)) {
|
|
122
|
+
return Results.failure(
|
|
123
|
+
ErrorEvents.invalidValue(scheme, {
|
|
124
|
+
namespace: Namespace,
|
|
125
|
+
message: `[${Namespace}]: Invalid characters in Scheme.`
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return Results.success(scheme);
|
|
130
|
+
};
|
|
131
|
+
var parseAuthorityPart = (initialUrl) => {
|
|
132
|
+
if (!initialUrl.startsWith("//")) {
|
|
133
|
+
return success2([{ host: null, authentication: null }, initialUrl]);
|
|
134
|
+
}
|
|
135
|
+
const url = Strings.removeStart(initialUrl, "//");
|
|
136
|
+
const authenticationPartResult = parseAuthenticationPart(url);
|
|
137
|
+
if (!authenticationPartResult.isSuccess) {
|
|
138
|
+
return authenticationPartResult;
|
|
139
|
+
}
|
|
140
|
+
const [authentication, rest1] = authenticationPartResult.value;
|
|
141
|
+
const hostPartResult = parseHostPart(rest1);
|
|
142
|
+
if (!hostPartResult.isSuccess) {
|
|
143
|
+
return hostPartResult;
|
|
144
|
+
}
|
|
145
|
+
const [host, rest2] = hostPartResult.value;
|
|
146
|
+
return success2([{ host, authentication }, rest2]);
|
|
147
|
+
};
|
|
148
|
+
var parseAuthenticationPart = (url) => {
|
|
149
|
+
let targetPart = url;
|
|
150
|
+
const queryMatch = Strings.splitFirst(targetPart, "?");
|
|
151
|
+
const fragmentMatch = Strings.splitFirst(targetPart, "#");
|
|
152
|
+
if (Objects.isPresent(queryMatch.selection)) {
|
|
153
|
+
targetPart = queryMatch.selection;
|
|
154
|
+
} else if (Objects.isPresent(fragmentMatch.selection)) {
|
|
155
|
+
targetPart = fragmentMatch.selection;
|
|
156
|
+
}
|
|
157
|
+
const { selection: authentication } = Strings.splitFirst(targetPart, "@");
|
|
158
|
+
if (Objects.isNil(authentication)) {
|
|
159
|
+
return Results.success([null, url]);
|
|
160
|
+
}
|
|
161
|
+
const { rest } = Strings.splitFirst(url, "@");
|
|
162
|
+
const authenticationParseResult = parseAuthentication(authentication);
|
|
163
|
+
if (!authenticationParseResult.isSuccess) {
|
|
164
|
+
return authenticationParseResult;
|
|
165
|
+
}
|
|
166
|
+
return Results.success([authenticationParseResult.value, rest]);
|
|
167
|
+
};
|
|
168
|
+
var parseAuthentication = (authentication) => {
|
|
169
|
+
const { selection: principal, rest: authenticationRest } = Strings.splitFirst(authentication, ":");
|
|
170
|
+
if (Objects.isNil(principal)) {
|
|
171
|
+
if (!isAuthenticationComponentValid(authenticationRest)) {
|
|
172
|
+
return Results.failure(
|
|
173
|
+
ErrorEvents.invalidValue(authenticationRest, {
|
|
174
|
+
namespace: Namespace,
|
|
175
|
+
message: `[${Namespace}]: Invalid characters for UriAuthentication in principal string: [${authenticationRest}]`
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return Results.success({ principal: decode(authenticationRest), password: null });
|
|
180
|
+
}
|
|
181
|
+
if (Strings.isEmpty(principal)) {
|
|
182
|
+
return Results.failure(
|
|
183
|
+
ErrorEvents.invalidValue(authentication, {
|
|
184
|
+
namespace: Namespace,
|
|
185
|
+
message: `[${Namespace}]: Unable to parse UriAuthentication from authentication string: [${authentication}]`
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (!isAuthenticationComponentValid(principal)) {
|
|
190
|
+
return Results.failure(
|
|
191
|
+
ErrorEvents.invalidValue(principal, {
|
|
192
|
+
namespace: Namespace,
|
|
193
|
+
message: `[${Namespace}]: Invalid characters for UriAuthentication in principal string: [${principal}]`
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (!isAuthenticationComponentValid(authenticationRest)) {
|
|
198
|
+
return Results.failure(
|
|
199
|
+
ErrorEvents.invalidValue(authenticationRest, {
|
|
200
|
+
namespace: Namespace,
|
|
201
|
+
message: `[${Namespace}]: Invalid characters for UriAuthentication in password string: [${authenticationRest}]`
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
return Results.success({ principal: decode(principal), password: decode(authenticationRest) });
|
|
206
|
+
};
|
|
207
|
+
var isAuthenticationComponentValid = (component) => {
|
|
208
|
+
const userinfoRegex = /^[A-Za-z0-9\-._~!$&'()*+,;=%]*$/;
|
|
209
|
+
if (component.includes("%")) {
|
|
210
|
+
const percentEncodingRegex = /%[0-9A-Fa-f]{2}/g;
|
|
211
|
+
const percentMatches = component.match(/%/g) || [];
|
|
212
|
+
const validEncodingMatches = component.match(percentEncodingRegex) || [];
|
|
213
|
+
if (percentMatches.length !== validEncodingMatches.length) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return userinfoRegex.test(component);
|
|
218
|
+
};
|
|
219
|
+
var parseHostPart = (url) => {
|
|
220
|
+
if (url.startsWith("?") || url.startsWith("#")) {
|
|
221
|
+
return Results.success([null, url]);
|
|
222
|
+
}
|
|
223
|
+
const urlMatch = Strings.splitFirst(url, /[\/?#]/);
|
|
224
|
+
let host = urlMatch.rest;
|
|
225
|
+
let rest = "";
|
|
226
|
+
if (Objects.isPresent(urlMatch.selection)) {
|
|
227
|
+
host = urlMatch.selection;
|
|
228
|
+
rest = urlMatch.separator + urlMatch.rest;
|
|
229
|
+
}
|
|
230
|
+
if (Strings.isEmpty(host)) {
|
|
231
|
+
return Results.success([null, rest]);
|
|
232
|
+
}
|
|
233
|
+
const parseHostResult = parseHost(host);
|
|
234
|
+
if (!parseHostResult.isSuccess) {
|
|
235
|
+
return parseHostResult;
|
|
236
|
+
}
|
|
237
|
+
return Results.success([parseHostResult.value, rest]);
|
|
238
|
+
};
|
|
239
|
+
var parseHost = (host) => {
|
|
240
|
+
if (host.startsWith("[")) {
|
|
241
|
+
const ipMatch = Strings.splitFirst(Strings.removeStart(host, "["), "]");
|
|
242
|
+
if (Objects.isPresent(ipMatch.selection)) {
|
|
243
|
+
const ipV6Result = IpV6Addresses.parseString(ipMatch.selection);
|
|
244
|
+
if (!ipV6Result.isSuccess) {
|
|
245
|
+
return ipV6Result;
|
|
246
|
+
}
|
|
247
|
+
const portMatch = Strings.splitFirst(ipMatch.rest, ":");
|
|
248
|
+
if (Objects.isPresent(portMatch.selection) && Strings.isEmpty(portMatch.selection)) {
|
|
249
|
+
if (!Strings.isNumber(portMatch.rest)) {
|
|
250
|
+
return Results.failure(ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host: [${host}]` }));
|
|
251
|
+
}
|
|
252
|
+
return Results.success({ value: `[${ipMatch.selection}]`, port: Number(portMatch.rest) });
|
|
253
|
+
} else {
|
|
254
|
+
return Results.success({ value: `[${ipMatch.selection}]`, port: null });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
let hostMatch = Strings.splitFirst(host, ":");
|
|
259
|
+
if (Objects.isNil(hostMatch.selection)) {
|
|
260
|
+
const hostNameResult2 = UriHostNames.parseString(hostMatch.rest);
|
|
261
|
+
if (!hostNameResult2.isSuccess) {
|
|
262
|
+
return Results.failure(
|
|
263
|
+
ErrorEvents.invalidValue(host, {
|
|
264
|
+
namespace: Namespace,
|
|
265
|
+
message: `[${Namespace}]: Unable to parse Host from host string: [${host}]`,
|
|
266
|
+
causes: hostNameResult2.value.causes
|
|
267
|
+
})
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
return Results.success({ value: hostNameResult2.value, port: null });
|
|
271
|
+
}
|
|
272
|
+
if (Strings.isEmpty(hostMatch.selection)) {
|
|
273
|
+
return Results.failure(
|
|
274
|
+
ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host from host string: [${host}]` })
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
const hostName = hostMatch.selection;
|
|
278
|
+
if (!Strings.isNumber(hostMatch.rest)) {
|
|
279
|
+
return Results.failure(
|
|
280
|
+
ErrorEvents.invalidValue(host, { namespace: Namespace, message: `[${Namespace}]: Unable to parse Host from host string: [${host}]` })
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
const hostNameResult = UriHostNames.parseString(hostName);
|
|
284
|
+
if (!hostNameResult.isSuccess) {
|
|
285
|
+
return Results.failure(
|
|
286
|
+
ErrorEvents.invalidValue(host, {
|
|
287
|
+
namespace: Namespace,
|
|
288
|
+
message: `[${Namespace}]: Unable to parse Host from host string: [${host}]`,
|
|
289
|
+
causes: hostNameResult.value.causes
|
|
290
|
+
})
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
return Results.success({ value: hostNameResult.value, port: Number(hostMatch.rest) });
|
|
294
|
+
};
|
|
295
|
+
var parseLocation = (url) => {
|
|
296
|
+
const location = { path: null, query: null, fragment: null };
|
|
297
|
+
const fragmentMatch = Strings.splitFirst(url, "#");
|
|
298
|
+
if (Objects.isPresent(fragmentMatch.selection) && !Strings.isEmpty(fragmentMatch.rest)) {
|
|
299
|
+
location.fragment = encodeWhitespace(fragmentMatch.rest);
|
|
300
|
+
}
|
|
301
|
+
const queryMatch = Strings.splitFirst(fragmentMatch.selection ?? fragmentMatch.rest, "?");
|
|
302
|
+
if (Objects.isPresent(queryMatch.selection) && !Strings.isEmpty(queryMatch.rest)) {
|
|
303
|
+
location.query = encodeWhitespace(queryMatch.rest);
|
|
304
|
+
}
|
|
305
|
+
const path = Strings.emptyToNull(queryMatch.selection ?? queryMatch.rest);
|
|
306
|
+
if (Objects.isPresent(path)) {
|
|
307
|
+
location.path = encodeWhitespace(path);
|
|
308
|
+
}
|
|
309
|
+
return location;
|
|
310
|
+
};
|
|
311
|
+
var build = (builder) => {
|
|
312
|
+
const scheme = Objects.isPresent(builder.scheme) ? ErrorEvents.unpackResult(parseScheme(builder.scheme)) : null;
|
|
313
|
+
let host = null;
|
|
314
|
+
let authentication = null;
|
|
315
|
+
if (Objects.isPresent(builder.host)) {
|
|
316
|
+
if (Strings.isString(builder.host)) {
|
|
317
|
+
host = ErrorEvents.unpackResult(parseHost(builder.host));
|
|
318
|
+
} else {
|
|
319
|
+
host = {
|
|
320
|
+
value: UriHostNames.from(builder.host.value),
|
|
321
|
+
port: builder.host.port ?? null
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
if (Objects.isPresent(builder.authentication)) {
|
|
325
|
+
if (Strings.isString(builder.authentication)) {
|
|
326
|
+
authentication = ErrorEvents.unpackResult(parseAuthentication(builder.authentication));
|
|
327
|
+
} else {
|
|
328
|
+
authentication = {
|
|
329
|
+
principal: builder.authentication.principal,
|
|
330
|
+
password: builder.authentication.password ?? null
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
let location = {
|
|
336
|
+
path: null,
|
|
337
|
+
query: null,
|
|
338
|
+
fragment: null
|
|
339
|
+
};
|
|
340
|
+
if (Objects.isPresent(builder.location)) {
|
|
341
|
+
if (Strings.isString(builder.location)) {
|
|
342
|
+
let locationString = builder.location;
|
|
343
|
+
if (Objects.isPresent(builder.host) && !locationString.startsWith("/") && !locationString.startsWith("?") && !locationString.startsWith("#")) {
|
|
344
|
+
locationString = "/" + locationString;
|
|
345
|
+
}
|
|
346
|
+
location = parseLocation(locationString);
|
|
347
|
+
} else {
|
|
348
|
+
let path = builder.location.path ?? null;
|
|
349
|
+
if (Objects.isPresent(path) && !path.startsWith("/") && Objects.isPresent(builder.host)) {
|
|
350
|
+
path = "/" + path;
|
|
351
|
+
}
|
|
352
|
+
location = {
|
|
353
|
+
path: Objects.isPresent(path) ? encodeWhitespace(path) : null,
|
|
354
|
+
query: Objects.isPresent(builder.location.query) ? encodeWhitespace(builder.location.query) : null,
|
|
355
|
+
fragment: Objects.isPresent(builder.location.fragment) ? encodeWhitespace(builder.location.fragment) : null
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const structure = {
|
|
360
|
+
_type: Namespace,
|
|
361
|
+
scheme,
|
|
362
|
+
host,
|
|
363
|
+
authentication,
|
|
364
|
+
location
|
|
365
|
+
};
|
|
366
|
+
return {
|
|
367
|
+
...structure,
|
|
368
|
+
href: formatInternal(structure)
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
var UriComponentType = {
|
|
372
|
+
Scheme: "Scheme",
|
|
373
|
+
Authentication: "Authentication",
|
|
374
|
+
Host: "Host",
|
|
375
|
+
Location: "Location",
|
|
376
|
+
Path: "Path",
|
|
377
|
+
Query: "Query",
|
|
378
|
+
Fragment: "Fragment"
|
|
379
|
+
};
|
|
380
|
+
var format = (uriLike, excludedUriComponents = []) => {
|
|
381
|
+
return formatInternal(from2(uriLike), excludedUriComponents);
|
|
382
|
+
};
|
|
383
|
+
var formatInternal = (uri, excludedUriComponents = []) => {
|
|
384
|
+
let urlString = "";
|
|
385
|
+
if (Objects.isPresent(uri.scheme) && !Arrays.contains(excludedUriComponents, UriComponentType.Scheme)) {
|
|
386
|
+
urlString = urlString + uri.scheme + ":";
|
|
387
|
+
}
|
|
388
|
+
if (Objects.isPresent(uri.host) && !Arrays.contains(excludedUriComponents, UriComponentType.Host)) {
|
|
389
|
+
urlString = urlString + "//";
|
|
390
|
+
if (Objects.isPresent(uri.authentication) && !Arrays.contains(excludedUriComponents, UriComponentType.Authentication)) {
|
|
391
|
+
urlString = urlString + encode(uri.authentication.principal);
|
|
392
|
+
if (Objects.isPresent(uri.authentication.password)) {
|
|
393
|
+
urlString = urlString + ":" + encode(uri.authentication.password);
|
|
394
|
+
}
|
|
395
|
+
urlString = urlString + "@";
|
|
396
|
+
}
|
|
397
|
+
urlString = urlString + uri.host.value;
|
|
398
|
+
if (Objects.isPresent(uri.host.port)) {
|
|
399
|
+
urlString = urlString + ":" + uri.host.port;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (!Arrays.contains(excludedUriComponents, UriComponentType.Location)) {
|
|
403
|
+
urlString = urlString + formatLocation(uri.location, excludedUriComponents);
|
|
404
|
+
}
|
|
405
|
+
return urlString;
|
|
406
|
+
};
|
|
407
|
+
var formatLocation = (location, excludedUriComponents = []) => {
|
|
408
|
+
let urlString = "";
|
|
409
|
+
if (Objects.isPresent(location.path) && !Arrays.contains(excludedUriComponents, UriComponentType.Path)) {
|
|
410
|
+
urlString = urlString + location.path;
|
|
411
|
+
}
|
|
412
|
+
if (Objects.isPresent(location.query) && !Arrays.contains(excludedUriComponents, UriComponentType.Query)) {
|
|
413
|
+
urlString = urlString + "?" + location.query;
|
|
414
|
+
}
|
|
415
|
+
if (Objects.isPresent(location.fragment) && !Arrays.contains(excludedUriComponents, UriComponentType.Fragment)) {
|
|
416
|
+
urlString = urlString + "#" + location.fragment;
|
|
417
|
+
}
|
|
418
|
+
return urlString;
|
|
419
|
+
};
|
|
420
|
+
var encodeWhitespace = (uriComponent) => {
|
|
421
|
+
return uriComponent.replaceAll(" ", "%20");
|
|
422
|
+
};
|
|
423
|
+
var encode = (uriComponent) => {
|
|
424
|
+
return encodeURIComponent(uriComponent);
|
|
425
|
+
};
|
|
426
|
+
var decode = (uriComponent) => {
|
|
427
|
+
return decodeURIComponent(uriComponent);
|
|
428
|
+
};
|
|
429
|
+
export {
|
|
430
|
+
EqualBy,
|
|
431
|
+
Namespace,
|
|
432
|
+
SchemaLiteral,
|
|
433
|
+
UriComponentType,
|
|
434
|
+
UrlNamespace,
|
|
435
|
+
decode,
|
|
436
|
+
encode,
|
|
437
|
+
format,
|
|
438
|
+
from2 as from,
|
|
439
|
+
isUri,
|
|
440
|
+
merge,
|
|
441
|
+
parseString3 as parseString,
|
|
442
|
+
toLiteral
|
|
443
|
+
};
|
|
444
|
+
//# sourceMappingURL=uri.js.map
|