-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
const router = OpenAPIRouter.fromSpec(Spec); | ||
|
||
router.implementRoute("/cool/test", "post", chain => | ||
chain.use(req => { | ||
if (req.contentType === "text/csv") { | ||
console.log(req.body.toUpperCase()); | ||
} else if (req.contentType === "application/json") { | ||
console.log(req.body.cool); | ||
} | ||
Check warning on line 74 in packages/test/src/openapi.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 74 in packages/test/src/openapi.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 74 in packages/test/src/openapi.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
Check warning on line 74 in packages/test/src/openapi.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
return { | ||
contentType: "application/json", | ||
statusCode: "400", | ||
headers: { | ||
"x-foo": "bar", | ||
}, | ||
} as const; | ||
})); | ||
Check warning on line 82 in packages/test/src/openapi.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
|
||
export const handler: APIGatewayProxyHandlerV2 = nornir<APIGatewayProxyEventV2>() | ||
.use(ApiGatewayProxyV2.toHttpEvent) | ||
.useChain(openAPIChain(router)) | ||
.use(ApiGatewayProxyV2.toResult) | ||
.build(); | ||
|
||
startLocalServer(openAPIChain(router)); | ||