@webiny/pulumi-sdk 5.28.0 → 5.29.0-beta.2

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 (50) hide show
  1. package/Pulumi.d.ts +6 -5
  2. package/Pulumi.js +24 -11
  3. package/Pulumi.js.map +1 -1
  4. package/README.md +0 -13
  5. package/index.d.ts +0 -9
  6. package/index.js +0 -117
  7. package/index.js.map +1 -1
  8. package/package.json +9 -9
  9. package/ApplicationBuilder.d.ts +0 -40
  10. package/ApplicationBuilder.js +0 -37
  11. package/ApplicationBuilder.js.map +0 -1
  12. package/ApplicationBuilderGeneric.d.ts +0 -10
  13. package/ApplicationBuilderGeneric.js +0 -108
  14. package/ApplicationBuilderGeneric.js.map +0 -1
  15. package/ApplicationBuilderLegacy.d.ts +0 -4
  16. package/ApplicationBuilderLegacy.js +0 -91
  17. package/ApplicationBuilderLegacy.js.map +0 -1
  18. package/ApplicationConfig.d.ts +0 -17
  19. package/ApplicationConfig.js +0 -5
  20. package/ApplicationConfig.js.map +0 -1
  21. package/ApplicationHook.d.ts +0 -4
  22. package/ApplicationHook.js +0 -11
  23. package/ApplicationHook.js.map +0 -1
  24. package/PulumiApp.d.ts +0 -118
  25. package/PulumiApp.js +0 -216
  26. package/PulumiApp.js.map +0 -1
  27. package/PulumiAppModule.d.ts +0 -17
  28. package/PulumiAppModule.js +0 -30
  29. package/PulumiAppModule.js.map +0 -1
  30. package/PulumiResource.d.ts +0 -22
  31. package/PulumiResource.js +0 -48
  32. package/PulumiResource.js.map +0 -1
  33. package/utils/getPulumiWorkDir.d.ts +0 -1
  34. package/utils/getPulumiWorkDir.js +0 -14
  35. package/utils/getPulumiWorkDir.js.map +0 -1
  36. package/utils/getStackName.d.ts +0 -5
  37. package/utils/getStackName.js +0 -11
  38. package/utils/getStackName.js.map +0 -1
  39. package/utils/index.d.ts +0 -5
  40. package/utils/index.js +0 -70
  41. package/utils/index.js.map +0 -1
  42. package/utils/mergeAppHooks.d.ts +0 -2
  43. package/utils/mergeAppHooks.js +0 -20
  44. package/utils/mergeAppHooks.js.map +0 -1
  45. package/utils/stagedRollouts.d.ts +0 -15
  46. package/utils/stagedRollouts.js +0 -58
  47. package/utils/stagedRollouts.js.map +0 -1
  48. package/utils/tagResources.d.ts +0 -5
  49. package/utils/tagResources.js +0 -52
  50. package/utils/tagResources.js.map +0 -1
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ApplicationBuilderLegacy = void 0;
7
-
8
- var _ApplicationBuilder = require("./ApplicationBuilder");
9
-
10
- class ApplicationBuilderLegacy extends _ApplicationBuilder.ApplicationBuilder {
11
- async createOrSelectStack(args) {
12
- const PULUMI_SECRETS_PROVIDER = String(process.env["PULUMI_SECRETS_PROVIDER"]);
13
- const PULUMI_CONFIG_PASSPHRASE = String(process.env["PULUMI_CONFIG_PASSPHRASE"]);
14
- const DEBUG = args.debug ?? false;
15
- await args.pulumi.run({
16
- command: ["stack", "select", args.env],
17
- args: {
18
- create: true,
19
- secretsProvider: PULUMI_SECRETS_PROVIDER
20
- },
21
- execa: {
22
- env: {
23
- PULUMI_CONFIG_PASSPHRASE
24
- }
25
- }
26
- });
27
- return {
28
- refresh: async () => {
29
- await args.pulumi.run({
30
- command: "refresh",
31
- args: {
32
- debug: DEBUG
33
- },
34
- execa: {
35
- stdio: "inherit",
36
- env: {
37
- WEBINY_ENV: args.env,
38
- WEBINY_PROJECT_NAME: this.config.name,
39
- PULUMI_CONFIG_PASSPHRASE
40
- }
41
- }
42
- });
43
- return undefined;
44
- },
45
- preview: async () => {
46
- await args.pulumi.run({
47
- command: "preview",
48
- args: {
49
- debug: DEBUG // Preview command does not accept "--secrets-provider" argument.
50
- // secretsProvider: PULUMI_SECRETS_PROVIDER
51
-
52
- },
53
- execa: {
54
- stdio: "inherit",
55
- env: {
56
- WEBINY_ENV: args.env,
57
- WEBINY_PROJECT_NAME: this.config.name,
58
- PULUMI_CONFIG_PASSPHRASE
59
- }
60
- }
61
- });
62
- return undefined;
63
- },
64
- up: async () => {
65
- await args.pulumi.run({
66
- command: "up",
67
- args: {
68
- yes: true,
69
- skipPreview: true,
70
- secretsProvider: PULUMI_SECRETS_PROVIDER,
71
- debug: DEBUG
72
- },
73
- execa: {
74
- // We pipe "stderr" so that we can intercept potential received error messages,
75
- // and hopefully, show extra information / help to the user.
76
- stdio: ["inherit", "inherit", "pipe"],
77
- env: {
78
- WEBINY_ENV: args.env,
79
- WEBINY_PROJECT_NAME: this.config.name,
80
- PULUMI_CONFIG_PASSPHRASE
81
- }
82
- }
83
- });
84
- return undefined;
85
- }
86
- };
87
- }
88
-
89
- }
90
-
91
- exports.ApplicationBuilderLegacy = ApplicationBuilderLegacy;
@@ -1 +0,0 @@
1
- {"version":3,"names":["ApplicationBuilderLegacy","ApplicationBuilder","createOrSelectStack","args","PULUMI_SECRETS_PROVIDER","String","process","env","PULUMI_CONFIG_PASSPHRASE","DEBUG","debug","pulumi","run","command","create","secretsProvider","execa","refresh","stdio","WEBINY_ENV","WEBINY_PROJECT_NAME","config","name","undefined","preview","up","yes","skipPreview"],"sources":["ApplicationBuilderLegacy.ts"],"sourcesContent":["import { ApplicationBuilder, ApplicationStack, ApplicationStackArgs } from \"./ApplicationBuilder\";\n\nexport class ApplicationBuilderLegacy extends ApplicationBuilder {\n public async createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack> {\n const PULUMI_SECRETS_PROVIDER = String(process.env[\"PULUMI_SECRETS_PROVIDER\"]);\n const PULUMI_CONFIG_PASSPHRASE = String(process.env[\"PULUMI_CONFIG_PASSPHRASE\"]);\n const DEBUG = args.debug ?? false;\n\n await args.pulumi.run({\n command: [\"stack\", \"select\", args.env],\n args: {\n create: true,\n secretsProvider: PULUMI_SECRETS_PROVIDER\n },\n execa: {\n env: {\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return {\n refresh: async () => {\n await args.pulumi.run({\n command: \"refresh\",\n args: {\n debug: DEBUG\n },\n execa: {\n stdio: \"inherit\",\n env: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return undefined;\n },\n preview: async () => {\n await args.pulumi.run({\n command: \"preview\",\n args: {\n debug: DEBUG\n // Preview command does not accept \"--secrets-provider\" argument.\n // secretsProvider: PULUMI_SECRETS_PROVIDER\n },\n execa: {\n stdio: \"inherit\",\n env: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return undefined;\n },\n up: async () => {\n await args.pulumi.run({\n command: \"up\",\n args: {\n yes: true,\n skipPreview: true,\n secretsProvider: PULUMI_SECRETS_PROVIDER,\n debug: DEBUG\n },\n execa: {\n // We pipe \"stderr\" so that we can intercept potential received error messages,\n // and hopefully, show extra information / help to the user.\n stdio: [\"inherit\", \"inherit\", \"pipe\"],\n env: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n PULUMI_CONFIG_PASSPHRASE\n }\n }\n });\n\n return undefined;\n }\n };\n }\n}\n"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,wBAAN,SAAuCC,sCAAvC,CAA0D;EAC7B,MAAnBC,mBAAmB,CAACC,IAAD,EAAwD;IACpF,MAAMC,uBAAuB,GAAGC,MAAM,CAACC,OAAO,CAACC,GAAR,CAAY,yBAAZ,CAAD,CAAtC;IACA,MAAMC,wBAAwB,GAAGH,MAAM,CAACC,OAAO,CAACC,GAAR,CAAY,0BAAZ,CAAD,CAAvC;IACA,MAAME,KAAK,GAAGN,IAAI,CAACO,KAAL,IAAc,KAA5B;IAEA,MAAMP,IAAI,CAACQ,MAAL,CAAYC,GAAZ,CAAgB;MAClBC,OAAO,EAAE,CAAC,OAAD,EAAU,QAAV,EAAoBV,IAAI,CAACI,GAAzB,CADS;MAElBJ,IAAI,EAAE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J;YAIHX,GAAG,EAAE;cACDY,UAAU,EAAEhB,IAAI,CAACI,GADhB;cAEDa,mBAAmB,EAAE,KAAKC,MAAL,CAAYC,IAFhC;cAGDd;YAHC;UAJF;QARW,CAAhB,CAAN;QAoBA,OAAOe,SAAP;MACH;IA7DE,CAAP;EA+DH;;AAlF4D"}
@@ -1,17 +0,0 @@
1
- import { ApplicationHook } from "./ApplicationHook";
2
- import { PulumiApp } from "./PulumiApp";
3
- export interface ApplicationContext {
4
- env: string;
5
- variant?: string | null;
6
- appDir: string;
7
- projectDir: string;
8
- }
9
- export interface ApplicationHooks {
10
- onBeforeBuild: ApplicationHook;
11
- onAfterBuild: ApplicationHook;
12
- onBeforeDeploy: ApplicationHook;
13
- onAfterDeploy: ApplicationHook;
14
- }
15
- export interface ApplicationConfig<TApp extends PulumiApp> extends Partial<ApplicationHooks> {
16
- config?(app: TApp, ctx: ApplicationContext): Promise<void> | void;
17
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["ApplicationConfig.ts"],"sourcesContent":["import { ApplicationHook } from \"./ApplicationHook\";\nimport { PulumiApp } from \"./PulumiApp\";\n\nexport interface ApplicationContext {\n env: string;\n variant?: string | null;\n appDir: string;\n projectDir: string;\n}\n\nexport interface ApplicationHooks {\n // TODO add typing to deploy hooks\n onBeforeBuild: ApplicationHook;\n onAfterBuild: ApplicationHook;\n onBeforeDeploy: ApplicationHook;\n onAfterDeploy: ApplicationHook;\n}\n\nexport interface ApplicationConfig<TApp extends PulumiApp> extends Partial<ApplicationHooks> {\n config?(app: TApp, ctx: ApplicationContext): Promise<void> | void;\n}\n"],"mappings":""}
@@ -1,4 +0,0 @@
1
- export interface ApplicationHook {
2
- (params: any, context: any): Promise<void> | void;
3
- }
4
- export declare function defineAppHook(appHook: ApplicationHook): ApplicationHook;
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.defineAppHook = defineAppHook;
7
-
8
- // TODO add typing to deploy hooks
9
- function defineAppHook(appHook) {
10
- return appHook;
11
- }
@@ -1 +0,0 @@
1
- {"version":3,"names":["defineAppHook","appHook"],"sources":["ApplicationHook.ts"],"sourcesContent":["// TODO add typing to deploy hooks\nexport interface ApplicationHook {\n (params: any, context: any): Promise<void> | void;\n}\n\nexport function defineAppHook(appHook: ApplicationHook) {\n return appHook;\n}\n"],"mappings":";;;;;;;AAAA;AAKO,SAASA,aAAT,CAAuBC,OAAvB,EAAiD;EACpD,OAAOA,OAAP;AACH"}
package/PulumiApp.d.ts DELETED
@@ -1,118 +0,0 @@
1
- import * as pulumi from "@pulumi/pulumi";
2
- import { ApplicationContext } from "./ApplicationConfig";
3
- import { PulumiAppModuleDefinition } from "./PulumiAppModule";
4
- import { ResourceArgs, ResourceConstructor, ResourceType } from "./PulumiResource";
5
- export interface CreateResourceParams<TCtor extends ResourceConstructor> {
6
- name: string;
7
- config: ResourceArgs<TCtor>;
8
- opts?: pulumi.CustomResourceOptions;
9
- }
10
- export interface PulumiAppResource<T extends ResourceConstructor> {
11
- name: string;
12
- readonly config: ResourceConfigProxy<ResourceArgs<T>>;
13
- readonly opts: pulumi.CustomResourceOptions;
14
- readonly output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;
15
- }
16
- export interface PulumiAppParams {
17
- name: string;
18
- ctx: ApplicationContext;
19
- }
20
- export interface ResourceHandler {
21
- (resource: PulumiAppResource<ResourceConstructor>): void;
22
- }
23
- export declare type ResourceConfigProxy<T extends object> = {
24
- readonly [K in keyof T]-?: ResourceConfigSetter<T[K]>;
25
- };
26
- export interface ResourceConfigSetter<T> {
27
- (value: T): void;
28
- (fcn: ResourceConfigModifier<T>): void;
29
- }
30
- export interface ResourceConfigModifier<T> {
31
- (value: pulumi.Unwrap<T>): T | void;
32
- }
33
- interface DeployEventParams {
34
- outputs: Record<string, any>;
35
- }
36
- interface DeployEventHandler {
37
- (params: DeployEventParams): Promise<void> | void;
38
- }
39
- export declare abstract class PulumiApp<TConfig = unknown> {
40
- readonly name: string;
41
- readonly ctx: ApplicationContext;
42
- private readonly resourceHandlers;
43
- private readonly afterDeployHandlers;
44
- private readonly handlers;
45
- private readonly outputs;
46
- private readonly modules;
47
- constructor(params: PulumiAppParams);
48
- abstract setup(config: TConfig): Promise<void> | void;
49
- onResource(handler: ResourceHandler): void;
50
- onAfterDeploy(handler: DeployEventHandler): void;
51
- /**
52
- * Adds a resource to pulumi app.
53
- * It's not running the script immadietely, but enqueues the call.
54
- * This way we are still able to modify the config of the resource.
55
- * @param ctor Resource to be added, ie aws.s3.Bucket
56
- * @param params Parameters to configure the resource
57
- * @returns Object giving access to both resource outputs and its config.
58
- */
59
- addResource<T extends ResourceConstructor>(ctor: T, params: CreateResourceParams<T>): PulumiAppResource<T>;
60
- /**
61
- * Registers output value within pulumi app.
62
- * @param name Name of the output value
63
- * @param output Value of the output
64
- */
65
- addOutput<T>(name: string, output: T): void;
66
- /**
67
- * Registers one or more output values.
68
- * @param outputs Dictionary containg output values.
69
- */
70
- addOutputs(outputs: Record<string, unknown>): void;
71
- /**
72
- * Registers an app module witin app.
73
- * Allows to decompose application into smaller pieces.
74
- * Added module can be then retrieved with `getModule`.
75
- * @param def Module definition
76
- */
77
- addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;
78
- /**
79
- * Registers an app module witin app.
80
- * Allows to decompose application into smaller pieces.
81
- * Added module can be then retrieved with `getModule`.
82
- * @param def Module definition
83
- * @param config Module config
84
- */
85
- addModule<TModule, TConfig>(def: PulumiAppModuleDefinition<TModule, TConfig>, config: TConfig): TModule;
86
- /**
87
- * Schedules a handler to be executed when running pulumi script.
88
- * Anything, that is returned from handler will be wrapped in pulumi.Output
89
- * so it can be used in other places.
90
- * @param handler Handler to be executed.
91
- * @returns Result of the handler wrapped with pulumi.Output
92
- */
93
- addHandler<T>(handler: () => Promise<T> | T): pulumi.Output<pulumi.Unwrap<T>>;
94
- /**
95
- * Returns a module by its definition
96
- * @param def Module definition
97
- */
98
- getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;
99
- getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
100
- optional: false;
101
- }): TModule;
102
- getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
103
- optional: true;
104
- }): TModule | null;
105
- /** Internal usage only. */
106
- createController(): {
107
- run: () => Promise<Record<string, any>>;
108
- deployFinished: (params: DeployEventParams) => Promise<void>;
109
- };
110
- private runProgram;
111
- private deployFinished;
112
- }
113
- export interface CreateAppParams<TOutput extends Record<string, unknown>, TConfig = void> {
114
- name: string;
115
- config(app: PulumiApp, config: TConfig): TOutput | Promise<TOutput>;
116
- }
117
- export declare function defineApp<TOutput extends Record<string, unknown>, TConfig = void>(params: CreateAppParams<TOutput, TConfig>): new (ctx: ApplicationContext) => PulumiApp<TConfig> & TOutput;
118
- export {};
package/PulumiApp.js DELETED
@@ -1,216 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.PulumiApp = void 0;
9
- exports.defineApp = defineApp;
10
-
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
-
13
- var pulumi = _interopRequireWildcard(require("@pulumi/pulumi"));
14
-
15
- var _utils = require("./utils");
16
-
17
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
-
19
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
-
21
- class PulumiApp {
22
- constructor(params) {
23
- (0, _defineProperty2.default)(this, "name", void 0);
24
- (0, _defineProperty2.default)(this, "ctx", void 0);
25
- (0, _defineProperty2.default)(this, "resourceHandlers", []);
26
- (0, _defineProperty2.default)(this, "afterDeployHandlers", []);
27
- (0, _defineProperty2.default)(this, "handlers", []);
28
- (0, _defineProperty2.default)(this, "outputs", {});
29
- (0, _defineProperty2.default)(this, "modules", new Map());
30
- this.name = params.name;
31
- this.ctx = params.ctx;
32
- }
33
-
34
- onResource(handler) {
35
- this.resourceHandlers.push(handler);
36
- }
37
-
38
- onAfterDeploy(handler) {
39
- this.afterDeployHandlers.push(handler);
40
- }
41
- /**
42
- * Adds a resource to pulumi app.
43
- * It's not running the script immadietely, but enqueues the call.
44
- * This way we are still able to modify the config of the resource.
45
- * @param ctor Resource to be added, ie aws.s3.Bucket
46
- * @param params Parameters to configure the resource
47
- * @returns Object giving access to both resource outputs and its config.
48
- */
49
-
50
-
51
- addResource(ctor, params) {
52
- const config = params.config ?? {};
53
- const opts = params.opts ?? {};
54
- const promise = new Promise(resolve => {
55
- this.handlers.push(() => {
56
- this.resourceHandlers.forEach(handler => handler(resourceInstance));
57
- const resourceInstance = new ctor(resource.name, config, opts);
58
- resolve(resourceInstance);
59
- });
60
- });
61
- const resource = {
62
- name: params.name,
63
- config: createConfigProxy(config),
64
- opts,
65
- output: pulumi.output(promise)
66
- };
67
- return resource;
68
- }
69
- /**
70
- * Registers output value within pulumi app.
71
- * @param name Name of the output value
72
- * @param output Value of the output
73
- */
74
-
75
-
76
- addOutput(name, output) {
77
- this.outputs[name] = output;
78
- }
79
- /**
80
- * Registers one or more output values.
81
- * @param outputs Dictionary containg output values.
82
- */
83
-
84
-
85
- addOutputs(outputs) {
86
- Object.assign(this.outputs, outputs);
87
- }
88
- /**
89
- * Registers an app module witin app.
90
- * Allows to decompose application into smaller pieces.
91
- * Added module can be then retrieved with `getModule`.
92
- * @param def Module definition
93
- */
94
-
95
-
96
- addModule(def, config) {
97
- if (this.modules.has(def.symbol)) {
98
- throw new Error(`Module "${def.name}" is already present in the "${this.name}" application.`);
99
- }
100
-
101
- const module = def.run(this, config);
102
- this.modules.set(def.symbol, module);
103
- return module;
104
- }
105
- /**
106
- * Schedules a handler to be executed when running pulumi script.
107
- * Anything, that is returned from handler will be wrapped in pulumi.Output
108
- * so it can be used in other places.
109
- * @param handler Handler to be executed.
110
- * @returns Result of the handler wrapped with pulumi.Output
111
- */
112
-
113
-
114
- addHandler(handler) {
115
- const promise = new Promise(resolve => {
116
- this.handlers.push(async () => {
117
- resolve(await handler());
118
- });
119
- });
120
- return pulumi.output(promise);
121
- }
122
- /**
123
- * Returns a module by its definition
124
- * @param def Module definition
125
- */
126
-
127
-
128
- getModule(def, opts) {
129
- const module = this.modules.get(def.symbol);
130
-
131
- if (!module) {
132
- if (opts !== null && opts !== void 0 && opts.optional) {
133
- return null;
134
- } else {
135
- throw new Error(`Module "${def.name}" not found in "${this.name}" app`);
136
- }
137
- }
138
-
139
- return module;
140
- }
141
- /** Internal usage only. */
142
-
143
-
144
- createController() {
145
- return {
146
- run: this.runProgram.bind(this),
147
- deployFinished: this.deployFinished.bind(this)
148
- };
149
- }
150
-
151
- async runProgram() {
152
- (0, _utils.tagResources)({
153
- WbyProjectName: String(process.env["WEBINY_PROJECT_NAME"]),
154
- WbyEnvironment: String(process.env["WEBINY_ENV"])
155
- });
156
-
157
- for (const handler of this.handlers) {
158
- await handler();
159
- }
160
-
161
- return this.outputs;
162
- }
163
-
164
- async deployFinished(params) {
165
- for (const handler of this.afterDeployHandlers) {
166
- await handler(params);
167
- }
168
- }
169
-
170
- }
171
-
172
- exports.PulumiApp = PulumiApp;
173
-
174
- function defineApp(params) {
175
- const appDef = class App extends PulumiApp {
176
- constructor(ctx) {
177
- super({
178
- name: params.name,
179
- ctx: ctx
180
- });
181
- }
182
-
183
- async setup(config) {
184
- const output = await params.config(this, config);
185
- Object.assign(this, output);
186
- }
187
-
188
- };
189
- return appDef;
190
- }
191
-
192
- function createConfigProxy(obj) {
193
- return new Proxy(obj, {
194
- get(target, p) {
195
- const key = p;
196
-
197
- const setter = value => {
198
- if (typeof value === "function") {
199
- const modifier = value;
200
- const currentValue = target[key]; // Wrap a current config with a function.
201
-
202
- const newValue = pulumi.output(currentValue).apply(v => {
203
- const newValue = modifier(v);
204
- return pulumi.output(newValue);
205
- });
206
- target[key] = newValue;
207
- } else {
208
- target[key] = value;
209
- }
210
- };
211
-
212
- return setter;
213
- }
214
-
215
- });
216
- }
package/PulumiApp.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["PulumiApp","constructor","params","Map","name","ctx","onResource","handler","resourceHandlers","push","onAfterDeploy","afterDeployHandlers","addResource","ctor","config","opts","promise","Promise","resolve","handlers","forEach","resourceInstance","resource","createConfigProxy","output","pulumi","addOutput","outputs","addOutputs","Object","assign","addModule","def","modules","has","symbol","Error","module","run","set","addHandler","getModule","get","optional","createController","runProgram","bind","deployFinished","tagResources","WbyProjectName","String","process","env","WbyEnvironment","defineApp","appDef","App","setup","obj","Proxy","target","p","key","setter","value","modifier","currentValue","newValue","apply","v"],"sources":["PulumiApp.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\nimport { ApplicationContext } from \"./ApplicationConfig\";\nimport { PulumiAppModuleDefinition } from \"./PulumiAppModule\";\nimport { ResourceArgs, ResourceConstructor, ResourceType } from \"./PulumiResource\";\nimport { tagResources } from \"./utils\";\n\nexport interface CreateResourceParams<TCtor extends ResourceConstructor> {\n name: string;\n config: ResourceArgs<TCtor>;\n opts?: pulumi.CustomResourceOptions;\n}\n\nexport interface PulumiAppResource<T extends ResourceConstructor> {\n name: string;\n readonly config: ResourceConfigProxy<ResourceArgs<T>>;\n readonly opts: pulumi.CustomResourceOptions;\n readonly output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;\n}\n\nexport interface PulumiAppParams {\n name: string;\n ctx: ApplicationContext;\n}\n\nexport interface ResourceHandler {\n (resource: PulumiAppResource<ResourceConstructor>): void;\n}\n\nexport type ResourceConfigProxy<T extends object> = {\n readonly [K in keyof T]-?: ResourceConfigSetter<T[K]>;\n};\n\nexport interface ResourceConfigSetter<T> {\n (value: T): void;\n (fcn: ResourceConfigModifier<T>): void;\n}\n\nexport interface ResourceConfigModifier<T> {\n (value: pulumi.Unwrap<T>): T | void;\n}\n\ninterface DeployEventParams {\n outputs: Record<string, any>;\n}\n\ninterface DeployEventHandler {\n (params: DeployEventParams): Promise<void> | void;\n}\n\nexport abstract class PulumiApp<TConfig = unknown> {\n public readonly name: string;\n public readonly ctx: ApplicationContext;\n private readonly resourceHandlers: ResourceHandler[] = [];\n private readonly afterDeployHandlers: DeployEventHandler[] = [];\n private readonly handlers: (() => void | Promise<void>)[] = [];\n private readonly outputs: Record<string, any> = {};\n private readonly modules = new Map<symbol, unknown>();\n\n constructor(params: PulumiAppParams) {\n this.name = params.name;\n this.ctx = params.ctx;\n }\n\n public abstract setup(config: TConfig): Promise<void> | void;\n\n public onResource(handler: ResourceHandler): void {\n this.resourceHandlers.push(handler);\n }\n\n public onAfterDeploy(handler: DeployEventHandler) {\n this.afterDeployHandlers.push(handler);\n }\n\n /**\n * Adds a resource to pulumi app.\n * It's not running the script immadietely, but enqueues the call.\n * This way we are still able to modify the config of the resource.\n * @param ctor Resource to be added, ie aws.s3.Bucket\n * @param params Parameters to configure the resource\n * @returns Object giving access to both resource outputs and its config.\n */\n public addResource<T extends ResourceConstructor>(ctor: T, params: CreateResourceParams<T>) {\n const config = params.config ?? ({} as ResourceArgs<T>);\n const opts = params.opts ?? {};\n\n const promise = new Promise<ResourceType<T>>(resolve => {\n this.handlers.push(() => {\n this.resourceHandlers.forEach(handler => handler(resourceInstance));\n const resourceInstance = new ctor(resource.name, config, opts);\n resolve(resourceInstance);\n });\n });\n\n const resource: PulumiAppResource<T> = {\n name: params.name,\n config: createConfigProxy(config),\n opts,\n output: pulumi.output(promise)\n };\n\n return resource;\n }\n\n /**\n * Registers output value within pulumi app.\n * @param name Name of the output value\n * @param output Value of the output\n */\n public addOutput<T>(name: string, output: T) {\n this.outputs[name] = output;\n }\n\n /**\n * Registers one or more output values.\n * @param outputs Dictionary containg output values.\n */\n public addOutputs(outputs: Record<string, unknown>) {\n Object.assign(this.outputs, outputs);\n }\n\n /**\n * Registers an app module witin app.\n * Allows to decompose application into smaller pieces.\n * Added module can be then retrieved with `getModule`.\n * @param def Module definition\n */\n public addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;\n\n /**\n * Registers an app module witin app.\n * Allows to decompose application into smaller pieces.\n * Added module can be then retrieved with `getModule`.\n * @param def Module definition\n * @param config Module config\n */\n public addModule<TModule, TConfig>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n config: TConfig\n ): TModule;\n public addModule<TModule, TConfig>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n config?: TConfig\n ) {\n if (this.modules.has(def.symbol)) {\n throw new Error(\n `Module \"${def.name}\" is already present in the \"${this.name}\" application.`\n );\n }\n\n const module = def.run(this, config as TConfig);\n this.modules.set(def.symbol, module);\n\n return module;\n }\n\n /**\n * Schedules a handler to be executed when running pulumi script.\n * Anything, that is returned from handler will be wrapped in pulumi.Output\n * so it can be used in other places.\n * @param handler Handler to be executed.\n * @returns Result of the handler wrapped with pulumi.Output\n */\n public addHandler<T>(handler: () => Promise<T> | T) {\n const promise = new Promise<T>(resolve => {\n this.handlers.push(async () => {\n resolve(await handler());\n });\n });\n\n return pulumi.output(promise);\n }\n\n /**\n * Returns a module by its definition\n * @param def Module definition\n */\n public getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: false }\n ): TModule;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: true }\n ): TModule | null;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts?: { optional: boolean }\n ) {\n const module = this.modules.get(def.symbol);\n\n if (!module) {\n if (opts?.optional) {\n return null;\n } else {\n throw new Error(`Module \"${def.name}\" not found in \"${this.name}\" app`);\n }\n }\n\n return module;\n }\n\n /** Internal usage only. */\n public createController() {\n return {\n run: this.runProgram.bind(this),\n deployFinished: this.deployFinished.bind(this)\n };\n }\n\n private async runProgram() {\n tagResources({\n WbyProjectName: String(process.env[\"WEBINY_PROJECT_NAME\"]),\n WbyEnvironment: String(process.env[\"WEBINY_ENV\"])\n });\n\n for (const handler of this.handlers) {\n await handler();\n }\n\n return this.outputs;\n }\n\n private async deployFinished(params: DeployEventParams) {\n for (const handler of this.afterDeployHandlers) {\n await handler(params);\n }\n }\n}\n\nexport interface CreateAppParams<TOutput extends Record<string, unknown>, TConfig = void> {\n name: string;\n config(app: PulumiApp, config: TConfig): TOutput | Promise<TOutput>;\n}\n\nexport function defineApp<TOutput extends Record<string, unknown>, TConfig = void>(\n params: CreateAppParams<TOutput, TConfig>\n) {\n const appDef = class App extends PulumiApp<TConfig> {\n constructor(ctx: ApplicationContext) {\n super({ name: params.name, ctx: ctx });\n }\n\n public async setup(config: TConfig) {\n const output = await params.config(this, config);\n Object.assign(this, output);\n }\n };\n\n return appDef as new (ctx: ApplicationContext) => PulumiApp<TConfig> & TOutput;\n}\n\nfunction createConfigProxy<T extends object>(obj: T) {\n return new Proxy(obj, {\n get(target, p: string) {\n type V = T[keyof T];\n const key = p as keyof T;\n const setter: ResourceConfigSetter<V> = (value: V | ResourceConfigModifier<V>) => {\n if (typeof value === \"function\") {\n const modifier = value as ResourceConfigModifier<V>;\n const currentValue = target[key];\n // Wrap a current config with a function.\n const newValue = pulumi.output(currentValue).apply(v => {\n const newValue = modifier(v);\n return pulumi.output(newValue);\n });\n\n target[key] = newValue as unknown as V;\n } else {\n target[key] = value;\n }\n };\n\n return setter;\n }\n }) as ResourceConfigProxy<T>;\n}\n"],"mappings":";;;;;;;;;;;;AAAA;;AAKA;;;;;;AA6CO,MAAeA,SAAf,CAA4C;EAS/CC,WAAW,CAACC,MAAD,EAA0B;IAAA;IAAA;IAAA,wDANkB,EAMlB;IAAA,2DALwB,EAKxB;IAAA,gDAJuB,EAIvB;IAAA,+CAHW,EAGX;IAAA,+CAFV,IAAIC,GAAJ,EAEU;IACjC,KAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;IACA,KAAKC,GAAL,GAAWH,MAAM,CAACG,GAAlB;EACH;;EAIMC,UAAU,CAACC,OAAD,EAAiC;IAC9C,KAAKC,gBAAL,CAAsBC,IAAtB,CAA2BF,OAA3B;EACH;;EAEMG,aAAa,CAACH,OAAD,EAA8B;IAC9C,KAAKI,mBAAL,CAAyBF,IAAzB,CAA8BF,OAA9B;EACH;EAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;;;EACWK,WAAW,CAAgCC,IAAhC,EAAyCX,MAAzC,EAA0E;IACxF,MAAMY,MAAM,GAAGZ,MAAM,CAACY,MAAP,IAAkB,EAAjC;IACA,MAAMC,IAAI,GAAGb,MAAM,CAACa,IAAP,IAAe,EAA5B;IAEA,MAAMC,OAAO,GAAG,IAAIC,OAAJ,CAA6BC,OAAO,IAAI;MACpD,KAAKC,QAAL,CAAcV,IAAd,CAAmB,MAAM;QACrB,KAAKD,gBAAL,CAAsBY,OAAtB,CAA8Bb,OAAO,IAAIA,OAAO,CAACc,gBAAD,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@@ -1,17 +0,0 @@
1
- declare type PulumiApp = import("./PulumiApp").PulumiApp;
2
- export interface PulumiAppModuleCallback<TModule, TConfig> {
3
- (this: void, app: PulumiApp, config: TConfig): TModule;
4
- }
5
- export interface PulumiAppModuleParams<TModule, TConfig> {
6
- name: string;
7
- config: PulumiAppModuleCallback<TModule, TConfig>;
8
- }
9
- export declare type PulumiAppModule<T extends PulumiAppModuleDefinition<any, any>> = T extends PulumiAppModuleDefinition<infer V, any> ? V : never;
10
- export declare class PulumiAppModuleDefinition<TModule, TConfig> {
11
- readonly symbol: symbol;
12
- readonly name: string;
13
- readonly run: PulumiAppModuleCallback<TModule, TConfig>;
14
- constructor(params: PulumiAppModuleParams<TModule, TConfig>);
15
- }
16
- export declare function defineAppModule<TModule, TConfig = void>(params: PulumiAppModuleParams<TModule, TConfig>): PulumiAppModuleDefinition<TModule, TConfig>;
17
- export {};
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.PulumiAppModuleDefinition = void 0;
9
- exports.defineAppModule = defineAppModule;
10
-
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
-
13
- // There is a circular dependency between the two.
14
- // This trick allow us to make it work.
15
- class PulumiAppModuleDefinition {
16
- constructor(params) {
17
- (0, _defineProperty2.default)(this, "symbol", Symbol());
18
- (0, _defineProperty2.default)(this, "name", void 0);
19
- (0, _defineProperty2.default)(this, "run", void 0);
20
- this.name = params.name;
21
- this.run = params.config;
22
- }
23
-
24
- }
25
-
26
- exports.PulumiAppModuleDefinition = PulumiAppModuleDefinition;
27
-
28
- function defineAppModule(params) {
29
- return new PulumiAppModuleDefinition(params);
30
- }
@@ -1 +0,0 @@
1
- {"version":3,"names":["PulumiAppModuleDefinition","constructor","params","Symbol","name","run","config","defineAppModule"],"sources":["PulumiAppModule.ts"],"sourcesContent":["// There is a circular dependency between the two.\n// This trick allow us to make it work.\ntype PulumiApp = import(\"./PulumiApp\").PulumiApp;\n\nexport interface PulumiAppModuleCallback<TModule, TConfig> {\n (this: void, app: PulumiApp, config: TConfig): TModule;\n}\n\nexport interface PulumiAppModuleParams<TModule, TConfig> {\n name: string;\n config: PulumiAppModuleCallback<TModule, TConfig>;\n}\n\nexport type PulumiAppModule<T extends PulumiAppModuleDefinition<any, any>> =\n T extends PulumiAppModuleDefinition<infer V, any> ? V : never;\n\nexport class PulumiAppModuleDefinition<TModule, TConfig> {\n public readonly symbol = Symbol();\n public readonly name: string;\n public readonly run: PulumiAppModuleCallback<TModule, TConfig>;\n constructor(params: PulumiAppModuleParams<TModule, TConfig>) {\n this.name = params.name;\n this.run = params.config;\n }\n}\n\nexport function defineAppModule<TModule, TConfig = void>(\n params: PulumiAppModuleParams<TModule, TConfig>\n) {\n return new PulumiAppModuleDefinition(params);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AACA;AAeO,MAAMA,yBAAN,CAAkD;EAIrDC,WAAW,CAACC,MAAD,EAAkD;IAAA,8CAHpCC,MAAM,EAG8B;IAAA;IAAA;IACzD,KAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;IACA,KAAKC,GAAL,GAAWH,MAAM,CAACI,MAAlB;EACH;;AAPoD;;;;AAUlD,SAASC,eAAT,CACHL,MADG,EAEL;EACE,OAAO,IAAIF,yBAAJ,CAA8BE,MAA9B,CAAP;AACH"}
@@ -1,22 +0,0 @@
1
- import * as pulumi from "@pulumi/pulumi";
2
- export interface ResourceConstructor<T = any, TArgs = any> {
3
- new (name: string, args: TArgs, opts?: pulumi.CustomResourceOptions): T;
4
- }
5
- export declare type ResourceType<T extends ResourceConstructor> = T extends ResourceConstructor<infer TType> ? TType : never;
6
- export declare type ResourceArgs<T extends ResourceConstructor> = T extends ResourceConstructor<any, infer TArgs> ? Exclude<TArgs, undefined> : never;
7
- export interface ResourceOverride<TCtor extends ResourceConstructor> {
8
- (args: ResourceArgs<TCtor>): void;
9
- }
10
- export interface PulumiResourceParams<T extends ResourceConstructor> {
11
- name: string;
12
- config: ResourceArgs<T>;
13
- opts?: pulumi.CustomResourceOptions;
14
- output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;
15
- }
16
- export declare class PulumiResource<T extends ResourceConstructor> {
17
- readonly output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;
18
- config: ResourceArgs<T>;
19
- opts: pulumi.CustomResourceOptions;
20
- readonly create: () => void;
21
- constructor(ctor: T, params: PulumiResourceParams<T>);
22
- }
package/PulumiResource.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.PulumiResource = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var pulumi = _interopRequireWildcard(require("@pulumi/pulumi"));
13
-
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- class PulumiResource {
19
- constructor(ctor, params) {
20
- (0, _defineProperty2.default)(this, "output", void 0);
21
- (0, _defineProperty2.default)(this, "config", void 0);
22
- (0, _defineProperty2.default)(this, "opts", void 0);
23
- (0, _defineProperty2.default)(this, "create", void 0);
24
- this.config = params.config;
25
- this.opts = params.opts ?? {};
26
- let resolve;
27
- let created = false;
28
-
29
- this.create = () => {
30
- if (created) {
31
- // prevent double initialization
32
- return;
33
- }
34
-
35
- const resource = new ctor(params.name, this.config, this.opts);
36
- resolve(resource);
37
- created = false;
38
- };
39
-
40
- const promise = new Promise(r => {
41
- resolve = r;
42
- });
43
- this.output = pulumi.output(promise);
44
- }
45
-
46
- }
47
-
48
- exports.PulumiResource = PulumiResource;
@@ -1 +0,0 @@
1
- {"version":3,"names":["PulumiResource","constructor","ctor","params","config","opts","resolve","created","create","resource","name","promise","Promise","r","output","pulumi"],"sources":["PulumiResource.ts"],"sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\nexport interface ResourceConstructor<T = any, TArgs = any> {\n new (name: string, args: TArgs, opts?: pulumi.CustomResourceOptions): T;\n}\n\nexport type ResourceType<T extends ResourceConstructor> = T extends ResourceConstructor<infer TType>\n ? TType\n : never;\n\nexport type ResourceArgs<T extends ResourceConstructor> = T extends ResourceConstructor<\n any,\n infer TArgs\n>\n ? Exclude<TArgs, undefined>\n : never;\n\nexport interface ResourceOverride<TCtor extends ResourceConstructor> {\n (args: ResourceArgs<TCtor>): void;\n}\n\nexport interface PulumiResourceParams<T extends ResourceConstructor> {\n name: string;\n config: ResourceArgs<T>;\n opts?: pulumi.CustomResourceOptions;\n output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;\n}\n\nexport class PulumiResource<T extends ResourceConstructor> {\n public readonly output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;\n public config: ResourceArgs<T>;\n public opts: pulumi.CustomResourceOptions;\n\n public readonly create: () => void;\n\n constructor(ctor: T, params: PulumiResourceParams<T>) {\n this.config = params.config;\n this.opts = params.opts ?? {};\n\n let resolve: (res: ResourceType<T>) => void;\n let created = false;\n\n this.create = () => {\n if (created) {\n // prevent double initialization\n return;\n }\n\n const resource = new ctor(params.name, this.config, this.opts);\n resolve(resource);\n created = false;\n };\n\n const promise = new Promise<ResourceType<T>>(r => {\n resolve = r;\n });\n\n this.output = pulumi.output(promise);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;;;;;AA4BO,MAAMA,cAAN,CAAoD;EAOvDC,WAAW,CAACC,IAAD,EAAUC,MAAV,EAA2C;IAAA;IAAA;IAAA;IAAA;IAClD,KAAKC,MAAL,GAAcD,MAAM,CAACC,MAArB;IACA,KAAKC,IAAL,GAAYF,MAAM,CAACE,IAAP,IAAe,EAA3B;IAEA,IAAIC,OAAJ;IACA,IAAIC,OAAO,GAAG,KAAd;;IAEA,KAAKC,MAAL,GAAc,MAAM;MAChB,IAAID,OAAJ,EAAa;QACT;QACA;MACH;;MAED,MAAME,QAAQ,GAAG,IAAIP,IAAJ,CAASC,MAAM,CAACO,IAAhB,EAAsB,KAAKN,MAA3B,EAAmC,KAAKC,IAAxC,CAAjB;MACAC,OAAO,CAACG,QAAD,CAAP;MACAF,OAAO,GAAG,KAAV;IACH,CATD;;IAWA,MAAMI,OAAO,GAAG,IAAIC,OAAJ,CAA6BC,CAAC,IAAI;MAC9CP,OAAO,GAAGO,CAAV;IACH,CAFe,CAAhB;IAIA,KAAKC,MAAL,GAAcC,MAAM,CAACD,MAAP,CAAcH,OAAd,CAAd;EACH;;AA9BsD"}
@@ -1 +0,0 @@
1
- export declare function getPulumiWorkDir(rootDir: string, appPath: string): string;