@terraforge/core 0.0.9 → 0.0.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/core",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,16 +9,16 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/terraforge-js/terraforge/issues"
11
11
  },
12
- "module": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
12
+ "module": "./dist/index.mjs",
13
+ "types": "./dist/index.d.mjs",
14
14
  "exports": {
15
15
  ".": {
16
- "import": "./dist/index.js",
17
- "types": "./dist/index.d.ts"
16
+ "import": "./dist/index.mjs",
17
+ "types": "./dist/index.d.mjs"
18
18
  }
19
19
  },
20
20
  "scripts": {
21
- "build": "tsup src/index.ts --format esm --dts --clean --out-dir ./dist",
21
+ "build": "tsdown src/index.ts --dts --clean --out-dir ./dist",
22
22
  "prepublishOnly": "if bun run test; then bun run build; else exit; fi",
23
23
  "test": "bun test"
24
24
  },
package/dist/index.d.ts DELETED
@@ -1,421 +0,0 @@
1
- import { UUID } from 'node:crypto';
2
- import { AwsCredentialIdentity, AwsCredentialIdentityProvider } from '@aws-sdk/types';
3
- import { S3Client } from '@aws-sdk/client-s3';
4
- import { DynamoDB } from '@aws-sdk/client-dynamodb';
5
-
6
- declare class Future<T = unknown> {
7
- protected callback: (resolve: (data: T) => void, reject: (error: unknown) => void) => void;
8
- protected listeners: Set<{
9
- resolve: (data: T) => void;
10
- reject?: (error: unknown) => void;
11
- }>;
12
- protected status: 0 | 1 | 2 | 3;
13
- protected data?: T;
14
- protected error?: unknown;
15
- constructor(callback: (resolve: (data: T) => void, reject: (error: unknown) => void) => void);
16
- get [Symbol.toStringTag](): string;
17
- pipe<N>(cb: (value: T) => N): Future<Awaited<N>>;
18
- then(resolve: (data: T) => void, reject?: (error: unknown) => void): void;
19
- }
20
-
21
- type Input<T = unknown> = T | Output<T> | Future<T> | Promise<T>;
22
- type OptionalInput<T = unknown> = Input<T> | Input<T | undefined> | Input<undefined>;
23
- type UnwrapInputArray<T extends Input[]> = {
24
- [K in keyof T]: UnwrapInput<T[K]>;
25
- };
26
- type UnwrapInput<T> = T extends Input<infer V> ? V : T;
27
- declare const findInputDeps: (props: unknown) => Meta[];
28
- declare const resolveInputs: <T>(inputs: T) => Promise<T>;
29
-
30
- type OptionalOutput<T = unknown> = Output<T | undefined>;
31
- declare class Output<T = unknown> extends Future<T> {
32
- readonly dependencies: Set<Meta>;
33
- constructor(dependencies: Set<Meta>, callback: (resolve: (data: T) => void, reject: (error: unknown) => void) => void);
34
- pipe<N>(cb: (value: T) => N): Output<Awaited<N>>;
35
- }
36
- declare const deferredOutput: <T>(cb: (resolve: (data: T) => void) => void) => Output<T>;
37
- declare const output: <T>(value: T) => Output<T>;
38
- declare const combine: <T extends Input[], R = UnwrapInputArray<T>>(...inputs: T) => Output<R>;
39
- declare const resolve: <T extends [Input, ...Input[]], R>(inputs: T, transformer: (...inputs: UnwrapInputArray<T>) => R) => Output<Awaited<R>>;
40
- declare const interpolate: (literals: TemplateStringsArray, ...placeholders: Input<any>[]) => Output<string>;
41
-
42
- type URN = `urn:${string}`;
43
-
44
- declare const nodeMetaSymbol: unique symbol;
45
- type Node<T extends Tag = Tag, O extends State = State> = {
46
- readonly [nodeMetaSymbol]: Meta<T>;
47
- readonly urn: URN;
48
- } & O;
49
- declare const isNode: (obj: object) => obj is {
50
- [nodeMetaSymbol]: Meta;
51
- };
52
- declare function getMeta(node: Resource): ResourceMeta;
53
- declare function getMeta(node: DataSource): DataSourceMeta;
54
- declare function getMeta(node: Node): Meta;
55
- declare const isResource: (obj: object) => obj is Resource;
56
- declare const isDataSource: (obj: object) => obj is DataSource;
57
-
58
- type ResourceConfig = Config & {
59
- /** Import an existing resource instead of creating a new resource. */
60
- import?: string;
61
- /** If true the resource will be retained in the backing cloud provider during a delete operation. */
62
- retainOnDelete?: boolean;
63
- /** If set, the provider’s Delete method will not be called for this resource if the specified resource is being deleted as well. */
64
- /** Declare that changes to certain properties should be treated as forcing a replacement. */
65
- replaceOnChanges?: string[];
66
- /** If true, create the replacement before deleting the existing resource. */
67
- createBeforeReplace?: boolean;
68
- };
69
- type ResourceMeta = Meta<'resource', ResourceConfig>;
70
- type Resource<O extends State = State> = O & {
71
- readonly [nodeMetaSymbol]: ResourceMeta;
72
- readonly urn: URN;
73
- };
74
- type ResourceClass<I extends State = State, O extends State = State> = {
75
- new (parent: Group, id: string, props: I, config?: ResourceConfig): Resource<O>;
76
- get(parent: Group, id: string, physicalId: string): DataSource<O>;
77
- };
78
-
79
- declare class Stack extends Group {
80
- readonly app: App;
81
- readonly dependencies: Set<Stack>;
82
- constructor(app: App, name: string);
83
- dependsOn(...stacks: Stack[]): this;
84
- }
85
-
86
- type Tag = 'resource' | 'data';
87
- type State = Record<string, unknown>;
88
- type Config = {
89
- /** Specify additional explicit dependencies in addition to the ones in the dependency graph. */
90
- dependsOn?: Resource[];
91
- /** Pass an ID of an explicitly configured provider, instead of using the default provider. */
92
- provider?: string;
93
- };
94
- type Meta<T extends Tag = Tag, C extends Config = Config> = {
95
- readonly tag: T;
96
- readonly urn: URN;
97
- readonly logicalId: string;
98
- readonly type: string;
99
- readonly stack: Stack;
100
- readonly provider: string;
101
- readonly input: State;
102
- readonly config?: C;
103
- readonly dependencies: Set<URN>;
104
- readonly resolve: (data: State) => void;
105
- readonly output: <V>(cb: (data: State) => V) => Output<V>;
106
- };
107
- declare const createMeta: <T extends Tag = Tag, C extends Config = Config>(tag: T, provider: string, parent: Group, type: string, logicalId: string, input: State, config?: C) => Meta<T, C>;
108
-
109
- type DataSourceMeta = Meta<'data'>;
110
- type DataSource<O extends State = State> = {
111
- readonly [nodeMetaSymbol]: DataSourceMeta;
112
- readonly urn: URN;
113
- } & O;
114
- type DataSourceFunction<I extends State = State, O extends State = State> = (parent: Group, id: string, input: I, config?: Config) => DataSource<O>;
115
-
116
- declare class Group {
117
- readonly parent: Group | undefined;
118
- readonly type: string;
119
- readonly name: string;
120
- protected children: Array<Group | Node>;
121
- constructor(parent: Group | undefined, type: string, name: string);
122
- get urn(): URN;
123
- protected addChild(child: Group | Node): void;
124
- add(...children: Array<Group | Node>): void;
125
- get nodes(): Node[];
126
- get resources(): Resource[];
127
- get dataSources(): DataSource[];
128
- }
129
-
130
- declare class App extends Group {
131
- readonly name: string;
132
- constructor(name: string);
133
- get stacks(): Stack[];
134
- }
135
-
136
- declare const enableDebug: () => void;
137
- declare const createDebugger: (group: string) => (...args: unknown[]) => void;
138
-
139
- interface LockBackend {
140
- insecureReleaseLock(urn: URN): Promise<void>;
141
- locked(urn: URN): Promise<boolean>;
142
- lock(urn: URN): Promise<() => Promise<void>>;
143
- }
144
-
145
- type AppState = {
146
- name: string;
147
- version?: number;
148
- idempotentToken?: UUID;
149
- stacks: Record<URN, StackState>;
150
- };
151
- type StackState = {
152
- name: string;
153
- nodes: Record<URN, NodeState>;
154
- };
155
- type NodeState = {
156
- tag: 'resource' | 'data';
157
- type: string;
158
- version?: number;
159
- provider: string;
160
- input: State;
161
- output: State;
162
- dependencies: URN[];
163
- lifecycle?: {
164
- retainOnDelete?: boolean;
165
- deleteAfterCreate?: boolean;
166
- };
167
- };
168
-
169
- type StateBackend = {
170
- get(urn: URN): Promise<AppState | undefined>;
171
- update(urn: URN, state: AppState): Promise<void>;
172
- delete(urn: URN): Promise<void>;
173
- };
174
-
175
- type CreateProps<T = State> = {
176
- type: string;
177
- state: T;
178
- idempotantToken?: string;
179
- };
180
- type UpdateProps<T = State> = {
181
- type: string;
182
- priorState: T;
183
- proposedState: T;
184
- idempotantToken?: string;
185
- };
186
- type DeleteProps<T = State> = {
187
- type: string;
188
- state: T;
189
- idempotantToken?: string;
190
- };
191
- type PlanProps<T = State> = {
192
- type: string;
193
- priorState: T;
194
- proposedState: T;
195
- };
196
- type GetProps<T = State> = {
197
- type: string;
198
- state: T;
199
- };
200
- type GetDataProps<T = State> = {
201
- type: string;
202
- state: T;
203
- };
204
- interface Provider {
205
- ownResource(id: string): boolean;
206
- getResource(props: GetProps): Promise<{
207
- version: number;
208
- state: State;
209
- }>;
210
- createResource(props: CreateProps): Promise<{
211
- version: number;
212
- state: State;
213
- }>;
214
- updateResource(props: UpdateProps): Promise<{
215
- version: number;
216
- state: State;
217
- }>;
218
- deleteResource(props: DeleteProps): Promise<void>;
219
- planResourceChange?(props: PlanProps): Promise<{
220
- version: number;
221
- state: State;
222
- requiresReplacement: boolean;
223
- }>;
224
- getData?(props: GetDataProps): Promise<{
225
- state: State;
226
- }>;
227
- destroy?(): Promise<void>;
228
- }
229
-
230
- type ResourceEvent = {
231
- urn: URN;
232
- type: string;
233
- };
234
- type BeforeResourceCreateEvent = ResourceEvent & {
235
- resource: Resource;
236
- newInput: State;
237
- };
238
- type AfterResourceCreateEvent = ResourceEvent & {
239
- resource: Resource;
240
- newInput: State;
241
- newOutput: State;
242
- };
243
- type BeforeResourceUpdateEvent = ResourceEvent & {
244
- resource: Resource;
245
- oldInput: State;
246
- newInput: State;
247
- oldOutput: State;
248
- };
249
- type AfterResourceUpdateEvent = ResourceEvent & {
250
- resource: Resource;
251
- oldInput: State;
252
- newInput: State;
253
- oldOutput: State;
254
- newOutput: State;
255
- };
256
- type BeforeResourceDeleteEvent = ResourceEvent & {
257
- oldInput: State;
258
- oldOutput: State;
259
- };
260
- type AfterResourceDeleteEvent = ResourceEvent & {
261
- oldInput: State;
262
- oldOutput: State;
263
- };
264
- type Hooks = {
265
- beforeResourceCreate?: (event: BeforeResourceCreateEvent) => Promise<void> | void;
266
- beforeResourceUpdate?: (event: BeforeResourceUpdateEvent) => Promise<void> | void;
267
- beforeResourceDelete?: (event: BeforeResourceDeleteEvent) => Promise<void> | void;
268
- afterResourceCreate?: (event: AfterResourceCreateEvent) => Promise<void> | void;
269
- afterResourceUpdate?: (event: AfterResourceUpdateEvent) => Promise<void> | void;
270
- afterResourceDelete?: (event: AfterResourceDeleteEvent) => Promise<void> | void;
271
- };
272
-
273
- type ProcedureOptions = {
274
- filters?: string[];
275
- idempotentToken?: UUID;
276
- };
277
- type WorkSpaceOptions = {
278
- providers: Provider[];
279
- concurrency?: number;
280
- backend: {
281
- state: StateBackend;
282
- lock: LockBackend;
283
- };
284
- hooks?: Hooks;
285
- };
286
- declare class WorkSpace {
287
- protected props: WorkSpaceOptions;
288
- constructor(props: WorkSpaceOptions);
289
- /**
290
- * Deploy the entire app or use the filter option to deploy specific stacks inside your app.
291
- */
292
- deploy(app: App, options?: ProcedureOptions): Promise<void>;
293
- /**
294
- * Delete the entire app or use the filter option to delete specific stacks inside your app.
295
- */
296
- delete(app: App, options?: ProcedureOptions): Promise<void>;
297
- /**
298
- * Hydrate the outputs of the resources & data-sources inside your app.
299
- */
300
- hydrate(app: App): Promise<void>;
301
- /**
302
- * Refresh the state of the resources & data-sources inside your app.
303
- */
304
- refresh(app: App): Promise<void>;
305
- protected destroyProviders(): Promise<void>;
306
- }
307
-
308
- type ResourceOperation = 'create' | 'update' | 'delete' | 'replace' | 'import' | 'resolve' | 'get';
309
-
310
- declare class ResourceError extends Error {
311
- readonly urn: URN;
312
- readonly type: string;
313
- readonly operation: ResourceOperation;
314
- static wrap(urn: URN, type: string, operation: ResourceOperation, error: unknown): ResourceError;
315
- constructor(urn: URN, type: string, operation: ResourceOperation, message: string);
316
- }
317
- declare class AppError extends Error {
318
- readonly app: string;
319
- readonly issues: (ResourceError | Error)[];
320
- constructor(app: string, issues: (ResourceError | Error)[], message: string);
321
- }
322
- declare class ResourceNotFound extends Error {
323
- }
324
- declare class ResourceAlreadyExists extends Error {
325
- }
326
-
327
- declare class MemoryStateBackend implements StateBackend {
328
- protected states: Map<`urn:${string}`, AppState>;
329
- get(urn: URN): Promise<AppState | undefined>;
330
- update(urn: URN, state: AppState): Promise<void>;
331
- delete(urn: URN): Promise<void>;
332
- clear(): void;
333
- }
334
-
335
- declare class MemoryLockBackend implements LockBackend {
336
- protected locks: Map<`urn:${string}`, number>;
337
- insecureReleaseLock(urn: URN): Promise<void>;
338
- locked(urn: URN): Promise<boolean>;
339
- lock(urn: URN): Promise<() => Promise<void>>;
340
- clear(): void;
341
- }
342
-
343
- declare class FileStateBackend implements StateBackend {
344
- private props;
345
- constructor(props: {
346
- dir: string;
347
- });
348
- private stateFile;
349
- private mkdir;
350
- get(urn: URN): Promise<AppState | undefined>;
351
- update(urn: URN, state: AppState): Promise<void>;
352
- delete(urn: URN): Promise<void>;
353
- }
354
-
355
- declare class FileLockBackend implements LockBackend {
356
- private props;
357
- constructor(props: {
358
- dir: string;
359
- });
360
- private lockFile;
361
- private mkdir;
362
- insecureReleaseLock(urn: URN): Promise<void>;
363
- locked(urn: URN): Promise<boolean>;
364
- lock(urn: URN): Promise<() => Promise<void>>;
365
- }
366
-
367
- type Props$1 = {
368
- credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider;
369
- region: string;
370
- bucket: string;
371
- };
372
- declare class S3StateBackend implements StateBackend {
373
- private props;
374
- protected client: S3Client;
375
- constructor(props: Props$1);
376
- get(urn: URN): Promise<any>;
377
- update(urn: URN, state: AppState): Promise<void>;
378
- delete(urn: URN): Promise<void>;
379
- }
380
-
381
- type Props = {
382
- credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider;
383
- region: string;
384
- tableName: string;
385
- };
386
- declare class DynamoLockBackend implements LockBackend {
387
- private props;
388
- protected client: DynamoDB;
389
- constructor(props: Props);
390
- insecureReleaseLock(urn: URN): Promise<void>;
391
- locked(urn: URN): Promise<boolean>;
392
- lock(urn: URN): Promise<() => Promise<void>>;
393
- }
394
-
395
- declare const file: (path: string, encoding?: BufferEncoding) => Future<string>;
396
- declare const hash: (path: string, algo?: string) => Future<string>;
397
-
398
- declare global {
399
- var $resolve: typeof resolve;
400
- var $combine: typeof combine;
401
- var $interpolate: typeof interpolate;
402
- var $hash: typeof hash;
403
- var $file: typeof file;
404
- }
405
-
406
- declare const createCustomResourceClass: <I extends State, O extends State>(providerId: string, resourceType: string) => ResourceClass<I, O>;
407
-
408
- type CustomResourceProvider = Partial<{
409
- getResource?(props: Omit<GetProps, 'type'>): Promise<State>;
410
- updateResource?(props: Omit<UpdateProps, 'type'>): Promise<State>;
411
- createResource?(props: Omit<CreateProps, 'type'>): Promise<State>;
412
- deleteResource?(props: Omit<DeleteProps, 'type'>): Promise<void>;
413
- getData?(props: Omit<GetDataProps, 'type'>): Promise<State>;
414
- planResourceChange?(props: Omit<PlanProps, 'type'>): Promise<{
415
- state: State;
416
- requiresReplacement: boolean;
417
- }>;
418
- }>;
419
- declare const createCustomProvider: (providerId: string, resourceProviders: Record<string, CustomResourceProvider>) => Provider;
420
-
421
- export { App, AppError, type Config, type CreateProps, type CustomResourceProvider, type DataSource, type DataSourceFunction, type DataSourceMeta, type DeleteProps, DynamoLockBackend, FileLockBackend, FileStateBackend, Future, type GetDataProps, type GetProps, Group, type Input, type LockBackend, MemoryLockBackend, MemoryStateBackend, type Meta, type Node, type OptionalInput, type OptionalOutput, Output, type PlanProps, type ProcedureOptions, type Provider, type Resource, ResourceAlreadyExists, type ResourceClass, type ResourceConfig, ResourceError, type ResourceMeta, ResourceNotFound, S3StateBackend, Stack, type State, type StateBackend, type Tag, type URN, type UpdateProps, WorkSpace, type WorkSpaceOptions, createCustomProvider, createCustomResourceClass, createDebugger, createMeta, deferredOutput, enableDebug, findInputDeps, getMeta, isDataSource, isNode, isResource, nodeMetaSymbol, output, resolveInputs };