-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
127 additions
and
23 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,28 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run tests | ||
run: npm run test |
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,26 @@ | ||
<p align="center"> | ||
<img src="./assets/logo.png" width="200" style="border-radius: 10px" /> | ||
</p> | ||
|
||
# Differential Code Examples | ||
|
||
## The simplest example | ||
|
||
To see the simplest example for a service and the service consumer, see: | ||
|
||
1. Hello service at [src/services/hello-service.ts](./src/services/hello-service.ts) | ||
2. Service consumer at [src/example-1-simple.ts](./src/example-1-simple.ts) | ||
|
||
To run the example: | ||
|
||
### Start the server | ||
|
||
```bash | ||
npm run services:hello | ||
``` | ||
|
||
### Start the client | ||
|
||
```bash | ||
npm run client:hello | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,26 @@ | ||
import process from "process"; | ||
import { d } from "../d"; | ||
|
||
export const hello = async (from: string) => { | ||
console.log("hello function called", from); | ||
return `Hello, ${from}! I'm running on ${process.platform} and on pid=${process.pid}.`; | ||
}; | ||
|
||
export const helloService = d.service({ | ||
name: "hello", | ||
functions: { | ||
hello, | ||
}, | ||
}); | ||
|
||
// this registers a service at api.differential.dev | ||
// under the api secret, and makes it available for | ||
// any d.call() function which uses the same api secret | ||
helloService.start(); | ||
|
||
console.log("hello service started"); | ||
|
||
process.on("beforeExit", async () => { | ||
console.log("stopping hello service"); | ||
await helloService.stop(); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
import test from "node:test"; | ||
import { helloService } from "../services/hello-service"; | ||
import { d } from "../d"; | ||
import assert from "node:assert"; | ||
|
||
test("example", async (t) => { | ||
// start the service | ||
helloService.start(); | ||
|
||
const greeting = await d.call<typeof helloService, "hello">( | ||
"hello", | ||
`process ${process.pid}` | ||
); | ||
|
||
assert.match( | ||
greeting, | ||
/Hello, process \d+! I'm running on [a-z]+ and on pid=\d+/ | ||
); | ||
|
||
console.log("stopping service"); | ||
|
||
// why the fuck is this service not stopping? | ||
|
||
// stop the service | ||
await helloService.stop(); | ||
|
||
console.log("stopped service"); | ||
}); |