@terraforge/terraform 0.0.1

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,84 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { parseArgs } from 'util'
4
+ import { createLazyPlugin } from '../src/lazy-plugin'
5
+ import { Version } from '../src/plugin/registry'
6
+ import { generateTypes } from '../src/type-gen'
7
+
8
+ const { values } = parseArgs({
9
+ args: Bun.argv,
10
+ options: {
11
+ org: {
12
+ type: 'string',
13
+ },
14
+ type: {
15
+ type: 'string',
16
+ },
17
+ },
18
+ strict: true,
19
+ allowPositionals: true,
20
+ })
21
+
22
+ if (!values.org) {
23
+ console.error('Missing required arguments: org')
24
+ process.exit(1)
25
+ }
26
+
27
+ if (!values.type) {
28
+ console.error('Missing required arguments: type')
29
+ process.exit(1)
30
+ }
31
+
32
+ const packageData = (await Bun.file('./package.json').json()) as { version?: Version }
33
+
34
+ if (!packageData) {
35
+ console.error('Failed to read package.json')
36
+ process.exit(1)
37
+ }
38
+
39
+ if (!packageData.version) {
40
+ console.error('Missing required arguments: version')
41
+ process.exit(1)
42
+ }
43
+
44
+ const org = values.org
45
+ const type = values.type
46
+ const version = packageData.version
47
+
48
+ console.log('org: ', org)
49
+ console.log('type: ', type)
50
+ console.log('version: ', version)
51
+
52
+ const ok = confirm('Continue?')
53
+
54
+ if (!ok) {
55
+ process.exit(0)
56
+ }
57
+
58
+ const load = createLazyPlugin({ org, type, version })
59
+ const plugin = await load()
60
+ const schema = plugin.schema()
61
+ const types = generateTypes(
62
+ {
63
+ [type]: schema.provider,
64
+ },
65
+ schema.resources,
66
+ schema.dataSources
67
+ )
68
+
69
+ await plugin.stop()
70
+
71
+ await Bun.write(`./src/types.ts`, types)
72
+
73
+ await Bun.write(
74
+ `./src/index.ts`,
75
+ `
76
+ import { createTerraformAPI } from '@terraforge/terraform'
77
+ import { root } from './types.ts'
78
+
79
+ export const ${type} = createTerraformAPI<typeof root.${type}>({
80
+ namespace: '${type}',
81
+ provider: { org: '${org}', type: '${type}', version: '${version}' },
82
+ }) as typeof root.${type}
83
+ `
84
+ )
@@ -0,0 +1,71 @@
1
+ type Version = `${number}.${number}.${number}` | "latest";
2
+ type TerraformProviderConfig = {
3
+ id?: string;
4
+ location?: string;
5
+ };
6
+ declare const createTerraformAPI: <T>(props: {
7
+ namespace: string;
8
+ provider: {
9
+ org: string;
10
+ type: string;
11
+ version: Version;
12
+ };
13
+ }) => T;
14
+ type Property = {
15
+ description?: string;
16
+ required?: boolean;
17
+ optional?: boolean;
18
+ /** The computed field means that it could be computed by the server. */
19
+ computed?: boolean;
20
+ deprecated?: boolean;
21
+ sensitive?: boolean;
22
+ } & ({
23
+ type: "string" | "number" | "boolean";
24
+ } | {
25
+ type: "array" | "record";
26
+ item: Property;
27
+ } | {
28
+ type: "object" | "array-object";
29
+ properties: Record<string, Property>;
30
+ } | {
31
+ type: "unknown";
32
+ });
33
+ declare const generateTypes: (providers: Record<string, Property>, resources: Record<string, Property>, dataSources: Record<string, Property>) => string;
34
+ import { CreateProps, DeleteProps, GetDataProps, GetProps, Provider, State as State2, UpdateProps } from "@terraforge/core";
35
+ type State = Record<string, unknown>;
36
+ type Plugin = Readonly<{
37
+ schema: () => {
38
+ provider: Property;
39
+ resources: Record<string, Property>;
40
+ dataSources: Record<string, Property>;
41
+ };
42
+ stop: () => Promise<void>;
43
+ configure: (config: State) => Promise<void>;
44
+ readResource: (type: string, state: State) => Promise<State>;
45
+ readDataSource: (type: string, state: State) => Promise<State>;
46
+ validateResource: (type: string, state: State) => Promise<void>;
47
+ planResourceChange: (type: string, priorState: State | null, proposedNewState: State | null) => Promise<{
48
+ requiresReplace: Array<string | number>[];
49
+ plannedState: State;
50
+ }>;
51
+ applyResourceChange: (type: string, priorState: State | null, proposedNewState: State | null) => Promise<State>;
52
+ }>;
53
+ declare class TerraformProvider implements Provider {
54
+ private type;
55
+ private id;
56
+ private createPlugin;
57
+ private config;
58
+ private configured?;
59
+ private plugin?;
60
+ constructor(type: string, id: string, createPlugin: () => Promise<Plugin>, config: State2);
61
+ private configure;
62
+ private prepare;
63
+ destroy(): Promise<void>;
64
+ ownResource(id: string): boolean;
65
+ getResource({ type, state }: GetProps);
66
+ createResource({ type, state }: CreateProps);
67
+ updateResource({ type, priorState, proposedState }: UpdateProps);
68
+ deleteResource({ type, state }: DeleteProps);
69
+ getData({ type, state }: GetDataProps);
70
+ }
71
+ export { generateTypes, createTerraformAPI, TerraformProviderConfig, TerraformProvider };