@cookbook/urlkit 1.0.0
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/LICENSE +21 -0
- package/README.md +707 -0
- package/dist/compile-path-wQfWAzOh.js +1318 -0
- package/dist/compile-path-wQfWAzOh.js.map +1 -0
- package/dist/compile-static-search-Cq3uaLe8.js +238 -0
- package/dist/compile-static-search-Cq3uaLe8.js.map +1 -0
- package/dist/contracts.d.ts +107 -0
- package/dist/create-url-contract-BYKPM9bn.js +1751 -0
- package/dist/create-url-contract-BYKPM9bn.js.map +1 -0
- package/dist/date/contracts.d.ts +5 -0
- package/dist/date/parse-custom-date.d.ts +7 -0
- package/dist/date/parse-date-time.d.ts +6 -0
- package/dist/date/parse-date.d.ts +6 -0
- package/dist/date/parse-unix-ms.d.ts +6 -0
- package/dist/date/parse-unix-seconds.d.ts +6 -0
- package/dist/date/serialize-custom-date.d.ts +7 -0
- package/dist/date/serialize-date-time.d.ts +6 -0
- package/dist/date/serialize-date.d.ts +6 -0
- package/dist/date/serialize-unix-ms.d.ts +6 -0
- package/dist/date/serialize-unix-seconds.d.ts +6 -0
- package/dist/errors/contracts.d.ts +5 -0
- package/dist/errors/url-kit-error.d.ts +8 -0
- package/dist/hash/build-hash.d.ts +4 -0
- package/dist/hash/compile-hash-descriptor.d.ts +2 -0
- package/dist/hash/compile-normalized-hash-descriptor.d.ts +2 -0
- package/dist/hash/compile-runtime-hash-descriptor.d.ts +3 -0
- package/dist/hash/compile-static-hash-descriptor.d.ts +3 -0
- package/dist/hash/contracts.d.ts +21 -0
- package/dist/hash/copy-normalized-hash-descriptor.d.ts +2 -0
- package/dist/hash/create-hash.d.ts +5 -0
- package/dist/hash/hash-fragment.d.ts +2 -0
- package/dist/hash/is-normalized-hash-descriptor.d.ts +2 -0
- package/dist/hash/normalize-hash.d.ts +3 -0
- package/dist/hash/parse-hash.d.ts +3 -0
- package/dist/hash/validate-normalized-hash-value.d.ts +5 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/router-runtime.d.ts +12 -0
- package/dist/router-runtime.js +214 -0
- package/dist/router-runtime.js.map +1 -0
- package/dist/runtime/build-route-search.d.ts +22 -0
- package/dist/runtime/compile-cached-static-search.d.ts +3 -0
- package/dist/runtime/contracts.d.ts +7 -0
- package/dist/runtime/create-route-url-contract.d.ts +15 -0
- package/dist/runtime/parse-route-search.d.ts +12 -0
- package/dist/schema/array.d.ts +9 -0
- package/dist/schema/boolean.d.ts +4 -0
- package/dist/schema/compile-runtime-schema-value.d.ts +6 -0
- package/dist/schema/compile-runtime-schema.d.ts +2 -0
- package/dist/schema/contracts.d.ts +87 -0
- package/dist/schema/create-schema-builder.d.ts +2 -0
- package/dist/schema/create-schema-value-error.d.ts +3 -0
- package/dist/schema/date-time.d.ts +4 -0
- package/dist/schema/date.d.ts +14 -0
- package/dist/schema/enum-of.d.ts +7 -0
- package/dist/schema/get-runtime-schema-internals.d.ts +2 -0
- package/dist/schema/handle-runtime-schema-absence.d.ts +6 -0
- package/dist/schema/int.d.ts +4 -0
- package/dist/schema/is-runtime-schema-kind.d.ts +2 -0
- package/dist/schema/normalize-compiled-runtime-schema-value.d.ts +3 -0
- package/dist/schema/normalize-runtime-schema-value.d.ts +2 -0
- package/dist/schema/number.d.ts +4 -0
- package/dist/schema/object.d.ts +20 -0
- package/dist/schema/parse-compiled-runtime-schema-value.d.ts +3 -0
- package/dist/schema/parse-runtime-schema-value.d.ts +2 -0
- package/dist/schema/runtime-schema-symbol.d.ts +5 -0
- package/dist/schema/runtime-schema-value-context.d.ts +2 -0
- package/dist/schema/safe-runtime-schema-value.d.ts +4 -0
- package/dist/schema/serialize-compiled-runtime-schema-value.d.ts +3 -0
- package/dist/schema/serialize-runtime-schema-value.d.ts +2 -0
- package/dist/schema/string.d.ts +4 -0
- package/dist/search/append-object-search-entries.d.ts +4 -0
- package/dist/search/append-raw-search-value.d.ts +2 -0
- package/dist/search/append-search-entry.d.ts +3 -0
- package/dist/search/are-search-values-equal.d.ts +1 -0
- package/dist/search/assert-object-search-collisions.d.ts +2 -0
- package/dist/search/build-compiled-search.d.ts +3 -0
- package/dist/search/build-raw-search.d.ts +2 -0
- package/dist/search/build-schema-search.d.ts +3 -0
- package/dist/search/build-search.d.ts +6 -0
- package/dist/search/collect-object-search-paths.d.ts +2 -0
- package/dist/search/compile-search-schema.d.ts +2 -0
- package/dist/search/contracts.d.ts +73 -0
- package/dist/search/copy-raw-search-params.d.ts +2 -0
- package/dist/search/copy-unknown-structured-search.d.ts +2 -0
- package/dist/search/create-search-params.d.ts +1 -0
- package/dist/search/create-search.d.ts +4 -0
- package/dist/search/delete-search-field-raw-keys.d.ts +2 -0
- package/dist/search/filter-raw-search.d.ts +3 -0
- package/dist/search/find-object-search-raw-value.d.ts +2 -0
- package/dist/search/has-search-field-raw-value.d.ts +2 -0
- package/dist/search/is-runtime-search-field.d.ts +2 -0
- package/dist/search/join-search-strings.d.ts +1 -0
- package/dist/search/normalize-compiled-search.d.ts +3 -0
- package/dist/search/normalize-search-build-value.d.ts +2 -0
- package/dist/search/normalize-search-field-default.d.ts +2 -0
- package/dist/search/normalize-search-field-type.d.ts +2 -0
- package/dist/search/object-search-key.d.ts +4 -0
- package/dist/search/object-search-path-key.d.ts +2 -0
- package/dist/search/object-search-raw-key-path.d.ts +1 -0
- package/dist/search/omit-search.d.ts +1 -0
- package/dist/search/parse-array-search-value.d.ts +4 -0
- package/dist/search/parse-compiled-search.d.ts +2 -0
- package/dist/search/parse-object-search-value.d.ts +4 -0
- package/dist/search/parse-partial-compiled-search.d.ts +6 -0
- package/dist/search/parse-partial-schema-search.d.ts +6 -0
- package/dist/search/parse-raw-search.d.ts +2 -0
- package/dist/search/parse-search-field-value.d.ts +2 -0
- package/dist/search/parse-search.d.ts +5 -0
- package/dist/search/patch-search.d.ts +6 -0
- package/dist/search/pick-search.d.ts +1 -0
- package/dist/search/replace-search.d.ts +5 -0
- package/dist/search/search-array-format.d.ts +3 -0
- package/dist/search/search-entries.d.ts +4 -0
- package/dist/search/serialize-search-build-value.d.ts +2 -0
- package/dist/search/serialize-search-entries.d.ts +3 -0
- package/dist/static/compile-static-hash.d.ts +3 -0
- package/dist/static/compile-static-search.d.ts +3 -0
- package/dist/static/compile-static-url.d.ts +3 -0
- package/dist/static/contracts.d.ts +81 -0
- package/dist/static/create-static-search-schema.d.ts +3 -0
- package/dist/static/normalize-static-search-default.d.ts +2 -0
- package/dist/static/static-search-field-kind.d.ts +4 -0
- package/dist/static.d.ts +7 -0
- package/dist/static.js +55 -0
- package/dist/static.js.map +1 -0
- package/dist/url/assert-path-match-failure.d.ts +2 -0
- package/dist/url/build-compiled-url.d.ts +3 -0
- package/dist/url/build-url.d.ts +3 -0
- package/dist/url/coerce-path-param.d.ts +2 -0
- package/dist/url/compile-path.d.ts +2 -0
- package/dist/url/compile-runtime-url-descriptor.d.ts +2 -0
- package/dist/url/compile-url-descriptor.d.ts +13 -0
- package/dist/url/contracts.d.ts +91 -0
- package/dist/url/create-unsupported-url-method.d.ts +1 -0
- package/dist/url/create-url-contract.d.ts +3 -0
- package/dist/url/create-url.d.ts +2 -0
- package/dist/url/filter-compiled-url-search.d.ts +4 -0
- package/dist/url/format-parsed-url.d.ts +2 -0
- package/dist/url/match-url.d.ts +3 -0
- package/dist/url/normalize-compiled-url.d.ts +3 -0
- package/dist/url/normalize-path-build-params.d.ts +1 -0
- package/dist/url/normalize-url.d.ts +3 -0
- package/dist/url/parse-compiled-url.d.ts +3 -0
- package/dist/url/parse-path-pattern.d.ts +2 -0
- package/dist/url/parse-request.d.ts +2 -0
- package/dist/url/parse-url.d.ts +6 -0
- package/dist/url/patch-compiled-url-search.d.ts +3 -0
- package/dist/url/path-constraints.d.ts +5 -0
- package/dist/url/path-param-kind.d.ts +3 -0
- package/dist/url/path-segment.d.ts +11 -0
- package/dist/url/register-urlkit-path-constraints.d.ts +1 -0
- package/dist/url/replace-compiled-url-search.d.ts +3 -0
- package/dist/url/resolve-url-unknown-search.d.ts +3 -0
- package/dist/url/url-state-brand.d.ts +7 -0
- package/package.json +73 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ConstraintValidation } from '@cookbook/pathkit';
|
|
2
|
+
import type { UrlKitError } from './errors/url-kit-error.js';
|
|
3
|
+
export type UrlMode = 'path' | 'pathless';
|
|
4
|
+
export type UnknownSearchBehavior = 'strip' | 'preserve' | 'error';
|
|
5
|
+
export type SearchArrayFormat = 'repeat' | 'comma';
|
|
6
|
+
export type UnknownSearchParams = Readonly<Record<string, string | readonly string[]>>;
|
|
7
|
+
export type EmptyParams = Readonly<Record<never, never>>;
|
|
8
|
+
export type PathConstraintMap = Record<string, ConstraintValidation>;
|
|
9
|
+
export interface RegisterPathConstraintOptions {
|
|
10
|
+
readonly overwrite?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface UrlState<Pathname, Params, Search, Hash> {
|
|
13
|
+
readonly pathname: Pathname;
|
|
14
|
+
readonly params: Params;
|
|
15
|
+
readonly search: Search;
|
|
16
|
+
readonly hash: Hash;
|
|
17
|
+
readonly unknownSearch?: UnknownSearchParams;
|
|
18
|
+
}
|
|
19
|
+
export interface UrlRequestInput {
|
|
20
|
+
readonly url: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ParseUrlOptions {
|
|
23
|
+
readonly unknownSearch?: UnknownSearchBehavior;
|
|
24
|
+
readonly arrayFormat?: SearchArrayFormat;
|
|
25
|
+
}
|
|
26
|
+
export interface NormalizeUrlOptions {
|
|
27
|
+
readonly unknownSearch?: UnknownSearchBehavior;
|
|
28
|
+
}
|
|
29
|
+
export interface BuildUrlOptions {
|
|
30
|
+
readonly defaults?: 'include' | 'omit';
|
|
31
|
+
readonly arrayFormat?: SearchArrayFormat;
|
|
32
|
+
}
|
|
33
|
+
export interface BuildSearchOptions extends BuildUrlOptions {
|
|
34
|
+
readonly sortKeys?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface PatchSearchOptions extends BuildSearchOptions {
|
|
37
|
+
readonly removeUndefined?: boolean;
|
|
38
|
+
readonly removeNull?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface ParseRequestOptions extends ParseUrlOptions {
|
|
41
|
+
readonly baseUrl?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface UrlSafeParseSuccess<Pathname, Params, Search, Hash> {
|
|
44
|
+
readonly success: true;
|
|
45
|
+
readonly data: UrlState<Pathname, Params, Search, Hash>;
|
|
46
|
+
}
|
|
47
|
+
export interface UrlSafeParseFailure<ErrorValue extends Error = UrlKitError> {
|
|
48
|
+
readonly success: false;
|
|
49
|
+
readonly error: ErrorValue;
|
|
50
|
+
}
|
|
51
|
+
export type UrlSafeParseResult<Pathname, Params, Search, Hash, ErrorValue extends Error = UrlKitError> = UrlSafeParseSuccess<Pathname, Params, Search, Hash> | UrlSafeParseFailure<ErrorValue>;
|
|
52
|
+
export interface UrlSafeNormalizeSuccess<Mode extends UrlMode, Pathname, Params, Search, Hash, Input> {
|
|
53
|
+
readonly success: true;
|
|
54
|
+
readonly data: NormalizeUrlState<Mode, Pathname, Params, Search, Hash, Input>;
|
|
55
|
+
}
|
|
56
|
+
export type UrlSafeNormalizeResult<Mode extends UrlMode, Pathname, Params, Search, Hash, Input, ErrorValue extends Error = UrlKitError> = UrlSafeNormalizeSuccess<Mode, Pathname, Params, Search, Hash, Input> | UrlSafeParseFailure<ErrorValue>;
|
|
57
|
+
export type PathBasedBuildInputWithParams<Params, Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = {
|
|
58
|
+
readonly pathname?: never;
|
|
59
|
+
readonly params: Params;
|
|
60
|
+
} & SearchInputProperty<SearchInput> & HashInputProperty<HashInput>;
|
|
61
|
+
export type PathBasedBuildInputWithoutParams<Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = {
|
|
62
|
+
readonly pathname?: never;
|
|
63
|
+
readonly params?: never | EmptyParams;
|
|
64
|
+
} & SearchInputProperty<SearchInput> & HashInputProperty<HashInput>;
|
|
65
|
+
export type PathBasedBuildInput<Params, Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = keyof Params extends never ? PathBasedBuildInputWithoutParams<Search, Hash, SearchInput, HashInput> : PathBasedBuildInputWithParams<Params, Search, Hash, SearchInput, HashInput>;
|
|
66
|
+
export type PathlessBuildInput<Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = {
|
|
67
|
+
readonly pathname?: string;
|
|
68
|
+
readonly params?: never;
|
|
69
|
+
} & SearchInputProperty<SearchInput> & HashInputProperty<HashInput>;
|
|
70
|
+
export type UrlBuildInput<Mode extends UrlMode, Params, Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = Mode extends 'path' ? PathBasedBuildInput<Params, Search, Hash, SearchInput, HashInput> : PathlessBuildInput<Search, Hash, SearchInput, HashInput>;
|
|
71
|
+
export type PathBasedNormalizeInputWithParams<Params, Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = {
|
|
72
|
+
readonly pathname?: never;
|
|
73
|
+
readonly params: Params;
|
|
74
|
+
} & SearchInputProperty<SearchInput> & HashInputProperty<HashInput>;
|
|
75
|
+
export type PathBasedNormalizeInputWithoutParams<Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = {
|
|
76
|
+
readonly pathname?: never;
|
|
77
|
+
readonly params?: never | EmptyParams;
|
|
78
|
+
} & SearchInputProperty<SearchInput> & HashInputProperty<HashInput>;
|
|
79
|
+
export type PathBasedNormalizeInput<Params, Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = keyof Params extends never ? PathBasedNormalizeInputWithoutParams<Search, Hash, SearchInput, HashInput> : PathBasedNormalizeInputWithParams<Params, Search, Hash, SearchInput, HashInput>;
|
|
80
|
+
export type PathlessNormalizeInput<Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = {
|
|
81
|
+
readonly pathname?: string;
|
|
82
|
+
readonly params?: never;
|
|
83
|
+
} & SearchInputProperty<SearchInput> & HashInputProperty<HashInput>;
|
|
84
|
+
export type UrlNormalizeInput<Mode extends UrlMode, Params, Search, Hash, SearchInput = Partial<Search>, HashInput = Hash> = Mode extends 'path' ? PathBasedNormalizeInput<Params, Search, Hash, SearchInput, HashInput> : PathlessNormalizeInput<Search, Hash, SearchInput, HashInput>;
|
|
85
|
+
export type SearchInputProperty<SearchInput> = keyof SearchInput extends never ? {
|
|
86
|
+
readonly search?: SearchInput;
|
|
87
|
+
} : RequiredKeys<SearchInput> extends never ? {
|
|
88
|
+
readonly search?: SearchInput;
|
|
89
|
+
} : {
|
|
90
|
+
readonly search: SearchInput;
|
|
91
|
+
};
|
|
92
|
+
export type SearchInputArgument<SearchInput> = RequiredKeys<SearchInput> extends never ? SearchInput | undefined : SearchInput;
|
|
93
|
+
export type HashInputProperty<HashInput> = undefined extends HashInput ? {
|
|
94
|
+
readonly hash?: HashInput;
|
|
95
|
+
} : {
|
|
96
|
+
readonly hash: HashInput;
|
|
97
|
+
};
|
|
98
|
+
export type BuildHashArguments<HashInput> = undefined extends HashInput ? [hash?: HashInput, options?: BuildUrlOptions] : [hash: HashInput, options?: BuildUrlOptions];
|
|
99
|
+
type RequiredKeys<Input> = {
|
|
100
|
+
[Key in keyof Input]-?: EmptyParams extends Pick<Input, Key> ? never : Key;
|
|
101
|
+
}[keyof Input];
|
|
102
|
+
export type NormalizeUrlState<Mode extends UrlMode, Pathname, Params, Search, Hash, Input> = Mode extends 'path' ? UrlState<Pathname, Params, Search, Hash> : UrlState<PathnameFromPathlessNormalizeInput<Input>, EmptyParams, Search, Hash>;
|
|
103
|
+
export type PathnameFromPathlessNormalizeInput<Input> = Input extends {
|
|
104
|
+
readonly pathname?: infer Pathname;
|
|
105
|
+
} ? Pathname extends string ? Pathname : string : string;
|
|
106
|
+
export type PathBuildMethod<Params> = keyof Params extends never ? (params?: never | EmptyParams) => string : (params: Params) => string;
|
|
107
|
+
export {};
|