@pulse-compute/cli 0.0.0 → 1.0.0-beta.2
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/API.md +572 -0
- package/CHANGELOG.md +71 -0
- package/README.md +71 -1
- package/bin/pulse.js +15 -0
- package/bin/pulsewasm-extract.js +22 -0
- package/cli-spec.json +575 -0
- package/completions/_pulse +106 -0
- package/completions/pulse.bash +31 -0
- package/completions/pulse.fish +76 -0
- package/docs/README.md +77 -0
- package/docs/architecture/current-contracts.md +470 -0
- package/docs/architecture/overview.md +93 -0
- package/docs/architecture/vision.md +515 -0
- package/docs/concepts/bodies.md +186 -0
- package/docs/concepts/compilation-and-lowering.md +496 -0
- package/docs/concepts/contracts-and-providers.md +158 -0
- package/docs/concepts/effects-and-continuations.md +300 -0
- package/docs/concepts/entities-and-adapters.md +71 -0
- package/docs/concepts/package-owned-lowering.md +175 -0
- package/docs/concepts/targets-and-hosts.md +70 -0
- package/docs/contributing/README.md +38 -0
- package/docs/contributing/adding-core-provider.md +315 -0
- package/docs/contributing/adding-first-party-lowerer.md +327 -0
- package/docs/contributing/entities-lowering.md +91 -0
- package/docs/contributing/package-lowerer-contract.md +383 -0
- package/docs/contributing/pulse-aware-packages.md +149 -0
- package/docs/examples.md +112 -0
- package/docs/fixtures/inspect-fetch-composition.selected.json +181 -0
- package/docs/getting-started.md +128 -0
- package/docs/guides/compatibility-imports.md +60 -0
- package/docs/guides/deploying-fastly.md +188 -0
- package/docs/guides/deploying-node.md +143 -0
- package/docs/guides/events.md +233 -0
- package/docs/guides/fastly-capabilities.md +153 -0
- package/docs/guides/fetching-and-composition.md +101 -0
- package/docs/guides/grip.md +94 -0
- package/docs/guides/json-schemas.md +233 -0
- package/docs/guides/migrating-from-express.md +192 -0
- package/docs/guides/project-lifecycle.md +143 -0
- package/docs/guides/routing.md +202 -0
- package/docs/guides/troubleshooting.md +47 -0
- package/docs/maintainers/README.md +60 -0
- package/docs/maintainers/codex-maintainer.md +71 -0
- package/docs/maintainers/documentation-deployment.md +147 -0
- package/docs/maintainers/documentation-system.md +58 -0
- package/docs/maintainers/documentation-versioning.md +65 -0
- package/docs/maintainers/maintainer-charter.md +100 -0
- package/docs/maintainers/maintenance-policy.json +809 -0
- package/docs/maintainers/maintenance-policy.md +124 -0
- package/docs/maintainers/npm-publishing.md +154 -0
- package/docs/maintainers/plugin-readiness.json +19 -0
- package/docs/maintainers/plugin-readiness.md +31 -0
- package/docs/maintainers/public-site.md +158 -0
- package/docs/maintainers/release-acceptance.md +293 -0
- package/docs/maintainers/release-manifest.md +89 -0
- package/docs/maintainers/repository-setup.md +145 -0
- package/docs/maintainers/scope-policy.md +105 -0
- package/docs/maintainers/support-and-triage.md +74 -0
- package/docs/maintainers/testing.md +334 -0
- package/docs/packages/README.md +60 -0
- package/docs/packages/assets.md +85 -0
- package/docs/packages/cli.md +190 -0
- package/docs/packages/crypto.md +78 -0
- package/docs/packages/entities.md +129 -0
- package/docs/packages/grip.md +82 -0
- package/docs/packages/implementation-packages.md +122 -0
- package/docs/packages/jwt.md +55 -0
- package/docs/packages/provider-fastly.md +243 -0
- package/docs/packages/pulse.md +159 -0
- package/docs/packages/runtime.md +265 -0
- package/docs/packages/s3.md +101 -0
- package/docs/preview-scope.md +142 -0
- package/docs/reference/README.md +33 -0
- package/docs/reference/cli-spec.json +575 -0
- package/docs/reference/cli.md +457 -0
- package/docs/reference/compatibility-matrix.md +169 -0
- package/docs/reference/diagnostics.md +1872 -0
- package/docs/reference/documentation-versions.json +22 -0
- package/docs/reference/environment.md +347 -0
- package/docs/reference/handler-authoring.md +264 -0
- package/docs/reference/project-config.md +582 -0
- package/docs/reference/project-config.schema.json +981 -0
- package/docs/reference/release-manifest.json +441 -0
- package/docs/reference/shell-completion.md +23 -0
- package/documentation-site.json +668 -0
- package/documentation-versions.json +22 -0
- package/examples/01-hello-json/.pulse/.gitignore +3 -0
- package/examples/01-hello-json/.pulse/config.ts +16 -0
- package/examples/01-hello-json/README.md +119 -0
- package/examples/01-hello-json/package.json +20 -0
- package/examples/01-hello-json/src/index.ts +9 -0
- package/examples/01-hello-json/tests/pulse.harness.ts +22 -0
- package/examples/01-hello-json/tsconfig.json +14 -0
- package/examples/02-request-schema/.pulse/.gitignore +3 -0
- package/examples/02-request-schema/.pulse/config.ts +17 -0
- package/examples/02-request-schema/README.md +145 -0
- package/examples/02-request-schema/package.json +20 -0
- package/examples/02-request-schema/src/index.ts +18 -0
- package/examples/02-request-schema/src/schemas.ts +20 -0
- package/examples/02-request-schema/tests/pulse.harness.ts +37 -0
- package/examples/02-request-schema/tsconfig.json +14 -0
- package/examples/03-fetch-composition/.pulse/.gitignore +3 -0
- package/examples/03-fetch-composition/.pulse/config.ts +31 -0
- package/examples/03-fetch-composition/README.md +210 -0
- package/examples/03-fetch-composition/package.json +20 -0
- package/examples/03-fetch-composition/src/index.ts +60 -0
- package/examples/03-fetch-composition/tests/pulse.harness.ts +47 -0
- package/examples/03-fetch-composition/tsconfig.json +14 -0
- package/examples/05-fastly-capabilities/.pulse/.gitignore +3 -0
- package/examples/05-fastly-capabilities/.pulse/config.ts +57 -0
- package/examples/05-fastly-capabilities/README.md +257 -0
- package/examples/05-fastly-capabilities/package.json +22 -0
- package/examples/05-fastly-capabilities/src/index.ts +55 -0
- package/examples/05-fastly-capabilities/tests/pulse.harness.ts +66 -0
- package/examples/05-fastly-capabilities/tsconfig.json +14 -0
- package/examples/07-opaque-proxy/.pulse/.gitignore +3 -0
- package/examples/07-opaque-proxy/.pulse/config.ts +38 -0
- package/examples/07-opaque-proxy/README.md +150 -0
- package/examples/07-opaque-proxy/package.json +21 -0
- package/examples/07-opaque-proxy/src/index.ts +9 -0
- package/examples/07-opaque-proxy/tests/pulse.harness.ts +25 -0
- package/examples/07-opaque-proxy/tsconfig.json +14 -0
- package/examples/09-router-lowering/.pulse/.gitignore +3 -0
- package/examples/09-router-lowering/.pulse/config.ts +22 -0
- package/examples/09-router-lowering/README.md +287 -0
- package/examples/09-router-lowering/package.json +22 -0
- package/examples/09-router-lowering/src/index.ts +65 -0
- package/examples/09-router-lowering/tests/pulse.harness.ts +91 -0
- package/examples/09-router-lowering/tsconfig.json +14 -0
- package/examples/10-entities-tools/.pulse/.gitignore +4 -0
- package/examples/10-entities-tools/.pulse/config.ts +23 -0
- package/examples/10-entities-tools/README.md +165 -0
- package/examples/10-entities-tools/package.json +21 -0
- package/examples/10-entities-tools/src/handlers.ts +15 -0
- package/examples/10-entities-tools/src/index.ts +31 -0
- package/examples/10-entities-tools/src/schemas.ts +18 -0
- package/examples/10-entities-tools/tests/pulse.harness.ts +40 -0
- package/examples/10-entities-tools/tools-facade.cjs +158 -0
- package/examples/10-entities-tools/tsconfig.json +14 -0
- package/examples/11-events/.pulse/.gitignore +4 -0
- package/examples/11-events/.pulse/config.ts +24 -0
- package/examples/11-events/README.md +194 -0
- package/examples/11-events/package.json +20 -0
- package/examples/11-events/src/index.ts +27 -0
- package/examples/11-events/src/schemas.ts +19 -0
- package/examples/11-events/tests/pulse.harness.ts +34 -0
- package/examples/11-events/tsconfig.json +15 -0
- package/examples/12-mcp-proxy/.pulse/.gitignore +3 -0
- package/examples/12-mcp-proxy/.pulse/config.ts +25 -0
- package/examples/12-mcp-proxy/README.md +149 -0
- package/examples/12-mcp-proxy/package.json +20 -0
- package/examples/12-mcp-proxy/src/index.ts +17 -0
- package/examples/12-mcp-proxy/tests/pulse.harness.ts +29 -0
- package/examples/12-mcp-proxy/tsconfig.json +14 -0
- package/examples/13-jwt-es256/.pulse/config.ts +19 -0
- package/examples/13-jwt-es256/README.md +195 -0
- package/examples/13-jwt-es256/package.json +21 -0
- package/examples/13-jwt-es256/src/index.ts +21 -0
- package/examples/13-jwt-es256/tests/pulse.harness.ts +54 -0
- package/examples/13-jwt-es256/tsconfig.json +14 -0
- package/examples/README.md +36 -0
- package/package.json +66 -6
- package/project-config.schema.json +981 -0
- package/release-manifest.json +441 -0
- package/src/command-spec.js +279 -0
- package/src/completion.js +113 -0
- package/src/diagnostics.js +350 -0
- package/src/documentation.js +45 -0
- package/src/index.d.ts +133 -0
- package/src/index.js +15 -0
- package/src/internal/command-executor.d.ts +29 -0
- package/src/internal/command-executor.js +143 -0
- package/src/internal/command-plan.d.ts +9 -0
- package/src/internal/command-plan.js +73 -0
- package/src/internal/command-reporter.d.ts +15 -0
- package/src/internal/command-reporter.js +133 -0
- package/src/internal/command-request.d.ts +35 -0
- package/src/internal/command-request.js +154 -0
- package/src/internal/node-http.js +54 -0
- package/src/internal/project-context.d.ts +66 -0
- package/src/internal/project-context.js +175 -0
- package/src/project-config-reference.js +4 -0
- package/src/project-config-schema.d.ts +23 -0
- package/src/project-config-schema.js +271 -0
- package/src/project-config.js +724 -0
- package/src/project-execution.js +2946 -0
- package/src/provider-drivers.js +3 -0
- package/src/target-support.js +3 -0
- package/src/typescript-module-loader.js +269 -0
- package/src/workflow.js +78 -0
- package/src/workspace.js +82 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from '@pulse-compute/pulse'
|
|
2
|
+
|
|
3
|
+
export default defineConfig((_scope) => ({
|
|
4
|
+
pulse: {
|
|
5
|
+
entry: 'src/index.ts',
|
|
6
|
+
tests: 'tests/pulse.harness.ts',
|
|
7
|
+
defaultProfile: 'local',
|
|
8
|
+
strict: true,
|
|
9
|
+
},
|
|
10
|
+
local: {
|
|
11
|
+
host: 'node',
|
|
12
|
+
target: 'native',
|
|
13
|
+
outDir: 'dist',
|
|
14
|
+
dev: { host: '127.0.0.1', port: 8787 },
|
|
15
|
+
},
|
|
16
|
+
}))
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Hello JSON
|
|
2
|
+
|
|
3
|
+
The smallest canonical Pulse project: branch on the request path and return JSON or text.
|
|
4
|
+
|
|
5
|
+
## Workflow
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pulse doctor
|
|
9
|
+
pulse inspect
|
|
10
|
+
pulse test
|
|
11
|
+
pulse dev
|
|
12
|
+
pulse build
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The documented test result below is executed by the documentation gate.
|
|
16
|
+
|
|
17
|
+
<!-- pulse-doc-run {"project":"examples/01-hello-json","args":["test","--json"]} -->
|
|
18
|
+
```bash
|
|
19
|
+
pulse test --json
|
|
20
|
+
```
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"status": "passed",
|
|
24
|
+
"provider": "node",
|
|
25
|
+
"summary": {
|
|
26
|
+
"total": 3,
|
|
27
|
+
"passed": 3,
|
|
28
|
+
"failed": 0
|
|
29
|
+
},
|
|
30
|
+
"cases": [
|
|
31
|
+
{
|
|
32
|
+
"name": "health",
|
|
33
|
+
"status": "passed",
|
|
34
|
+
"response": {
|
|
35
|
+
"status": 200
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Wasm size
|
|
43
|
+
|
|
44
|
+
| Artifact | Default build | `--experimental-native-size` | Reduction |
|
|
45
|
+
|---|---:|---:|---:|
|
|
46
|
+
| `canonical-native.wasm` | 2.2 KiB (2,212 bytes) | 2.0 KiB (2,058 bytes) | 7.0% |
|
|
47
|
+
|
|
48
|
+
The executable documentation gate rebuilds and measures both variants on
|
|
49
|
+
`1.0.0-beta.2`. These are uncompressed on-disk sizes, not transfer sizes or
|
|
50
|
+
platform limits.
|
|
51
|
+
|
|
52
|
+
## Handler
|
|
53
|
+
|
|
54
|
+
<!-- pulse-doc-source: examples/01-hello-json/src/index.ts -->
|
|
55
|
+
```ts
|
|
56
|
+
import { Pulse } from '@pulse-compute/pulse'
|
|
57
|
+
|
|
58
|
+
const app = new Pulse({ auto: true })
|
|
59
|
+
|
|
60
|
+
app.get('/health', async (ctx) => ctx.json({ ok: true }))
|
|
61
|
+
app.get('/hello', async (ctx) => ctx.json({ message: 'hello from Pulse' }))
|
|
62
|
+
app.get('/*', async (ctx) => ctx.text('not found', { status: 404 }))
|
|
63
|
+
|
|
64
|
+
export default app
|
|
65
|
+
```
|
|
66
|
+
<!-- /pulse-doc-source -->
|
|
67
|
+
|
|
68
|
+
## Project config
|
|
69
|
+
|
|
70
|
+
<!-- pulse-doc-source: examples/01-hello-json/.pulse/config.ts -->
|
|
71
|
+
```ts
|
|
72
|
+
import { defineConfig } from '@pulse-compute/pulse'
|
|
73
|
+
|
|
74
|
+
export default defineConfig((_scope) => ({
|
|
75
|
+
pulse: {
|
|
76
|
+
entry: 'src/index.ts',
|
|
77
|
+
tests: 'tests/pulse.harness.ts',
|
|
78
|
+
defaultProfile: 'local',
|
|
79
|
+
strict: true,
|
|
80
|
+
},
|
|
81
|
+
local: {
|
|
82
|
+
host: 'node',
|
|
83
|
+
target: 'native',
|
|
84
|
+
outDir: 'dist',
|
|
85
|
+
dev: { host: '127.0.0.1', port: 8787 },
|
|
86
|
+
},
|
|
87
|
+
}))
|
|
88
|
+
```
|
|
89
|
+
<!-- /pulse-doc-source -->
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## Test harness
|
|
93
|
+
|
|
94
|
+
<!-- pulse-doc-source: examples/01-hello-json/tests/pulse.harness.ts -->
|
|
95
|
+
```ts
|
|
96
|
+
export default {
|
|
97
|
+
cases: [
|
|
98
|
+
{
|
|
99
|
+
name: 'health',
|
|
100
|
+
request: { path: '/health' },
|
|
101
|
+
expect: { status: 200, json: { ok: true } },
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'hello',
|
|
105
|
+
request: { path: '/hello' },
|
|
106
|
+
expect: {
|
|
107
|
+
status: 200,
|
|
108
|
+
json: { message: 'hello from Pulse' },
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'missing',
|
|
113
|
+
request: { path: '/missing' },
|
|
114
|
+
expect: { status: 404, text: 'not found' },
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
<!-- /pulse-doc-source -->
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pulse-examples/01-hello-json",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"doctor": "pulse doctor",
|
|
8
|
+
"inspect": "pulse inspect",
|
|
9
|
+
"test": "pulse test",
|
|
10
|
+
"dev": "pulse dev",
|
|
11
|
+
"build": "pulse build"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@pulse-compute/pulse": "1.0.0-beta.2"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@pulse-compute/cli": "1.0.0-beta.2",
|
|
18
|
+
"typescript": "5.9.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Pulse } from '@pulse-compute/pulse'
|
|
2
|
+
|
|
3
|
+
const app = new Pulse({ auto: true })
|
|
4
|
+
|
|
5
|
+
app.get('/health', async (ctx) => ctx.json({ ok: true }))
|
|
6
|
+
app.get('/hello', async (ctx) => ctx.json({ message: 'hello from Pulse' }))
|
|
7
|
+
app.get('/*', async (ctx) => ctx.text('not found', { status: 404 }))
|
|
8
|
+
|
|
9
|
+
export default app
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
cases: [
|
|
3
|
+
{
|
|
4
|
+
name: 'health',
|
|
5
|
+
request: { path: '/health' },
|
|
6
|
+
expect: { status: 200, json: { ok: true } },
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: 'hello',
|
|
10
|
+
request: { path: '/hello' },
|
|
11
|
+
expect: {
|
|
12
|
+
status: 200,
|
|
13
|
+
json: { message: 'hello from Pulse' },
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'missing',
|
|
18
|
+
request: { path: '/missing' },
|
|
19
|
+
expect: { status: 404, text: 'not found' },
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from '@pulse-compute/pulse'
|
|
2
|
+
|
|
3
|
+
export default defineConfig((_scope) => ({
|
|
4
|
+
pulse: {
|
|
5
|
+
entry: 'src/index.ts',
|
|
6
|
+
schema: 'src/schemas.ts',
|
|
7
|
+
tests: 'tests/pulse.harness.ts',
|
|
8
|
+
defaultProfile: 'local',
|
|
9
|
+
strict: true,
|
|
10
|
+
},
|
|
11
|
+
local: {
|
|
12
|
+
host: 'node',
|
|
13
|
+
target: 'native',
|
|
14
|
+
outDir: 'dist',
|
|
15
|
+
schemas: { contentTypePolicy: 'require-json', maxBytes: 1024 },
|
|
16
|
+
},
|
|
17
|
+
}))
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Request schema
|
|
2
|
+
|
|
3
|
+
Compiles explicit TypeScript request and response schemas with the project. The
|
|
4
|
+
same codecs are used by `test`, `dev`, Node builds, and Fastly builds.
|
|
5
|
+
|
|
6
|
+
## Workflow
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pulse doctor
|
|
10
|
+
pulse inspect
|
|
11
|
+
pulse test
|
|
12
|
+
pulse dev
|
|
13
|
+
pulse build
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The documented test result below is executed by the documentation gate.
|
|
17
|
+
|
|
18
|
+
<!-- pulse-doc-run {"project":"examples/02-request-schema","args":["test","--json"]} -->
|
|
19
|
+
```bash
|
|
20
|
+
pulse test --json
|
|
21
|
+
```
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"status": "passed",
|
|
25
|
+
"provider": "node",
|
|
26
|
+
"summary": {
|
|
27
|
+
"total": 2,
|
|
28
|
+
"passed": 2,
|
|
29
|
+
"failed": 0
|
|
30
|
+
},
|
|
31
|
+
"cases": [
|
|
32
|
+
{
|
|
33
|
+
"name": "create-user",
|
|
34
|
+
"status": "passed",
|
|
35
|
+
"response": {
|
|
36
|
+
"status": 201
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Wasm size
|
|
44
|
+
|
|
45
|
+
| Artifact | Default build | `--experimental-native-size` | Reduction |
|
|
46
|
+
|---|---:|---:|---:|
|
|
47
|
+
| `canonical-native.wasm` | 38.9 KiB (39,795 bytes) | 30.8 KiB (31,578 bytes) | 20.6% |
|
|
48
|
+
|
|
49
|
+
The executable documentation gate rebuilds and measures both variants on
|
|
50
|
+
`1.0.0-beta.2`. These are uncompressed on-disk sizes, not transfer sizes or
|
|
51
|
+
platform limits.
|
|
52
|
+
|
|
53
|
+
## Handler
|
|
54
|
+
|
|
55
|
+
<!-- pulse-doc-source: examples/02-request-schema/src/index.ts -->
|
|
56
|
+
```ts
|
|
57
|
+
import { Pulse } from '@pulse-compute/pulse'
|
|
58
|
+
import type { CreateUserInput, CreateUserOutput } from './schemas.js'
|
|
59
|
+
|
|
60
|
+
const app = new Pulse({ auto: true })
|
|
61
|
+
|
|
62
|
+
app.post('/users', async (ctx) => {
|
|
63
|
+
const first = await ctx.req.json<CreateUserInput>('app.CreateUserInput')
|
|
64
|
+
const second = await ctx.req.json<CreateUserInput>('app.CreateUserInput')
|
|
65
|
+
const output: CreateUserOutput = {
|
|
66
|
+
id: 7,
|
|
67
|
+
name: first.name,
|
|
68
|
+
active: first.active,
|
|
69
|
+
sameReference: first === second,
|
|
70
|
+
}
|
|
71
|
+
return ctx.json(output, { status: 201, schema: 'app.CreateUserOutput' })
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
export default app
|
|
75
|
+
```
|
|
76
|
+
<!-- /pulse-doc-source -->
|
|
77
|
+
|
|
78
|
+
## Project config
|
|
79
|
+
|
|
80
|
+
<!-- pulse-doc-source: examples/02-request-schema/.pulse/config.ts -->
|
|
81
|
+
```ts
|
|
82
|
+
import { defineConfig } from '@pulse-compute/pulse'
|
|
83
|
+
|
|
84
|
+
export default defineConfig((_scope) => ({
|
|
85
|
+
pulse: {
|
|
86
|
+
entry: 'src/index.ts',
|
|
87
|
+
schema: 'src/schemas.ts',
|
|
88
|
+
tests: 'tests/pulse.harness.ts',
|
|
89
|
+
defaultProfile: 'local',
|
|
90
|
+
strict: true,
|
|
91
|
+
},
|
|
92
|
+
local: {
|
|
93
|
+
host: 'node',
|
|
94
|
+
target: 'native',
|
|
95
|
+
outDir: 'dist',
|
|
96
|
+
schemas: { contentTypePolicy: 'require-json', maxBytes: 1024 },
|
|
97
|
+
},
|
|
98
|
+
}))
|
|
99
|
+
```
|
|
100
|
+
<!-- /pulse-doc-source -->
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Test harness
|
|
104
|
+
|
|
105
|
+
<!-- pulse-doc-source: examples/02-request-schema/tests/pulse.harness.ts -->
|
|
106
|
+
```ts
|
|
107
|
+
export default {
|
|
108
|
+
cases: [
|
|
109
|
+
{
|
|
110
|
+
name: 'create-user',
|
|
111
|
+
request: {
|
|
112
|
+
method: 'POST',
|
|
113
|
+
path: '/users',
|
|
114
|
+
headers: { 'content-type': 'application/json' },
|
|
115
|
+
body: JSON.stringify({ name: 'Ada', active: true }),
|
|
116
|
+
},
|
|
117
|
+
expect: {
|
|
118
|
+
status: 201,
|
|
119
|
+
json: {
|
|
120
|
+
id: 7,
|
|
121
|
+
name: 'Ada',
|
|
122
|
+
active: true,
|
|
123
|
+
sameReference: true,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: 'invalid-user',
|
|
129
|
+
request: {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
path: '/users',
|
|
132
|
+
headers: { 'content-type': 'application/json' },
|
|
133
|
+
body: JSON.stringify({ name: 12, active: true }),
|
|
134
|
+
},
|
|
135
|
+
expect: {
|
|
136
|
+
error: {
|
|
137
|
+
name: 'SchemaDecodeError',
|
|
138
|
+
code: 'PULSE_SCHEMA_DECODE',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
<!-- /pulse-doc-source -->
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pulse-examples/02-request-schema",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"doctor": "pulse doctor",
|
|
8
|
+
"inspect": "pulse inspect",
|
|
9
|
+
"test": "pulse test",
|
|
10
|
+
"dev": "pulse dev",
|
|
11
|
+
"build": "pulse build"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@pulse-compute/pulse": "1.0.0-beta.2"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@pulse-compute/cli": "1.0.0-beta.2",
|
|
18
|
+
"typescript": "5.9.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Pulse } from '@pulse-compute/pulse'
|
|
2
|
+
import type { CreateUserInput, CreateUserOutput } from './schemas.js'
|
|
3
|
+
|
|
4
|
+
const app = new Pulse({ auto: true })
|
|
5
|
+
|
|
6
|
+
app.post('/users', async (ctx) => {
|
|
7
|
+
const first = await ctx.req.json<CreateUserInput>('app.CreateUserInput')
|
|
8
|
+
const second = await ctx.req.json<CreateUserInput>('app.CreateUserInput')
|
|
9
|
+
const output: CreateUserOutput = {
|
|
10
|
+
id: 7,
|
|
11
|
+
name: first.name,
|
|
12
|
+
active: first.active,
|
|
13
|
+
sameReference: first === second,
|
|
14
|
+
}
|
|
15
|
+
return ctx.json(output, { status: 201, schema: 'app.CreateUserOutput' })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
export default app
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineSchemaRegistry, schema } from '@pulse-compute/pulse/schema'
|
|
2
|
+
|
|
3
|
+
export interface CreateUserInput {
|
|
4
|
+
name: string
|
|
5
|
+
active: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface CreateUserOutput {
|
|
9
|
+
id: number
|
|
10
|
+
name: string
|
|
11
|
+
active: boolean
|
|
12
|
+
sameReference: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default defineSchemaRegistry({
|
|
16
|
+
schemas: {
|
|
17
|
+
'app.CreateUserInput': schema<CreateUserInput>(),
|
|
18
|
+
'app.CreateUserOutput': schema<CreateUserOutput>(),
|
|
19
|
+
},
|
|
20
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
cases: [
|
|
3
|
+
{
|
|
4
|
+
name: 'create-user',
|
|
5
|
+
request: {
|
|
6
|
+
method: 'POST',
|
|
7
|
+
path: '/users',
|
|
8
|
+
headers: { 'content-type': 'application/json' },
|
|
9
|
+
body: JSON.stringify({ name: 'Ada', active: true }),
|
|
10
|
+
},
|
|
11
|
+
expect: {
|
|
12
|
+
status: 201,
|
|
13
|
+
json: {
|
|
14
|
+
id: 7,
|
|
15
|
+
name: 'Ada',
|
|
16
|
+
active: true,
|
|
17
|
+
sameReference: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'invalid-user',
|
|
23
|
+
request: {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
path: '/users',
|
|
26
|
+
headers: { 'content-type': 'application/json' },
|
|
27
|
+
body: JSON.stringify({ name: 12, active: true }),
|
|
28
|
+
},
|
|
29
|
+
expect: {
|
|
30
|
+
error: {
|
|
31
|
+
name: 'SchemaDecodeError',
|
|
32
|
+
code: 'PULSE_SCHEMA_DECODE',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineConfig } from '@pulse-compute/pulse'
|
|
2
|
+
|
|
3
|
+
export default defineConfig((_scope) => ({
|
|
4
|
+
pulse: {
|
|
5
|
+
entry: 'src/index.ts',
|
|
6
|
+
tests: 'tests/pulse.harness.ts',
|
|
7
|
+
defaultProfile: 'local',
|
|
8
|
+
strict: true,
|
|
9
|
+
},
|
|
10
|
+
local: {
|
|
11
|
+
host: 'node',
|
|
12
|
+
target: 'native',
|
|
13
|
+
outDir: 'dist',
|
|
14
|
+
dev: {
|
|
15
|
+
fetches: {
|
|
16
|
+
'https://users.example.test/users/123': {
|
|
17
|
+
value: { id: 123, name: 'Ada' },
|
|
18
|
+
delayMs: 15,
|
|
19
|
+
},
|
|
20
|
+
'https://stats.example.test/users/123': {
|
|
21
|
+
value: { score: 42 },
|
|
22
|
+
delayMs: 5,
|
|
23
|
+
},
|
|
24
|
+
'https://flags.example.test/users/123': {
|
|
25
|
+
value: { enabled: true },
|
|
26
|
+
delayMs: 1,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}))
|