create-relkit 0.7.4 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-capabilities.d.ts +24 -33
- package/dist/create-capabilities.d.ts.map +1 -1
- package/dist/create-capabilities.js +52 -9
- package/dist/create-capabilities.js.map +1 -1
- package/dist/create-capabilities.types.d.ts +55 -0
- package/dist/create-capabilities.types.d.ts.map +1 -0
- package/dist/create-capabilities.types.js +2 -0
- package/dist/create-capabilities.types.js.map +1 -0
- package/dist/domain-artifact.d.ts.map +1 -1
- package/dist/domain-artifact.js +11 -3
- package/dist/domain-artifact.js.map +1 -1
- package/dist/domain-planning.d.ts +5 -0
- package/dist/domain-planning.d.ts.map +1 -1
- package/dist/domain-planning.js +25 -16
- package/dist/domain-planning.js.map +1 -1
- package/dist/generate-deployment-manifest.d.ts +10 -0
- package/dist/generate-deployment-manifest.d.ts.map +1 -0
- package/dist/generate-deployment-manifest.js +56 -0
- package/dist/generate-deployment-manifest.js.map +1 -0
- package/dist/generate-deployment.d.ts +2 -3
- package/dist/generate-deployment.d.ts.map +1 -1
- package/dist/generate-deployment.js +6 -47
- package/dist/generate-deployment.js.map +1 -1
- package/dist/generate-examples.d.ts +11 -0
- package/dist/generate-examples.d.ts.map +1 -0
- package/dist/generate-examples.js +28 -0
- package/dist/generate-examples.js.map +1 -0
- package/dist/generate-files-utilities.d.ts +1 -8
- package/dist/generate-files-utilities.d.ts.map +1 -1
- package/dist/generate-files-utilities.js +5 -19
- package/dist/generate-files-utilities.js.map +1 -1
- package/dist/project-discovery-artifacts.d.ts +15 -0
- package/dist/project-discovery-artifacts.d.ts.map +1 -0
- package/dist/project-discovery-artifacts.js +107 -0
- package/dist/project-discovery-artifacts.js.map +1 -0
- package/dist/project-discovery-artifacts.types.d.ts +22 -0
- package/dist/project-discovery-artifacts.types.d.ts.map +1 -0
- package/dist/project-discovery-artifacts.types.js +2 -0
- package/dist/project-discovery-artifacts.types.js.map +1 -0
- package/dist/project-discovery-facts.d.ts +8 -9
- package/dist/project-discovery-facts.d.ts.map +1 -1
- package/dist/project-discovery-facts.js +29 -135
- package/dist/project-discovery-facts.js.map +1 -1
- package/dist/project-discovery-members.d.ts +16 -0
- package/dist/project-discovery-members.d.ts.map +1 -0
- package/dist/project-discovery-members.js +57 -0
- package/dist/project-discovery-members.js.map +1 -0
- package/dist/project-discovery-types.d.ts +8 -0
- package/dist/project-discovery-types.d.ts.map +1 -1
- package/dist/render-auth-database.d.ts +33 -0
- package/dist/render-auth-database.d.ts.map +1 -0
- package/dist/render-auth-database.js +69 -0
- package/dist/render-auth-database.js.map +1 -0
- package/dist/render-auth-sources.d.ts +8 -2
- package/dist/render-auth-sources.d.ts.map +1 -1
- package/dist/render-auth-sources.js +9 -3
- package/dist/render-auth-sources.js.map +1 -1
- package/dist/render-auth.d.ts +14 -11
- package/dist/render-auth.d.ts.map +1 -1
- package/dist/render-auth.js +41 -108
- package/dist/render-auth.js.map +1 -1
- package/dist/render-database-sources.d.ts +7 -1
- package/dist/render-database-sources.d.ts.map +1 -1
- package/dist/render-database-sources.js +3 -2
- package/dist/render-database-sources.js.map +1 -1
- package/dist/render-database.d.ts +7 -10
- package/dist/render-database.d.ts.map +1 -1
- package/dist/render-database.js +12 -4
- package/dist/render-database.js.map +1 -1
- package/dist/render-database.types.d.ts +15 -0
- package/dist/render-database.types.d.ts.map +1 -0
- package/dist/render-database.types.js +2 -0
- package/dist/render-database.types.js.map +1 -0
- package/dist/render-route-sources.d.ts +3 -1
- package/dist/render-route-sources.d.ts.map +1 -1
- package/dist/render-route-sources.js +4 -2
- package/dist/render-route-sources.js.map +1 -1
- package/dist/render-routes.d.ts +1 -0
- package/dist/render-routes.d.ts.map +1 -1
- package/dist/render-routes.js +2 -1
- package/dist/render-routes.js.map +1 -1
- package/dist/render-service-members.d.ts +32 -0
- package/dist/render-service-members.d.ts.map +1 -0
- package/dist/render-service-members.js +61 -0
- package/dist/render-service-members.js.map +1 -0
- package/dist/render-service-requests.d.ts +35 -0
- package/dist/render-service-requests.d.ts.map +1 -0
- package/dist/render-service-requests.js +62 -0
- package/dist/render-service-requests.js.map +1 -0
- package/dist/render-service-support.d.ts +37 -0
- package/dist/render-service-support.d.ts.map +1 -0
- package/dist/render-service-support.js +74 -0
- package/dist/render-service-support.js.map +1 -0
- package/dist/render-service.d.ts +16 -13
- package/dist/render-service.d.ts.map +1 -1
- package/dist/render-service.js +33 -149
- package/dist/render-service.js.map +1 -1
- package/dist/render-service.types.d.ts +13 -0
- package/dist/render-service.types.d.ts.map +1 -0
- package/dist/render-service.types.js +2 -0
- package/dist/render-service.types.js.map +1 -0
- package/dist/scaffold-layout.d.ts +10 -0
- package/dist/scaffold-layout.d.ts.map +1 -0
- package/dist/scaffold-layout.js +29 -0
- package/dist/scaffold-layout.js.map +1 -0
- package/dist/templates/default/README.md +1 -1
- package/dist/templates/default/v1/agent/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/agent/README.md +9 -0
- package/dist/templates/default/v1/agent/package.json +4 -4
- package/dist/templates/default/v1/agent/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/agents/assistant.agent.ts +2 -1
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/agents/review.agent.ts +1 -0
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/functions/hello.function.ts +7 -0
- package/dist/templates/default/v1/agent/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/tools/lookup.tool.ts +2 -1
- package/dist/templates/default/v1/agent/tests/fixtures/lookup.tool.ts +2 -1
- package/dist/templates/default/v1/agent/tests/fixtures/mcp-options.ts +2 -1
- package/dist/templates/default/v1/agent/tests/unit/assistant.agent.test.ts +3 -2
- package/dist/templates/default/v1/agent/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/agent/tests/unit/lookup.tool.test.ts +2 -1
- package/dist/templates/default/v1/agent/tests/unit/review.agent.test.ts +2 -1
- package/dist/templates/default/v1/agent/tsconfig.json +1 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/api/README.md +10 -0
- package/dist/templates/default/v1/api/package.json +3 -3
- package/dist/templates/default/v1/api/src/routes/echo/route.ts +2 -1
- package/dist/templates/default/v1/api/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/api/src/routes/orders/route.ts +2 -1
- package/dist/templates/default/v1/api/src/{echo → services/echo}/functions/echo.function.ts +1 -0
- package/dist/templates/default/v1/api/src/services/echo/service.ts +5 -0
- package/dist/templates/default/v1/api/src/{hello → services/hello}/functions/hello.function.ts +7 -0
- package/dist/templates/default/v1/api/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/api/src/{orders → services/orders}/functions/create-order.function.ts +2 -1
- package/dist/templates/default/v1/api/src/{orders → services/orders}/functions/price-order.function.ts +1 -0
- package/dist/templates/default/v1/api/src/services/orders/service.ts +8 -0
- package/dist/templates/default/v1/api/tests/unit/echo.function.test.ts +2 -1
- package/dist/templates/default/v1/api/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/api/tests/unit/orders.function.test.ts +2 -1
- package/dist/templates/default/v1/api/tsconfig.json +1 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/fullstack/README.md +9 -0
- package/dist/templates/default/v1/fullstack/package.json +5 -5
- package/dist/templates/default/v1/fullstack/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/agents/assistant.agent.ts +2 -1
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/agents/review.agent.ts +1 -0
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/functions/hello.function.ts +1 -0
- package/dist/templates/default/v1/fullstack/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/tools/lookup.tool.ts +2 -1
- package/dist/templates/default/v1/fullstack/tests/unit/assistant.agent.test.ts +3 -2
- package/dist/templates/default/v1/fullstack/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/fullstack/tests/unit/review.agent.test.ts +2 -1
- package/dist/templates/default/v1/fullstack/tsconfig.json +1 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/minimal/README.md +10 -0
- package/dist/templates/default/v1/minimal/package.json +3 -3
- package/dist/templates/default/v1/minimal/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/minimal/src/{hello → services/hello}/functions/hello.function.ts +7 -0
- package/dist/templates/default/v1/minimal/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/minimal/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/minimal/tsconfig.json +1 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/tasks/README.md +8 -1
- package/dist/templates/default/v1/tasks/package.json +3 -3
- package/dist/templates/default/v1/tasks/src/routes/health/route.ts +2 -1
- package/dist/templates/default/v1/tasks/src/{orders → services/orders}/functions/health.function.ts +1 -0
- package/dist/templates/default/v1/tasks/src/{orders → services/orders}/jobs/export-orders.job.ts +2 -1
- package/dist/templates/default/v1/tasks/src/services/orders/service.ts +11 -0
- package/dist/templates/default/v1/tasks/src/{orders → services/orders}/tasks/export-orders.task.ts +1 -0
- package/dist/templates/default/v1/tasks/tests/unit/export-orders.task.test.ts +2 -1
- package/dist/templates/default/v1/tasks/tsconfig.json +2 -0
- package/package.json +3 -3
- package/dist/templates/default/v1/agent/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/api/src/echo/service.ts +0 -4
- package/dist/templates/default/v1/api/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/api/src/orders/service.ts +0 -7
- package/dist/templates/default/v1/fullstack/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/minimal/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/tasks/src/orders/service.ts +0 -10
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Testing a RELKIT application
|
|
2
|
+
|
|
3
|
+
Generated projects use Bun's test runner and `@relkit/testing`. Start with the existing `tests/unit` and `tests/integration` examples, then test the boundary that owns the behavior. Keep external providers and test state explicit; `RELKIT_ENV=test` alone does not select fakes.
|
|
4
|
+
|
|
5
|
+
## Direct function tests
|
|
6
|
+
|
|
7
|
+
`invokeFunction` runs a function descriptor through RELKIT's input/output validation and handler path without an HTTP server. Import a service's public function through its `service.ts` when testing the public member:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { expect, test } from "bun:test";
|
|
11
|
+
import { invokeFunction } from "@relkit/testing";
|
|
12
|
+
import orders from "@app/services/orders/service.js";
|
|
13
|
+
|
|
14
|
+
test("createOrder calculates its total", async () => {
|
|
15
|
+
await expect(
|
|
16
|
+
invokeFunction(orders.createOrder, { orderId: "order-1", sku: "book", quantity: 3 }),
|
|
17
|
+
).resolves.toEqual({ orderId: "order-1", sku: "book", totalCents: 300 });
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Pass explicit `env`, `context`, `clients`, or other `InvokeFunctionOptions` when the function needs them. Test invalid input and declared errors as well as success. Direct invocation does not test route mapping or middleware.
|
|
22
|
+
|
|
23
|
+
For several invocations that share a deterministic clock or provider state, use `createTestRuntime({ app, env, providers, startTimeMs })` and `runtime.invoke(target, input)`. `runtime.clock.advance(ms)` controls its test clock. Always `await runtime.close()` in `finally` or `afterAll`.
|
|
24
|
+
|
|
25
|
+
## Application and HTTP tests
|
|
26
|
+
|
|
27
|
+
`createTestApplication` discovers the generated project's routes and services. Pass its existing `relkit.config.ts`; `resourceProviders: "fake"` explicitly replaces graph-required resource providers for local tests:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { afterAll, expect, test } from "bun:test";
|
|
31
|
+
import { createTestApplication } from "@relkit/testing";
|
|
32
|
+
import config from "../../relkit.config.js";
|
|
33
|
+
|
|
34
|
+
const app = await createTestApplication(config, { resourceProviders: "fake" });
|
|
35
|
+
afterAll(() => app.close());
|
|
36
|
+
|
|
37
|
+
test("POST /orders maps and validates input", async () => {
|
|
38
|
+
const response = await app.http.request("/orders", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "content-type": "application/json" },
|
|
41
|
+
body: JSON.stringify({ orderId: "order-1", sku: "book", quantity: 3 }),
|
|
42
|
+
});
|
|
43
|
+
expect(response.status).toBe(201);
|
|
44
|
+
expect(await response.json()).toEqual({ orderId: "order-1", sku: "book", totalCents: 300 });
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Use `app.http.request`, `get`, or other client methods to assert status, body, and headers. Add requests for invalid input, anonymous callers, and unauthorized resource access where relevant. The harness has `runtime`, `clock`, `fakes`, and `observability` for controlled state and inspection. Options include `env`, `environment`, `bindingValues`, `providers`, and `projectRoot`; use explicit values for test-only configuration. This in-process HTTP boundary does not prove the full production middleware, cookie/origin policy, OpenAPI, or network transport. Verify those against a running backend when relevant.
|
|
49
|
+
|
|
50
|
+
## Provider and feature tests
|
|
51
|
+
|
|
52
|
+
- `createTestCacheFake`, `createTestBucketFake`, `createTestJobFake`, and `createTestEventFake` provide owned, inspectable test dependencies. `createTestFakes` groups native clients. Close any separately created fake after use. Replace every configured provider profile the graph needs, not only the one under direct assertion.
|
|
53
|
+
- `createTestHttpClient` exercises a standalone in-memory HTTP application. Use `createTestApplication` when route discovery and service wiring matter. `createTestRealtimeProvider` and `createTestAgentStateProvider` supply local stateful provider replacements.
|
|
54
|
+
- `createTestModel`, `createTestAgent`, and `assertAgentTrace` support deterministic agent execution. Use scripted responses and inspect tool calls or traces instead of live model calls or sleeps.
|
|
55
|
+
- For jobs, assert behavior beyond the descriptor shape: input/output, accepted run handle, progress, retry or cancellation policy, and idempotency where applicable. Use the test job adapter or fake appropriate to the contract.
|
|
56
|
+
- For database and auth integration, migrate an isolated temporary database before starting the application. Supply both parsed RELKIT environment and any native auth process environment required by the provider; close the app before removing test-owned files. Test public and protected requests with real cookies and separate users. A direct function mock does not verify migrations, sessions, or route protection.
|
|
57
|
+
- For realtime, streaming, and observability, test the exposed route or channel contract and recorded events/spans as applicable. Use a running backend for actual transport, connection, and browser behavior.
|
|
58
|
+
|
|
59
|
+
## Run the generated project checks
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
bun test tests/unit/hello.function.test.ts
|
|
63
|
+
bun run test:unit
|
|
64
|
+
bun run test:integration
|
|
65
|
+
bun run test
|
|
66
|
+
bun run check
|
|
67
|
+
bun run typecheck
|
|
68
|
+
bun run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Run only scripts present in the generated `package.json`; the task template may have a different test layout. Keep Docker, external providers, and cloud acceptance as explicit integration gates. The installed `@relkit/testing` declarations and the project's existing tests are the source for exact helper options.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# my-app
|
|
2
2
|
|
|
3
|
+
This maintained API candidate is exercised internally. Public API creation remains
|
|
4
|
+
disabled until its exact native and readiness certification passes.
|
|
5
|
+
|
|
3
6
|
A RelKit TypeScript/Bun API project with greeting, echo, and order routes.
|
|
4
7
|
Functions own the application handlers; routes describe transport mapping and
|
|
5
8
|
responses. Source-scoped IDs are inferred where safe, the order route targets a
|
|
@@ -21,3 +24,10 @@ The example routes are `GET /hello?name=RelKit`, `POST /echo` with a JSON
|
|
|
21
24
|
|
|
22
25
|
The default project needs no Docker daemon, cloud account, or deployment
|
|
23
26
|
credentials.
|
|
27
|
+
|
|
28
|
+
Each service owns `src/services/<name>/service.ts` and its local implementations.
|
|
29
|
+
Routes live in `src/routes/`, and configuration support lives in `src/platform/`.
|
|
30
|
+
Keep public descriptors and async handlers in ordinary TypeScript. When installation
|
|
31
|
+
is skipped, install dependencies and run `bunx --no-install relkit dev --prepare`
|
|
32
|
+
before development. Use `relkit migrate layout` to preview a move of an existing
|
|
33
|
+
flat application; additions otherwise preserve its detected root.
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"graph": "relkit graph print"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@relkit/app": "0.7.
|
|
18
|
+
"@relkit/app": "0.7.6",
|
|
19
19
|
"effect": "4.0.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "1.3.10",
|
|
23
|
-
"@relkit/cli": "0.7.
|
|
24
|
-
"@relkit/testing": "0.7.
|
|
23
|
+
"@relkit/cli": "0.7.6",
|
|
24
|
+
"@relkit/testing": "0.7.6",
|
|
25
25
|
"typescript": "5.9.3"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/** Maps the HTTP endpoint to its owning service's public member. */
|
|
1
2
|
import { defineRoute } from "@relkit/app/routes";
|
|
2
|
-
import echo from "@app/echo/service.js";
|
|
3
|
+
import echo from "@app/services/echo/service.js";
|
|
3
4
|
|
|
4
5
|
export const POST = defineRoute({
|
|
5
6
|
target: echo.echo,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/** Maps the HTTP endpoint to its owning service's public member. */
|
|
1
2
|
import { defineRoute } from "@relkit/app/routes";
|
|
2
|
-
import hello from "@app/hello/service.js";
|
|
3
|
+
import hello from "@app/services/hello/service.js";
|
|
3
4
|
|
|
4
5
|
export const GET = defineRoute({
|
|
5
6
|
target: hello.hello,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/** Maps the HTTP endpoint to its owning service's public member. */
|
|
1
2
|
import { defineServiceRoutes } from "@relkit/app/routes";
|
|
2
|
-
import orders from "@app/orders/service.js";
|
|
3
|
+
import orders from "@app/services/orders/service.js";
|
|
3
4
|
|
|
4
5
|
export const { POST } = defineServiceRoutes(orders, {
|
|
5
6
|
POST: { member: "createOrder", successStatus: 201 },
|
package/dist/templates/default/v1/api/src/{hello → services/hello}/functions/hello.function.ts
RENAMED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
/** Returns a validated named greeting and logs each invocation through RELKIT's request context. */
|
|
1
2
|
import { defineFunction } from "@relkit/app/functions";
|
|
2
3
|
import { z } from "@relkit/app/schema";
|
|
3
4
|
|
|
4
5
|
const hello = defineFunction({
|
|
5
6
|
input: z.object({ name: z.string().min(1).default("world") }),
|
|
6
7
|
output: z.object({ message: z.string() }),
|
|
8
|
+
/**
|
|
9
|
+
* Logs the greeting invocation and returns the validated greeting response.
|
|
10
|
+
* @param input - Validated name from the function schema.
|
|
11
|
+
* @param context - RELKIT invocation context owning structured logging.
|
|
12
|
+
* @returns Greeting response matching the output schema.
|
|
13
|
+
*/
|
|
7
14
|
handler: async ({ name }, context) => {
|
|
8
15
|
context.log.info("hello invoked", { name });
|
|
9
16
|
return { message: `Hello, ${name}!` };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/** Validates order input, invokes the service-local pricing function, and returns the calculated order. */
|
|
1
2
|
import { defineFunction } from "@relkit/app/functions";
|
|
2
3
|
import { z } from "@relkit/app/schema";
|
|
3
|
-
import priceOrder from "@app/orders/functions/price-order.function.js";
|
|
4
|
+
import priceOrder from "@app/services/orders/functions/price-order.function.js";
|
|
4
5
|
|
|
5
6
|
const orderInput = z.object({
|
|
6
7
|
orderId: z.string().min(1),
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Declares the orders service boundary and its public members. */
|
|
2
|
+
import { defineService } from "@relkit/app/services";
|
|
3
|
+
import createOrder from "@app/services/orders/functions/create-order.function.js";
|
|
4
|
+
import priceOrder from "@app/services/orders/functions/price-order.function.js";
|
|
5
|
+
|
|
6
|
+
export default defineService({
|
|
7
|
+
functions: { createOrder, priceOrder },
|
|
8
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/** Checks echo.function through the supported public RELKIT APIs. */
|
|
1
2
|
import { expect, test } from "bun:test";
|
|
2
3
|
import { invokeFunction } from "@relkit/testing";
|
|
3
|
-
import echo from "@app/echo/functions/echo.function.js";
|
|
4
|
+
import echo from "@app/services/echo/functions/echo.function.js";
|
|
4
5
|
|
|
5
6
|
test("echo returns its input", async () => {
|
|
6
7
|
await expect(invokeFunction(echo, { message: "hello" })).resolves.toEqual({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/** Checks hello.function through the supported public RELKIT APIs. */
|
|
1
2
|
import { expect, test } from "bun:test";
|
|
2
3
|
import { invokeFunction } from "@relkit/testing";
|
|
3
|
-
import hello from "@app/hello/functions/hello.function.js";
|
|
4
|
+
import hello from "@app/services/hello/functions/hello.function.js";
|
|
4
5
|
|
|
5
6
|
test("hello returns a greeting", async () => {
|
|
6
7
|
await expect(invokeFunction(hello, { name: "Mustafa" })).resolves.toEqual({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/** Checks orders.function through the supported public RELKIT APIs. */
|
|
1
2
|
import { expect, test } from "bun:test";
|
|
2
3
|
import { invokeFunction } from "@relkit/testing";
|
|
3
|
-
import orders from "@app/orders/service.js";
|
|
4
|
+
import orders from "@app/services/orders/service.js";
|
|
4
5
|
|
|
5
6
|
test("createOrder invokes pricing", async () => {
|
|
6
7
|
const result = await invokeFunction(orders.createOrder, {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: relkit
|
|
3
|
+
description: Build or extend a RELKIT CLI-generated application using its installed scaffolding and project commands. Use for application config, environments, services, functions, routes, auth, database, jobs, providers, and related app work.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Work in a RELKIT application
|
|
7
|
+
|
|
8
|
+
Run commands from the generated application's root, where `relkit.config.ts` and `package.json` live. Use `bun run relkit` to invoke the project's installed CLI. Check `bun run relkit <command> --help` before relying on an option, especially after a dependency upgrade.
|
|
9
|
+
|
|
10
|
+
## Source placement
|
|
11
|
+
|
|
12
|
+
New projects place every generic, database, and auth boundary at `src/services/<name>/service.ts`. Keep its functions, events, tasks, jobs, tools, agents, channels, schemas, resources, helpers, and assets under that service. Routes live at `src/routes`; configuration support and environment contracts live at `src/platform`. Application descriptors use plain TypeScript and supported public APIs; Effect imports are not required.
|
|
13
|
+
|
|
14
|
+
Existing flat projects with `src/<name>/service.ts` remain supported. `relkit add` preserves the detected layout; empty projects default to grouped. Never mix flat and grouped boundaries or add an aggregate `src/services/service.ts`. Across services and from routes, import only the destination's `service.ts`; Platform cannot import services or Routes. Ordinary helpers do not become independently discovered descriptors.
|
|
15
|
+
|
|
16
|
+
Read [layout migration](references/layout-migration.md) before moving an existing app. Keep logical IDs, exposure, provider profiles, and durable contract versions stable during a source-only move.
|
|
17
|
+
|
|
18
|
+
## Add application artifacts
|
|
19
|
+
|
|
20
|
+
Inspect the existing `src/` tree and `relkit.config.ts` before scaffolding. Prefer `relkit add` for supported artifacts, then edit the generated source for the required behavior. An interactive terminal can prompt for missing choices; scripts and noninteractive runs should provide the kind, name, service, route mode, and mappings explicitly.
|
|
21
|
+
|
|
22
|
+
Read [the CLI reference](references/cli.md) for commands and option patterns covering services, functions, routes, auth, database, and the other add kinds.
|
|
23
|
+
|
|
24
|
+
## Authoring API references
|
|
25
|
+
|
|
26
|
+
Read only the reference relevant to the requested change. These examples describe the template's public APIs; check the installed package's TypeScript declarations when an exact option or signature matters.
|
|
27
|
+
|
|
28
|
+
- [Application configuration and environments](references/config-environments.md)
|
|
29
|
+
- [Functions, services, events, and errors](references/domain-apis.md)
|
|
30
|
+
- [HTTP routes and request policy](references/http-apis.md)
|
|
31
|
+
- [Streaming responses](references/streaming-apis.md)
|
|
32
|
+
- [Tasks and jobs](references/jobs-apis.md)
|
|
33
|
+
- [Agents, tools, and prompts](references/agent-apis.md)
|
|
34
|
+
- [Database, auth, cache, and storage](references/data-apis.md)
|
|
35
|
+
- [Realtime channels](references/realtime-apis.md)
|
|
36
|
+
- [Observability and tracing](references/observability-apis.md)
|
|
37
|
+
- [Testing functions, routes, and providers](references/testing-apis.md)
|
|
38
|
+
|
|
39
|
+
## Working conventions
|
|
40
|
+
|
|
41
|
+
- Generic domain services own callable functions and public event contracts. Other domains and routes should import a service's public members through its `service.ts`.
|
|
42
|
+
- A service route maps HTTP methods to existing public callable members. A raw route is a standalone handler. The CLI will not overwrite an existing route file.
|
|
43
|
+
- Database and auth are singletons under `src/services/database` and `src/services/auth`; extend an existing one instead of creating another. Auth may create a database baseline if none exists. Scaffolding does not run migrations, create secrets, or provision cloud resources.
|
|
44
|
+
- Preserve existing application configuration, environment fields, service members, routes, and user changes when specializing generated files.
|
|
45
|
+
|
|
46
|
+
## Verify the result
|
|
47
|
+
|
|
48
|
+
Review the CLI's created and updated files, warnings, and next steps. Run `bun run check`, `bun run typecheck`, and focused tests after editing. For HTTP work, exercise the route itself; a direct function test does not cover request mapping. Database and auth work also needs the reported environment and migration steps before runtime verification.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Agents, tools, and prompts
|
|
2
|
+
|
|
3
|
+
| API | Import | Role |
|
|
4
|
+
| ----------------------------------------------- | -------------------- | ------------------------------------ |
|
|
5
|
+
| `defineAgent`, `defineGraph`, `defineGraphNode` | `@relkit/app/agents` | Model-driven agent or explicit graph |
|
|
6
|
+
| `defineTool` | `@relkit/app/tools` | Policy-controlled view of a function |
|
|
7
|
+
| `definePrompt` | `@relkit/app` | Reusable instructions |
|
|
8
|
+
| `z` | `@relkit/app/schema` | Agent and tool schemas |
|
|
9
|
+
|
|
10
|
+
## `defineAgent`
|
|
11
|
+
|
|
12
|
+
Use `defineAgent` when a model should choose among tools. The agent template provides an executable offline LangChain model example. This shortened form uses the same public options:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { defineAgent } from "@relkit/app/agents";
|
|
16
|
+
import { z } from "@relkit/app/schema";
|
|
17
|
+
import { FakeToolCallingModel } from "langchain";
|
|
18
|
+
import lookup from "@app/services/hello/tools/lookup.tool.js";
|
|
19
|
+
export default defineAgent({
|
|
20
|
+
id: "hello.assistant",
|
|
21
|
+
input: z.object({ message: z.string().min(1) }),
|
|
22
|
+
output: z.object({ answer: z.string() }),
|
|
23
|
+
model: new FakeToolCallingModel({
|
|
24
|
+
toolCalls: [[{ name: "relkit_output", args: { value: { answer: "Hello!" } }, id: "output-1" }]],
|
|
25
|
+
}),
|
|
26
|
+
instructions: "Answer greeting questions with the available tools.",
|
|
27
|
+
tools: [lookup],
|
|
28
|
+
limits: { maxSteps: 4, maxToolCalls: 4, timeoutMs: 10_000 },
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Other generated projects may need a native model package and application-owned provider configuration. `limits` requires positive `maxSteps`, `maxToolCalls`, and `timeoutMs`. `instructions` can be text or a `definePrompt` descriptor. A model can call only tools listed in the agent's `tools` array. A fixed sequence can be a function; a stateful explicit workflow can use `defineGraph` and `defineGraphNode`.
|
|
33
|
+
|
|
34
|
+
## `defineTool` and `definePrompt`
|
|
35
|
+
|
|
36
|
+
A RELKIT tool wraps a callable function without duplicating its schemas:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { defineTool } from "@relkit/app/tools";
|
|
40
|
+
import lookup from "@app/services/orders/functions/lookup.function.js";
|
|
41
|
+
export default defineTool({
|
|
42
|
+
id: "orders.lookup",
|
|
43
|
+
target: lookup,
|
|
44
|
+
description: "Look up an order by ID",
|
|
45
|
+
sideEffect: "read",
|
|
46
|
+
approval: "never",
|
|
47
|
+
timeoutMs: 2_000,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { definePrompt } from "@relkit/app";
|
|
53
|
+
export default definePrompt("Answer using the available tools.", {
|
|
54
|
+
id: "hello.assistant-instructions",
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`lookup.asTool({ ... })` is the alternate tool form. Choose accurate `sideEffect` (`none`, `read`, `write`, or `external`) and `approval` (`never`, `on-write`, or `always`) policies. Tools are available to MCP by default; set `mcp: false` when a tool should remain inside the app. Permission checks belong in application logic.
|
|
59
|
+
If a browser client needs an agent, configure its explicit `client` contract. Keep provider credentials and native model instances on the server. A typed agent run uses a stable thread ID; resume the same thread instead of creating a replacement run.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# CLI commands in a generated project
|
|
2
|
+
|
|
3
|
+
These examples use the local binary through `bun run relkit`. The installed CLI's `--help` is authoritative if its version differs from the template.
|
|
4
|
+
|
|
5
|
+
## Service and HTTP scaffolding
|
|
6
|
+
|
|
7
|
+
| Goal | Command |
|
|
8
|
+
| ---------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
9
|
+
| Create a domain with a public example function | `bun run relkit add service Billing` |
|
|
10
|
+
| Select extra domain artifacts | `bun run relkit add service Billing --include function --include error` |
|
|
11
|
+
| Create the full domain bundle | `bun run relkit add service Billing --full` |
|
|
12
|
+
| Add a public callable function | `bun run relkit add function "Send Receipt" --service billing` |
|
|
13
|
+
| Add a standalone GET handler | `bun run relkit add route '/status' --mode route` |
|
|
14
|
+
| Map an existing public member to HTTP | `bun run relkit add route '/billing' --mode service-route --service billing --map GET=example` |
|
|
15
|
+
|
|
16
|
+
`--include` is repeatable and exclusive with `--full`. `--service` selects an existing generic domain; `--create-service` creates it while adding an artifact. Use `--internal` on a function or event that should stay out of the public service API. A service route needs one or more `--map METHOD=member` values in noninteractive use; the member must be a public callable function. Quote paths containing `*` or `?`.
|
|
17
|
+
|
|
18
|
+
## Database and auth
|
|
19
|
+
|
|
20
|
+
| Goal | Command |
|
|
21
|
+
| -------------------------------------------- | ------------------------------------------------------------------------- |
|
|
22
|
+
| Scaffold a SQLite Drizzle service | `bun run relkit add database --orm drizzle --dialect sqlite` |
|
|
23
|
+
| Scaffold Better Auth and its catch-all route | `bun run relkit add auth --adapter better-auth --database-dialect sqlite` |
|
|
24
|
+
|
|
25
|
+
Database `--dialect` and auth `--database-dialect` also accept `postgresql` and `mysql`. Auth's `--base-path` changes the default `/api/auth` mount. The CLI adds dependencies and an environment example as needed, but it does not apply database migrations or populate secrets. Follow the scaffold's reported next steps after reviewing the schema and environment values.
|
|
26
|
+
|
|
27
|
+
## Other add kinds
|
|
28
|
+
|
|
29
|
+
Run `bun run relkit add <kind> --help` for each kind's flags and requirements:
|
|
30
|
+
|
|
31
|
+
| Area | Kinds |
|
|
32
|
+
| --------------- | ---------------------------------------- |
|
|
33
|
+
| Domain behavior | `function`, `task`, `error`, `constants` |
|
|
34
|
+
| Events and work | `event`, `event-function`, `job` |
|
|
35
|
+
| Providers | `cache`, `bucket` |
|
|
36
|
+
| AI | `tool`, `prompt`, `agent` |
|
|
37
|
+
| HTTP | `middleware`, `transform`, `route` |
|
|
38
|
+
|
|
39
|
+
For example, jobs need a target task, tools need an existing or newly created function, and agents need a prompt or inline instructions. Check the existing service and profile before selecting one. `--no-install` skips installing newly required packages and may skip verification; `--project-root <directory>` targets another app. `bun run relkit --json add ...` disables prompts and emits structured results for automation.
|
|
40
|
+
|
|
41
|
+
There is no `relkit add channel` or `relkit add observability` kind. Author channels with `defineChannel` and configure observability in `defineApp({ telemetry })`; see the [realtime](realtime-apis.md) and [observability](observability-apis.md) references.
|
|
42
|
+
|
|
43
|
+
For streaming responses, scaffold a function and route, then edit the function's output to `streamOf(itemSchema)` and the route's `stream` option; see the [streaming reference](streaming-apis.md).
|
|
44
|
+
|
|
45
|
+
## Inspect and run the app
|
|
46
|
+
|
|
47
|
+
| Goal | Command |
|
|
48
|
+
| --------------------------------------- | ----------------------------------- |
|
|
49
|
+
| Validate the application graph | `bun run check` |
|
|
50
|
+
| Typecheck and test | `bun run typecheck`, `bun run test` |
|
|
51
|
+
| Start app, inspector, and API reference | `bun run dev` |
|
|
52
|
+
| Inspect the graph | `bun run relkit graph print` |
|
|
53
|
+
| Inspect environment value status | `bun run relkit env list` |
|
|
54
|
+
| Validate active environment values | `bun run relkit env check` |
|
|
55
|
+
| Explain one environment declaration | `bun run relkit env explain NAME` |
|
|
56
|
+
| Render a safe environment example | `bun run relkit env example` |
|
|
57
|
+
| Check local prerequisites | `bun run relkit doctor` |
|
|
58
|
+
| Inspect local service status | `bun run relkit local status` |
|
|
59
|
+
| Build or start a built app | `bun run build`, `bun run start` |
|
|
60
|
+
|
|
61
|
+
Use `bun run relkit --help` to discover additional `graph`, `env`, `local`, `jobs`, `client`, and deployment commands. Start Docker-backed local services with `bun run relkit local up --detach` only when the app actually declares and needs them. Deployment commands require a configured deployment target.
|
|
62
|
+
|
|
63
|
+
For optional flat-to-grouped migration, use `bun run relkit migrate layout` for preview, `--write` for validated publication, and `--rollback <receipt>` for guarded restoration. See [layout migration](layout-migration.md). After `--no-install`, install dependencies and run `bun run relkit dev --prepare` before evaluating prepared-start readiness.
|
package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/config-environments.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Application configuration and environments
|
|
2
|
+
|
|
3
|
+
A generated application has two authoring files at its root: `relkit.config.ts` declares topology and runtime policy with `defineApp`, and `src/platform/env.ts` declares application environment values with `defineEnv`. Extend these existing files rather than creating a second application or environment contract.
|
|
4
|
+
|
|
5
|
+
## `defineEnv`: values for handlers
|
|
6
|
+
|
|
7
|
+
In `src/platform/env.ts`:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineEnv, env } from "@relkit/app/config";
|
|
11
|
+
|
|
12
|
+
export default defineEnv({
|
|
13
|
+
LOG_LEVEL: env.literal("debug", "info", "warn", "error").default("info"),
|
|
14
|
+
DATABASE_PATH: env.string().default(".relkit/app.sqlite"),
|
|
15
|
+
BETTER_AUTH_SECRET: env.secret().requiredIn("production"),
|
|
16
|
+
PUBLIC_ORIGIN: env.url().optional(),
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Builders include `string`, `secret`, `number`, `boolean`, `port`, `url`, `json`, and `literal(...)`. Use `.default(value)` only for intentional safe defaults, `.optional()` for absent values, `.requiredIn("production")` for environment-specific requirements, and `.description(text)` or `.example(value)` for safe metadata. A URL field resolves to a `URL`, a number field to a number, and a Boolean field to a boolean. Do not declare `PORT` or `RELKIT_ENV`; RELKIT reserves them.
|
|
21
|
+
|
|
22
|
+
Pass the definition into `defineApp({ env })`. Functions read the resolved, typed values through `context.env`:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { defineFunction } from "@relkit/app/functions";
|
|
26
|
+
import { z } from "@relkit/app/schema";
|
|
27
|
+
|
|
28
|
+
export default defineFunction({
|
|
29
|
+
input: z.object({}),
|
|
30
|
+
output: z.object({ level: z.string() }),
|
|
31
|
+
handler: async (_input, context) => ({ level: context.env.LOG_LEVEL }),
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Mark credentials with `env.secret()`; keep actual values outside source control. Secret metadata enables redaction in generated output, diagnostics, telemetry, and Inspector data. Avoid placeholder production secrets or logging resolved secrets.
|
|
36
|
+
|
|
37
|
+
## `defineApp`: topology and policy
|
|
38
|
+
|
|
39
|
+
In `relkit.config.ts`, the baseline application contains the environment contract, telemetry redaction, backend settings, and Inspector settings:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { defineApp } from "@relkit/app/config";
|
|
43
|
+
import env from "@app/platform/env.js";
|
|
44
|
+
|
|
45
|
+
export default defineApp({
|
|
46
|
+
env,
|
|
47
|
+
telemetry: { redaction: { mode: "development-redacted", maxBytes: 65_536 } },
|
|
48
|
+
server: { port: 3000, maxBodyBytes: 1_048_576 },
|
|
49
|
+
inspector: { port: 3210 },
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`defineApp` also accepts `id`, `defaults`, `deployment`, and provider capabilities `bucket`, `cache`, `jobs`, `event`, `model`, `realtime`, and `"agent-state"`. A capability can have one `default` profile or a named profile map. `defaults.<capability>` must name a configured profile. The `jobs` key is the public spelling for the job provider. Add only providers the app uses; the base template has none. Public creation currently certifies only the minimal starter with examples, no jobs, no cloud, and no deployment. API, agent, fullstack, jobs, and AWS/Pulumi creation tuples are internal candidates and must remain rejected until their exact release evidence is certified. Configure an existing app's optional integrations only when the installed version supports them and the task requires them.
|
|
54
|
+
|
|
55
|
+
For a one-machine realtime provider and a named Docker-backed cache profile, the complete configuration shape is:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { defineApp, env as binding } from "@relkit/app/config";
|
|
59
|
+
import { docker } from "@relkit/docker";
|
|
60
|
+
import { localRealtime } from "@relkit/local";
|
|
61
|
+
import { redis } from "@relkit/redis";
|
|
62
|
+
import env from "@app/platform/env.js";
|
|
63
|
+
|
|
64
|
+
export default defineApp({
|
|
65
|
+
env,
|
|
66
|
+
cache: {
|
|
67
|
+
requests: docker(redis({ url: binding.secret("REQUESTS_REDIS_URL") })),
|
|
68
|
+
},
|
|
69
|
+
realtime: localRealtime(),
|
|
70
|
+
defaults: { cache: "requests", realtime: "default" },
|
|
71
|
+
telemetry: { redaction: { mode: "development-redacted", maxBytes: 65_536 } },
|
|
72
|
+
server: { port: 3000, maxBodyBytes: 1_048_576 },
|
|
73
|
+
inspector: { port: 3210 },
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Merge only the needed capabilities into the existing `defineApp`, preserving its other settings. Install the optional integration packages before importing them. `binding.secret("REQUESTS_REDIS_URL")` is a value-free provider binding; it is not a `context.env` field unless `defineEnv` declares that name too. Stable topology belongs in source; machine, stack, and secret values belong in environment bindings.
|
|
78
|
+
|
|
79
|
+
Platform fragments may explicitly export server, Inspector, telemetry, deployment, or provider settings and be imported by `relkit.config.ts`. Unimported files are not autoloaded. Keep provider acquisition in supported lazy factories and compose one `defineApp`.
|
|
80
|
+
|
|
81
|
+
CLI `--environment` selects provider configuration; `RELKIT_ENV` selects the application environment. `.env` and `.env.local` supply runtime values according to existing CLI loading; `.env.example` is informational and is not loaded as credentials.
|
|
82
|
+
|
|
83
|
+
## Inspect and verify environment values
|
|
84
|
+
|
|
85
|
+
From the generated project root:
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
bun run relkit env check
|
|
89
|
+
bun run relkit env list
|
|
90
|
+
bun run relkit env explain BETTER_AUTH_SECRET
|
|
91
|
+
bun run relkit env example
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`check` validates active values, `list` shows presence/status without printing secrets, `explain` describes one declaration, and `example` renders a safe template. `env example --write --path .env.example` writes it when requested. Use `--environment <name>` with environment-aware CLI commands to select provider configuration; it does not define an application env field. Run `bun run check` and `bun run typecheck` after changing the contract, then exercise the affected runtime path. Run `bun run relkit local status` before using Docker-backed providers.
|
|
95
|
+
|
|
96
|
+
For observability settings, see [Observability and tracing](observability-apis.md); for realtime provider behavior, see [Realtime channels](realtime-apis.md).
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Database, authentication, cache, and storage
|
|
2
|
+
|
|
3
|
+
For the full `defineApp`, `defineEnv`, provider profile, and environment binding workflow, read [Application configuration and environments](config-environments.md).
|
|
4
|
+
|
|
5
|
+
The database and auth integrations are specialized services, separate from `defineService` domain maps. `relkit add database` creates the Drizzle baseline in `src/services/database`; `relkit add auth` creates `src/services/auth` and its recognized `ALL` handler route. There should be one of each. Extend an existing one while preserving schema exports, environment fields, and routes.
|
|
6
|
+
|
|
7
|
+
## `defineEnv` and `defineDrizzleService`
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineEnv, env as envFactory } from "@relkit/app/config";
|
|
11
|
+
|
|
12
|
+
export default defineEnv({
|
|
13
|
+
DATABASE_PATH: envFactory.string().default(".relkit/app.sqlite"),
|
|
14
|
+
BETTER_AUTH_SECRET: envFactory.secret(),
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { Database } from "bun:sqlite";
|
|
20
|
+
import { defineDrizzleService } from "@relkit/drizzle";
|
|
21
|
+
import { drizzle } from "drizzle-orm/bun-sqlite";
|
|
22
|
+
import * as schema from "./schema/index.js";
|
|
23
|
+
|
|
24
|
+
export default defineDrizzleService({
|
|
25
|
+
schema,
|
|
26
|
+
client: ({ env }) => drizzle({ client: new Database(env.DATABASE_PATH, { create: true }) }),
|
|
27
|
+
dispose: (database) => database.$client.close(),
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Open the native connection in the `client({ env })` factory and close it with `dispose` when needed. Discovery does not run the factory. Generate and review migrations with the installed Drizzle tooling; service creation does not create tables or apply migrations. After `bun run check`, generated context declarations provide typed `context.database`.
|
|
32
|
+
|
|
33
|
+
## `defineBetterAuthService`
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { defineBetterAuthService } from "@relkit/better-auth";
|
|
37
|
+
|
|
38
|
+
export default defineBetterAuthService({
|
|
39
|
+
baseURL: process.env.BETTER_AUTH_URL ?? "http://127.0.0.1:3000",
|
|
40
|
+
emailAndPassword: { enabled: true },
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Better Auth uses the same Drizzle connection and needs its tables in that schema. Mount `auth.handler` directly with `export const ALL = defineRoute({ handler: auth.handler })` under the auth base path. Supply a stable server-side `BETTER_AUTH_SECRET` and correct public `BETTER_AUTH_URL`; the scaffold only adds environment examples. Protect application routes and enforce ownership separately from signing in.
|
|
45
|
+
|
|
46
|
+
## `defineCache` and `defineBucket`
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { defineCache } from "@relkit/app/cache";
|
|
50
|
+
import { z } from "@relkit/app/schema";
|
|
51
|
+
|
|
52
|
+
export default defineCache({
|
|
53
|
+
id: "orders.prices",
|
|
54
|
+
profile: "requests",
|
|
55
|
+
key: z.object({ sku: z.string() }),
|
|
56
|
+
value: z.number().int().nonnegative(),
|
|
57
|
+
defaultTtlMs: 60_000,
|
|
58
|
+
maxTtlMs: 300_000,
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { defineBucket } from "@relkit/app/buckets";
|
|
64
|
+
|
|
65
|
+
export default defineBucket({
|
|
66
|
+
id: "assets.objects",
|
|
67
|
+
profile: "assets",
|
|
68
|
+
visibility: "private",
|
|
69
|
+
maxObjectBytes: 5_000_000,
|
|
70
|
+
allowedContentTypes: ["application/json", "image/*"],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Configure compatible profiles in `relkit.config.ts` and declare each resource in a function's `dependencies` before using its checked context client. A profile selects a provider; the descriptor does not create Redis, S3, or credentials. Use `bun run relkit local status` to inspect Docker-backed resources.
|