Open History to see the last commit
1import { spawnSync } from 'node:child_process'
2import { mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
3import { tmpdir } from 'node:os'
4import { join, resolve } from 'node:path'
5
6const root = resolve(import.meta.dirname, '..')
7const temporary = await mkdtemp(join(tmpdir(), 'durable-streams-package-'))
8function run(command, args, cwd) {
9 const result = spawnSync(command, args, { cwd, encoding: 'utf8', env: process.env })
10 if (result.status !== 0) throw new Error(`${command} ${args.join(' ')} failed\n${result.stdout}\n${result.stderr}`)
11 return result.stdout
12}
13try {
14 run('pnpm', ['build'], root)
15 run('pnpm', ['pack', '--pack-destination', temporary], root)
16 const tarball = (await readdir(temporary)).find((f) => f.endsWith('.tgz'))
17 if (!tarball) throw new Error('No package tarball was produced')
18 await writeFile(join(temporary, 'package.json'), JSON.stringify({ private: true, type: 'module',
19 dependencies: { '@samwillis/durable-streams-neon': `file:./${tarball}`, pg: '8.23.1' },
20 devDependencies: { '@types/pg': '8.23.1', '@types/node': '24.10.1' },
21 }))
22 run('pnpm', ['install', '--prefer-offline', '--ignore-scripts'], temporary)
23 const installed = join(temporary, 'node_modules/@samwillis/durable-streams-neon')
24 const metadata = JSON.parse(await readFile(join(installed, 'package.json'), 'utf8'))
25 if (metadata.license !== 'Apache-2.0' || !(await readFile(join(installed, 'LICENSE'), 'utf8')).includes('Apache License')
26 || !(await readFile(join(installed, 'NOTICE'), 'utf8')).includes('Copyright 2026 Sam Willis')) throw new Error('Packaged license/notice missing')
27 await writeFile(join(temporary, 'consumer.ts'), `
28import { createDurableStreams, type Principal } from '@samwillis/durable-streams-neon'
29import { migrationPlan } from '@samwillis/durable-streams-neon/migrations'
30import { createNeonRealtimeNotifier } from '@samwillis/durable-streams-neon/neon'
31import { createS3ChunkStorage } from '@samwillis/durable-streams-neon/s3'
32import { parseSubscriptionKeyring } from '@samwillis/durable-streams-neon/subscriptions'
33import { inspectInstallation, beginRecovery, verifyRecovery, finishRecovery } from '@samwillis/durable-streams-neon/operations'
34import pg from 'pg'
35if ([inspectInstallation, beginRecovery, verifyRecovery, finishRecovery].some((fn) => typeof fn !== 'function')) throw new Error('Operations entrypoint missing')
36if (typeof createNeonRealtimeNotifier !== 'function') throw new Error('Realtime entrypoint missing')
37const storage = createS3ChunkStorage({ endpoint: 'https://storage.example.test', region: 'eu-central-1', bucket: 'consumer-tests' })
38storage.close()
39parseSubscriptionKeyring(JSON.stringify({ currentKeyId: 'consumer', keys: { consumer: Buffer.alloc(32).toString('base64') } }))
40const pool = new pg.Pool()
41const server = createDurableStreams({ postgres: { pool }, auth: {
42 authenticate: (): Principal | null => null, authorize: () => false,
43} })
44const result = await server.fetch(new Request('https://example.test/v1/stream/test'))
45if (result.status !== 401) throw new Error('Unexpected unauthenticated behavior')
46const plan = await migrationPlan('consumer_schema')
47if (plan.length !== 6 || !plan[0]!.sql.includes('"consumer_schema".streams') || !plan[1]!.sql.includes('"consumer_schema".chunks') || !plan[2]!.sql.includes('fork_source_fk') || !plan[3]!.sql.includes('webhook_signing_keys') || !plan[4]!.sql.includes('serving_epoch') || !plan[5]!.sql.includes('replay_pins')) throw new Error('Packaged SQL migrations missing')
48await server.close()
49await pool.end()
50`)
51 run(process.execPath, [join(root, 'node_modules/typescript/bin/tsc'), '--strict', '--skipLibCheck', '--target', 'ES2024',
52 '--module', 'NodeNext', '--moduleResolution', 'NodeNext', '--noEmit', 'consumer.ts'], temporary)
53 run(process.execPath, ['consumer.ts'], temporary)
54 console.log('Packed consumer: install, public declarations, runtime exports, SQL assets, and licensing passed.')
55} finally {
56 await rm(temporary, { recursive: true, force: true })
57}