@pikku/cli 0.12.54 → 0.12.56
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/cli.schema.json +1 -1
- package/console-app/assets/{index-DYnbceYg.js → index-xN8LW0II.js} +155 -155
- package/console-app/index.html +1 -1
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +3 -3
- package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-channel.d.ts +6 -6
- package/dist/.pikku/cli/pikku-cli-channel.js +11 -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 +14 -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 +29 -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 +8 -31
- 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 +1420 -1384
- package/dist/.pikku/function/pikku-functions.gen.js +3 -1
- 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/http/pikku-http-wirings-meta.gen.js +1 -1
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-wirings.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.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 +4 -2
- package/dist/.pikku/pikku-services.gen.js +2 -0
- 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-meta.gen.json +0 -248
- 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 +69 -67
- 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 +191 -185
- package/dist/.pikku/schemas/schemas/FabricAddonVerifyInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/FabricAddonVerifyOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuAuthInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +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 +9 -3
- 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 +15 -1
- package/dist/src/deploy/analyzer/analyzer.d.ts +6 -0
- package/dist/src/deploy/analyzer/analyzer.js +5 -4
- package/dist/src/deploy/build-pipeline.d.ts +5 -1
- package/dist/src/deploy/build-pipeline.js +5 -5
- package/dist/src/deploy/bundler/bun-bundler.d.ts +14 -0
- package/dist/src/deploy/bundler/bun-bundler.js +121 -0
- package/dist/src/deploy/bundler/bundler.d.ts +25 -30
- package/dist/src/deploy/bundler/bundler.interface.d.ts +54 -0
- package/dist/src/deploy/bundler/bundler.interface.js +11 -0
- package/dist/src/deploy/bundler/bundler.js +120 -190
- package/dist/src/deploy/bundler/dep-extractor.d.ts +11 -3
- package/dist/src/deploy/bundler/dep-extractor.js +12 -6
- package/dist/src/deploy/bundler/index.d.ts +5 -2
- package/dist/src/deploy/bundler/index.js +4 -2
- package/dist/src/deploy/bundler/node-bundler.d.ts +13 -0
- package/dist/src/deploy/bundler/node-bundler.js +80 -0
- package/dist/src/deploy/provider-adapter.d.ts +11 -0
- package/dist/src/deploy/server-entry.js +3 -1
- package/dist/src/fabric/fabric-commands.d.ts +109 -72
- package/dist/src/fabric/fabric-commands.js +8 -0
- package/dist/src/fabric/functions/add.function.d.ts +3 -3
- package/dist/src/fabric/functions/addon-verify.function.d.ts +54 -0
- package/dist/src/fabric/functions/addon-verify.function.js +153 -0
- package/dist/src/fabric/functions/db-schema.function.d.ts +3 -3
- package/dist/src/fabric/functions/deploy-list.function.d.ts +3 -3
- package/dist/src/fabric/functions/deploy-units.function.d.ts +3 -3
- package/dist/src/fabric/functions/deploy.function.d.ts +6 -6
- package/dist/src/fabric/functions/domains-add.function.d.ts +3 -3
- package/dist/src/fabric/functions/domains-list.function.d.ts +3 -3
- package/dist/src/fabric/functions/domains-remove.function.d.ts +3 -3
- package/dist/src/fabric/functions/errors.function.d.ts +3 -3
- package/dist/src/fabric/functions/init.function.d.ts +3 -3
- package/dist/src/fabric/functions/link.function.d.ts +3 -3
- package/dist/src/fabric/functions/llm-key.function.d.ts +3 -3
- package/dist/src/fabric/functions/llm-key.function.js +1 -1
- package/dist/src/fabric/functions/login.function.d.ts +3 -3
- package/dist/src/fabric/functions/logs.function.d.ts +3 -3
- package/dist/src/fabric/functions/metrics.function.d.ts +3 -3
- package/dist/src/fabric/functions/publish.function.d.ts +3 -3
- package/dist/src/fabric/functions/publish.function.js +8 -3
- package/dist/src/fabric/functions/rollback.function.d.ts +3 -3
- package/dist/src/fabric/functions/secrets-list.function.d.ts +3 -3
- package/dist/src/fabric/functions/secrets-set.function.d.ts +3 -3
- package/dist/src/fabric/functions/smoke.function.d.ts +3 -3
- package/dist/src/fabric/functions/status.function.d.ts +3 -3
- package/dist/src/fabric/functions/trace.function.d.ts +3 -3
- package/dist/src/fabric/functions/validate.function.d.ts +3 -3
- package/dist/src/functions/commands/all.d.ts +1 -1
- package/dist/src/functions/commands/all.js +19 -2
- package/dist/src/functions/commands/binary.d.ts +3 -3
- package/dist/src/functions/commands/bootstrap.d.ts +1 -1
- package/dist/src/functions/commands/bootstrap.js +3 -0
- package/dist/src/functions/commands/console.d.ts +3 -3
- package/dist/src/functions/commands/db-audit.d.ts +1 -1
- package/dist/src/functions/commands/db-generate.d.ts +1 -1
- package/dist/src/functions/commands/db-migrate.d.ts +1 -1
- package/dist/src/functions/commands/db-reset.d.ts +1 -1
- package/dist/src/functions/commands/db-seed.d.ts +1 -1
- package/dist/src/functions/commands/deploy-apply.d.ts +3 -3
- package/dist/src/functions/commands/deploy-apply.js +32 -1
- package/dist/src/functions/commands/deploy-info.d.ts +1 -1
- package/dist/src/functions/commands/deploy-plan.d.ts +3 -3
- package/dist/src/functions/commands/deploy-plan.js +3 -1
- package/dist/src/functions/commands/dev.d.ts +3 -3
- package/dist/src/functions/commands/dev.js +17 -45
- package/dist/src/functions/commands/emails-init.d.ts +1 -1
- package/dist/src/functions/commands/enable.d.ts +6 -5
- package/dist/src/functions/commands/enable.js +4 -0
- package/dist/src/functions/commands/info.d.ts +4 -4
- package/dist/src/functions/commands/login.d.ts +7 -7
- package/dist/src/functions/commands/meta.d.ts +31 -31
- package/dist/src/functions/commands/new-addon.d.ts +3 -3
- package/dist/src/functions/commands/new-function.d.ts +3 -3
- package/dist/src/functions/commands/new-middleware.d.ts +3 -3
- package/dist/src/functions/commands/new-permission.d.ts +3 -3
- package/dist/src/functions/commands/new-wiring.d.ts +3 -3
- package/dist/src/functions/commands/pikku-command-bootstrap.d.ts +1 -1
- package/dist/src/functions/commands/pikku-command-summary.d.ts +1 -1
- package/dist/src/functions/commands/pikku-command-summary.js +6 -1
- package/dist/src/functions/commands/skills.d.ts +6 -6
- package/dist/src/functions/commands/tests-coverage.d.ts +3 -3
- package/dist/src/functions/commands/tests-init.d.ts +3 -3
- package/dist/src/functions/commands/versions-check.d.ts +1 -1
- package/dist/src/functions/commands/versions-init.d.ts +3 -3
- package/dist/src/functions/commands/versions-update.d.ts +1 -1
- package/dist/src/functions/commands/watch.d.ts +3 -3
- package/dist/src/functions/commands/workspace-validate.d.ts +3 -3
- package/dist/src/functions/db/db-codegen.js +14 -0
- package/dist/src/functions/db/sqlite/sqlite-runtime-bun.js +10 -0
- package/dist/src/functions/runtimes/fetch/index.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.d.ts +1 -1
- package/dist/src/functions/runtimes/tanstack-start/pikku-command-tanstack-start.d.ts +1 -1
- package/dist/src/functions/runtimes/websocket/pikku-command-websocket-typed.d.ts +1 -1
- package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent-types.d.ts +1 -1
- package/dist/src/functions/wirings/ai-agent/pikku-command-ai-agent.d.ts +1 -1
- package/dist/src/functions/wirings/ai-agent/pikku-command-public-agent.d.ts +1 -1
- package/dist/src/functions/wirings/auth/pikku-command-auth.d.ts +7 -1
- package/dist/src/functions/wirings/auth/pikku-command-auth.js +14 -2
- package/dist/src/functions/wirings/auth/serialize-auth-types.d.ts +10 -0
- package/dist/src/functions/wirings/auth/serialize-auth-types.js +15 -0
- package/dist/src/functions/wirings/channels/pikku-channels.d.ts +1 -1
- package/dist/src/functions/wirings/channels/pikku-command-channel-types.d.ts +1 -1
- package/dist/src/functions/wirings/channels/pikku-command-channels-map.d.ts +1 -1
- package/dist/src/functions/wirings/channels/pikku-command-channels.d.ts +1 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli-entry.d.ts +1 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli-types.d.ts +1 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli.d.ts +1 -1
- package/dist/src/functions/wirings/console/pikku-command-console-functions.d.ts +1 -1
- package/dist/src/functions/wirings/console/pikku-command-node-types.d.ts +1 -1
- package/dist/src/functions/wirings/console/pikku-command-nodes-meta.d.ts +1 -1
- package/dist/src/functions/wirings/credentials/pikku-command-credentials.d.ts +1 -1
- package/dist/src/functions/wirings/emails/pikku-command-emails.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-addon-types.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-function-types-split.d.ts +3 -3
- package/dist/src/functions/wirings/functions/pikku-command-function-types.d.ts +3 -3
- package/dist/src/functions/wirings/functions/pikku-command-function-types.js +10 -3
- package/dist/src/functions/wirings/functions/pikku-command-functions.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
- package/dist/src/functions/wirings/functions/schemas.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +6 -29
- package/dist/src/functions/wirings/gateway/pikku-command-gateway.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-http-map.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-http-routes.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-http-types.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-command-openapi.d.ts +1 -1
- package/dist/src/functions/wirings/http/pikku-http-routes.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/pikku-command-mcp.d.ts +1 -1
- package/dist/src/functions/wirings/middleware/pikku-command-middleware.d.ts +1 -1
- package/dist/src/functions/wirings/package/pikku-command-package-types.d.ts +2 -2
- package/dist/src/functions/wirings/package/pikku-command-package.d.ts +1 -1
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue-map.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue-service.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue-types.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-command-queue.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-queue-map.d.ts +1 -1
- package/dist/src/functions/wirings/queue/pikku-queue.d.ts +1 -1
- package/dist/src/functions/wirings/realtime/pikku-command-events-scaffold.d.ts +1 -1
- package/dist/src/functions/wirings/realtime/pikku-command-realtime.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-public-rpc.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-react-query.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-remote-rpc.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.d.ts +1 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.d.ts +2 -2
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.d.ts +1 -1
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.d.ts +1 -1
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.d.ts +1 -1
- package/dist/src/functions/wirings/secrets/pikku-command-secrets.d.ts +1 -1
- package/dist/src/functions/wirings/triggers/pikku-command-trigger-types.d.ts +3 -3
- package/dist/src/functions/wirings/triggers/pikku-command-trigger.d.ts +1 -1
- package/dist/src/functions/wirings/variables/pikku-command-variables.d.ts +1 -1
- package/dist/src/functions/wirings/workflow/pikku-command-workflow-routes.d.ts +1 -1
- package/dist/src/functions/wirings/workflow/pikku-command-workflow.d.ts +1 -1
- package/dist/src/functions/workflows/all.workflow.js +6 -1
- package/dist/src/scaffold/rpc-remote.gen.d.ts +3 -3
- package/dist/src/scaffold/rpc-remote.gen.js +1 -1
- package/dist/src/server/bun-server-runner.d.ts +17 -0
- package/dist/src/server/bun-server-runner.js +25 -0
- package/dist/src/server/dev-server-runner.interface.d.ts +31 -0
- package/dist/src/server/dev-server-runner.interface.js +11 -0
- package/dist/src/server/node-server-runner.d.ts +12 -0
- package/dist/src/server/node-server-runner.js +30 -0
- package/dist/src/services/cli-logger.service.js +7 -1
- package/dist/src/services.js +18 -0
- package/dist/src/utils/detect-better-auth.d.ts +7 -0
- package/dist/src/utils/detect-better-auth.js +29 -0
- package/dist/src/utils/parse-cli-filters.d.ts +1 -0
- package/dist/src/utils/parse-cli-filters.js +1 -0
- package/dist/src/utils/pikku-cli-config.js +1 -1
- package/dist/src/utils/serialize-schemas.js +5 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/skills/pikku-addon/SKILL.md +25 -117
- package/skills/pikku-addon/references/addon-package-manifest.md +63 -0
- package/skills/pikku-cli/SKILL.md +7 -93
- package/skills/pikku-cli/references/complete-example.md +82 -0
- package/skills/pikku-concepts/SKILL.md +17 -69
- package/skills/pikku-concepts/references/concept-mapping.md +37 -13
- package/skills/pikku-concepts/references/packages.md +29 -0
- package/skills/pikku-http/SKILL.md +14 -105
- package/skills/pikku-http/references/http-options.md +57 -0
- package/skills/pikku-middleware/SKILL.md +11 -68
- package/skills/pikku-middleware/references/middleware-patterns.md +61 -0
- package/skills/pikku-realtime/SKILL.md +56 -105
- package/skills/pikku-realtime/references/other-routes.md +23 -0
- package/skills/pikku-services/SKILL.md +25 -108
- package/skills/pikku-services/references/audit-wire-service.md +34 -0
- package/skills/pikku-testing/SKILL.md +51 -359
- package/skills/pikku-testing/references/cucumber-bdd-testing.md +176 -0
- package/skills/pikku-workflow/SKILL.md +93 -259
- package/skills/pikku-workflow/references/workflow-reference.md +63 -0
|
@@ -18,7 +18,7 @@ Use this skill as an execution checklist, not reference material.
|
|
|
18
18
|
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.
|
|
19
19
|
5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
|
|
20
20
|
|
|
21
|
-
Pikku uses factory functions for dependency injection. Singleton services are created once at startup
|
|
21
|
+
Pikku uses factory functions for dependency injection. Singleton services are created once at startup; wire services are created fresh per request/job/command. See `pikku-concepts` for the core mental model.
|
|
22
22
|
|
|
23
23
|
## Before You Start
|
|
24
24
|
|
|
@@ -27,47 +27,44 @@ pikku info functions --verbose # See which services existing functions use
|
|
|
27
27
|
pikku info tags --verbose # Understand project organization
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
See `pikku-concepts` for the core mental model.
|
|
31
|
-
|
|
32
30
|
## API Reference
|
|
33
31
|
|
|
34
|
-
### `pikkuServices(factory)`
|
|
35
|
-
|
|
36
|
-
Create singleton services — instantiated once at server startup.
|
|
32
|
+
### `pikkuServices(factory)` — singleton services (created once at startup)
|
|
37
33
|
|
|
38
34
|
```typescript
|
|
39
35
|
import { pikkuServices } from '#pikku'
|
|
36
|
+
import { ConsoleLogger } from '@pikku/core/services'
|
|
37
|
+
import { JoseJWTService } from '@pikku/jose'
|
|
40
38
|
|
|
41
|
-
const createSingletonServices = pikkuServices(
|
|
39
|
+
export const createSingletonServices = pikkuServices(
|
|
42
40
|
async (config, existingServices?) => {
|
|
43
41
|
// config: your CoreConfig object
|
|
44
42
|
// existingServices: optional, for chaining factories
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const logger = new ConsoleLogger()
|
|
44
|
+
const database = new DatabasePool(config.database)
|
|
45
|
+
await database.connect()
|
|
46
|
+
const jwt = new JoseJWTService(
|
|
47
|
+
async () => [{ id: 'my-key', value: config.jwtSecret }],
|
|
48
|
+
logger
|
|
49
|
+
)
|
|
50
|
+
return { config, logger, database, jwt, books: new BookService() }
|
|
52
51
|
}
|
|
53
52
|
)
|
|
54
53
|
```
|
|
55
54
|
|
|
56
|
-
### `pikkuWireServices(factory)`
|
|
57
|
-
|
|
58
|
-
Create per-request services — fresh instance for each HTTP request, queue job, CLI command, etc.
|
|
55
|
+
### `pikkuWireServices(factory)` — per-request services (fresh per HTTP request, queue job, CLI command, etc.)
|
|
59
56
|
|
|
60
57
|
```typescript
|
|
61
58
|
import { pikkuWireServices } from '#pikku'
|
|
62
59
|
|
|
63
|
-
const createWireServices = pikkuWireServices(
|
|
60
|
+
export const createWireServices = pikkuWireServices(
|
|
64
61
|
async (singletonServices, wire) => {
|
|
65
62
|
// singletonServices: all singleton services
|
|
66
63
|
// wire: transport context (session, channel, etc.)
|
|
67
64
|
// Pikku merges these with singleton services automatically
|
|
68
65
|
return {
|
|
69
|
-
userSession:
|
|
70
|
-
dbTransaction: DatabaseTransaction,
|
|
66
|
+
userSession: createUserSessionService(wire),
|
|
67
|
+
dbTransaction: new DatabaseTransaction(singletonServices.database),
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
)
|
|
@@ -75,10 +72,9 @@ const createWireServices = pikkuWireServices(
|
|
|
75
72
|
|
|
76
73
|
### Auto-Generated Service Manifest
|
|
77
74
|
|
|
78
|
-
After `npx pikku prebuild`, Pikku generates a manifest of which services are actually used:
|
|
75
|
+
After `npx pikku prebuild`, Pikku generates `.pikku/pikku-services.gen.ts`, a manifest of which services are actually used by wired functions:
|
|
79
76
|
|
|
80
77
|
```typescript
|
|
81
|
-
// .pikku/pikku-services.gen.ts (auto-generated)
|
|
82
78
|
export const requiredSingletonServices = {
|
|
83
79
|
database: true, // used by getUser, deleteUser
|
|
84
80
|
audit: true, // used by deleteUser
|
|
@@ -95,47 +91,9 @@ export type RequiredSingletonServices = Pick<
|
|
|
95
91
|
|
|
96
92
|
## Usage Patterns
|
|
97
93
|
|
|
98
|
-
### Basic Singleton Services
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
const createSingletonServices = pikkuServices(
|
|
102
|
-
async (config, existingServices) => {
|
|
103
|
-
const logger = new ConsoleLogger()
|
|
104
|
-
const database = new DatabasePool(config.database)
|
|
105
|
-
await database.connect()
|
|
106
|
-
|
|
107
|
-
const jwt = new JoseJWTService(
|
|
108
|
-
async () => [{ id: 'my-key', value: JWT_SECRET }],
|
|
109
|
-
logger
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
config,
|
|
114
|
-
logger,
|
|
115
|
-
database,
|
|
116
|
-
jwt,
|
|
117
|
-
books: new BookService(),
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
)
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### Per-Request Wire Services
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
const createWireServices = pikkuWireServices(
|
|
127
|
-
async (singletonServices, wire) => {
|
|
128
|
-
return {
|
|
129
|
-
userSession: createUserSessionService(wire),
|
|
130
|
-
dbTransaction: new DatabaseTransaction(singletonServices.database),
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
)
|
|
134
|
-
```
|
|
135
|
-
|
|
136
94
|
### Using Services in Functions
|
|
137
95
|
|
|
138
|
-
**Every service must be declared in `SingletonServices` (or `Services`) in `application-types.d.ts`.** Never access a service via a body-level cast (`services as typeof services & { myService: MyService }`) — that means the type is missing. Add the import and the field to `SingletonServices`, then destructure inline in the function signature. The inspector emits `SERVICES_NOT_DESTRUCTURED` and tree-shaking breaks when the first param is a plain identifier rather than an object pattern.
|
|
96
|
+
**Every service must be declared in `SingletonServices` (or `Services`) in `application-types.d.ts`.** Never access a service via a body-level cast (`services as typeof services & { myService: MyService }`) — that means the type is missing. Add the import and the field to `SingletonServices`, then destructure inline in the function signature. The inspector emits `SERVICES_NOT_DESTRUCTURED` and tree-shaking breaks when the first param is a plain identifier rather than an object pattern. Never `new` a service inside a function — services arrive only via injection.
|
|
139
97
|
|
|
140
98
|
```typescript
|
|
141
99
|
// ✅ Correct — inline destructure, no cast
|
|
@@ -143,8 +101,7 @@ const getUser = pikkuFunc({
|
|
|
143
101
|
title: 'Get User',
|
|
144
102
|
func: async ({ db, logger, jwt }, { userId }) => {
|
|
145
103
|
logger.info('Fetching user', { userId })
|
|
146
|
-
|
|
147
|
-
return { user }
|
|
104
|
+
return { user: await db.getUser(userId) }
|
|
148
105
|
},
|
|
149
106
|
})
|
|
150
107
|
|
|
@@ -159,7 +116,7 @@ const getUser = pikkuFunc({
|
|
|
159
116
|
|
|
160
117
|
### Dynamic Import Optimization
|
|
161
118
|
|
|
162
|
-
Use the generated manifest to conditionally import heavy dependencies:
|
|
119
|
+
Use the generated manifest to conditionally import heavy dependencies — only the services actually wired get instantiated:
|
|
163
120
|
|
|
164
121
|
```typescript
|
|
165
122
|
import { requiredSingletonServices } from '.pikku/pikku-services.gen.js'
|
|
@@ -184,38 +141,7 @@ const createSingletonServices = pikkuServices(async (config) => {
|
|
|
184
141
|
|
|
185
142
|
### Audit Wire Service
|
|
186
143
|
|
|
187
|
-
`createInvocationAudit`
|
|
188
|
-
|
|
189
|
-
Pair with `createAuditedKysely` to auto-capture every Kysely query as an audit event.
|
|
190
|
-
|
|
191
|
-
```typescript
|
|
192
|
-
// services.ts
|
|
193
|
-
import { createInvocationAudit } from '@pikku/core/services'
|
|
194
|
-
import { createAuditedKysely } from '@pikku/kysely'
|
|
195
|
-
|
|
196
|
-
export const createWireServices = pikkuWireServices(async (singletonServices, wire) => {
|
|
197
|
-
const audit = createInvocationAudit(singletonServices.audit, wire)
|
|
198
|
-
const kysely = singletonServices.kysely
|
|
199
|
-
? createAuditedKysely(singletonServices.kysely, { audit })
|
|
200
|
-
: undefined
|
|
201
|
-
return { audit, ...(kysely ? { kysely } : {}) }
|
|
202
|
-
})
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
The `audit` wire service is typed as `AuditLog` (from `@pikku/core`). Functions that emit custom events use it directly:
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
const deleteUser = pikkuFunc({
|
|
209
|
-
func: async ({ audit }, { userId }) => {
|
|
210
|
-
await audit.audit({ type: 'user.deleted', actor_user_id: userId })
|
|
211
|
-
// ...
|
|
212
|
-
},
|
|
213
|
-
})
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
`closeWireServices` (called automatically by the function-runner) invokes `audit.close()` → `singletonServices.audit.write(batch)` → platform-specific flush (e.g. CF Queue, libsql INSERT). No manual flushing needed.
|
|
217
|
-
|
|
218
|
-
> **Fabric note:** Fabric provisions the audit queue and consumer worker automatically. The audit table schema is in `db/sqlite/0003-audit.sql` (starter-template). Run `pikku fabric validate` to confirm the migration is in place.
|
|
144
|
+
`createInvocationAudit` + `createAuditedKysely` add per-request audit buffering that flushes on request close (no-op if `audit` is unconfigured). For the full pattern, no-op behavior, custom-event usage, and Fabric notes, read `references/audit-wire-service.md`.
|
|
219
145
|
|
|
220
146
|
### Built-in Services
|
|
221
147
|
|
|
@@ -240,22 +166,14 @@ import { JoseJWTService } from '@pikku/jose'
|
|
|
240
166
|
// Custom service
|
|
241
167
|
class TodoStore {
|
|
242
168
|
private todos: Map<string, Todo> = new Map()
|
|
243
|
-
|
|
244
169
|
async create(title: string, priority: string) {
|
|
245
170
|
const todo = { id: crypto.randomUUID(), title, priority, completed: false }
|
|
246
171
|
this.todos.set(todo.id, todo)
|
|
247
172
|
return todo
|
|
248
173
|
}
|
|
249
|
-
|
|
250
|
-
async
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
async list() {
|
|
254
|
-
return [...this.todos.values()]
|
|
255
|
-
}
|
|
256
|
-
async delete(id: string) {
|
|
257
|
-
this.todos.delete(id)
|
|
258
|
-
}
|
|
174
|
+
async get(id: string) { return this.todos.get(id) }
|
|
175
|
+
async list() { return [...this.todos.values()] }
|
|
176
|
+
async delete(id: string) { this.todos.delete(id) }
|
|
259
177
|
}
|
|
260
178
|
|
|
261
179
|
export const createSingletonServices = pikkuServices(async (config) => {
|
|
@@ -264,7 +182,6 @@ export const createSingletonServices = pikkuServices(async (config) => {
|
|
|
264
182
|
async () => [{ id: 'my-key', value: config.jwtSecret }],
|
|
265
183
|
logger
|
|
266
184
|
)
|
|
267
|
-
|
|
268
185
|
return {
|
|
269
186
|
config,
|
|
270
187
|
logger,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Audit Wire Service
|
|
2
|
+
|
|
3
|
+
`createInvocationAudit` creates a per-request `InvocationAuditLog` that buffers audit events in memory and flushes them as a batch when the function-runner calls `closeWireServices` at the end of the request. If `singletonServices.audit` is not configured (local dev without Fabric), it returns a no-op `DisabledInvocationAudit` — no crash, events are silently dropped.
|
|
4
|
+
|
|
5
|
+
Pair with `createAuditedKysely` to auto-capture every Kysely query as an audit event.
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// services.ts
|
|
9
|
+
import { createInvocationAudit } from '@pikku/core/services'
|
|
10
|
+
import { createAuditedKysely } from '@pikku/kysely'
|
|
11
|
+
|
|
12
|
+
export const createWireServices = pikkuWireServices(async (singletonServices, wire) => {
|
|
13
|
+
const audit = createInvocationAudit(singletonServices.audit, wire)
|
|
14
|
+
const kysely = singletonServices.kysely
|
|
15
|
+
? createAuditedKysely(singletonServices.kysely, { audit })
|
|
16
|
+
: undefined
|
|
17
|
+
return { audit, ...(kysely ? { kysely } : {}) }
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The `audit` wire service is typed as `AuditLog` (from `@pikku/core`). Functions that emit custom events use it directly:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
const deleteUser = pikkuFunc({
|
|
25
|
+
func: async ({ audit }, { userId }) => {
|
|
26
|
+
await audit.audit({ type: 'user.deleted', actor_user_id: userId })
|
|
27
|
+
// ...
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`closeWireServices` (called automatically by the function-runner) invokes `audit.close()` → `singletonServices.audit.write(batch)` → platform-specific flush (e.g. CF Queue, libsql INSERT). No manual flushing needed.
|
|
33
|
+
|
|
34
|
+
> **Fabric note:** Fabric provisions the audit queue and consumer worker automatically. The audit table schema is in `db/sqlite/0003-audit.sql` (starter-template). Run `pikku fabric validate` to confirm the migration is in place.
|