@lengkapp/edge 0.0.51 → 0.0.52

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @lengkapp/edge v0.0.51
2
+ * @lengkapp/edge v0.0.52
3
3
  * MIT License
4
4
  *
5
5
  * LengkApp Edge License
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @lengkapp/edge v0.0.51
2
+ * @lengkapp/edge v0.0.52
3
3
  * MIT License
4
4
  *
5
5
  * LengkApp Edge License
@@ -33,13 +33,6 @@
33
33
  /* ------------------------------------------------------------------ *
34
34
  * JSX runtime *
35
35
  * ------------------------------------------------------------------ */
36
-
37
- /**
38
- * Runtime value is `Symbol('Fragment')`. The function signature is a
39
- * type-level shim so `<></>` works with the automatic JSX runtime.
40
- * Never called directly — `jsx(Fragment, …)` passes it through and
41
- * `renderToString` compares by identity.
42
- */
43
36
  export const Fragment: (props: { children?: any }) => JSXNode;
44
37
 
45
38
  export interface JSXNode {
@@ -62,7 +55,7 @@ export function jsx(
62
55
  * The optional `ctx` is normally supplied by `Context.html`/`Context.page`;
63
56
  * user code never needs to pass it.
64
57
  */
65
- export function renderToString<Env = unknown>(
58
+ export function renderToString<Env = any>(
66
59
  node: any,
67
60
  ctx?: Context<Env>
68
61
  ): Promise<string>;
@@ -75,17 +68,12 @@ export function renderToString<Env = unknown>(
75
68
  * Returns the Context of the request whose render is currently executing.
76
69
  *
77
70
  * MUST be called synchronously at the top of a component — before any
78
- * `await`. After an `await`, use the captured local reference; the
79
- * ambient slot is no longer guaranteed to belong to your request.
71
+ * `await`. After an `await`, use the captured local reference.
80
72
  *
81
73
  * Throws if called outside an active render (module top-level, scheduled
82
74
  * handler, `waitUntil` callback, or after an `await`).
83
- *
84
- * NOTE: `useCtx()` cannot infer your app's `Env` — the ambient stack is
85
- * erased at runtime. Pass the type explicitly when you need it:
86
- * const c = useCtx<MyEnv>();
87
75
  */
88
- export function useCtx<Env = unknown>(): Context<Env>;
76
+ export function useCtx<Env = any>(): Context<Env>;
89
77
 
90
78
  /* ------------------------------------------------------------------ *
91
79
  * Context *
@@ -101,7 +89,7 @@ export interface CookieOptions {
101
89
  sameSite?: 'Strict' | 'Lax' | 'None' | string;
102
90
  }
103
91
 
104
- export class Context<Env = unknown> {
92
+ export class Context<Env = any> {
105
93
  constructor(
106
94
  request: Request,
107
95
  env: Env,
@@ -110,7 +98,7 @@ export class Context<Env = unknown> {
110
98
  );
111
99
 
112
100
  req: Request;
113
- env: Env; // <-- typed per app
101
+ env: Env;
114
102
  params: Record<string, string>;
115
103
  status: number;
116
104
  headers: Headers;
@@ -124,14 +112,12 @@ export class Context<Env = unknown> {
124
112
  text(data: string, status?: number, headers?: Record<string, string>): Response;
125
113
  json(data: any, status?: number, headers?: Record<string, string>): Response;
126
114
 
127
- /** Async — JSX trees may contain async components. */
128
115
  html(
129
116
  data: string | JSXNode | JSXNode[] | null | undefined,
130
117
  status?: number,
131
118
  headers?: Record<string, string>
132
119
  ): Promise<Response>;
133
120
 
134
- /** Async — JSX trees may contain async components. */
135
121
  page(
136
122
  data: string | JSXNode | JSXNode[] | null | undefined,
137
123
  status?: number,
@@ -145,95 +131,38 @@ export class Context<Env = unknown> {
145
131
  * Edge router *
146
132
  * ------------------------------------------------------------------ */
147
133
 
148
- export type RouteHandler<Env = unknown> =
134
+ export type RouteHandler<Env = any> =
149
135
  (ctx: Context<Env>) => any | Promise<any>;
150
136
 
151
- export type ScheduledHandler<Env = unknown> = (
152
- event: ScheduledEvent,
137
+ export type ScheduledHandler<Env = any> = (
138
+ event: any,
153
139
  env: Env,
154
- ctx: ExecutionContext
140
+ ctx: any
155
141
  ) => void | Promise<void>;
156
142
 
157
- /**
158
- * Invoked when no route matches the incoming request.
159
- *
160
- * Receives a full Context (same shape as a route handler) so it can
161
- * set `c.status` and return a Response, or a JSX tree (which is
162
- * coerced to an HTML response at that status).
163
- */
164
- export type NotFoundHandler<Env = unknown> =
143
+ export type NotFoundHandler<Env = any> =
165
144
  (ctx: Context<Env>) => any | Promise<any>;
166
145
 
167
- /**
168
- * Invoked when a route handler (or the not-found handler) throws.
169
- *
170
- * The thrown value is `unknown` because nothing enforces that handlers
171
- * throw `Error` specifically. Returning a Response uses it verbatim;
172
- * returning JSX renders it as a 500 HTML response. Errors thrown by
173
- * the error handler itself are swallowed and replaced with a
174
- * plain-text 500.
175
- */
176
- export type ErrorHandler<Env = unknown> = (
146
+ export type ErrorHandler<Env = any> = (
177
147
  ctx: Context<Env>,
178
148
  err: unknown
179
149
  ) => any | Promise<any>;
180
150
 
181
- export class Edge<Env = unknown> {
182
- /**
183
- * @param prefix Optional mount prefix for this Edge. `''` and `'/'`
184
- * both mean "no prefix". Joined with every registered route path at
185
- * registration time — never stripped or re-applied per request.
186
- */
151
+ export class Edge<Env = any> {
187
152
  constructor(prefix?: string);
188
153
 
189
- /**
190
- * Normalized mount prefix for this Edge. `''` means "no prefix".
191
- * Set once at construction; applied to every route registered on this
192
- * Edge (and merged from sub-apps) so lookups at request time are
193
- * plain map/trie hits with no prefix stripping.
194
- */
195
154
  prefix: string;
196
155
 
197
156
  readonly staticRoutes: Map<string, Map<string, RouteHandler<Env>>>;
198
157
  readonly dynamicTries: Record<string, any>;
199
158
 
200
- /**
201
- * Set via `.scheduled()`. `null` until `.scheduled()` is called.
202
- * Read it only from the Worker entry
203
- * (`export default { fetch, scheduled }`) if you wire that up yourself.
204
- */
205
159
  scheduledHandler: ScheduledHandler<Env> | null;
206
160
 
207
- /* ---- Fallback handlers ------------------------------------------ *
208
- * Exposed as public fields to mirror the runtime shape; normally *
209
- * set via `.notFound()` / `.onError()` rather than assigned *
210
- * directly. */
211
161
  notFoundHandler: NotFoundHandler<Env> | null;
212
162
  errorHandler: ErrorHandler<Env> | null;
213
163
 
214
- /* ---- Sub-app mounting ------------------------------------------- */
215
-
216
- /**
217
- * Assigning runs a one-time merge: every route on each sub-app is
218
- * copied into this Edge's own tables, prefixed with `this.prefix`
219
- * combined with the sub-app's own prefix. After the merge the hot
220
- * path is unchanged — no per-request dispatch, no path rewriting.
221
- *
222
- * const signIn = new Edge('/sign-in');
223
- * signIn.get('/login', h);
224
- * const app = new Edge();
225
- * app.routes = [signIn]; // GET /sign-in/login
226
- *
227
- * Non-`Edge` entries throw. Mount is eager and one-way: routes
228
- * registered on a sub-app *after* it was mounted do not propagate.
229
- */
230
164
  set routes(apps: Edge<Env> | Edge<Env>[]);
231
165
 
232
- /* ---- Route registration ----------------------------------------- *
233
- * Paths are joined with this Edge's `prefix` (if any) at *
234
- * registration time; the resulting full path is what the router *
235
- * matches against on each request. */
236
-
237
166
  get(path: string, handler: RouteHandler<Env>): void;
238
167
  post(path: string, handler: RouteHandler<Env>): void;
239
168
  put(path: string, handler: RouteHandler<Env>): void;
@@ -242,39 +171,12 @@ export class Edge<Env = unknown> {
242
171
  options(path: string, handler: RouteHandler<Env>): void;
243
172
  head(path: string, handler: RouteHandler<Env>): void;
244
173
 
245
- /* ---- Scheduled handler ------------------------------------------ */
246
174
  scheduled(handler: ScheduledHandler<Env>): void;
247
175
 
248
- /* ---- Fallback registration -------------------------------------- */
249
-
250
- /**
251
- * Register a handler invoked when no route matches the incoming
252
- * request. The handler runs with a full Context (headers, cookies,
253
- * `c.page`, `c.html`).
254
- *
255
- * `OPTIONS` requests are short-circuited to a 204 (with base security
256
- * headers, no body) before this handler runs, so preflights never
257
- * render an HTML error page.
258
- */
259
176
  notFound(handler: NotFoundHandler<Env>): void;
260
-
261
- /**
262
- * Register a handler invoked when a route handler (including the
263
- * not-found handler) throws. Returning a Response uses it verbatim;
264
- * returning JSX renders it as a 500 HTML response. Errors thrown by
265
- * the error handler itself are swallowed and replaced with a
266
- * plain-text 500.
267
- */
268
177
  onError(handler: ErrorHandler<Env>): void;
269
178
 
270
- /* ---- Entry point ------------------------------------------------ *
271
- * The Workers module contract also passes an `ExecutionContext` as
272
- * the third argument; the router ignores it. Declare only what the
273
- * implementation consumes. */
274
- fetch(
275
- request: Request,
276
- env: Env
277
- ): Promise<Response>;
179
+ fetch(request: Request, env: Env): Promise<Response>;
278
180
  }
279
181
 
280
182
  export default Edge;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @lengkapp/edge v0.0.51
2
+ * @lengkapp/edge v0.0.52
3
3
  * MIT License
4
4
  *
5
5
  * LengkApp Edge License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lengkapp/edge",
3
- "version": "0.0.51",
3
+ "version": "0.0.52",
4
4
  "description": "Edge framework used by Lengkapp",
5
5
  "main": "dist/edge-server.js",
6
6
  "types": "dist/edge-server.d.ts",