@tupik/edge 0.0.0-stage → 1.1.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 +79 -2
- package/dist/index.d.mts +105 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.mjs +40 -0
- package/package.json +50 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Carlos Alberto Barbosa Stenzel / Tupik Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tupik/edge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Edge adapter for **Tupik**: exposes an app as a fetch handler for Cloudflare Workers. Worker `env` and `ctx`
|
|
4
|
+
are forwarded to `ctx.runtime`. Fastly and other fetch-based runtimes are not verified yet (planned).
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @tupik/edge @tupik/core
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createApp, createModule } from '@tupik/core';
|
|
16
|
+
import { createEdgeWorker, getEnv } from '@tupik/edge';
|
|
17
|
+
|
|
18
|
+
const app = createApp().register(
|
|
19
|
+
createModule().get('/', { access: 'public', handler: (ctx) => ({ greeting: getEnv<{ GREETING?: string }>(ctx).GREETING ?? 'hello' }) }),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Cloudflare Workers: `export default worker;`
|
|
23
|
+
const worker = createEdgeWorker(app);
|
|
24
|
+
|
|
25
|
+
const response = await worker.fetch(new Request('https://example.com/'), { GREETING: 'hi from the edge' });
|
|
26
|
+
console.log(await response.json()); // { greeting: 'hi from the edge' }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Cron, queues and email
|
|
30
|
+
|
|
31
|
+
`createEdgeWorker` also takes the other Worker events. Only the handlers you pass are exported.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createEdgeWorker } from '@tupik/edge';
|
|
35
|
+
|
|
36
|
+
interface Env {
|
|
37
|
+
readonly DB: D1Database;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface EmailJob {
|
|
41
|
+
readonly to: string;
|
|
42
|
+
readonly template: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default createEdgeWorker<Env>(app, {
|
|
46
|
+
// Cron Triggers
|
|
47
|
+
scheduled: async (controller, env) => {
|
|
48
|
+
await env.DB.prepare('DELETE FROM sessions WHERE expires_at < ?').bind(controller.scheduledTime).run();
|
|
49
|
+
},
|
|
50
|
+
// One message at a time: acked when it resolves, retried when it throws.
|
|
51
|
+
queue: {
|
|
52
|
+
message: async (job: EmailJob, message, env) => {
|
|
53
|
+
await sendEmail(env, job);
|
|
54
|
+
},
|
|
55
|
+
retryDelaySeconds: 60,
|
|
56
|
+
},
|
|
57
|
+
// Email Routing
|
|
58
|
+
email: async (message) => {
|
|
59
|
+
if (!message.from.endsWith('@example.com')) message.setReject('Unknown sender');
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
A failed queue message is logged with the error name and message id only, never its body or error message,
|
|
65
|
+
since those can carry personal data or tokens. Pass `onError(error, { queue, messageId, attempts })` to report it
|
|
66
|
+
elsewhere. To handle the whole batch yourself, pass a function instead: `queue: (batch, env, ctx) => { ... }`.
|
|
67
|
+
|
|
68
|
+
## Key API
|
|
69
|
+
|
|
70
|
+
| Export | Purpose |
|
|
71
|
+
| --- | --- |
|
|
72
|
+
| `createEdgeWorker(app, handlers?)` | Module worker with `fetch` and the `scheduled`, `queue` and `email` handlers you pass |
|
|
73
|
+
| `QueueConsumer<Env, Body>` | Per-message queue consumer: `message`, `retryDelaySeconds`, `onError` |
|
|
74
|
+
| `ScheduledControllerLike`, `MessageBatchLike`, `MessageLike`, `ForwardableEmailMessageLike` | Structural types of the Cloudflare event objects, no dependency on `@cloudflare/workers-types` |
|
|
75
|
+
| `toEdgeHandler(app)` | Bare `(request, env?, ctx?) => Promise<Response>` handler |
|
|
76
|
+
| `getEnv<TEnv>(ctx)` | Typed access to the runtime bindings inside a handler |
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ExecutionContextLike, RuntimeBindings } from '@tupik/core';
|
|
2
|
+
export { ExecutionContextLike } from '@tupik/core';
|
|
3
|
+
|
|
4
|
+
type Awaitable<T> = T | Promise<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Structural subset of `@tupik/core` apps accepted by the edge adapter.
|
|
7
|
+
* `env`/`executionCtx` are forwarded to `ctx.runtime` (Cloudflare Workers).
|
|
8
|
+
*/
|
|
9
|
+
interface EdgeApp {
|
|
10
|
+
fetch(request: Request, env?: unknown, executionCtx?: ExecutionContextLike): Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
/** WinterCG-style Fetch handler; Workers pass `env` and `ctx` as extra arguments. */
|
|
13
|
+
type EdgeHandler<TEnv = unknown> = (request: Request, env?: TEnv, executionCtx?: ExecutionContextLike) => Promise<Response>;
|
|
14
|
+
/** Cron Trigger controller passed to `scheduled` (structural subset of Cloudflare's `ScheduledController`). */
|
|
15
|
+
interface ScheduledControllerLike {
|
|
16
|
+
readonly cron: string;
|
|
17
|
+
readonly scheduledTime: number;
|
|
18
|
+
noRetry(): void;
|
|
19
|
+
}
|
|
20
|
+
/** One queue message (structural subset of Cloudflare's `Message`). */
|
|
21
|
+
interface MessageLike<TBody = unknown> {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly body: TBody;
|
|
24
|
+
readonly attempts: number;
|
|
25
|
+
readonly timestamp: Date;
|
|
26
|
+
ack(): void;
|
|
27
|
+
retry(options?: {
|
|
28
|
+
delaySeconds?: number;
|
|
29
|
+
}): void;
|
|
30
|
+
}
|
|
31
|
+
/** A batch delivered to `queue` (structural subset of Cloudflare's `MessageBatch`). */
|
|
32
|
+
interface MessageBatchLike<TBody = unknown> {
|
|
33
|
+
readonly queue: string;
|
|
34
|
+
readonly messages: readonly MessageLike<TBody>[];
|
|
35
|
+
ackAll(): void;
|
|
36
|
+
retryAll(options?: {
|
|
37
|
+
delaySeconds?: number;
|
|
38
|
+
}): void;
|
|
39
|
+
}
|
|
40
|
+
/** Inbound email for Email Routing (structural subset of Cloudflare's `ForwardableEmailMessage`). */
|
|
41
|
+
interface ForwardableEmailMessageLike {
|
|
42
|
+
readonly from: string;
|
|
43
|
+
readonly to: string;
|
|
44
|
+
readonly headers: Headers;
|
|
45
|
+
readonly raw: ReadableStream<Uint8Array>;
|
|
46
|
+
readonly rawSize: number;
|
|
47
|
+
setReject(reason: string): void;
|
|
48
|
+
forward(rcptTo: string, headers?: Headers): Promise<unknown>;
|
|
49
|
+
}
|
|
50
|
+
type ScheduledHandler<TEnv> = (controller: ScheduledControllerLike, env: TEnv, ctx: ExecutionContextLike) => Awaitable<void>;
|
|
51
|
+
type EmailHandler<TEnv> = (message: ForwardableEmailMessageLike, env: TEnv, ctx: ExecutionContextLike) => Awaitable<void>;
|
|
52
|
+
interface QueueBatchMethod<TEnv, TBody> {
|
|
53
|
+
handle(batch: MessageBatchLike<TBody>, env: TEnv, ctx: ExecutionContextLike): Awaitable<void>;
|
|
54
|
+
}
|
|
55
|
+
/** Whole-batch consumer: you ack or retry the messages yourself. */
|
|
56
|
+
type QueueBatchHandler<TEnv, TBody = unknown> = QueueBatchMethod<TEnv, TBody>['handle'];
|
|
57
|
+
/** Where a per-message failure happened, without the message body. */
|
|
58
|
+
interface QueueFailure {
|
|
59
|
+
readonly queue: string;
|
|
60
|
+
readonly messageId: string;
|
|
61
|
+
readonly attempts: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Per-message consumer: each message is acked when `message` resolves and retried when it throws,
|
|
65
|
+
* so one bad message never makes the platform redeliver the whole batch.
|
|
66
|
+
*/
|
|
67
|
+
interface QueueConsumer<TEnv, TBody = unknown> {
|
|
68
|
+
message(body: TBody, message: MessageLike<TBody>, env: TEnv, ctx: ExecutionContextLike): Awaitable<void>;
|
|
69
|
+
/** Delay before a failed message is delivered again. Default: the queue's own retry delay. */
|
|
70
|
+
readonly retryDelaySeconds?: number;
|
|
71
|
+
/** Called for each failed message. Default: `console.error` with the error name and message id only. */
|
|
72
|
+
onError?(error: unknown, failure: QueueFailure): void;
|
|
73
|
+
}
|
|
74
|
+
/** Handlers for the Worker events other than `fetch`. */
|
|
75
|
+
interface EdgeWorkerHandlers<TEnv> {
|
|
76
|
+
readonly scheduled?: ScheduledHandler<TEnv>;
|
|
77
|
+
readonly queue?: QueueBatchHandler<TEnv> | QueueConsumer<TEnv>;
|
|
78
|
+
readonly email?: EmailHandler<TEnv>;
|
|
79
|
+
}
|
|
80
|
+
/** Worker module export: `fetch` plus the event handlers that were given. */
|
|
81
|
+
interface EdgeWorker<TEnv> {
|
|
82
|
+
readonly fetch: EdgeHandler<TEnv>;
|
|
83
|
+
readonly scheduled?: ScheduledHandler<TEnv>;
|
|
84
|
+
readonly queue?: QueueBatchHandler<TEnv>;
|
|
85
|
+
readonly email?: EmailHandler<TEnv>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Zero-conversion Fetch adapter for Edge runtimes (Cloudflare, Fastly, Deno). */
|
|
89
|
+
declare function toEdgeHandler<TEnv = unknown>(app: EdgeApp): EdgeHandler<TEnv>;
|
|
90
|
+
/**
|
|
91
|
+
* Worker-style module export: `export default createEdgeWorker<Env>(app, { scheduled, queue, email });`.
|
|
92
|
+
* Cloudflare calls `fetch(request, env, ctx)`; both reach handlers as `ctx.runtime`. Only the handlers
|
|
93
|
+
* you pass are exported, so Cloudflare never sees a `queue` or `scheduled` the Worker does not have.
|
|
94
|
+
*/
|
|
95
|
+
declare function createEdgeWorker<TEnv = unknown>(app: EdgeApp, handlers?: EdgeWorkerHandlers<TEnv>): EdgeWorker<TEnv>;
|
|
96
|
+
/**
|
|
97
|
+
* Typed access to Worker bindings from a handler: `getEnv<Env>(ctx).MY_KV`.
|
|
98
|
+
* Throws when the runtime did not provide an `env` (Deno, Fastly, tests).
|
|
99
|
+
*/
|
|
100
|
+
declare function getEnv<TEnv>(ctx: {
|
|
101
|
+
readonly runtime: RuntimeBindings;
|
|
102
|
+
}): TEnv;
|
|
103
|
+
|
|
104
|
+
export { createEdgeWorker, getEnv, toEdgeHandler };
|
|
105
|
+
export type { EdgeApp, EdgeHandler, EdgeWorker, EdgeWorkerHandlers, EmailHandler, ForwardableEmailMessageLike, MessageBatchLike, MessageLike, QueueBatchHandler, QueueConsumer, QueueFailure, ScheduledControllerLike, ScheduledHandler };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ExecutionContextLike, RuntimeBindings } from '@tupik/core';
|
|
2
|
+
export { ExecutionContextLike } from '@tupik/core';
|
|
3
|
+
|
|
4
|
+
type Awaitable<T> = T | Promise<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Structural subset of `@tupik/core` apps accepted by the edge adapter.
|
|
7
|
+
* `env`/`executionCtx` are forwarded to `ctx.runtime` (Cloudflare Workers).
|
|
8
|
+
*/
|
|
9
|
+
interface EdgeApp {
|
|
10
|
+
fetch(request: Request, env?: unknown, executionCtx?: ExecutionContextLike): Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
/** WinterCG-style Fetch handler; Workers pass `env` and `ctx` as extra arguments. */
|
|
13
|
+
type EdgeHandler<TEnv = unknown> = (request: Request, env?: TEnv, executionCtx?: ExecutionContextLike) => Promise<Response>;
|
|
14
|
+
/** Cron Trigger controller passed to `scheduled` (structural subset of Cloudflare's `ScheduledController`). */
|
|
15
|
+
interface ScheduledControllerLike {
|
|
16
|
+
readonly cron: string;
|
|
17
|
+
readonly scheduledTime: number;
|
|
18
|
+
noRetry(): void;
|
|
19
|
+
}
|
|
20
|
+
/** One queue message (structural subset of Cloudflare's `Message`). */
|
|
21
|
+
interface MessageLike<TBody = unknown> {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly body: TBody;
|
|
24
|
+
readonly attempts: number;
|
|
25
|
+
readonly timestamp: Date;
|
|
26
|
+
ack(): void;
|
|
27
|
+
retry(options?: {
|
|
28
|
+
delaySeconds?: number;
|
|
29
|
+
}): void;
|
|
30
|
+
}
|
|
31
|
+
/** A batch delivered to `queue` (structural subset of Cloudflare's `MessageBatch`). */
|
|
32
|
+
interface MessageBatchLike<TBody = unknown> {
|
|
33
|
+
readonly queue: string;
|
|
34
|
+
readonly messages: readonly MessageLike<TBody>[];
|
|
35
|
+
ackAll(): void;
|
|
36
|
+
retryAll(options?: {
|
|
37
|
+
delaySeconds?: number;
|
|
38
|
+
}): void;
|
|
39
|
+
}
|
|
40
|
+
/** Inbound email for Email Routing (structural subset of Cloudflare's `ForwardableEmailMessage`). */
|
|
41
|
+
interface ForwardableEmailMessageLike {
|
|
42
|
+
readonly from: string;
|
|
43
|
+
readonly to: string;
|
|
44
|
+
readonly headers: Headers;
|
|
45
|
+
readonly raw: ReadableStream<Uint8Array>;
|
|
46
|
+
readonly rawSize: number;
|
|
47
|
+
setReject(reason: string): void;
|
|
48
|
+
forward(rcptTo: string, headers?: Headers): Promise<unknown>;
|
|
49
|
+
}
|
|
50
|
+
type ScheduledHandler<TEnv> = (controller: ScheduledControllerLike, env: TEnv, ctx: ExecutionContextLike) => Awaitable<void>;
|
|
51
|
+
type EmailHandler<TEnv> = (message: ForwardableEmailMessageLike, env: TEnv, ctx: ExecutionContextLike) => Awaitable<void>;
|
|
52
|
+
interface QueueBatchMethod<TEnv, TBody> {
|
|
53
|
+
handle(batch: MessageBatchLike<TBody>, env: TEnv, ctx: ExecutionContextLike): Awaitable<void>;
|
|
54
|
+
}
|
|
55
|
+
/** Whole-batch consumer: you ack or retry the messages yourself. */
|
|
56
|
+
type QueueBatchHandler<TEnv, TBody = unknown> = QueueBatchMethod<TEnv, TBody>['handle'];
|
|
57
|
+
/** Where a per-message failure happened, without the message body. */
|
|
58
|
+
interface QueueFailure {
|
|
59
|
+
readonly queue: string;
|
|
60
|
+
readonly messageId: string;
|
|
61
|
+
readonly attempts: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Per-message consumer: each message is acked when `message` resolves and retried when it throws,
|
|
65
|
+
* so one bad message never makes the platform redeliver the whole batch.
|
|
66
|
+
*/
|
|
67
|
+
interface QueueConsumer<TEnv, TBody = unknown> {
|
|
68
|
+
message(body: TBody, message: MessageLike<TBody>, env: TEnv, ctx: ExecutionContextLike): Awaitable<void>;
|
|
69
|
+
/** Delay before a failed message is delivered again. Default: the queue's own retry delay. */
|
|
70
|
+
readonly retryDelaySeconds?: number;
|
|
71
|
+
/** Called for each failed message. Default: `console.error` with the error name and message id only. */
|
|
72
|
+
onError?(error: unknown, failure: QueueFailure): void;
|
|
73
|
+
}
|
|
74
|
+
/** Handlers for the Worker events other than `fetch`. */
|
|
75
|
+
interface EdgeWorkerHandlers<TEnv> {
|
|
76
|
+
readonly scheduled?: ScheduledHandler<TEnv>;
|
|
77
|
+
readonly queue?: QueueBatchHandler<TEnv> | QueueConsumer<TEnv>;
|
|
78
|
+
readonly email?: EmailHandler<TEnv>;
|
|
79
|
+
}
|
|
80
|
+
/** Worker module export: `fetch` plus the event handlers that were given. */
|
|
81
|
+
interface EdgeWorker<TEnv> {
|
|
82
|
+
readonly fetch: EdgeHandler<TEnv>;
|
|
83
|
+
readonly scheduled?: ScheduledHandler<TEnv>;
|
|
84
|
+
readonly queue?: QueueBatchHandler<TEnv>;
|
|
85
|
+
readonly email?: EmailHandler<TEnv>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Zero-conversion Fetch adapter for Edge runtimes (Cloudflare, Fastly, Deno). */
|
|
89
|
+
declare function toEdgeHandler<TEnv = unknown>(app: EdgeApp): EdgeHandler<TEnv>;
|
|
90
|
+
/**
|
|
91
|
+
* Worker-style module export: `export default createEdgeWorker<Env>(app, { scheduled, queue, email });`.
|
|
92
|
+
* Cloudflare calls `fetch(request, env, ctx)`; both reach handlers as `ctx.runtime`. Only the handlers
|
|
93
|
+
* you pass are exported, so Cloudflare never sees a `queue` or `scheduled` the Worker does not have.
|
|
94
|
+
*/
|
|
95
|
+
declare function createEdgeWorker<TEnv = unknown>(app: EdgeApp, handlers?: EdgeWorkerHandlers<TEnv>): EdgeWorker<TEnv>;
|
|
96
|
+
/**
|
|
97
|
+
* Typed access to Worker bindings from a handler: `getEnv<Env>(ctx).MY_KV`.
|
|
98
|
+
* Throws when the runtime did not provide an `env` (Deno, Fastly, tests).
|
|
99
|
+
*/
|
|
100
|
+
declare function getEnv<TEnv>(ctx: {
|
|
101
|
+
readonly runtime: RuntimeBindings;
|
|
102
|
+
}): TEnv;
|
|
103
|
+
|
|
104
|
+
export { createEdgeWorker, getEnv, toEdgeHandler };
|
|
105
|
+
export type { EdgeApp, EdgeHandler, EdgeWorker, EdgeWorkerHandlers, EmailHandler, ForwardableEmailMessageLike, MessageBatchLike, MessageLike, QueueBatchHandler, QueueConsumer, QueueFailure, ScheduledControllerLike, ScheduledHandler };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function toEdgeHandler(app) {
|
|
2
|
+
return (request, env, executionCtx) => app.fetch(request, env, executionCtx);
|
|
3
|
+
}
|
|
4
|
+
function createEdgeWorker(app, handlers = {}) {
|
|
5
|
+
const { scheduled, queue, email } = handlers;
|
|
6
|
+
return {
|
|
7
|
+
fetch: toEdgeHandler(app),
|
|
8
|
+
...scheduled === void 0 ? {} : { scheduled },
|
|
9
|
+
...queue === void 0 ? {} : { queue: typeof queue === "function" ? queue : consumeEachMessage(queue) },
|
|
10
|
+
...email === void 0 ? {} : { email }
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function consumeEachMessage(consumer) {
|
|
14
|
+
const retryOptions = consumer.retryDelaySeconds === void 0 ? void 0 : { delaySeconds: consumer.retryDelaySeconds };
|
|
15
|
+
return async (batch, env, ctx) => {
|
|
16
|
+
for (const message of batch.messages) {
|
|
17
|
+
try {
|
|
18
|
+
await consumer.message(message.body, message, env, ctx);
|
|
19
|
+
message.ack();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
message.retry(retryOptions);
|
|
22
|
+
const failure = { queue: batch.queue, messageId: message.id, attempts: message.attempts };
|
|
23
|
+
if (consumer.onError !== void 0) consumer.onError(error, failure);
|
|
24
|
+
else console.error(`[tupik] queue ${failure.queue} message ${failure.messageId} failed (attempt ${failure.attempts}): ${errorName(error)}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function errorName(error) {
|
|
30
|
+
return error instanceof Error ? error.name : typeof error;
|
|
31
|
+
}
|
|
32
|
+
function getEnv(ctx) {
|
|
33
|
+
const env = ctx.runtime.env;
|
|
34
|
+
if (env === void 0) {
|
|
35
|
+
throw new Error("No platform env available: the runtime did not pass bindings to fetch()");
|
|
36
|
+
}
|
|
37
|
+
return env;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { createEdgeWorker, getEnv, toEdgeHandler };
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tupik/edge",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Edge adapter for Tupik: Cloudflare Workers, Fastly and any fetch-handler runtime.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"tupik",
|
|
8
|
+
"typescript",
|
|
9
|
+
"web-framework",
|
|
10
|
+
"edge",
|
|
11
|
+
"cloudflare-workers",
|
|
12
|
+
"fastly",
|
|
13
|
+
"serverless"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/CodeHamper/tupikjs/tree/main/packages/edge#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/CodeHamper/tupikjs.git",
|
|
19
|
+
"directory": "packages/edge"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/CodeHamper/tupikjs/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22.12"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@tupik/core": "^1.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"typescript": "^5.6.0",
|
|
45
|
+
"unbuild": "^3.0.0",
|
|
46
|
+
"vitest": "^2.1.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "unbuild",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "vitest run"
|
|
52
|
+
}
|
|
6
53
|
}
|