@pikku/cli 0.12.91 → 0.12.93
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/LICENSE +106 -0
- package/console-app/assets/{index-D0HG8q0B.css → index-BYj7ZbUU.css} +1 -1
- package/console-app/assets/{index-CpkvmAGb.js → index-CmAplHjZ.js} +151 -149
- package/console-app/index.html +2 -2
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-channel.js +16 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.json +15 -0
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +48 -0
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
- package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +1 -1
- package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.json +73 -40
- package/dist/.pikku/function/pikku-functions.gen.js +1 -3
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
- package/dist/.pikku/pikku-bootstrap-scenarios.gen.d.ts +2 -1
- package/dist/.pikku/pikku-bootstrap-scenarios.gen.js +2 -1
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
- package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
- package/dist/.pikku/pikku-meta-service.gen.js +1 -1
- package/dist/.pikku/pikku-services.gen.d.ts +1 -1
- package/dist/.pikku/pikku-types.gen.d.ts +1 -1
- package/dist/.pikku/pikku-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +3 -1
- package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.js +1 -1
- package/dist/.pikku/scenarios/pikku-scenario-functions.gen.d.ts +1 -1
- package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.js +1 -1
- package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.d.ts +1 -1
- package/dist/.pikku/scenarios/schemas/register.gen.d.ts +4 -0
- package/dist/.pikku/scenarios/schemas/register.gen.js +4 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
- package/dist/.pikku/schemas/register.gen.js +13 -3
- package/dist/.pikku/schemas/schemas/FabricSecretsListOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/FabricSecretsRotateInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/FabricSecretsRotateOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/FabricSecretsSetOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/KnowledgeIndexInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/KnowledgeIndexOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/KnowledgeValidateInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/KnowledgeValidateOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/ScenarioRunInput.schema.json +1 -1
- package/dist/.pikku/scopes/pikku-scope-types.gen.d.ts +1 -1
- package/dist/.pikku/scopes/pikku-scope-types.gen.js +1 -1
- package/dist/.pikku/scopes/pikku-scopes.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
- package/dist/.pikku/workflow/meta/allWorkflow.gen.json +2 -8
- package/dist/.pikku/workflow/pikku-scenario-actors.gen.d.ts +1 -1
- package/dist/.pikku/workflow/pikku-scenario-actors.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
- package/dist/bin/pikku-bin.mjs +2 -2
- package/dist/src/cli.wiring.js +29 -0
- package/dist/src/deploy/analyzer/analyzer.js +22 -5
- package/dist/src/deploy/build-pipeline.js +5 -1
- package/dist/src/fabric/fabric-commands.d.ts +37 -9
- package/dist/src/fabric/fabric-commands.js +12 -0
- package/dist/src/fabric/functions/domains-add.function.d.ts +4 -4
- package/dist/src/fabric/functions/secrets-list.function.d.ts +16 -4
- package/dist/src/fabric/functions/secrets-list.function.js +12 -10
- package/dist/src/fabric/functions/secrets-rotate.function.d.ts +24 -0
- package/dist/src/fabric/functions/secrets-rotate.function.js +36 -0
- package/dist/src/fabric/functions/secrets-set.function.d.ts +8 -4
- package/dist/src/fabric/functions/secrets-set.function.js +18 -7
- package/dist/src/fabric/functions/validate.function.js +16 -7
- package/dist/src/fabric/lib/http.d.ts +7 -1
- package/dist/src/fabric/lib/sealed-box.d.ts +16 -0
- package/dist/src/fabric/lib/sealed-box.js +72 -0
- package/dist/src/functions/commands/dev.js +9 -0
- package/dist/src/functions/commands/knowledge-index.d.ts +30 -0
- package/dist/src/functions/commands/knowledge-index.js +11 -0
- package/dist/src/functions/commands/knowledge-validate.d.ts +33 -0
- package/dist/src/functions/commands/knowledge-validate.js +11 -0
- package/dist/src/functions/commands/new-addon.d.ts +18 -0
- package/dist/src/functions/commands/new-addon.js +40 -24
- package/dist/src/functions/commands/pikku-command-bootstrap.js +1 -0
- package/dist/src/functions/commands/scenario-browser.d.ts +17 -2
- package/dist/src/functions/commands/scenario-browser.js +16 -8
- package/dist/src/functions/commands/scenario-environment.d.ts +32 -0
- package/dist/src/functions/commands/scenario-environment.js +61 -0
- package/dist/src/functions/commands/scenario.d.ts +6 -0
- package/dist/src/functions/commands/scenario.js +14 -9
- package/dist/src/functions/commands/skills.js +27 -61
- package/dist/src/functions/db/db-codegen.d.ts +6 -0
- package/dist/src/functions/db/db-codegen.js +9 -0
- package/dist/src/functions/db/db-migrator.js +14 -0
- package/dist/src/functions/db/local-db.d.ts +8 -0
- package/dist/src/functions/db/local-db.js +24 -2
- package/dist/src/functions/db/migration-identifiers.d.ts +58 -0
- package/dist/src/functions/db/migration-identifiers.js +262 -0
- package/dist/src/functions/db/migration-provenance.d.ts +35 -0
- package/dist/src/functions/db/migration-provenance.js +80 -0
- package/dist/src/functions/db/schema-sql.d.ts +43 -0
- package/dist/src/functions/db/schema-sql.js +135 -0
- package/dist/src/functions/db/sqlite/sqlite-kysely.js +22 -2
- package/dist/src/functions/knowledge/render.d.ts +3 -0
- package/dist/src/functions/knowledge/render.js +66 -0
- package/dist/src/functions/knowledge/schemas.d.ts +51 -0
- package/dist/src/functions/knowledge/schemas.js +25 -0
- package/dist/src/functions/wirings/credentials/serialize-credentials-types.js +8 -1
- package/dist/src/functions/wirings/functions/schemas.js +13 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +6 -1
- package/dist/src/functions/wirings/scenarios/register-scenario-instrumentation.d.ts +10 -0
- package/dist/src/functions/wirings/scenarios/register-scenario-instrumentation.js +102 -0
- package/dist/src/functions/wirings/scenarios/scenario-partition.d.ts +13 -0
- package/dist/src/functions/wirings/scenarios/scenario-partition.js +15 -2
- package/dist/src/functions/wirings/scenarios/scenario-schema-partition.d.ts +33 -0
- package/dist/src/functions/wirings/scenarios/scenario-schema-partition.js +49 -0
- package/dist/src/functions/wirings/secrets/serialize-secrets-types.js +10 -3
- package/dist/src/functions/wirings/variables/serialize-variables-types.js +8 -1
- package/dist/src/functions/workflows/all.workflow.js +2 -7
- package/dist/src/utils/file-writer.js +14 -2
- package/dist/src/utils/pikku-cli-config.d.ts +14 -0
- package/dist/src/utils/pikku-cli-config.js +34 -0
- package/dist/src/utils/remove-legacy-scaffold-file.d.ts +14 -0
- package/dist/src/utils/remove-legacy-scaffold-file.js +23 -0
- package/dist/src/utils/serialize-schemas.d.ts +3 -1
- package/dist/src/utils/serialize-schemas.js +39 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -9
- package/dist/.pikku/schemas/schemas/PikkuScenarioFunctionsOutput.schema.json +0 -1
- package/dist/src/functions/wirings/scenarios/pikku-command-scenario-functions.d.ts +0 -1
- package/dist/src/functions/wirings/scenarios/pikku-command-scenario-functions.js +0 -31
- package/dist/src/functions/wirings/scenarios/serialize-scenario-functions.d.ts +0 -10
- package/dist/src/functions/wirings/scenarios/serialize-scenario-functions.js +0 -104
- package/skills/pikku-addon/SKILL.md +0 -243
- package/skills/pikku-addon/references/addon-package-manifest.md +0 -63
- package/skills/pikku-ai-agent/SKILL.md +0 -231
- package/skills/pikku-ai-vercel/SKILL.md +0 -82
- package/skills/pikku-ai-voice/SKILL.md +0 -88
- package/skills/pikku-audit/SKILL.md +0 -175
- package/skills/pikku-aws/SKILL.md +0 -111
- package/skills/pikku-backblaze/SKILL.md +0 -71
- package/skills/pikku-better-auth/SKILL.md +0 -298
- package/skills/pikku-cli/SKILL.md +0 -198
- package/skills/pikku-cli/references/complete-example.md +0 -82
- package/skills/pikku-concepts/SKILL.md +0 -250
- package/skills/pikku-concepts/references/concept-mapping.md +0 -556
- package/skills/pikku-concepts/references/packages.md +0 -29
- package/skills/pikku-config/SKILL.md +0 -212
- package/skills/pikku-cron/SKILL.md +0 -214
- package/skills/pikku-deploy-azure/SKILL.md +0 -71
- package/skills/pikku-deploy-cloudflare/SKILL.md +0 -82
- package/skills/pikku-deploy-express/SKILL.md +0 -86
- package/skills/pikku-deploy-fastify/SKILL.md +0 -73
- package/skills/pikku-deploy-lambda/SKILL.md +0 -110
- package/skills/pikku-deploy-nextjs/SKILL.md +0 -78
- package/skills/pikku-deploy-uws/SKILL.md +0 -88
- package/skills/pikku-deps/SKILL.md +0 -98
- package/skills/pikku-emails/SKILL.md +0 -163
- package/skills/pikku-fabric/SKILL.md +0 -318
- package/skills/pikku-fabric-debug/SKILL.md +0 -112
- package/skills/pikku-feature/SKILL.md +0 -258
- package/skills/pikku-gateway-slack/SKILL.md +0 -115
- package/skills/pikku-http/SKILL.md +0 -220
- package/skills/pikku-http/references/http-options.md +0 -55
- package/skills/pikku-i18n/SKILL.md +0 -137
- package/skills/pikku-info/SKILL.md +0 -100
- package/skills/pikku-jose/SKILL.md +0 -105
- package/skills/pikku-kysely/SKILL.md +0 -219
- package/skills/pikku-machine-auth/SKILL.md +0 -183
- package/skills/pikku-mcp/SKILL.md +0 -241
- package/skills/pikku-middleware/SKILL.md +0 -231
- package/skills/pikku-middleware/references/middleware-patterns.md +0 -61
- package/skills/pikku-mongodb/SKILL.md +0 -105
- package/skills/pikku-n8n-import/SKILL.md +0 -109
- package/skills/pikku-n8n-import/SPEC.md +0 -84
- package/skills/pikku-n8n-import/references/addon-mapping.md +0 -121
- package/skills/pikku-n8n-import/references/code-translation.md +0 -121
- package/skills/pikku-n8n-import/references/loops-and-control.md +0 -87
- package/skills/pikku-paraglide/SKILL.md +0 -117
- package/skills/pikku-permissions/SKILL.md +0 -192
- package/skills/pikku-pino/SKILL.md +0 -79
- package/skills/pikku-product-second-opinion/README.md +0 -43
- package/skills/pikku-product-second-opinion/SKILL.md +0 -158
- package/skills/pikku-product-second-opinion/example/sample-report.md +0 -90
- package/skills/pikku-product-second-opinion/references/report-template.md +0 -73
- package/skills/pikku-queue/SKILL.md +0 -240
- package/skills/pikku-react/SKILL.md +0 -212
- package/skills/pikku-react-query/SKILL.md +0 -242
- package/skills/pikku-realtime/SKILL.md +0 -236
- package/skills/pikku-realtime/references/other-routes.md +0 -23
- package/skills/pikku-redis/SKILL.md +0 -90
- package/skills/pikku-rpc/SKILL.md +0 -171
- package/skills/pikku-rtl/SKILL.md +0 -219
- package/skills/pikku-scenario/SKILL.md +0 -382
- package/skills/pikku-schedule/SKILL.md +0 -57
- package/skills/pikku-schema-ajv/SKILL.md +0 -62
- package/skills/pikku-schema-cfworker/SKILL.md +0 -63
- package/skills/pikku-security/SKILL.md +0 -108
- package/skills/pikku-services/SKILL.md +0 -248
- package/skills/pikku-services/references/audit-wire-service.md +0 -34
- package/skills/pikku-software-archaeology/README.md +0 -70
- package/skills/pikku-software-archaeology/SKILL.md +0 -186
- package/skills/pikku-software-archaeology/references/blueprint.schema.json +0 -625
- package/skills/pikku-software-archaeology/references/pikku-mapping.md +0 -49
- package/skills/pikku-software-archaeology/scripts/validate.mjs +0 -173
- package/skills/pikku-tag-middleware/SKILL.md +0 -13
- package/skills/pikku-template-clone/SKILL.md +0 -40
- package/skills/pikku-trigger/SKILL.md +0 -181
- package/skills/pikku-versioning/SKILL.md +0 -173
- package/skills/pikku-websocket/SKILL.md +0 -243
- package/skills/pikku-workflow/SKILL.md +0 -172
- package/skills/pikku-workflow/references/workflow-reference.md +0 -63
- package/skills/pikku-workflows-client/SKILL.md +0 -150
- package/skills/pikku-ws/SKILL.md +0 -47
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pikku-concepts
|
|
3
|
-
description: >-
|
|
4
|
-
Foundational guide to Pikku framework concepts. Use this skill when working with any Pikku
|
|
5
|
-
codebase, starting a new Pikku project, or migrating a backend to Pikku. Covers the core mental
|
|
6
|
-
model, function types, project structure, code generation, testing, and how Pikku maps to
|
|
7
|
-
traditional backend patterns. TRIGGER when: user asks "what is Pikku?", starts a new Pikku
|
|
8
|
-
project, migrates from Express/NestJS/Hono, or needs to understand how Pikku works. DO NOT
|
|
9
|
-
TRIGGER when: user is doing a specific wiring task (use the specific skill instead, e.g.
|
|
10
|
-
pikku-http, pikku-websocket).
|
|
11
|
-
installGroups: [core]
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
# Pikku Framework Concepts
|
|
15
|
-
|
|
16
|
-
## Agent Operating Procedure
|
|
17
|
-
|
|
18
|
-
Use this skill as an execution checklist, not reference material.
|
|
19
|
-
|
|
20
|
-
1. Discover before editing. Prefer OpenCode tools such as `pikku-meta` when available; otherwise run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
|
|
21
|
-
2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
|
|
22
|
-
3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
|
|
23
|
-
4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
|
|
24
|
-
5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
|
|
25
|
-
|
|
26
|
-
Pikku is a TypeScript framework that separates business logic from transport mechanisms. You define a function once, then wire it to HTTP, WebSocket, queues, schedulers, MCP, CLI, or RPC — without the function knowing how it's being called.
|
|
27
|
-
|
|
28
|
-
For deep-dive on each topic, see the dedicated skills:
|
|
29
|
-
|
|
30
|
-
- **Wiring**: `pikku-http`, `pikku-websocket`, `pikku-rpc`, `pikku-mcp`, `pikku-queue`, `pikku-cron`, `pikku-trigger`, `pikku-cli`, `pikku-ai-agent`, `pikku-workflow`
|
|
31
|
-
- **Infrastructure**: `pikku-services`, `pikku-security`, `pikku-config`
|
|
32
|
-
- **Project introspection**: `pikku-info`
|
|
33
|
-
|
|
34
|
-
## Core Mental Model
|
|
35
|
-
|
|
36
|
-
```text
|
|
37
|
-
pikkuFunc (pure business logic)
|
|
38
|
-
│
|
|
39
|
-
├── wireHTTP → Express, Fastify, Next.js, Lambda, Cloudflare...
|
|
40
|
-
├── wireChannel → WebSocket (real-time)
|
|
41
|
-
├── wireQueueWorker → BullMQ, PgBoss (async jobs)
|
|
42
|
-
├── wireScheduler → Cron (scheduled tasks)
|
|
43
|
-
├── wireMCPTool → Model Context Protocol (AI tools)
|
|
44
|
-
├── wireCLI → CLI commands
|
|
45
|
-
├── wireTrigger → Event-driven (Redis pub/sub, PG LISTEN/NOTIFY)
|
|
46
|
-
├── pikkuAIAgent → AI agents / chatbots
|
|
47
|
-
├── pikkuWorkflow → Multi-step durable workflows
|
|
48
|
-
└── wire.rpc → Internal function-to-function calls
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
A `pikkuFunc` receives three things:
|
|
52
|
-
|
|
53
|
-
1. **Services** — injected dependencies (logger, db, jwt, custom stores). See `pikku-services`.
|
|
54
|
-
2. **Data** — input from any source (HTTP body/query/params, WS message, queue payload, CLI args)
|
|
55
|
-
3. **Wire** — transport context (session, channel, rpc, mcp, http, queue)
|
|
56
|
-
|
|
57
|
-
The function never imports Express, never reads `req.body`, never touches `ws.send()`. It just works with typed data and services.
|
|
58
|
-
|
|
59
|
-
## Concept Mapping: Generic Backend → Pikku
|
|
60
|
-
|
|
61
|
-
Controllers/routes → `pikkuFunc`; middleware/auth/permissions → `pikku-security`; DI → `pikku-services`; transports (HTTP/WS/queue/cron) → their `wire*` + skill. For the full Generic Backend → Pikku mapping table (with side-by-side code examples), read `references/concept-mapping.md`.
|
|
62
|
-
|
|
63
|
-
## Functions
|
|
64
|
-
|
|
65
|
-
Three main function types:
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
// Requires authentication — receives session in wire context.
|
|
69
|
-
// input/output are Zod schemas; the data + return types are inferred from them.
|
|
70
|
-
const updateTodo = pikkuFunc({
|
|
71
|
-
input: UpdateTodoInput,
|
|
72
|
-
output: TodoOutput,
|
|
73
|
-
func: async (services, data, wire) => {
|
|
74
|
-
const { session } = wire
|
|
75
|
-
return services.todoStore.update(data.id, data)
|
|
76
|
-
},
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
// No authentication required
|
|
80
|
-
const listTodos = pikkuSessionlessFunc({
|
|
81
|
-
input: ListTodosInput,
|
|
82
|
-
output: TodoListOutput,
|
|
83
|
-
func: async (services, data) => {
|
|
84
|
-
return { todos: services.todoStore.list(data.filters) }
|
|
85
|
-
},
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
// No input or output (for scheduled tasks, lifecycle hooks)
|
|
89
|
-
const cleanup = pikkuVoidFunc(async (services) => {
|
|
90
|
-
services.todoStore.cleanOldItems()
|
|
91
|
-
})
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Services can be destructured inline in the `func` signature (e.g. `async ({ logger, todoStore }, { title }) => ...`). Full config options:
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
pikkuFunc({
|
|
98
|
-
title?: string, // Human-readable name
|
|
99
|
-
description?: string, // What the function does
|
|
100
|
-
version?: number, // Contract version (see pikku-config for versioning)
|
|
101
|
-
tags?: string[], // For grouping and middleware targeting
|
|
102
|
-
expose?: boolean, // Allow external RPC calls (see pikku-rpc)
|
|
103
|
-
remote?: boolean, // Allow remote RPC calls
|
|
104
|
-
mcp?: boolean, // Expose as MCP tool (see pikku-mcp)
|
|
105
|
-
auth?: boolean, // Override default auth requirement
|
|
106
|
-
input?: ZodSchema, // Input validation schema
|
|
107
|
-
output?: ZodSchema, // Output validation schema
|
|
108
|
-
permissions?: PermissionGroup, // See pikku-security
|
|
109
|
-
middleware?: PikkuMiddleware[], // See pikku-security
|
|
110
|
-
func: async (services, data, wire) => { ... },
|
|
111
|
-
})
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**Generics XOR `input`/`output` — never both.** A function's data and return
|
|
115
|
-
types come from *one* source: either the `input`/`output` schemas (preferred —
|
|
116
|
-
they double as runtime validation and OpenAPI) or type generics
|
|
117
|
-
(`pikkuFunc<In, Out>({ ... })`). Passing both makes the two disagree and forces
|
|
118
|
-
`as any` casts. Do not annotate the `func` return type inline either — let the
|
|
119
|
-
`output` schema (or the generic) be the single source of truth for the type.
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
// Correct — schema-based (no generics, no inline return type)
|
|
123
|
-
pikkuFunc({ input: MyInput, output: MyOutput, func: async (s, d) => { ... } })
|
|
124
|
-
// Correct — generic-based (no input/output)
|
|
125
|
-
pikkuFunc<MyIn, MyOut>({ func: async (s, d) => { ... } })
|
|
126
|
-
// WRONG — mixing the two
|
|
127
|
-
pikkuFunc<MyIn, MyOut>({ input: MyInput as any, func: async (s, d) => { ... } })
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Schemas (Validation)
|
|
131
|
-
|
|
132
|
-
Pikku uses Standard Schema — works with Zod, Valibot, ArkType:
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
import { z } from 'zod'
|
|
136
|
-
|
|
137
|
-
const CreateTodoInputSchema = z.object({
|
|
138
|
-
title: z.string().min(1).max(200),
|
|
139
|
-
priority: z.enum(['low', 'medium', 'high']).optional(),
|
|
140
|
-
tags: z.array(z.string()).optional(),
|
|
141
|
-
})
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
Schemas serve triple duty: runtime validation, TypeScript types, and OpenAPI documentation.
|
|
145
|
-
|
|
146
|
-
## Server Bootstrap
|
|
147
|
-
|
|
148
|
-
Every Pikku app follows the same bootstrap pattern regardless of runtime:
|
|
149
|
-
|
|
150
|
-
```typescript
|
|
151
|
-
import '../../functions/.pikku/pikku-bootstrap.gen.js' // Generated — registers all wirings
|
|
152
|
-
|
|
153
|
-
const config = await createConfig()
|
|
154
|
-
const singletonServices = await createSingletonServices(config)
|
|
155
|
-
|
|
156
|
-
// Pick your runtime:
|
|
157
|
-
const server = new PikkuFastifyServer(
|
|
158
|
-
config,
|
|
159
|
-
singletonServices,
|
|
160
|
-
createWireServices
|
|
161
|
-
)
|
|
162
|
-
// or: new PikkuExpressServer(config, singletonServices, createWireServices)
|
|
163
|
-
// or: pikkuAWSLambdaHandler(singletonServices)
|
|
164
|
-
// or: PikkuCloudflareHandler(singletonServices)
|
|
165
|
-
// or: pikkuNextHandler(singletonServices)
|
|
166
|
-
|
|
167
|
-
await server.init()
|
|
168
|
-
await server.start()
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Code Generation
|
|
172
|
-
|
|
173
|
-
Run `npx pikku all` to generate:
|
|
174
|
-
|
|
175
|
-
- `pikku-types.gen.ts` — Typed function factories and wiring functions
|
|
176
|
-
- `pikku-fetch.gen.ts` — Type-safe HTTP client
|
|
177
|
-
- `pikku-websocket.gen.ts` — Type-safe WebSocket client
|
|
178
|
-
- `pikku-bootstrap.gen.js` — Runtime initialization (auto-imports all wirings)
|
|
179
|
-
- `pikku-services.gen.ts` — Service factory types
|
|
180
|
-
|
|
181
|
-
Config lives in `pikku.config.json`:
|
|
182
|
-
|
|
183
|
-
```json
|
|
184
|
-
{
|
|
185
|
-
"tsconfig": "./tsconfig.json",
|
|
186
|
-
"srcDirectories": ["src"],
|
|
187
|
-
"outDir": ".pikku"
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Project Structure Convention
|
|
192
|
-
|
|
193
|
-
```text
|
|
194
|
-
src/
|
|
195
|
-
├── functions/ # Business logic (pikkuFunc definitions)
|
|
196
|
-
│ ├── todos.functions.ts
|
|
197
|
-
│ ├── auth.functions.ts
|
|
198
|
-
│ └── scheduled.functions.ts
|
|
199
|
-
├── wirings/ # Transport bindings
|
|
200
|
-
│ ├── todos.http.ts
|
|
201
|
-
│ ├── channel.wiring.ts
|
|
202
|
-
│ ├── scheduler.wiring.ts
|
|
203
|
-
│ └── queue.wiring.ts
|
|
204
|
-
├── schemas.ts # Zod/Valibot schemas
|
|
205
|
-
├── services.ts # Service factories (see pikku-services)
|
|
206
|
-
├── middleware.ts # Middleware definitions (see pikku-security)
|
|
207
|
-
├── permissions.ts # Permission definitions (see pikku-security)
|
|
208
|
-
└── .pikku/ # Generated (gitignored)
|
|
209
|
-
├── pikku-types.gen.ts
|
|
210
|
-
├── pikku-fetch.gen.ts
|
|
211
|
-
└── pikku-bootstrap.gen.js
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
## Environment Variables
|
|
215
|
-
|
|
216
|
-
Never use `process.env` inside Pikku functions. Use the `variables` service (see `pikku-config`):
|
|
217
|
-
|
|
218
|
-
```typescript
|
|
219
|
-
const apiKey = services.variables.get('API_KEY')
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
`process.env` belongs in server bootstrap code (`start.ts`) only.
|
|
223
|
-
|
|
224
|
-
## Testing
|
|
225
|
-
|
|
226
|
-
Functions are easily testable because they're pure:
|
|
227
|
-
|
|
228
|
-
```typescript
|
|
229
|
-
const mockServices = {
|
|
230
|
-
logger: new MockLogger(),
|
|
231
|
-
todoStore: new MockTodoStore(),
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Call function directly — no HTTP, no framework
|
|
235
|
-
const result = await listTodos.func(mockServices, { userId: 'test' })
|
|
236
|
-
expect(result.todos).toHaveLength(3)
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## Available Packages
|
|
240
|
-
|
|
241
|
-
Pikku ships runtime adapters (`@pikku/express-server`, `@pikku/fastify-server`, `@pikku/next`, `@pikku/aws-lambda`, `@pikku/cloudflare`, `@pikku/uws-server`, `@pikku/modelcontextprotocol`, ...) and service packages (`@pikku/jose`, `@pikku/schema-ajv`, `@pikku/pino`, `@pikku/kysely`, `@pikku/redis`, `@pikku/queue-bullmq`, `@pikku/queue-pg-boss`, ...). For the full list with use cases, read `references/packages.md`.
|
|
242
|
-
|
|
243
|
-
## Key Differences from Traditional Frameworks
|
|
244
|
-
|
|
245
|
-
1. **No decorators** — plain functions + explicit wiring, not `@Get()` or `@Injectable()`
|
|
246
|
-
2. **No classes required** — everything is functions and objects
|
|
247
|
-
3. **Transport is configuration, not code** — business logic doesn't know about HTTP/WS/etc.
|
|
248
|
-
4. **One function, many transports** — same function can serve HTTP, WebSocket, queue, and MCP simultaneously
|
|
249
|
-
5. **Generated type safety** — clients are auto-generated with full types, not manually maintained
|
|
250
|
-
6. **Schema-first validation** — Standard Schema (Zod/Valibot) replaces class-validator decorators
|