effect-start 0.21.0 → 0.22.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 +1 -4
- package/dist/Cookies.js +392 -0
- package/dist/FileSystem.js +131 -0
- package/dist/Socket.js +37 -0
- package/package.json +35 -36
- package/src/Commander.ts +73 -130
- package/src/ContentNegotiation.ts +64 -95
- package/src/Cookies.ts +36 -57
- package/src/Development.ts +47 -62
- package/src/Effectify.ts +222 -206
- package/src/Entity.ts +59 -86
- package/src/FilePathPattern.ts +5 -5
- package/src/FileRouter.ts +37 -62
- package/src/FileRouterCodegen.ts +63 -55
- package/src/FileSystem.ts +46 -59
- package/src/Http.ts +17 -50
- package/src/PathPattern.ts +33 -41
- package/src/PlatformError.ts +29 -50
- package/src/PlatformRuntime.ts +39 -47
- package/src/Route.ts +68 -187
- package/src/RouteBody.ts +45 -161
- package/src/RouteHook.ts +22 -45
- package/src/RouteHttp.ts +88 -142
- package/src/RouteHttpTracer.ts +25 -26
- package/src/RouteMount.ts +100 -238
- package/src/RouteSchema.ts +67 -201
- package/src/RouteSse.ts +28 -82
- package/src/RouteTree.ts +31 -79
- package/src/RouteTrie.ts +13 -32
- package/src/SchemaExtra.ts +3 -5
- package/src/Socket.ts +5 -2
- package/src/Start.ts +20 -21
- package/src/StreamExtra.ts +93 -96
- package/src/TuplePathPattern.ts +54 -43
- package/src/Unique.ts +9 -15
- package/src/Values.ts +26 -30
- package/src/bun/BunBundle.ts +27 -73
- package/src/bun/BunImportTrackerPlugin.ts +67 -65
- package/src/bun/BunRoute.ts +12 -31
- package/src/bun/BunRuntime.ts +3 -10
- package/src/bun/BunServer.ts +55 -91
- package/src/bun/BunVirtualFilesPlugin.ts +1 -4
- package/src/bun/_BunEnhancedResolve.ts +17 -42
- package/src/bun/_empty.html +0 -1
- package/src/bundler/Bundle.ts +20 -36
- package/src/bundler/BundleFiles.ts +35 -55
- package/src/client/Overlay.ts +1 -2
- package/src/client/ScrollState.ts +5 -9
- package/src/client/index.ts +10 -13
- package/src/datastar/actions/fetch.ts +29 -48
- package/src/datastar/actions/peek.ts +1 -5
- package/src/datastar/actions/setAll.ts +2 -2
- package/src/datastar/actions/toggleAll.ts +2 -2
- package/src/datastar/attributes/attr.ts +17 -18
- package/src/datastar/attributes/bind.ts +41 -61
- package/src/datastar/attributes/class.ts +2 -5
- package/src/datastar/attributes/computed.ts +2 -10
- package/src/datastar/attributes/effect.ts +1 -2
- package/src/datastar/attributes/indicator.ts +2 -8
- package/src/datastar/attributes/init.ts +2 -10
- package/src/datastar/attributes/jsonSignals.ts +1 -6
- package/src/datastar/attributes/on.ts +4 -13
- package/src/datastar/attributes/onIntersect.ts +10 -22
- package/src/datastar/attributes/onInterval.ts +2 -10
- package/src/datastar/attributes/onSignalPatch.ts +18 -28
- package/src/datastar/attributes/ref.ts +1 -2
- package/src/datastar/attributes/show.ts +1 -2
- package/src/datastar/attributes/signals.ts +1 -5
- package/src/datastar/attributes/style.ts +6 -12
- package/src/datastar/attributes/text.ts +1 -2
- package/src/datastar/engine.ts +102 -158
- package/src/datastar/index.ts +2 -2
- package/src/datastar/utils.ts +16 -51
- package/src/datastar/watchers/patchElements.ts +35 -93
- package/src/datastar/watchers/patchSignals.ts +1 -2
- package/src/experimental/EncryptedCookies.ts +79 -142
- package/src/hyper/Hyper.ts +14 -33
- package/src/hyper/HyperHtml.ts +9 -10
- package/src/hyper/HyperNode.ts +2 -7
- package/src/hyper/HyperRoute.ts +2 -5
- package/src/hyper/jsx-runtime.ts +2 -10
- package/src/hyper/jsx.d.ts +171 -440
- package/src/lint/plugin.js +276 -0
- package/src/node/NodeFileSystem.ts +138 -186
- package/src/node/NodeUtils.ts +1 -3
- package/src/testing/TestLogger.ts +9 -22
- package/src/testing/utils.ts +30 -31
- package/src/x/cloudflare/CloudflareTunnel.ts +37 -54
- package/src/x/datastar/Datastar.ts +3 -10
- package/src/x/datastar/index.ts +1 -3
- package/src/x/datastar/jsx-datastar.d.ts +1 -4
- package/src/x/tailwind/TailwindPlugin.ts +119 -112
- package/src/x/tailwind/compile.ts +10 -33
- package/src/x/tailwind/plugin.ts +2 -2
package/src/PlatformError.ts
CHANGED
|
@@ -7,29 +7,18 @@ import * as Predicate from "effect/Predicate"
|
|
|
7
7
|
import * as Schema from "effect/Schema"
|
|
8
8
|
import type * as Types from "effect/Types"
|
|
9
9
|
|
|
10
|
-
export const TypeId: unique symbol = Symbol.for(
|
|
11
|
-
"@effect/platform/Error/PlatformError",
|
|
12
|
-
)
|
|
10
|
+
export const TypeId: unique symbol = Symbol.for("@effect/platform/Error/PlatformError")
|
|
13
11
|
|
|
14
12
|
export type TypeId = typeof TypeId
|
|
15
13
|
|
|
16
|
-
export const isPlatformError = (u: unknown): u is PlatformError =>
|
|
17
|
-
Predicate.hasProperty(u, TypeId)
|
|
14
|
+
export const isPlatformError = (u: unknown): u is PlatformError => Predicate.hasProperty(u, TypeId)
|
|
18
15
|
|
|
19
|
-
export const TypeIdError = <
|
|
20
|
-
const TypeId extends symbol,
|
|
21
|
-
const Tag extends string,
|
|
22
|
-
>(
|
|
16
|
+
export const TypeIdError = <const TypeId extends symbol, const Tag extends string>(
|
|
23
17
|
typeId: TypeId,
|
|
24
18
|
tag: Tag,
|
|
25
|
-
): new<A extends Record<string, any>>(
|
|
19
|
+
): (new <A extends Record<string, any>>(
|
|
26
20
|
args: Types.Simplify<A>,
|
|
27
|
-
) =>
|
|
28
|
-
& Cause.YieldableError
|
|
29
|
-
& Record<TypeId, TypeId>
|
|
30
|
-
& { readonly _tag: Tag }
|
|
31
|
-
& Readonly<A> =>
|
|
32
|
-
{
|
|
21
|
+
) => Cause.YieldableError & Record<TypeId, TypeId> & { readonly _tag: Tag } & Readonly<A>) => {
|
|
33
22
|
class Base extends Data.Error<{}> {
|
|
34
23
|
readonly _tag = tag
|
|
35
24
|
}
|
|
@@ -48,23 +37,18 @@ export const Module = Schema.Literal(
|
|
|
48
37
|
"Terminal",
|
|
49
38
|
)
|
|
50
39
|
|
|
51
|
-
export class BadArgument
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
)
|
|
61
|
-
{
|
|
40
|
+
export class BadArgument extends Schema.TaggedError<BadArgument>(
|
|
41
|
+
"@effect/platform/Error/BadArgument",
|
|
42
|
+
)("BadArgument", {
|
|
43
|
+
module: Module,
|
|
44
|
+
method: Schema.String,
|
|
45
|
+
description: Schema.optional(Schema.String),
|
|
46
|
+
cause: Schema.optional(Schema.Defect),
|
|
47
|
+
}) {
|
|
62
48
|
readonly [TypeId]: typeof TypeId = TypeId
|
|
63
49
|
|
|
64
50
|
get message(): string {
|
|
65
|
-
return `${this.module}.${this.method}${
|
|
66
|
-
this.description ? `: ${this.description}` : ""
|
|
67
|
-
}`
|
|
51
|
+
return `${this.module}.${this.method}${this.description ? `: ${this.description}` : ""}`
|
|
68
52
|
}
|
|
69
53
|
}
|
|
70
54
|
|
|
@@ -84,22 +68,17 @@ export const SystemErrorReason = Schema.Literal(
|
|
|
84
68
|
|
|
85
69
|
export type SystemErrorReason = typeof SystemErrorReason.Type
|
|
86
70
|
|
|
87
|
-
export class SystemError
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
),
|
|
99
|
-
cause: Schema.optional(Schema.Defect),
|
|
100
|
-
},
|
|
101
|
-
)
|
|
102
|
-
{
|
|
71
|
+
export class SystemError extends Schema.TaggedError<SystemError>(
|
|
72
|
+
"@effect/platform/Error/SystemError",
|
|
73
|
+
)("SystemError", {
|
|
74
|
+
reason: SystemErrorReason,
|
|
75
|
+
module: Module,
|
|
76
|
+
method: Schema.String,
|
|
77
|
+
description: Schema.optional(Schema.String),
|
|
78
|
+
syscall: Schema.optional(Schema.String),
|
|
79
|
+
pathOrDescriptor: Schema.optional(Schema.Union(Schema.String, Schema.Number)),
|
|
80
|
+
cause: Schema.optional(Schema.Defect),
|
|
81
|
+
}) {
|
|
103
82
|
readonly [TypeId]: typeof TypeId = TypeId
|
|
104
83
|
|
|
105
84
|
get message(): string {
|
|
@@ -111,7 +90,7 @@ export class SystemError
|
|
|
111
90
|
|
|
112
91
|
export type PlatformError = BadArgument | SystemError
|
|
113
92
|
|
|
114
|
-
export const PlatformError: Schema.Union<[
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
93
|
+
export const PlatformError: Schema.Union<[typeof BadArgument, typeof SystemError]> = Schema.Union(
|
|
94
|
+
BadArgument,
|
|
95
|
+
SystemError,
|
|
96
|
+
)
|
package/src/PlatformRuntime.ts
CHANGED
|
@@ -21,13 +21,11 @@ export const defaultTeardown: Teardown = <E, A>(
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface RunMain {
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
): <E, A>(effect: Effect.Effect<A, E>) => void
|
|
24
|
+
(options?: {
|
|
25
|
+
readonly disableErrorReporting?: boolean | undefined
|
|
26
|
+
readonly disablePrettyLogger?: boolean | undefined
|
|
27
|
+
readonly teardown?: Teardown | undefined
|
|
28
|
+
}): <E, A>(effect: Effect.Effect<A, E>) => void
|
|
31
29
|
<E, A>(
|
|
32
30
|
effect: Effect.Effect<A, E>,
|
|
33
31
|
options?: {
|
|
@@ -38,10 +36,7 @@ export interface RunMain {
|
|
|
38
36
|
): void
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
const addPrettyLogger = (
|
|
42
|
-
refs: FiberRefs.FiberRefs,
|
|
43
|
-
fiberId: FiberId.Runtime,
|
|
44
|
-
) => {
|
|
39
|
+
const addPrettyLogger = (refs: FiberRefs.FiberRefs, fiberId: FiberId.Runtime) => {
|
|
45
40
|
const loggers = FiberRefs.getOrDefault(refs, FiberRef.currentLoggers)
|
|
46
41
|
if (!HashSet.has(loggers, Logger.defaultLogger)) {
|
|
47
42
|
return refs
|
|
@@ -57,39 +52,37 @@ const addPrettyLogger = (
|
|
|
57
52
|
}
|
|
58
53
|
|
|
59
54
|
export const makeRunMain = (
|
|
60
|
-
f: <E, A>(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
) => void,
|
|
55
|
+
f: <E, A>(options: {
|
|
56
|
+
readonly fiber: Fiber.RuntimeFiber<A, E>
|
|
57
|
+
readonly teardown: Teardown
|
|
58
|
+
}) => void,
|
|
66
59
|
): RunMain =>
|
|
67
60
|
Function.dual(
|
|
68
61
|
(args) => Effect.isEffect(args[0]),
|
|
69
|
-
(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
62
|
+
(
|
|
63
|
+
effect: Effect.Effect<any, any>,
|
|
64
|
+
options?: {
|
|
65
|
+
readonly disableErrorReporting?: boolean | undefined
|
|
66
|
+
readonly disablePrettyLogger?: boolean | undefined
|
|
67
|
+
readonly teardown?: Teardown | undefined
|
|
68
|
+
},
|
|
69
|
+
) => {
|
|
70
|
+
const fiber =
|
|
71
|
+
options?.disableErrorReporting === true
|
|
72
|
+
? Effect.runFork(effect, {
|
|
73
|
+
updateRefs: options?.disablePrettyLogger === true ? undefined : addPrettyLogger,
|
|
74
|
+
})
|
|
75
|
+
: Effect.runFork(
|
|
76
|
+
Effect.tapErrorCause(effect, (cause) => {
|
|
77
|
+
if (Cause.isInterruptedOnly(cause)) {
|
|
78
|
+
return Effect.void
|
|
79
|
+
}
|
|
80
|
+
return Effect.logError(cause)
|
|
81
|
+
}),
|
|
82
|
+
{
|
|
83
|
+
updateRefs: options?.disablePrettyLogger === true ? undefined : addPrettyLogger,
|
|
84
|
+
},
|
|
85
|
+
)
|
|
93
86
|
const teardown = options?.teardown ?? defaultTeardown
|
|
94
87
|
return f({ fiber, teardown })
|
|
95
88
|
},
|
|
@@ -99,10 +92,9 @@ export const makeRunMain = (
|
|
|
99
92
|
* Are we running within an agent harness, like Claude Code?
|
|
100
93
|
*/
|
|
101
94
|
export function isAgentHarness() {
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
&&
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
)
|
|
95
|
+
return (
|
|
96
|
+
typeof process !== "undefined" &&
|
|
97
|
+
!process.stdout.isTTY &&
|
|
98
|
+
(process.env.CLAUDECODE || process.env.CURSOR_AGENT)
|
|
99
|
+
)
|
|
108
100
|
}
|
package/src/Route.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as Predicate from "effect/Predicate"
|
|
|
6
6
|
import * as Entity from "./Entity.ts"
|
|
7
7
|
import * as RouteBody from "./RouteBody.ts"
|
|
8
8
|
import * as RouteTree from "./RouteTree.ts"
|
|
9
|
-
import * as Values from "./Values.ts"
|
|
9
|
+
import type * as Values from "./Values.ts"
|
|
10
10
|
|
|
11
11
|
export const RouteItems: unique symbol = Symbol()
|
|
12
12
|
export const RouteDescriptor: unique symbol = Symbol()
|
|
@@ -26,49 +26,30 @@ export namespace RouteSet {
|
|
|
26
26
|
D extends RouteDescriptor.Any = {},
|
|
27
27
|
B = {},
|
|
28
28
|
M extends Route.Tuple = [],
|
|
29
|
-
> =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
& Pipeable.Pipeable
|
|
35
|
-
& Iterable<M[number]>
|
|
29
|
+
> = Data<D, B, M> & {
|
|
30
|
+
[TypeId]: typeof TypeId
|
|
31
|
+
} & Pipeable.Pipeable &
|
|
32
|
+
Iterable<M[number]>
|
|
36
33
|
|
|
37
|
-
export type Data<
|
|
38
|
-
D extends RouteDescriptor.Any = {},
|
|
39
|
-
B = {},
|
|
40
|
-
M extends Route.Tuple = [],
|
|
41
|
-
> = {
|
|
34
|
+
export type Data<D extends RouteDescriptor.Any = {}, B = {}, M extends Route.Tuple = []> = {
|
|
42
35
|
[RouteItems]: M
|
|
43
36
|
[RouteDescriptor]: D
|
|
44
37
|
[RouteBindings]: B
|
|
45
38
|
}
|
|
46
39
|
|
|
47
|
-
export type Proto =
|
|
48
|
-
&
|
|
49
|
-
& Iterable<Route.Route<any, any, any, any, any>>
|
|
50
|
-
& {
|
|
40
|
+
export type Proto = Pipeable.Pipeable &
|
|
41
|
+
Iterable<Route.Route<any, any, any, any, any>> & {
|
|
51
42
|
[TypeId]: typeof TypeId
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
export type Any = RouteSet<{}, {}, Route.Tuple>
|
|
55
46
|
|
|
56
|
-
export type Infer<R> = R extends RouteSet<infer D, infer B, infer I>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
export type
|
|
61
|
-
T extends Data<
|
|
62
|
-
> = T extends Data<
|
|
63
|
-
any,
|
|
64
|
-
any,
|
|
65
|
-
infer M
|
|
66
|
-
> ? M
|
|
67
|
-
: never
|
|
68
|
-
|
|
69
|
-
export type Descriptor<
|
|
70
|
-
T extends Data<any, any, any>,
|
|
71
|
-
> = T extends Data<infer D, any, any> ? D : never
|
|
47
|
+
export type Infer<R> = R extends RouteSet<infer D, infer B, infer I> ? RouteSet<D, B, I> : R
|
|
48
|
+
|
|
49
|
+
export type Items<T extends Data<any, any, any>> = T extends Data<any, any, infer M> ? M : never
|
|
50
|
+
|
|
51
|
+
export type Descriptor<T extends Data<any, any, any>> =
|
|
52
|
+
T extends Data<infer D, any, any> ? D : never
|
|
72
53
|
}
|
|
73
54
|
|
|
74
55
|
export namespace Route {
|
|
@@ -78,25 +59,15 @@ export namespace Route {
|
|
|
78
59
|
A = any,
|
|
79
60
|
E = never,
|
|
80
61
|
R = never,
|
|
81
|
-
> extends
|
|
82
|
-
RouteSet.RouteSet<D, {}, [
|
|
83
|
-
Route<D, B, A, E, R>,
|
|
84
|
-
]>
|
|
85
|
-
{
|
|
62
|
+
> extends RouteSet.RouteSet<D, {}, [Route<D, B, A, E, R>]> {
|
|
86
63
|
readonly handler: Handler<B & D, A, E, R>
|
|
87
64
|
}
|
|
88
65
|
|
|
89
|
-
export type With<D extends RouteDescriptor.Any> =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[RouteDescriptor]: D
|
|
93
|
-
}
|
|
66
|
+
export type With<D extends RouteDescriptor.Any> = Route<any, any, any, any, any> & {
|
|
67
|
+
[RouteDescriptor]: D
|
|
68
|
+
}
|
|
94
69
|
|
|
95
|
-
export type Tuple<
|
|
96
|
-
_D extends RouteDescriptor.Any = {},
|
|
97
|
-
> = [
|
|
98
|
-
...Route<any, any, any, any, any>[],
|
|
99
|
-
]
|
|
70
|
+
export type Tuple<_D extends RouteDescriptor.Any = {}> = [...Route<any, any, any, any, any>[]]
|
|
100
71
|
|
|
101
72
|
export type Handler<B, A, E, R> = (
|
|
102
73
|
context: B,
|
|
@@ -106,17 +77,13 @@ export namespace Route {
|
|
|
106
77
|
/**
|
|
107
78
|
* Extracts only the bindings (B) from routes, excluding descriptors.
|
|
108
79
|
*/
|
|
109
|
-
export type Bindings<
|
|
110
|
-
T extends RouteSet.Any,
|
|
111
|
-
M extends Tuple = RouteSet.Items<T>,
|
|
112
|
-
> = M extends [
|
|
80
|
+
export type Bindings<T extends RouteSet.Any, M extends Tuple = RouteSet.Items<T>> = M extends [
|
|
113
81
|
infer Head,
|
|
114
82
|
...infer Tail extends Tuple,
|
|
115
|
-
]
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
83
|
+
]
|
|
84
|
+
? Head extends Route<any, infer B, any, any, any>
|
|
85
|
+
? ShallowMerge<B, Bindings<T, Tail>>
|
|
86
|
+
: Bindings<T, Tail>
|
|
120
87
|
: {}
|
|
121
88
|
|
|
122
89
|
/**
|
|
@@ -125,32 +92,16 @@ export namespace Route {
|
|
|
125
92
|
* taking precedence via ShallowMerge to avoid `never` from conflicting
|
|
126
93
|
* literal types (e.g. `{ method: "*" } & { method: "GET" }`).
|
|
127
94
|
*/
|
|
128
|
-
export type Context<T extends RouteSet.Any> =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
infer Head,
|
|
139
|
-
...infer Tail extends Tuple,
|
|
140
|
-
] ? (
|
|
141
|
-
Head extends Route<
|
|
142
|
-
infer D,
|
|
143
|
-
infer B,
|
|
144
|
-
any,
|
|
145
|
-
any,
|
|
146
|
-
any
|
|
147
|
-
> ? ShallowMerge<
|
|
148
|
-
& Omit<D, keyof B>
|
|
149
|
-
& B,
|
|
150
|
-
ExtractContext<Tail>
|
|
151
|
-
>
|
|
152
|
-
: ExtractContext<Tail>
|
|
153
|
-
)
|
|
95
|
+
export type Context<T extends RouteSet.Any> = Omit<
|
|
96
|
+
RouteSet.Descriptor<T>,
|
|
97
|
+
keyof ExtractContext<RouteSet.Items<T>>
|
|
98
|
+
> &
|
|
99
|
+
ExtractContext<RouteSet.Items<T>>
|
|
100
|
+
|
|
101
|
+
type ExtractContext<M extends Tuple> = M extends [infer Head, ...infer Tail extends Tuple]
|
|
102
|
+
? Head extends Route<infer D, infer B, any, any, any>
|
|
103
|
+
? ShallowMerge<Omit<D, keyof B> & B, ExtractContext<Tail>>
|
|
104
|
+
: ExtractContext<Tail>
|
|
154
105
|
: {}
|
|
155
106
|
}
|
|
156
107
|
|
|
@@ -164,55 +115,34 @@ const Proto: RouteSet.Proto = {
|
|
|
164
115
|
},
|
|
165
116
|
}
|
|
166
117
|
|
|
167
|
-
export function isRouteSet(
|
|
168
|
-
input: unknown,
|
|
169
|
-
): input is RouteSet.Any {
|
|
118
|
+
export function isRouteSet(input: unknown): input is RouteSet.Any {
|
|
170
119
|
return Predicate.hasProperty(input, TypeId)
|
|
171
120
|
}
|
|
172
121
|
|
|
173
|
-
export function isRoute(
|
|
174
|
-
input
|
|
175
|
-
): input is Route.Route {
|
|
176
|
-
return isRouteSet(input)
|
|
177
|
-
&& Predicate.hasProperty(input, "handler")
|
|
122
|
+
export function isRoute(input: unknown): input is Route.Route {
|
|
123
|
+
return isRouteSet(input) && Predicate.hasProperty(input, "handler")
|
|
178
124
|
}
|
|
179
125
|
|
|
180
|
-
export function set<
|
|
181
|
-
D extends RouteDescriptor.Any = {},
|
|
182
|
-
B = {},
|
|
183
|
-
I extends Route.Tuple = [],
|
|
184
|
-
>(
|
|
126
|
+
export function set<D extends RouteDescriptor.Any = {}, B = {}, I extends Route.Tuple = []>(
|
|
185
127
|
items: I = [] as unknown as I,
|
|
186
128
|
descriptor: D = {} as D,
|
|
187
129
|
): RouteSet.RouteSet<D, B, I> {
|
|
188
|
-
return Object.assign(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
[RouteDescriptor]: descriptor,
|
|
193
|
-
},
|
|
194
|
-
) as RouteSet.RouteSet<D, B, I>
|
|
130
|
+
return Object.assign(Object.create(Proto), {
|
|
131
|
+
[RouteItems]: items,
|
|
132
|
+
[RouteDescriptor]: descriptor,
|
|
133
|
+
}) as RouteSet.RouteSet<D, B, I>
|
|
195
134
|
}
|
|
196
135
|
|
|
197
|
-
export function make<
|
|
198
|
-
D extends RouteDescriptor.Any,
|
|
199
|
-
B,
|
|
200
|
-
A,
|
|
201
|
-
E = never,
|
|
202
|
-
R = never,
|
|
203
|
-
>(
|
|
136
|
+
export function make<D extends RouteDescriptor.Any, B, A, E = never, R = never>(
|
|
204
137
|
handler: Route.Handler<B & D, A, E, R>,
|
|
205
138
|
descriptor?: D,
|
|
206
139
|
): Route.Route<D, B, A, E, R> {
|
|
207
140
|
const items: any = []
|
|
208
|
-
const route: Route.Route<D, B, A, E, R> = Object.assign(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
handler,
|
|
214
|
-
},
|
|
215
|
-
)
|
|
141
|
+
const route: Route.Route<D, B, A, E, R> = Object.assign(Object.create(Proto), {
|
|
142
|
+
[RouteItems]: items,
|
|
143
|
+
[RouteDescriptor]: descriptor,
|
|
144
|
+
handler,
|
|
145
|
+
})
|
|
216
146
|
|
|
217
147
|
items.push(route)
|
|
218
148
|
|
|
@@ -221,36 +151,22 @@ export function make<
|
|
|
221
151
|
|
|
222
152
|
export const empty = set()
|
|
223
153
|
|
|
224
|
-
export function describe<
|
|
225
|
-
D extends RouteDescriptor.Any,
|
|
226
|
-
>(
|
|
227
|
-
descriptor: D,
|
|
228
|
-
) {
|
|
154
|
+
export function describe<D extends RouteDescriptor.Any>(descriptor: D) {
|
|
229
155
|
return set([], descriptor)
|
|
230
156
|
}
|
|
231
157
|
|
|
232
|
-
export function items<
|
|
233
|
-
T extends RouteSet.Data<any, any, any>,
|
|
234
|
-
>(
|
|
235
|
-
self: T,
|
|
236
|
-
): RouteSet.Items<T> {
|
|
158
|
+
export function items<T extends RouteSet.Data<any, any, any>>(self: T): RouteSet.Items<T> {
|
|
237
159
|
return self[RouteItems]
|
|
238
160
|
}
|
|
239
161
|
|
|
240
|
-
export function descriptor<
|
|
241
|
-
T extends RouteSet.Data<any, any, any>,
|
|
242
|
-
>(
|
|
162
|
+
export function descriptor<T extends RouteSet.Data<any, any, any>>(
|
|
243
163
|
self: T,
|
|
244
164
|
): T[typeof RouteDescriptor]
|
|
245
|
-
export function descriptor<
|
|
246
|
-
T extends RouteSet.Data<any, any, any>,
|
|
247
|
-
>(
|
|
165
|
+
export function descriptor<T extends RouteSet.Data<any, any, any>>(
|
|
248
166
|
self: Iterable<T>,
|
|
249
|
-
): T[typeof RouteDescriptor]
|
|
167
|
+
): Array<T[typeof RouteDescriptor]>
|
|
250
168
|
export function descriptor(
|
|
251
|
-
self:
|
|
252
|
-
| RouteSet.Data<any, any, any>
|
|
253
|
-
| Iterable<RouteSet.Data<any, any, any>>,
|
|
169
|
+
self: RouteSet.Data<any, any, any> | Iterable<RouteSet.Data<any, any, any>>,
|
|
254
170
|
): RouteDescriptor.Any | RouteDescriptor.Any[] {
|
|
255
171
|
if (RouteDescriptor in self) {
|
|
256
172
|
return self[RouteDescriptor]
|
|
@@ -258,30 +174,20 @@ export function descriptor(
|
|
|
258
174
|
return [...self].map((r) => r[RouteDescriptor])
|
|
259
175
|
}
|
|
260
176
|
|
|
261
|
-
export type ExtractBindings<
|
|
262
|
-
M extends Route.Tuple,
|
|
263
|
-
> = M extends [
|
|
177
|
+
export type ExtractBindings<M extends Route.Tuple> = M extends [
|
|
264
178
|
infer Head,
|
|
265
179
|
...infer Tail extends Route.Tuple,
|
|
266
|
-
]
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
any,
|
|
271
|
-
any,
|
|
272
|
-
any
|
|
273
|
-
> ? ShallowMerge<B, ExtractBindings<Tail>>
|
|
274
|
-
: ExtractBindings<Tail>
|
|
275
|
-
)
|
|
180
|
+
]
|
|
181
|
+
? Head extends Route.Route<any, infer B, any, any, any>
|
|
182
|
+
? ShallowMerge<B, ExtractBindings<Tail>>
|
|
183
|
+
: ExtractBindings<Tail>
|
|
276
184
|
: {}
|
|
277
185
|
|
|
278
186
|
// Shallow merge two object types.
|
|
279
187
|
// For overlapping keys, intersect the values.
|
|
280
|
-
type ShallowMerge<A, B> =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
[K in keyof B]: K extends keyof A ? A[K] & B[K] : B[K]
|
|
284
|
-
}
|
|
188
|
+
type ShallowMerge<A, B> = Omit<A, keyof B> & {
|
|
189
|
+
[K in keyof B]: K extends keyof A ? A[K] & B[K] : B[K]
|
|
190
|
+
}
|
|
285
191
|
|
|
286
192
|
export type ExtractContext<
|
|
287
193
|
Items extends Route.Tuple,
|
|
@@ -291,17 +197,7 @@ export type ExtractContext<
|
|
|
291
197
|
export * from "./RouteHook.ts"
|
|
292
198
|
export * from "./RouteSchema.ts"
|
|
293
199
|
|
|
294
|
-
export {
|
|
295
|
-
add,
|
|
296
|
-
del,
|
|
297
|
-
get,
|
|
298
|
-
head,
|
|
299
|
-
options,
|
|
300
|
-
patch,
|
|
301
|
-
post,
|
|
302
|
-
put,
|
|
303
|
-
use,
|
|
304
|
-
} from "./RouteMount.ts"
|
|
200
|
+
export { add, del, get, head, options, patch, post, put, use } from "./RouteMount.ts"
|
|
305
201
|
|
|
306
202
|
export const text = RouteBody.build<string, "text">({
|
|
307
203
|
format: "text",
|
|
@@ -319,13 +215,9 @@ export const bytes = RouteBody.build<Uint8Array, "bytes">({
|
|
|
319
215
|
format: "bytes",
|
|
320
216
|
})
|
|
321
217
|
|
|
322
|
-
export {
|
|
323
|
-
render,
|
|
324
|
-
} from "./RouteBody.ts"
|
|
218
|
+
export { render } from "./RouteBody.ts"
|
|
325
219
|
|
|
326
|
-
export {
|
|
327
|
-
sse,
|
|
328
|
-
} from "./RouteSse.ts"
|
|
220
|
+
export { sse } from "./RouteSse.ts"
|
|
329
221
|
|
|
330
222
|
export function redirect(
|
|
331
223
|
url: string | URL,
|
|
@@ -339,24 +231,13 @@ export function redirect(
|
|
|
339
231
|
})
|
|
340
232
|
}
|
|
341
233
|
|
|
342
|
-
export class Routes extends Context.Tag("effect-start/Routes")<
|
|
343
|
-
Routes,
|
|
344
|
-
RouteTree.RouteTree
|
|
345
|
-
>() {}
|
|
234
|
+
export class Routes extends Context.Tag("effect-start/Routes")<Routes, RouteTree.RouteTree>() {}
|
|
346
235
|
|
|
347
236
|
export function layer(routes: RouteTree.RouteMap | RouteTree.RouteTree) {
|
|
348
|
-
return Layer.sync(
|
|
349
|
-
Routes,
|
|
350
|
-
() =>
|
|
351
|
-
RouteTree.isRouteTree(routes)
|
|
352
|
-
? routes
|
|
353
|
-
: RouteTree.make(routes),
|
|
354
|
-
)
|
|
237
|
+
return Layer.sync(Routes, () => (RouteTree.isRouteTree(routes) ? routes : RouteTree.make(routes)))
|
|
355
238
|
}
|
|
356
239
|
|
|
357
|
-
export {
|
|
358
|
-
make as tree,
|
|
359
|
-
} from "./RouteTree.ts"
|
|
240
|
+
export { make as tree } from "./RouteTree.ts"
|
|
360
241
|
|
|
361
242
|
export function lazy<T extends RouteSet.Any>(
|
|
362
243
|
load: () => Promise<{ default: T }>,
|