Skip to content

Commit

Permalink
Add root readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrconley committed Mar 11, 2024
1 parent 12f39bf commit 8b50af7
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Nornir Event Processing

This is a monorepo for the Nornir Event Processing framework.
It is a collection of packages that can be used together or independently to build event-driven applications.

## Packages
### [Nornir Core](packages/core/README.md)
Provides the core functionality for Nornir.
It is a lightweight, functional, and type-safe event processing framework based on a middleware chain.

### [Nornir Rest](packages/rest/README.md)
A ergonomic and type-safe REST framework based on Nornir chains.
It allows you to build strongly typed APIs exactly in sync with your documentation.
Supports both specification-first and code-first development.
90 changes: 90 additions & 0 deletions packages/test/src/openapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import nornir from "@nornir/core";
import { ApiGatewayProxyV2, openAPIChain, OpenAPIRouter, OpenAPIV3_1, startLocalServer } from "@nornir/rest";
import type { APIGatewayProxyEventV2, APIGatewayProxyHandlerV2 } from "aws-lambda";

const Spec = {
info: {
title: "Test API",
version: "1.0.0",
},
openapi: "3.1.0",
components: {
schemas: {
"cool": {
type: "object",
properties: {
cool: {
type: "string",
},
},
},
"csv": {
type: "string",
pattern: "^[a-zA-Z0-9,]+$",
},
},
},
paths: {
"/cool/test": {
post: {
requestBody: {
required: true,
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/cool",
},
},
"text/csv": {
schema: {
$ref: "#/components/schemas/csv",
},
},
},
},
responses: {
"200": {
description: "cool",
},
"400": {
description: "bad",
headers: {
"x-foo": {
schema: {
type: "string",
},
required: true,
},
},
},
},
},
},
},
} as const satisfies OpenAPIV3_1.Document;

Check warning on line 64 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

const router = OpenAPIRouter.fromSpec(Spec);

Check warning on line 66 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

router.implementRoute("/cool/test", "post", chain =>

Check warning on line 68 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
chain.use(req => {

Check warning on line 69 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
if (req.contentType === "text/csv") {
console.log(req.body.toUpperCase());

Check warning on line 71 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else if (req.contentType === "application/json") {
console.log(req.body.cool);

Check warning on line 73 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 74 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 74 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 74 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 74 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 74 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return {
contentType: "application/json",
statusCode: "400",
headers: {
"x-foo": "bar",
},
} as const;

Check warning on line 81 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}));

Check warning on line 82 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 82 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

export const handler: APIGatewayProxyHandlerV2 = nornir<APIGatewayProxyEventV2>()
.use(ApiGatewayProxyV2.toHttpEvent)
.useChain(openAPIChain(router))
.use(ApiGatewayProxyV2.toResult)
.build();

Check warning on line 88 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

startLocalServer(openAPIChain(router));

Check warning on line 90 in packages/test/src/openapi.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

0 comments on commit 8b50af7

Please sign in to comment.