@zabaca/zbc 0.22.0 → 0.23.0
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/package.json +1 -1
- package/templates/CLAUDE.md +5 -0
- package/templates/apps/walgit/CONTEXT.md +5 -1
- package/templates/apps/walgit/README.md +159 -24
- package/templates/apps/walgit/package.json +2 -2
- package/templates/apps/walgit/registry.json +1 -1
- package/templates/apps/walgit/shared/browse.ts +18 -4
- package/templates/apps/walgit/shared/capabilities.ts +28 -3
- package/templates/apps/walgit/shared/container-env.ts +41 -2
- package/templates/apps/walgit/shared/container-lifecycle.ts +239 -0
- package/templates/apps/walgit/shared/container-snapshot.ts +219 -0
- package/templates/apps/walgit/shared/edge-refs.ts +612 -0
- package/templates/apps/walgit/{src → shared}/instructions.ts +8 -4
- package/templates/apps/walgit/shared/keys.ts +17 -0
- package/templates/apps/walgit/shared/landing.ts +10 -3
- package/templates/apps/walgit/shared/llms.ts +14 -5
- package/templates/apps/walgit/shared/policy.ts +1 -1
- package/templates/apps/walgit/shared/protocol.ts +35 -0
- package/templates/apps/walgit/shared/sleep-after.ts +44 -0
- package/templates/apps/walgit/shared/wal-index.ts +22 -1
- package/templates/apps/walgit/src/boot-residue.ts +58 -0
- package/templates/apps/walgit/src/cache.ts +9 -0
- package/templates/apps/walgit/src/cli.ts +39 -4
- package/templates/apps/walgit/src/delete-repo.ts +58 -9
- package/templates/apps/walgit/src/edge-refs.ts +148 -0
- package/templates/apps/walgit/src/expire.ts +75 -7
- package/templates/apps/walgit/src/hook-main.ts +2 -0
- package/templates/apps/walgit/src/http.ts +17 -4
- package/templates/apps/walgit/src/materialize.ts +34 -15
- package/templates/apps/walgit/src/push.ts +34 -8
- package/templates/apps/walgit/src/reconcile.ts +6 -1
- package/templates/apps/walgit/src/server.ts +69 -8
- package/templates/apps/walgit/src/sync.ts +10 -2
- package/templates/apps/walgit/worker/container-binding.ts +104 -0
- package/templates/apps/walgit/worker/durable-container.ts +786 -0
- package/templates/apps/walgit/worker/events-do.ts +16 -12
- package/templates/apps/walgit/worker/index.ts +235 -17
- package/templates/apps/walgit/worker/mcp.ts +9 -4
- package/templates/apps/walgit/wrangler.jsonc +44 -33
- package/templates/claude/settings.json +8 -0
- package/templates/infra/modules/cloudflare/index.ts +9 -0
- package/templates/infra/modules/d1/index.ts +30 -4
- package/templates/infra/modules/d1/registry.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import { defineModule } from '../../src/define-module'
|
|
3
|
+
import type { ApplyContext } from '../../src/types'
|
|
3
4
|
import { CfError, type CfOptions, cf, cfRaw } from '../cloudflare-api'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -16,7 +17,10 @@ import { CfError, type CfOptions, cf, cfRaw } from '../cloudflare-api'
|
|
|
16
17
|
* 'database_id', from: '<this instance>', output: 'databaseId' }` and the
|
|
17
18
|
* placeholder id in the checked-in wrangler config is never read.
|
|
18
19
|
*
|
|
19
|
-
* Token scope: CLOUDFLARE_API_TOKEN needs Account → D1: Edit.
|
|
20
|
+
* Token scope: CLOUDFLARE_API_TOKEN needs Account → D1: Edit. Or set
|
|
21
|
+
* `apiToken: { from, output }` to use an imported instance's output instead
|
|
22
|
+
* (e.g. a `cloudflare-token` instance's `tokenValue`), the same way the
|
|
23
|
+
* `cloudflare` module takes its deploy credential.
|
|
20
24
|
*/
|
|
21
25
|
|
|
22
26
|
/** Named per-code guidance for this module's calls — see `../cloudflare-api`. */
|
|
@@ -118,11 +122,33 @@ function isDuplicateColumn(err: unknown): boolean {
|
|
|
118
122
|
return err instanceof CfError && /duplicate column name/i.test(err.message)
|
|
119
123
|
}
|
|
120
124
|
|
|
125
|
+
/**
|
|
126
|
+
* The credential every call below uses: an imported instance's output when
|
|
127
|
+
* `apiToken` is set, else CLOUDFLARE_API_TOKEN from secrets.yaml. One helper
|
|
128
|
+
* so apply, destroy and the readiness probe can never disagree on it.
|
|
129
|
+
*/
|
|
130
|
+
function apiTokenFor(
|
|
131
|
+
config: { apiToken?: { from: string; output: string } },
|
|
132
|
+
ctx: ApplyContext,
|
|
133
|
+
): string {
|
|
134
|
+
return config.apiToken
|
|
135
|
+
? ctx.output(config.apiToken, 'apiToken')
|
|
136
|
+
: ctx.secret('CLOUDFLARE_API_TOKEN')
|
|
137
|
+
}
|
|
138
|
+
|
|
121
139
|
export const d1Module = defineModule({
|
|
122
140
|
name: 'd1',
|
|
123
141
|
configSchema: z.object({
|
|
124
142
|
/** Cloudflare account id (not a secret — it's in the dashboard URL). */
|
|
125
143
|
accountId: z.string(),
|
|
144
|
+
/**
|
|
145
|
+
* Where the credential comes from. Omit to read CLOUDFLARE_API_TOKEN from
|
|
146
|
+
* this environment's secrets.yaml. Set `{ from, output }` to pull it from
|
|
147
|
+
* an imported instance's outputs instead — e.g. a minted `cloudflare-token`
|
|
148
|
+
* whose permissions include D1 Read and D1 Write — so it never sits at
|
|
149
|
+
* rest. Mirrors the `cloudflare` module's `apiToken`.
|
|
150
|
+
*/
|
|
151
|
+
apiToken: z.object({ from: z.string(), output: z.string() }).optional(),
|
|
126
152
|
/** Database name — account-scoped, so namespace it per project/env. */
|
|
127
153
|
databaseName: z.string(),
|
|
128
154
|
/**
|
|
@@ -154,7 +180,7 @@ export const d1Module = defineModule({
|
|
|
154
180
|
databaseId: z.string(),
|
|
155
181
|
}),
|
|
156
182
|
async apply(config, ctx) {
|
|
157
|
-
const apiToken = ctx
|
|
183
|
+
const apiToken = apiTokenFor(config, ctx)
|
|
158
184
|
const { accountId, databaseName } = config
|
|
159
185
|
|
|
160
186
|
const existing = (await listDatabases(apiToken, accountId)).find((d) => d.name === databaseName)
|
|
@@ -211,7 +237,7 @@ export const d1Module = defineModule({
|
|
|
211
237
|
* strand every instance behind it in a `zbc destroy`.
|
|
212
238
|
*/
|
|
213
239
|
async destroy(config, ctx) {
|
|
214
|
-
const apiToken = ctx
|
|
240
|
+
const apiToken = apiTokenFor(config, ctx)
|
|
215
241
|
const { accountId, databaseName } = config
|
|
216
242
|
// The lookup is deliberately OUTSIDE the try: the forgiving case is
|
|
217
243
|
// "already gone", and that is the `!existing` branch. A listing that failed
|
|
@@ -246,7 +272,7 @@ export const d1Module = defineModule({
|
|
|
246
272
|
ready: {
|
|
247
273
|
proves: 'the database answers a query',
|
|
248
274
|
async probe(outputs, config, ctx) {
|
|
249
|
-
const apiToken = ctx
|
|
275
|
+
const apiToken = apiTokenFor(config, ctx)
|
|
250
276
|
await query(apiToken, config.accountId, outputs.databaseId, 'SELECT 1')
|
|
251
277
|
},
|
|
252
278
|
},
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
"secrets": ["CLOUDFLARE_API_TOKEN"],
|
|
10
10
|
"signupUrl": "https://dash.cloudflare.com/sign-up",
|
|
11
11
|
"tokenUrl": "https://dash.cloudflare.com/profile/api-tokens",
|
|
12
|
-
"instructions": "Reads the Cloudflare API through `../cloudflare-api`; CLOUDFLARE_API_TOKEN needs the Account → D1: Edit scope.\n\nInstance example:\n\n // packages/infra/environments/production/app-db.ts\n import { d1Module } from '../../modules/d1'\n export default d1Module.instance({\n name: 'app-db',\n config: {\n accountId: '<account id>',\n databaseName: 'myproject-production',\n statements: ['CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY)'],\n },\n })\n\nWire it into a Worker via the cloudflare module — the binding must ALREADY be declared in that package's wrangler.jsonc (placeholder database_id and all); zbc only supplies the id:\n\n imports: [appDb],\n config: { ..., bindings: [{ type: 'd1_databases', binding: 'DB', field: 'database_id', from: 'app-db', output: 'databaseId' }] }\n\n`statements` are replayed on every apply, so each must be idempotent (`CREATE TABLE IF NOT EXISTS`). Use `additiveColumns` for `ALTER TABLE … ADD COLUMN`, which SQLite cannot spell idempotently — an already-present column is treated as success."
|
|
12
|
+
"instructions": "Reads the Cloudflare API through `../cloudflare-api`; CLOUDFLARE_API_TOKEN needs the Account → D1: Edit scope.\n\nInstance example:\n\n // packages/infra/environments/production/app-db.ts\n import { d1Module } from '../../modules/d1'\n export default d1Module.instance({\n name: 'app-db',\n config: {\n accountId: '<account id>',\n databaseName: 'myproject-production',\n statements: ['CREATE TABLE IF NOT EXISTS users (id TEXT PRIMARY KEY)'],\n },\n })\n\nWire it into a Worker via the cloudflare module — the binding must ALREADY be declared in that package's wrangler.jsonc (placeholder database_id and all); zbc only supplies the id:\n\n imports: [appDb],\n config: { ..., bindings: [{ type: 'd1_databases', binding: 'DB', field: 'database_id', from: 'app-db', output: 'databaseId' }] }\n\nTo use a minted token instead of secrets.yaml (a `cloudflare-token` instance with 'D1 Read' and 'D1 Write'), import it and set `apiToken: { from: '<token instance>', output: 'tokenValue' }`.\n\n`statements` are replayed on every apply, so each must be idempotent (`CREATE TABLE IF NOT EXISTS`). Use `additiveColumns` for `ALTER TABLE … ADD COLUMN`, which SQLite cannot spell idempotently — an already-present column is treated as success."
|
|
13
13
|
}
|