Skip to content
Open
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
1 change: 0 additions & 1 deletion .github/workflows/test-npm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
- run: corepack enable

- uses: actions/checkout@v4
- run: npm --no-workspaces ci
- run: npm run generate
- run: npm --workspaces ci
- run: npm --workspaces test
8 changes: 8 additions & 0 deletions SkiffaExamples.code-workspace
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"folders": [
{
"name": ".github/workflows",
"path": ".github/workflows",
},
{
"name": "specifications",
"path": "specifications",
Expand All @@ -16,6 +20,10 @@
"name": "npm/todo",
"path": "packages/npm/todo",
},
{
"name": "npm/appsignal",
"path": "packages/npm/appsignal",
},
],
"settings": {
"window.title": "Skiffa Examples",
Expand Down
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version: "0.2"
words:
- APPSIGNAL
- esbenp
- iife
- openapi
Expand Down
4,660 changes: 4,076 additions & 584 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"scripts": {
"spelling": "cspell",
"formatting": "prettier --check *",
"generate": "node ./scripts/generate.mjs",
"initialize": "node ./scripts/initialize.mjs"
"generate": "$npm_node_execpath ./scripts/generate.mjs",
"build": "$npm_execpath run --workspaces --if-present build",
"pretest": "$npm_execpath run --workspaces --if-present pretest",
"test": "$npm_node_execpath --test packages/npm/*/transpiled/**/*.test.js"
},
"devDependencies": {
"@skiffa/generator": "^0.13.20",
"cspell": "^8.14.2",
"prettier": "^3.3.3"
}
Expand Down
17 changes: 17 additions & 0 deletions packages/npm/appsignal/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "run file",
"program": "${file}",
"args": [],
"cwd": "${workspaceFolder}",
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/transpiled/**/*.js"],
"preLaunchTask": "build",
"outputCapture": "std"
}
]
}
15 changes: 15 additions & 0 deletions packages/npm/appsignal/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"label": "build",
"script": "build",
"problemMatcher": ["$tsc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
3 changes: 3 additions & 0 deletions packages/npm/appsignal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AppSignal example

To test AppSignal.
29 changes: 29 additions & 0 deletions packages/npm/appsignal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"private": true,
"type": "commonjs",
"scripts": {
"prepack": "$npm_node_execpath ./scripts/build.mjs",
"pretest": "$npm_node_execpath ./scripts/build.mjs",
"prestart": "$npm_node_execpath ./scripts/build.mjs",
"start": "$npm_node_execpath transpiled/server.js",
"build": "$npm_node_execpath ./scripts/build.mjs",
"test": "$npm_node_execpath --test ./transpiled/**/*.test.js"
},
"dependencies": {
"@appsignal/nodejs": "^3.5.0",
"@skiffa/appsignal": "^0.3.3",
"@types/node": "^18.19.45",
"msecs": "^1.0.4",
"noop-api": "^0.1.0",
"shared": "^0.1.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@tsconfig/node18": "^18.2.4",
"rollup": "^4.21.0",
"typescript": "^5.5.4"
},
"engines": {
"node": ">=18"
}
}
14 changes: 14 additions & 0 deletions packages/npm/appsignal/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

import cp from "child_process";
import path from "path";
import { fileURLToPath } from "url";

const dirname = path.dirname(fileURLToPath(import.meta.url));
const projectRoot = path.resolve(dirname, "..");

const options = { shell: true, stdio: "inherit", env: process.env, cwd: projectRoot };

cp.execFileSync(process.env.npm_execpath, ["--workspace", "todo-api", "run", "build"], options);

cp.execFileSync("tsc", ["--build"], options);
12 changes: 12 additions & 0 deletions packages/npm/appsignal/src/appsignal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Appsignal } from "@appsignal/nodejs";
import * as skiffaAppsignal from "@skiffa/appsignal";

const appsignalPushApiKey = process.env.APPSIGNAL_PUSH_API_KEY;

export const appsignal = new Appsignal({
active: appsignalPushApiKey != null,
environment: process.env.NODE_ENV,
name: "skiffa-examples/appsignal",
pushApiKey: appsignalPushApiKey,
additionalInstrumentations: [new skiffaAppsignal.Instrumentation()],
});
1 change: 1 addition & 0 deletions packages/npm/appsignal/src/operation-handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./operation-handlers/noop.js";
14 changes: 14 additions & 0 deletions packages/npm/appsignal/src/operation-handlers/noop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import test from "node:test";
import * as api from "noop-api";
import * as operationHandlers from "../operation-handlers.js";

test("noop", async () => {
const server = new api.server.Server();
server.registerNoopOperation(operationHandlers.noop);

await using listener = await api.lib.listen(server);

const baseUrl = new URL(`http://localhost:${listener.port}`);

await api.client.noop({ baseUrl });
});
7 changes: 7 additions & 0 deletions packages/npm/appsignal/src/operation-handlers/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { second } from "msecs";
import * as api from "noop-api";
import timers from "timers/promises";

export const noop: api.server.NoopOperationHandler<{}> = async () => {
await timers.setTimeout(2 * second);
};
12 changes: 12 additions & 0 deletions packages/npm/appsignal/src/root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import path from "path";
import { fileURLToPath } from "url";

/**
* the absolute path to this projects root directory
*/
export const projectRoot = makeProjectRoot();

function makeProjectRoot() {
const dirname = path.dirname(fileURLToPath(import.meta.url));
return path.resolve(dirname, "..");
}
38 changes: 38 additions & 0 deletions packages/npm/appsignal/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import "./appsignal.js";

import * as api from "noop-api";
import * as shared from "shared";
import * as operationHandlers from "./operation-handlers.js";

main();

// entrypoint for the server
async function main() {
// create the server
const server = new api.server.Server();

// register all operations
server.registerOperations(operationHandlers);

// get port to listen to from the environment or use the default
const port = Number(process.env.PORT ?? 8080);

console.info(`Starting server...`);
{
// listen to the specified port and send requests to the server. We are
// using the `using` syntax here, the server will be disposed (terminated)
// at the end of the current block.
await using listener = await api.lib.listen(server, { port });

console.info(`Server started (${listener.port})`);

// wait for a user to send a signal and eventually stop listening.
await shared.waitForSignal("SIGINT", "SIGTERM");

console.info("Stopping server...");

// Thanks to the `using` keyword (and a proper implementation of the dispose)
// the server is terminated here, at the end of this block.
}
console.info(`Server stopped`);
}
13 changes: 13 additions & 0 deletions packages/npm/appsignal/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@tsconfig/node18",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./transpiled",
"declarationDir": "./typed",
"sourceMap": true,
"declaration": true,
"composite": true
},
"include": ["src/**/*"],
"references": [{ "path": "../shared/" }]
}
14 changes: 6 additions & 8 deletions packages/npm/reverse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
"private": true,
"type": "module",
"scripts": {
"prepack": "node ./scripts/build.js",
"pretest": "node ./scripts/build.js",
"prestart": "node ./scripts/build.js",
"start": "node transpiled/server.js",
"build": "node ./scripts/build.js",
"test": "node --test ./transpiled/**/*.test.js"
"prepack": "tsc",
"pretest": "tsc",
"prestart": "tsc",
"start": "$npm_node_execpath transpiled/server.js",
"build": "tsc",
"test": "$npm_node_execpath --test ./transpiled/**/*.test.js"
},
"dependencies": {
"@types/node": "^18.19.45",
"reverse-api": "^0.1.0",
"shared": "^0.1.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@tsconfig/node18": "^18.2.4",
"rollup": "^4.21.0",
"typescript": "^5.5.4"
},
"engines": {
Expand Down
20 changes: 0 additions & 20 deletions packages/npm/reverse/rollup.config.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const projectRoot = path.resolve(dirname, "..");

const options = { shell: true, stdio: "inherit", env: process.env, cwd: projectRoot };

cp.execFileSync("npm", ["--workspace", "todo-api", "run", "build"], options);
cp.execFileSync(process.env.npm_execpath, ["--workspace", "reverse-api", "run", "build"], options);

cp.execFileSync("tsc", ["--build"], options);

Expand Down
2 changes: 1 addition & 1 deletion packages/npm/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pretest": "tsc --build",
"prestart": "tsc --build",
"build": "tsc --build",
"test": "node --test ./transpiled/**/*.test.js"
"test": "$npm_node_execpath --test ./transpiled/**/*.test.js"
},
"dependencies": {
"@types/node": "^18.19.45"
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/shared/src/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let lastId = Date.now();

export function nextId() {
const id = ++lastId;
return id
return id;
}

export function nextStringId(prefix: string) {
Expand Down
1 change: 0 additions & 1 deletion packages/npm/shared/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./id.js";
export * from "./signal.js";

12 changes: 6 additions & 6 deletions packages/npm/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"prepack": "node ./scripts/build.js",
"pretest": "node ./scripts/build.js",
"prestart": "node ./scripts/build.js",
"start": "node transpiled/server.js",
"build": "node ./scripts/build.js",
"test": "node --test ./transpiled/operation-handlers/todo.test.js"
"prepack": "$npm_node_execpath ./scripts/build.mjs",
"pretest": "$npm_node_execpath ./scripts/build.mjs",
"prestart": "$npm_node_execpath ./scripts/build.mjs",
"start": "$npm_node_execpath transpiled/server.js",
"build": "$npm_node_execpath ./scripts/build.mjs",
"test": "$npm_node_execpath --test ./transpiled/**/*.test.js"
},
"keywords": [],
"author": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const projectRoot = path.resolve(dirname, "..");

const options = { shell: true, stdio: "inherit", env: process.env, cwd: projectRoot };

cp.execFileSync("npm", ["--workspace", "reverse-api", "run", "build"], options);
cp.execFileSync(process.env.npm_execpath, ["--workspace", "todo-api", "run", "build"], options);

cp.execFileSync("tsc", ["--build"], options);

Expand Down
2 changes: 1 addition & 1 deletion packages/npm/todo/src/operation-handlers/todo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test("todo test scenario", async () => {
await using listener = await api.lib.listen(server);
const baseUrl = new URL(`http://localhost:${listener.port}`);

let id: number
let id: number;

await test("list (expect empty list)", async () => {
const listTodo = await api.client.listTodoItems({ baseUrl });
Expand Down
12 changes: 7 additions & 5 deletions scripts/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ const workspaceRoot = path.resolve(dirname, "..");

const options = { shell: true, stdio: "inherit", env: process.env };

const names = ["reverse-api", "todo-api"];
const names = ["reverse-api", "todo-api", "noop-api"];

for (const name of names) {
cp.execFileSync(
"skiffa-generator",
"npx",
[
"--yes",
"--package",
"@skiffa/generator@0.13.20",
"--",
"skiffa-generator",
"package",
path.resolve(workspaceRoot, "specifications", `${name}.yaml`),
"--package-directory",
Expand All @@ -26,7 +31,4 @@ for (const name of names) {
],
options,
);

cp.execFileSync(process.env.npm_execpath, ["--workspace", name, "install"], options);
cp.execFileSync(process.env.npm_execpath, ["--workspace", name, "run", "build"], options);
}
9 changes: 0 additions & 9 deletions scripts/initialize.mjs

This file was deleted.

Loading