@typed/router 0.32.0 → 1.0.0-beta.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/README.md +111 -2
- package/dist/AST.d.ts +96 -0
- package/dist/AST.d.ts.map +1 -0
- package/dist/AST.js +32 -0
- package/dist/CurrentRoute.d.ts +18 -0
- package/dist/CurrentRoute.d.ts.map +1 -0
- package/dist/CurrentRoute.js +18 -0
- package/dist/Matcher.d.ts +191 -0
- package/dist/Matcher.d.ts.map +1 -0
- package/dist/Matcher.js +597 -0
- package/dist/Parser.d.ts +96 -0
- package/dist/Parser.d.ts.map +1 -0
- package/dist/Parser.js +1 -0
- package/dist/Path.d.ts +216 -0
- package/dist/Path.d.ts.map +1 -0
- package/dist/Path.js +248 -0
- package/dist/Route.d.ts +57 -0
- package/dist/Route.d.ts.map +1 -0
- package/dist/Route.js +151 -0
- package/dist/Router.d.ts +9 -0
- package/dist/Router.d.ts.map +1 -0
- package/dist/Router.js +8 -0
- package/dist/Uri.d.ts +115 -0
- package/dist/Uri.d.ts.map +1 -0
- package/dist/Uri.js +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/package.json +25 -70
- package/src/AST.ts +166 -0
- package/src/CurrentRoute.ts +30 -331
- package/src/Matcher.test.ts +476 -0
- package/src/Matcher.ts +1269 -328
- package/src/Parser.ts +282 -0
- package/src/Path.test.ts +318 -0
- package/src/Path.ts +691 -0
- package/src/Route.test.ts +268 -0
- package/src/Route.ts +316 -0
- package/src/Router.ts +31 -0
- package/src/Uri.ts +214 -0
- package/src/index.ts +4 -28
- package/tsconfig.json +6 -0
- package/CurrentRoute/package.json +0 -6
- package/LICENSE +0 -21
- package/MatchInput/package.json +0 -6
- package/Matcher/package.json +0 -6
- package/RouteGuard/package.json +0 -6
- package/RouteMatch/package.json +0 -6
- package/dist/cjs/CurrentRoute.js +0 -170
- package/dist/cjs/CurrentRoute.js.map +0 -1
- package/dist/cjs/MatchInput.js +0 -96
- package/dist/cjs/MatchInput.js.map +0 -1
- package/dist/cjs/Matcher.js +0 -138
- package/dist/cjs/Matcher.js.map +0 -1
- package/dist/cjs/RouteGuard.js +0 -78
- package/dist/cjs/RouteGuard.js.map +0 -1
- package/dist/cjs/RouteMatch.js +0 -49
- package/dist/cjs/RouteMatch.js.map +0 -1
- package/dist/cjs/index.js +0 -53
- package/dist/cjs/index.js.map +0 -1
- package/dist/dts/CurrentRoute.d.ts +0 -94
- package/dist/dts/CurrentRoute.d.ts.map +0 -1
- package/dist/dts/MatchInput.d.ts +0 -143
- package/dist/dts/MatchInput.d.ts.map +0 -1
- package/dist/dts/Matcher.d.ts +0 -121
- package/dist/dts/Matcher.d.ts.map +0 -1
- package/dist/dts/RouteGuard.d.ts +0 -94
- package/dist/dts/RouteGuard.d.ts.map +0 -1
- package/dist/dts/RouteMatch.d.ts +0 -50
- package/dist/dts/RouteMatch.d.ts.map +0 -1
- package/dist/dts/index.d.ts +0 -24
- package/dist/dts/index.d.ts.map +0 -1
- package/dist/esm/CurrentRoute.js +0 -152
- package/dist/esm/CurrentRoute.js.map +0 -1
- package/dist/esm/MatchInput.js +0 -79
- package/dist/esm/MatchInput.js.map +0 -1
- package/dist/esm/Matcher.js +0 -130
- package/dist/esm/Matcher.js.map +0 -1
- package/dist/esm/RouteGuard.js +0 -57
- package/dist/esm/RouteGuard.js.map +0 -1
- package/dist/esm/RouteMatch.js +0 -29
- package/dist/esm/RouteMatch.js.map +0 -1
- package/dist/esm/index.js +0 -24
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/package.json +0 -4
- package/src/MatchInput.ts +0 -303
- package/src/RouteGuard.ts +0 -217
- package/src/RouteMatch.ts +0 -104
package/dist/Route.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { pipeArguments } from "effect/Pipeable";
|
|
4
|
+
import { singleton } from "effect/Record";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Parser from "effect/SchemaParser";
|
|
7
|
+
import * as Transformation from "effect/SchemaTransformation";
|
|
8
|
+
import * as AST from "./AST.js";
|
|
9
|
+
import * as Path from "./Path.js";
|
|
10
|
+
export function make(ast) {
|
|
11
|
+
const getParts = once(() => getPathAst(ast));
|
|
12
|
+
const path = once(() => Path.join(getParts()));
|
|
13
|
+
const paramsSchema = once(() => getParamsSchema(ast));
|
|
14
|
+
const pathSchema = once(() => getPathSchema(ast));
|
|
15
|
+
const querySchema = once(() => getQuerySchema(ast));
|
|
16
|
+
return {
|
|
17
|
+
ast,
|
|
18
|
+
get path() {
|
|
19
|
+
return path();
|
|
20
|
+
},
|
|
21
|
+
get paramsSchema() {
|
|
22
|
+
return paramsSchema();
|
|
23
|
+
},
|
|
24
|
+
get pathSchema() {
|
|
25
|
+
return pathSchema();
|
|
26
|
+
},
|
|
27
|
+
get querySchema() {
|
|
28
|
+
return querySchema();
|
|
29
|
+
},
|
|
30
|
+
pipe() {
|
|
31
|
+
return pipeArguments(this, arguments);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function once(fn) {
|
|
36
|
+
let memoized = [];
|
|
37
|
+
return () => {
|
|
38
|
+
if (memoized.length === 1) {
|
|
39
|
+
return memoized[0];
|
|
40
|
+
}
|
|
41
|
+
const result = fn();
|
|
42
|
+
memoized = [result];
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function getPathAst(ast) {
|
|
47
|
+
switch (ast.type) {
|
|
48
|
+
case "path":
|
|
49
|
+
return [ast.path];
|
|
50
|
+
case "transform":
|
|
51
|
+
return getPathAst(ast.from);
|
|
52
|
+
case "join": {
|
|
53
|
+
const result = [];
|
|
54
|
+
for (let i = 0; i < ast.parts.length; i++) {
|
|
55
|
+
if (i > 0) {
|
|
56
|
+
result.push(AST.slash());
|
|
57
|
+
}
|
|
58
|
+
result.push(...getPathAst(ast.parts[i]));
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function getParamsSchema(ast) {
|
|
65
|
+
switch (ast.type) {
|
|
66
|
+
case "path": {
|
|
67
|
+
const { paramsSchema } = Path.getSchemas(getPathAst(ast));
|
|
68
|
+
return paramsSchema;
|
|
69
|
+
}
|
|
70
|
+
case "transform": {
|
|
71
|
+
const { paramsSchema } = Path.getSchemas(getPathAst(ast.from));
|
|
72
|
+
return paramsSchema.pipe(Schema.decodeTo(ast.to, ast.transformation));
|
|
73
|
+
}
|
|
74
|
+
case "join": {
|
|
75
|
+
const parts = ast.parts.map((part) => Path.getSchemaFields(getPathAst(part)));
|
|
76
|
+
const requiredFields = [];
|
|
77
|
+
const optionalFields = [];
|
|
78
|
+
const queryParams = [];
|
|
79
|
+
for (const part of parts) {
|
|
80
|
+
requiredFields.push(...part.requiredFields);
|
|
81
|
+
optionalFields.push(...part.optionalFields);
|
|
82
|
+
queryParams.push(...part.queryParams);
|
|
83
|
+
}
|
|
84
|
+
const pathFields = Object.fromEntries(requiredFields);
|
|
85
|
+
const queryFields = Object.fromEntries(queryParams.map(([name, { optionalFields, requiredFields }]) => [
|
|
86
|
+
name,
|
|
87
|
+
Schema.StructWithRest(Schema.Struct(Object.fromEntries(requiredFields)), optionalFields.map(([key, value]) => Schema.Record(key, value))),
|
|
88
|
+
]));
|
|
89
|
+
const paramsSchema = Schema.StructWithRest(Schema.Struct({ ...pathFields, ...queryFields }), optionalFields.map(([key, value]) => Schema.Record(key, value)));
|
|
90
|
+
return paramsSchema;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function getPathSchema(ast) {
|
|
95
|
+
if (ast.type !== "join")
|
|
96
|
+
return Path.getSchemas(getPathAst(ast)).pathSchema;
|
|
97
|
+
const parts = ast.parts.map((part) => Path.getSchemaFields(getPathAst(part)));
|
|
98
|
+
const requiredFields = [];
|
|
99
|
+
const optionalFields = [];
|
|
100
|
+
for (const part of parts) {
|
|
101
|
+
requiredFields.push(...part.requiredFields);
|
|
102
|
+
optionalFields.push(...part.optionalFields);
|
|
103
|
+
}
|
|
104
|
+
const pathFields = Object.fromEntries(requiredFields);
|
|
105
|
+
return Schema.StructWithRest(Schema.Struct(pathFields), optionalFields.map(([key, value]) => Schema.Record(key, value)));
|
|
106
|
+
}
|
|
107
|
+
function getQuerySchema(ast) {
|
|
108
|
+
if (ast.type !== "join")
|
|
109
|
+
return Path.getSchemas(getPathAst(ast)).querySchema;
|
|
110
|
+
const parts = ast.parts.map((part) => Path.getSchemaFields(getPathAst(part)));
|
|
111
|
+
const queryParams = [];
|
|
112
|
+
for (const part of parts) {
|
|
113
|
+
queryParams.push(...part.queryParams);
|
|
114
|
+
}
|
|
115
|
+
const queryFields = Object.fromEntries(queryParams.map(([name, { optionalFields, requiredFields }]) => [
|
|
116
|
+
name,
|
|
117
|
+
Schema.StructWithRest(Schema.Struct(Object.fromEntries(requiredFields)), optionalFields.map(([key, value]) => Schema.Record(key, value))),
|
|
118
|
+
]));
|
|
119
|
+
return Schema.Struct(queryFields);
|
|
120
|
+
}
|
|
121
|
+
export const Parse = (path) => {
|
|
122
|
+
const asts = Path.parse(path);
|
|
123
|
+
if (asts.length === 0)
|
|
124
|
+
return Slash;
|
|
125
|
+
if (asts.length === 1)
|
|
126
|
+
return make(AST.path(asts[0]));
|
|
127
|
+
return Join(...asts.map((ast) => make(AST.path(ast))));
|
|
128
|
+
};
|
|
129
|
+
export const Slash = make(AST.path(AST.literal("")));
|
|
130
|
+
export const Wildcard = make(AST.path(AST.wildcard()));
|
|
131
|
+
export const Param = (paramName) => make(AST.path(AST.parameter(paramName)));
|
|
132
|
+
export const ParamWithSchema = (paramName, schema) => {
|
|
133
|
+
const decode = Parser.decodeEffect(schema);
|
|
134
|
+
const encode = Parser.encodeEffect(schema);
|
|
135
|
+
return make(AST.transform(AST.path(AST.parameter(paramName)), Schema.Struct(singleton(paramName, schema.Type)), Transformation.transformOrFail({
|
|
136
|
+
decode: (input) => Effect.map(decode(input[paramName]), (decoded) => singleton(paramName, decoded)),
|
|
137
|
+
encode: (output) => Effect.map(encode(output[paramName]), (encoded) => singleton(paramName, encoded)),
|
|
138
|
+
})));
|
|
139
|
+
};
|
|
140
|
+
export const Number = (paramName) => ParamWithSchema(paramName, Schema.NumberFromString);
|
|
141
|
+
export const Int = (paramName) => ParamWithSchema(paramName, Schema.NumberFromString.pipe(Schema.decodeTo(Schema.Int)));
|
|
142
|
+
const removeSlash = (ast) => {
|
|
143
|
+
if (ast.type === "path" && ast.path.type === "slash")
|
|
144
|
+
return [];
|
|
145
|
+
return [ast];
|
|
146
|
+
};
|
|
147
|
+
export const Join = (...routes) => make(AST.join(routes.flatMap((route) => {
|
|
148
|
+
if (Array.isArray(route))
|
|
149
|
+
return route.flatMap(removeSlash);
|
|
150
|
+
return removeSlash(route.ast);
|
|
151
|
+
})));
|
package/dist/Router.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as Layer from "effect/Layer";
|
|
2
|
+
import { type InitialMemoryOptions, type MemoryOptions } from "@typed/navigation/memory";
|
|
3
|
+
import type { Navigation } from "@typed/navigation/Navigation";
|
|
4
|
+
import { CurrentRoute } from "./CurrentRoute.js";
|
|
5
|
+
export type Router = CurrentRoute | Navigation;
|
|
6
|
+
export declare const BrowserRouter: (window?: Window) => Layer.Layer<Router>;
|
|
7
|
+
export declare const ServerRouter: (options: MemoryOptions | InitialMemoryOptions) => Layer.Layer<Router>;
|
|
8
|
+
export declare const TestRouter: (options: (MemoryOptions | InitialMemoryOptions) & {}) => Layer.Layer<Router>;
|
|
9
|
+
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,UAAU,CAAC;AAE/C,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,KAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAI/D,CAAC;AAEJ,eAAO,MAAM,YAAY,GAAI,SAAS,aAAa,GAAG,oBAAoB,KAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAI5F,CAAC;AAEJ,eAAO,MAAM,UAAU,GAAI,SAAS,CAAC,aAAa,GAAG,oBAAoB,CAAC,GAAG,EAAE,KAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAIjG,CAAC"}
|
package/dist/Router.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as Layer from "effect/Layer";
|
|
2
|
+
import { fromWindow } from "@typed/navigation/fromWindow";
|
|
3
|
+
import { initialMemory, memory, } from "@typed/navigation/memory";
|
|
4
|
+
import { CurrentRoute } from "./CurrentRoute.js";
|
|
5
|
+
import { Ids } from "@typed/id";
|
|
6
|
+
export const BrowserRouter = (window) => CurrentRoute.Default.pipe(Layer.provideMerge(fromWindow(window)), Layer.provideMerge(Ids.Default));
|
|
7
|
+
export const ServerRouter = (options) => CurrentRoute.Default.pipe(Layer.provideMerge("url" in options ? initialMemory(options) : memory(options)), Layer.provideMerge(Ids.Default));
|
|
8
|
+
export const TestRouter = (options) => CurrentRoute.Default.pipe(Layer.provideMerge("url" in options ? initialMemory(options) : memory(options)), Layer.provideMerge(Ids.Test()));
|
package/dist/Uri.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Arg0, Call1W, Identity, Pipe, TypeLambda, TypeLambda1 } from "hkt-core";
|
|
2
|
+
/**
|
|
3
|
+
* @since 1.0.0
|
|
4
|
+
*/
|
|
5
|
+
export type ParseUri<Input extends string, BaseUri extends string = never> = Pipe<Input, ParseUriLambda, [
|
|
6
|
+
BaseUri
|
|
7
|
+
] extends [never] ? Identity : ApplyBaseUriLambda<ParseUri<BaseUri>>> extends infer R ? Uri<GetUriKey<R, "protocol">, GetUriKey<R, "username">, GetUriKey<R, "password">, GetUriKey<R, "hostname">, GetUriKey<R, "port">, GetUriKey<R, "pathname">, GetUriKey<R, "query">, GetUriKey<R, "hash">> : never;
|
|
8
|
+
/**
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
export interface Uri<Protocol extends string = string, Username extends string = "", Password extends string = "", Hostname extends string = string, Port extends number | "" = "", Pathname extends string = "/", Query extends string = "", Hash extends string = ""> {
|
|
12
|
+
readonly protocol: Protocol;
|
|
13
|
+
readonly username: Username;
|
|
14
|
+
readonly password: Password;
|
|
15
|
+
readonly hostname: Hostname;
|
|
16
|
+
readonly port: Port;
|
|
17
|
+
readonly pathname: Pathname;
|
|
18
|
+
readonly query: Query;
|
|
19
|
+
readonly hash: Hash;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export declare namespace Uri {
|
|
25
|
+
type Any = Uri<string, string, string, string, number | "", string, string, string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
export type FormatUri<Uri extends Uri.Any, BaseUri extends string = never> = Call1W<FormatUrlLambda, [
|
|
31
|
+
BaseUri
|
|
32
|
+
] extends [never] ? Uri : Call1W<ApplyBaseUriLambda<ParseUri<BaseUri>>, Uri>>;
|
|
33
|
+
interface FormatUrlLambda extends TypeLambda1 {
|
|
34
|
+
readonly return: Arg0<this> extends infer Uri extends Uri.Any ? StringJoin<[
|
|
35
|
+
FormatProtocol<Uri["protocol"]>,
|
|
36
|
+
FormatAuthentication<Uri["username"], Uri["password"]>,
|
|
37
|
+
FormatHostname<Uri["hostname"]>,
|
|
38
|
+
FormatPort<Uri["port"]>,
|
|
39
|
+
FormatPathname<Uri["pathname"]>,
|
|
40
|
+
FormatQuery<Uri["query"]>,
|
|
41
|
+
FormatHash<Uri["hash"]>
|
|
42
|
+
]> : never;
|
|
43
|
+
}
|
|
44
|
+
type IfNotEmpty<T, Then> = IsEmpty<T> extends 1 ? "" : Then;
|
|
45
|
+
type FormatProtocol<Protocol extends string> = IfNotEmpty<Protocol, EnsureEndsWithDoubleSlash<EnsureEndsWithColon<Protocol>>>;
|
|
46
|
+
type EnsureEndsWithColon<T extends string> = `${T extends `${infer Rest}:` ? Rest : T}:`;
|
|
47
|
+
type EnsureEndsWithDoubleSlash<T extends string> = T extends `${infer Rest}//` ? Rest : T extends `${infer Rest}/` ? `${Rest}//` : `${T}//`;
|
|
48
|
+
type FormatAuthentication<Username extends string, Password extends string> = {
|
|
49
|
+
0: `${Username}:${Password}@`;
|
|
50
|
+
1: "";
|
|
51
|
+
}[IsEmpty<Username> & IsEmpty<Password>];
|
|
52
|
+
type FormatHostname<Hostname extends string> = IfNotEmpty<Hostname, Hostname>;
|
|
53
|
+
type FormatPort<Port extends number | ""> = IfNotEmpty<Port, EnsureStartsWithColon<`${Port}`>>;
|
|
54
|
+
type EnsureStartsWithColon<T extends string> = T extends `:${infer _}` ? T : `:${T}`;
|
|
55
|
+
type FormatPathname<Pathname extends string> = IfNotEmpty<Pathname, EnsureStartsWithSlash<`${Pathname}`>>;
|
|
56
|
+
type EnsureStartsWithSlash<T extends string> = T extends `/${infer _}` ? T : `/${T}`;
|
|
57
|
+
type FormatQuery<Query extends string> = IfNotEmpty<Query, EnsureStartsWithQuestionMark<`${Query}`>>;
|
|
58
|
+
type EnsureStartsWithQuestionMark<T extends string> = T extends `?${infer _}` ? T : `?${T}`;
|
|
59
|
+
type FormatHash<Hash extends string> = IfNotEmpty<Hash, EnsureStartsWithHash<`${Hash}`>>;
|
|
60
|
+
type EnsureStartsWithHash<T extends string> = T extends `#${infer _}` ? T : `#${T}`;
|
|
61
|
+
type IsEmpty<T> = [T] extends [""] ? 1 : [T] extends [never] ? 1 : 0;
|
|
62
|
+
type GetUriKey<UriLike, Key extends keyof Uri> = Key extends keyof UriLike ? UriLike[Key] extends Uri.Any[Key] ? UriLike[Key] : Uri[Key] : Uri[Key];
|
|
63
|
+
interface ParseUriLambda extends TypeLambda<[uri: string], Uri> {
|
|
64
|
+
return: Arg0<this> extends infer R ? Pipe<[
|
|
65
|
+
{},
|
|
66
|
+
R
|
|
67
|
+
], UriParserReducerLambda<ParseHashLambda>, UriParserReducerLambda<ParseQueryLambda>, UriParserReducerLambda<ParseProtocolLambda>, UriParserReducerLambda<ParseAuthenticationLambda>, UriParserReducerLambda<ParsePathnamePortPathnameLambda>> extends readonly [infer Result, infer Remaining extends string] ? Remaining extends "" ? Result : `Failed to parse URI: ${Arg0<this>}` : never : never;
|
|
68
|
+
}
|
|
69
|
+
interface UriParserReducerLambda<F extends TypeLambda> extends TypeLambda {
|
|
70
|
+
return: Arg0<this> extends readonly [infer State, infer Input extends string] ? Pipe<Input, F> extends readonly [infer NextState, infer Remaining extends string] ? [NextState & State, Remaining] : never : never;
|
|
71
|
+
}
|
|
72
|
+
interface ParseProtocolLambda extends TypeLambda {
|
|
73
|
+
readonly return: Arg0<this> extends `${infer Protocol}//${infer Rest}` ? [{
|
|
74
|
+
readonly protocol: Protocol;
|
|
75
|
+
}, Rest] : [unknown, Arg0<this>];
|
|
76
|
+
}
|
|
77
|
+
interface ParseHashLambda extends TypeLambda {
|
|
78
|
+
readonly return: Arg0<this> extends `${infer Rest}#${infer Hash}` ? [{
|
|
79
|
+
readonly hash: Hash;
|
|
80
|
+
}, Rest] : [unknown, Arg0<this>];
|
|
81
|
+
}
|
|
82
|
+
interface ParseQueryLambda extends TypeLambda {
|
|
83
|
+
readonly return: Arg0<this> extends `${infer Rest}?${infer Query}` ? [{
|
|
84
|
+
readonly query: Query;
|
|
85
|
+
}, Rest] : [unknown, Arg0<this>];
|
|
86
|
+
}
|
|
87
|
+
interface ParseAuthenticationLambda extends TypeLambda {
|
|
88
|
+
readonly return: Arg0<this> extends `${infer Username}:${infer Password}@${infer Rest}` ? [{
|
|
89
|
+
readonly username: Username;
|
|
90
|
+
readonly password: Password;
|
|
91
|
+
}, Rest] : [unknown, Arg0<this>];
|
|
92
|
+
}
|
|
93
|
+
interface ParsePathnamePortPathnameLambda extends TypeLambda {
|
|
94
|
+
readonly return: Arg0<this> extends `${infer Hostname}:${infer Port extends number}/${infer Pathname}` ? [{
|
|
95
|
+
readonly hostname: Hostname;
|
|
96
|
+
readonly port: Port;
|
|
97
|
+
readonly pathname: Pathname;
|
|
98
|
+
}, ""] : Arg0<this> extends `${infer Hostname}:${infer Port extends number}` ? [{
|
|
99
|
+
readonly hostname: Hostname;
|
|
100
|
+
readonly port: Port;
|
|
101
|
+
}, ""] : Arg0<this> extends `${infer Hostname}/${infer Pathname}` ? "" extends Hostname ? [{
|
|
102
|
+
readonly pathname: Pathname;
|
|
103
|
+
}, ""] : [{
|
|
104
|
+
readonly hostname: Hostname;
|
|
105
|
+
readonly pathname: Pathname;
|
|
106
|
+
}, ""] : Arg0<this> extends `${infer Hostname}` ? [{
|
|
107
|
+
readonly hostname: Hostname;
|
|
108
|
+
}, ""] : [unknown, Arg0<this>];
|
|
109
|
+
}
|
|
110
|
+
interface ApplyBaseUriLambda<BaseUri extends Uri.Any> extends TypeLambda1<Uri.Any, Uri.Any> {
|
|
111
|
+
readonly return: Arg0<this> extends infer R extends Uri.Any ? Uri<GetUriKey<BaseUri, "protocol">, GetUriKey<BaseUri, "username">, GetUriKey<BaseUri, "password">, GetUriKey<BaseUri, "hostname">, GetUriKey<BaseUri, "port">, GetUriKey<R, "pathname">, GetUriKey<R, "query">, GetUriKey<R, "hash">> : never;
|
|
112
|
+
}
|
|
113
|
+
type StringJoin<Input extends ReadonlyArray<string>, R extends string = ""> = Input extends readonly [infer A extends string, ...infer Rest extends ReadonlyArray<string>] ? StringJoin<Rest, `${R}${A}`> : R;
|
|
114
|
+
export {};
|
|
115
|
+
//# sourceMappingURL=Uri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uri.d.ts","sourceRoot":"","sources":["../src/Uri.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtF;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,GAAG,KAAK,IACvE,IAAI,CACF,KAAK,EACL,cAAc,EACd;IAAC,OAAO;CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAC7E,SAAS,MAAM,CAAC,GACb,GAAG,CACD,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,EACxB,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,EACxB,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,EACxB,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,EACxB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,EACpB,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,EACxB,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,EACrB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CACrB,GACD,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,GAAG,CAClB,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,QAAQ,SAAS,MAAM,GAAG,EAAE,EAC5B,QAAQ,SAAS,MAAM,GAAG,EAAE,EAC5B,QAAQ,SAAS,MAAM,GAAG,MAAM,EAChC,IAAI,SAAS,MAAM,GAAG,EA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CAAC,EAC9B,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,EAC9B,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,EAC9B,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,EAC9B,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,EAC1B,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,EACxB,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,EACrB,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CACrB,GACD,KAAK,CAAC;CACX;AAED,KAAK,UAAU,CACb,KAAK,SAAS,aAAa,CAAC,MAAM,CAAC,EACnC,CAAC,SAAS,MAAM,GAAG,EAAE,IACnB,KAAK,SAAS,SAAS,CAAC,MAAM,CAAC,SAAS,MAAM,EAAE,GAAG,MAAM,IAAI,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAC5F,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAC5B,CAAC,CAAC"}
|
package/dist/Uri.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,80 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/router",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/tylors/typed.git"
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
9
6
|
},
|
|
10
|
-
"
|
|
11
|
-
"author": "Typed contributors",
|
|
12
|
-
"homepage": "https://github.com/tylors/typed",
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"@effect/schema": "^0.74.1",
|
|
15
|
-
"effect": "^3.8.4",
|
|
16
|
-
"@typed/context": "0.30.0",
|
|
17
|
-
"@typed/dom": "18.0.0",
|
|
18
|
-
"@typed/environment": "0.11.0",
|
|
19
|
-
"@typed/fx": "1.32.0",
|
|
20
|
-
"@typed/guard": "0.6.0",
|
|
21
|
-
"@typed/navigation": "0.18.0",
|
|
22
|
-
"@typed/path": "0.15.0",
|
|
23
|
-
"@typed/route": "9.0.0"
|
|
24
|
-
},
|
|
25
|
-
"main": "./dist/cjs/index.js",
|
|
26
|
-
"module": "./dist/esm/index.js",
|
|
27
|
-
"types": "./dist/dts/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
28
8
|
"exports": {
|
|
29
|
-
"./package.json": "./package.json",
|
|
30
9
|
".": {
|
|
31
|
-
"types": "./dist/
|
|
32
|
-
"import": "./dist/
|
|
33
|
-
"default": "./dist/cjs/index.js"
|
|
34
|
-
},
|
|
35
|
-
"./CurrentRoute": {
|
|
36
|
-
"types": "./dist/dts/CurrentRoute.d.ts",
|
|
37
|
-
"import": "./dist/esm/CurrentRoute.js",
|
|
38
|
-
"default": "./dist/cjs/CurrentRoute.js"
|
|
39
|
-
},
|
|
40
|
-
"./MatchInput": {
|
|
41
|
-
"types": "./dist/dts/MatchInput.d.ts",
|
|
42
|
-
"import": "./dist/esm/MatchInput.js",
|
|
43
|
-
"default": "./dist/cjs/MatchInput.js"
|
|
44
|
-
},
|
|
45
|
-
"./Matcher": {
|
|
46
|
-
"types": "./dist/dts/Matcher.d.ts",
|
|
47
|
-
"import": "./dist/esm/Matcher.js",
|
|
48
|
-
"default": "./dist/cjs/Matcher.js"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
49
12
|
},
|
|
50
|
-
"
|
|
51
|
-
"types": "./dist
|
|
52
|
-
"import": "./dist
|
|
53
|
-
"default": "./dist/cjs/RouteGuard.js"
|
|
54
|
-
},
|
|
55
|
-
"./RouteMatch": {
|
|
56
|
-
"types": "./dist/dts/RouteMatch.d.ts",
|
|
57
|
-
"import": "./dist/esm/RouteMatch.js",
|
|
58
|
-
"default": "./dist/cjs/RouteMatch.js"
|
|
13
|
+
"./*": {
|
|
14
|
+
"types": "./dist/*.d.ts",
|
|
15
|
+
"import": "./dist/*.js"
|
|
59
16
|
}
|
|
60
17
|
},
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
]
|
|
78
|
-
}
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"effect": "4.0.0-beta.4",
|
|
20
|
+
"find-my-way-ts": "0.1.6",
|
|
21
|
+
"hkt-core": "1.3.4",
|
|
22
|
+
"@typed/guard": "1.0.0-beta.0",
|
|
23
|
+
"@typed/fx": "2.0.0-beta.0",
|
|
24
|
+
"@typed/id": "1.0.0-beta.0",
|
|
25
|
+
"@typed/navigation": "1.0.0-beta.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "5.9.3",
|
|
29
|
+
"vitest": "4.0.18"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"test": "vitest run --passWithNoTests"
|
|
79
34
|
}
|
|
80
35
|
}
|
package/src/AST.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { Cause } from "effect/Cause";
|
|
2
|
+
import { succeedSome } from "effect/Effect";
|
|
3
|
+
import type { Top } from "effect/Schema";
|
|
4
|
+
import type { Transformation } from "effect/SchemaTransformation";
|
|
5
|
+
import type { Fx } from "@typed/fx/Fx";
|
|
6
|
+
import type { RefSubject } from "@typed/fx/RefSubject/RefSubject";
|
|
7
|
+
import type { Guard } from "@typed/guard";
|
|
8
|
+
import type { AnyLayer, Layout as LayoutType, MatchHandler } from "./Matcher.js";
|
|
9
|
+
|
|
10
|
+
export type PathAst =
|
|
11
|
+
| PathAst.Literal
|
|
12
|
+
| PathAst.Parameter
|
|
13
|
+
| PathAst.Slash
|
|
14
|
+
| PathAst.Wildcard
|
|
15
|
+
| PathAst.QueryParams;
|
|
16
|
+
|
|
17
|
+
export declare namespace PathAst {
|
|
18
|
+
export type Literal = {
|
|
19
|
+
type: "literal";
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
export type Parameter = {
|
|
23
|
+
type: "parameter";
|
|
24
|
+
name: string;
|
|
25
|
+
optional?: boolean;
|
|
26
|
+
regex?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Wildcard = {
|
|
30
|
+
type: "wildcard";
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type Slash = {
|
|
34
|
+
type: "slash";
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type QueryParams = {
|
|
38
|
+
type: "query-params";
|
|
39
|
+
value: ReadonlyArray<PathAst.QueryParam>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type QueryParam = {
|
|
43
|
+
type: "query-param";
|
|
44
|
+
name: string;
|
|
45
|
+
value: PathAst;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const literal = (value: string): PathAst.Literal => ({ type: "literal", value });
|
|
50
|
+
export const parameter = (name: string, optional?: boolean, regex?: string): PathAst.Parameter => ({
|
|
51
|
+
type: "parameter",
|
|
52
|
+
name,
|
|
53
|
+
...(optional ? { optional } : {}),
|
|
54
|
+
...(regex ? { regex } : {}),
|
|
55
|
+
});
|
|
56
|
+
export const wildcard = (): PathAst.Wildcard => ({ type: "wildcard" });
|
|
57
|
+
export const slash = (): PathAst.Slash => ({ type: "slash" });
|
|
58
|
+
export const queryParams = (value: ReadonlyArray<PathAst.QueryParam>): PathAst.QueryParams => ({
|
|
59
|
+
type: "query-params",
|
|
60
|
+
value,
|
|
61
|
+
});
|
|
62
|
+
export const queryParam = (name: string, value: PathAst): PathAst.QueryParam => ({
|
|
63
|
+
type: "query-param",
|
|
64
|
+
name,
|
|
65
|
+
value,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export type RouteAst = RouteAst.Path | RouteAst.Transform | RouteAst.Join;
|
|
69
|
+
|
|
70
|
+
export declare namespace RouteAst {
|
|
71
|
+
export interface Path {
|
|
72
|
+
type: "path";
|
|
73
|
+
path: PathAst;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface Transform {
|
|
77
|
+
type: "transform";
|
|
78
|
+
from: RouteAst;
|
|
79
|
+
to: Top;
|
|
80
|
+
transformation: Transformation<any, any, any, any>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface Join {
|
|
84
|
+
type: "join";
|
|
85
|
+
parts: ReadonlyArray<RouteAst>;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const path = (path: PathAst): RouteAst.Path => ({ type: "path", path });
|
|
90
|
+
export const transform = (
|
|
91
|
+
from: RouteAst,
|
|
92
|
+
to: Top,
|
|
93
|
+
transformation: Transformation<any, any, any, any>,
|
|
94
|
+
): RouteAst.Transform => ({
|
|
95
|
+
type: "transform",
|
|
96
|
+
from,
|
|
97
|
+
to,
|
|
98
|
+
transformation,
|
|
99
|
+
});
|
|
100
|
+
export const join = (parts: ReadonlyArray<RouteAst>): RouteAst.Join => ({ type: "join", parts });
|
|
101
|
+
|
|
102
|
+
export type MatchAst =
|
|
103
|
+
| MatchAst.Route
|
|
104
|
+
| MatchAst.Layer
|
|
105
|
+
| MatchAst.Layout
|
|
106
|
+
| MatchAst.Prefixed
|
|
107
|
+
| MatchAst.Catch;
|
|
108
|
+
|
|
109
|
+
export declare namespace MatchAst {
|
|
110
|
+
export interface Route {
|
|
111
|
+
type: "route";
|
|
112
|
+
route: RouteAst;
|
|
113
|
+
guard: Guard<any, any, any, any>;
|
|
114
|
+
handler: MatchHandler<any, any, any, any>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface Layer {
|
|
118
|
+
type: "layer";
|
|
119
|
+
matches: ReadonlyArray<MatchAst>;
|
|
120
|
+
deps: ReadonlyArray<AnyLayer>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface Layout {
|
|
124
|
+
type: "layout";
|
|
125
|
+
matches: ReadonlyArray<MatchAst>;
|
|
126
|
+
layout: LayoutType<any, any, any, any, any, any, any>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface Prefixed {
|
|
130
|
+
type: "prefixed";
|
|
131
|
+
matches: ReadonlyArray<MatchAst>;
|
|
132
|
+
prefix: RouteAst;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface Catch {
|
|
136
|
+
type: "catch";
|
|
137
|
+
matches: ReadonlyArray<MatchAst>;
|
|
138
|
+
f: (cause: RefSubject<Cause<any>>) => Fx<any, any, any>;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const route = (
|
|
143
|
+
route: RouteAst,
|
|
144
|
+
handler: MatchHandler<any, any, any, any>,
|
|
145
|
+
guard: Guard<any, any, any, any> = succeedSome,
|
|
146
|
+
): MatchAst.Route => ({ type: "route", route, guard, handler });
|
|
147
|
+
|
|
148
|
+
export const layer = (
|
|
149
|
+
matches: ReadonlyArray<MatchAst>,
|
|
150
|
+
deps: ReadonlyArray<AnyLayer>,
|
|
151
|
+
): MatchAst.Layer => ({ type: "layer", matches, deps });
|
|
152
|
+
|
|
153
|
+
export const layout = (
|
|
154
|
+
matches: ReadonlyArray<MatchAst>,
|
|
155
|
+
layout: LayoutType<any, any, any, any, any, any, any>,
|
|
156
|
+
): MatchAst.Layout => ({ type: "layout", matches, layout });
|
|
157
|
+
|
|
158
|
+
export const prefixed = (
|
|
159
|
+
matches: ReadonlyArray<MatchAst>,
|
|
160
|
+
prefix: RouteAst,
|
|
161
|
+
): MatchAst.Prefixed => ({ type: "prefixed", matches, prefix });
|
|
162
|
+
|
|
163
|
+
export const catchCause = (
|
|
164
|
+
matches: ReadonlyArray<MatchAst>,
|
|
165
|
+
f: (cause: RefSubject<Cause<any>>) => Fx<any, any, any>,
|
|
166
|
+
): MatchAst.Catch => ({ type: "catch", matches, f });
|