-
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
0 parents
commit 8878219
Showing
25 changed files
with
4,725 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 @@ | ||
dist/ |
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,25 @@ | ||
/* eslint-env node */ | ||
|
||
/** @type {import('eslint').ESLint.ConfigData} */ | ||
module.exports = { | ||
extends: ['prettier'], | ||
|
||
// Extra rules for TypeScript files | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx'], | ||
extends: ['plugin:@typescript-eslint/recommended', 'prettier'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./tsconfig.json', './example/tsconfig.json'], | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
rules: { | ||
'@typescript-eslint/consistent-type-imports': 'error', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-floating-promises': 'error', | ||
}, | ||
}, | ||
], | ||
} |
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,20 @@ | ||
name: ci | ||
on: push | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v3 | ||
with: | ||
version: 8.x.x | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
cache: pnpm | ||
- run: pnpm install --frozen-lockfile | ||
- run: pnpm fmt:check | ||
- run: pnpm type-check | ||
- run: pnpm lint | ||
- run: pnpm build |
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,5 @@ | ||
.wrangler/ | ||
dist/ | ||
node_modules/ | ||
*.log | ||
.dev.vars |
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 @@ | ||
pnpm-lock.yaml |
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,11 @@ | ||
{ | ||
"npm.packageManager": "pnpm", | ||
"typescript.enablePromptUseWorkspaceTsdk": true, | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"prettier.prettierPath": "node_modules/prettier/index.cjs", | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
}, | ||
"eslint.lintTask.enable": true, | ||
"eslint.lintTask.options": "--cache --cache-location node_modules/.cache/.eslintcache ." | ||
} |
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,41 @@ | ||
# `@depot/connectrpc-workers` | ||
|
||
A [Connect RPC](https://connectrpc.com/) adapter for [Cloudflare Workers](https://workers.cloudflare.com/). | ||
|
||
## Installation | ||
|
||
You can install the module with your favorite package manager: | ||
|
||
```bash | ||
pnpm add @depot/connectrpc-workers | ||
``` | ||
|
||
This package depends on the peer dependencies `@connectrpc/connect` and `@cloudflare/workers-types`. | ||
|
||
## Usage | ||
|
||
You can construct a function to register handlers for your Connect services, then construct a Cloudflare Workers fetch event handler from those routes: | ||
|
||
```typescript | ||
import type {ConnectRouter} from '@connectrpc/connect' | ||
import {connectWorkersAdapter} from '@depot/connectrpc-workers' | ||
|
||
function routes(router: ConnectRouter) { | ||
// implement rpc Say(SayRequest) returns (SayResponse) | ||
router.rpc(ElizaService, ElizaService.methods.say, async (req) => ({ | ||
sentence: `you said: ${req.sentence}`, | ||
})) | ||
} | ||
|
||
const handler = connectWorkersAdapter({routes}) | ||
|
||
export default { | ||
fetch(request, env, context) { | ||
return handler(request, env, context) | ||
}, | ||
} satisfies ExportedHandler | ||
``` | ||
|
||
## License | ||
|
||
MIT License, see `LICENSE`. |
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 @@ | ||
pnpm-lock.yaml |
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,27 @@ | ||
# Example | ||
|
||
## Setup | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
## Run | ||
|
||
In one terminal: | ||
|
||
```bash | ||
pnpm run server | ||
``` | ||
|
||
Then in another terminal: | ||
|
||
```bash | ||
pnpm run client | ||
``` | ||
|
||
Or to run against a deployed worker (to test HTTP/2): | ||
|
||
```bash | ||
BASE_URL=https://example.worker.workers.dev run client | ||
``` |
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,12 @@ | ||
version: v1 | ||
plugins: | ||
- name: es | ||
out: src/proto | ||
opt: | ||
- target=ts | ||
- import_extension=none | ||
- name: connect-es | ||
out: src/proto | ||
opt: | ||
- target=ts | ||
- import_extension=none |
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,3 @@ | ||
version: v1 | ||
directories: | ||
- proto |
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,25 @@ | ||
{ | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"client": "tsx src/client.ts", | ||
"generate": "buf generate --include-imports && prettier --write src/proto", | ||
"server": "wrangler dev", | ||
"type-check": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@bufbuild/protobuf": "^1.8.0", | ||
"@cloudflare/workers-types": "^4.20240405.0", | ||
"@connectrpc/connect": "^1.4.0", | ||
"@connectrpc/connect-node": "^1.4.0" | ||
}, | ||
"devDependencies": { | ||
"@bufbuild/protoc-gen-es": "^1.8.0", | ||
"@connectrpc/protoc-gen-connect-es": "^1.4.0", | ||
"@types/node": "^20.12.7", | ||
"esbuild": "^0.20.2", | ||
"tsx": "^4.7.2", | ||
"typescript": "^5.4.5", | ||
"wrangler": "^3.50.0" | ||
} | ||
} |
Oops, something went wrong.