@pikku/skills 0.12.46 → 0.12.49
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/skills.gen.js +2 -2
- package/package.json +1 -1
- package/skills/pikku-addon/SKILL.md +6 -0
- package/skills/pikku-build/references/app.md +2 -1
- package/skills/pikku-build/references/quick.md +2 -1
- package/skills/pikku-fabric/SKILL.md +16 -0
- package/skills/pikku-kysely/SKILL.md +19 -0
- package/skills/pikku-wiring/references/trigger.md +43 -11
- package/skills/pikku-workflow/SKILL.md +38 -24
- package/skills/pikku-workflow/references/workflow-reference.md +1 -1
package/package.json
CHANGED
|
@@ -292,8 +292,14 @@ Author the DDL per dialect:
|
|
|
292
292
|
```text
|
|
293
293
|
db/sqlite/0001-labels.sql
|
|
294
294
|
db/postgres/0001-labels.sql
|
|
295
|
+
db/mysql/0001-labels.sql
|
|
295
296
|
```
|
|
296
297
|
|
|
298
|
+
`db/mysql` is the one that needs a server to publish: MySQL has no embedded
|
|
299
|
+
engine, so `pikku all` applies the SQL to a scratch database on the server named
|
|
300
|
+
by `db.mysqlUrl` in the addon's `pikku.config.json`, and refuses to build
|
|
301
|
+
without one. Use `varchar(n)` for a key column — MySQL rejects `TEXT` there.
|
|
302
|
+
|
|
297
303
|
`pikku all` publishes `<outDir>/db/pikku-db-meta.gen.json` on every build — per
|
|
298
304
|
dialect, the SQL verbatim plus a table/column map — and writes it **empty** when
|
|
299
305
|
the addon has no tables, because a consumer reads an absent file as a package
|
|
@@ -436,7 +436,8 @@ covered_. A stack of half-milestones cannot be reviewed and cannot be handed
|
|
|
436
436
|
over, and an uncovered function is a half-milestone whether or not the note says
|
|
437
437
|
`built`.
|
|
438
438
|
|
|
439
|
-
1. **Migration.** SQL in `db/sqlite/` at the project root
|
|
439
|
+
1. **Migration.** SQL in `db/sqlite/` at the project root (`db/postgres/` or
|
|
440
|
+
`db/mysql/` when `createConfig` sets `postgresUrl` or `mysqlUrl`), numbered on from the
|
|
440
441
|
ones already there. Apply with `bunx --bun pikku db migrate`, which also
|
|
441
442
|
regenerates the Kysely types your functions import. **Neither `pikku all` nor
|
|
442
443
|
restarting `pikku dev` applies a migration** — so a new column reads as
|
|
@@ -103,7 +103,8 @@ codegen depends on; without it your first `db migrate` fails with
|
|
|
103
103
|
|
|
104
104
|
Then, in this order — it is the order codegen depends on:
|
|
105
105
|
|
|
106
|
-
1. **Migration** — SQL in `db/sqlite
|
|
106
|
+
1. **Migration** — SQL in `db/sqlite/` (or `db/postgres/`, `db/mysql/` when
|
|
107
|
+
`createConfig` sets `postgresUrl` or `mysqlUrl`), numbered on from what is there. Apply
|
|
107
108
|
with `bunx --bun pikku db migrate`, which regenerates the Kysely types.
|
|
108
109
|
2. **Seed** — rows in `db/sqlite-dev-seed.sql`. There is no seed command:
|
|
109
110
|
`bunx --bun pikku db reset` wipes, migrates and seeds in one go, and is the
|
|
@@ -522,6 +522,22 @@ It mints a short-lived operator token for the stage and calls the stage's own
|
|
|
522
522
|
a 404 is refused by name and nothing is created. A generated password is printed
|
|
523
523
|
once; one you passed is never echoed. With no TTY, pass `--password` or pipe it.
|
|
524
524
|
|
|
525
|
+
### Opening a private stage
|
|
526
|
+
|
|
527
|
+
A non-production stage is private: without a link it answers "This preview is
|
|
528
|
+
private". `pikku fabric stage link` prints the link that opens it:
|
|
529
|
+
|
|
530
|
+
```bash
|
|
531
|
+
pikku fabric stage link access -b develop --route /login # use the stage
|
|
532
|
+
pikku fabric stage link changes -b develop # use it with the changes panel
|
|
533
|
+
pikku fabric stage visibility public -b develop # or: private
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
A stage has one live link of each kind, so asking again returns the same one
|
|
537
|
+
until it expires. A `changes` link turns the panel on first; if that needs a
|
|
538
|
+
deploy, the command says so. `visibility public` opens the stage to anyone with
|
|
539
|
+
its URL — hand out an `access` link instead when that is all you need.
|
|
540
|
+
|
|
525
541
|
## Versioning
|
|
526
542
|
|
|
527
543
|
Functions with `expose: true` are versioned via `versions.pikku.json`. When you change a function's input or output schema, you must bump its version number — otherwise `pikku all` will report a breaking change and callers' generated clients become stale.
|
|
@@ -305,6 +305,25 @@ than the CamelCasePlugin, because it exists to back the stores below. Reach for
|
|
|
305
305
|
`createNodeSqliteKysely` / `createBunSqliteKysely` for the instance your
|
|
306
306
|
functions query.
|
|
307
307
|
|
|
308
|
+
### MySQL and `pikku db`
|
|
309
|
+
|
|
310
|
+
`mysqlUrl` in `createConfig` makes MySQL the third dialect the `pikku db`
|
|
311
|
+
commands drive, with migrations in `db/mysql/` and the seed in
|
|
312
|
+
`db/mysql-dev-seed.sql`. It behaves like the other two with four differences:
|
|
313
|
+
|
|
314
|
+
- **No embedded engine.** Commands that need a throwaway database create and drop
|
|
315
|
+
a `pikku_scratch_<hex>` one on your server, so the account needs `CREATE` and
|
|
316
|
+
`DROP`.
|
|
317
|
+
- **DDL is not transactional.** A migration that fails halfway is replayed from
|
|
318
|
+
the top, so write migrations that are safe to run twice.
|
|
319
|
+
- **Inline `REFERENCES` is discarded** — declare foreign keys as
|
|
320
|
+
`FOREIGN KEY (...) REFERENCES ...` or none exists.
|
|
321
|
+
- **A key column cannot be `TEXT`**, nor can a `TEXT` column have a literal
|
|
322
|
+
default. Use `varchar(n)`, or `DEFAULT ('...')` for an expression default.
|
|
323
|
+
|
|
324
|
+
`db.schema` is refused (a MySQL schema is a database), and a standalone bundle
|
|
325
|
+
cannot target MySQL yet.
|
|
326
|
+
|
|
308
327
|
### Available Services
|
|
309
328
|
|
|
310
329
|
Each database variant exports these services with a prefix (`Pg`, `MySQL`, `SQLite`, or base `Kysely`):
|
|
@@ -107,17 +107,30 @@ subscribe to its events as `<source>:<event>`:
|
|
|
107
107
|
- The route is `POST /webhooks/<name>` unless `method`/`route` say otherwise.
|
|
108
108
|
`method` may be a list, e.g. `['get', 'post']` for a provider that verifies
|
|
109
109
|
the URL with a GET and delivers events with a POST, or `['head', 'post']`
|
|
110
|
-
for one that checks the URL with a HEAD.
|
|
111
|
-
It needs no session.
|
|
110
|
+
for one that checks the URL with a HEAD. A HEAD is answered with a `200`
|
|
111
|
+
before `verify` or `receive` run. It needs no session.
|
|
112
112
|
- `events` maps each event name to a schema. An event that fails its schema is
|
|
113
113
|
logged and dropped; so is one no `wireTrigger` listens for. Both still get a
|
|
114
114
|
`200`, so the provider does not retry forever.
|
|
115
|
-
- `receive(services, { body, headers, method, url, query })` gets the
|
|
116
|
-
bytes**
|
|
117
|
-
|
|
115
|
+
- `receive(services, { body, headers, method, url, query }, { http })` gets the
|
|
116
|
+
**raw bytes** and only parses them: it returns `{ events: [{ name, id?, data }] }`.
|
|
117
|
+
A handshake returns nothing and answers through `http.response`
|
|
118
|
+
(`http.response.header('x-hook-secret', secret)`,
|
|
119
|
+
`http.response.json({ challenge })`), which is sent only then. Throwing
|
|
118
120
|
rejects the request with the error's status (`UnauthorizedError` → 401).
|
|
119
121
|
Omitted, the JSON body becomes one event dispatched to a trigger named just
|
|
120
122
|
`<source>`.
|
|
123
|
+
- A named `receive` is declared with `pikkuWebhookReceive` from `#pikku/trigger`
|
|
124
|
+
(`#pikku/addon/trigger` in an addon), never `pikkuSessionlessFunc`: it is
|
|
125
|
+
public, typed to the request, and never callable as an RPC. The inspector
|
|
126
|
+
rejects any other wrapper. `parseJson` from `#pikku/utils`
|
|
127
|
+
(`#pikku/addon/utils`) parses the bytes and answers a body that is not JSON
|
|
128
|
+
with a 400:
|
|
129
|
+
|
|
130
|
+
```ts snippet:pikkuWebhookReceive
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
|
|
121
134
|
- Every accepted event is queued on `pikku-incoming-webhooks` and run by a
|
|
122
135
|
generated worker, so the provider is answered quickly and a failing trigger is
|
|
123
136
|
retried by the queue. This needs a `queueService` and an
|
|
@@ -129,12 +142,31 @@ id?, data }] }`, or `{ respond: { status, body } }` for a handshake. Throwing
|
|
|
129
142
|
even on queues that ignore job ids, and records each attempt and its last
|
|
130
143
|
error. Its `webhookReceipt` table comes from `pikku db generate`; `pikku dev`
|
|
131
144
|
and `pikku serve` use it when a Kysely database is configured.
|
|
132
|
-
-
|
|
133
|
-
|
|
134
|
-
`
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
- Signature checks belong in `verify`, never in `receive`. pikku runs it on
|
|
146
|
+
every request against the secret in the credential
|
|
147
|
+
`<name>WebhookSecret` (camelCased: `microsoft-outlook` →
|
|
148
|
+
`microsoftOutlookWebhookSecret`; `credential` overrides it). Declaring
|
|
149
|
+
`verify` declares that credential as a singleton string, so there is no
|
|
150
|
+
`defineCredential` and no service holding the secret; `credentialDescription`
|
|
151
|
+
tells whoever sets it where to find it. Pick the declared form that matches
|
|
152
|
+
the provider:
|
|
153
|
+
- `{ hmac: { header, prefix?, algorithm, encoding, secretEncoding? } }`:
|
|
154
|
+
a signature over the raw body in one header (GitHub, Shopify, Linear).
|
|
155
|
+
- `{ token: { header, prefix? } }`: the provider echoes the shared secret
|
|
156
|
+
(GitLab, Telegram).
|
|
157
|
+
- `{ publicKey: { header, algorithm?, dsaEncoding? } }`: signed with the
|
|
158
|
+
provider's private key; the stored secret is its PEM public key (Wise).
|
|
159
|
+
- Anything else (a timestamp in the signed payload, a signature in the body
|
|
160
|
+
or query, a URL in the signed string) is a function
|
|
161
|
+
`(request, secret, services) => boolean`, built from `hmacDigest`,
|
|
162
|
+
`verifyHmacSignature`, `verifyPublicKeySignature` and
|
|
163
|
+
`timingSafeStringEqual` in `@pikku/core/hmac`.
|
|
164
|
+
|
|
165
|
+
A request with a body that fails is refused with a 401. A bodiless request
|
|
166
|
+
that fails (a validation token in the query) still reaches
|
|
167
|
+
`receive` so it can answer the handshake, but any events it returns are
|
|
168
|
+
refused. A handshake that hands over the secret (Asana) stores it with
|
|
169
|
+
`credentialService.set` under the same credential name.
|
|
138
170
|
|
|
139
171
|
`check`, `setup` and `teardown` register the route with the provider. Each gets
|
|
140
172
|
`{ url, label, events, previous? }`, where `events` are only the ones some
|
|
@@ -237,38 +237,52 @@ with `outcome: 'success' | 'denied'`, the decider under `userIdentity`, and the
|
|
|
237
237
|
run, reason and refusal in `metadata`. Wire an `audit` service to keep it; a
|
|
238
238
|
project without one records nothing and is otherwise unaffected.
|
|
239
239
|
|
|
240
|
-
###
|
|
240
|
+
### Failure: `compensate`, never try/catch
|
|
241
241
|
|
|
242
242
|
**Do not wrap steps in try/catch.** The DSL extractor serialises the body into a
|
|
243
243
|
step graph, and a `catch` block is control flow it cannot represent — so the
|
|
244
|
-
graph would no longer describe what actually runs
|
|
245
|
-
|
|
244
|
+
graph would no longer describe what actually runs. This is a settled design
|
|
245
|
+
decision, not a temporary limitation.
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
Declare how a function is undone **on the function itself**. When a later step
|
|
248
|
+
fails (after its retries), the engine runs the `compensate` of every earlier
|
|
249
|
+
step that completed, newest first, then the failed step's own:
|
|
249
250
|
|
|
250
251
|
```typescript
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
)
|
|
252
|
+
export const chargePayment = pikkuFunc({
|
|
253
|
+
func: async ({ payments }, { orderId }) => payments.charge(orderId),
|
|
254
|
+
compensate: async ({ payments }, { orderId }, { workflow }) => {
|
|
255
|
+
const { ok, output } = workflow!.compensatingFor!
|
|
256
|
+
// ok: false → the charge itself failed; output is null, `error` is set
|
|
257
|
+
if (ok) await payments.refund(output.chargeId)
|
|
258
|
+
},
|
|
259
|
+
})
|
|
261
260
|
```
|
|
262
261
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
262
|
+
- `compensate` gets the **same input** as the forward call. `wire.workflow.compensatingFor`
|
|
263
|
+
is `{ ok: true, output, stepName }` or `{ ok: false, output: null, error, stepName }`.
|
|
264
|
+
- It is never callable over HTTP, MCP or RPC — only the engine runs it, as the
|
|
265
|
+
durable step `<step>:compensate` with the same retry defaults as forward steps.
|
|
266
|
+
- Opt a call site out with `{ compensate: false }` (graph nodes likewise).
|
|
267
|
+
- A run ends `compensated` (everything undone), `compensation_failed` (a
|
|
268
|
+
compensation ran out of retries; `stuckSteps` names them — steps that ran
|
|
269
|
+
before a stuck one are not undone, parallel siblings still are) or `failed`
|
|
270
|
+
(nothing needed undoing).
|
|
271
|
+
- `await workflow.milestone('paid')` bounds the unwind: steps finished before the
|
|
272
|
+
last milestone are kept, and the run ends `compensated` with `restedAt: 'paid'`.
|
|
273
|
+
- A failing child workflow unwinds itself first; a stuck child makes the parent
|
|
274
|
+
`compensation_failed`. Cancelling a run (`cancelRun`) unwinds it the same way,
|
|
275
|
+
children first.
|
|
276
|
+
|
|
277
|
+
To **recover** instead of undo, use a graph node's `recover`:
|
|
278
|
+
`recover: 'nodeId' | ['a','b'] | 'ignore'`. The failure is routed to those nodes
|
|
279
|
+
(`'ignore'` continues to `next` with a null output) and the failing step is not
|
|
280
|
+
compensated. The error arrives as `wire.graph.recoveringFrom`
|
|
281
|
+
(`{ nodeId, stepName, error }`). The DSL has no recovery — branch on a result
|
|
282
|
+
object (`{ success: false, reason }`) instead.
|
|
283
|
+
|
|
284
|
+
Full step options: `description`, `retries`, `retryDelay`, `compensate: false`
|
|
285
|
+
(plus `actor`, which is scenario-only — see `pikku-scenario`).
|
|
272
286
|
|
|
273
287
|
### Parallel fan-out
|
|
274
288
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Step execution: inline vs queue dispatch
|
|
4
4
|
|
|
5
|
-
Whether a step runs **inline** (same process/session, no queue round-trip) or is **dispatched to the queue** is decided **purely by the step's function** — there is no workflow-level or per-call dispatch flag. `workflow.do(...)` options are only `description`/`retries`/`retryDelay`/`
|
|
5
|
+
Whether a step runs **inline** (same process/session, no queue round-trip) or is **dispatched to the queue** is decided **purely by the step's function** — there is no workflow-level or per-call dispatch flag. `workflow.do(...)` options are only `description`/`retries`/`retryDelay`/`compensate: false`.
|
|
6
6
|
|
|
7
7
|
- **Steps default to inline.** Most steps don't need their own worker; running them inline avoids a queue round-trip per step, so a normally-started workflow executes its whole chain in one orchestrator pass.
|
|
8
8
|
- **`workflowQueued: true` opts a function out.** Set it on the **function config** (`pikkuFunc` / `pikkuSessionlessFunc`, same level as `auth`/`expose`) to dispatch that step via the queue — for expensive/long-running steps that deserve their own worker, retry isolation, and concurrency limits. `workflowRetries` and `workflowTimeout` sit alongside it.
|