https://github.com/spacecloud-io/space-sdk-ts
Typescript API for Space Cloud
https://github.com/spacecloud-io/space-sdk-ts
Last synced: 12 months ago
JSON representation
Typescript API for Space Cloud
- Host: GitHub
- URL: https://github.com/spacecloud-io/space-sdk-ts
- Owner: spacecloud-io
- License: apache-2.0
- Created: 2023-05-31T09:35:35.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-24T03:20:51.000Z (over 2 years ago)
- Last Synced: 2025-02-17T04:41:24.210Z (about 1 year ago)
- Language: TypeScript
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Space SDK (Typescript)
Typescript API for Space Cloud
## Worker API
### Sample usage
```ts
import { Server } from "@spacecloud-io/worker";
import { z } from "zod";
// We first create the server object
const server = Server.create({
name: "myServer",
baseUrl: "/v2", // Optional. Defaults to `/v1`.
port: 8080 // Optional. Defaults to `3000`.
});
// Create a router object. All operations are registered on this router.
const router = server.router();
// Register a query object.
router.query("operate") // `opId` is the name of the operation
.method("GET") // Defaults to `GET` for queries and `POST` for mutations
.url("/v1/operate") // Defaults to `${baseUrl}/${opId}`
.input(z.object({ name: z.string() }))
.output(z.object({ greeting: z.string() }))
.fn(async (_ctx, req) => {
return { greeting: `Hi ${req.name}` };
});
// Start the express http server.
server.start();
```
The worker generates the some additional routes as shown below:
```
# Routes created to expose the OpenAPI specification generated
[GET] `${baseUrl}/openapi.json`
[GET] `${baseUrl}/openapi.yaml`
```
### Saving OpenAPI specification to disk
Simply add the flag `--save-openapi` flag to save the autogenerated Open API specification in yaml format. Use the `-f, --file ` flag to control the file path. The specification will be persisted at `${file}/openapi.yaml`.
```
node index.js --save-openapi -f ./config
```