@zabaca/zbc 0.21.0 → 0.22.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.
Files changed (52) hide show
  1. package/package.json +6 -1
  2. package/templates/apps/walgit/CONTEXT.md +25 -0
  3. package/templates/apps/walgit/README.md +152 -4
  4. package/templates/apps/walgit/e2e/harness.ts +2 -2
  5. package/templates/apps/walgit/e2e/scenarios.ts +302 -2
  6. package/templates/apps/walgit/shared/browse.ts +733 -0
  7. package/templates/apps/walgit/shared/capabilities.ts +17 -0
  8. package/templates/apps/walgit/shared/container-env.ts +9 -0
  9. package/templates/apps/walgit/shared/landing.ts +8 -27
  10. package/templates/apps/walgit/shared/llms.ts +25 -0
  11. package/templates/apps/walgit/shared/policy.ts +21 -0
  12. package/templates/apps/walgit/shared/pooled.ts +31 -0
  13. package/templates/apps/walgit/shared/protocol.ts +120 -0
  14. package/templates/apps/walgit/shared/repo-list.ts +478 -0
  15. package/templates/apps/walgit/shared/store.ts +307 -0
  16. package/templates/apps/walgit/shared/telemetry.ts +68 -6
  17. package/templates/apps/walgit/shared/wal-index.ts +249 -0
  18. package/templates/apps/walgit/shared/web.ts +46 -0
  19. package/templates/apps/walgit/src/announce-main.ts +1 -1
  20. package/templates/apps/walgit/src/announce.ts +1 -1
  21. package/templates/apps/walgit/src/append-only.ts +5 -8
  22. package/templates/apps/walgit/src/browse.ts +230 -0
  23. package/templates/apps/walgit/src/cache.ts +4 -4
  24. package/templates/apps/walgit/src/compact.ts +6 -12
  25. package/templates/apps/walgit/src/delete-repo.ts +4 -3
  26. package/templates/apps/walgit/src/expire.ts +3 -3
  27. package/templates/apps/walgit/src/gc.ts +4 -3
  28. package/templates/apps/walgit/src/git.ts +127 -10
  29. package/templates/apps/walgit/src/hook-main.ts +1 -1
  30. package/templates/apps/walgit/src/http.ts +386 -3
  31. package/templates/apps/walgit/src/limits.ts +1 -1
  32. package/templates/apps/walgit/src/materialize.bench.ts +4 -10
  33. package/templates/apps/walgit/src/materialize.ts +11 -4
  34. package/templates/apps/walgit/src/orphans.ts +3 -3
  35. package/templates/apps/walgit/src/pending.ts +1 -1
  36. package/templates/apps/walgit/src/private.ts +1 -1
  37. package/templates/apps/walgit/src/proposals.ts +3 -3
  38. package/templates/apps/walgit/src/push-cert.ts +10 -1
  39. package/templates/apps/walgit/src/push.ts +11 -9
  40. package/templates/apps/walgit/src/reconcile.ts +4 -3
  41. package/templates/apps/walgit/src/server.ts +29 -2
  42. package/templates/apps/walgit/src/signers.ts +9 -3
  43. package/templates/apps/walgit/src/store-env.ts +8 -21
  44. package/templates/apps/walgit/src/store.ts +12 -241
  45. package/templates/apps/walgit/src/sync.ts +2 -2
  46. package/templates/apps/walgit/src/usage.ts +4 -18
  47. package/templates/apps/walgit/src/verify.ts +2 -2
  48. package/templates/apps/walgit/src/wal-index.ts +20 -239
  49. package/templates/apps/walgit/worker/index.ts +232 -1
  50. package/templates/infra/modules/cloudflare-zone/index.ts +83 -9
  51. /package/templates/apps/walgit/{src → shared}/keys.ts +0 -0
  52. /package/templates/apps/walgit/{src → shared}/ulid.ts +0 -0
@@ -138,6 +138,26 @@ const recordSchema = z.discriminatedUnion('type', [
138
138
  ttl: ttlField,
139
139
  })
140
140
  .strict(),
141
+ /**
142
+ * Declared as its four fields rather than as one `content` string, because
143
+ * no single string means the same thing on both sides: the dashboard shows
144
+ * `priority weight port target`, while the API's `content` is
145
+ * `weight port target` with priority in a field of its own. A copied
146
+ * dashboard value would shift every number one place. See `desiredRecord`.
147
+ */
148
+ z
149
+ .object({
150
+ type: z.literal('SRV'),
151
+ /** The `_service._proto` label, e.g. `_autodiscover._tcp`. */
152
+ name: z.string(),
153
+ priority: z.number().int().min(0).max(65535),
154
+ weight: z.number().int().min(0).max(65535),
155
+ port: z.number().int().min(0).max(65535),
156
+ /** The host the service lives on. */
157
+ target: z.string().min(1),
158
+ ttl: ttlField,
159
+ })
160
+ .strict(),
141
161
  ])
142
162
 
143
163
  export type RecordConfig = z.infer<typeof recordSchema>
@@ -234,6 +254,9 @@ export function fqdn(name: string, zone: string): string {
234
254
  * Comparable form of a record's content. Cloudflare round-trips TXT values
235
255
  * with surrounding quotes in some API versions and normalises hostname targets
236
256
  * to lowercase without a trailing dot; neither difference is a change.
257
+ *
258
+ * An SRV's content is `weight port target`, and only the target is a hostname:
259
+ * the numbers compare as written, the last token as any other hostname does.
237
260
  */
238
261
  export function normalizeContent(type: string, content: string): string {
239
262
  const value = content.trim()
@@ -245,9 +268,22 @@ export function normalizeContent(type: string, content: string): string {
245
268
  if (type === 'CNAME' || type === 'MX' || type === 'NS' || type === 'AAAA') {
246
269
  return value.replace(/\.$/, '').toLowerCase()
247
270
  }
271
+ if (type === 'SRV') {
272
+ const tokens = value.split(/\s+/)
273
+ const target = tokens.pop() ?? ''
274
+ return [...tokens, target.replace(/\.$/, '').toLowerCase()].join(' ')
275
+ }
248
276
  return value
249
277
  }
250
278
 
279
+ /** What Cloudflare's create and PATCH take for an SRV, in place of `content`. */
280
+ export interface SrvData {
281
+ priority: number
282
+ weight: number
283
+ port: number
284
+ target: string
285
+ }
286
+
251
287
  export interface DesiredRecord {
252
288
  type: string
253
289
  /** Always an FQDN by the time it gets here. */
@@ -256,6 +292,38 @@ export interface DesiredRecord {
256
292
  ttl: number
257
293
  proxied?: boolean
258
294
  priority?: number
295
+ /** SRV only: the fields `content` and `priority` were derived from. */
296
+ data?: SrvData
297
+ }
298
+
299
+ /**
300
+ * One declared record in the shape the live one is compared against. For an
301
+ * SRV that is the API's shape, not the dashboard's: `content` is
302
+ * `weight port target` and priority rides alongside, exactly as
303
+ * `GET /dns_records` returns it, so `sameValue` and `differs` need no SRV case.
304
+ * `data` is carried too, because it and not `content` is what the write sends.
305
+ */
306
+ export function desiredRecord(record: RecordConfig, zone: string): DesiredRecord {
307
+ const name = fqdn(record.name, zone)
308
+ if (record.type === 'SRV') {
309
+ const { priority, weight, port, target } = record
310
+ return {
311
+ type: record.type,
312
+ name,
313
+ content: `${weight} ${port} ${target}`,
314
+ ttl: record.ttl,
315
+ priority,
316
+ data: { priority, weight, port, target },
317
+ }
318
+ }
319
+ return {
320
+ type: record.type,
321
+ name,
322
+ content: record.content,
323
+ ttl: record.ttl,
324
+ ...('proxied' in record ? { proxied: record.proxied } : {}),
325
+ ...('priority' in record ? { priority: record.priority } : {}),
326
+ }
259
327
  }
260
328
 
261
329
  export interface ActualRecord extends DesiredRecord {
@@ -323,7 +391,15 @@ function differs(desired: DesiredRecord, actual: DesiredRecord): boolean {
323
391
  return false
324
392
  }
325
393
 
326
- export const describeRecord = (r: DesiredRecord) => `${r.type} ${r.name} -> ${r.content}`
394
+ /**
395
+ * An SRV is printed `priority weight port target`, the order the dashboard and
396
+ * a zone file use. Its `content` alone omits priority, and a drift line is what
397
+ * an operator copies into an instance, so it has to carry all four numbers.
398
+ */
399
+ export const describeRecord = (r: DesiredRecord) =>
400
+ r.type === 'SRV'
401
+ ? `${r.type} ${r.name} -> ${r.priority ?? 0} ${r.content}`
402
+ : `${r.type} ${r.name} -> ${r.content}`
327
403
 
328
404
  export interface ZonePlan {
329
405
  create: DesiredRecord[]
@@ -562,6 +638,11 @@ async function listRecords(token: string, zoneId: string): Promise<ActualRecord[
562
638
 
563
639
  /** The request body Cloudflare wants for one declared record. */
564
640
  function recordBody(record: DesiredRecord): Record<string, unknown> {
641
+ // An SRV is written as its fields; `content` is what Cloudflare derives from
642
+ // them, and priority lives only inside `data`.
643
+ if (record.data) {
644
+ return { type: record.type, name: record.name, ttl: record.ttl, data: record.data }
645
+ }
565
646
  const body: Record<string, unknown> = {
566
647
  type: record.type,
567
648
  name: record.name,
@@ -617,14 +698,7 @@ export const cloudflareZoneModule = defineModule({
617
698
  }
618
699
 
619
700
  // 2. Diff the whole zone before mutating any of it.
620
- const desired = config.records.map((record) => ({
621
- type: record.type,
622
- name: fqdn(record.name, config.zone),
623
- content: record.content,
624
- ttl: record.ttl,
625
- ...('proxied' in record ? { proxied: record.proxied } : {}),
626
- ...('priority' in record ? { priority: record.priority } : {}),
627
- }))
701
+ const desired = config.records.map((record) => desiredRecord(record, config.zone))
628
702
  const actual = await listRecords(token, zone.id)
629
703
  const plan = planZone({ desired, actual })
630
704
 
File without changes
File without changes