@webiny/project 0.0.0-unstable.7be00a75a9 → 0.0.0-unstable.9f53ea597d
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/ProjectSdk.d.ts +1 -0
- package/ProjectSdk.js +4 -1
- package/ProjectSdk.js.map +1 -1
- package/abstractions/features/DestroyApp.d.ts +2 -2
- package/abstractions/features/DestroyApp.js.map +1 -1
- package/abstractions/services/GetProjectInstallationIdService.d.ts +10 -0
- package/abstractions/services/GetProjectInstallationIdService.js +5 -0
- package/abstractions/services/GetProjectInstallationIdService.js.map +1 -0
- package/abstractions/services/StackOutputCacheService.d.ts +10 -0
- package/abstractions/services/StackOutputCacheService.js +5 -0
- package/abstractions/services/StackOutputCacheService.js.map +1 -0
- package/abstractions/services/index.d.ts +2 -0
- package/abstractions/services/index.js +2 -0
- package/createProjectSdkContainer.js +3 -1
- package/createProjectSdkContainer.js.map +1 -1
- package/decorators/DestroyAppClearStackOutputCache.d.ts +25 -0
- package/decorators/DestroyAppClearStackOutputCache.js +29 -0
- package/decorators/DestroyAppClearStackOutputCache.js.map +1 -0
- package/decorators/GetFeatureFlagsWithLicense.js +1 -0
- package/decorators/GetFeatureFlagsWithLicense.js.map +1 -1
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +1 -0
- package/extensions/FeatureFlags.d.ts +7 -0
- package/extensions/FeatureFlags.js +10 -3
- package/extensions/FeatureFlags.js.map +1 -1
- package/extensions/Project/SetAdminAppEnvVarsBeforeBuild.d.ts +3 -2
- package/extensions/Project/SetAdminAppEnvVarsBeforeBuild.js +8 -2
- package/extensions/Project/SetAdminAppEnvVarsBeforeBuild.js.map +1 -1
- package/extensions/Project/SetAdminAppEnvVarsBeforeWatch.d.ts +3 -2
- package/extensions/Project/SetAdminAppEnvVarsBeforeWatch.js +8 -2
- package/extensions/Project/SetAdminAppEnvVarsBeforeWatch.js.map +1 -1
- package/extensions/Project/ValidateProductionPulumiState.d.ts +3 -2
- package/extensions/Project/ValidateProductionPulumiState.js +6 -7
- package/extensions/Project/ValidateProductionPulumiState.js.map +1 -1
- package/extensions/index.d.ts +24 -17
- package/package.json +17 -17
- package/services/GetProjectConfigService/renderConfigWorker.js +8 -2
- package/services/GetProjectConfigService/renderConfigWorker.js.map +1 -1
- package/services/GetProjectInstallationIdService/GetProjectInstallationIdService.d.ts +10 -0
- package/services/GetProjectInstallationIdService/GetProjectInstallationIdService.js +34 -0
- package/services/GetProjectInstallationIdService/GetProjectInstallationIdService.js.map +1 -0
- package/services/GetProjectInstallationIdService/index.d.ts +1 -0
- package/services/GetProjectInstallationIdService/index.js +1 -0
- package/services/InitProjectSdkService/InitProjectSdkService.js +2 -1
- package/services/InitProjectSdkService/InitProjectSdkService.js.map +1 -1
- package/services/IsRemotePulumiBackendService/IsRemotePulumiBackendService.d.ts +3 -2
- package/services/IsRemotePulumiBackendService/IsRemotePulumiBackendService.js +1 -1
- package/services/IsRemotePulumiBackendService/IsRemotePulumiBackendService.js.map +1 -1
- package/services/LoggerService/LoggerService.js +3 -3
- package/services/PulumiGetStackOutputService/PulumiGetStackOutputService.d.ts +3 -11
- package/services/PulumiGetStackOutputService/PulumiGetStackOutputService.js +7 -64
- package/services/PulumiGetStackOutputService/PulumiGetStackOutputService.js.map +1 -1
- package/services/PulumiLoginService/PulumiLoginService.js +1 -1
- package/services/PulumiLoginService/PulumiLoginService.js.map +1 -1
- package/services/StackOutputCacheService/StackOutputCacheService.d.ts +18 -0
- package/services/StackOutputCacheService/StackOutputCacheService.js +89 -0
- package/services/StackOutputCacheService/StackOutputCacheService.js.map +1 -0
- package/services/StackOutputCacheService/index.d.ts +1 -0
- package/services/StackOutputCacheService/index.js +1 -0
- package/services/index.d.ts +2 -0
- package/services/index.js +2 -0
|
@@ -1,36 +1,18 @@
|
|
|
1
1
|
import { createImplementation } from "@webiny/di";
|
|
2
|
-
import {
|
|
2
|
+
import { GetPulumiService, LoggerService, PulumiGetStackOutputService, PulumiSelectStackService, StackOutputCacheService } from "../../abstractions/index.js";
|
|
3
3
|
import { createEnvConfiguration, withPulumiConfigPassphrase } from "../../utils/env/index.js";
|
|
4
4
|
import { mapStackOutput } from "./mapStackOutput.js";
|
|
5
|
-
import promises from "fs/promises";
|
|
6
|
-
import path from "path";
|
|
7
5
|
class DefaultPulumiGetStackOutputService {
|
|
8
|
-
|
|
9
|
-
this.DEFAULT_ENV = "dev";
|
|
10
|
-
}
|
|
11
|
-
static{
|
|
12
|
-
this.DEFAULT_REGION = "default";
|
|
13
|
-
}
|
|
14
|
-
static{
|
|
15
|
-
this.DEFAULT_VARIANT = "default";
|
|
16
|
-
}
|
|
17
|
-
constructor(getPulumiService, pulumiSelectStackService, loggerService, getProjectService, projectSdkParamsService){
|
|
6
|
+
constructor(getPulumiService, pulumiSelectStackService, loggerService, stackOutputCacheService){
|
|
18
7
|
this.getPulumiService = getPulumiService;
|
|
19
8
|
this.pulumiSelectStackService = pulumiSelectStackService;
|
|
20
9
|
this.loggerService = loggerService;
|
|
21
|
-
this.
|
|
22
|
-
this.projectSdkParamsService = projectSdkParamsService;
|
|
10
|
+
this.stackOutputCacheService = stackOutputCacheService;
|
|
23
11
|
}
|
|
24
12
|
async execute(app, params) {
|
|
25
13
|
if (!params?.skipCache) {
|
|
26
|
-
const cachedOutput = await this.
|
|
27
|
-
if (null !== cachedOutput)
|
|
28
|
-
this.loggerService.debug({
|
|
29
|
-
app: app.name,
|
|
30
|
-
cacheKey: this.getCacheKey(app)
|
|
31
|
-
}, "Stack output read from cache");
|
|
32
|
-
return this.applyMapping(cachedOutput, params?.map);
|
|
33
|
-
}
|
|
14
|
+
const cachedOutput = await this.stackOutputCacheService.read(app);
|
|
15
|
+
if (null !== cachedOutput) return this.applyMapping(cachedOutput, params?.map);
|
|
34
16
|
}
|
|
35
17
|
const pulumi = await this.getPulumiService.execute({
|
|
36
18
|
app
|
|
@@ -55,11 +37,7 @@ class DefaultPulumiGetStackOutputService {
|
|
|
55
37
|
try {
|
|
56
38
|
const stackOutputJson = JSON.parse(stackOutputString.stdout);
|
|
57
39
|
if (!stackOutputJson) return null;
|
|
58
|
-
await this.
|
|
59
|
-
this.loggerService.debug("Stack output stored to cache", {
|
|
60
|
-
app: app.name,
|
|
61
|
-
cacheKey: this.getCacheKey(app)
|
|
62
|
-
});
|
|
40
|
+
await this.stackOutputCacheService.write(app, stackOutputJson);
|
|
63
41
|
return this.applyMapping(stackOutputJson, params?.map);
|
|
64
42
|
} catch {
|
|
65
43
|
this.loggerService.error("Could not parse stack output as JSON.", stackOutputString.stdout, app, params);
|
|
@@ -70,40 +48,6 @@ class DefaultPulumiGetStackOutputService {
|
|
|
70
48
|
if (!map) return data;
|
|
71
49
|
return mapStackOutput(data, map);
|
|
72
50
|
}
|
|
73
|
-
getCacheKey(app) {
|
|
74
|
-
const sdkParams = this.projectSdkParamsService.get();
|
|
75
|
-
const env = sdkParams.env || DefaultPulumiGetStackOutputService.DEFAULT_ENV;
|
|
76
|
-
const region = sdkParams.region || DefaultPulumiGetStackOutputService.DEFAULT_REGION;
|
|
77
|
-
const variant = sdkParams.variant || DefaultPulumiGetStackOutputService.DEFAULT_VARIANT;
|
|
78
|
-
return `${app.name}-${env}-${region}-${variant}.json`;
|
|
79
|
-
}
|
|
80
|
-
getCachePath(app) {
|
|
81
|
-
const project = this.getProjectService.execute();
|
|
82
|
-
const cacheDir = project.paths.dotWebinyFolder.join("caches", "stack-output").toString();
|
|
83
|
-
const cacheKey = this.getCacheKey(app);
|
|
84
|
-
return path.join(cacheDir, cacheKey);
|
|
85
|
-
}
|
|
86
|
-
async readFromCache(app) {
|
|
87
|
-
const cachePath = this.getCachePath(app);
|
|
88
|
-
try {
|
|
89
|
-
const content = await promises.readFile(cachePath, "utf-8");
|
|
90
|
-
return JSON.parse(content);
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async writeToCache(app, data) {
|
|
96
|
-
const cachePath = this.getCachePath(app);
|
|
97
|
-
const cacheDir = path.dirname(cachePath);
|
|
98
|
-
try {
|
|
99
|
-
await promises.mkdir(cacheDir, {
|
|
100
|
-
recursive: true
|
|
101
|
-
});
|
|
102
|
-
await promises.writeFile(cachePath, JSON.stringify(data, null, 2), "utf-8");
|
|
103
|
-
} catch (error) {
|
|
104
|
-
this.loggerService.error("Could not write to cache file.", cachePath, error);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
51
|
}
|
|
108
52
|
const pulumiGetStackOutputService = createImplementation({
|
|
109
53
|
abstraction: PulumiGetStackOutputService,
|
|
@@ -112,8 +56,7 @@ const pulumiGetStackOutputService = createImplementation({
|
|
|
112
56
|
GetPulumiService,
|
|
113
57
|
PulumiSelectStackService,
|
|
114
58
|
LoggerService,
|
|
115
|
-
|
|
116
|
-
ProjectSdkParamsService
|
|
59
|
+
StackOutputCacheService
|
|
117
60
|
]
|
|
118
61
|
});
|
|
119
62
|
export { DefaultPulumiGetStackOutputService, pulumiGetStackOutputService };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services/PulumiGetStackOutputService/PulumiGetStackOutputService.js","sources":["../../../src/services/PulumiGetStackOutputService/PulumiGetStackOutputService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport {\n GetPulumiService,\n
|
|
1
|
+
{"version":3,"file":"services/PulumiGetStackOutputService/PulumiGetStackOutputService.js","sources":["../../../src/services/PulumiGetStackOutputService/PulumiGetStackOutputService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport {\n GetPulumiService,\n LoggerService,\n PulumiGetStackOutputService,\n PulumiSelectStackService,\n StackOutputCacheService\n} from \"~/abstractions/index.js\";\nimport { type AppModel } from \"~/models/index.js\";\nimport { createEnvConfiguration, withPulumiConfigPassphrase } from \"~/utils/env/index.js\";\nimport { mapStackOutput } from \"./mapStackOutput.js\";\n\nexport class DefaultPulumiGetStackOutputService implements PulumiGetStackOutputService.Interface {\n constructor(\n private getPulumiService: GetPulumiService.Interface,\n private pulumiSelectStackService: PulumiSelectStackService.Interface,\n private loggerService: LoggerService.Interface,\n private stackOutputCacheService: StackOutputCacheService.Interface\n ) {}\n\n async execute<TOutput extends Record<string, any> = Record<string, any>>(\n app: AppModel,\n params?: PulumiGetStackOutputService.Params\n ): Promise<TOutput | null> {\n // Try to read from cache if skipCache is not true\n if (!params?.skipCache) {\n const cachedOutput = await this.stackOutputCacheService.read(app);\n if (cachedOutput !== null) {\n return this.applyMapping(cachedOutput, params?.map) as TOutput;\n }\n }\n\n const pulumi = await this.getPulumiService.execute({ app });\n\n await this.pulumiSelectStackService.execute(app);\n\n const stackOutputString = await pulumi.run({\n command: [\"stack\", \"output\"],\n args: {\n json: true\n },\n execa: {\n env: createEnvConfiguration({\n configurations: [withPulumiConfigPassphrase()]\n })\n }\n });\n\n try {\n const stackOutputJson = JSON.parse(stackOutputString.stdout);\n if (!stackOutputJson) {\n return null;\n }\n\n await this.stackOutputCacheService.write(app, stackOutputJson);\n\n return this.applyMapping(stackOutputJson, params?.map) as TOutput;\n } catch {\n this.loggerService.error(\n \"Could not parse stack output as JSON.\",\n stackOutputString.stdout,\n app,\n params\n );\n return null;\n }\n }\n\n private applyMapping(\n data: Record<string, any>,\n map?: Record<string, any>\n ): Record<string, any> {\n if (!map) {\n return data;\n }\n // If a mapping is provided, we map the output to the specified structure.\n return mapStackOutput(data, map);\n }\n}\n\nexport const pulumiGetStackOutputService = createImplementation({\n abstraction: PulumiGetStackOutputService,\n implementation: DefaultPulumiGetStackOutputService,\n dependencies: [\n GetPulumiService,\n PulumiSelectStackService,\n LoggerService,\n StackOutputCacheService\n ]\n});\n"],"names":["DefaultPulumiGetStackOutputService","getPulumiService","pulumiSelectStackService","loggerService","stackOutputCacheService","app","params","cachedOutput","pulumi","stackOutputString","createEnvConfiguration","withPulumiConfigPassphrase","stackOutputJson","JSON","data","map","mapStackOutput","pulumiGetStackOutputService","createImplementation","PulumiGetStackOutputService","GetPulumiService","PulumiSelectStackService","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AC5D,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QACVoB;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -17,7 +17,7 @@ class DefaultPulumiLoginService {
|
|
|
17
17
|
app
|
|
18
18
|
});
|
|
19
19
|
const projectAppRelativePath = path.join("apps", app.name);
|
|
20
|
-
let loginUrl = process.env.WEBINY_PULUMI_BACKEND;
|
|
20
|
+
let loginUrl = process.env.WEBINY_CLI_PULUMI_BACKEND || process.env.WEBINY_PULUMI_BACKEND;
|
|
21
21
|
if (loginUrl) {
|
|
22
22
|
const selfManagedBackend = SELF_MANAGED_BACKEND.find((item)=>loginUrl.startsWith(item));
|
|
23
23
|
if (selfManagedBackend) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services/PulumiLoginService/PulumiLoginService.js","sources":["../../../src/services/PulumiLoginService/PulumiLoginService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GetPulumiService, PulumiLoginService } from \"~/abstractions/index.js\";\nimport { type AppModel } from \"~/models/index.js\";\nimport trimEnd from \"lodash/trimEnd.js\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nconst SELF_MANAGED_BACKEND = [\"s3://\", \"azblob://\", \"gs://\"];\n\nexport class DefaultPulumiLoginService implements PulumiLoginService.Interface {\n constructor(private getPulumiService: GetPulumiService.Interface) {}\n\n async execute(app: AppModel) {\n const pulumi = await this.getPulumiService.execute({ app });\n\n const projectAppRelativePath = path.join(\"apps\", app.name);\n\n //
|
|
1
|
+
{"version":3,"file":"services/PulumiLoginService/PulumiLoginService.js","sources":["../../../src/services/PulumiLoginService/PulumiLoginService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GetPulumiService, PulumiLoginService } from \"~/abstractions/index.js\";\nimport { type AppModel } from \"~/models/index.js\";\nimport trimEnd from \"lodash/trimEnd.js\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nconst SELF_MANAGED_BACKEND = [\"s3://\", \"azblob://\", \"gs://\"];\n\nexport class DefaultPulumiLoginService implements PulumiLoginService.Interface {\n constructor(private getPulumiService: GetPulumiService.Interface) {}\n\n async execute(app: AppModel) {\n const pulumi = await this.getPulumiService.execute({ app });\n\n const projectAppRelativePath = path.join(\"apps\", app.name);\n\n // `WEBINY_CLI_PULUMI_BACKEND` is the canonical variable. We still read the legacy\n // `WEBINY_PULUMI_BACKEND` as a fallback, to preserve backwards compatibility.\n let loginUrl = process.env.WEBINY_CLI_PULUMI_BACKEND || process.env.WEBINY_PULUMI_BACKEND;\n\n if (loginUrl) {\n // If the user passed `s3://my-bucket`, we want to store files in `s3://my-bucket/{project-application-path}`\n const selfManagedBackend = SELF_MANAGED_BACKEND.find(item =>\n loginUrl!.startsWith(item)\n );\n if (selfManagedBackend) {\n loginUrl = trimEnd(loginUrl, \"/\") + \"/\" + projectAppRelativePath;\n loginUrl = loginUrl.replace(/\\\\/g, \"/\");\n }\n } else {\n // By default, we use local file system as backend. All files are stored in project root's\n // `.pulumi` folder, e.g. `.pulumi/apps/admin`.\n const stateFilesFolder = app.paths.localPulumiStateFilesFolder.toString();\n\n if (!fs.existsSync(stateFilesFolder)) {\n fs.mkdirSync(stateFilesFolder, { recursive: true });\n }\n\n loginUrl = `file://${stateFilesFolder}`;\n }\n\n await pulumi.run({ command: [\"login\", loginUrl] });\n\n return { login: loginUrl };\n }\n}\n\nexport const pulumiLoginService = createImplementation({\n abstraction: PulumiLoginService,\n implementation: DefaultPulumiLoginService,\n dependencies: [GetPulumiService]\n});\n"],"names":["SELF_MANAGED_BACKEND","DefaultPulumiLoginService","getPulumiService","app","pulumi","projectAppRelativePath","path","loginUrl","process","selfManagedBackend","item","trimEnd","stateFilesFolder","fs","pulumiLoginService","createImplementation","PulumiLoginService","GetPulumiService"],"mappings":";;;;;AAOA,MAAMA,uBAAuB;IAAC;IAAS;IAAa;CAAQ;AAErD,MAAMC;IACT,YAAoBC,gBAA4C,CAAE;aAA9CA,gBAAgB,GAAhBA;IAA+C;IAEnE,MAAM,QAAQC,GAAa,EAAE;QACzB,MAAMC,SAAS,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAAED;QAAI;QAEzD,MAAME,yBAAyBC,KAAK,IAAI,CAAC,QAAQH,IAAI,IAAI;QAIzD,IAAII,WAAWC,QAAQ,GAAG,CAAC,yBAAyB,IAAIA,QAAQ,GAAG,CAAC,qBAAqB;QAEzF,IAAID,UAAU;YAEV,MAAME,qBAAqBT,qBAAqB,IAAI,CAACU,CAAAA,OACjDH,SAAU,UAAU,CAACG;YAEzB,IAAID,oBAAoB;gBACpBF,WAAWI,QAAQJ,UAAU,OAAO,MAAMF;gBAC1CE,WAAWA,SAAS,OAAO,CAAC,OAAO;YACvC;QACJ,OAAO;YAGH,MAAMK,mBAAmBT,IAAI,KAAK,CAAC,2BAA2B,CAAC,QAAQ;YAEvE,IAAI,CAACU,GAAG,UAAU,CAACD,mBACfC,GAAG,SAAS,CAACD,kBAAkB;gBAAE,WAAW;YAAK;YAGrDL,WAAW,CAAC,OAAO,EAAEK,kBAAkB;QAC3C;QAEA,MAAMR,OAAO,GAAG,CAAC;YAAE,SAAS;gBAAC;gBAASG;aAAS;QAAC;QAEhD,OAAO;YAAE,OAAOA;QAAS;IAC7B;AACJ;AAEO,MAAMO,qBAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgBf;IAChB,cAAc;QAACgB;KAAiB;AACpC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GetProjectService, LoggerService, ProjectSdkParamsService, StackOutputCacheService } from "../../abstractions/index.js";
|
|
2
|
+
import { type AppModel } from "../../models/index.js";
|
|
3
|
+
export declare class DefaultStackOutputCacheService implements StackOutputCacheService.Interface {
|
|
4
|
+
private getProjectService;
|
|
5
|
+
private projectSdkParamsService;
|
|
6
|
+
private loggerService;
|
|
7
|
+
private static readonly DEFAULT_ENV;
|
|
8
|
+
private static readonly DEFAULT_REGION;
|
|
9
|
+
private static readonly DEFAULT_VARIANT;
|
|
10
|
+
constructor(getProjectService: GetProjectService.Interface, projectSdkParamsService: ProjectSdkParamsService.Interface, loggerService: LoggerService.Interface);
|
|
11
|
+
read(app: AppModel): Promise<Record<string, any> | null>;
|
|
12
|
+
write(app: AppModel, data: Record<string, any>): Promise<void>;
|
|
13
|
+
delete(app: AppModel): Promise<void>;
|
|
14
|
+
private getCacheKey;
|
|
15
|
+
private getCacheDir;
|
|
16
|
+
private getCachePath;
|
|
17
|
+
}
|
|
18
|
+
export declare const stackOutputCacheService: import("@webiny/di").Implementation<typeof DefaultStackOutputCacheService>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createImplementation } from "@webiny/di";
|
|
2
|
+
import { GetProjectService, LoggerService, ProjectSdkParamsService, StackOutputCacheService } from "../../abstractions/index.js";
|
|
3
|
+
import promises from "fs/promises";
|
|
4
|
+
class DefaultStackOutputCacheService {
|
|
5
|
+
static{
|
|
6
|
+
this.DEFAULT_ENV = "dev";
|
|
7
|
+
}
|
|
8
|
+
static{
|
|
9
|
+
this.DEFAULT_REGION = "default";
|
|
10
|
+
}
|
|
11
|
+
static{
|
|
12
|
+
this.DEFAULT_VARIANT = "default";
|
|
13
|
+
}
|
|
14
|
+
constructor(getProjectService, projectSdkParamsService, loggerService){
|
|
15
|
+
this.getProjectService = getProjectService;
|
|
16
|
+
this.projectSdkParamsService = projectSdkParamsService;
|
|
17
|
+
this.loggerService = loggerService;
|
|
18
|
+
}
|
|
19
|
+
async read(app) {
|
|
20
|
+
const cachePath = this.getCachePath(app);
|
|
21
|
+
try {
|
|
22
|
+
const content = await promises.readFile(cachePath, "utf-8");
|
|
23
|
+
const data = JSON.parse(content);
|
|
24
|
+
this.loggerService.debug({
|
|
25
|
+
app: app.name,
|
|
26
|
+
cacheKey: this.getCacheKey(app)
|
|
27
|
+
}, "Stack output read from cache");
|
|
28
|
+
return data;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async write(app, data) {
|
|
34
|
+
const cachePath = this.getCachePath(app);
|
|
35
|
+
const cacheDir = this.getCacheDir().toString();
|
|
36
|
+
try {
|
|
37
|
+
await promises.mkdir(cacheDir, {
|
|
38
|
+
recursive: true
|
|
39
|
+
});
|
|
40
|
+
await promises.writeFile(cachePath, JSON.stringify(data, null, 2), "utf-8");
|
|
41
|
+
this.loggerService.debug("Stack output stored to cache", {
|
|
42
|
+
app: app.name,
|
|
43
|
+
cacheKey: this.getCacheKey(app)
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
this.loggerService.error("Could not write to cache file.", cachePath, error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async delete(app) {
|
|
50
|
+
const cachePath = this.getCachePath(app);
|
|
51
|
+
try {
|
|
52
|
+
await promises.rm(cachePath, {
|
|
53
|
+
force: true
|
|
54
|
+
});
|
|
55
|
+
this.loggerService.debug("Stack output cache deleted.", {
|
|
56
|
+
app: app.name,
|
|
57
|
+
cacheKey: this.getCacheKey(app)
|
|
58
|
+
});
|
|
59
|
+
} catch (error) {
|
|
60
|
+
this.loggerService.error("Could not delete stack output cache file.", cachePath, error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getCacheKey(app) {
|
|
64
|
+
const sdkParams = this.projectSdkParamsService.get();
|
|
65
|
+
const env = sdkParams.env || DefaultStackOutputCacheService.DEFAULT_ENV;
|
|
66
|
+
const region = sdkParams.region || DefaultStackOutputCacheService.DEFAULT_REGION;
|
|
67
|
+
const variant = sdkParams.variant || DefaultStackOutputCacheService.DEFAULT_VARIANT;
|
|
68
|
+
return `${app.name}-${env}-${region}-${variant}.json`;
|
|
69
|
+
}
|
|
70
|
+
getCacheDir() {
|
|
71
|
+
const project = this.getProjectService.execute();
|
|
72
|
+
return project.paths.dotWebinyFolder.join("caches", "stack-output");
|
|
73
|
+
}
|
|
74
|
+
getCachePath(app) {
|
|
75
|
+
return this.getCacheDir().join(this.getCacheKey(app)).toString();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const stackOutputCacheService = createImplementation({
|
|
79
|
+
abstraction: StackOutputCacheService,
|
|
80
|
+
implementation: DefaultStackOutputCacheService,
|
|
81
|
+
dependencies: [
|
|
82
|
+
GetProjectService,
|
|
83
|
+
ProjectSdkParamsService,
|
|
84
|
+
LoggerService
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
export { DefaultStackOutputCacheService, stackOutputCacheService };
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=StackOutputCacheService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services/StackOutputCacheService/StackOutputCacheService.js","sources":["../../../src/services/StackOutputCacheService/StackOutputCacheService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport {\n GetProjectService,\n LoggerService,\n ProjectSdkParamsService,\n StackOutputCacheService\n} from \"~/abstractions/index.js\";\nimport { type AppModel } from \"~/models/index.js\";\nimport fs from \"fs/promises\";\n\nexport class DefaultStackOutputCacheService implements StackOutputCacheService.Interface {\n private static readonly DEFAULT_ENV = \"dev\";\n private static readonly DEFAULT_REGION = \"default\";\n private static readonly DEFAULT_VARIANT = \"default\";\n\n constructor(\n private getProjectService: GetProjectService.Interface,\n private projectSdkParamsService: ProjectSdkParamsService.Interface,\n private loggerService: LoggerService.Interface\n ) {}\n\n async read(app: AppModel): Promise<Record<string, any> | null> {\n const cachePath = this.getCachePath(app);\n\n try {\n const content = await fs.readFile(cachePath, \"utf-8\");\n const data = JSON.parse(content);\n this.loggerService.debug(\n { app: app.name, cacheKey: this.getCacheKey(app) },\n \"Stack output read from cache\"\n );\n return data;\n } catch {\n // File doesn't exist or couldn't be read/parsed - this is expected on first run.\n return null;\n }\n }\n\n async write(app: AppModel, data: Record<string, any>): Promise<void> {\n const cachePath = this.getCachePath(app);\n const cacheDir = this.getCacheDir().toString();\n\n try {\n // Create cache directory if it doesn't exist.\n await fs.mkdir(cacheDir, { recursive: true });\n await fs.writeFile(cachePath, JSON.stringify(data, null, 2), \"utf-8\");\n this.loggerService.debug(\"Stack output stored to cache\", {\n app: app.name,\n cacheKey: this.getCacheKey(app)\n });\n } catch (error) {\n this.loggerService.error(\"Could not write to cache file.\", cachePath, error);\n }\n }\n\n async delete(app: AppModel): Promise<void> {\n const cachePath = this.getCachePath(app);\n\n try {\n // `force: true` makes this a no-op if the cache file doesn't exist.\n await fs.rm(cachePath, { force: true });\n this.loggerService.debug(\"Stack output cache deleted.\", {\n app: app.name,\n cacheKey: this.getCacheKey(app)\n });\n } catch (error) {\n this.loggerService.error(\"Could not delete stack output cache file.\", cachePath, error);\n }\n }\n\n private getCacheKey(app: AppModel): string {\n const sdkParams = this.projectSdkParamsService.get();\n const env = sdkParams.env || DefaultStackOutputCacheService.DEFAULT_ENV;\n const region = sdkParams.region || DefaultStackOutputCacheService.DEFAULT_REGION;\n const variant = sdkParams.variant || DefaultStackOutputCacheService.DEFAULT_VARIANT;\n return `${app.name}-${env}-${region}-${variant}.json`;\n }\n\n private getCacheDir() {\n const project = this.getProjectService.execute();\n return project.paths.dotWebinyFolder.join(\"caches\", \"stack-output\");\n }\n\n private getCachePath(app: AppModel): string {\n return this.getCacheDir().join(this.getCacheKey(app)).toString();\n }\n}\n\nexport const stackOutputCacheService = createImplementation({\n abstraction: StackOutputCacheService,\n implementation: DefaultStackOutputCacheService,\n dependencies: [GetProjectService, ProjectSdkParamsService, LoggerService]\n});\n"],"names":["DefaultStackOutputCacheService","getProjectService","projectSdkParamsService","loggerService","app","cachePath","content","fs","data","JSON","cacheDir","error","sdkParams","env","region","variant","project","stackOutputCacheService","createImplementation","StackOutputCacheService","GetProjectService","ProjectSdkParamsService","LoggerService"],"mappings":";;;AAUO,MAAMA;;aACe,WAAW,GAAG;;;aACd,cAAc,GAAG;;;aACjB,eAAe,GAAG;;IAE1C,YACYC,iBAA8C,EAC9CC,uBAA0D,EAC1DC,aAAsC,CAChD;aAHUF,iBAAiB,GAA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CAAC,KAAK,CAAC,6CAA6CN,WAAWM;QACrF;IACJ;IAEQ,YAAYP,GAAa,EAAU;QACvC,MAAMQ,YAAY,IAAI,CAAC,uBAAuB,CAAC,GAAG;QAClD,MAAMC,MAAMD,UAAU,GAAG,IAAIZ,+BAA+B,WAAW;QACvE,MAAMc,SAASF,UAAU,MAAM,IAAIZ,+BAA+B,cAAc;QAChF,MAAMe,UAAUH,UAAU,OAAO,IAAIZ,+BAA+B,eAAe;QACnF,OAAO,GAAGI,IAAI,IAAI,CAAC,CAAC,EAAES,IAAI,CAAC,EAAEC,OAAO,CAAC,EAAEC,QAAQ,KAAK,CAAC;IACzD;IAEQ,cAAc;QAClB,MAAMC,UAAU,IAAI,CAAC,iBAAiB,CAAC,OAAO;QAC9C,OAAOA,QAAQ,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU;IACxD;IAEQ,aAAaZ,GAAa,EAAU;QACxC,OAAO,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAACA,MAAM,QAAQ;IAClE;AACJ;AAEO,MAAMa,0BAA0BC,qBAAqB;IACxD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAmBC;QAAyBC;KAAc;AAC7E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./StackOutputCacheService.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./StackOutputCacheService.js";
|
package/services/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./GetCwdService/index.js";
|
|
|
6
6
|
export * from "./GetProjectConfigService/index.js";
|
|
7
7
|
export * from "./GetProjectIdService/index.js";
|
|
8
8
|
export * from "./GetProjectService/index.js";
|
|
9
|
+
export * from "./GetProjectInstallationIdService/index.js";
|
|
9
10
|
export * from "./GetProjectVersionService/index.js";
|
|
10
11
|
export * from "./GetPulumiService/index.js";
|
|
11
12
|
export * from "./InitProjectSdkService/index.js";
|
|
@@ -28,6 +29,7 @@ export * from "./PulumiGetStackOutputService/index.js";
|
|
|
28
29
|
export * from "./PulumiLoginService/index.js";
|
|
29
30
|
export * from "./PulumiSelectStackService/index.js";
|
|
30
31
|
export * from "./SetProjectIdService/index.js";
|
|
32
|
+
export * from "./StackOutputCacheService/index.js";
|
|
31
33
|
export * from "./StdioService/index.js";
|
|
32
34
|
export * from "./UiService/index.js";
|
|
33
35
|
export * from "./ValidateProjectConfigService/index.js";
|
package/services/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./GetCwdService/index.js";
|
|
|
6
6
|
export * from "./GetProjectConfigService/index.js";
|
|
7
7
|
export * from "./GetProjectIdService/index.js";
|
|
8
8
|
export * from "./GetProjectService/index.js";
|
|
9
|
+
export * from "./GetProjectInstallationIdService/index.js";
|
|
9
10
|
export * from "./GetProjectVersionService/index.js";
|
|
10
11
|
export * from "./GetPulumiService/index.js";
|
|
11
12
|
export * from "./InitProjectSdkService/index.js";
|
|
@@ -28,6 +29,7 @@ export * from "./PulumiGetStackOutputService/index.js";
|
|
|
28
29
|
export * from "./PulumiLoginService/index.js";
|
|
29
30
|
export * from "./PulumiSelectStackService/index.js";
|
|
30
31
|
export * from "./SetProjectIdService/index.js";
|
|
32
|
+
export * from "./StackOutputCacheService/index.js";
|
|
31
33
|
export * from "./StdioService/index.js";
|
|
32
34
|
export * from "./UiService/index.js";
|
|
33
35
|
export * from "./ValidateProjectConfigService/index.js";
|