@zabaca/zbc 0.1.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.
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@{{PROJECT_NAME}}/infra",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.ts"
8
+ },
9
+ "dependencies": {
10
+ "zod": "^3.24.0"
11
+ },
12
+ "devDependencies": {
13
+ "@types/node": "^25.6.0"
14
+ }
15
+ }
@@ -0,0 +1,8 @@
1
+ interface ZbcConfig {
2
+ project: string
3
+ environments: string[]
4
+ }
5
+
6
+ export function defineConfig(config: ZbcConfig): ZbcConfig {
7
+ return config
8
+ }
@@ -0,0 +1,34 @@
1
+ import type { z } from 'zod'
2
+ import type { ApplyFn, DestroyFn, ModuleDefinition, ModuleInstance, InstanceOptions } from './types'
3
+
4
+ interface DefineModuleOptions<TConfig extends z.ZodType, TOutputs extends z.ZodType> {
5
+ name: string
6
+ configSchema: TConfig
7
+ outputs: TOutputs
8
+ apply: ApplyFn<z.infer<TConfig>, z.infer<TOutputs>>
9
+ destroy?: DestroyFn<z.infer<TConfig>>
10
+ }
11
+
12
+ export function defineModule<TConfig extends z.ZodType, TOutputs extends z.ZodType>(
13
+ opts: DefineModuleOptions<TConfig, TOutputs>,
14
+ ): ModuleDefinition<TConfig, TOutputs> {
15
+ const definition: ModuleDefinition<TConfig, TOutputs> = {
16
+ name: opts.name,
17
+ configSchema: opts.configSchema,
18
+ outputsSchema: opts.outputs,
19
+ apply: opts.apply,
20
+ destroy: opts.destroy,
21
+ instance(instanceOpts: InstanceOptions<TConfig>): ModuleInstance<TOutputs> {
22
+ return {
23
+ name: instanceOpts.name,
24
+ moduleName: opts.name,
25
+ config: instanceOpts.config,
26
+ imports: instanceOpts.imports ?? [],
27
+ _outputsSchema: opts.outputs,
28
+ _definition: definition as ModuleDefinition<any, TOutputs>,
29
+ }
30
+ },
31
+ }
32
+
33
+ return definition
34
+ }
@@ -0,0 +1,3 @@
1
+ export { defineModule } from './define-module'
2
+ export { defineConfig } from './config'
3
+ export type { ModuleDefinition, ModuleInstance, ApplyContext, InstanceOptions } from './types'
@@ -0,0 +1,36 @@
1
+ import type { z } from 'zod'
2
+
3
+ export type ApplyFn<TConfig, TOutputs> = (config: TConfig, ctx: ApplyContext) => Promise<TOutputs>
4
+
5
+ export type DestroyFn<TConfig> = (config: TConfig, ctx: ApplyContext) => Promise<void>
6
+
7
+ export interface ApplyContext {
8
+ secrets: Record<string, string>
9
+ imports: Record<string, unknown>
10
+ projectRoot: string
11
+ }
12
+
13
+ export interface ModuleDefinition<TConfig extends z.ZodType, TOutputs extends z.ZodType> {
14
+ name: string
15
+ configSchema: TConfig
16
+ outputsSchema: TOutputs
17
+ apply: ApplyFn<z.infer<TConfig>, z.infer<TOutputs>>
18
+ destroy?: DestroyFn<z.infer<TConfig>>
19
+ instance: (opts: InstanceOptions<TConfig>) => ModuleInstance<TOutputs>
20
+ }
21
+
22
+ export interface InstanceOptions<TConfig extends z.ZodType> {
23
+ name: string
24
+ config: z.input<TConfig>
25
+ imports?: ModuleInstance[]
26
+ }
27
+
28
+ export interface ModuleInstance<TOutputs extends z.ZodType = z.ZodType> {
29
+ name: string
30
+ moduleName: string
31
+ config: unknown
32
+ imports: ModuleInstance[]
33
+ _outputsSchema: TOutputs
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ _definition: ModuleDefinition<any, TOutputs>
36
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": ".",
6
+ "types": ["node"]
7
+ },
8
+ "include": ["src/**/*", "modules/**/*", "environments/**/*"]
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "{{PROJECT_NAME}}",
3
+ "private": true,
4
+ "packageManager": "bun@1.3.4",
5
+ "workspaces": ["packages/*"],
6
+ "scripts": {
7
+ "build": "turbo run build",
8
+ "dev": "turbo run dev"
9
+ }
10
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "esnext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "resolveJsonModule": true,
11
+ "declaration": true,
12
+ "declarationMap": true,
13
+ "sourceMap": true,
14
+ "noUncheckedIndexedAccess": true
15
+ },
16
+ "include": ["packages/*/src/**/*"]
17
+ }
@@ -0,0 +1,11 @@
1
+ # Add your age public keys below as recipients. Run `age-keygen` to generate
2
+ # a keypair if you don't have one. The private key stays on your machine; the
3
+ # public key goes here.
4
+ #
5
+ # CI: store the CI private key as a GitHub Actions secret (SOPS_AGE_KEY) and
6
+ # add the matching public key to the recipients list below.
7
+ #
8
+ # After editing, run: sops updatekeys packages/infra/environments/<env>/secrets.yaml
9
+ creation_rules:
10
+ - age: >-
11
+ # add public keys here, comma-separated
@@ -0,0 +1,52 @@
1
+ name: Preview
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, synchronize, reopened, closed]
6
+
7
+ concurrency:
8
+ group: preview-${{ github.event.pull_request.number }}
9
+ cancel-in-progress: true
10
+
11
+ env:
12
+ PR_NUMBER: ${{ github.event.pull_request.number }}
13
+
14
+ jobs:
15
+ deploy:
16
+ if: github.event.action != 'closed'
17
+ runs-on: ubuntu-latest
18
+ permissions:
19
+ contents: read
20
+ pull-requests: write
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - uses: oven-sh/setup-bun@v2
25
+ with:
26
+ bun-version: latest
27
+
28
+ - run: bun install
29
+
30
+ - name: Apply preview
31
+ env:
32
+ SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
33
+ run: bunx @zabaca/zbc apply preview
34
+
35
+ cleanup:
36
+ if: github.event.action == 'closed'
37
+ runs-on: ubuntu-latest
38
+ permissions:
39
+ contents: read
40
+ steps:
41
+ - uses: actions/checkout@v4
42
+
43
+ - uses: oven-sh/setup-bun@v2
44
+ with:
45
+ bun-version: latest
46
+
47
+ - run: bun install
48
+
49
+ - name: Destroy preview
50
+ env:
51
+ SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
52
+ run: bunx @zabaca/zbc destroy preview
@@ -0,0 +1,28 @@
1
+ name: Production
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ concurrency:
8
+ group: production
9
+ cancel-in-progress: false
10
+
11
+ jobs:
12
+ deploy:
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: read
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: oven-sh/setup-bun@v2
20
+ with:
21
+ bun-version: latest
22
+
23
+ - run: bun install
24
+
25
+ - name: Apply production
26
+ env:
27
+ SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
28
+ run: bunx @zabaca/zbc apply production
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from '@{{PROJECT_NAME}}/infra'
2
+
3
+ export default defineConfig({
4
+ project: '{{PROJECT_NAME}}',
5
+ environments: ['production', 'preview'],
6
+ })