Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dir: [consent-management, data-collection]
dir: [edge-function, data-collection]
defaults:
run:
working-directory: ${{ matrix.dir }}
Expand Down
32 changes: 0 additions & 32 deletions consent-management/src/index.ts

This file was deleted.

23 changes: 0 additions & 23 deletions consent-management/test/index.spec.ts

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions consent-management/types/wit.d.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
manifest-version = 1

[component]
name = "example-ts-consent-management-component"
name = "example-ts-edge-function-component"
version = "1.0.0"
category = "consent-management"
subcategory = "consent-mapping"
description = "Example TypeScript component for consent management"
category = "edge-function"
subcategory = "wasm-function"
description = "Example TypeScript component for edge function"
documentation = "https://github.com/edgee-cloud/example-ts-component"
repository = "https://github.com/edgee-cloud/example-ts-component"
language = "TypeScript"
wit-version = "1.0.0"

[component.build]
command = "npm install && npm run generate && npm run build"
output_path = "./example-ts-component.wasm"
output_path = "./example-ts-edge-function-component.wasm"

[component.settings.example]
title = "Example Config Field"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "example-ts-component",
"name": "example-ts-edge-function-component",
"type": "module",
"main": "src/index.ts",
"types": "types/wit.d.ts",
"scripts": {
"generate": "npx @bytecodealliance/jco types .edgee/wit -o types",
"compile": "npx tsc",
"build": "npm run compile && npx @bytecodealliance/jco componentize src/index.js --wit .edgee/wit -o example-ts-component.wasm -n consent-management -d all",
"build": "npm run compile && npx @bytecodealliance/jco componentize src/index.js --wit .edgee/wit -o example-ts-edge-function-component.wasm -n edge-function",
"lint": "npx eslint",
"test": "mocha",
"coverage": "c8 --src js --all -r text -r text-summary npm test"
Expand Down
86 changes: 86 additions & 0 deletions edge-function/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
ResponseOutparam,
OutgoingBody,
OutgoingResponse,
Fields,
InputStream,
IncomingRequest,
} from "wasi:http/types@0.2.0";

const index = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Coming Soon</title>
<style>
body {
margin: 0;
padding: 0;
font-family: system-ui, sans-serif;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
height: 100vh;
background-color: #f4f4f4;
color: #333;
}
.container {
max-width: 400px;
padding: 2rem;
}
h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
}
p {
font-size: 1.1rem;
margin-bottom: 2rem;
}
footer {
font-size: 0.9rem;
color: #888;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>Coming Soon</h1>
<p>We're working hard to launch something awesome. Stay tuned!</p>
<footer>Served by <a href="https://www.edgee.cloud">Edgee</a></footer>
</div>
</body>
</html>
`

function handle(req: IncomingRequest, resp: ResponseOutparam) {
const outgoingResponse = new OutgoingResponse(new Fields());
outgoingResponse.setStatusCode(200);

let outgoingBody = outgoingResponse.body();
{
let outputStream = outgoingBody.write();
outputStream.write(
new Uint8Array(new TextEncoder().encode(index))
);
outputStream.flush();
// @ts-ignore: need to drop the stream according to WASI spec
outputStream[Symbol.dispose]();
}

OutgoingBody.finish(outgoingBody, undefined);
ResponseOutparam.set(resp, { tag: 'ok', val: outgoingResponse });
}

export const incomingHandler = {
handle,
};
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"strict": true,
"noImplicitAny": true,
"skipLibCheck": true,
"paths": {
"wasi:http/types@0.2.0": [ "./types/interfaces/wasi-http-types.d.ts" ]
},
}
}
35 changes: 35 additions & 0 deletions edge-function/types/interfaces/wasi-clocks-monotonic-clock.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @module Interface wasi:clocks/monotonic-clock@0.2.0 **/
/**
* Read the current value of the clock.
*
* The clock is monotonic, therefore calling this function repeatedly will
* produce a sequence of non-decreasing values.
*/
export function now(): Instant;
/**
* Query the resolution of the clock. Returns the duration of time
* corresponding to a clock tick.
*/
export function resolution(): Duration;
/**
* Create a `pollable` which will resolve once the specified instant
* occured.
*/
export function subscribeInstant(when: Instant): Pollable;
/**
* Create a `pollable` which will resolve once the given duration has
* elapsed, starting at the time at which this function was called.
* occured.
*/
export function subscribeDuration(when: Duration): Pollable;
export type Pollable = import('./wasi-io-poll.js').Pollable;
/**
* An instant in time, in nanoseconds. An instant is relative to an
* unspecified initial value, and can only be compared to instances from
* the same monotonic-clock.
*/
export type Instant = bigint;
/**
* A duration of time, in nanoseconds.
*/
export type Duration = bigint;
16 changes: 16 additions & 0 deletions edge-function/types/interfaces/wasi-http-incoming-handler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @module Interface wasi:http/incoming-handler@0.2.0 **/
/**
* This function is invoked with an incoming HTTP Request, and a resource
* `response-outparam` which provides the capability to reply with an HTTP
* Response. The response is sent by calling the `response-outparam.set`
* method, which allows execution to continue after the response has been
* sent. This enables both streaming to the response body, and performing other
* work.
*
* The implementor of this function must write a response to the
* `response-outparam` before returning, or else the caller will respond
* with an error on its behalf.
*/
export function handle(request: IncomingRequest, responseOut: ResponseOutparam): void;
export type IncomingRequest = import('./wasi-http-types.js').IncomingRequest;
export type ResponseOutparam = import('./wasi-http-types.js').ResponseOutparam;
18 changes: 18 additions & 0 deletions edge-function/types/interfaces/wasi-http-outgoing-handler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @module Interface wasi:http/outgoing-handler@0.2.0 **/
/**
* This function is invoked with an outgoing HTTP Request, and it returns
* a resource `future-incoming-response` which represents an HTTP Response
* which may arrive in the future.
*
* The `options` argument accepts optional parameters for the HTTP
* protocol's transport layer.
*
* This function may return an error if the `outgoing-request` is invalid
* or not allowed to be made. Otherwise, protocol errors are reported
* through the `future-incoming-response`.
*/
export function handle(request: OutgoingRequest, options: RequestOptions | undefined): FutureIncomingResponse;
export type OutgoingRequest = import('./wasi-http-types.js').OutgoingRequest;
export type RequestOptions = import('./wasi-http-types.js').RequestOptions;
export type FutureIncomingResponse = import('./wasi-http-types.js').FutureIncomingResponse;
export type ErrorCode = import('./wasi-http-types.js').ErrorCode;
Loading